using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using DBFactory; namespace ControlSystem { public partial class FrmBarcode : Form { private FrmBarcode() { InitializeComponent(); } static private FrmBarcode _formstatnce; public static FrmBarcode Formstatnce { get { if (_formstatnce == null) { _formstatnce = new FrmBarcode(); } return _formstatnce; } set { _formstatnce = value; } } static DBOperator dbo = CStaticClass.dbo; string[] strs1 = new string[10]; string[] strs2 = new string[10]; private void FrmBarcode_Load(object sender, EventArgs e) { flash(); } public void flash() { this.treeView1.Nodes.Clear(); this.treeView2.Nodes.Clear(); DataView dv = dbo.ExceSQL("select * from T_Base_PLC_Ask n where n.F_DeviceIndex =14011").Tables[0].DefaultView; if (dv.Count > 0) { if (dv[0]["F_BarCode"] == DBNull.Value || dv[0]["F_BarCode"].ToString() == string.Empty) { } else { string F_BarCode = dv[0]["F_BarCode"].ToString(); strs1 = F_BarCode.Split('|'); for (int i = 0; i < strs1.Length; i++) { if (strs1[i] != null && strs1[i] != string.Empty) { this.treeView1.Nodes.Add(strs1[i], strs1[i]); } } } } dv = null; dv = dbo.ExceSQL("select * from T_Base_PLC_Ask n where n.F_DeviceIndex =14021").Tables[0].DefaultView; if (dv.Count > 0) { if (dv[0]["F_BarCode"] == DBNull.Value || dv[0]["F_BarCode"].ToString() == string.Empty) { } else { string F_BarCode = dv[0]["F_BarCode"].ToString(); strs2 = F_BarCode.Split('|'); for (int i = 0; i < strs2.Length; i++) { if (strs2[i] != null && strs2[i] != string.Empty) { this.treeView2.Nodes.Add(strs2[i], strs2[i]); } } } } } private void button1_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); string fbarcode = string.Empty; if (this.tabControl1.SelectedIndex == 0) { if ((this.treeView1.Nodes != null) && (this.treeView1.SelectedNode != null)) { for (int i = 0; i < this.treeView1.Nodes.Count; i++) { if (this.treeView1.Nodes[i] != this.treeView1.SelectedNode) { sb.Append(this.treeView1.Nodes[i].Text).Append("|"); } } fbarcode = sb.ToString(); dbo.ExceSQL("update T_Base_PLC_Ask set F_BarCode ='" + fbarcode + "' where F_DeviceIndex =14011"); this.treeView1.SelectedNode.Remove(); } } else { if ((this.treeView2.Nodes != null) && (this.treeView2.SelectedNode != null)) { for (int i = 0; i < this.treeView2.Nodes.Count; i++) { if (this.treeView2.Nodes[i] != this.treeView2.SelectedNode) { sb.Append(this.treeView2.Nodes[i].Text).Append("|"); } } fbarcode = sb.ToString(); dbo.ExceSQL("update T_Base_PLC_Ask set F_BarCode ='" + fbarcode + "' where F_DeviceIndex =14021"); this.treeView2.SelectedNode.Remove(); } } flash(); } private void button2_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); if (this.textBox1.Text.Trim() == string.Empty) { return; } if (this.tabControl1.SelectedIndex == 0) { for (int i = 0; i < this.treeView1.Nodes.Count; i++) { sb.Append(this.treeView1.Nodes[i].Text).Append("|"); } sb.Append(this.textBox1.Text.Trim()).Append("|"); dbo.ExceSQL("update T_Base_PLC_Ask set F_BarCode ='" + sb.ToString() + "' where F_DeviceIndex =14011"); } else { for (int i = 0; i < this.treeView2.Nodes.Count; i++) { sb.Append(this.treeView2.Nodes[i].Text).Append("|"); } sb.Append(this.textBox1.Text.Trim()).Append("|"); dbo.ExceSQL("update T_Base_PLC_Ask set F_BarCode ='" + sb.ToString() + "' where F_DeviceIndex =14021"); } this.textBox1.Text = string.Empty; flash(); } private void button3_Click(object sender, EventArgs e) { flash(); } } }