diff --git a/Document/opreator.wmv b/Document/opreator.wmv new file mode 100644 index 0000000..43de5c0 Binary files /dev/null and b/Document/opreator.wmv differ diff --git a/SCADA/Example/TagConfig.exe b/SCADA/Example/TagConfig.exe index ce7b5d1..fcb535b 100644 Binary files a/SCADA/Example/TagConfig.exe and b/SCADA/Example/TagConfig.exe differ diff --git a/SCADA/Program/TagConfig/TagConfig/Form1.Designer.cs b/SCADA/Program/TagConfig/TagConfig/Form1.Designer.cs index 30085a6..6fa7a2d 100644 --- a/SCADA/Program/TagConfig/TagConfig/Form1.Designer.cs +++ b/SCADA/Program/TagConfig/TagConfig/Form1.Designer.cs @@ -113,6 +113,7 @@ this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); + this.粘贴CSVToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -394,9 +395,10 @@ this.tspcut, this.tsppaste, this.批量删除ToolStripMenuItem, - this.事件归档ToolStripMenuItem}); + this.事件归档ToolStripMenuItem, + this.粘贴CSVToolStripMenuItem}); this.contextMenuStrip2.Name = "contextMenuStrip2"; - this.contextMenuStrip2.Size = new System.Drawing.Size(195, 202); + this.contextMenuStrip2.Size = new System.Drawing.Size(195, 224); this.contextMenuStrip2.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip2_Opening); this.contextMenuStrip2.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.contextMenuStrip2_ItemClicked); // @@ -773,6 +775,13 @@ this.tspCount.Name = "tspCount"; this.tspCount.Size = new System.Drawing.Size(0, 17); // + // 粘贴CSVToolStripMenuItem + // + this.粘贴CSVToolStripMenuItem.Name = "粘贴CSVToolStripMenuItem"; + this.粘贴CSVToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Y))); + this.粘贴CSVToolStripMenuItem.Size = new System.Drawing.Size(194, 22); + this.粘贴CSVToolStripMenuItem.Text = "粘贴CSV"; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -888,6 +897,7 @@ private System.Windows.Forms.ToolStripSeparator toolStripSeparator9; private System.Windows.Forms.ToolStripButton toolStripButton5; private System.Windows.Forms.ToolStripTextBox tspOffset; + private System.Windows.Forms.ToolStripMenuItem 粘贴CSVToolStripMenuItem; } } diff --git a/SCADA/Program/TagConfig/TagConfig/Form1.cs b/SCADA/Program/TagConfig/TagConfig/Form1.cs index eba4376..8d23626 100644 --- a/SCADA/Program/TagConfig/TagConfig/Form1.cs +++ b/SCADA/Program/TagConfig/TagConfig/Form1.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Data.SqlClient; using System.IO; using System.Linq; +using System.Text; using System.Windows.Forms; using System.Xml; using Excel = Microsoft.Office.Interop.Excel; @@ -398,34 +399,44 @@ namespace TagConfig } } - private void LoadFromCsv(string file) + private void LoadFromCsv() { - Excel.Application app = new Excel.Application(); - Workbook book = app.Workbooks.Open(file); - Worksheet sheet = (Worksheet)book.Sheets[1]; - list.Clear(); - for (int i = 2; i < sheet.Rows.Count; i++) + if (Clipboard.ContainsText(TextDataFormat.Text)) { - if (((Range)sheet.Cells[i, 1]).Value2 == null) - break; - try + string data = Clipboard.GetText(TextDataFormat.Text); + if (string.IsNullOrEmpty(data)) return; + list.Clear(); + using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(data))) { - short id = Convert.ToInt16(((Range)sheet.Cells[i, 1]).Value2); - TagData tag = new TagData(id, Convert.ToInt16(((Range)sheet.Cells[i, 2]).Value2), ((Range)sheet.Cells[i, 3]).Value2.ToString(), - ((Range)sheet.Cells[i, 4]).Value2.ToString(), Convert.ToByte(((Range)sheet.Cells[i, 5]).Value2), Convert.ToUInt16(((Range)sheet.Cells[i, 6]).Value2), - Convert.ToBoolean(((Range)sheet.Cells[i, 7]).Value2), Convert.ToBoolean(((Range)sheet.Cells[i, 8]).Value2), Convert.ToBoolean(((Range)sheet.Cells[i, 9]).Value2), - Convert.ToBoolean(((Range)sheet.Cells[i, 10]).Value2), ((Range)sheet.Cells[i, 11]).Value2, ((Range)sheet.Cells[i, 12]).Value2 as string, - Convert.ToSingle(((Range)sheet.Cells[i, 13]).Value2), Convert.ToSingle(((Range)sheet.Cells[i, 14]).Value2), Convert.ToInt32(((Range)sheet.Cells[i, 15]).Value2)); - list.Add(tag); - } - catch (Exception e) - { - continue; - //Program.AddErrorLog(e); + using (var mysr = new StreamReader(stream)) + { + string strline = mysr.ReadLine(); + while ((strline = mysr.ReadLine()) != null) + { + string[] aryline = strline.Split('\t'); + try + { + var id = Convert.ToInt16(aryline[0]); + var groupid = Convert.ToInt16(aryline[1]); + var name = aryline[2]; + var address = aryline[3]; + var type = Convert.ToByte(aryline[4]); + var size = Convert.ToUInt16(aryline[5]); + var active = Convert.ToBoolean(aryline[6]); + var desp = aryline[7]; + TagData tag = new TagData(id, groupid, name, address, type, size, active, false, false, false, null, desp, 0, 0, 0); + list.Add(tag); + } + catch (Exception err) + { + continue; + } + } + } } + list.Sort(); + start = true; } - list.Sort(); - start = true; } private void LoadFromExcel(string file) @@ -914,7 +925,7 @@ namespace TagConfig } break; case "导入变量": - openFileDialog1.Filter = "xml文件 (*.xml)|*.xml|csv文件 (*.csv)|*.csv|excel文件 (*.xlsx)|*.xlsx|kepserver文件 (*.csv)|*.csv|All files (*.*)|*.*"; + openFileDialog1.Filter = "xml文件 (*.xml)|*.xml|excel文件 (*.xlsx)|*.xlsx|kepserver文件 (*.csv)|*.csv|All files (*.*)|*.*"; openFileDialog1.DefaultExt = "xml"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { @@ -925,12 +936,9 @@ namespace TagConfig LoadFromXml(file); break; case 2: - LoadFromCsv(file); - break; - case 3: LoadFromExcel(file); break; - case 4: + case 3: LoadFromKepserverCSV(file); break; } @@ -1170,6 +1178,9 @@ namespace TagConfig isCut = true; } break; + case "粘贴CSV": + LoadFromCsv(); + break; case "粘帖": { if (treeView1.SelectedNode == null || treeView1.SelectedNode.Level != 2) diff --git a/SCADA/Program/TagConfig/TagConfig/Form1.resx b/SCADA/Program/TagConfig/TagConfig/Form1.resx index b190ec7..1c985b2 100644 --- a/SCADA/Program/TagConfig/TagConfig/Form1.resx +++ b/SCADA/Program/TagConfig/TagConfig/Form1.resx @@ -128,7 +128,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAC6 - CAAAAk1TRnQBSQFMAgEBAwEAARABAgEQAQIBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + CAAAAk1TRnQBSQFMAgEBAwEAARgBAgEYAQIBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA