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 Core.Mes.Client.Comm.Tool; using Core.Mes.Client.Comm.Server; using Infragistics.Win.UltraWinGrid; using System.Collections; using Core.Mes.Client.Comm.Format; using Infragistics.Win.UltraWinEditors; namespace Core.StlMes.Client.SaleOrder.Dialog { /// /// 现货合同客户端 /// public partial class FrmMatInfo : FrmBase { public FrmMatInfo() { InitializeComponent(); } /// /// 构造函数 /// /// OB对象 public FrmMatInfo(OpeBase _ob) { InitializeComponent(); this.ob = _ob; } //销售组织 string saleorg = ""; public string Saleorg { get { return saleorg; } set { saleorg = value; } } /// /// 合同头PK值 /// private string ordPk; /// /// 合同头PK值 /// public string OrdPk { get { return ordPk; } set { ordPk = value; } } /// /// 制造商代码 /// private string suppUnit; /// /// 制造商代码 /// public string SuppUnit { get { return suppUnit; } set { suppUnit = value; } } private string orderNo; /// /// 合同号 /// public string OrderNo { get { return orderNo; } set { orderNo = value; } } /// /// 窗体关闭属性 默认关闭 /// private string closeEvent = "formClose"; /// /// 窗体关闭属性 /// public string CloseEvent { get { return closeEvent; } set { closeEvent = value; } } private string createDept = ""; /// /// 创建部门 /// public string CreateDept { get { return createDept; } set { createDept = value; } } private string createName = ""; /// /// 创建人 /// public string CreateName { get { return createName; } set { createName = value; } } /// /// 重写基类load事件,屏蔽平台过滤功能。 /// /// protected override void OnLoad(EventArgs e) { base.OnLoad(e); gdMat.DisplayLayout.Override.FilterUIType = Infragistics.Win.UltraWinGrid.FilterUIType.FilterRow; gdMat.DisplayLayout.Override.FilterOperatorDefaultValue = Infragistics.Win.UltraWinGrid.FilterOperatorDefaultValue.Contains; } private void FrmMatInfo_Load(object sender, EventArgs e) { EntityHelper.ShowGridCaption(gdMat.DisplayLayout.Bands[0]); UltraComboEditor uce = new UltraComboEditor(); uce.Items.Add("1", "封锁"); uce.Items.Add("0", "未封锁"); gdMat.DisplayLayout.Bands[0].Columns["lockFlag"].EditorComponent = uce; gdMat.DisplayLayout.Bands[0].Columns["mngLockFlag"].EditorComponent = uce; } private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e) { switch (e.Tool.Key) { case "Query": QueryMat(); break; case "Add": string dept = UserInfo.GetDeptid(); string name = UserInfo.GetUserName(); if (dept == this.CreateDept && name == this.CreateName) { AddOrderLine(); } else { MessageUtil.ShowWarning("操作权限不够!此合同是'" + this.CreateName + "'录入的!"); return; } break; case "Close": this.Close(); break; } } /// /// 库存信息查询 /// public void QueryMat() { string[] arr = new string[4]; string saleOrg = ClsBaseInfo.GetSaleOrg(UserInfo.GetDeptid()); if (UserInfo.GetUserName() == "admin") { arr[0] = "100101"; arr[1] = "100102"; arr[2] = "100103"; arr[3] = "100105"; } if (saleOrg == "100101" || saleOrg == "100103") { arr[0] = "100101"; arr[1] = "100103"; arr[2] = "100103"; arr[3] = "100105"; } else if (saleOrg == "100102") { arr[0] = "100102"; arr[1] = "100102"; arr[2] = "100102"; arr[3] = "100105"; } else if (saleOrg == "100105") { arr[0] = "100101"; arr[1] = "100102"; arr[2] = "100103"; arr[3] = "100105"; } string judgeStoveNo = ""; string proName = ""; string steelName = ""; string specName = ""; if (chkJudgeStoveNo.Checked) judgeStoveNo = txtJudgeStoveNo.Text.Trim(); if (chkPro.Checked) proName = txtPro.Text.Trim(); if (chkSteel.Checked) steelName = txtSteel.Text.Trim(); if (chkSpec.Checked) specName = txtSpec.Text.Trim(); ArrayList parm = new ArrayList(); parm.Add(judgeStoveNo); parm.Add(proName); parm.Add(steelName); parm.Add(specName); parm.Add(suppUnit); List listSource = EntityHelper.GetData( "com.steering.pss.sale.order.CoreMatInfo.queryMatInfo", new object[] { arr, parm }, this.ob); matZcMEntityBindingSource.DataSource = listSource; } /// /// 新增现货合同行 /// public void AddOrderLine() { gdMat.UpdateData(); gdOrderLine.UpdateData(); string saleOrg = Saleorg; UltraGridRow[] rows = gdMat.Rows.AsQueryable().Where(a => a.Cells["CHK"].Value.ToString() == "True").ToArray(); if (rows.Length <= 0) { MessageUtil.ShowWarning("请选择库存数据来新增现货合同!"); return; } ArrayList orderLine = new ArrayList(); foreach (UltraGridRow line in gdOrderLine.Rows) { SlmOrderLineNewEntity ole = new SlmOrderLineNewEntity(); ole.Psc = "N/A"; ole.PscDesc = "N/A"; ole.OrderSpecCode = "N/A"; ole.OrderSpecDesc = "N/A"; ole.Produccode = line.Cells["PRODUCCODE"].Value.ToString(); ole.Producname = line.Cells["PRODUCNAME"].Value.ToString(); if (line.Cells["JUDGESTDNAME"].Value != null && line.Cells["JUDGESTDNAME"].Value.ToString() != "" && string.IsNullOrEmpty(line.Cells["STDNAME"].Value.ToString())) { ole.StdCode = "N/A"; ole.StdName = line.Cells["JUDGESTDNAME"].Value.ToString(); } else { ole.StdCode = line.Cells["STDCODE"].Value.ToString(); ole.StdName = line.Cells["STDNAME"].Value.ToString(); } ole.Steelcode = line.Cells["STEELCODE"].Value.ToString(); ole.Steelname = line.Cells["STEELNAME"].Value.ToString(); ole.StdStyle = line.Cells["STDSTYLE"].Value.ToString(); ole.StdStyleDesc = line.Cells["STDSTYLEDESC"].Value.ToString(); ole.SpecCode = line.Cells["SPECCODE"].Value.ToString(); ole.SpecName = line.Cells["SPECNAME"].Value.ToString(); ole.Dimater = Convert.ToDecimal(line.Cells["ACTDIMATER"].Value.ToString() == "" ? "0" : line.Cells["ACTDIMATER"].Value); ole.Height = Convert.ToDecimal(line.Cells["ACTHEIGHT"].Value.ToString() == "" ? "0" : line.Cells["ACTHEIGHT"].Value); ole.ModelCode = line.Cells["MODELCODE"].Value.ToString(); ole.ModelDesc = line.Cells["MODELDESC"].Value.ToString(); ole.LenDesc = line.Cells["ACTLENMIN"].Value.ToString() + "-" + line.Cells["ACTLENMAX"].Value.ToString(); ole.LenMin = Convert.ToDecimal(line.Cells["ACTLENMIN"].Value.ToString3()); ole.LenMax = Convert.ToDecimal(line.Cells["ACTLENMAX"].Value.ToString3()); if (rdbD.Checked) { ole.OrderUnit = rdbD.Tag.ToString(); } else { ole.OrderUnit = rdbZ.Tag.ToString(); } ole.FinalUser = "N/A"; ole.FinalUserDesc = "N/A"; ole.CreateName = UserInfo.GetUserName(); ole.OrdPk = this.OrdPk; if (rdbD.Checked) { ole.OrderQty = Convert.ToDecimal(line.Cells["ORDERQTY"].Value); } else { ole.OrderQty = Convert.ToDecimal(line.Cells["ORDERCOUNT"].Value); } ole.PrdctWgt = Convert.ToDecimal(line.Cells["ORDERQTY"].Value); ole.DelvryRangeTpe = "%"; ole.DelvryRangeMin = 100; ole.DelvryRangeMax = 50; ole.OrderLnStatus = "12020101"; ole.StoveBatchGroup = line.Cells["STOBATCHGROUP"].Value.ToString(); //这一行合同行 由哪些炉号批号组号 组成 ole.OrderCount = line.Cells["ORDERCOUNT"].Value.ToString(); orderLine.Add(JSONFormat.Format(ole)); } ArrayList parm = new ArrayList(); foreach (UltraGridRow row in rows) { ArrayList list = new ArrayList(); list.Add(row.Cells["JUDGESTOVENO"].Value.ToString()); list.Add(row.Cells["BATCHNO"].Value.ToString()); list.Add(row.Cells["BATCHGROUDNO"].Value.ToString()); list.Add(row.Cells["LKACTCOUNT"].Value.ToString()); list.Add(row.Cells["BELONGCODE"].Text); list.Add(row.Cells["ActLen"].Text); list.Add(row.Cells["ActLenMin"].Text); list.Add(row.Cells["ActLenMax"].Text); if (!saleOrg.Equals(row.Cells["BELONGCODE"].Text)) { MessageUtil.ShowWarning("炉号"+row.Cells["JUDGESTOVENO"].Value.ToString()+"库存销售组织与您当前的销售组织不一致,请所属权转移至您当前销售组织!"); return; } parm.Add(list); //decimal actCount = Convert.ToDecimal(row.Cells["ACTCOUNT"].Value.ToString()); //decimal lkActCount = Convert.ToDecimal(row.Cells["LKACTCOUNT"].Value.ToString()); //decimal weight = Convert.ToDecimal(row.Cells["ACTWEIGHT"].Value.ToString()); //qty += Math.Round(Convert.ToDecimal(lkActCount / actCount * weight), 3); } if (MessageUtil.ShowYesNoAndQuestion("是否使用勾选的库存信息新增[ " + gdOrderLine.Rows.Count + " ]行现货合同行?") == DialogResult.No) return; CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.pss.sale.order.CoreMatInfo"; ccp.MethodName = "addSpotOrderLine"; ccp.ServerParams = new object[] { orderLine, parm, this.OrderNo, this.OrdPk, saleOrg,UserInfo.GetUserName() }; ccp.IfShowErrMsg = false; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp != null) { if (ccp.ReturnCode == -1) { MessageUtil.ShowWarning(ccp.ReturnInfo); return; } MessageUtil.ShowTips("现货合同新增成功,请维护最终用户,交货信息!"); this.CloseEvent = "Add"; this.Close(); } } /// /// 勾选炉号信息 之前只能新增一个合同行(相同产品信息),后改成根据产品信息自动生成多个合同行 /// /// /// private void gdMat_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { gdMat.UpdateData(); if (e.Cell.Column.Key.Equals("CHK")) { //如果材料是被 质量锁定或者管理锁定 将无法作现货合同 if (e.Cell.Row.Cells["lockFlag"].Value.ToString2() == "1") { MessageUtil.ShowWarning("所选材料已被质量封锁,不能用于现货合同!"); e.Cell.Value = false; return; } if (e.Cell.Row.Cells["mngLockFlag"].Value.ToString2() == "1") { MessageUtil.ShowWarning("所选材料已被管理封锁,不能用于现货合同!"); e.Cell.Value = false; return; } dataTable1.Clear(); Dictionary dic = new Dictionary(); //重量 Dictionary dicLen = new Dictionary(); //长度上下限 Dictionary dicStove = new Dictionary(); //炉批组 Dictionary dicCount = new Dictionary(); //支数 UltraGridRow[] rows = gdMat.Rows.AsQueryable().Where(a => a.Cells["CHK"].Value.ToString() == "True").ToArray(); foreach (UltraGridRow row in rows) { decimal qty = 0; DataRow dr = dataTable1.NewRow(); string str = row.Cells["PRODUCCODE"].Value.ToString() + row.Cells["STDSTYLE"].Value.ToString() + row.Cells["STEELCODE"].Value.ToString() + row.Cells["JUDGESTDNAME"].Value.ToString() + row.Cells["MODELCODE"].Value.ToString() + row.Cells["SPECCODE"].Value.ToString(); decimal actCount = Convert.ToDecimal(row.Cells["ACTCOUNT"].Value.ToString()); decimal lkActCount = Convert.ToDecimal(row.Cells["LKACTCOUNT"].Value.ToString()); decimal weight = Convert.ToDecimal(row.Cells["ACTWEIGHT"].Value.ToString()); qty = Math.Round(Convert.ToDecimal(lkActCount / actCount * weight), 3); //炉批组 @符号分割 string stove = row.Cells["JudgeStoveNo"].Value.ToString() + "@" + row.Cells["BatchNo"].Value.ToString() + "@" + row.Cells["BatchGroudNo"].Value.ToString(); if (!dic.ContainsKey(str) && dic.Count > 0) { //MessageUtil.ShowWarning("品种、标准类别、钢级、判定标准、扣型、规格不完全一样,不能勾选!"); //e.Cell.Value = false; //return; dic.Add(str, qty); dicStove.Add(str, stove); dr["KEYSTR"] = str; dr["PRODUCCODE"] = row.Cells["PRODUCCODE"].Value.ToString(); dr["PRODUCNAME"] = row.Cells["PRODUCNAME"].Value.ToString(); dr["STEELCODE"] = row.Cells["STEELCODE"].Value.ToString(); dr["STEELNAME"] = row.Cells["STEELNAME"].Value.ToString(); dr["STDCODE"] = row.Cells["STDCODE"].Value.ToString(); dr["STDNAME"] = row.Cells["STDNAME"].Value.ToString(); dr["STDSTYLE"] = row.Cells["STDSTYLE"].Value.ToString(); dr["STDSTYLEDESC"] = row.Cells["STDSTYLEDESC"].Value.ToString(); dr["JUDGESTDNAME"] = row.Cells["JUDGESTDNAME"].Value.ToString(); dr["MODELCODE"] = row.Cells["MODELCODE"].Value.ToString(); dr["MODELDESC"] = row.Cells["MODELDESC"].Value.ToString(); dr["ACTLENMIN"] = row.Cells["ACTLENMIN"].Value.ToString(); dr["ACTLENMAX"] = row.Cells["ACTLENMAX"].Value.ToString(); dr["ACTDIMATER"] = row.Cells["ACTDIMATER"].Value.ToString(); dr["ACTHEIGHT"] = row.Cells["ACTHEIGHT"].Value.ToString(); dr["SPECCODE"] = row.Cells["SPECCODE"].Value.ToString(); dr["SPECNAME"] = row.Cells["SPECNAME"].Value.ToString(); dr["ORDERQTY"] = qty; dr["STOBATCHGROUP"] = stove; dr["ORDERCOUNT"] = lkActCount; decimal x = Convert.ToDecimal(dr["ACTLENMIN"].ToString() == "" ? "0" : dr["ACTLENMIN"].ToString()); decimal y = Convert.ToDecimal(dr["ACTLENMAX"].ToString() == "" ? "0" : dr["ACTLENMAX"].ToString()); MyPoint point = new MyPoint(x, y); dicLen.Add(str, point); dicCount.Add(str, lkActCount); dataTable1.Rows.Add(dr); } else { if (dic.Count <= 0) { dic.Add(str, qty); dr["KEYSTR"] = str; dr["PRODUCCODE"] = row.Cells["PRODUCCODE"].Value.ToString(); dr["PRODUCNAME"] = row.Cells["PRODUCNAME"].Value.ToString(); dr["STEELCODE"] = row.Cells["STEELCODE"].Value.ToString(); dr["STEELNAME"] = row.Cells["STEELNAME"].Value.ToString(); dr["STDCODE"] = row.Cells["STDCODE"].Value.ToString(); dr["STDNAME"] = row.Cells["STDNAME"].Value.ToString(); dr["STDSTYLE"] = row.Cells["STDSTYLE"].Value.ToString(); dr["STDSTYLEDESC"] = row.Cells["STDSTYLEDESC"].Value.ToString(); dr["JUDGESTDNAME"] = row.Cells["JUDGESTDNAME"].Value.ToString(); dr["MODELCODE"] = row.Cells["MODELCODE"].Value.ToString(); dr["MODELDESC"] = row.Cells["MODELDESC"].Value.ToString(); dr["ACTLENMIN"] = row.Cells["ACTLENMIN"].Value.ToString(); dr["ACTLENMAX"] = row.Cells["ACTLENMAX"].Value.ToString(); dr["ACTDIMATER"] = row.Cells["ACTDIMATER"].Value.ToString(); dr["ACTHEIGHT"] = row.Cells["ACTHEIGHT"].Value.ToString(); dr["SPECCODE"] = row.Cells["SPECCODE"].Value.ToString(); dr["SPECNAME"] = row.Cells["SPECNAME"].Value.ToString(); dr["ORDERQTY"] = qty; dr["STOBATCHGROUP"] = stove; dr["ORDERCOUNT"] = lkActCount; decimal x = Convert.ToDecimal(dr["ACTLENMIN"].ToString() == "" ? "0" : dr["ACTLENMIN"].ToString()); decimal y = Convert.ToDecimal(dr["ACTLENMAX"].ToString() == "" ? "0" : dr["ACTLENMAX"].ToString()); MyPoint point = new MyPoint(x, y); dicLen.Add(str, point); dicStove.Add(str, stove); dicCount.Add(str, lkActCount); dataTable1.Rows.Add(dr); } else { dic[str] = dic[str] + qty; MyPoint oldPoint = dicLen[str]; decimal x = Convert.ToDecimal(row.Cells["ACTLENMIN"].Value.ToString() == "" ? "0" : row.Cells["ACTLENMIN"].Value.ToString()); decimal y = Convert.ToDecimal(row.Cells["ACTLENMAX"].Value.ToString() == "" ? "0" : row.Cells["ACTLENMAX"].Value.ToString()); if (oldPoint.X > x) //小中取小 大中取大 oldPoint.X = x; if (oldPoint.Y < y) oldPoint.Y = y; dicLen[str] = oldPoint; dicCount[str] = dicCount[str] + lkActCount; string stove1 = dicStove[str]; dicStove[str] = stove1 + "&" + stove; foreach (DataRow dRow in dataTable1.Rows) { if (dRow["KEYSTR"].ToString() == str) { dRow["ORDERQTY"] = dic[str]; dRow["ACTLENMIN"] = dicLen[str].X.ToString(); dRow["ACTLENMAX"] = dicLen[str].Y.ToString(); dRow["STOBATCHGROUP"] = dicStove[str]; dRow["ORDERCOUNT"] = dicCount[str]; break; } } } } } if (e.Cell.Value.ToString() == "True") { e.Cell.Row.Cells["LKACTCOUNT"].Activation = Activation.AllowEdit; } } else if (e.Cell.Column.Key.ToUpper().Equals("LKACTCOUNT")) { if (e.Cell.Value == null) { MessageUtil.ShowWarning("请输入利库支数!"); return; } else if (Convert.ToDecimal(e.Cell.Value) > Convert.ToDecimal(e.Cell.Row.Cells["ACTCOUNT"].Value)) { MessageUtil.ShowWarning("输入的利库支数不能大于炉号的支数!"); e.Cell.Value = e.Cell.Row.Cells["ACTCOUNT"].Value; return; } Dictionary dic = new Dictionary(); Dictionary dicCount = new Dictionary(); //支数 UltraGridRow[] rows = gdMat.Rows.AsQueryable().Where(a => a.Cells["CHK"].Value.ToString() == "True").ToArray(); decimal qty = 0; foreach (UltraGridRow row in rows) { string str = row.Cells["PRODUCCODE"].Value.ToString() + row.Cells["STDSTYLE"].Value.ToString() + row.Cells["STEELCODE"].Value.ToString() + row.Cells["JUDGESTDNAME"].Value.ToString() + row.Cells["MODELCODE"].Value.ToString() + row.Cells["SPECCODE"].Value.ToString(); decimal actCount = Convert.ToDecimal(row.Cells["ACTCOUNT"].Value.ToString()); decimal lkActCount = Convert.ToDecimal(row.Cells["LKACTCOUNT"].Value.ToString()); decimal weight = Convert.ToDecimal(row.Cells["ACTWEIGHT"].Value.ToString()); qty = Math.Round(Convert.ToDecimal(lkActCount / actCount * weight), 3); if (!dic.ContainsKey(str) && dic.Count > 0) { dic.Add(str, qty); dicCount.Add(str, lkActCount); } else { if (dic.Count <= 0) { dic.Add(str, qty); dicCount.Add(str, lkActCount); } else { dic[str] += qty; dicCount[str] += lkActCount; } } } foreach (DataRow dRow in dataTable1.Rows) { if (dic.ContainsKey(dRow["KEYSTR"].ToString())) { dRow["ORDERQTY"] = dic[dRow["KEYSTR"].ToString()]; dRow["ORDERCOUNT"] = dicCount[dRow["KEYSTR"].ToString()]; } } } } private void gdMat_AfterRowActivate(object sender, EventArgs e) { UltraGridRow row = gdMat.ActiveRow; if (row == null) return; foreach (UltraGridCell cell in row.Cells) { if (!cell.Column.Key.Equals("CHK")) { cell.Activation = Activation.ActivateOnly; } } if (row.Cells["CHK"].Value.ToString().ToUpper() == "TRUE") { row.Cells["LKACTCOUNT"].Activation = Activation.AllowEdit; } } private void chkJudgeStoveNo_CheckedChanged(object sender, EventArgs e) { if (chkJudgeStoveNo.Checked) { txtJudgeStoveNo.ReadOnly = false; } else { txtJudgeStoveNo.ReadOnly = true; } } private void txtJudgeStoveNo_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) QueryMat(); } private void chkPro_CheckedChanged(object sender, EventArgs e) { if (chkPro.Checked) { txtPro.ReadOnly = false; } else { txtPro.ReadOnly = true; } } private void chkSteel_CheckedChanged(object sender, EventArgs e) { if (chkSteel.Checked) { txtSteel.ReadOnly = false; } else { txtSteel.ReadOnly = true; } } private void chkSpec_CheckedChanged(object sender, EventArgs e) { if (chkSpec.Checked) { txtSpec.ReadOnly = false; } else { txtSpec.ReadOnly = true; } } private void txtPro_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) QueryMat(); } private void txtSteel_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) QueryMat(); } private void txtSpec_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) QueryMat(); } } /// /// 坐标 /// struct MyPoint { decimal x; public decimal X { get { return x; } set { x = value; } } decimal y; public decimal Y { get { return y; } set { y = value; } } public MyPoint(decimal x, decimal y) { this.x = x; this.y = y; } } }