private void TNodeDel_Click(object sender, EventArgs e) { TreeNode tn = treeView.SelectedNode; if (tn.Tag.ToString().Length / 2 == 1) { MessageBox.Show("不能删除根节点"); return; } else { if (MessageBox.Show("是否要删除该节点?", "确定", MessageBoxButtons.OKCancel) == DialogResult.OK) { tTableDiffcult db = new tTableDiffcult(); if (db.Delete(Convert.ToInt32(tn.Tag))) { MessageBox.Show("删除节点成功"); } else { MessageBox.Show("删除节点失败"); } } update(); } }
private void treeView_DoubleClick(object sender, EventArgs e) { TreeNode tn = treeView.SelectedNode; tTableDiffcult db = new tTableDiffcult(); DataTable dt = db.Select(Convert.ToInt32(tn.Tag)); MessageBox.Show(string.Format("节点名称:{0}\r\n节点层级:{1}\r\n节点备注:{2}\r\n", dt.Rows[0]["fName"], dt.Rows[0]["fid"].ToString().Length / 2 - 1, dt.Rows[0]["fRemark"])); treeView.ExpandAll(); }
private void btnOK_Click(object sender, EventArgs e) { tTableDiffcult db = new tTableDiffcult(); if (op.Equals("Add")) { int fid = Convert.ToInt32(tn.Tag) * 100 + tn.Nodes.Count; db.Insert(fid, txtBox_fName.Text, txtBox_fRemark.Text); } else if (op.Equals("Edit")) { db.updateByID(Convert.ToInt32(tn.Tag), txtBox_fName.Text, txtBox_fRemark.Text); } this.Hide(); }
public FormDetail(TreeNode tn, string op) { InitializeComponent(); this.tn = tn; this.op = op; if (op.Equals("Add")) { } else if (op.Equals("Edit")) { tTableDiffcult db = new tTableDiffcult(); DataTable dt = db.Select(Convert.ToInt32(tn.Tag)); btnOK.Text = "修改"; txtBox_fName.Text = dt.Rows[0]["fName"].ToString(); txtBox_fRemark.Text = dt.Rows[0]["fRemark"].ToString(); } }
private void update() { listNode.Clear(); treeView.Nodes.Clear(); tTableDiffcult db = new tTableDiffcult(); DataTable dt = db.SelectAll(); foreach (DataRow row in dt.Rows) { TreeNode tn = new TreeNode(row["fName"].ToString()); tn.Tag = row["fid"].ToString(); listNode.Add(tn); if (tn.Tag.ToString().Length / 2 == 1) { treeView.Nodes.Add(tn); } else { foreach (TreeNode tmpTn in listNode) { if (tmpTn.Tag.ToString().Equals(tn.Tag.ToString().Substring(0, tn.Tag.ToString().Length - 2))) { tmpTn.Nodes.Add(tn); break; } } } } treeView.ExpandAll(); }