-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConvertPluginDatabase.cs
More file actions
74 lines (66 loc) · 3.09 KB
/
ConvertPluginDatabase.cs
File metadata and controls
74 lines (66 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using OpenDentBusiness;
namespace PluginExample {
public class ConvertPluginDatabase {
private static Version FromVersion;
public static void Begin() {//unlike in the main program, this conversion script runs on every startup.
Version MainAppVersion=new Version(System.Windows.Forms.Application.ProductVersion);//eg. 6.8.0.0
Version MainAppMajMin=new Version(MainAppVersion.Major,MainAppVersion.Minor);//eg. 6.8
Version ThisAssemblyVersion=System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;//eg. 6.7.0.0
Version ThisAssMajMin=new Version(ThisAssemblyVersion.Major,ThisAssemblyVersion.Minor);//eg. 6.7
if(ThisAssMajMin > MainAppMajMin) {
//Prevent the use of a new plugin with an old version of OD. User should upgrade OD.
throw new ApplicationException("Version of plug-in may not be newer than version of Open Dental.");
}
//In case the developer of a plug-in gets hit by a bus etc, there should be no restriction on using an old plugin with a new version of OD.
//If a plug-in is distributed, there should be a separate plugin available for each minor version.
string command="SELECT ValueString FROM preference WHERE PrefName='Plugin_JSS_DataBaseVersion'";//notice the very unique name.
DataTable table=DataCore.GetTable(command);
if(table.Rows.Count==0) {//This plugin has never run before.
command="INSERT INTO preference (PrefName,ValueString) VALUES('Plugin_JSS_DataBaseVersion','1.0.0.0')";
DataCore.NonQ(command);
FromVersion=new Version(1,0);
}
else {
FromVersion=new Version(table.Rows[0][0].ToString());
}
if(FromVersion < new Version("6.8.0.0")) {//6.8.1.0
//remember to NEVER use "0" versions (head), which are still in development.
command="DROP TABLE IF EXISTS jss_dev_myveryuniquetable";//best practice to drop first in case file is present from an old backup.
DataCore.NonQ(command);
command=@"CREATE TABLE jss_dev_myveryuniquetable (
PriKeyNum INT AUTO_INCREMENT,
ForeignKeyNum INT,
Descript VARCHAR(255),
PRIMARY KEY(PriKeyNum)
)";
DataCore.NonQ(command);
command="UPDATE preference SET ValueString = '6.8.0.0' WHERE PrefName = 'Plugin_JSS_DataBaseVersion'";
DataCore.NonQ(command);
}
To7_1_0();
}
private static void To7_1_0(){//don't forget to change the version of this dll in AssemblyInfo.cs in order to trigger this method.
if(FromVersion < new Version("7.1.0.0")) {
string command;
command="ALTER TABLE jss_dev_myveryuniquetable CHANGE PriKeyNum PriKeyNum bigint NOT NULL auto_increment";
DataCore.NonQ(command);
command="ALTER TABLE jss_dev_myveryuniquetable CHANGE ForeignKeyNum ForeignKeyNum bigint NOT NULL";
DataCore.NonQ(command);
command="UPDATE preference SET ValueString = '7.1.0.0' WHERE PrefName = 'Plugin_JSS_DataBaseVersion'";
DataCore.NonQ(command);
}
//To7_2_0(){//etc
}
//private static void To7_2_0() {
//if(FromVersion < new Version("7.2.0.0")) {//etc
//etc
//}
//To7_3_0(){//etc
//}
}
}