using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using CoreFS.CA06;using Pur.Entity; using Infragistics.Win; using Infragistics.Win.UltraWinGrid; using Pur.Entity.configureEntity; using Core.Mes.Client.Comm.Control; using Infragistics.Win.UltraWinTree; using Core.Mes.Client.Comm.Tool; using com.hnshituo.pur.vo; using Pur.configure; using Pur.Pop_upWindow; using System.Collections; namespace Pur { public partial class FrmPurMatClass : FrmPmsBase { PurmatclassEntity Q_mat = null; private bool QclickQueryCell = false;//是否点击查询按钮或grid1单元格 public FrmPurMatClass() { InitializeComponent(); ultraGrid1.DisplayLayout.Bands[0].Override.AllowUpdate = DefaultableBoolean.False; } //菜单按钮事件 public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": ultraTree1.Nodes.Clear(); getultree();// 获取物料分类树形结构 GetPUR_MAT_CLASS(getEnSelContion(null)); if (ultraGrid1.Rows.Count < 1) { if (ultraTree1.ActiveNode != null) { ultraTree1.ActiveNode.Expanded = true; } } else { QclickQueryCell = true; UltraTreeNode uttNode = ultraTree1.GetNodeByKey(ultraGrid1.Rows[0].Cells["BASECODE"].Value.ToString()).Parent; if (uttNode == ultraTree1.ActiveNode) { return; } ultraTree1.CollapseAll(); if (uttNode == null) { ultraTree1.ActiveNode = ultraTree1.GetNodeByKey(ultraGrid1.Rows[0].Cells["BASECODE"].Value.ToString()); } else { ultraTree1.ActiveNode = uttNode; uttNode.Expanded = true; while (uttNode.Parent != null) { uttNode = uttNode.Parent; uttNode.Expanded = true; } } } break; case "Add": AddPUR_MAT_CLASS(); break; case "Update": UpdPUR_MAT_CLASS(); break; case "Delete": DelPUR_MAT_CLASS(); break; case "UpdClassName": UpdClassName(); break; case "doExcel": doExcel(); break; } } private void doExcel() { try { this.Cursor = Cursors.Default; if (ultraGrid1.Rows.Count <= 0) { MessageUtil.ShowTips("无可导出明细!"); } ArrayList alUltraGrid = new ArrayList(); alUltraGrid.Add(ultraGrid1); ArrayList alSheeft = new ArrayList(); alSheeft.Add("物料分类"); if (ultraGrid1.Rows.Count > 0) { GridHelper.ulGridToExcel(alUltraGrid, alSheeft, "物料分类表");//导出excel } else { MessageUtil.ShowTips("无可导出明细!"); } } catch (Exception e) { MessageUtil.ShowTips("导出失败" + e.Message); } finally { this.Cursor = Cursors.Default; } } /// /// 修改分类的父类 /// private void UpdClassName() { frmPopMatClass frm = new frmPopMatClass(this.ob); frm.ShowDialog(); if(frm.Q_Ultnode!=null) { //string strNode=ultraTree1.ActiveNode.Key; string strBaseName= ultraGrid1.ActiveRow.Cells["BASENAME"].Value.ToString().Trim(); string strBaseCode = ultraGrid1.ActiveRow.Cells["BASECODE"].Value.ToString().Trim(); if (MessageUtil.ShowYesNoAndQuestion("确定要将分类【" + strBaseName + "】移动到分类【" + frm.Q_Ultnode.Text + "】下吗?").Equals(DialogResult.Yes)) { PurmatclassEntity Purmatclass_Entity = new PurmatclassEntity(); Purmatclass_Entity.Basecode = strBaseCode; Purmatclass_Entity.Parentcode = frm.Q_Ultnode.Key; Purmatclass_Entity.UpdateName = UserInfo.GetUserName(); Purmatclass_Entity.UpdateUserid = UserInfo.GetUserID(); CoreResult crt = this.execute("com.hnshituo.pur.configure.service.MatClassService", "doUpdate", new object[] { Purmatclass_Entity }); if (crt.Resultcode != 0) { MessageUtil.ShowTips("修改失败 " + crt.Resultmsg); return; } MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); if (ultraTree1.ActiveNode != null) { //查询物料分类 ultraTree1.Nodes.Clear(); getultree();// 获取物料分类树形结构 PurmatclassEntity pmcE = new PurmatclassEntity(); pmcE.Parentcode = frm.Q_Ultnode.Key; GetPUR_MAT_CLASS(pmcE); ConfigureClassCommon.doActiveSelRow(ultraGrid1, "BASECODE", Purmatclass_Entity.Basecode);//激活当前行 ExpNode(Purmatclass_Entity.Basecode); } } } } /// /// 查询物料分类 /// public void GetPUR_MAT_CLASS(PurmatclassEntity mat) { dataTable1.Clear(); DataTable dt = this.execute("com.hnshituo.pur.configure.service.MatClassService", "getMatClass", new object[] { mat, 0, 0 }); // GetJsonService().execute("com.hnshituo.pur.configure.service.MatClassService", "getMatClass", new object[] { mat, 0, 0 }); //按创建时间降序 if (dt.Rows.Count > 0) { dt.DefaultView.Sort = "CREATETIME DESC"; dt = dt.DefaultView.ToTable(); } GridHelper.CopyDataToDatatable(ref dt, ref dataTable1, true);//绑定物料分类表 Q_mat = mat; } /// /// 添加 /// public void AddPUR_MAT_CLASS() { try { if (txt_BASENAME.Text.Trim() == "") { MessageUtil.ShowTips("填写物料分类名称"); return; } if (txt_BASECODE.Text.Trim() == "") { MessageUtil.ShowTips("填写物料分类编码"); return; } PurmatclassEntity Purmatclass_Entity = new PurmatclassEntity(); Purmatclass_Entity.Basecode = txt_BASECODE.Text;//分类编码 if (isExsitRow("com.hnshituo.pur.configure.service.MatClassService", Purmatclass_Entity))//判断分类编码是否存在 { MessageUtil.ShowTips("分类编码已存在,请重新输入"); return; } Purmatclass_Entity.Basecode = null; Purmatclass_Entity.Basename = txt_BASENAME.Text; if (isExsitRow("com.hnshituo.pur.configure.service.MatClassService", Purmatclass_Entity))//判断分类名称是否存在 { MessageUtil.ShowTips("数据库中已存在相同的分类名称,请重新输入"); return; } if (ultraCheckEditor3.Checked)//添加物料大类 { if (!IsCharacter(txt_BASECODE.Text)) { MessageUtil.ShowTips("物料大类必须为单个大写英文字母,请重新输入"); return; } Purmatclass_Entity.Parentcode = null;//如果添加大类,则分类编码null } else { Purmatclass_Entity.Parentcode = ultraTree1.ActiveNode.Key; } //else//添加物料小类 //{ // if (ultraTree1.ActiveNode == null) // { // MessageUtil.ShowTips("请选择左侧树形结构的节点"); // return; // } // if (Q_mat.Parentcode == null) // { // MessageBox.Show("请选择父类节点或者勾“选添加物料大类”", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); // return; // } // Purmatclass_Entity.Basecode = getItemCodeClass(Q_mat.Parentcode);//分类编码 // Purmatclass_Entity.Parentcode = ultraTree1.ActiveNode.Key; //} //判断分类名称是否存在 //if (ultraGrid1.ActiveRow.Cells["BASENAME"].Value.ToString() != txt_BASENAME.Text) //{ //Purmatclass_Entity.Basecode = null; //} Purmatclass_Entity.Parentcode = ultraTree1.ActiveNode.Key; Purmatclass_Entity.Basecode = txt_BASECODE.Text;//分类编码 Purmatclass_Entity.Basename = txt_BASENAME.Text.Trim();//分类名称 Purmatclass_Entity.CreateName = UserInfo.GetUserName(); Purmatclass_Entity.CreateTime = System.DateTime.Now;//创建时间 Purmatclass_Entity.CreateUserid = UserInfo.GetUserID(); Purmatclass_Entity.Validflag = "1"; CoreResult crt = this.execute("com.hnshituo.pur.configure.service.MatClassService", "doInsert", new object[] { Purmatclass_Entity });//添加操作 if (crt.Resultcode != 0) { MessageUtil.ShowTips("添加失败 " + crt.Resultmsg); return; } MessageBox.Show("添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); if (ultraTree1.ActiveNode != null) { //查询物料分类 PurmatclassEntity pmcE = new PurmatclassEntity(); pmcE.Parentcode = ultraTree1.ActiveNode.Key; GetPUR_MAT_CLASS(pmcE); ConfigureClassCommon.doActiveSelRow(ultraGrid1, "BASECODE", Purmatclass_Entity.Basecode);//激活当前行 //展开上次激活的节点 if (ultraCheckEditor3.Checked)//添加根节点 { ultraTree1.Nodes.Add(Purmatclass_Entity.Basecode, Purmatclass_Entity.Basename); } else { UltraTreeNode node = ultraTree1.ActiveNode; node.Nodes.Add(Purmatclass_Entity.Basecode, Purmatclass_Entity.Basename); } } } catch (Exception e) { MessageBox.Show(" 添加出现异常:" + e.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } /// /// 修改 /// public void UpdPUR_MAT_CLASS() { try { if (MessageUtil.ShowYesNoAndQuestion("是否确定更新?") == DialogResult.No) { return; } if (ultraCheckEditor3.Checked) { MessageUtil.ShowTips("你已勾选“添加物料大类”复选框,不能进行修改操作"); return; } if (txt_BASENAME.Text.Trim() == "") { MessageUtil.ShowTips("填写物料分类名称"); return; } if (ultraGrid1.ActiveRow == null) { MessageBox.Show("请选择要修改的物料分类!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (txt_BASECODE.Text.Trim() != ultraGrid1.ActiveRow.Cells["BASECODE"].Value.ToString().Trim()) { MessageUtil.ShowTips("不能更新分类编码"); //txt_BASECODE.Text = ultraGrid1.ActiveRow.Cells["BASECODE"].Value.ToString(); return; } PurmatclassEntity Purmatclass_Entity = new PurmatclassEntity(); if (txt_BASENAME.Text.Trim() != ultraGrid1.ActiveRow.Cells["BASENAME"].Value.ToString().Trim()) { Purmatclass_Entity.Basename = txt_BASENAME.Text; if (isExsitRow("com.hnshituo.pur.configure.service.MatClassService", Purmatclass_Entity))//判断分类名称是否存在 { MessageUtil.ShowTips("数据库中已存在相同的分类名称,请重新输入"); return; } } Purmatclass_Entity.Basecode = ultraGrid1.ActiveRow.Cells["BASECODE"].Value.ToString();//分类编码 Purmatclass_Entity.Basename = txt_BASENAME.Text;//分类名称 Purmatclass_Entity.UpdateName = UserInfo.GetUserName(); Purmatclass_Entity.UpdateUserid = UserInfo.GetUserID(); Purmatclass_Entity.UpdateTime = System.DateTime.Now;//修改时间 CoreResult crt = this.execute("com.hnshituo.pur.configure.service.MatClassService", "doUpdate", new object[] { Purmatclass_Entity }); if (crt.Resultcode != 0) { MessageUtil.ShowTips("修改失败 " + crt.Resultmsg); return; } MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); if (ultraTree1.ActiveNode != null) { //查询物料分类 PurmatclassEntity pmcE = new PurmatclassEntity(); pmcE.Parentcode = ultraTree1.ActiveNode.Key; GetPUR_MAT_CLASS(pmcE); ConfigureClassCommon.doActiveSelRow(ultraGrid1, "BASECODE", Purmatclass_Entity.Basecode);//激活当前行 //展开上次激活的节点 if (ultraTree1.ActiveNode.Parent != null) { UltraTreeNode node = ultraTree1.ActiveNode.Nodes[Purmatclass_Entity.Basecode]; node.Text = Purmatclass_Entity.Basename; } else { ultraTree1.Nodes.Add(Purmatclass_Entity.Basecode, Purmatclass_Entity.Basename); } } } catch (Exception e) { MessageBox.Show("修改出现异常:" + e.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } /// /// 删除 /// public void DelPUR_MAT_CLASS() { try { if (ultraGrid1.ActiveRow == null) { MessageBox.Show("请选择要删除的物料分类!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (MessageUtil.ShowYesNoAndQuestion("确定要删除物料分类【" + ultraGrid1.ActiveRow.Cells["BASECODE"].Value.ToString() + "】?") == DialogResult.No) { return; } PurmatclassEntity Purmatclass_Entity = new PurmatclassEntity(); Purmatclass_Entity.Parentcode = ultraGrid1.ActiveRow.Cells["BASECODE"].Value.ToString();//分类编码 Purmatclass_Entity.Validflag = "1"; if (this.execute("com.hnshituo.pur.configure.service.MatClassService", "count", new object[] { Purmatclass_Entity }) > 0) { MessageUtil.ShowTips("分类编码【" + ultraGrid1.ActiveRow.Cells["BASECODE"].Value.ToString() + "】存在子节点,不能删除"); return; } MatEntity mat = new MatEntity(); mat.ArcCode = Purmatclass_Entity.Parentcode; mat.Validflag = "1"; if (this.execute("com.hnshituo.pur.configure.service.MatService", "count", new object[] { mat }) > 0) { MessageUtil.ShowTips("分类编码【" + ultraGrid1.ActiveRow.Cells["BASECODE"].Value.ToString() + "】存在物料,不能删除"); return; } Purmatclass_Entity.Basecode = ultraGrid1.ActiveRow.Cells["BASECODE"].Value.ToString();//分类编码 Purmatclass_Entity.DeleteName = UserInfo.GetUserName(); Purmatclass_Entity.DeleteTime = System.DateTime.Now;//修改时间 Purmatclass_Entity.DeleteUserid = UserInfo.GetUserID();//修改时间 Purmatclass_Entity.Validflag = "0"; CoreResult crt = this.execute("com.hnshituo.pur.configure.service.MatClassService", "doUpdate", new object[] { Purmatclass_Entity }); if (crt.Resultcode != 0) { MessageUtil.ShowTips("删除失败 " + crt.Resultmsg); return; } if (Q_mat != null) { //查询物料分类 PurmatclassEntity pmcE = new PurmatclassEntity(); pmcE.Parentcode = ultraTree1.ActiveNode.Key; GetPUR_MAT_CLASS(pmcE); //展开上次激活的节点 if (ultraTree1.ActiveNode != null) { UltraTreeNode node = ultraTree1.ActiveNode.Nodes[Purmatclass_Entity.Basecode]; ultraTree1.ActiveNode.Nodes.Remove(node); } MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception e) { MessageBox.Show("删除出现异常:" + e.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } /// /// 获取物料分类树形结构 /// public void getultree() { PurmatclassEntity mat = new PurmatclassEntity(); mat.Validflag = "1"; DataTable dt = this.execute("com.hnshituo.pur.configure.service.MatClassService", "find", new object[] { mat, 0, 0 }); if (dt == null || dt.Rows.Count < 1) { return; } DataTable dt_A = new DataTable();//物料分类 //筛选出根节点 DataRow[] rows = dt.Select("PARENTCODE='' or PARENTCODE is null"); dt_A = dt.Clone(); //克隆A的结构 foreach (DataRow row in rows) { dt_A.ImportRow(row);//复制行数据 } dt_A.DefaultView.Sort = "basename"; dt_A = dt_A.DefaultView.ToTable(); //添加物料大类 for (int j = 0; j < dt_A.Rows.Count; j++) { if (!ultraTree1.Nodes.Exists(dt_A.Rows[j]["BASECODE"].ToString())) { UltraTreeNode Ultnode = ultraTree1.Nodes.Add(dt_A.Rows[j]["BASECODE"].ToString(), dt_A.Rows[j]["BASENAME"].ToString()); getChildNodes(Ultnode, dt); } } } /// /// 递归查询父节点下的所有子节点 /// /// public void getChildNodes(UltraTreeNode Tnode, DataTable dt) { DataTable dt_A = dt.Clone();//物料分类 DataRow[] rows = dt.Select("PARENTCODE='" + Tnode.Key + "'"); foreach (DataRow row in rows) { dt_A.ImportRow(row);//复制行数据 } //添加物料分类 dt_A.DefaultView.Sort = "basename"; dt_A = dt_A.DefaultView.ToTable(); //添加物料分类 for (int j = 0; j < dt_A.Rows.Count; j++) { UltraTreeNode Ultnode = Tnode.Nodes.Add(dt_A.Rows[j]["BASECODE"].ToString(), dt_A.Rows[j]["BASENAME"].ToString()); getChildNodes(Ultnode, dt);//利用递归将当前节点的子节点添加进去 } } /// /// 获取激活子节点 /// /// public void ActiveChildNodes(UltraTreeNode Tnode) { Q_mat = new PurmatclassEntity(); Q_mat.Validflag = "1"; Q_mat.Parentcode = Tnode.Key; DataTable dt_A = this.execute("com.hnshituo.pur.configure.service.MatClassService", "find", new object[] { Q_mat, 0, 100 }); for (int j = 0; j < dt_A.Rows.Count; j++) { UltraTreeNode Ultnode = Tnode.Nodes.Add(dt_A.Rows[j]["BASECODE"].ToString(), dt_A.Rows[j]["BASENAME"].ToString()); ActiveChildNodes(Ultnode);//利用递归将当前节点的子节点添加进去 } } //选中ultraGrid1激活行事件 private void ultraGrid1_AfterRowActivate(object sender, EventArgs e) { txt_BASECODE.Text = ultraGrid1.ActiveRow.Cells["BASECODE"].Value.ToString();//分类编码 txt_BASENAME.Text = ultraGrid1.ActiveRow.Cells["Basename"].Value.ToString();//分类名称 //txt_BUYER_UNIT_CODE.Text = ultraGrid1.ActiveRow.Cells["BuyerUnitCode"].Value.ToString();//采购科室代码 //txt_BUYER_POST.Text = ultraGrid1.ActiveRow.Cells["BuyerPost"].Value.ToString();//采购科室描叙 } //选中 ultraTree1节点事件 private void ultraTree1_AfterSelect(object sender, SelectEventArgs e) { ////清空 //txt_BASECODE.Text = ""; //txt_BASENAME.Text = ""; //UltraTreeNode Ultnode = ultraTree1.ActiveNode; //GetPUR_MAT_CLASS(getEnSelContion(Ultnode.Key)); } /// /// 筛选选中节点的子记录 /// //public void getNodedt(UltraTreeNode Ultnode) //{ // if (dt_Purmatclass != null && dt_Purmatclass.Rows.Count > 0) // { // DataTable dt_A = dt_Purmatclass.Clone();//物料分类 // DataRow[] rows = dt_Purmatclass.Select("PARENTCODE='" + Ultnode.Key + "'"); // foreach (DataRow row in rows) // { // dt_A.ImportRow(row);//复制行数据 // } // dataTable1.Clear(); // GridHelper.CopyDataToDatatable(ref dt_A, ref dataTable1, true);//绑定物料分类表 // } //} //选中后自动展开 private void ultraTree1_BeforeSelect(object sender, BeforeSelectEventArgs e) { //UltraTreeNode Ultnode = ultraTree1.ActiveNode; //Ultnode.Expanded = true; } /// /// 获取查询条件 /// /// private PurmatclassEntity getEnSelContion(string str) { PurmatclassEntity eMatClass = new PurmatclassEntity(); if (str == null) { if (ultraTextEditor1.Text.Trim() != "") { eMatClass.Basecode = ultraTextEditor1.Text; } if (ultraTextEditor2.Text.Trim() != "") { eMatClass.Basename = ultraTextEditor2.Text; } } else { eMatClass.Parentcode = str; } eMatClass.Validflag = "1"; return eMatClass; } /// /// 获取物料分类编码 /// /// /// public string getItemCodeClass(string str) { string strChild = ""; PurmatclassEntity mat = new PurmatclassEntity(); mat.Parentcode = ultraTree1.ActiveNode.Key; int intChild = this.execute("com.hnshituo.pur.configure.service.MatClassService", "count", new object[] { mat }); intChild++; strChild = intChild.ToString(); while (strChild.Length < 2) { strChild = "0" + strChild; } //判断编码是否存在 PurmatclassEntity matIsExsitRow = new PurmatclassEntity(); matIsExsitRow.Basecode = str + strChild; while (isExsitRow("com.hnshituo.pur.configure.service.MatClassService", matIsExsitRow)) { intChild++; strChild = intChild.ToString(); while (strChild.Length < 2) { strChild = "0" + strChild; } matIsExsitRow.Basecode = str + strChild; } return str + strChild; } /// /// 添加物料大类 /// /// /// private void ultraCheckEditor3_CheckedChanged(object sender, EventArgs e) { //txt_BASECODE.Enabled = ultraCheckEditor3.Checked; } private bool IsCharacter(string str) { if (str.Trim() != "" && str.Length == 1) { System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); byte[] byteArray = asciiEncoding.GetBytes(str); if ((int)byteArray[0] >= 65 && (int)byteArray[0] <= 90) { return true; } } return false; } //判断物料中是否存在相同的列 public bool isExsitRow(string strJavaPackName, object o) { DataTable dt = this.execute(strJavaPackName, "find", new object[] { o, 0, 0 }); if (dt != null && dt.Rows.Count > 0)//存在相同的行 { return true; } return false; } /// /// 单击grid行,自动展开左侧树形结构 /// /// /// private void ultraGrid1_ClickCell(object sender, ClickCellEventArgs e) { ExpNode(e.Cell.Row.Cells["BASECODE"].Value.ToString()); } private void ExpNode(string strBASECODE) { UltraTreeNode uttNode = ultraTree1.GetNodeByKey(strBASECODE).Parent; if (uttNode == ultraTree1.ActiveNode) { return; } ultraTree1.CollapseAll(); QclickQueryCell = true; if (uttNode == null) { ultraTree1.ActiveNode = ultraTree1.GetNodeByKey(strBASECODE); } else { ultraTree1.ActiveNode = uttNode; } ultraTree1.ActiveNode.Expanded = true; UltraTreeNode uttNodeExpand = ultraTree1.ActiveNode; while (uttNodeExpand.Parent != null) { uttNodeExpand = uttNodeExpand.Parent; uttNodeExpand.Expanded = true; } } /// /// 激活左侧树形结构 /// /// /// private void ultraTree1_AfterActivate(object sender, NodeEventArgs e) { //清空 if (!QclickQueryCell) { txt_BASECODE.Text = ""; txt_BASENAME.Text = ""; UltraTreeNode Ultnode = ultraTree1.ActiveNode; Ultnode.Expanded = true; GetPUR_MAT_CLASS(getEnSelContion(Ultnode.Key)); } QclickQueryCell = false;//设置未点击 } private void ultraTree1_Click(object sender, EventArgs e) { } } }