using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Linq; using System.Windows.Forms; using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.Mcp.Control.Entity; using CoreFS.CA06; using Infragistics.Win.UltraWinGrid; using Infragistics.Win.UltraWinTree; namespace Core.StlMes.Client.Mcp.Control.Base { public partial class FrmBaseInfoNew : FrmBase { private List Codes = new List(); public FrmBaseInfoNew() { InitializeComponent(); ExceptionHelper.RegistException(); //this.IsLoadUserView = true; //平台F1功能 } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "doQuery": try { this.Cursor = Cursors.WaitCursor; doQuery(); } finally { this.Cursor = Cursors.Default; } break; case "doAdd": doAdd(); break; case "doModify": doModify(); break; case "doDelete": this.doDeleteOrResume(true); break; case "doResume": this.doDeleteOrResume(false); break; case "Close": this.Close(); break; } } /// /// 树节点选中事件触发时,存储父节点id,防止当父节点选中项转移到其他焦点时,无法获取数据。 /// private static string parentCode = ""; /// /// 用于修改时验证重复项 /// private static string VName = ""; private bool IsExistValidChild(string baseCode) { DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreBaseInfoNew.isExistValidChild", new object[]{baseCode}, ob); if (dt != null && dt.Rows[0][0].ToString() != "0") { return true; } return false; } private bool IsExistValidParent(string sortCode) { DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreBaseInfoNew.isExistValidParent", new object[]{sortCode}, ob); if (dt != null && dt.Rows[0][0].ToString() != "0") { return true; } return false; } /// /// 作废或恢复 /// /// true作废 false恢复 private void doDeleteOrResume(bool isDelete) { //已经没有批量作废功能,单表作废功能实现。 ArrayList param = new ArrayList(); if (ultraGrid1.ActiveRow == null) { MessageBox.Show("请选择需要" + (isDelete ? "作废" : "恢复") + "的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string validflagStr = ultraGrid1.ActiveRow.Cells["VALIDFLAG"].Value.ToString(); //无效数据不允许作废 if ("0".Equals(validflagStr)) { if (isDelete) { MessageBox.Show("无效数据不支持作废操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } else { //有效数据不允许恢复 if (!isDelete) { MessageBox.Show("有效数据不支持恢复操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } string baseCode = ultraGrid1.ActiveRow.Cells["BASECODE"].Value.ToString(); string parentCode = ultraGrid1.ActiveRow.Cells["SORTCODE"].Value.ToString(); if (isDelete && IsExistValidChild(baseCode)) { MessageUtil.ShowWarning("该节点包含有效的子节点,不能作废!"); return; } if (isDelete == false && IsExistValidParent(parentCode) == false) { MessageUtil.ShowWarning("该节点没有有效的父节点,不能恢复!"); return; } ArrayList parm = new ArrayList(); param.Add(baseCode); if (param.Count > 0 && MessageBox.Show("是否确认" + (isDelete ? "作废" : "恢复") + "选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { int count = ServerHelper.SetData("com.steering.pss.qcm.CoreBaseInfoNew.deleteLineInfo", new Object[] { param, UserInfo.GetUserName(), isDelete }, this.ob); if (count > 0) { binUltraGrid(parentCode); //作废聚焦 Infragistics.Win.UltraWinGrid.UltraGridRow row = null; for (int i = 0; i < ultraGrid1.Rows.Count; i++) { row = ultraGrid1.Rows[i]; if (row.Cells["BASECODE"].Value.ToString().Equals(baseCode)) { row.Activate(); break; } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } /// /// 验证必填项 /// /// private bool ValidInput() { if (string.IsNullOrEmpty(txtName.Text.Trim())) { MessageBox.Show("请输入基础分类名称!","提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } return true; } /// /// 修改操作 /// private void doModify() { //判断当前树节点是否有选中项,如果没有则不允许新增。 || !(treeView1.SelectedNode.Nodes.Count > 0) //if (treeView1.SelectedNode == null) //{ // MessageBox.Show("请先选中左侧基础分类树节点!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; //} if (parentCode == "") { MessageBox.Show("请先选中左侧基础分类树节点!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //BASECODE,BASENAME,SORTCODE,ISVISIBLE,MNEMONIC_CODE,SEQ,FLAG //基础分类编码,基础分类名称,快速检索码,可编辑标志(1:可编辑,0:不可编辑),拼音助记码,序号(排序用), //是否允许增加子类(1:允许,0:不允许) if (ultraGrid1.ActiveRow == null) { MessageBox.Show("请选择需要修改的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string validflagStr = ultraGrid1.ActiveRow.Cells["VALIDFLAG"].Value.ToString(); //无效数据不允许修改 if ("0".Equals(validflagStr)) { MessageBox.Show("无效数据不支持修改操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (ValidInput()) { ArrayList parm = new ArrayList(); //父节点的编号+当前手动输入的后半段编号,需要提供验证功能。 string baseCode = this.ultraGrid1.ActiveRow.Cells["baseCode"].Value.ToString(); //先判断基础分类名称是否重复,如果重复则return,并提示他。 string name = txtName.Text.Trim(); //验证是否修改了name if (!VName.Equals(name)) { //验证名称是否重复。 if (isRepeatName(parentCode, name)) { MessageBox.Show("基础分类名称\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if (MessageBox.Show("是否确认修改?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } //基础分类名称 parm.Add(name); //快速检索码,父节点编号 //string parentCode = this.parentCode; //parm.Add(parentCode); //可编辑标识 //parm.Add(cmbEdit.Value.ToString().Trim()); //拼音助记码 parm.Add(""); //序号也应该是自动生成的 //parm.Add(txtSEQ.Text.Trim()); //是否允许添加子类,因此,实际上在新增时,还需要判断该字段,假设为否,则提示他不可以新增子类。 if (chbxAddChild.Checked) { parm.Add(1); } else { parm.Add(0); } //admin parm.Add(this.UserInfo.GetUserName()); //备注 parm.Add(txtMemo.Text); //属性A parm.Add(""); //属性B parm.Add(""); //责任部门 parm.Add(""); //标准 parm.Add(""); //id最后加入 parm.Add(baseCode); CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.pss.qcm.CoreBaseInfoNew"; ccp.MethodName = "doModify"; ccp.ServerParams = new object[] { parm }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode == -1) return; //刷新Grid数据 binUltraGrid(parentCode); //刷新树节点数据 //treeView1.SelectedNode.Nodes.Find(baseCode,false) = name; //修改树节点数据 foreach (UltraTreeNode anode in treeView1.ActiveNode.Nodes) { if (baseCode.Equals(anode.Tag.ToString())) { anode.Text = name; } } //高亮显示新增的数据 Infragistics.Win.UltraWinGrid.UltraGridRow row = null; for (int i = 0; i < ultraGrid1.Rows.Count; i++) { row = ultraGrid1.Rows[i]; if (row.Cells["BASECODE"].Value.ToString().Equals(baseCode)) { row.Activate(); break; } } } } /// /// 查找树节点根据tag /// /// 要查找的树 /// treetag /// public TreeNode[] FindTreeNodeByNodeTag(TreeView treeview, string treeTag) { if (treeview.Nodes == null) { return null; } TreeNode[] treeNodeList = null; ArrayList treelist = new ArrayList(); foreach (TreeNode trnode in treeview.Nodes) { FindTreeNodeFromTag(trnode, treeTag, ref treelist); } if (treelist.Count > 0) { treeNodeList = new TreeNode[treelist.Count]; for (int i = 0; i < treelist.Count; i++) { treeNodeList[i] = (TreeNode)treelist[i]; } } return treeNodeList; } /// /// 查找具体的tag /// /// /// /// private void FindTreeNodeFromTag(TreeNode trnode, string treeTag, ref ArrayList treelist) { if (trnode.Tag != null && trnode.Tag.ToString() == treeTag) { treelist.Add(trnode); } foreach (TreeNode anode in trnode.Nodes) { FindTreeNodeFromTag(anode, treeTag, ref treelist); } } /// /// 验证名称是否重复。 /// /// /// private bool isRepeatName(string sortCode,string baseName) { DataTable dt = new DataTable(); dt = ServerHelper.GetData("com.steering.pss.qcm.CoreBaseInfoNew.GetName", new Object[] { sortCode, baseName }, this.ob); if (dt.Rows.Count > 0) { return true; } else { return false; } } /// /// 验证是否允许添加子项 /// /// /// private bool isAddChild(string baseCode) { DataTable dt = new DataTable(); dt = ServerHelper.GetData("com.steering.pss.qcm.CoreBaseInfoNew.isAddChild", new Object[] { baseCode }, this.ob); if ("1".Equals(dt.Rows[0]["FLAG"].ToString())) { return true; } else { return false; } } /// /// 新增操作 /// private void doAdd() { //判断当前树节点是否有选中项,如果没有则不允许新增。 //单击新增时,树节点势必没有选中。 //if (treeView1.SelectedNode == null || !(treeView1.SelectedNode.Nodes.Count > 0)) //{ // MessageBox.Show("请先选中树节点!", "提示"); // return; //} if (parentCode == "") { MessageBox.Show("请先选中左侧基础分类树节点!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (ValidInput()) { //基础分类名称 string name = txtName.Text.Trim(); if (isRepeatName(parentCode, name)) { MessageBox.Show("基础分类名称\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //string parentCode = parentCode; //判断当前父类是否允许增加子类 if (!isAddChild(parentCode)) { MessageBox.Show("当前父类基础信息不允许增加子类!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (MessageBox.Show("是否确认新增?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } ArrayList parm = new ArrayList(); //BASECODE,BASENAME,SORTCODE,ISVISIBLE,MNEMONIC_CODE,SEQ,FLAG //基础分类编码,基础分类名称,快速检索码,可编辑标志(1:可编辑,0:不可编辑),拼音助记码,序号(排序用), //是否允许增加子类(1:允许,0:不允许) //自动生成编号,需要查询出当前父节点下最大编号。 DataTable dt = new DataTable(); dt = ServerHelper.GetData("com.steering.pss.qcm.CoreBaseInfoNew.GetMaxBaseCode", new Object[] { parentCode }, this.ob); string baseCode = ""; if (dt.Rows.Count > 0&&!"".Equals(dt.Rows[0][0].ToString())) { baseCode = (Convert.ToInt64(dt.Rows[0][0]) + 1).ToString(); } else { if (parentCode.Length > 1) { baseCode = parentCode + "01"; } else { baseCode = parentCode + "001"; } } parm.Add(baseCode); parm.Add(name); //快速检索码,父节点编号 parm.Add(parentCode); //可编辑标识 //parm.Add(cmbEdit.Value.ToString()); //拼音助记码 parm.Add(""); //序号也应该是自动生成的 //parm.Add(txtSEQ.Text.Trim()); //是否允许添加子类,因此,实际上在新增时,还需要判断该字段,假设为否,则提示他不可以新增子类。 if (chbxAddChild.Checked) { parm.Add(1); } else { parm.Add(0); } //admin parm.Add(this.UserInfo.GetUserName()); //备注 parm.Add(txtMemo.Text); //属性A parm.Add(""); //属性B parm.Add(""); //责任部门 parm.Add(""); //属性B parm.Add(""); CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.pss.qcm.CoreBaseInfoNew"; ccp.MethodName = "doAdd"; ccp.ServerParams = new object[] { parm }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode == -1) return; //刷新数据源 binUltraGrid(parentCode); //树节点刷新,树节点会折叠起来。 //bandTreeView(); //当前父节点新增一个子节点 UltraTreeNode tn = new UltraTreeNode(); tn.Text = name; tn.Tag = baseCode; treeView1.ActiveNode.Nodes.Add(tn); //高亮显示新增的数据 Infragistics.Win.UltraWinGrid.UltraGridRow row = null; for (int i = 0; i < ultraGrid1.Rows.Count; i++) { row = ultraGrid1.Rows[i]; if (row.Cells["BASECODE"].Value.ToString().Equals(baseCode)) { row.Activate(); break; } } } } /// /// 刷新操作 /// private void doQuery() { //查询按钮就当刷新功能。 bandTreeView(); } /// /// 刷新树控件 /// /// /// private void FrmBaseInfoNew_Load(object sender, EventArgs e) { //绑定是否可编辑控件 //bandCmbEdit(); Codes = this.CustomInfo.ToString2().Split(';').ToList(); //根据已选择的项,绑定树控件。 bandTreeView(); } /// /// //绑定是否可编辑控件 /// //public void bandCmbEdit() //{ // DataTable dt = new DataTable(); // dt.Columns.Add("display"); // dt.Columns.Add("value"); // DataRow dr = dt.NewRow(); // dr["display"] = "是"; // dr["value"] = "1"; // DataRow drB = dt.NewRow(); // drB["display"] = "否"; // drB["value"] = "0"; // dt.Rows.Add(dr); // dt.Rows.Add(drB); // cmbEdit.DataSource = dt; // cmbEdit.DisplayMember = "display"; // cmbEdit.ValueMember = "value"; //} /// /// 树控件绑定数据源 /// public void bandTreeView() { List list = EntityHelper.GetData( "com.steering.pss.qcm.CoreBaseInfoNew.getTreeDataNew", new object[] { Codes }, ob); AddChildNodes(treeView1, list); } /// /// top复选框选中事件触发,更新树控件数据源 /// /// /// private void chbx_CheckedChanged(object sender, EventArgs e) { if (this.Cursor == Cursors.WaitCursor) return; //刷新功能。 try { this.Cursor = Cursors.WaitCursor; bandTreeView(); } finally { this.Cursor = Cursors.Default; } } /// /// 刷新Grid数据源 /// /// private void binUltraGrid(string basecode) { this.dataTable1.Clear(); DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreBaseInfoNew.doQuery", new Object[] { basecode }, this.ob); GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true); //不同颜色区分是否有效数据 Infragistics.Win.UltraWinGrid.UltraGridRow row = null; for (int i = 0; i < ultraGrid1.Rows.Count; i++) { row = ultraGrid1.Rows[i]; if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1")) { row.Appearance.ForeColor = Color.Red; } else { row.Appearance.ForeColor = Color.Black; } } //内容自适应 GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid1, new UltraGridColumn[] { ultraGrid1.DisplayLayout.Bands[0].Columns["MEMO"] }); } public void AddChildNodes(UltraTree Root, List Data) { Root.Nodes.Clear(); Data.Where(p =>Codes.Contains(p.Basecode)).ToList().ForEach(p => { UltraTreeNode child = new UltraTreeNode { Text = p.Basename, Tag = p.Basecode }; AddChildNodes(child, Data, p.Basecode); Root.Nodes.Add(child); } ); } public void AddChildNodes(UltraTreeNode Root, List Data, string Key) { Data.Where(p => p.Sortcode == Key).ToList().ForEach(p => { UltraTreeNode child = new UltraTreeNode { Text = p.Basename, Tag = p.Basecode }; AddChildNodes(child, Data, p.Basecode); Root.Nodes.Add(child); } ); } /// /// 为编辑区域赋值 /// /// /// private void ultraGrid1_AfterRowActivate(object sender, EventArgs e) { //BASECODE,BASENAME,SORTCODE,ISVISIBLE,MNEMONIC_CODE,SEQ,FLAG //基础分类编码,基础分类名称,快速检索码,可编辑标志(1:可编辑,0:不可编辑),拼音助记码,序号(排序用), //是否允许增加子类(1:允许,0:不允许) Infragistics.Win.UltraWinGrid.UltraGridRow row = ultraGrid1.ActiveRow; if (row != null) { //基础分类编码 //txtCodePart2.Text = row.Cells["BASECODE"].Value.ToString(); //基础分类名称 txtName.Text = row.Cells["BASENAME"].Value.ToString(); //存储name,用于修改时验证重复项。 VName = row.Cells["BASENAME"].Value.ToString(); //快速检索码,进入Grid之前就已经进行赋值。 //txtCodePart2.Text = row.Cells["SORTCODE"].Value.ToString(); //可编辑标志 //cmbEdit.Value = row.Cells["ISVISIBLE"].Value.ToString(); //拼音助记码 //txtPym.Text = row.Cells["MNEMONIC_CODE"].Value.ToString(); //序号 //txtSEQ.Text = row.Cells["SEQ"].Value.ToString(); //是否允许增加子类 if ("1".Equals(row.Cells["FLAG"].Value.ToString())) { chbxAddChild.Checked = true; } else { chbxAddChild.Checked = false; } //备注 txtMemo.Text = row.Cells["MEMO"].Value.ToString(); } } private void treeView1_AfterActivate(object sender, NodeEventArgs e) { try { this.Cursor = Cursors.WaitCursor; //给编辑区域控件赋值。 //基础分类编码 //txtCodePart1.Text = e.Node.Tag.ToString(); //快速检索码 //txtSCode.Text = e.Node.Tag.ToString(); //刷新Grid数据源,将父节点等于当前选中节点的数据全部取出来,构建数据源。 parentCode = e.TreeNode.Tag.ToString(); binUltraGrid(parentCode); } finally { this.Cursor = Cursors.Default; } } } }