private void btn_TreeNode_Click(object sender, EventArgs e) { frmTree frm = new frmTree(); if (frm.ShowDialog() == DialogResult.OK) { string strPID = frm.SelectedID; string strSQL = string.Format("select * from {0} where pid='{1}'", m_strTableNameDict, strPID); try { DataSet dtSet = DbHelperOra.Query(DbHelperOra.connectionString_172, strSQL); DataTable dtTable = dtSet.Tables[0]; m_treeListItems = new List <csListItemObject>(); foreach (DataRow dr in dtTable.Rows) { string strID = string.Format("{0}", dr[0]); string strBM = string.Format("{0}", dr[1]); string strName = string.Format("{0}", dr[2]); //string strPID = string.Format("{0}", dr[3]); string strZBLX = string.Format("{0}", dr[4]); string strSTable = string.Format("{0}", dr[5]); string strSUnit = string.Format("{0}", dr[6]); csTreeNodeTag csTNT = new csTreeNodeTag(strID, strName, strBM, strPID, strZBLX, strSTable, strSUnit); csListItemObject csLIO = new csListItemObject(strName, csTNT); m_treeListItems.Add(csLIO); } checkedListBox_Tree.DataSource = m_treeListItems; checkedListBox_Tree.DisplayMember = "Name"; checkedListBox_Tree.ValueMember = "TreeNodeTag"; } catch {} } }
private void Tree_ModifyItem_Click(object sender, EventArgs e) { csTreeNodeTag csTNT = m_selTreeNode.Tag as csTreeNodeTag; if (csTNT != null) { frmSettingInfo frm = new frmSettingInfo(); frm.SetStatsInfo(csTNT, 2); if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { csTreeNodeTag newTNT = frm.GetStatsInfo(); //更新记录 string strSQL = string.Format("update {0} set (ID,ZBBM,ZBMC,PID,ZBLX,STATS_TABLE,STATS_UNIT) = ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'))", m_strTableName, newTNT.strID, newTNT.strBM, newTNT.strName, newTNT.strPID, newTNT.strZBLX, newTNT.strSTATSTable, newTNT.strShowUnit); if (DbHelperOra.ExecuteSql(DbHelperOra.connectionString_172, strSQL) > 0) { //TreeNode tNode = m_selTreeNode.Nodes.Add(newTNT.strName); m_selTreeNode.Tag = newTNT; } } } }
private void InsertIntoTree(DataRow dr) { if (dr != null) { try { string strID = string.Format("{0}", dr[0]); string strBM = string.Format("{0}", dr[1]); string strName = string.Format("{0}", dr[2]); string strPID = string.Format("{0}", dr[3]); string strZBLX = string.Format("{0}", dr[4]); string strSTable = string.Format("{0}", dr[5]); string strSUnit = string.Format("{0}", dr[6]); csTreeNodeTag csTNT = new csTreeNodeTag(strID, strName, strBM, strPID, strZBLX, strSTable, strSUnit); TreeNode parent_tn = GetTreeNodeByID(csTNT.strPID); if (parent_tn != null) { TreeNode tn = parent_tn.Nodes.Add(csTNT.strName); tn.Tag = csTNT; } else { TreeNode tn = ctrlTree_Stats.Nodes.Add(csTNT.strName); tn.Tag = csTNT; } } catch { } } }
private void Tree_AddItem_Click(object sender, EventArgs e) { csTreeNodeTag csTNT = m_selTreeNode.Tag as csTreeNodeTag; if (csTNT != null) { frmSettingInfo frm = new frmSettingInfo(); frm.SetStatsInfo(csTNT, 3); frm.SetNewBM(GetNewBM()); if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { csTreeNodeTag newTNT = frm.GetStatsInfo(); //添加记录到数据库中 string strSQL = string.Format("insert into {0} values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", m_strTableName, newTNT.strID, newTNT.strBM, newTNT.strName, newTNT.strPID, newTNT.strZBLX, newTNT.strSTATSTable, newTNT.strShowUnit); if (DbHelperOra.ExecuteSql(DbHelperOra.connectionString_172, strSQL) > 0) { TreeNode tNode = m_selTreeNode.Nodes.Add(newTNT.strName); tNode.Tag = newTNT; } } } }
private TreeNode GetTreeNodeByID(TreeNode pNode, string strID) { TreeNode tNode = null; { csTreeNodeTag csTNT = pNode.Tag as csTreeNodeTag; if (csTNT.strID == strID) { tNode = pNode; } } if (tNode == null) { //寻找其子节点 foreach (TreeNode tn in pNode.Nodes) { csTreeNodeTag csTNT = tn.Tag as csTreeNodeTag; if (csTNT.strID == strID) { tNode = tn; break; } if (tn.Nodes.Count > 0) { tNode = GetTreeNodeByID(tn, strID); } } } return(tNode); }
private void ctrlTree_Stats_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { //左键双击 if (e.Node != null && e.Button == System.Windows.Forms.MouseButtons.Left) { //选中某个项,进行匹配处理 csTreeNodeTag csTNT = e.Node.Tag as csTreeNodeTag; m_strSelectedID = csTNT.strID; this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } }
public csTreeNodeTag GetStatsInfo() { m_csTNT = new csTreeNodeTag(); m_csTNT.strID = textBox_ID.Text; m_csTNT.strName = textBox_MC.Text; m_csTNT.strBM = textBox_BM.Text; m_csTNT.strPID = textBox_PID.Text; m_csTNT.strShowUnit = textBox_SUnit.Text; m_csTNT.strSTATSTable = comboBox_STable.Text; m_csTNT.strZBLX = comboBox_ZBLX.Text; return(m_csTNT); }
private void Tree_DeleteItem_Click(object sender, EventArgs e) { csTreeNodeTag csTNT = m_selTreeNode.Tag as csTreeNodeTag; if (csTNT != null) { //执行删除节点和数据库记录的操作 string strSQL = string.Format("delete {0} where id='{1}'", m_strTableName, csTNT.strID); if (DbHelperOra.ExecuteSql(DbHelperOra.connectionString_172, strSQL) > 0) { m_selTreeNode.Remove(); m_selTreeNode = null; } } }
private void Tree_ViewItem_Click(object sender, EventArgs e) { if (m_selTreeNode != null) { csTreeNodeTag csTNT = m_selTreeNode.Tag as csTreeNodeTag; if (csTNT != null) { frmSettingInfo frm = new frmSettingInfo(); frm.SetStatsInfo(csTNT, 1); if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { } } } }
/// <summary> /// 设置节点对象 /// </summary> /// <param name="csTNT">节点对象</param> /// <param name="iType">1表示查看,2表示编辑,3表示添加</param> public void SetStatsInfo(csTreeNodeTag csTNT, int iType) { if (iType == 1) { if (csTNT != null) { this.textBox_BM.Text = csTNT.strBM; this.textBox_ID.Text = csTNT.strID; this.textBox_MC.Text = csTNT.strName; this.textBox_PID.Text = csTNT.strPID; this.textBox_SUnit.Text = csTNT.strShowUnit; //设置映射表 this.comboBox_STable.Text = csTNT.strSTATSTable; //设置指标类型 this.comboBox_ZBLX.Text = csTNT.strZBLX; this.button_OK.Enabled = this.button_Cancel.Enabled = false; } } else if (iType == 2) { if (csTNT != null) { this.textBox_BM.Text = csTNT.strBM; this.textBox_ID.Text = csTNT.strID; this.textBox_MC.Text = csTNT.strName; this.textBox_PID.Text = csTNT.strPID; this.textBox_SUnit.Text = csTNT.strShowUnit; //设置映射表 this.comboBox_STable.Text = csTNT.strSTATSTable; //设置指标类型 this.comboBox_ZBLX.Text = csTNT.strZBLX; this.button_OK.Enabled = this.button_Cancel.Enabled = true; } } else if (iType == 3) { this.textBox_ID.Text = Guid.NewGuid().ToString("N").ToUpper(); this.textBox_PID.Text = csTNT.strID; this.textBox_BM.Text = ""; this.button_OK.Enabled = this.button_Cancel.Enabled = true; } }