private void button1_Click(object sender, EventArgs e) { string text = textBox2.Text.Trim(); if (text == string.Empty) { MessageBox.Show("节点标识不能为空!"); return; } string name = textBox3.Text.Trim(); if (name == string.Empty) { MessageBox.Show("节点名称不能为空!"); return; } int imageindex = Convert.ToInt32(comboBox1.SelectedIndex); int selectedimageindex = Convert.ToInt32(comboBox2.SelectedIndex); int parentid = Convert.ToInt32(parentnode.Tag); int afternode = Convert.ToInt32(comboBox3.SelectedIndex); if (afternode == -1) { MessageBox.Show("请选择新增节点的后节点!"); return; } if (Convert.ToInt32(comboBox3.SelectedIndex) != (comboBox3.Items.Count - 1))//如果该节点不是添加到最后 { TreeNodes.UpdateParentIndexAdd(parentid, afternode); } string sql = "insert into treenodes_tab t (t.name,t.text,t.imageindex,t.selectedimageindex,t.parent_id,t.flag,t.parent_index) values ('" + name + "','" + text + "'," + imageindex + "," + selectedimageindex + "," + parentid + ",'" + flag + "'," + afternode + ")"; User.UpdateCon(sql, DataAccess.OIDSConnStr); if (flag == "Y") { int n = 0; for (int i = 0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.GetItemChecked(i)) { n++; checkedListBox1.SetSelected(i, true); int privilegeid = Convert.ToInt32(checkedListBox1.SelectedValue); string sqlstr = "insert into privilege_node_tab t ( t.privilege_id,t.node_id) values (" + privilegeid + ",(select max(d.id) from treenodes_tab d))";//添加该节点的权限设置关系 User.UpdateCon(sqlstr, DataAccess.OIDSConnStr); SetPrivilegetoParentnode(privilegeid, parentid); } } if (n == 0) { MessageBox.Show("请选择权限!", "提示信息", MessageBoxButtons.OK); return; } MessageBox.Show("添加节点成功!"); } else { MessageBox.Show("添加节点成功!"); } this.add_setreload(); }