using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Windows.Forms; using Core.Mes.Client.Comm.Format; 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; using Infragistics.Win.UltraWinGrid; namespace Core.StlMes.Client.Mcp.Control.Common { public partial class FrmScrapNum : FrmBase { private string plineCode ; private string _slGx ; private string[] gxs; private string heatPlanNo ; private int _processSeq ; private string defaultStorage ; private List _batchNo; private readonly List SignOfflineMatNo = new DataSourceList(); public FrmScrapNum(OpeBase ob, string heatPlanNo, List batchNo, string slGx, int processSeq, string plineCode, string[] gxs, string defaultStorage) { InitializeComponent(); this.heatPlanNo = heatPlanNo; ucBatchNo.DataSource = batchNo; ucBatchNo.DisplayMember = "PhyBatchNo"; ucBatchNo.ValueMember = "PhyBatchNo"; _slGx = slGx; _processSeq = processSeq; this.plineCode = plineCode; this.gxs = gxs; this.defaultStorage = defaultStorage; this.ob = ob; SignOfflineMatNo = new DataSourceList(); _batchNo = EntityHelper.GetData( "com.steering.mes.mcp.common.PlanService.getQueryDbkPortVrphot", new object[] { heatPlanNo, processSeq }, ob); httOfflineResultDentityBindingSource.DataSource = new List(); EntityHelper.ShowGridCaption(ultraGridDetailDes1.DisplayLayout.Bands[1]); } public string alamNum = ""; public string scrapNum = ""; public string testOfflineNum = ""; private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e) { switch (e.Tool.Key) { case "Save": Save(); break; case "Close": CloseFrm(); break; } } private void CloseFrm() { this.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.Close(); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); ultraGridDetailDes1.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False; ultraGridDetailDes1.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Default; var dt = ServerHelper.GetData( "com.steering.mes.mcp.common.PlanService.getBaseInfo", new object[] { "6003" }, ob); ucMemo.DataSource = dt; ucMemo.DisplayMember = "BASENAME"; ucMemo.ValueMember = "BASENAME"; YdmBaseClass.SetComboItemHeight(ucMemo); } /// /// 保存离线 /// private void Save() { this.ultraGridDetailDes1.UpdateData(); string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ArrayList list = new ArrayList(); list.Add(heatPlanNo); list.Add(""); list.Add(_slGx); list.Add(_processSeq); list.Add(this.UserInfo.GetUserName()); list.Add(this.UserInfo.GetUserOrder()); list.Add(this.UserInfo.GetUserGroup()); list.Add(""); list.Add(plineCode); list.Add(gxs); if (MessageUtil.ShowYesNoAndQuestion("是否离线?") == DialogResult.No) return; var list1 = httOfflineResultDentityBindingSource.DataSource as List; list1 = list1.Where(p => p.Chk).ToList(); if (list1.Any(p => p.OfflineNum == null || p.OfflineNum == "0")) { MessageUtil.ShowTips("支数不能为空或者为零支,请输入!"); return; } if (list1.Any(p => !p.OfflineNum.TryParseInt())) { MessageUtil.ShowTips("支数请输入整数!"); return; } if (list1.Any(p => string.IsNullOrEmpty(p.Memo))) { MessageUtil.ShowTips("请选择离线原因!"); return; } CoreClientParam ccp = new CoreClientParam(); try { this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待 if (Constant.WaitingForm == null) { Constant.WaitingForm = new WaitingForm(); } Constant.WaitingForm.ShowToUser = true; Constant.WaitingForm.Show(); Constant.WaitingForm.Update(); ccp.ServerName = "com.steering.mes.mcp.common.OfflineHelper"; ccp.MethodName = "HttOffLine"; ccp.ServerParams = new Object[] { list1.Select(JSONFormat.Format).ToList(), list }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); this.Cursor = Cursors.Default; Constant.WaitingForm.ShowToUser = false; Constant.WaitingForm.Close(); Constant.WaitingForm = null; } catch (Exception ex) { this.Cursor = Cursors.Default; Constant.WaitingForm.ShowToUser = false; Constant.WaitingForm.Close(); Constant.WaitingForm = null; } if (ccp.ReturnCode != -1) { MessageUtil.ShowTips(ccp.ReturnInfo); if (ccp.ReturnInfo.Equals("离线成功!")) { this.DialogResult = System.Windows.Forms.DialogResult.OK; } } } private void ultraGridDetailDes1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { this.ultraGridDetailDes1.UpdateData(); GridEdite(e.Cell.Row); HttOfflineResultDentity Entity = e.Cell.Row.ListObject as HttOfflineResultDentity; if (e.Cell.Column.Key.Equals("BatchNo")) { foreach (var t in Entity.GetTotal().Where(p => p.Check)) { RemoveWes(t); } Entity.ListPortMarts.Where(p => { if (p.InstoreFlag == "已入库" || p.MatStatus != "合格") return false; return !SignOfflineMatNo.Contains(p.MatNo); } ) .ToList().ForEach(AddWes); try { Entity.OfflineNum = Entity.ListPortMarts.Count(p=>p.Check).ToString(); } catch (Exception) { Entity.OfflineNum = "0"; } } else if ((e.Cell.Column.Key == "Check") && e.Cell.Row.HasParent()) { var t = e.Cell.Row.ListObject as PortHttBatchSampleResultEntityWithCheck; if ((bool)e.Cell.Value) AddWes(t); else RemoveWes(t); ultraGridDetailDes1.UpdateData(); var HttOfflineResultDentity = e.Cell.Row.ParentRow.ListObject as HttOfflineResultDentity; HttOfflineResultDentity.OfflineNum = HttOfflineResultDentity.ListPortMarts.Count(p => p.Check).ToString(); } else if ((e.Cell.Column.Key == "OfflineNum") && e.Cell.Row.HasChild()) { var HttOfflineResultDentity = e.Cell.Row.ListObject as HttOfflineResultDentity; if ((HttOfflineResultDentity != null) && (HttOfflineResultDentity.OfflineNum != null)) { var signedData = HttOfflineResultDentity.ListPortMarts.Where(p => p.Check).ToList(); int count = 0; if (!int.TryParse(HttOfflineResultDentity.OfflineNum, out count)) { count = 0; } if (signedData.Count >= count) signedData.Skip(count).ToList().ForEach(RemoveWes); else HttOfflineResultDentity.ListPortMarts.Where(p => { if (p.InstoreFlag == "已入库" || p.MatStatus != "合格") return false; return !SignOfflineMatNo.Contains(p.MatNo); } ).ToList() .OrderBy( p=> p.IsSamplePipe ).ThenBy(p=>p.MatNo) .Take(count - signedData.Count).ToList().ForEach( AddWes ); var listCheck = HttOfflineResultDentity.ListPortMarts.Where(p => p.Check).ToList(); int Count = listCheck.Count; if (Count < count) { MessageBox.Show("无足够的合格管可以离线,请检查是否入库或者已经离线!"); HttOfflineResultDentity.OfflineNum = Count.ToString(); ultraGridDetailDes1.PerformAction(UltraGridAction.ExitEditMode); } } } ultraGridDetailDes1.UpdateData(); if (e.Cell.Row.HasParent()) ultraGridDetailDes1.PerformAction(UltraGridAction.ExitEditMode); ultraGridDetailDes1.Refresh(); } public void AddWes(PortHttBatchSampleResultEntityWithCheck t) { try { if (t.InstoreFlag == "已入库") { MessageBox.Show("该管号已入库!"); t.Check = false; return; } if (t.MatStatus != "合格") { MessageBox.Show("该管号不是合格管号!"); t.Check = false; return; } if (SignOfflineMatNo.Contains(t.MatNo)) { MessageBox.Show("该管号在另一行已被标记将要离线!"); t.Check = false; return; } SignOfflineMatNo.Add(t.MatNo); t.Check = true; } catch (Exception ex) { MessageBox.Show(ex.Message); t.Check = false; } } public void RemoveWes(PortHttBatchSampleResultEntityWithCheck t) { try { t.Check = false; SignOfflineMatNo.Remove(t.MatNo); } catch (Exception ex) { } } /// /// /// ulltragrid控件受勾影响(打钩可编辑,不打勾不能编辑)** /// /// private void GridEdite(UltraGridRow row) { if(row.HasParent()) return; if (row.GetValue("Chk") == "True") { foreach (UltraGridCell cell in row.Cells) { if (cell.Column.CellActivation == Activation.AllowEdit) { cell.Activation = Activation.AllowEdit; } } } else { foreach (UltraGridCell cell in row.Cells) { if (cell.Column.Key.Contains("Chk")) continue; if (cell.Column.CellActivation == Activation.AllowEdit) { cell.Activation = Activation.ActivateOnly; } } } ultraGridDetailDes1.UpdateData(); } private void ultraGridDetailDes1_AfterRowInsert(object sender, RowEventArgs e) { this.ultraGridDetailDes1.UpdateData(); List list = ucBatchNo.DataSource as List; HttOfflineResultDentity currentEntity = e.Row.ListObject as HttOfflineResultDentity; var listAll = httOfflineResultDentityBindingSource.DataSource as List; var list1 = list.Where(p => listAll.All(q => q.BatchNo.ToString() != p.PhyBatchNo)).ToList(); currentEntity.BatchNo =list1.Any()? list1[0].PhyBatchNo :""; currentEntity.ListPortMarts = _batchNo.Select(p=>p.Clone()).ToList(); var listOk = currentEntity.ListPortMarts.Where(p => { if (p.InstoreFlag == "已入库" || p.MatStatus != "合格") return false; return !SignOfflineMatNo.Contains(p.MatNo); } ) .ToList(); try { currentEntity.OfflineNum = listOk.Count.ToString(); listOk.ForEach(AddWes); } catch (Exception) { currentEntity.OfflineNum = "0"; } ultraGridDetailDes1.DisplayLayout.Bands[1].Columns["BarCode"].PerformAutoResize(Infragistics.Win.UltraWinGrid.PerformAutoSizeType.AllRowsInBand, true); GridEdite(e.Row); ultraGridDetailDes1.UpdateData(); ultraGridDetailDes1.Refresh(); } private void ultraGridDetailDes1_InitializeTemplateAddRow(object sender, InitializeTemplateAddRowEventArgs e) { if (ultraGridDetailDes1.ActiveRow == null) e.TemplateAddRow.Activated = true; } } }