private void btn_modify_Click(object sender, EventArgs e) { string typename = tb_TypeName.Text.Trim(); if (typename.Length == 0) { MessageBox.Show("错误:您必须输入类型名称"); return; } if (hasTypeWithOutSelectedItemName(typename, treeView1.SelectedNode)) { MessageBox.Show("错误:该类型名已经存在"); return; } TreeNode modifyWhere = null; if (treeView1.SelectedNode != null) { var i = treeView1.SelectedNode.Tag as DisableGetObjects.IConfigSwitchOrGroup; modifyWhere = treeView1.SelectedNode; } else { MessageBox.Show("请先选定待修改项"); return; } if (cb_itemType.SelectedItem == null) { MessageBox.Show("无效类型"); return; } DisableGetObjects.IConfigSwitchOrGroup icsg; DisableGetObjects.TypeOfSwitchOrGroup typeofnewitem = (DisableGetObjects.TypeOfSwitchOrGroup)cb_itemType.SelectedItem; if (typeofnewitem == DisableGetObjects.TypeOfSwitchOrGroup.分组) { icsg = new DisableGetObjects.Setting_Type_Group { Name = tb_TypeName.Text, //ItemList = new List<DisableGetObjects.IConfigSwitchOrGroup>() }; } else { if (cb_switchType.SelectedItem == null) { MessageBox.Show("请选择交换机类型"); return; } icsg = new DisableGetObjects.Setting_Type_Switch { Name = tb_TypeName.Text, Password = tb_password.Text, UserName = tb_username.Text, IpAddress = tb_IPAddress.Text, EnablePassword = tb_enablePassword.Text, EnableUsername = tb_enableUsername.Text, SwitchTypeNameBelongTo = (cb_switchType.SelectedItem as DisableGetObjects.Setting_SwitchType).SwitchTypeName }; } var t = modifyWhere.Tag as DisableGetObjects.IConfigSwitchOrGroup; if (t.IfHaveNextItems() && icsg.GetTypeOfThisItem() == DisableGetObjects.TypeOfSwitchOrGroup.交换机) { MessageBox.Show("有子项的分组项不能被修改为交换机"); return; } if (t.IfHaveNextItems()) { foreach (var tmp in t.NextItems()) { icsg.AddSubItem(tmp); } } findAndReplaceInData(t, icsg); flushTreeViewItems(); }
private void btn_add_Click(object sender, EventArgs e) { string typename = tb_TypeName.Text.Trim(); if (typename.Length == 0) { MessageBox.Show("错误:您必须输入类型名称"); return; } if (hasTypeName(typename)) { MessageBox.Show("错误:该类型名已经存在"); return; } TreeNode addToWhere = null; if (treeView1.SelectedNode != null) { var i = treeView1.SelectedNode.Tag as DisableGetObjects.IConfigSwitchOrGroup; if (i.GetTypeOfThisItem() == DisableGetObjects.TypeOfSwitchOrGroup.交换机) { addToWhere = treeView1.SelectedNode.Parent; } else { addToWhere = treeView1.SelectedNode; } } if (cb_itemType.SelectedItem == null) { MessageBox.Show("无效类型"); return; } DisableGetObjects.IConfigSwitchOrGroup icsg; DisableGetObjects.TypeOfSwitchOrGroup typeofnewitem = (DisableGetObjects.TypeOfSwitchOrGroup)cb_itemType.SelectedItem; if (typeofnewitem == DisableGetObjects.TypeOfSwitchOrGroup.分组) { icsg = new DisableGetObjects.Setting_Type_Group { Name = tb_TypeName.Text, }; } else { if (cb_switchType.SelectedItem == null) { MessageBox.Show("请选择交换机类型"); return; } icsg = new DisableGetObjects.Setting_Type_Switch { Name = tb_TypeName.Text, Password = tb_password.Text, UserName = tb_username.Text, EnablePassword = tb_enablePassword.Text, IpAddress = tb_IPAddress.Text, EnableUsername = tb_enableUsername.Text, SwitchTypeNameBelongTo = (cb_switchType.SelectedItem as DisableGetObjects.Setting_SwitchType).SwitchTypeName }; } if (addToWhere == null) { //增加到顶级项 var nodeadded = treeView1.Nodes.Add(icsg.GetNowItemName()); nodeadded.Tag = icsg; } else { var tempitem = addToWhere.Tag as DisableGetObjects.IConfigSwitchOrGroup; tempitem.AddSubItem(icsg); } saveItemsToMem(); flushTreeViewItems(); }