/// <summary> /// 增加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuAdd_Click(object sender, EventArgs e) { string nodecode; //{FF5503FA-0057-413e-BF08-5A8C1DCF7ED8} 药理作用级别校验 int girdLevel; //如果选择了节点,则选择的节点作为父节点,否则添加到根节点下 if (this.tvFunction.SelectedNode != null) { nodecode = this.tvFunction.SelectedNode.Tag.ToString(); girdLevel = this.tvFunction.SelectedNode.Level; //根据树节点层次设置药理作用级别 {FF5503FA-0057-413e-BF08-5A8C1DCF7ED8} } else { nodecode = "-1"; girdLevel = 0; //根节点下 药理作用级别为 1 {FF5503FA-0057-413e-BF08-5A8C1DCF7ED8} } if (girdLevel == 3) //父节点已经是三级节点 { MessageBox.Show("药理作最多支持三级分类,不能再进行四级分类添加", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //初始化实体 functionObject = new Neusoft.HISFC.Models.Pharmacy.PhaFunction(); //初始化控件 {FF5503FA-0057-413e-BF08-5A8C1DCF7ED8} 此时增加的是当前节点的下一级节点 Level + 1 ucProperty = new ucPharmacyFunctionProperty(nodecode, "INSERT", girdLevel + 1); //窗口标题 Neusoft.FrameWork.WinForms.Classes.Function.PopForm.Text = "添加药理作用"; DialogResult dlg = Neusoft.FrameWork.WinForms.Classes.Function.PopShowControl(ucProperty); if (dlg == DialogResult.OK) { TreeNode tn = new TreeNode(); //获取最近插入的实体 functionObject = (Neusoft.HISFC.Models.Pharmacy.PhaFunction) this.pharmacyConstant.QueryPhaFunctionNodeName()[0]; //插入新加节点 tn.Tag = functionObject.ID; tn.Text = functionObject.Name; tn.ImageIndex = 0; tn.SelectedImageIndex = 0; if (this.tvFunction.SelectedNode != null) { this.tvFunction.SelectedNode.Nodes.Add(tn); this.tvFunction.SelectedNode.ImageIndex = 2; this.tvFunction.SelectedNode.SelectedImageIndex = 1; } else { this.tvFunction.Nodes.Add(tn); } //添加到ListView ListViewItem lvi = new ListViewItem(); lvi.Text = tn.Text; lvi.Tag = tn.Tag; lvi.ImageIndex = tn.ImageIndex; this.lvFunctionList.Items.Add(lvi); } }
/// <summary> /// 控件初始化 /// </summary> /// <param name="e"></param> protected override void OnLoad(EventArgs e) { functionObject = new Neusoft.HISFC.Models.Pharmacy.PhaFunction( ); ArrayList al = new ArrayList( ); al = this.pharmacyConstant.QueryPhaFunction( ); if (al != null) { //初始化父级节点列表 this.cmbparent.AddItems(al); } //如果是修改或者删除 if (this.operKind == "UPDATE" || this.operKind == "DELETE") { functionObject = (Neusoft.HISFC.Models.Pharmacy.PhaFunction) this.pharmacyConstant.QueryFunctionByNode(this.nodeCode)[0]; ////{FF5503FA-0057-413e-BF08-5A8C1DCF7ED8} 获取原始值:原始药理作用节点 this.gridLevel = functionObject.GradeLevel; this.cmbparent.Tag = functionObject.ParentNode; //父级节点 this.txtName.Text = functionObject.Name; //节点名 //{C8D1015E-41B3-4e90-B624-8B47CF81E665} 校验药理作用名称重复 this.txtName.Tag = functionObject.Name; this.txtCode.Enabled = false; this.txtCode.Text = functionObject.ID;//节点ID this.txtWBCode.Text = functionObject.WBCode; this.txtSpellCode.Text = functionObject.SpellCode; this.txtMark.Text = functionObject.Memo; if (functionObject.IsValid) { this.chkIsValid.Checked = true; } } //如果是增加 if (this.operKind == "INSERT") { this.txtName.Text = null;//节点名 this.txtCode.Text = null; this.txtWBCode.Text = null; this.txtSpellCode.Text = null; this.txtMark.Text = null; this.chkIsValid.Checked = true; this.cmbparent.Tag = this.nodeCode;//传入的节点做为父节点 } base.OnLoad(e); }
/// <summary> /// 修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuModify_Click(object sender, EventArgs e) { //如果当前树没有节点则不能显示 if (this.tvFunction.Nodes.Count == 0) { return; } //定义当前节点和父节点 TreeNode node, nodep; if (this.lvFunctionList.Focused == true && this.lvFunctionList.SelectedItems.Count > 0) { node = this.lvFunctionList.SelectedItems[0].Tag as TreeNode; nodep = node.Parent; } else { node = this.tvFunction.SelectedNode; } //初始化实体 functionObject = new Neusoft.HISFC.Models.Pharmacy.PhaFunction(); //初始化控件 ucProperty = new ucPharmacyFunctionProperty(node.Tag.ToString(), "UPDATE", this.tvFunction.SelectedNode.Level); //窗口标题 Neusoft.FrameWork.WinForms.Classes.Function.PopForm.Text = "修改作用维护"; DialogResult dlg = Neusoft.FrameWork.WinForms.Classes.Function.PopShowControl(ucProperty); object myobj = new object(); if (dlg == DialogResult.OK) { functionObject = (Neusoft.HISFC.Models.Pharmacy.PhaFunction) this.pharmacyConstant.QueryPhaFunctionNodeName()[0]; //取出最新更改的节点的名称 node.Text = functionObject.Name; //如果更新的不是根节点 if (this.lvFunctionList.SelectedItems.Count > 0) { this.lvFunctionList.SelectedItems[0].Text = functionObject.Name; //新更改节点的父节点和原来父节点不同则重新LOAD if (functionObject.ParentNode != node.Parent.Tag.ToString()) { myobj = node; nodep = node.Parent; node.Remove(); //从当前列表种删除 this.lvFunctionList.SelectedItems[0].Remove(); //递归遍历整个树,添加到新根节点下 GetAllNode(this.tvFunction.Nodes, functionObject.ParentNode, (TreeNode)myobj); //如果当前修改的节点的父节点没有子节点,则更新子节点标志为0(因为当前节点的的节点类别已经更改) if (nodep.Nodes.Count == 0) { //叶子节点更改nodekind this.pharmacyConstant.UpdateFunctionnNodekind(nodep.Tag.ToString(), 0); SettreeImage(nodep, true); } } } else { this.tvFunction.InitTreeView(); if (this.tvFunction.Nodes.Count > 0) { this.tvFunction.Nodes[0].Expand(); } } } }
/// <summary> /// 保存设置 /// </summary> /// <returns></returns> private int Save() { //{FF5503FA-0057-413e-BF08-5A8C1DCF7ED8} 有效性校验 更改实体获取方式 if (this.IsDataValid() == false) { return(-1); } //实体初始化 this.functionObject = new Neusoft.HISFC.Models.Pharmacy.PhaFunction(); this.GetPhaFunction(); //{FF5503FA-0057-413e-BF08-5A8C1DCF7ED8} //判断是否有子节点 ArrayList al = new ArrayList(); al = pharmacyConstant.QueryFunctionByParentNode(functionObject.ID); if (al != null) { int ifleave = al.Count; if (ifleave > 0) //有子节点 用于排序 { functionObject.NodeKind = 1; //叶子节点 } else { functionObject.NodeKind = 0;//非叶子节点 } } else { functionObject.NodeKind = 0;//非叶子节点 } //判断是否重复 if (this.operKind == "INSERT")//插入 { int i = 0; ArrayList alfun = new ArrayList(); alfun = pharmacyConstant.QueryFunctionByNode(functionObject.ID); if (alfun != null) { i = alfun.Count; if (i >= 1) { MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("该节点编号") + this.txtCode.Text.Trim() + Neusoft.FrameWork.Management.Language.Msg("已存在!"), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //节点已存在的不能再插入 return(-1); } } } ////增,删,改操作 try { if (pharmacyConstant.SetFunction(functionObject, this.operKind) == -1) { MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("更新药理作用信息失败"), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return(-1); } return(0); } catch (Exception ex) { MessageBox.Show(ex.Message); return(-1); } }