diff --git a/SCADA/Example/BatchCoreTest.exe b/SCADA/Example/BatchCoreTest.exe index 3cae248..c9c9adf 100644 Binary files a/SCADA/Example/BatchCoreTest.exe and b/SCADA/Example/BatchCoreTest.exe differ diff --git a/SCADA/Example/ClientDriver.dll b/SCADA/Example/ClientDriver.dll index 06d7814..da28d6e 100644 Binary files a/SCADA/Example/ClientDriver.dll and b/SCADA/Example/ClientDriver.dll differ diff --git a/SCADA/Example/CoreTest.exe b/SCADA/Example/CoreTest.exe index 413a9ae..ac8459a 100644 Binary files a/SCADA/Example/CoreTest.exe and b/SCADA/Example/CoreTest.exe differ diff --git a/SCADA/Example/DataHelper.dll b/SCADA/Example/DataHelper.dll index 8938dbb..d1dc396 100644 Binary files a/SCADA/Example/DataHelper.dll and b/SCADA/Example/DataHelper.dll differ diff --git a/SCADA/Example/DataService.dll b/SCADA/Example/DataService.dll index 0623367..b916cdb 100644 Binary files a/SCADA/Example/DataService.dll and b/SCADA/Example/DataService.dll differ diff --git a/SCADA/Example/HMIControl.dll b/SCADA/Example/HMIControl.dll index c1f964c..eb263b5 100644 Binary files a/SCADA/Example/HMIControl.dll and b/SCADA/Example/HMIControl.dll differ diff --git a/SCADA/Example/MySql.Data.dll b/SCADA/Example/MySql.Data.dll new file mode 100644 index 0000000..7eaba45 Binary files /dev/null and b/SCADA/Example/MySql.Data.dll differ diff --git a/SCADA/Example/TagConfig.exe b/SCADA/Example/TagConfig.exe new file mode 100644 index 0000000..ce7b5d1 Binary files /dev/null and b/SCADA/Example/TagConfig.exe differ diff --git a/SCADA/Program/DataExchange.sln b/SCADA/Program/DataExchange.sln index 4b160fa..196a3f4 100644 --- a/SCADA/Program/DataExchange.sln +++ b/SCADA/Program/DataExchange.sln @@ -29,6 +29,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModbusDriver", "ModbusDrive EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SiemensPLCDriver", "SiemensPLCDriver\SiemensPLCDriver.csproj", "{9CEBFDA4-CF05-44D1-881B-13775AA46B27}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TagConfig", "TagConfig\TagConfig\TagConfig.csproj", "{18F86945-9CB9-4149-A09C-85B8C5C7C4ED}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -261,6 +263,20 @@ Global {9CEBFDA4-CF05-44D1-881B-13775AA46B27}.Release|x64.Build.0 = Release|x64 {9CEBFDA4-CF05-44D1-881B-13775AA46B27}.Release|x86.ActiveCfg = Release|Any CPU {9CEBFDA4-CF05-44D1-881B-13775AA46B27}.Release|x86.Build.0 = Release|Any CPU + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Debug|Any CPU.ActiveCfg = Debug|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Debug|Itanium.ActiveCfg = Debug|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Debug|x64.ActiveCfg = Debug|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Debug|x86.ActiveCfg = Debug|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Debug|x86.Build.0 = Debug|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Release|Any CPU.ActiveCfg = Release|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Release|Itanium.ActiveCfg = Release|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Release|Mixed Platforms.Build.0 = Release|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Release|x64.ActiveCfg = Release|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Release|x86.ActiveCfg = Release|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SCADA/Program/DataService/PLCGroup.cs b/SCADA/Program/DataService/PLCGroup.cs index 536570c..cea6922 100644 --- a/SCADA/Program/DataService/PLCGroup.cs +++ b/SCADA/Program/DataService/PLCGroup.cs @@ -278,7 +278,11 @@ namespace DataService _cacheReader.Size = cacheLength; } else - _cacheReader.Size = _start.DataSize <= bitCount ? 1 : _start.DataSize / bitCount;//改变Cache的Size属性值将创建Cache的内存区域 + { + var size= _start.DataSize <= bitCount ? 1 : _start.DataSize / bitCount; + _rangeList.Add(new PDUArea(_start, size, 0, 1)); + _cacheReader.Size = size;//改变Cache的Size属性值将创建Cache的内存区域 + } } } @@ -313,18 +317,6 @@ namespace DataService { if (_plcReader.IsClosed) return -1; byte[] cache = (byte[])_cacheReader.Cache; - if (_items.Count == 1) - { - byte[] rcvBytes = _plcReader.ReadBytes(_items[0].Address, (ushort)cache.Length); - if (rcvBytes == null) return -1; - for (int j = 0; j < rcvBytes.Length; j++) - { - if (cache[j] != rcvBytes[j]) - _changedList.Add(0); - cache[j] = rcvBytes[j]; - } - return 1; - } int offset = 0; foreach (PDUArea area in _rangeList) { diff --git a/SCADA/Program/TagConfig/TagConfig.sln b/SCADA/Program/TagConfig/TagConfig.sln new file mode 100644 index 0000000..e612bb2 --- /dev/null +++ b/SCADA/Program/TagConfig/TagConfig.sln @@ -0,0 +1,62 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TagConfig", "TagConfig\TagConfig.csproj", "{18F86945-9CB9-4149-A09C-85B8C5C7C4ED}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataHelper", "..\Program\DataHelper\DataHelper.csproj", "{755C5459-BCA4-4729-A93C-0C73A41BDF3C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|Itanium = Debug|Itanium + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|Itanium = Release|Itanium + Release|Mixed Platforms = Release|Mixed Platforms + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Debug|Any CPU.ActiveCfg = Debug|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Debug|Itanium.ActiveCfg = Debug|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Debug|x64.ActiveCfg = Debug|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Debug|x86.ActiveCfg = Debug|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Debug|x86.Build.0 = Debug|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Release|Any CPU.ActiveCfg = Release|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Release|Itanium.ActiveCfg = Release|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Release|Mixed Platforms.Build.0 = Release|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Release|x64.ActiveCfg = Release|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Release|x86.ActiveCfg = Release|x86 + {18F86945-9CB9-4149-A09C-85B8C5C7C4ED}.Release|x86.Build.0 = Release|x86 + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Debug|Itanium.ActiveCfg = Debug|Itanium + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Debug|Itanium.Build.0 = Debug|Itanium + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Debug|x64.ActiveCfg = Debug|x64 + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Debug|x64.Build.0 = Debug|x64 + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Debug|x86.ActiveCfg = Debug|x86 + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Debug|x86.Build.0 = Debug|x86 + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Release|Any CPU.Build.0 = Release|Any CPU + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Release|Itanium.ActiveCfg = Release|Itanium + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Release|Itanium.Build.0 = Release|Itanium + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Release|Mixed Platforms.Build.0 = Release|x86 + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Release|x64.ActiveCfg = Release|x64 + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Release|x64.Build.0 = Release|x64 + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Release|x86.ActiveCfg = Release|x86 + {755C5459-BCA4-4729-A93C-0C73A41BDF3C}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/SCADA/TagConfig/TagConfig/AlarmForm.Designer.cs b/SCADA/Program/TagConfig/TagConfig/AlarmForm.Designer.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/AlarmForm.Designer.cs rename to SCADA/Program/TagConfig/TagConfig/AlarmForm.Designer.cs diff --git a/SCADA/TagConfig/TagConfig/AlarmForm.cs b/SCADA/Program/TagConfig/TagConfig/AlarmForm.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/AlarmForm.cs rename to SCADA/Program/TagConfig/TagConfig/AlarmForm.cs diff --git a/SCADA/TagConfig/TagConfig/AlarmForm.resx b/SCADA/Program/TagConfig/TagConfig/AlarmForm.resx similarity index 100% rename from SCADA/TagConfig/TagConfig/AlarmForm.resx rename to SCADA/Program/TagConfig/TagConfig/AlarmForm.resx diff --git a/SCADA/TagConfig/TagConfig/AlarmParam.Designer.cs b/SCADA/Program/TagConfig/TagConfig/AlarmParam.Designer.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/AlarmParam.Designer.cs rename to SCADA/Program/TagConfig/TagConfig/AlarmParam.Designer.cs diff --git a/SCADA/TagConfig/TagConfig/AlarmParam.cs b/SCADA/Program/TagConfig/TagConfig/AlarmParam.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/AlarmParam.cs rename to SCADA/Program/TagConfig/TagConfig/AlarmParam.cs diff --git a/SCADA/TagConfig/TagConfig/AlarmParam.resx b/SCADA/Program/TagConfig/TagConfig/AlarmParam.resx similarity index 100% rename from SCADA/TagConfig/TagConfig/AlarmParam.resx rename to SCADA/Program/TagConfig/TagConfig/AlarmParam.resx diff --git a/SCADA/TagConfig/TagConfig/Condition.cs b/SCADA/Program/TagConfig/TagConfig/Condition.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/Condition.cs rename to SCADA/Program/TagConfig/TagConfig/Condition.cs diff --git a/SCADA/Program/TagConfig/TagConfig/DataHelper.cs b/SCADA/Program/TagConfig/TagConfig/DataHelper.cs new file mode 100644 index 0000000..ffce236 --- /dev/null +++ b/SCADA/Program/TagConfig/TagConfig/DataHelper.cs @@ -0,0 +1,74 @@ +using System.Data; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; + +namespace TagConfig +{ + public static class DataConvert //:MarshalByRefObject + { + public static DataTable ConvertTextToTable(string str) + { + if (string.IsNullOrEmpty(str)) return null; + DataTable mydt = new DataTable(""); + using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(str))) + { + using (var mysr = new StreamReader(stream)) + { + string strline = mysr.ReadLine(); + string[] aryline = strline.Split('\t'); + for (int i = 0; i < aryline.Length; i++) + { + aryline[i] = aryline[i].Replace("\"", ""); + mydt.Columns.Add(new DataColumn(aryline[i] + i)); + } + int intColCount = aryline.Length; + while ((strline = mysr.ReadLine()) != null) + { + aryline = strline.Split('\t'); + DataRow mydr = mydt.NewRow(); + for (int i = 0; i < intColCount; i++) + { + mydr[i] = aryline[i].Replace("\"", ""); + } + mydt.Rows.Add(mydr); + } + return mydt; + } + } + } + + public static DataTable ConvertCSVToTable(string str) + { + DataTable mydt = new DataTable(""); + using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(str))) + { + using (var mysr = new StreamReader(stream)) + { + string strline = mysr.ReadLine(); + + Regex reg = new Regex(@",(?=(?:[^\""]*\""[^\""]*\"")*(?![^\""]*\""))"); + string[] aryline = reg.Split(strline); + for (int i = 0; i < aryline.Length; i++) + { + aryline[i] = aryline[i].Replace("\"", ""); + mydt.Columns.Add(new DataColumn(aryline[i])); + } + int intColCount = aryline.Length; + while ((strline = mysr.ReadLine()) != null) + { + aryline = reg.Split(strline); + + DataRow mydr = mydt.NewRow(); + for (int i = 0; i < intColCount; i++) + { + mydr[i] = aryline[i].Replace("\"", ""); + } + mydt.Rows.Add(mydr); + } + return mydt; + } + } + } + } +} diff --git a/SCADA/TagConfig/TagConfig/DriverSet.Designer.cs b/SCADA/Program/TagConfig/TagConfig/DriverSet.Designer.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/DriverSet.Designer.cs rename to SCADA/Program/TagConfig/TagConfig/DriverSet.Designer.cs diff --git a/SCADA/TagConfig/TagConfig/DriverSet.cs b/SCADA/Program/TagConfig/TagConfig/DriverSet.cs similarity index 91% rename from SCADA/TagConfig/TagConfig/DriverSet.cs rename to SCADA/Program/TagConfig/TagConfig/DriverSet.cs index f3f6a5c..bf74988 100644 --- a/SCADA/TagConfig/TagConfig/DriverSet.cs +++ b/SCADA/Program/TagConfig/TagConfig/DriverSet.cs @@ -1,6 +1,7 @@ using System; using System.Windows.Forms; using System.Collections.Generic; +using DatabaseLib; namespace TagConfig { @@ -13,7 +14,7 @@ namespace TagConfig _device = device; InitializeComponent(); List typeList = new List(); - using (var reader = DataHelper.ExecuteReader("SELECT DRIVERID,ISNULL(Description,CLASSNAME) FROM RegisterModule")) + using (var reader = DataHelper.Instance.ExecuteReader("SELECT DRIVERID,ISNULL(Description,CLASSNAME) FROM RegisterModule")) { while (reader.Read()) { diff --git a/SCADA/TagConfig/TagConfig/DriverSet.resx b/SCADA/Program/TagConfig/TagConfig/DriverSet.resx similarity index 100% rename from SCADA/TagConfig/TagConfig/DriverSet.resx rename to SCADA/Program/TagConfig/TagConfig/DriverSet.resx diff --git a/SCADA/TagConfig/TagConfig/ExMethos.cs b/SCADA/Program/TagConfig/TagConfig/ExMethos.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/ExMethos.cs rename to SCADA/Program/TagConfig/TagConfig/ExMethos.cs diff --git a/SCADA/TagConfig/TagConfig/Form1.Designer.cs b/SCADA/Program/TagConfig/TagConfig/Form1.Designer.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/Form1.Designer.cs rename to SCADA/Program/TagConfig/TagConfig/Form1.Designer.cs diff --git a/SCADA/TagConfig/TagConfig/Form1.cs b/SCADA/Program/TagConfig/TagConfig/Form1.cs similarity index 87% rename from SCADA/TagConfig/TagConfig/Form1.cs rename to SCADA/Program/TagConfig/TagConfig/Form1.cs index 9a8a43b..a01547c 100644 --- a/SCADA/TagConfig/TagConfig/Form1.cs +++ b/SCADA/Program/TagConfig/TagConfig/Form1.cs @@ -1,15 +1,13 @@ -using System; +using DatabaseLib; +using Microsoft.Office.Interop.Excel; +using System; using System.Collections.Generic; -using System.Data; using System.Data.SqlClient; -using System.Diagnostics; using System.IO; using System.Linq; using System.Windows.Forms; using System.Xml; -using Microsoft.Office.Interop.Excel; using Excel = Microsoft.Office.Interop.Excel; -using System.Text; namespace TagConfig { @@ -17,7 +15,6 @@ namespace TagConfig public partial class Form1 : Form { const string FILENAME = "meta.xml"; - const string CONFIGFILE = @"C:\DataConfig\host.cfg"; bool start = false; string file = null; @@ -70,122 +67,17 @@ namespace TagConfig private void Form1_Load(object sender, EventArgs e) { majorTop = treeView1.Nodes.Add("", "服务器", 0, 0); - LoadConfig(); LoadFromDatabase(); treeView1.ExpandAll(); } - private void LoadConfig() - { - try - { - using (StreamReader objReader = new StreamReader(CONFIGFILE)) - { - objReader.ReadLine(); - string sLine = objReader.ReadLine(); - if (!string.IsNullOrEmpty(sLine)) - { - DataHelper.m_ConnStr = sLine; - return; - } - } - } - catch (Exception e) - { - Program.AddErrorLog(e); - } - using (XmlReader reader = XmlTextReader.Create(FILENAME)) - { - while (reader.Read()) - { - switch (reader.NodeType) - { - case XmlNodeType.Attribute: - break; - case XmlNodeType.Element: - //if (reader.IsEmptyElement) continue; - switch (reader.Name) - { - case "ConnectionString": - string server = null; - string ins = null; - if (reader.MoveToAttribute("server")) - { - server = reader.Value; - } - if (reader.MoveToAttribute("ins")) - { - ins = reader.Value; - } - if (reader.MoveToAttribute("database")) - { - builder.InitialCatalog = reader.Value; - } - if (reader.MoveToAttribute("user")) - { - builder.UserID = reader.Value; - } - if (reader.MoveToAttribute("password")) - { - builder.Password = reader.Value; - } - builder.DataSource = ins == null ? server : string.Format(@"{0}\{1}", server, ins); - break; - case "Script": - if (reader.MoveToAttribute("file")) - { - file = reader.Value; - } - break; - } - break; - } - } - } - //builder.InitialCatalog = "MYCOS"; - DataHelper.m_ConnStr = builder.ConnectionString; - } - - public void ExecuteScript()//应支持从Server类导出到XML; - //应支持从TreeView控件导出到XML;应支持直接从XML文件生成Server;支持从XML生成TreeView;从配置文件读入用户名和密码 - { - string[] args = new string[5]; - args[0] = "-U " + builder.UserID; //用户名 - args[1] = "-P " + builder.Password; //用户密码 - args[2] = "-S " + builder.DataSource; //服务器 - args[3] = "-d " + "master"; //数据库 - args[4] = "-i " + AppDomain.CurrentDomain.BaseDirectory + file; //sql脚本路径 - try - { - Process pr = new Process(); - pr.StartInfo.FileName = "osql.exe "; - //pr.StartInfo.Arguments = "-U sa -P sa -d master -s 127.0.0.1 -i " + file; - pr.StartInfo.Arguments = string.Join("", args); - pr.StartInfo.UseShellExecute = false; - pr.StartInfo.RedirectStandardOutput = true; //重定向输出 - - pr.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;//隐藏输出窗口 - pr.Start(); - - var sr = pr.StandardOutput; - Console.WriteLine(sr.ReadToEnd()); - - pr.WaitForExit(); - pr.Close(); - } - catch (Exception err) - { - Program.AddErrorLog(err); - } - } - private void LoadFromDatabase() { list.Clear(); //subConds.Clear(); majorTop.Nodes.Clear(); string sql = "SELECT DriverID,DriverType,DriverName,Server,TimeOut,Spare1,Spare2 FROM META_DRIVER;"; - using (var reader = DataHelper.ExecuteReader(sql)) + using (var reader = DataHelper.Instance.ExecuteReader(sql)) { while (reader.Read()) { @@ -198,7 +90,7 @@ namespace TagConfig foreach (TreeNode node in majorTop.Nodes) { sql = string.Format("SELECT GroupID,DriverID,GroupName,UpdateRate,DeadBand,IsActive FROM META_GROUP WHERE DriverID={0};", node.Name); - using (var reader = DataHelper.ExecuteReader(sql)) + using (var reader = DataHelper.Instance.ExecuteReader(sql)) { while (reader.Read()) { @@ -212,7 +104,7 @@ namespace TagConfig + "(SELECT COUNT(1) FROM Meta_Condition WHERE Source=t.TagName) HasAlarm," + "(SELECT COUNT(1) FROM Meta_Scale WHERE ScaleID=t.TagID) HasScale," + "Archive,DefaultValue,Description,Maximum,Minimum,Cycle FROM Meta_Tag t WHERE DataType<12"; - using (var reader = DataHelper.ExecuteReader(sql)) + using (var reader = DataHelper.Instance.ExecuteReader(sql)) { while (reader.Read()) { @@ -223,7 +115,7 @@ namespace TagConfig } } sql = "SELECT TypeID,Source,AlarmType,EventType,ConditionType,Para,IsEnabled,Deadband,Delay,Comment FROM Meta_Condition"; - using (var reader = DataHelper.ExecuteReader(sql)) + using (var reader = DataHelper.Instance.ExecuteReader(sql)) { while (reader.Read()) { @@ -233,7 +125,7 @@ namespace TagConfig } } sql = "SELECT IsEnable,Severity,ConditionID,SubAlarmType,Threshold,Message FROM Meta_SubCondition"; - using (var reader = DataHelper.ExecuteReader(sql)) + using (var reader = DataHelper.Instance.ExecuteReader(sql)) { while (reader.Read()) { @@ -243,7 +135,7 @@ namespace TagConfig } } sql = "SELECT ScaleID,ScaleType,EUHI,EULO,RAWHI,RAWLO FROM Meta_Scale"; - using (var reader = DataHelper.ExecuteReader(sql)) + using (var reader = DataHelper.Instance.ExecuteReader(sql)) { while (reader.Read()) { @@ -281,7 +173,7 @@ namespace TagConfig condition.SubConditions.Add(sub); } } - var obj = DataHelper.ExecuteScalar("SELECT MAX(TypeID) FROM Meta_Condition"); + var obj = DataHelper.Instance.ExecuteScalar("SELECT MAX(TypeID) FROM Meta_Condition"); if (obj != DBNull.Value) Program.MAXCONDITIONID = (int)obj; start = true; } @@ -290,63 +182,28 @@ namespace TagConfig { dataGridView1.CurrentCell = null; bindingSource1.EndEdit(); - //subConds.Clear(); - //foreach (var cond in conditions) - //{ - // foreach (var sub in cond.SubConditions) - // { - // //sub.ConditionId = cond.TypeId; - // subConds.Add(sub); - // } - //} + TagDataReader reader = new TagDataReader(list); ConditionReader condReader = new ConditionReader(conditions); SubConditionReader subReader = new SubConditionReader(subConds); ScaleReader scalereader = new ScaleReader(scaleList); - SqlConnection m_Conn = new SqlConnection(DataHelper.m_ConnStr); - SqlTransaction sqlT = null; - try + string sql = "DELETE FROM Meta_Driver;DELETE FROM Meta_Group;"; + foreach (Driver device in devices) { - if (m_Conn.State == ConnectionState.Closed) - m_Conn.Open(); - sqlT = m_Conn.BeginTransaction(); - string sql = "DELETE FROM Meta_Tag;DELETE FROM Meta_Driver;DELETE FROM Meta_Group;DELETE FROM Meta_Condition;DELETE FROM Meta_SubCondition;DELETE FROM Meta_Scale;"; - foreach (Driver device in devices) - { - sql = string.Concat(sql, string.Format("INSERT INTO Meta_Driver(DriverID,DriverName,DriverType,Server,TimeOut,Spare1,Spare2)" - + " VALUES({0},'{1}',{2},'{3}',{4},'{5}','{6}');", - device.ID, device.Name, device.DeviceDriver, device.ServerName, device.TimeOut, device.Spare1, device.Spare2)); - } - foreach (Group grp in groups) - { - sql = string.Concat(sql, string.Format("INSERT INTO Meta_Group(GroupID,GroupName,DriverID,UpdateRate,DeadBand,IsActive) VALUES({0},'{1}',{2},{3},{4},'{5}');", - grp.ID, grp.Name, grp.DriverID, grp.UpdateRate, grp.DeadBand, grp.Active)); - } - SqlCommand cmd = new SqlCommand(sql, m_Conn); - cmd.Transaction = sqlT; - cmd.ExecuteNonQuery(); - SqlBulkCopy bulk = new SqlBulkCopy(m_Conn, SqlBulkCopyOptions.KeepIdentity, sqlT); - bulk.DestinationTableName = "Meta_Tag"; - bulk.WriteToServer(reader); - bulk.DestinationTableName = "Meta_Condition"; - bulk.WriteToServer(condReader); - bulk.DestinationTableName = "Meta_SubCondition"; - bulk.WriteToServer(subReader); - bulk.DestinationTableName = "Meta_Scale"; - bulk.WriteToServer(scalereader); - //cmd.CommandText = ""; - sqlT.Commit(); - m_Conn.Close(); - //var obj = DataHelper.ExecuteScalar("SELECT MAX(TypeID) FROM Meta_Condition"); - //if (obj != DBNull.Value) Program.MAXCONDITIONID = (int)obj; + sql = string.Concat(sql, string.Format("INSERT INTO Meta_Driver(DriverID,DriverName,DriverType,Server,TimeOut,Spare1,Spare2)" + + " VALUES({0},'{1}',{2},'{3}',{4},'{5}','{6}');", + device.ID, device.Name, device.DeviceDriver, device.ServerName, device.TimeOut, device.Spare1, device.Spare2)); } - catch (Exception e) + foreach (Group grp in groups) { - if (sqlT != null) - sqlT.Rollback(); - m_Conn.Close(); - Program.AddErrorLog(e); + sql = string.Concat(sql, string.Format("INSERT INTO Meta_Group(GroupID,GroupName,DriverID,UpdateRate,DeadBand,IsActive) VALUES({0},'{1}',{2},{3},{4},'{5}');", + grp.ID, grp.Name, grp.DriverID, grp.UpdateRate, grp.DeadBand, grp.Active)); } + DataHelper.Instance.ExecuteNonQuery(sql); + DataHelper.Instance.BulkCopy(reader, "Meta_Tag", "DELETE FROM Meta_Tag", SqlBulkCopyOptions.KeepIdentity); + DataHelper.Instance.BulkCopy(condReader, "Meta_Condition", "DELETE FROM Meta_Condition", SqlBulkCopyOptions.KeepIdentity); + DataHelper.Instance.BulkCopy(subReader, "Meta_SubCondition", "DELETE FROM Meta_SubCondition", SqlBulkCopyOptions.KeepIdentity); + DataHelper.Instance.BulkCopy(scalereader, "Meta_Scale", "DELETE FROM Meta_Scale", SqlBulkCopyOptions.KeepIdentity); } private void LoadFromXml(string file) @@ -1396,7 +1253,7 @@ namespace TagConfig if (autolist == null) { var templist = new List { "@Time", "@Date", "@DateTime", "@User", "@AppName", "@LocName", "@Region", "@Path" }; - using (var reader = DataHelper.ExecuteReader("SELECT ISNULL(TagName,'') FROM Meta_Tag ORDER BY TagName")) + using (var reader = DataHelper.Instance.ExecuteReader("SELECT ISNULL(TagName,'') FROM Meta_Tag ORDER BY TagName")) { while (reader.Read()) { diff --git a/SCADA/TagConfig/TagConfig/Form1.resx b/SCADA/Program/TagConfig/TagConfig/Form1.resx similarity index 100% rename from SCADA/TagConfig/TagConfig/Form1.resx rename to SCADA/Program/TagConfig/TagConfig/Form1.resx diff --git a/SCADA/TagConfig/TagConfig/GroupParam.Designer.cs b/SCADA/Program/TagConfig/TagConfig/GroupParam.Designer.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/GroupParam.Designer.cs rename to SCADA/Program/TagConfig/TagConfig/GroupParam.Designer.cs diff --git a/SCADA/TagConfig/TagConfig/GroupParam.cs b/SCADA/Program/TagConfig/TagConfig/GroupParam.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/GroupParam.cs rename to SCADA/Program/TagConfig/TagConfig/GroupParam.cs diff --git a/SCADA/TagConfig/TagConfig/GroupParam.resx b/SCADA/Program/TagConfig/TagConfig/GroupParam.resx similarity index 100% rename from SCADA/TagConfig/TagConfig/GroupParam.resx rename to SCADA/Program/TagConfig/TagConfig/GroupParam.resx diff --git a/SCADA/TagConfig/TagConfig/Program.cs b/SCADA/Program/TagConfig/TagConfig/Program.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/Program.cs rename to SCADA/Program/TagConfig/TagConfig/Program.cs diff --git a/SCADA/TagConfig/TagConfig/Properties/AssemblyInfo.cs b/SCADA/Program/TagConfig/TagConfig/Properties/AssemblyInfo.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/Properties/AssemblyInfo.cs rename to SCADA/Program/TagConfig/TagConfig/Properties/AssemblyInfo.cs diff --git a/SCADA/TagConfig/TagConfig/Properties/Resources.Designer.cs b/SCADA/Program/TagConfig/TagConfig/Properties/Resources.Designer.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/Properties/Resources.Designer.cs rename to SCADA/Program/TagConfig/TagConfig/Properties/Resources.Designer.cs diff --git a/SCADA/TagConfig/TagConfig/Properties/Resources.resx b/SCADA/Program/TagConfig/TagConfig/Properties/Resources.resx similarity index 100% rename from SCADA/TagConfig/TagConfig/Properties/Resources.resx rename to SCADA/Program/TagConfig/TagConfig/Properties/Resources.resx diff --git a/SCADA/TagConfig/TagConfig/Properties/Settings.Designer.cs b/SCADA/Program/TagConfig/TagConfig/Properties/Settings.Designer.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/Properties/Settings.Designer.cs rename to SCADA/Program/TagConfig/TagConfig/Properties/Settings.Designer.cs diff --git a/SCADA/TagConfig/TagConfig/Properties/Settings.settings b/SCADA/Program/TagConfig/TagConfig/Properties/Settings.settings similarity index 100% rename from SCADA/TagConfig/TagConfig/Properties/Settings.settings rename to SCADA/Program/TagConfig/TagConfig/Properties/Settings.settings diff --git a/SCADA/TagConfig/TagConfig/RegisterSet.Designer.cs b/SCADA/Program/TagConfig/TagConfig/RegisterSet.Designer.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/RegisterSet.Designer.cs rename to SCADA/Program/TagConfig/TagConfig/RegisterSet.Designer.cs diff --git a/SCADA/TagConfig/TagConfig/RegisterSet.cs b/SCADA/Program/TagConfig/TagConfig/RegisterSet.cs similarity index 97% rename from SCADA/TagConfig/TagConfig/RegisterSet.cs rename to SCADA/Program/TagConfig/TagConfig/RegisterSet.cs index e7013ef..5acdba5 100644 --- a/SCADA/TagConfig/TagConfig/RegisterSet.cs +++ b/SCADA/Program/TagConfig/TagConfig/RegisterSet.cs @@ -1,4 +1,5 @@ -using System; +using DatabaseLib; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Reflection; @@ -98,7 +99,7 @@ namespace TagConfig .Append("','").Append(reg.Description).Append("');"); } } - if (DataHelper.ExecuteNonQuery(sb.ToString()) >= 0) + if (DataHelper.Instance.ExecuteNonQuery(sb.ToString()) >= 0) MessageBox.Show("注册成功!"); } } diff --git a/SCADA/TagConfig/TagConfig/RegisterSet.resx b/SCADA/Program/TagConfig/TagConfig/RegisterSet.resx similarity index 100% rename from SCADA/TagConfig/TagConfig/RegisterSet.resx rename to SCADA/Program/TagConfig/TagConfig/RegisterSet.resx diff --git a/SCADA/TagConfig/TagConfig/Resources/Attribute.gif b/SCADA/Program/TagConfig/TagConfig/Resources/Attribute.gif similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/Attribute.gif rename to SCADA/Program/TagConfig/TagConfig/Resources/Attribute.gif diff --git a/SCADA/TagConfig/TagConfig/Resources/Clear.gif b/SCADA/Program/TagConfig/TagConfig/Resources/Clear.gif similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/Clear.gif rename to SCADA/Program/TagConfig/TagConfig/Resources/Clear.gif diff --git a/SCADA/TagConfig/TagConfig/Resources/Collect.gif b/SCADA/Program/TagConfig/TagConfig/Resources/Collect.gif similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/Collect.gif rename to SCADA/Program/TagConfig/TagConfig/Resources/Collect.gif diff --git a/SCADA/TagConfig/TagConfig/Resources/Copy.gif b/SCADA/Program/TagConfig/TagConfig/Resources/Copy.gif similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/Copy.gif rename to SCADA/Program/TagConfig/TagConfig/Resources/Copy.gif diff --git a/SCADA/TagConfig/TagConfig/Resources/Database.ico b/SCADA/Program/TagConfig/TagConfig/Resources/Database.ico similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/Database.ico rename to SCADA/Program/TagConfig/TagConfig/Resources/Database.ico diff --git a/SCADA/TagConfig/TagConfig/Resources/Delete.gif b/SCADA/Program/TagConfig/TagConfig/Resources/Delete.gif similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/Delete.gif rename to SCADA/Program/TagConfig/TagConfig/Resources/Delete.gif diff --git a/SCADA/TagConfig/TagConfig/Resources/Excel.gif b/SCADA/Program/TagConfig/TagConfig/Resources/Excel.gif similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/Excel.gif rename to SCADA/Program/TagConfig/TagConfig/Resources/Excel.gif diff --git a/SCADA/TagConfig/TagConfig/Resources/Exit.gif b/SCADA/Program/TagConfig/TagConfig/Resources/Exit.gif similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/Exit.gif rename to SCADA/Program/TagConfig/TagConfig/Resources/Exit.gif diff --git a/SCADA/TagConfig/TagConfig/Resources/Find.gif b/SCADA/Program/TagConfig/TagConfig/Resources/Find.gif similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/Find.gif rename to SCADA/Program/TagConfig/TagConfig/Resources/Find.gif diff --git a/SCADA/TagConfig/TagConfig/Resources/Help.gif b/SCADA/Program/TagConfig/TagConfig/Resources/Help.gif similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/Help.gif rename to SCADA/Program/TagConfig/TagConfig/Resources/Help.gif diff --git a/SCADA/TagConfig/TagConfig/Resources/Link.ico b/SCADA/Program/TagConfig/TagConfig/Resources/Link.ico similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/Link.ico rename to SCADA/Program/TagConfig/TagConfig/Resources/Link.ico diff --git a/SCADA/TagConfig/TagConfig/Resources/PPrint.gif b/SCADA/Program/TagConfig/TagConfig/Resources/PPrint.gif similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/PPrint.gif rename to SCADA/Program/TagConfig/TagConfig/Resources/PPrint.gif diff --git a/SCADA/TagConfig/TagConfig/Resources/PSave.gif b/SCADA/Program/TagConfig/TagConfig/Resources/PSave.gif similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/PSave.gif rename to SCADA/Program/TagConfig/TagConfig/Resources/PSave.gif diff --git a/SCADA/TagConfig/TagConfig/Resources/Page-Setup.ico b/SCADA/Program/TagConfig/TagConfig/Resources/Page-Setup.ico similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/Page-Setup.ico rename to SCADA/Program/TagConfig/TagConfig/Resources/Page-Setup.ico diff --git a/SCADA/TagConfig/TagConfig/Resources/Timer.gif b/SCADA/Program/TagConfig/TagConfig/Resources/Timer.gif similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/Timer.gif rename to SCADA/Program/TagConfig/TagConfig/Resources/Timer.gif diff --git a/SCADA/TagConfig/TagConfig/Resources/Tip.ico b/SCADA/Program/TagConfig/TagConfig/Resources/Tip.ico similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/Tip.ico rename to SCADA/Program/TagConfig/TagConfig/Resources/Tip.ico diff --git a/SCADA/TagConfig/TagConfig/Resources/Tool.gif b/SCADA/Program/TagConfig/TagConfig/Resources/Tool.gif similarity index 100% rename from SCADA/TagConfig/TagConfig/Resources/Tool.gif rename to SCADA/Program/TagConfig/TagConfig/Resources/Tool.gif diff --git a/SCADA/TagConfig/TagConfig/ScaleParam.Designer.cs b/SCADA/Program/TagConfig/TagConfig/ScaleParam.Designer.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/ScaleParam.Designer.cs rename to SCADA/Program/TagConfig/TagConfig/ScaleParam.Designer.cs diff --git a/SCADA/TagConfig/TagConfig/ScaleParam.cs b/SCADA/Program/TagConfig/TagConfig/ScaleParam.cs similarity index 100% rename from SCADA/TagConfig/TagConfig/ScaleParam.cs rename to SCADA/Program/TagConfig/TagConfig/ScaleParam.cs diff --git a/SCADA/TagConfig/TagConfig/ScaleParam.resx b/SCADA/Program/TagConfig/TagConfig/ScaleParam.resx similarity index 100% rename from SCADA/TagConfig/TagConfig/ScaleParam.resx rename to SCADA/Program/TagConfig/TagConfig/ScaleParam.resx diff --git a/SCADA/TagConfig/TagConfig/TagConfig.csproj b/SCADA/Program/TagConfig/TagConfig/TagConfig.csproj similarity index 97% rename from SCADA/TagConfig/TagConfig/TagConfig.csproj rename to SCADA/Program/TagConfig/TagConfig/TagConfig.csproj index 80e71c6..ce509ab 100644 --- a/SCADA/TagConfig/TagConfig/TagConfig.csproj +++ b/SCADA/Program/TagConfig/TagConfig/TagConfig.csproj @@ -200,6 +200,12 @@ + + + {755c5459-bca4-4729-a93c-0c73a41bdf3c} + DataHelper + +