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 Infragistics.Win.UltraWinGrid; using Infragistics.Win; using CoreFS.CA06; using Pur.Entity; using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm; using Core.Mes.Client.Comm.Tool; using Pur.Entity.configureEntity; using Infragistics.Win.UltraWinTree; using Core.Mes.Client.Comm.Server; using Pur.Pop_upWindow; using com.hnshituo.pur.vo; using Pur.configure; using System.Collections; using Infragistics.Win.UltraWinToolTip; using Pur.require_plan; using Infragistics.Win.UltraWinEditors; using Pur.PublicTools; namespace Pur.Pop_upWindow { public partial class frmPop_updPrice : FrmPmsBase { public frmPop_updPrice(string strItemName,string strItemCode,string dPrice,OpeBase ob) { InitializeComponent(); this.ob = ob; } public frmPop_updPrice() { InitializeComponent(); } private void frmPop_updPrice_Load(object sender, EventArgs e) { PublicPur.InitCellEdit(new UltraGrid[] { GridMat }, new string[] { "Check", "newPrice" }); PublicPur.InitCellPositionRight(new UltraGrid[] { GridMat }, new string[] { "newPrice" }); PublicPur.InitColumnShowLength(new UltraGrid[] { GridMat }, 0, new string[] { "newPrice" }, 2, false); QtimeB.Value = System.DateTime.Now.AddYears(-1).AddDays(-3); QtimeE.Value = DateTime.Now.AddDays(-3); QueryNum.SelectedIndex = 0;//每页显示数量 GridHelper.SetExcludeColumnsActive(GridMat.DisplayLayout.Bands[0], new string[] { "Check", "newPrice" }); if (selectType == "1") { GridHelper.HidenColumns(GridMat.DisplayLayout.Bands[0], new string[] { "Check" }); } //查询物料分类树 GetPUR_MAT_Class(); ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[0]; } public double dPrice = 0; MatEntity Q_mat = null; String selectType = "0";//0:全选,1:单个选 Boolean QClickCellOrQuery = false;//是否点击查询按钮或grid数据单元格,控制是否刷新右侧物料数据,true为不刷新 DataTable dt_Purmatclass = null; UltraTreeNode qUltraNode = null; public ArrayList List_item=new ArrayList(); public String selectedItemCode=""; public String SelectedItemName=""; public string tips="0"; #region toolbar工具栏 public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": doQuery(); break; case "conFirmation": doSure(); break; case "updByClass"://按分类修改 { MessageUtil.ShowTips("无权限"); return; GridMat.UpdateData(); UltraTreeNode nd = ulTreeMat.ActiveNode; if (nd == null) { MessageUtil.ShowTips("请选择物料分类"); return; } ArrayList a3 = new ArrayList(); MatEntity m = new MatEntity(); m.ArcCode = nd.Key; m.LastPrice = 1; if (QtimeB.Value != null) { m.UpdateTime = (DateTime)QtimeB.Value; } else { MessageUtil.ShowTips("请选择加权平均价格计算区间"); return; } if (QtimeE.Value != null) { m.CreateTime = (DateTime)QtimeE.Value; } else { MessageUtil.ShowTips("请选择加权平均价格计算区间"); return; } //m.BugPrice = double.Parse(a2[i].ToString()); a3.Add(m); if (comm.ConfirmOption("注:修改新计划价格为到货合同加权平均价,如果合同加权平均价为空,则默认为原计划价。\n确定按物料分类【" + nd.Text + "】批量修改物料计划价")) { CoreResult crt = this.execute("com.hnshituo.pur.configure.service.MatService", "updateBugPrice", new object[] { a3 });//更新操作 if (crt.Resultcode != 0) { MessageUtil.ShowTips("更新失败 " + crt.Resultmsg); return; } MessageUtil.ShowTips("更新成功"); if (Q_mat != null) getMat(Q_mat);//刷新物料 } break; } case "ESC": { this.Close(); } break; case "doExcel": { doExcel(); } break; } } private void doSure() { GridMat.UpdateData(); ArrayList a3 = new ArrayList(); DataRow[] arr = DTmat.Select("Check = 'True'"); foreach (DataRow row in arr) { MatEntity m = new MatEntity(); m.ItemCode = row["itemCode"].ToString().Trim(); m.BugPrice = double.Parse(row["newPrice"].ToString().Trim()); m.CreateName = UserInfo.GetUserName(); m.CreateUserid = UserInfo.GetUserID(); m.CreateTime = DateTime.Now; a3.Add(m); } if (comm.ConfirmOption("注:新计划价格为合同加权库存平均价,如果合同加权平均价为空,则默认为原计划价。\n确定修改物料计划价")) { CoreResult crt = this.execute("com.hnshituo.pur.configure.service.MatService", "updateNewPrice", new object[] { a3 });//更新操作 if (crt.Resultcode != 0) { MessageUtil.ShowTips("更新失败: " + crt.Resultmsg); return; } MessageUtil.ShowTips("更新成功"); if (Q_mat != null) getMat(Q_mat);//刷新物料 } } private void doQuery() { if (ultraTabControl1.SelectedTab.Key == "1") { QClickCellOrQuery = true; GetPUR_MAT_Class(); if (GridMat.Rows.Count > 0) { ulTreeMat.CollapseAll(); UltraTreeNode uttNode = ulTreeMat.GetNodeByKey(GridMat.Rows[0].Cells["ARCCODE"].Value.ToString()); ulTreeMat.ActiveNode = uttNode; if (uttNode == null) { MessageUtil.ShowTips("物料名称:" + GridMat.Rows[0].Cells["ITEMNAME"].Value.ToString() + " 未找到相应的分类:" + GridMat.Rows[0].Cells["ARCCODE"].Value.ToString()); } else { while (ulTreeMat.ActiveNode != uttNode) { ulTreeMat.ActiveNode = uttNode; } uttNode.Expanded = true; //展开分类 while (uttNode.Parent != null) { uttNode = uttNode.Parent; uttNode.Expanded = true; } } QClickCellOrQuery = false;//设置未点击 } } else { DTrecord.Clear(); MatBugpirceRecord record = new MatBugpirceRecord(); record.ItemCode = QitemCode_record.Text.Trim(); record.ItemName = QitemName_record.Text.Trim(); DataTable dt11 = this.execute("com.hnshituo.pur.configure.service.MatBugpirceRecordService", "find", new object[] { record, 0, 0 }); GridHelper.CopyDataToDatatable(ref dt11, ref DTrecord, true);//绑定物料分类表 GridHelper.RefreshAndAutoSize(GridRecord); } } private void doExcel() { try { this.Cursor = Cursors.Default; if (ultraTabControl1.SelectedTab.Key == "1") { if (GridMat.ActiveRow == null) { MessageUtil.ShowTips("请选择需导出物料!"); return; } String strclass = ""; if (ulTreeMat.ActiveNode != null && !String.IsNullOrEmpty(ulTreeMat.ActiveNode.Text)) { strclass = ulTreeMat.ActiveNode.Text + "_"; } ArrayList alUltraGrid = new ArrayList(); alUltraGrid.Add(GridMat); ArrayList alSheeft = new ArrayList(); alSheeft.Add(strclass + "物料计划价格清单"); GridHelper.ulGridToExcel(alUltraGrid, alSheeft, strclass + "物料计划价格清单"); } else { if (GridRecord.Rows.Count <= 0) { MessageUtil.ShowTips("无可导出记录!"); return; } ArrayList alUltraGrid = new ArrayList(); alUltraGrid.Add(GridRecord); ArrayList alSheeft = new ArrayList(); alSheeft.Add("计划价格修改记录"); GridHelper.ulGridToExcel(alUltraGrid, alSheeft, "计划价格修改记录"); } } catch (Exception e) { MessageUtil.ShowTips("导出失败" + e.Message); } finally { this.Cursor = Cursors.Default; } } #endregion #region 加载物料分类树 /// /// 查询物料分类和物料 /// public void GetPUR_MAT_Class() { //查询物料分类 PurmatclassEntity matclassEntity = new PurmatclassEntity(); matclassEntity.Validflag = "1"; DataTable dt = this.execute("com.hnshituo.pur.configure.service.MatClassService", "getMatClass", new object[] { matclassEntity }); dt_Purmatclass = dt; getultree(dt);//绑定物料分类表 //查询物料 MatEntity mat = new MatEntity(); mat.Validflag = "1"; //物料分类 if (checkBox1.Checked) { mat.UpdateName = txt_ARC_CODE.Text; } mat.ItemCode = txt_wlbm.Text; string strItemName = txt_wlmc.Text.Trim(); while (strItemName.Contains(" ")) { strItemName = strItemName.Replace(" ", " "); } mat.MatItems = strItemName.Split(' '); getMat(mat); } /// /// 获取物料分类树形结构 /// public void getultree(DataTable dt) { ulTreeMat.Nodes.Clear(); if (dt == null || dt.Rows.Count < 1) { return; } dt_Purmatclass = dt;//保存物料分类全局变量 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);//复制行数据 } //添加物料大类 for (int j = 0; j < dt_A.Rows.Count; j++) { UltraTreeNode Ultnode = ulTreeMat.Nodes.Add(dt_A.Rows[j]["BASECODE"].ToString(), dt_A.Rows[j]["BASENAME"].ToString()); getChildNodes(Ultnode); } } /// /// 递归查询父节点下的所有子节点 /// /// public void getChildNodes(UltraTreeNode Tnode) { DataTable dt_A = dt_Purmatclass.Clone();//物料分类 DataRow[] rows = dt_Purmatclass.Select("PARENTCODE='" + Tnode.Key + "'"); foreach (DataRow row in rows) { dt_A.ImportRow(row);//复制行数据 } //添加物料分类 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);//利用递归将当前节点的子节点添加进去 } } private void ulTreeMat_AfterActivate(object sender, NodeEventArgs e) { if (!QClickCellOrQuery)//如果不是点击查询按钮或单击grig行数据,刷新右侧数据 { MatEntity eMat = new MatEntity(); ulTreeMat.ActiveNode.Expanded = true; qUltraNode = ulTreeMat.ActiveNode; eMat.ArcCode = qUltraNode.Key; eMat.Validflag = "1"; getMat(eMat); } txt_ARC_CODE.Text = ulTreeMat.ActiveNode.Key; txt_ARC_ITEM.Text = ulTreeMat.ActiveNode.Text; } #endregion #region 物料查询 /// /// 查询物料 /// private void getMat(MatEntity mat) { DTmat.Clear(); //查询合同加权平均价 if (QtimeB.Value != null) { mat.UpdateTime = (DateTime)QtimeB.Value; } if (QtimeE.Value != null) { mat.CreateTime = (DateTime)QtimeE.Value; } mat.LastPrice = 1; mat.ItemUomConefficient = double.Parse(QueryNum.Value.ToString()); DataTable dt_mat = this.execute("com.hnshituo.pur.configure.service.MatService", "getMat", new object[] { mat }); GridHelper.CopyDataToDatatable(ref dt_mat, ref DTmat, true);//绑定物料分类表 GridHelper.RefreshAndAutoSize(GridMat); } #endregion private void ultraTabControl1_SelectedTabChanged(object sender, Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs e) { if (ultraTabControl1.SelectedTab.Key == "2") { this.ToolBarItemEnable(this, "conFirmation", false); this.ToolBarItemEnable(this, "updByClass", false); } else { this.ToolBarItemEnable(this, "conFirmation", true); this.ToolBarItemEnable(this, "updByClass", true); } } private void frmPop_updPrice_Shown(object sender, EventArgs e) { this.ToolBarItemEnable(this, "conFirmation", true); this.ToolBarItemEnable(this, "updByClass", true); } } }