From 456beb835a50a4af6b97ffa2a4a41d0b396428be Mon Sep 17 00:00:00 2001 From: qicb Date: Mon, 22 Oct 2012 17:44:00 +0800 Subject: [PATCH] =?UTF-8?q?OK=20=E6=98=8E=E5=A4=A9=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Code/SqlHelper.cs | 4 + Application/Properties/Settings.Designer.cs | 36 ++++ Application/Properties/Settings.settings | 9 + Application/app.config | 16 ++ Application/frmAddItem.Designer.cs | 1 + Application/frmAddItem.cs | 20 +- Application/frmAddItem.resx | 3 + Application/frmAddMachine.cs | 4 +- Application/frmAddPoint.Designer.cs | 14 +- Application/frmAddPoint.cs | 20 +- Application/frmAddRoutName.cs | 2 +- Application/frmAddRoute.Designer.cs | 48 +++-- Application/frmAddRoute.cs | 220 +++++++++++++++----- 13 files changed, 303 insertions(+), 94 deletions(-) diff --git a/Application/Code/SqlHelper.cs b/Application/Code/SqlHelper.cs index fbf6af6..f668f16 100644 --- a/Application/Code/SqlHelper.cs +++ b/Application/Code/SqlHelper.cs @@ -225,6 +225,10 @@ public static int ExecuteNonQuery(string connectionString, CommandType commandTy } } + public static int RunPredure(string spName, params object[] parameterValues) + { + return ExecuteNonQuery(sqlConnectionStr,spName,parameterValues); + } /// /// 执行指定连接字符串的存储过程,将对象数组的值赋给存储过程参数, /// 此方法需要在参数缓存方法中探索参数并生成参数. diff --git a/Application/Properties/Settings.Designer.cs b/Application/Properties/Settings.Designer.cs index fc11c21..7820368 100644 --- a/Application/Properties/Settings.Designer.cs +++ b/Application/Properties/Settings.Designer.cs @@ -32,5 +32,41 @@ public sealed partial class Settings : global::System.Configuration.ApplicationS return ((string)(this["ConnectionString"])); } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool tvRoute { + get { + return ((bool)(this["tvRoute"])); + } + set { + this["tvRoute"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool tvLogicalPoint { + get { + return ((bool)(this["tvLogicalPoint"])); + } + set { + this["tvLogicalPoint"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool tvPhysicalPoint { + get { + return ((bool)(this["tvPhysicalPoint"])); + } + set { + this["tvPhysicalPoint"] = value; + } + } } } diff --git a/Application/Properties/Settings.settings b/Application/Properties/Settings.settings index b078cac..ee3fac7 100644 --- a/Application/Properties/Settings.settings +++ b/Application/Properties/Settings.settings @@ -9,5 +9,14 @@ </SerializableConnectionString> Data Source=192.168.1.221;Initial Catalog=Patrol;UserId=sa;Password=sa123 + + True + + + True + + + True + \ No newline at end of file diff --git a/Application/app.config b/Application/app.config index 165f2c7..7b647c6 100644 --- a/Application/app.config +++ b/Application/app.config @@ -1,9 +1,25 @@  + +
+ + + + + True + + + True + + + True + + + \ No newline at end of file diff --git a/Application/frmAddItem.Designer.cs b/Application/frmAddItem.Designer.cs index 34fa59a..af04904 100644 --- a/Application/frmAddItem.Designer.cs +++ b/Application/frmAddItem.Designer.cs @@ -215,6 +215,7 @@ private void InitializeComponent() this.labID.Size = new System.Drawing.Size(53, 12); this.labID.TabIndex = 20; this.labID.Text = "巡检项ID"; + this.labID.Visible = false; // // frmAddItem // diff --git a/Application/frmAddItem.cs b/Application/frmAddItem.cs index f5f626e..25b9660 100644 --- a/Application/frmAddItem.cs +++ b/Application/frmAddItem.cs @@ -19,6 +19,7 @@ public frmAddItem() private void frmAddItem_Load(object sender, EventArgs e) { + this.labID.Text = ""; getMachine(); getValueType(); getPoint(); @@ -38,7 +39,7 @@ private void btnSave_Click(object sender, EventArgs e) MessageBox.Show("请选择所属地点"); return; } - + //if(SqlHelper.ExecuteNonQuery("Select 1 From CheckItem Where ")) string str_insert = "Insert into CheckItem([Name],Alias,Machine_ID,ValueType,Phy_ID,Comment) Values(@name,@alias,@machineid,@valuetype,@pointid,@comment)"; SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@name",SqlDbType.NVarChar), @@ -136,6 +137,10 @@ private void dgvItems_CellClick(object sender, DataGridViewCellEventArgs e) private void btnUpdate_Click(object sender, EventArgs e) { + if (labID.Text == "") + { + return; + } if (cboMachine.SelectedValue.ToString() == "") { MessageBox.Show("请选择所属机器"); @@ -146,7 +151,7 @@ private void btnUpdate_Click(object sender, EventArgs e) MessageBox.Show("请选择所属地点"); return; } - + string str_insert = "Update CheckItem set [Name]=@name,Alias=@alias,Machine_ID=@machineid,ValueType=@valuetype,Phy_ID=@phyid,Comment=@comment where ID=" + labID.Text.Trim(); SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@name",SqlDbType.NVarChar), @@ -170,9 +175,8 @@ private void btnUpdate_Click(object sender, EventArgs e) } bindDgvItems(); } - private void btnDel_Click(object sender, EventArgs e) - { + { string Del = ""; string strsql = "Delete From CheckItem Where ID in("; for (int i = 0; i < dgvItems.Rows.Count; i++) @@ -193,9 +197,13 @@ private void btnDel_Click(object sender, EventArgs e) { Del = Del.Substring(0, Del.Length - 1); strsql += Del + ")"; + SqlHelper.ExecuteNonQuery(strsql); + bindDgvItems(); + } + else + { + MessageBox.Show("请选择要删除的项"); } - SqlHelper.ExecuteNonQuery(strsql); - bindDgvItems(); } } } diff --git a/Application/frmAddItem.resx b/Application/frmAddItem.resx index 64fa149..ea347e6 100644 --- a/Application/frmAddItem.resx +++ b/Application/frmAddItem.resx @@ -120,4 +120,7 @@ True + + True + \ No newline at end of file diff --git a/Application/frmAddMachine.cs b/Application/frmAddMachine.cs index 4a52c0d..2e632a0 100644 --- a/Application/frmAddMachine.cs +++ b/Application/frmAddMachine.cs @@ -43,7 +43,7 @@ private void btnSave_Click(object sender, EventArgs e) private void getArea() { - DataSet ds = SqlHelper.ExecuteDataset("select ID,Name From SiteArea"); + DataSet ds = SqlHelper.ExecuteDataset("select ID,Name From Site"); this.cboArea.DataSource = ds.Tables[0]; this.cboArea.DisplayMember = "Name"; this.cboArea.ValueMember = "ID"; @@ -57,7 +57,7 @@ private void bindDgvMachine() m.name as 设备名称, m.alias as 别名, s.name as 厂区 - from machine m,sitearea s + from machine m,site s where m.site_id=s.id"; DataSet ds = SqlHelper.ExecuteDataset(str_select); this.dgvMachine.DataSource=ds.Tables[0]; diff --git a/Application/frmAddPoint.Designer.cs b/Application/frmAddPoint.Designer.cs index 7e767e9..92fe175 100644 --- a/Application/frmAddPoint.Designer.cs +++ b/Application/frmAddPoint.Designer.cs @@ -56,7 +56,7 @@ private void InitializeComponent() // lblAlias // this.lblAlias.AutoSize = true; - this.lblAlias.Location = new System.Drawing.Point(385, 44); + this.lblAlias.Location = new System.Drawing.Point(379, 44); this.lblAlias.Name = "lblAlias"; this.lblAlias.Size = new System.Drawing.Size(29, 12); this.lblAlias.TabIndex = 1; @@ -80,7 +80,7 @@ private void InitializeComponent() // // txtAlias // - this.txtAlias.Location = new System.Drawing.Point(420, 41); + this.txtAlias.Location = new System.Drawing.Point(414, 41); this.txtAlias.Name = "txtAlias"; this.txtAlias.Size = new System.Drawing.Size(262, 21); this.txtAlias.TabIndex = 4; @@ -95,7 +95,7 @@ private void InitializeComponent() // // btnRead // - this.btnRead.Location = new System.Drawing.Point(420, 79); + this.btnRead.Location = new System.Drawing.Point(414, 79); this.btnRead.Name = "btnRead"; this.btnRead.Size = new System.Drawing.Size(75, 23); this.btnRead.TabIndex = 6; @@ -105,7 +105,7 @@ private void InitializeComponent() // // btnSave // - this.btnSave.Location = new System.Drawing.Point(420, 124); + this.btnSave.Location = new System.Drawing.Point(414, 124); this.btnSave.Name = "btnSave"; this.btnSave.Size = new System.Drawing.Size(75, 23); this.btnSave.TabIndex = 7; @@ -115,7 +115,7 @@ private void InitializeComponent() // // btnUpdate // - this.btnUpdate.Location = new System.Drawing.Point(515, 124); + this.btnUpdate.Location = new System.Drawing.Point(509, 124); this.btnUpdate.Name = "btnUpdate"; this.btnUpdate.Size = new System.Drawing.Size(75, 23); this.btnUpdate.TabIndex = 9; @@ -125,7 +125,7 @@ private void InitializeComponent() // // btnDel // - this.btnDel.Location = new System.Drawing.Point(607, 124); + this.btnDel.Location = new System.Drawing.Point(616, 124); this.btnDel.Name = "btnDel"; this.btnDel.Size = new System.Drawing.Size(75, 23); this.btnDel.TabIndex = 10; @@ -158,7 +158,7 @@ private void InitializeComponent() // labID // this.labID.AutoSize = true; - this.labID.Location = new System.Drawing.Point(513, 84); + this.labID.Location = new System.Drawing.Point(507, 84); this.labID.Name = "labID"; this.labID.Size = new System.Drawing.Size(41, 12); this.labID.TabIndex = 12; diff --git a/Application/frmAddPoint.cs b/Application/frmAddPoint.cs index 9b9df77..21d1b4a 100644 --- a/Application/frmAddPoint.cs +++ b/Application/frmAddPoint.cs @@ -19,12 +19,19 @@ public frmAddPoint() private void frmAddPoint_Load(object sender, EventArgs e) { + this.labID.Text = ""; this.btnSave.Enabled = false; getDgvPoint(); } private void btnSave_Click(object sender, EventArgs e) { + if (SqlHelper.ExecuteNonQuery("Select Count(1) From PhysicalCheckPoint Where [Name]='" + this.txtName.Text.Trim() + "'") > 0) + { + MessageBox.Show("已存在巡检点名称,"); + this.txtName.Focus(); + return; + } SqlParameter[] pars = new SqlParameter[] { new SqlParameter("@name",SqlDbType.NVarChar), new SqlParameter("@alias",SqlDbType.NVarChar), @@ -78,11 +85,14 @@ private void dgvPoint_CellClick(object sender, DataGridViewCellEventArgs e) txtName.Text = dgvPoint.Rows[e.RowIndex].Cells[2].Value.ToString(); txtAlias.Text = dgvPoint.Rows[e.RowIndex].Cells[3].Value.ToString(); txtRelation.Text = dgvPoint.Rows[e.RowIndex].Cells[4].Value.ToString(); + } } private void btnUpdate_Click(object sender, EventArgs e) { + if (labID.Text == "") + return; SqlParameter[] pars = new SqlParameter[] { new SqlParameter("@name",SqlDbType.NVarChar), new SqlParameter("@alias",SqlDbType.NVarChar), @@ -108,7 +118,7 @@ private void btnUpdate_Click(object sender, EventArgs e) private void btnDel_Click(object sender, EventArgs e) { string Del = ""; - string strsql = "Delete From Machine Where ID in("; + string strsql = "Delete From PhysicalCheckPoint Where ID in("; for (int i = 0; i < dgvPoint.Rows.Count; i++) { try @@ -127,9 +137,13 @@ private void btnDel_Click(object sender, EventArgs e) { Del = Del.Substring(0, Del.Length - 1); strsql += Del + ")"; + SqlHelper.ExecuteNonQuery(strsql); + getDgvPoint(); } - SqlHelper.ExecuteNonQuery(strsql); - getDgvPoint(); + else + { + MessageBox.Show("请选择要删除的项。"); + } } } diff --git a/Application/frmAddRoutName.cs b/Application/frmAddRoutName.cs index d8c279a..8dfb2d8 100644 --- a/Application/frmAddRoutName.cs +++ b/Application/frmAddRoutName.cs @@ -21,7 +21,7 @@ public frmAddRoutName(ref TreeView tr) private void frmAddRoutName_Load(object sender, EventArgs e) { - DataSet ds = SqlHelper.ExecuteDataset("Select Id,Name From SiteArea"); + DataSet ds = SqlHelper.ExecuteDataset("Select Id,Name From Site"); cboSiteArea.DataSource=ds.Tables[0]; cboSiteArea.DisplayMember = "Name"; cboSiteArea.ValueMember = "ID"; diff --git a/Application/frmAddRoute.Designer.cs b/Application/frmAddRoute.Designer.cs index 5d21f36..efbfe85 100644 --- a/Application/frmAddRoute.Designer.cs +++ b/Application/frmAddRoute.Designer.cs @@ -35,10 +35,10 @@ private void InitializeComponent() this.chkRoute = new System.Windows.Forms.CheckBox(); this.tvRoute = new System.Windows.Forms.TreeView(); this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.labRouteID = new System.Windows.Forms.Label(); this.btnAddTemplate = new System.Windows.Forms.Button(); this.chkPhysicalPoint = new System.Windows.Forms.CheckBox(); this.chkLogicalPoint = new System.Windows.Forms.CheckBox(); - this.chkShowPyPoint = new System.Windows.Forms.CheckBox(); this.tvPhysicalPoint = new System.Windows.Forms.TreeView(); this.label2 = new System.Windows.Forms.Label(); this.tbRoute = new System.Windows.Forms.TextBox(); @@ -77,6 +77,7 @@ private void InitializeComponent() this.删除路线ToolStripMenuItem.Name = "删除路线ToolStripMenuItem"; this.删除路线ToolStripMenuItem.Size = new System.Drawing.Size(65, 20); this.删除路线ToolStripMenuItem.Text = "删除路线"; + this.删除路线ToolStripMenuItem.Click += new System.EventHandler(this.删除路线ToolStripMenuItem_Click); // // groupBox1 // @@ -92,12 +93,15 @@ private void InitializeComponent() // chkRoute // this.chkRoute.AutoSize = true; + this.chkRoute.Checked = true; + this.chkRoute.CheckState = System.Windows.Forms.CheckState.Checked; this.chkRoute.Location = new System.Drawing.Point(93, 458); this.chkRoute.Name = "chkRoute"; this.chkRoute.Size = new System.Drawing.Size(72, 16); this.chkRoute.TabIndex = 1; this.chkRoute.Text = "自动展开"; this.chkRoute.UseVisualStyleBackColor = true; + this.chkRoute.CheckedChanged += new System.EventHandler(this.chkRoute_CheckedChanged); // // tvRoute // @@ -109,10 +113,10 @@ private void InitializeComponent() // // groupBox2 // + this.groupBox2.Controls.Add(this.labRouteID); this.groupBox2.Controls.Add(this.btnAddTemplate); this.groupBox2.Controls.Add(this.chkPhysicalPoint); this.groupBox2.Controls.Add(this.chkLogicalPoint); - this.groupBox2.Controls.Add(this.chkShowPyPoint); this.groupBox2.Controls.Add(this.tvPhysicalPoint); this.groupBox2.Controls.Add(this.label2); this.groupBox2.Controls.Add(this.tbRoute); @@ -130,6 +134,16 @@ private void InitializeComponent() this.groupBox2.TabStop = false; this.groupBox2.Text = "路线巡检点设置"; // + // labRouteID + // + this.labRouteID.AutoSize = true; + this.labRouteID.Location = new System.Drawing.Point(273, 31); + this.labRouteID.Name = "labRouteID"; + this.labRouteID.Size = new System.Drawing.Size(41, 12); + this.labRouteID.TabIndex = 18; + this.labRouteID.Text = "路线ID"; + this.labRouteID.Visible = false; + // // btnAddTemplate // this.btnAddTemplate.Location = new System.Drawing.Point(202, 82); @@ -142,32 +156,28 @@ private void InitializeComponent() // chkPhysicalPoint // this.chkPhysicalPoint.AutoSize = true; - this.chkPhysicalPoint.Location = new System.Drawing.Point(293, 458); + this.chkPhysicalPoint.Checked = true; + this.chkPhysicalPoint.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkPhysicalPoint.Location = new System.Drawing.Point(338, 458); this.chkPhysicalPoint.Name = "chkPhysicalPoint"; this.chkPhysicalPoint.Size = new System.Drawing.Size(72, 16); this.chkPhysicalPoint.TabIndex = 16; this.chkPhysicalPoint.Text = "自动展开"; this.chkPhysicalPoint.UseVisualStyleBackColor = true; + this.chkPhysicalPoint.CheckedChanged += new System.EventHandler(this.chkPhysicalPoint_CheckedChanged); // // chkLogicalPoint // this.chkLogicalPoint.AutoSize = true; + this.chkLogicalPoint.Checked = true; + this.chkLogicalPoint.CheckState = System.Windows.Forms.CheckState.Checked; this.chkLogicalPoint.Location = new System.Drawing.Point(50, 458); this.chkLogicalPoint.Name = "chkLogicalPoint"; this.chkLogicalPoint.Size = new System.Drawing.Size(72, 16); this.chkLogicalPoint.TabIndex = 15; this.chkLogicalPoint.Text = "自动展开"; this.chkLogicalPoint.UseVisualStyleBackColor = true; - // - // chkShowPyPoint - // - this.chkShowPyPoint.AutoSize = true; - this.chkShowPyPoint.Location = new System.Drawing.Point(371, 458); - this.chkShowPyPoint.Name = "chkShowPyPoint"; - this.chkShowPyPoint.Size = new System.Drawing.Size(108, 16); - this.chkShowPyPoint.TabIndex = 14; - this.chkShowPyPoint.Text = "显示所有巡检点"; - this.chkShowPyPoint.UseVisualStyleBackColor = true; + this.chkLogicalPoint.CheckedChanged += new System.EventHandler(this.chkLogicalPoint_CheckedChanged); // // tvPhysicalPoint // @@ -176,15 +186,16 @@ private void InitializeComponent() this.tvPhysicalPoint.Size = new System.Drawing.Size(197, 396); this.tvPhysicalPoint.TabIndex = 13; this.tvPhysicalPoint.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.tvPhysicalPoint_BeforeSelect); + this.tvPhysicalPoint.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tvPhysicalPoint_NodeMouseDoubleClick); // // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(323, 29); + this.label2.Location = new System.Drawing.Point(336, 31); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(89, 12); + this.label2.Size = new System.Drawing.Size(41, 12); this.label2.TabIndex = 12; - this.label2.Text = "未选择的巡检点"; + this.label2.Text = "巡检点"; // // tbRoute // @@ -210,7 +221,7 @@ private void InitializeComponent() this.tvLogicalPoint.Size = new System.Drawing.Size(189, 396); this.tvLogicalPoint.TabIndex = 9; this.tvLogicalPoint.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.tvLogicalPoint_BeforeSelect); - this.tvLogicalPoint.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvLogicalPoint_AfterSelect); + this.tvLogicalPoint.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.tvLogicalPoint_NodeMouseDoubleClick); // // btnSave // @@ -273,6 +284,7 @@ private void InitializeComponent() this.MainMenuStrip = this.menuStrip1; this.Name = "frmAddRoute"; this.Text = "新建巡检路线"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmAddRoute_FormClosing); this.Load += new System.EventHandler(this.frmAddRoute_Load); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); @@ -302,12 +314,12 @@ private void InitializeComponent() private System.Windows.Forms.Button btnAddTemplate; private System.Windows.Forms.CheckBox chkPhysicalPoint; private System.Windows.Forms.CheckBox chkLogicalPoint; - private System.Windows.Forms.CheckBox chkShowPyPoint; private System.Windows.Forms.TreeView tvPhysicalPoint; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox tbRoute; private System.Windows.Forms.Label label1; private System.Windows.Forms.TreeView tvLogicalPoint; + private System.Windows.Forms.Label labRouteID; } diff --git a/Application/frmAddRoute.cs b/Application/frmAddRoute.cs index e7b831f..2d6ad3c 100644 --- a/Application/frmAddRoute.cs +++ b/Application/frmAddRoute.cs @@ -16,6 +16,7 @@ public frmAddRoute() { InitializeComponent(); } + WorkStation.Properties.Settings wset = new Properties.Settings(); Boolean isRoute = false;//是否选中了路线 List listPhy = new List(); @@ -23,24 +24,45 @@ public frmAddRoute() private void frmAddRoute_Load(object sender, EventArgs e) { tvRouteInit(tvRoute); - tvRoute.ExpandAll(); + if (isRoute == true&&tbRoute.Text!="") { getTvLogicalPoint(tbRoute.Text.Trim()); } getTvPhysicalPoint(); + + //chkRoute.Checked = wset.tvRoute; + //chkLogicalPoint.Checked = wset.tvLogicalPoint; + //chkPhysicalPoint.Checked = wset.tvPhysicalPoint; + + //if (wset.tvRoute) tvRoute.ExpandAll(); else tvRoute.CollapseAll(); + //if (wset.tvPhysicalPoint) tvPhysicalPoint.ExpandAll(); else tvPhysicalPoint.CollapseAll(); + //if (wset.tvLogicalPoint) tvLogicalPoint.ExpandAll(); else tvLogicalPoint.CollapseAll(); } private void tvRoute_AfterSelect(object sender, TreeViewEventArgs e) { - if (tvRoute.SelectedNode.Nodes.Count == 0&&tvRoute.SelectedNode.Level==2) + if (tvRoute.SelectedNode.Nodes.Count == 0 && tvRoute.SelectedNode.Level == 2) { getTvLogicalPoint(tvRoute.SelectedNode.Tag.ToString()); + tbRoute.Text = tvRoute.SelectedNode.Text; + labRouteID.Text = tvRoute.SelectedNode.Tag.ToString() ; + } + else + { + tbRoute.Text = ""; + labRouteID.Text = ""; + tvLogicalPoint.Nodes.Clear(); } } private void btnAdd_Click(object sender, EventArgs e) { + if (labRouteID.Text == "" && tbRoute.Text == "") + { + MessageBox.Show("请选择路线"); + return; + } foreach (TreeNode node in listPhy) { if (node.Parent != null) //node有上级 @@ -48,12 +70,12 @@ private void btnAdd_Click(object sender, EventArgs e) bool isExit = false; foreach (TreeNode no in tvLogicalPoint.Nodes) { - if (no.Parent == null && no.Tag == node.Parent.Tag) //如果存在node的上级 + if (no.Parent == null && no.Tag.ToString() == node.Parent.Tag.ToString()) //如果存在node的上级 { bool isChild = false; foreach (TreeNode t in no.Nodes) { - if (t.Tag == node.Tag && t.Text == node.Text) + if (t.Tag.ToString() == node.Tag.ToString() && t.Text == node.Text) { isChild = true; break; } @@ -80,7 +102,7 @@ private void btnAdd_Click(object sender, EventArgs e) bool isExitNode = false; foreach (TreeNode no in tvLogicalPoint.Nodes) { - if (no.Parent == null && no.Tag == node.Tag) + if (no.Parent == null && no.Tag.ToString() == node.Tag.ToString()) { isExitNode = true; break; @@ -102,13 +124,26 @@ private void btnDel_Click(object sender, EventArgs e) { foreach (TreeNode node in listLogical) { + if (node.Parent == null) + { + Object obj_ID= SqlHelper.ExecuteScalar("Select ID From LogicalCheckPoint Where Route_ID=" + labRouteID.Text + " and PhysicalPoint_ID=" + node.Tag); + SqlHelper.ExecuteNonQuery("Delete From LogicalCheckPoint where ID=" + obj_ID.ToString()); + if (node.Nodes.Count > 0) + { + foreach (TreeNode de in node.Nodes) + { + SqlHelper.ExecuteNonQuery("Delete From LogicalPoint_Item Where ID="+obj_ID.ToString()); + } + } + } tvLogicalPoint.Nodes.Remove(node); } } private void btnMoveUp_Click(object sender, EventArgs e) { - TreeNode selnode = tvLogicalPoint.SelectedNode; + TreeNode selnode = listLogical[0]; + if (selnode.Parent != null) { selnode = selnode.Parent; @@ -130,60 +165,73 @@ private void btnMoveUp_Click(object sender, EventArgs e) private void btnMoveDown_Click(object sender, EventArgs e) { - TreeNode selnode = tvLogicalPoint.SelectedNode; - if (selnode.Parent != null) + TreeNode selnode = listLogical[0]; + if (selnode.Parent != null) + { + selnode = selnode.Parent; + } + TreeNode nextnode = selnode.NextNode; + TreeNode newnode = selnode.Clone() as TreeNode; + if (nextnode != null) + { + tvLogicalPoint.Nodes.Insert(nextnode.Index+1, newnode); + selnode.Remove(); + tvLogicalPoint.SelectedNode = newnode; + } + else + { + MessageBox.Show("已经到底"); return; + } + } + + private void btnSave_Click(object sender, EventArgs e) + { + foreach (TreeNode node in tvLogicalPoint.Nodes) { - selnode = selnode.Parent; + if (node.Level == 0 && node.Nodes.Count == 0) + { + MessageBox.Show("请确保每个巡检点下有巡检项"); + return; + } } - TreeNode nextnode = selnode.NextNode; - TreeNode newnode = selnode.Clone() as TreeNode; - if (nextnode != null) + string route_id = ""; + if (labRouteID.Text!="") { - tvLogicalPoint.Nodes.Insert(nextnode.Index, newnode); - selnode.Remove(); - tvLogicalPoint.SelectedNode = newnode; + route_id = tvRoute.SelectedNode.Tag.ToString(); } else { - MessageBox.Show("已经到底"); return; + MessageBox.Show("请选择要保存的路线"); + return; } - } + string strs=""; + for (int i = 0; i < tvLogicalPoint.Nodes.Count; i++) + { + if (tvLogicalPoint.Nodes[i].Level == 0) + { + SqlParameter[] pars = new SqlParameter[] { + new SqlParameter("@Route_ID",SqlDbType.BigInt), + new SqlParameter("@PhysicalPoint_ID",SqlDbType.BigInt), + new SqlParameter("@Name",SqlDbType.VarChar), + new SqlParameter("@Alias",SqlDbType.VarChar), + new SqlParameter("@ItemsID",SqlDbType.VarChar) + }; + pars[0].Value = labRouteID.Text; + pars[1].Value = tvLogicalPoint.Nodes[i].Tag; + pars[2].Value = tvLogicalPoint.Nodes[i].Text; + pars[3].Value = ""; - private void btnSave_Click(object sender, EventArgs e) - { - //string route_id=""; - //if (tvRoute.SelectedNode.Level == 2 && tvRoute.SelectedNode.Nodes.Count == 0) - //{ - // route_id = tvRoute.SelectedNode.Tag.ToString(); - //} - //else - //{ - // MessageBox.Show("请选择要保存的路线"); - // return; - //} - //string[] strSqls=null; - //if (lstRoutePoint.Items.Count > 0) - //{ - // strSqls = new string[lstRoutePoint.Items.Count]; - //} - //else - //{ - // MessageBox.Show("请往路线中添加巡检点"); - // return; - //} - //for (int i = 0; i < lstRoutePoint.Items.Count; i++) - //{ - // BoxItem obj = (BoxItem)lstRoutePoint.Items[i]; - // strSqls[i] = "Insert Into LogicalCheckPoint(Route_ID,PhysicalPoint_ID) values("+route_id+","+obj.Value+")"; - //} - //try - //{ - // int _ret = SqlHelper.ExecuteSqls(strSqls); - //} - //catch - //{ - // MessageBox.Show("保存失败,请稍后再试"); - //} + string parValue = ""; + foreach (TreeNode node in tvLogicalPoint.Nodes[i].Nodes) + { + parValue += node.Tag + ","; + } + pars[4].Value = parValue; + + int _ret= SqlHelper.RunPredure("LogicalPointItemControl", pars); + } + + } } @@ -197,14 +245,14 @@ private void 新建路线ToolStripMenuItem_Click(object sender, EventArgs e) private void getTvLogicalPoint(string route_id) { tvLogicalPoint.Nodes.Clear(); - SqlDataReader dr = SqlHelper.ExecuteReader("Select ID,Name From LogicalCheckPoint where route_ID=" + route_id); + SqlDataReader dr = SqlHelper.ExecuteReader("Select PhysicalPoint_ID,Name,ID From LogicalCheckPoint where route_ID=" + route_id); if (dr == null) return; while (dr.Read()) { TreeNode tnode = new TreeNode(); tnode.Text = dr["Name"].ToString(); - tnode.Tag = dr["ID"].ToString(); - tnode = tvNodeAdd(tnode, "select l.ID,c.[Name] from LogicalPoint_Item l ,CheckItem c where l.Item_ID=c.ID and l.ID="+dr["ID"].ToString().Trim()); + tnode.Tag = dr["PhysicalPoint_ID"].ToString(); + tnode = tvNodeAdd(tnode, "select l.ID as LIID,c.[Name],c.ID from LogicalPoint_Item l ,CheckItem c where l.Item_ID=c.ID and l.ID="+dr["ID"].ToString().Trim()); tvLogicalPoint.Nodes.Add(tnode); } @@ -235,13 +283,14 @@ public static void tvRouteInit(TreeView tvRoute) TreeNode tnode = new TreeNode(); tnode.Text = dr["Name"].ToString(); tnode.Tag = dr["ID"].ToString(); - tnode = tvNodeAdd(tnode, "select ID,Name from SiteArea where Company_ID='" + dr["ID"].ToString() + "'"); + tnode = tvNodeAdd(tnode, "select ID,Name from Site where Company_ID='" + dr["ID"].ToString() + "'"); for (int i = 0; i < tnode.Nodes.Count; i++) { (tnode.Nodes)[i] = tvNodeAdd((tnode.Nodes)[i], "Select ID,Name from CheckRoute Where site_id=" + (tnode.Nodes)[i].Tag); } tvRoute.Nodes.Add(tnode); } + tvRoute.ExpandAll(); dr.Close(); } @@ -334,9 +383,66 @@ public void ClearSelectedNode(TreeView tv,TreeNode tr) } } - private void tvLogicalPoint_AfterSelect(object sender, TreeViewEventArgs e) + private void tvLogicalPoint_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) + { + MessageBox.Show(e.Node.Text); + listLogical.Clear(); + listLogical.Add(e.Node); + PaintSelectedNode(tvLogicalPoint, listLogical); + } + + private void tvPhysicalPoint_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) + { + MessageBox.Show(e.Node.Text); + listPhy.Clear(); + listPhy.Add(e.Node); + PaintSelectedNode(tvPhysicalPoint, listPhy); + } + + private void 删除路线ToolStripMenuItem_Click(object sender, EventArgs e) + { + if (tvRoute.SelectedNode.Level != 2) + { + MessageBox.Show("请选择具体路线"); + return; + } + string strDel = "Delete From CheckRoute Where ID="+tvRoute.SelectedNode.Tag; + if (SqlHelper.ExecuteNonQuery(strDel) != 1) + { + MessageBox.Show("删除失败"); + return; + } + else + { + tvRouteInit(tvRoute); + } + } + + private void chkRoute_CheckedChanged(object sender, EventArgs e) { + wset.tvRoute = wset.tvRoute == true ? false : true; + if (wset.tvRoute) tvRoute.ExpandAll(); else tvRoute.CollapseAll(); + chkRoute.Checked = wset.tvRoute; + } + private void chkLogicalPoint_CheckedChanged(object sender, EventArgs e) + { + wset.tvLogicalPoint = wset.tvLogicalPoint == true ? false : true; + if (wset.tvLogicalPoint) tvLogicalPoint.ExpandAll(); else tvLogicalPoint.CollapseAll(); + chkLogicalPoint.Checked = wset.tvLogicalPoint; + } + + private void chkPhysicalPoint_CheckedChanged(object sender, EventArgs e) + { + //wset.tvPhysicalPoint = wset.tvPhysicalPoint == true ? false : true; + //if (wset.tvPhysicalPoint) tvPhysicalPoint.ExpandAll(); else tvPhysicalPoint.CollapseAll(); + //chkPhysicalPoint.Checked = wset.tvPhysicalPoint; } + + private void frmAddRoute_FormClosing(object sender, FormClosingEventArgs e) + { + wset.Save(); + } + } }