using System; using System.Collections.Generic; using System.Drawing; 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; using ButtonDisplayStyle = Infragistics.Win.UltraWinGrid.ButtonDisplayStyle; using ColumnStyle = Infragistics.Win.UltraWinGrid.ColumnStyle; using System.Collections; namespace Core.StlMes.Client.Mcp.Control.Common { public delegate void HttWasteChange(); public partial class PortHttBatchControl : UserControl { public HttWasteChange HttWasteChange = null; public PortHttBatchControl() { InitializeComponent(); EntityHelper.ShowGridCaption(ultraGrid3.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGrid3.DisplayLayout.Bands[1]); commHelper.setOtherColumnReadOnly(ultraGrid3, new string[] { "DeleteReason", "DeleteNum" }); commHelper.setOtherColumnReadOnly(ultraGrid3, new string[] { }, 1); ultraGrid3.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False; foreach (UltraGridColumn ugc in ultraGrid3.DisplayLayout.Bands[0].Columns) { ugc.SortIndicator = SortIndicator.Disabled; } foreach (UltraGridColumn ugc in ultraGrid3.DisplayLayout.Bands[1].Columns) { ugc.SortIndicator = SortIndicator.Disabled; } commHelper.RefreshAndAutoSize(ultraGrid3); datas = new List(); } public bool ShowTop { get { return ultraPanel9.Visible; } set { ultraPanel9.Visible = value; } } public bool Show1 { get { return ultraPanel3.Visible; } set { ultraPanel3.Visible = value; } } public bool Show2 { get { return ultraPanel2.Visible; } set { ultraPanel2.Visible = value; } } public bool Show4 { get { return ultraPanel4.Visible; } set { ultraPanel4.Visible = value; } } public bool ShowDelete { get { return !ultraGrid3.DisplayLayout.Bands[1].Columns["DeleteReason"].Hidden; } set { ultraGrid3.DisplayLayout.Bands[1].Columns["DeleteReason"].Hidden = !value; ultraGrid3.DisplayLayout.Bands[0].Columns["DeleteReason"].Hidden = !value; ultraGrid3.DisplayLayout.Bands[0].Columns["DeleteNum"].Hidden = !value; } } public OpeBase ob { get; set; } public void SetDeleteReason(string failCode) { ultraGrid3.DisplayLayout.Bands[1].Columns["DeleteReason"].Hidden = !ShowDelete; var dt3 = ServerHelper.GetData("com.steering.mes.mcp.collarMaterial.ComBaseInfo.getBaseInfo", new object[] { failCode }, ob); reason.DataSource = dt3; reason.DisplayMember = "BASENAME"; reason.ValueMember = "BASECODE"; YdmBaseClass.SetComboItemHeight(reason); ultraGrid3.DisplayLayout.Bands[0].Columns["DeleteReason"].EditorComponent = reason; ultraGrid3.DisplayLayout.Bands[0].Columns["DeleteReason"].ButtonDisplayStyle = ButtonDisplayStyle.Always; ultraGrid3.DisplayLayout.Bands[0].Columns["DeleteReason"].Style = ColumnStyle.DropDownList; ultraGrid3.DisplayLayout.Bands[1].Columns["DeleteReason"].EditorComponent = reason; ultraGrid3.DisplayLayout.Bands[1].Columns["DeleteReason"].ButtonDisplayStyle = ButtonDisplayStyle.Always; ultraGrid3.DisplayLayout.Bands[1].Columns["DeleteReason"].Style = ColumnStyle.DropDownList; } private string heatPlanNo = ""; private string plineCode = ""; private int ProcessSeq = 1; private string GoWhere = ""; public string userName { get; set; } private void Query() { Query(heatPlanNo, plineCode, ProcessSeq, GoWhere); } public void updateLen() { try { ArrayList parm = new ArrayList(); UltraGridBand band = this.ultraGrid3.DisplayLayout.Bands[1]; foreach (UltraGridRow row in band.GetRowEnumerator(GridRowType.DataRow)) { String str = row.Cells["check"].Text.ToString(); if (row.Cells["check"].Text.ToString() == "True") { PortHttBatchSampleResultEntity portHttBatchSampleResultEntity = new PortHttBatchSampleResultEntity(); portHttBatchSampleResultEntity.MatNo = row.Cells["matNo"].Text.ToString(); portHttBatchSampleResultEntity.ActLen = Decimal.Parse(row.Cells["actLen"].Text.ToString()); portHttBatchSampleResultEntity.ActLenU = Decimal.Parse(row.Cells["actLenU"].Text.ToString() == null ? "0.00" : row.Cells["actLenU"].Text.ToString()); string portHttBatchSampleResult = JSONFormat.Format(portHttBatchSampleResultEntity); parm.Add(portHttBatchSampleResult); } } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.mcp.common.PlanService"; ccp.MethodName = "updateAcLen"; ccp.ServerParams = new object[] { parm }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("操作成功")) { // DoQueryInList(); Query(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } catch { return; } } public void Query(string HeatPlanNo, string PlineCode, int processSeq, string goWhere) { heatPlanNo = HeatPlanNo; plineCode = PlineCode; ProcessSeq = processSeq; GoWhere = goWhere; datas = EntityHelper.GetData( "com.steering.mes.mcp.common.PlanService.getQueryDbkPortVrphot", new object[] { HeatPlanNo, processSeq }, ob); toltal = datas.GroupBy(p => p.PhyBatchNo).Select(p => { return new PortHttBatchSampleResultEntityTotal { PhyBatchNo = p.Key, PortHttBatchSampleResultEntitys = p.ToList(), ActCount = p.Count(), ActWeight = p.Sum(q=>q.ActWeight), PassCount = p.Count(q => q.MatStatus == "00" || q.MatStatus == "合格"), PassWeight = p.Where(q => q.MatStatus == "00" || q.MatStatus == "合格").Sum(q => q.ActWeight), FailCount = p.Count( q => q.MatStatus == "10" || q.MatStatus == "剔除" || q.MatStatus == "40" || q.MatStatus == "委外废品"), FailWeight = p.Where( q => q.MatStatus == "10" || q.MatStatus == "剔除" || q.MatStatus == "40" || q.MatStatus == "委外废品").Sum(q=>q.ActWeight), OffLineCount = p.Count(q => q.MatStatus == "20" || q.MatStatus == "待处理"), OffLineWeight = p.Where(q => q.MatStatus == "20" || q.MatStatus == "待处理").Sum(q => q.ActWeight), NewStoveCount = p.Count(q => q.MatStatus == "30" || q.MatStatus == "另组炉"), NewStoveWeight = p.Where(q => q.MatStatus == "30" || q.MatStatus == "另组炉").Sum(q => q.ActWeight) }; } ).OrderBy(p => p.PhyBatchNo).ToList(); portHttBatchSampleResultEntityTotalBindingSource.DataSource = toltal; commHelper.RefreshAndAutoSize(ultraGrid3); Show4 = false; /* uceBatchNo.DataSource = toltal; uceBatchNo.ValueMember = "PhyBatchNo"; uceBatchNo.DisplayMember = "PhyBatchNo"; uceBatchNo.DataBind(); if (toltal.Any()) uceBatchNo.SelectedIndex = 0;*/ } public List datas { get; set; } public List toltal { get; set; } private void ultraGrid3_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) { if (e.Row.HasParent()) { if (e.Row.Cells["MatStatus"].Text.Equals("剔除") || e.Row.Cells["MatStatus"].Text.Equals("委外废品")) e.Row.Cells["MatStatus"].Appearance.ForeColor = Color.Red; if (e.Row.Cells["MatStatus"].Text.Equals("合格") && ShowDelete) { e.Row.Cells["MatStatus"].EditorComponent = utDelete; e.Row.Cells["MatStatus"].IgnoreRowColActivation = true; ultraGrid3.DisplayLayout.Bands[1].Columns["DeleteReason"].CellActivation = Activation.AllowEdit; } if (e.Row.Cells["MatStatus"].Text.Equals("剔除") && ShowDelete && _gxs.Contains(e.Row.Cells["OpProcessCode"].Value)) { e.Row.Cells["MatStatus"].EditorComponent = utCancelDelete; e.Row.Cells["MatStatus"].IgnoreRowColActivation = true; } } else { e.Row.Cells["DeleteNum"].EditorComponent = utDelete; e.Row.Cells["DeleteNum"].IgnoreRowColActivation = true; ultraGrid3.DisplayLayout.Bands[0].Columns["DeleteReason"].CellActivation = Activation.AllowEdit; ultraGrid3.DisplayLayout.Bands[0].Columns["DeleteNum"].ButtonDisplayStyle = ButtonDisplayStyle.Always; } ultraGrid3.DisplayLayout.Bands[1].Columns["check"].CellActivation = Activation.AllowEdit; ultraGrid3.DisplayLayout.Bands[1].Columns["ActLen"].CellActivation = Activation.AllowEdit; ultraGrid3.DisplayLayout.Bands[1].Columns["ActLenU"].CellActivation = Activation.AllowEdit; } private string[] _gxs; public void SetOfflineCode(string[] gxs) { _gxs = gxs; var dt5 = ServerHelper.GetData("com.steering.mes.mcp.heatTreatment.ScrapHelper.doQuery", new object[] {"6002", gxs }, ob); ultraComboEditor1.DataSource = dt5; ultraComboEditor1.DisplayMember = "BASENAME"; ultraComboEditor1.ValueMember = "BASECODE"; if (dt5.Rows.Count > 0) { ultraComboEditor1.SelectedIndex = 0; } Show2 = gxs.Length > 1; } private void officeNum_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e) { if (ob == null || heatPlanNo == "") return; if (ultraComboEditor1.SelectedIndex < 0) { MessageBox.Show("请选择工序"); } /* if (uceBatchNo.SelectedIndex < 0) return;*/ FrmScrapNum matfrm = new FrmScrapNum(ob, heatPlanNo, toltal, ultraComboEditor1.SelectedItem.DataValue.ToString(), ProcessSeq, plineCode, _gxs, GoWhere); matfrm.ShowDialog(); if (matfrm.DialogResult == DialogResult.OK) { var handler = HttWasteChange; if (handler != null) handler(); } } private void utDelete_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e) { try { if (ultraGrid3.ActiveRow.HasChild()) { ultraGrid3.UpdateData(); PortHttBatchSampleResultEntityTotal entity = ultraGrid3.ActiveRow.ListObject as PortHttBatchSampleResultEntityTotal; if (ultraGrid3.ActiveRow.Cells["DeleteReason"].Value.ToString2() == "") { MessageBox.Show("请选择废品原因"); return; } int Num = 0; if (! int.TryParse(ultraGrid3.ActiveRow.Cells["DeleteNum"].Value.ToString3(),out Num) || Num<=0) { MessageBox.Show("请输入正确的废品数量"); return; } var list = entity.PortHttBatchSampleResultEntitys.Where(p => p.MatStatus == "合格" && p.InstoreFlag == "未入库").OrderBy(p=>p.MatNo) .Take(Num).Select(p=>p.MatNo).ToList(); var listW = list.Select(p => new HttWasteResultEntity() { MatNo = p, BatchNo = ultraGrid3.ActiveRow.Cells["PhyBatchNo"].Text, DefFillCode = ultraGrid3.ActiveRow.Cells["DeleteReason"].Value.ToString2(), DefFillNum = 1, DefFillName = ultraGrid3.ActiveRow.Cells["DeleteReason"].Text.ToString2(), DefFillWt = decimal.Parse(ultraGrid3.ActiveRow.Cells["ActWeight"].Value.ToString3()) }).ToList(); if (list.Count < Num) { MessageBox.Show("无足够可剔除的未下线合格管"); return; } ServerHelper.SetData("com.steering.mes.mcp.heatTreatment.FrmHttBugD.AddHttWaste", new object[] { heatPlanNo, ultraComboEditor1.SelectedItem.DataValue.ToString(), plineCode, userName, ProcessSeq, list, listW.Select(JSONFormat.Format).ToList() }, ob); } else { if (ultraGrid3.ActiveRow.Cells["DeleteReason"].Value.ToString2() == "") { MessageBox.Show("请选择废品原因"); return; } ServerHelper.SetData("com.steering.mes.mcp.heatTreatment.FrmHttBugD.AddHttWaste", new object[] { heatPlanNo, ultraComboEditor1.SelectedItem.DataValue.ToString(), plineCode, userName, ProcessSeq, ultraGrid3.ActiveRow.Cells["MatNo"].Text.ToString2(), new List(){new HttWasteResultEntity() { MatNo = ultraGrid3.ActiveRow.Cells["MatNo"].Text.ToString2(), BatchNo = ultraGrid3.ActiveRow.Cells["PhyBatchNo"].Text, DefFillCode = ultraGrid3.ActiveRow.Cells["DeleteReason"].Value.ToString2(), DefFillNum = 1, DefFillName = ultraGrid3.ActiveRow.Cells["DeleteReason"].Text.ToString2(), DefFillWt = decimal.Parse(ultraGrid3.ActiveRow.Cells["ActWeight"].Value.ToString3()) }}.Select(JSONFormat.Format).ToList() }, ob); } MessageBox.Show("剔除成功"); var handler = HttWasteChange; if (handler != null) handler(); } catch (Exception) { } } private void utCancelDelete_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e) { try { ServerHelper.SetData("com.steering.mes.mcp.heatTreatment.FrmHttBugD.DeleteHttWaste", new object[] { heatPlanNo, ultraGrid3.ActiveRow.Cells["MatNo"].Text.ToString2(), ultraComboEditor1.SelectedItem.DataValue.ToString(), plineCode, ProcessSeq }, ob); MessageBox.Show("撤销成功"); var handler = HttWasteChange; if (handler != null) handler(); } catch (Exception) { } } } }