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.Format; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.LgCommon; using Core.StlMes.Client.LgResMgt.Mcms.entity; using CoreFS.CA06; using Infragistics.Win; using Infragistics.Win.UltraWinGrid; namespace Core.StlMes.Client.LgResMgt.Mcms { public partial class FrmBuyGpIn : FrmBase { public FrmBuyGpIn() { InitializeComponent(); IsLoadUserView = true; } private string defaulStorage = ""; private string defaulLocation = ""; private string WeightPerMeterFormula = string.Empty; private Dictionary> storageList = new Dictionary>(); protected override void OnLoad(EventArgs e) { base.OnLoad(e); RegStartTime.Value = DateTime.Parse(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 00:00:00")); RegEndTime.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59")); RegStartTime1.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00")); RegEndTime1.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59")); matGrid.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Default; matGrid.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False; EntityHelper.ShowGridCaption(ugInlist.DisplayLayout.Bands[0]); GetWeightPerMeterFormula(); BindStorageDropDown(); Query1(); Query2(); } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "DoQuery": Query(); break; case "doSave": doSave(); break; case "DoAdd": DoAdd(); break; case "DoDelete": DoDelete(); break; case "DoBeside": DoBeside(); break; case "DoClose": Close(); break; case "Export": Export(); break; } } private void doSave(bool showOkMessage = true) { CmmWeightResultEntity entity = ugData.ActiveRow.ListObject as CmmWeightResultEntity; if (entity == null) return; matGrid.UpdateData(); List data = cmmWeightMatEntityBindingSource.DataSource as List; if (data != null && data.Any(p => p.Chk)) { data = data.Where(p => p.Chk).ToList(); } else { MessageBox.Show("请勾选需要保存的信息"); return; } //if (data.Any(p => p.InstoreType == "1" && p.ActWeight != p.EditWt)) //{ // MessageBox.Show("入库重量需和过磅重量一致!"); // return; //} var ccp = new CoreClientParam(); ccp.ServerName = "com.steering.Mcms.BuyGpInServer"; ccp.MethodName = "doSave"; ccp.ServerParams = new object[] { data.Select(JSONFormat.Format).ToList() }; ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Contains("成功")) { if (showOkMessage) { MessageUtil.ShowTips(ccp.ReturnInfo); ugData_AfterRowActivate(null, null); } } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } private void Export() { if (tabC.ActiveTab == null) return; if (tabC.ActiveTab.Key == "1") { GridHelper.ulGridToExcel(ugData, "磅单明细"); } else if (tabC.ActiveTab.Key == "2") { GridHelper.ulGridToExcel(ugInlist, "入库记录"); } } private void DoBeside() { List list; if ((ugData.Selected.Rows.Count <= 0) && (ugData.ActiveRow == null)) { MessageBox.Show("请选择需要完成的数据!"); return; } if (ugData.Selected.Rows.Count <= 0) list = new List { (ugData.ActiveRow.ListObject as CmmWeightResultEntity).ResultNo }; else list = (from UltraGridRow p in ugData.Selected.Rows select p.ListObject as CmmWeightResultEntity).Select(p => p.ResultNo).ToList(); var ccp = new CoreClientParam(); ccp.ServerName = "com.steering.Mcms.ResultServer"; ccp.MethodName = "DoFinish"; ccp.ServerParams = new object[] { list }; ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { MessageUtil.ShowTips(ccp.ReturnInfo); if (ccp.ReturnInfo.Contains("成功!")) Query1(); } } private void DoDelete() { ugInlist.UpdateData(); List list = ydmGpInlistEntityBindingSource.DataSource as List; if(list==null ) return; list = list.Where(p => p.Chk).ToList(); if (!list.Any()) { MessageBox.Show("请勾选需要撤销入库的数据!"); return; } var ccp = new CoreClientParam(); ccp.ServerName = "com.steering.Mcms.BuyGpInServer"; ccp.MethodName = "DoDelete"; ccp.ServerParams = new object[] { list.Select(JSONFormat.Format).ToList() }; ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { MessageUtil.ShowTips(ccp.ReturnInfo); if (ccp.ReturnInfo.Contains("成功!")) Query2(); } } private void DoAdd() { CmmWeightResultEntity entity = ugData.ActiveRow.ListObject as CmmWeightResultEntity; if (entity == null) return; matGrid.UpdateData(); List data= cmmWeightMatEntityBindingSource.DataSource as List; if (data != null && data.Any(p => p.Chk)) { data = data.Where(p => p.Chk).ToList(); } else { MessageBox.Show("请勾选需求要入库的信息"); return; } if (data.Any(p => { decimal editWt, actWt; if (decimal.TryParse(p.ActTheoryWeight.ToString3(), out actWt) && decimal.TryParse(p.EditWt.ToString3(), out editWt)) { if (Math.Abs(actWt - editWt) > 1) { return true; } } else { return true; } return false; })) { if (MessageUtil.ShowYesNoAndQuestion("入库重量与理论重量差别过大,请确认是否继续入库?") == DialogResult.No) return; } //int quoteIndex = 0;//小数位数 //double quoteValue = 0.0; //IQueryable checkMagRows = this.matGrid.Rows.AsQueryable().Where(" CHK = 'True'"); //foreach (UltraGridRow uRow in checkMagRows) //{ // quoteValue = double.Parse(uRow.Cells["EditWt"].Text.ToString3()) / double.Parse(uRow.Cells["EditInstockNum"].Text.ToString3()); // quoteIndex = quoteValue.ToString3().Length - quoteValue.ToString3().IndexOf('.') - 1;//小数位数 // if (quoteIndex > 3) // { // MessageBox.Show("单支入库重量精度不对,请分多次入库。!"); // return; // } //} var ccp = new CoreClientParam(); ccp.ServerName = "com.steering.Mcms.BuyGpInServer"; ccp.MethodName = "DoAdd"; ccp.ServerParams = new object[] { data.Select(JSONFormat.Format).ToList(),entity.ResultNo, this.UserInfo.GetUserName() }; ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { MessageUtil.ShowTips(ccp.ReturnInfo); if (ccp.ReturnInfo.Contains("成功")) Query(); } } private void Query() { if(tabC.ActiveTab==null) return; if (tabC.ActiveTab.Key == "1") { Query1(); } else if (tabC.ActiveTab.Key == "2") { Query2(); } } private void Query1() { var dic = new Dictionary(); if (chkTim.Checked) { dic.Add("time", RegStartTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); dic.Add("time1", RegEndTime.Value.ToString("yyy-MM-dd HH:mm:ss")); } dic.Add("matType", "钢坯采购"); if (chkShippersName.Checked) dic.Add("shippersName", uteShippersName.Text); dic.Add("validflag", new List { "1" }); if (chkJudgeStove.Checked) dic.Add("judgeStoveNo", uteJudgeStoveNo.Text); if (chkOrder.Checked) dic.Add("orderNo", utOrderNo.Text); dic.Add("storageFlag", new List() { "1", "0" }); List list = EntityHelper.GetData( "com.steering.Mcms.ResultServer.doQuery", new object[] { dic }, ob); cmmWeightMatEntityBindingSource.Clear(); if (list.Count == 0) return; List listProject = EntityHelper.GetData( "com.steering.Mcms.ResultServer.doCmmWeightMat", new object[] { list.Select(p => p.ResultNo).ToArray() }, ob); foreach (CmmWeightResultEntity entity in list) { entity.OrderFull = String.Join(",", listProject.Where(q => q.ResultNo == entity.ResultNo).Select(q => q.OrderFull).Distinct().ToList()); entity.SpecName = String.Join(",", listProject.Where(q => q.ResultNo == entity.ResultNo).Select(q => q.SpecName).Distinct().ToList()); entity.ActDimater = String.Join(",", listProject.Where(q => q.ResultNo == entity.ResultNo).Select(q => q.ActDimater).Distinct().ToList()); entity.Steelname = String.Join(",", listProject.Where(q => q.ResultNo == entity.ResultNo).Select(q => q.Steelname).Distinct().ToList()); entity.Producname = String.Join(",", listProject.Where(q => q.ResultNo == entity.ResultNo).Select(q => q.Producname).Distinct().ToList()); entity.Gradename = String.Join(",", listProject.Where(q => q.ResultNo == entity.ResultNo).Select(q => q.Gradename).Distinct().ToList()); entity.JudgeStoveNo = String.Join(",", listProject.Where(q => q.ResultNo == entity.ResultNo).Select(q => q.JudgeStoveNo).Distinct().ToList()); } QueryBS.DataSource = list; Comm.RefreshAndAutoSize(ugData); } private void Query2() { var dic = new Dictionary(); if (chkTim.Checked) { dic.Add("time", RegStartTime1.Value.ToString("yyyy-MM-dd HH:mm:ss")); dic.Add("time1", RegEndTime1.Value.ToString("yyy-MM-dd HH:mm:ss")); } if (chkJudgeStove1.Checked) dic.Add("judgeStoveNo", uteJudgeStoveNo1.Text); if (chkOrder1.Checked) dic.Add("orderNo", utOrderNo1.Text); List list = EntityHelper.GetData( "com.steering.Mcms.BuyGpInServer.doQueryInList", new object[] { dic }, ob); ydmGpInlistEntityBindingSource.DataSource = list; Comm.RefreshAndAutoSize(ugInlist); } private void FrmBuyGpIn_Shown(object sender, EventArgs e) { if (toolMenu == null) return; if (toolMenu.Toolbars[0].Tools.Exists("DoDelete")) { toolMenu.Toolbars[0].Tools["DoDelete"].InstanceProps.Visible = DefaultableBoolean.False; } if (toolMenu.Toolbars[0].Tools.Exists("doSave")) { toolMenu.Toolbars[0].Tools["doSave"].InstanceProps.Visible = DefaultableBoolean.True; } } private void tabC_SelectedTabChanged(object sender, Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs e) { if (toolMenu == null) return; if (toolMenu.Toolbars[0].Tools.Exists("DoDelete")) toolMenu.Toolbars[0].Tools["DoDelete"].InstanceProps.Visible = tabC.SelectedTab.Key == "1" ? DefaultableBoolean.False : DefaultableBoolean.True; if (toolMenu.Toolbars[0].Tools.Exists("doSave")) toolMenu.Toolbars[0].Tools["doSave"].InstanceProps.Visible = tabC.SelectedTab.Key == "1" ? DefaultableBoolean.True : DefaultableBoolean.False; if (toolMenu.Toolbars[0].Tools.Exists("DoAdd")) toolMenu.Toolbars[0].Tools["DoAdd"].InstanceProps.Visible = tabC.SelectedTab.Key == "2" ? DefaultableBoolean.False : DefaultableBoolean.True; if (toolMenu.Toolbars[0].Tools.Exists("DoBeside")) toolMenu.Toolbars[0].Tools["DoBeside"].InstanceProps.Visible = tabC.SelectedTab.Key == "2" ? DefaultableBoolean.False : DefaultableBoolean.True; } private void ugData_AfterRowActivate(object sender, EventArgs e) { CmmWeightResultEntity data = ugData.ActiveRow.ListObject as CmmWeightResultEntity; if (data == null) return; List list = EntityHelper.GetData( "com.steering.Mcms.PoundMatServer.doQuery", new object[] { data.ResultNo }, ob); for (var i = 0; i < list.Count; i++) { CmmWeightMatEntityFull p = list[i]; decimal num = 0; if (decimal.TryParse(p.UnInstockNum, out num)) { //入库支不等于0的自动勾上 //p.Chk = num > 0; if (p.EditInstockNum == null || (!string.IsNullOrWhiteSpace(p.InstockNum) &&decimal.Parse( p.InstockNum)>0)) p.EditInstockNum = num; } if (string.IsNullOrWhiteSpace(p.InstockNum)) p.InstockNum = "0"; decimal len = 0; if (decimal.TryParse(p.ActLenTemp, out len) && p.EditLength==null) p.EditLength = len; decimal actCount = p.ActCount ?? 0; decimal dimater = 0; decimal.TryParse(p.ActDimater.ToString3(), out dimater); p.ActTheoryWeight = GetActTheoryWt(len,p.ActDimater) * p.ActCount; if (p.EditWt == null || (p.InstockNum != null && decimal.Parse(p.InstockNum) > 0)) { if (p.InstoreType == "1") { if (p.EditInstockNum != null && p.EditInstockNum <= decimal.Parse(p.UnInstockNum) && p.PerWt != null) { try { p.EditWt = p.EditInstockNum == decimal.Parse(p.UnInstockNum) ? decimal.Parse(p.UnInstockWt) : Math.Round((decimal)(decimal.Parse(p.UnInstockWt) / decimal.Parse(p.UnInstockNum) * p.EditInstockNum), 3); } catch (Exception) { p.EditWt = null; } } else { p.EditWt = null; } } else { if (p.EditInstockNum != null && p.EditInstockNum <= p.RemainNum && p.PerWt != null) { try { p.EditWt = p.EditInstockNum == p.RemainNum ? p.RemainWt : Math.Round((decimal) (p.PerWt*p.EditInstockNum*p.EditLength), 3); } catch (Exception) { p.EditWt = null; } } else { p.EditWt = null; } } } else { //预报标记了来料清单 且是最后几支 不取保存的重量 if (p.InstoreType != null && p.InstoreType == "2" && p.EditInstockNum == p.RemainNum) { p.EditWt = p.RemainWt; } } try { p.ActTheoryWeight = GetActTheoryWt(p.EditLength, p.ActDimater) * p.EditInstockNum; } catch (Exception) { p.ActTheoryWeight = null; } if (uceStorageNo.Items.Count > 0) { p.StorageNo = string.IsNullOrWhiteSpace(defaulStorage) ? uceStorageNo.Items[0].DataValue.ToString2() : defaulStorage; List locationInfos; if (!storageList.ContainsKey(p.StorageNo)) { locationInfos = EntityHelper.GetData( "Core.LgMes.Server.LgDeviceManager.StorageManage.GetStorageLocationInfoNew", new[] {p.StorageNo}, ob); storageList.Add(p.StorageNo, locationInfos); } else { locationInfos = storageList[p.StorageNo]; } if (locationInfos != null && locationInfos.Any()) { var selectLoc = locationInfos.Where(no => no.LocationNo == defaulLocation).ToList(); if (selectLoc.Any()) { p.LocationNo = selectLoc[0].LocationNo; p.LocationName = selectLoc[0].LocationName; } else { p.LocationNo = locationInfos[0].LocationNo; p.LocationName = locationInfos[0].LocationName; } } } p.LaryNo = "1"; } // uceStorageNoEdit.SelectedIndex = -1; cmmWeightMatEntityBindingSource.DataSource = list; if (matGrid.Rows.Count>0) { matGrid.Rows[0].Cells["EditWt"].EditorComponent = uteInputWt; } Comm.RefreshAndAutoSize(matGrid, new string[] { "EditWt" }); } private decimal? GetActTheoryWt( decimal? len, decimal? actDimater) { try { var dt = new DataTable(); decimal weightPerMeter; decimal.TryParse( dt.Compute(WeightPerMeterFormula.Replace("断面", actDimater.ToString2().Replace("250", "251")), null).ToString(), out weightPerMeter); return Math.Round(decimal.Parse((weightPerMeter*len/1000).ToString2()),3); } catch (Exception) { } return null; } private void matGrid_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) { CmmWeightMatEntityFull list = e.Row.ListObject as CmmWeightMatEntityFull; if(list==null ) return; if (string.IsNullOrWhiteSpace(list.DocumentNo)) e.Row.Cells["OrderFull"].Appearance.BackColor = Color.Red; //if (!list.Chk) e.Row.Cells["Chk"].Appearance.BackColor = Color.DarkGray; //入库支为0时整行变灰 if (int.Parse( e.Row.Cells["EditInstockNum"].Text.Replace("_", "").ToString3()) == 0) { e.Row.Appearance.BackColor = Color.DarkGray; } } private void matGrid_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { if (e.Cell.Column.Key == "Chk") { matGrid.UpdateData(); //if((bool)e.Cell.Value) e.Cell.Appearance.ResetBackColor(); //else e.Cell.Appearance.BackColor = Color.DarkGray; } else if (e.Cell.Column.Key == "StorageNo") { matGrid.UpdateData(); List locationInfos; if (!storageList.ContainsKey(e.Cell.Value.ToString2())) { locationInfos = EntityHelper.GetData( "Core.LgMes.Server.LgDeviceManager.StorageManage.GetStorageLocationInfoNew", new[] { e.Cell.Value.ToString2() }, ob); storageList.Add(e.Cell.Value.ToString2(), locationInfos); } else { locationInfos = storageList[e.Cell.Value.ToString2()]; } e.Cell.Row.Cells["LocationNo"].Value = locationInfos != null && locationInfos.Any() ? locationInfos[0].LocationNo : ""; e.Cell.Row.Cells["LocationName"].Value = locationInfos != null && locationInfos.Any() ? locationInfos[0].LocationName : ""; } else if (e.Cell.Column.Key == "EditInstockNum" || e.Cell.Column.Key == "EditLength") { try { e.Cell.Row.Cells["ActTheoryWeight"].Value = GetActTheoryWt( decimal.Parse( e.Cell.Row.Cells["EditLength"].Text.Replace( "_", "")), decimal.Parse( e.Cell.Row.Cells["ActDimater"].Value.ToString3())) * decimal.Parse( e.Cell.Row.Cells["EditInstockNum"].Text.Replace( "_", "")); } catch (Exception) { e.Cell.Row.Cells["ActTheoryWeight"].Value = null; } if (e.Cell.Row.Cells["InstoreType"].Value.ToString2() == "1") { if (string.IsNullOrWhiteSpace(e.Cell.Row.Cells["EditInstockNum"].Text.Replace("_", "")) || string.IsNullOrWhiteSpace(e.Cell.Row.Cells["EditLength"].Text.Replace("_", "")) || string.IsNullOrWhiteSpace(e.Cell.Row.Cells["PerWt"].Text.Replace("_", "")) ) e.Cell.Row.Cells["EditWt"].Value = null; else { decimal num = decimal.Parse(e.Cell.Row.Cells["EditInstockNum"].Text.Replace("_", "")); decimal len = decimal.Parse(e.Cell.Row.Cells["EditLength"].Text.Replace("_", "")); decimal perWt = decimal.Parse(e.Cell.Row.Cells["PerWt"].Text.Replace("_", "")); decimal UnInstockNum = decimal.Parse(e.Cell.Row.Cells["UnInstockNum"].Value.ToString3()); decimal UnInstockWt = decimal.Parse(e.Cell.Row.Cells["UnInstockWt"].Value.ToString3()); if (num <= UnInstockNum) { decimal wt = num == UnInstockNum ? UnInstockWt : Math.Round(UnInstockWt / UnInstockNum * num, 3); if (wt > UnInstockWt) wt = UnInstockWt; e.Cell.Row.Cells["EditWt"].Value = wt; } else { e.Cell.Row.Cells["EditWt"].Value = null; } } }else { if (string.IsNullOrWhiteSpace(e.Cell.Row.Cells["EditInstockNum"].Text.Replace("_", "")) || string.IsNullOrWhiteSpace(e.Cell.Row.Cells["EditLength"].Text.Replace("_", "")) || string.IsNullOrWhiteSpace(e.Cell.Row.Cells["PerWt"].Text.Replace("_", "")) ) e.Cell.Row.Cells["EditWt"].Value = null; else { decimal num = decimal.Parse(e.Cell.Row.Cells["EditInstockNum"].Text.Replace("_", "")); decimal len = decimal.Parse(e.Cell.Row.Cells["EditLength"].Text.Replace("_", "")); decimal perWt = decimal.Parse(e.Cell.Row.Cells["PerWt"].Text.Replace("_", "")); decimal RemaindNum = decimal.Parse(e.Cell.Row.Cells["RemainNum"].Value.ToString3()); decimal RemainWt = decimal.Parse(e.Cell.Row.Cells["RemainWt"].Value.ToString3()); if (num <= RemaindNum) { decimal wt = num == RemaindNum ? RemainWt : Math.Round(perWt*len*num, 3); if (wt > RemainWt) wt = RemainWt; e.Cell.Row.Cells["EditWt"].Value = wt; } else { e.Cell.Row.Cells["EditWt"].Value = null; } } } if (e.Cell.Column.Key == "EditLength") { //CmmWeightResultEntity data = ugData.ActiveRow.ListObject as CmmWeightResultEntity; //if (data == null) return; //List list = // cmmWeightMatEntityBindingSource.DataSource as List; //decimal singleLenWt = (decimal)data.NetWt / list.Where(p => p.ActCount != null && StringUtil.IsInt(p.ActLenTemp)) // .Select(p => (decimal)p.ActCount * decimal.Parse(p.ActLenTemp) * decimal.Parse(p.ActDimater.ToString3()) * decimal.Parse(p.ActDimater.ToString3())).Sum(); //decimal usedWt = 0; //for (var i = 0; i < matGrid.Rows.Count; i++) //{ // decimal actCount, editLength,actDimater; // if (!decimal.TryParse(matGrid.Rows[i].Cells["ActCount"].Text.Replace( // "_", ""), out actCount)) // { // actCount = 0; // } // if (!decimal.TryParse(matGrid.Rows[i].Cells["EditLength"].Text.Replace( // "_", ""), out editLength)) // { // editLength = 0; // } // if (!decimal.TryParse(matGrid.Rows[i].Cells["ActDimater"].Text.Replace( //"_", ""), out actDimater)) // { // actDimater = 0; // } // decimal actWt = // Math.Round( // i == list.Count - 1 // ? (decimal)data.NetWt - usedWt // : singleLenWt * actCount * editLength * actDimater * actDimater, 3); // matGrid.Rows[i].Cells["ActWeight"].Value = actWt; // if (matGrid.Rows[i].Cells["EditLength"].Value.ToString2() == "1") // matGrid.Rows[i].Cells["EditWt"].Value = actWt; // usedWt = usedWt + actWt; //} } } } public void GetWeightPerMeterFormula() { try { var strErr = ""; var arry = new ArrayList(); arry.Add("frmBaseInfo_Parent.select"); arry.Add("405202"); var ccs = new CommonClientToServer(); ccs.ob = ob; var ds = ccs.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBQuery", "doSimpleQuery", arry, out strErr); if ((ds != null) && (ds.Tables.Count > 0) && (ds.Tables[0].Rows.Count > 0)) WeightPerMeterFormula = Convert.ToString(ds.Tables[0].Rows[0]["BASENAME"]); } catch { } } public void BindStorageDropDown() { var dic = new Dictionary(); var customInfo = CustomInfo.ToString2(); if (!string.IsNullOrWhiteSpace(customInfo)) dic.Add("storageTypeNo", customInfo.Split(',')); dic.Add("managementNo", ValidDataPurviewIds); var dt = ServerHelper.GetData("Core.LgMes.Server.LgDeviceManager.StorageManage.GetStorageNoList", new object[] { dic }, ob); if ((dt != null) && (dt.Rows.Count > 0)) { uceStorageNo.DataSource = dt; uceStorageNo.ValueMember = "STORAGE_NO"; uceStorageNo.DisplayMember = "STORAGE_NAME"; uceStorageNoEdit.DataSource = dt; uceStorageNoEdit.ValueMember = "STORAGE_NO"; uceStorageNoEdit.DisplayMember = "STORAGE_NAME"; if (dt.AsEnumerable().Any(p => p["STORAGE_NO"].ToString2() == "LSG2")) { defaulStorage = "LSG2"; } } } private void uteUpload2_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e) { if (string.IsNullOrWhiteSpace(matGrid.ActiveRow.Cells["StorageNo"].Value.ToString2())) return; using (var s = new StorageInfoSelect(matGrid.ActiveRow.Cells["StorageNo"].Value.ToString2(),ob)) { if (s.ShowDialog() == DialogResult.OK) { matGrid.ActiveRow.Cells["LocationNo"].Value = s.SelectLocation.LocationNo; matGrid.ActiveRow.Cells["LocationName"].Value = s.SelectLocation.LocationName; matGrid.DisplayLayout.Bands[0].Columns["LocationName"].PerformAutoResize(Infragistics.Win.UltraWinGrid.PerformAutoSizeType.AllRowsInBand, true); } } } private void utbLocaiton_Click(object sender, EventArgs e) { if (uceStorageNoEdit.SelectedIndex<0) return; using (var s = new StorageInfoSelect(uceStorageNoEdit.SelectedItem.DataValue.ToString2(), ob)) { if (s.ShowDialog() == DialogResult.OK) { defaulLocation = s.SelectLocation.LocationNo; defaulStorage = s.SelectLocation.StorageNo; if (matGrid.Selected.Rows.Count > 0) { foreach (var ultraGridRow in matGrid.Selected.Rows) { ultraGridRow.Cells["StorageNo"].Value = s.SelectLocation.StorageNo; ultraGridRow.Cells["LocationNo"].Value = s.SelectLocation.LocationNo; ultraGridRow.Cells["LocationName"].Value = s.SelectLocation.LocationName; } } else { foreach (var ultraGridRow in matGrid.Rows) { ultraGridRow.Cells["StorageNo"].Value = s.SelectLocation.StorageNo; ultraGridRow.Cells["LocationNo"].Value = s.SelectLocation.LocationNo; ultraGridRow.Cells["LocationName"].Value = s.SelectLocation.LocationName; } } } } } private void uceStorageNoEdit_ValueChanged(object sender, EventArgs e) { defaulStorage = uceStorageNoEdit.Value.ToString2(); if (matGrid.Selected.Rows.Count > 0) { foreach (var ultraGridRow in matGrid.Selected.Rows) { ultraGridRow.Cells["StorageNo"].Value = uceStorageNoEdit.Value.ToString2(); List locationInfos; if (!storageList.ContainsKey( uceStorageNoEdit.Value.ToString2())) { locationInfos = EntityHelper.GetData( "Core.LgMes.Server.LgDeviceManager.StorageManage.GetStorageLocationInfoNew", new[] { uceStorageNoEdit.Value.ToString2() }, ob); storageList.Add( uceStorageNoEdit.Value.ToString2(), locationInfos); } else { locationInfos = storageList[uceStorageNoEdit.Value.ToString2()]; } ultraGridRow.Cells["LocationNo"].Value = locationInfos != null && locationInfos.Any() ? locationInfos[0].LocationNo : ""; ultraGridRow.Cells["LocationName"].Value = locationInfos != null && locationInfos.Any() ? locationInfos[0].LocationName : ""; defaulLocation = locationInfos != null && locationInfos.Any() ? locationInfos[0].LocationNo : ""; } } else { foreach (var ultraGridRow in matGrid.Rows) { ultraGridRow.Cells["StorageNo"].Value = uceStorageNoEdit.Value.ToString2(); List locationInfos; if (!storageList.ContainsKey(uceStorageNoEdit.Value.ToString2())) { locationInfos = EntityHelper.GetData( "Core.LgMes.Server.LgDeviceManager.StorageManage.GetStorageLocationInfoNew", new[] { uceStorageNoEdit.Value.ToString2() }, ob); storageList.Add(uceStorageNoEdit.Value.ToString2(), locationInfos); } else { locationInfos = storageList[uceStorageNoEdit.Value.ToString2()]; } ultraGridRow.Cells["LocationNo"].Value = locationInfos != null && locationInfos.Any() ? locationInfos[0].LocationNo : ""; ultraGridRow.Cells["LocationName"].Value = locationInfos != null && locationInfos.Any() ? locationInfos[0].LocationName : ""; } } } private void uteInputWt_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e) { decimal wt = 0; decimal currentWt = 0; bool canInput = false; foreach (var ultraGridRow in matGrid.Rows) { if ((bool) ultraGridRow.Cells["Chk"].Value) { decimal rowWt = 0; decimal rowActWt = 0; if (decimal.TryParse(ultraGridRow.Cells["ActTheoryWeight"].Value.ToString2(), out rowWt)) { wt += rowWt; canInput = true; } if (decimal.TryParse(ultraGridRow.Cells["EditWt"].Value.ToString2(), out rowActWt)) { currentWt += rowActWt; canInput = true; } } } if (!canInput) { MessageBox.Show("请先勾选数据,或者输入入库支"); return; } using (var InputWt = new InputWt(currentWt)) { if (InputWt.ShowDialog() == DialogResult.OK) { decimal remaidWt = wt; decimal remaidInputWt = InputWt.TotalWt; decimal perWt = InputWt.TotalWt/wt; foreach (var ultraGridRow in matGrid.Rows) { if ((bool)ultraGridRow.Cells["Chk"].Value) { decimal rowWt = 0; if (decimal.TryParse(ultraGridRow.Cells["ActTheoryWeight"].Value.ToString2(), out rowWt)) { remaidWt = remaidWt - rowWt; decimal cWt = remaidWt <= 0 ? remaidInputWt : Math.Round(perWt*rowWt, 3); ultraGridRow.Cells["EditWt"].Value = cWt; remaidInputWt = remaidInputWt - cWt; } } } doSave(false); } } } } }