using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Format; using Core.Mes.Client.Comm.Tool; using CoreFS.CA06; using Infragistics.Win.UltraWinGrid; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Windows.Forms; using Infragistics.Win; using Core.StlMes.Client.Lims.Port.数据管理.实体类; namespace Core.StlMes.Client.Lims.Port { public partial class FrmPhyOutsourcing : FrmBase { public FrmPhyOutsourcing() { InitializeComponent(); } private void FrmPhyOutsourcing_Load(object sender, EventArgs e) { DateTime now = DateTime.Now; DateTime dt1 = new DateTime(now.Year, now.Month, 1);//当月第一天 DateTime dt2 = dt1.AddMonths(1).AddDays(-1);//当月最后一天 this.RegStartTime.Value = DateTime.Parse(dt1.ToString("yyyy-MM-dd") + " 00:00:00"); this.RegEndTime.Value = DateTime.Parse(dt2.ToString("yyyy-MM-dd") + " 23:59:59"); EntityHelper.ShowGridCaption(ultraGrid1.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGrid2.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGrid3.DisplayLayout.Bands[0]); initPhyCodeM(); } /// /// 加载试样组\检验项 /// private void initPhyCodeM() { DataTable dsPhyCodeM = PublicServer.GetData("com.steering.mes.port.vrp.FrmPhyOutsourcing.doQueryPhyCodeM", new object[] { }, ob); if (dsPhyCodeM.Rows.Count > 0) { ultraComboEditor1.DataSource = dsPhyCodeM; ultraComboEditor1.ValueMember = "PHY_CODE"; } doQueryPhyF(); doQueryPhyS(); doQueryPhyW(); } /// /// 重写基类方法 /// /// /// public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": doQueryData(); break; case "Add": doAdd(); break; case"AddTesting": doAddTesting(); break; case"Update": doUpdate(); break; case "Delete": doDelete(); break; case "Cope": doCope(); break; case"Export": exportData(); break; case "Close": close(); break; } } /// /// 导出 /// private void exportData() { GridHelper.ulGridToExcel(ultraGrid2, "外购管成品成分导出"); } /// /// 查询 /// private void doQueryData() { string stoveNo = ""; string judgeNo = ""; string strRegStart = ""; string strRegEnd = ""; if (this.chkFurnace.Checked && this.txtFurnace.Text.Trim() != "") { stoveNo = this.txtFurnace.Text.Trim(); } if(this.chkJudgeNo.Checked && this.txtJudgeNo.Text.Trim() != "") { judgeNo = this.txtJudgeNo.Text.Trim(); } ArrayList parm = new ArrayList(); if (chkRegTime.Checked) { strRegStart = RegStartTime.Value.ToString(); strRegEnd = RegEndTime.Value.ToString(); } parm.Add(stoveNo); parm.Add(judgeNo); parm.Add(strRegStart); parm.Add(strRegEnd); List listSource = EntityHelper.GetData( "com.steering.mes.port.vrp.FrmPhyOutsourcing.doQueryData", new object[] { parm }, this.ob); ydmBcInlistEntityBindingSource.DataSource = listSource; } /// /// 查询理化数据 /// private void doQueryChemical(string judgeNo,string batchNo,string ordLnDlyPk) { List listSource = EntityHelper.GetData( "com.steering.mes.port.vrp.FrmPhyOutsourcing.doQueryPhy", new object[] { judgeNo,batchNo,ordLnDlyPk }, this.ob); bool isnull = false; if (listSource.Count() == 0) { isnull = true; listSource = new List() { new QcmJhyPhyresultEntity() }; } qcmJhyPhyresultEntityBindingSource.DataSource = listSource; foreach (UltraGridRow row in ultraGrid2.Rows) { row.Cells["CHK"].Value = "True"; } //if (!isnull) //{ // ultraGrid2.Rows[0].Cells["CHK"].Value = "True"; //} } /// /// 新增 /// private void doAdd() { if (tabMain.SelectedTab.Index == 0) { this.ultraGrid2.UpdateData(); UltraGridRow uRow = this.ultraGrid1.ActiveRow; if (uRow == null) { return; } IQueryable checkMagRows = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'"); if (checkMagRows.Count() == 0) { MessageUtil.ShowTips("请选择录入的理化性能数据!"); return; } YdmBcInlistEntity ydmTity = (YdmBcInlistEntity)uRow.ListObject; string ydmBcEntity = JSONFormat.Format(ydmTity); ArrayList parm = new ArrayList(); List> parmList = new List>(); foreach (UltraGridRow row in checkMagRows) { if (row.Cells["SampleNo"].Text.Trim().Equals("") || row.Cells["PhyCodeMin"].Text.Trim().Equals("") || row.Cells["PhyCode"].Text.Trim().Equals("")) { MessageUtil.ShowTips("试样号、式样组、检验项不能为空!"); return; } QcmJhyPhyresultEntity entity = (QcmJhyPhyresultEntity)row.ListObject; entity.PhyCodeMin = row.Cells["PhyCodeMin"].Value.ToString(); entity.PhyNameMin = row.Cells["PhyCodeMin"].Text.Trim(); entity.PhyCode = row.Cells["PhyCode"].Value.ToString(); entity.PhyName = row.Cells["PhyCode"].Text; entity.ItemCodeF = row.Cells["ItemCodeF"].Value.ToString(); entity.ItemNameF = row.Cells["ItemCodeF"].Text; entity.ItemCodeW = row.Cells["ItemCodeW"].Value.ToString(); entity.ItemNameW = row.Cells["ItemCodeW"].Text; entity.ItemCodeS = row.Cells["ItemCodeS"].Value.ToString(); entity.ItemNameS = row.Cells["ItemCodeS"].Text; entity.IsGood = row.Cells["IsGood"].Value.ToString(); entity.IsDefect = row.Cells["IsDefect"].Value.ToString(); entity.ItemCodeW1 = row.Cells["ItemCodeW1"].Value.ToString(); entity.ItemNameW1 = row.Cells["ItemCodeW1"].Text.ToString(); entity.ItemCodeS1 = row.Cells["ItemCodeS1"].Value.ToString(); entity.ItemNameS1 = row.Cells["ItemCodeS1"].Text.ToString(); if (entity.PhyCodeMin.Equals("C0002") || entity.PhyCodeMin.Equals("C0074") || entity.PhyCodeMin.Equals("C0126") || entity.PhyCodeMin.Equals("C0127") || entity.PhyCodeMin.Equals("C0129")) { } string qcmEntity = JSONFormat.Format(entity); parm.Add(qcmEntity); List ss = new List(); ss.Add(row.Cells["SampleNo"].Text); ss.Add(row.Cells["PhyCodeMin"].Value.ToString()); ss.Add(row.Cells["PhyCodeMin"].Text); parmList.Add(ss); } if (MessageUtil.ShowYesNoAndQuestion("是否新增该理化性能数据?") == DialogResult.No) { return; } List> batchList = parmList.GroupBy(p => p[0]+ "-"+ p[1]).Select(p => p.FirstOrDefault() ).ToList(); CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.port.vrp.FrmPhyOutsourcing"; ccp.MethodName = "doAdd"; ccp.ServerParams = new object[] { parm, ydmBcEntity, UserInfo.GetUserName(), batchList }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("新增成功!")) { doQueryData(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } } /// /// 增加探伤信息 /// private void doAddTesting() { this.ultraGrid3.UpdateData(); IQueryable checkMagRows = this.ultraGrid3.Rows.AsQueryable().Where(" CHK = 'True'"); if (checkMagRows.Count() == 0) { MessageUtil.ShowTips("请选择需要保存的探伤信息!"); return; } ArrayList parmList = new ArrayList(); foreach(UltraGridRow row in checkMagRows) { QcmZgJugdeApplyEntity qcmTity = (QcmZgJugdeApplyEntity)row.ListObject; string qcmEntity = JSONFormat.Format(qcmTity); parmList.Add(qcmEntity); } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.port.vrp.FrmPhyOutsourcing"; ccp.MethodName = "doAddTesting"; ccp.ServerParams = new object[] { parmList }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("保存成功!")) { doQueryData(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } /// /// 修改 /// private void doUpdate() { this.ultraGrid2.UpdateData(); this.ultraGrid1.UpdateData(); IQueryable checkMagRows = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'"); if (checkMagRows.Count() == 0) { MessageUtil.ShowTips("请选择需要修改的理化性能数据!"); return; } UltraGridRow row = this.ultraGrid1.ActiveRow; YdmBcInlistEntity ydmBcEntity = (YdmBcInlistEntity)row.ListObject; string ydmEntity = JSONFormat.Format(ydmBcEntity); ArrayList parm = new ArrayList(); foreach(UltraGridRow uRow in checkMagRows) { QcmJhyPhyresultEntity entity = (QcmJhyPhyresultEntity)uRow.ListObject; entity.ItemCodeF = uRow.Cells["ItemCodeF"].Value.ToString(); entity.ItemNameF = uRow.Cells["ItemCodeF"].Text.ToString(); entity.ItemCodeS = uRow.Cells["ItemCodeS"].Value.ToString(); entity.ItemNameS = uRow.Cells["ItemCodeS"].Text.ToString(); entity.ItemCodeW = uRow.Cells["ItemCodeW"].Value.ToString(); entity.ItemNameW = uRow.Cells["ItemCodeW"].Text.ToString(); entity.ItemCodeW1 = uRow.Cells["ItemCodeW1"].Value.ToString(); entity.ItemNameW1 = uRow.Cells["ItemCodeW1"].Text.ToString(); entity.ItemCodeS1 = uRow.Cells["ItemCodeS1"].Value.ToString(); entity.ItemNameS1 = uRow.Cells["ItemCodeS1"].Text.ToString(); string qcmEntity = JSONFormat.Format(entity); parm.Add(qcmEntity); } if (MessageUtil.ShowYesNoAndQuestion("是否修改该理化性能数据?") == DialogResult.No) { return; } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.port.vrp.FrmPhyOutsourcing"; ccp.MethodName = "doUpdate"; ccp.ServerParams = new object[] { parm, ydmEntity }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("修改成功!")) { doQueryData(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } /// /// 删除 /// private void doDelete() { this.ultraGrid2.UpdateData(); this.ultraGrid1.UpdateData(); IQueryable checkMagRows = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'"); if (checkMagRows.Count() == 0) { MessageUtil.ShowTips("请选择需要删除的理化性能数据!"); return; } UltraGridRow row = this.ultraGrid1.ActiveRow; YdmBcInlistEntity ydmBcEntity = (YdmBcInlistEntity)row.ListObject; string ydmEntity = JSONFormat.Format(ydmBcEntity); ArrayList parm = new ArrayList(); foreach (UltraGridRow uRow in checkMagRows) { QcmJhyPhyresultEntity entity = (QcmJhyPhyresultEntity)uRow.ListObject; string qcmEntity = JSONFormat.Format(entity); parm.Add(qcmEntity); } if (MessageUtil.ShowYesNoAndQuestion("是否删除该理化性能数据?") == DialogResult.No) { return; } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.port.vrp.FrmPhyOutsourcing"; ccp.MethodName = "doDelete"; ccp.ServerParams = new object[] { parm, ydmEntity }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("删除成功!")) { doQueryData(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } /// /// 复制 /// private void doCope() { if (tabMain.SelectedTab.Index == 0) { this.ultraGrid2.UpdateData(); UltraGridRow uRow = this.ultraGrid1.ActiveRow; if (uRow == null) { return; } IQueryable checkMagRows = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'"); if (checkMagRows.Count() == 0) { MessageUtil.ShowTips("请选择复制的理化性能数据!"); return; } DataTable copyTable = CreateTableByEntity((QcmJhyPhyresultEntity)ultraGrid2.Rows.FirstOrDefault().ListObject); foreach (UltraGridRow row in checkMagRows) { DataRow dr = copyTable.NewRow(); CopyEntityToRow((QcmJhyPhyresultEntity)row.ListObject, dr); copyTable.Rows.Add(dr); } List data = (List)qcmJhyPhyresultEntityBindingSource.DataSource; QcmJhyPhyresultEntity activeFd = null; foreach (DataRow row in copyTable.Rows) { QcmJhyPhyresultEntity fd = new QcmJhyPhyresultEntity(); CopyRowToEntity(row, fd); data.Add(fd); activeFd = fd; } qcmJhyPhyresultEntityBindingSource.ResetBindings(false); ultraGrid2.UpdateData(); } } private void CopyRowToEntity(DataRow row, QcmJhyPhyresultEntity fdEntity) { PropertyInfo[] pros = fdEntity.GetType().GetProperties(); foreach (DataColumn dc in row.Table.Columns) { if (dc.ColumnName == "CREATE_TIME") continue; PropertyInfo pro = fdEntity.GetType().GetProperty(dc.ColumnName); if (pro != null) { pro.SetValue(fdEntity, ConvertDataType(pro.PropertyType, row[dc.ColumnName].ToString()), null); } } } private void CopyEntityToRow(QcmJhyPhyresultEntity fdEntity, DataRow desRow) { PropertyInfo[] pros = fdEntity.GetType().GetProperties(); foreach (PropertyInfo pro in pros) { desRow[pro.Name] = pro.GetValue(fdEntity, null); } } private DataTable CreateTableByEntity(QcmJhyPhyresultEntity fdEntity) { DataTable dt = new DataTable(); PropertyInfo[] srcPropertyInfos = fdEntity.GetType().GetProperties(); foreach (PropertyInfo srcPropertyInfo in srcPropertyInfos) { dt.Columns.Add(srcPropertyInfo.Name); } return dt; } /// /// 关闭 /// private void close() { this.Close(); } private void chkFurnace_CheckedChanged(object sender, EventArgs e) { this.txtFurnace.Enabled = this.chkFurnace.Checked; } private void ultraGrid1_AfterRowActivate(object sender, EventArgs e) { UltraGridRow uRow = this.ultraGrid1.ActiveRow; if (uRow == null) { return; } doQueryChemical(uRow.Cells["JudgeStoveNo"].Text,uRow.Cells["BatchNo"].Text, uRow.Cells["OrdLnDlyPk"].Text); doQueryQcmApply(uRow.Cells["JudgeStoveNo"].Text, uRow.Cells["BatchNo"].Text); } /// /// 查询送判信息 /// /// /// private void doQueryQcmApply(string judgeNo,string batchNo) { List listSource = EntityHelper.GetData( "com.steering.mes.port.vrp.FrmPhyOutsourcing.doQueryQcmApply", new object[] { judgeNo, batchNo }, this.ob); qcmZgJugdeApplyEntityBindingSource.DataSource = listSource; foreach (UltraGridRow row in ultraGrid3.Rows) { row.Cells["CHK"].Value = "True"; } } private void ultraGrid2_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Right) { if (ultraGrid2.ActiveCell.Column.Index + 1== ultraGrid2.DisplayLayout.Bands[0].Columns.Count) { return; } ultraGrid2.ActiveColScrollRegion.ScrollColIntoView(ultraGrid2.DisplayLayout.Bands[0].Columns[ultraGrid2.ActiveCell.Column.Index + 1], true); ultraGrid2.PerformAction(UltraGridAction.EnterEditMode); } if (e.KeyData == Keys.Left) { if (ultraGrid2.ActiveCell.Column.Index - 1 == 0) { return; } ultraGrid2.ActiveColScrollRegion.ScrollColIntoView(ultraGrid2.DisplayLayout.Bands[0].Columns[ultraGrid2.ActiveCell.Column.Index - 1], true); ultraGrid2.PerformAction(UltraGridAction.EnterEditMode); } } private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { YdmBcInlistEntity matGpEntity = e.Row.ListObject as YdmBcInlistEntity; if (!matGpEntity.ActCount.ToString().Equals("0")) { e.Row.RowSelectorAppearance.BackColor = Color.LightGreen; } } private void txtFurnace_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == 13) { doQueryData(); } } private void tabMain_SelectedTabChanged(object sender, Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs e) { if (toolMenu==null|| toolMenu.Toolbars==null ) return; if (toolMenu.Toolbars[0].Tools.Exists("Query")) { toolMenu.Toolbars[0].Tools["Query"].InstanceProps.Visible = tabMain.SelectedTab.Index == 0 ? DefaultableBoolean.True : DefaultableBoolean.False; } if (toolMenu.Toolbars[0].Tools.Exists("Update")) { toolMenu.Toolbars[0].Tools["Update"].InstanceProps.Visible = tabMain.SelectedTab.Index == 0 ? DefaultableBoolean.True : DefaultableBoolean.False; } if (toolMenu.Toolbars[0].Tools.Exists("Delete")) { toolMenu.Toolbars[0].Tools["Delete"].InstanceProps.Visible = tabMain.SelectedTab.Index == 0 ? DefaultableBoolean.True : DefaultableBoolean.False; } if (toolMenu.Toolbars[0].Tools.Exists("Export")) { toolMenu.Toolbars[0].Tools["Export"].InstanceProps.Visible = tabMain.SelectedTab.Index == 0 ? DefaultableBoolean.True : DefaultableBoolean.False; } } private void chkRegTime_CheckedChanged(object sender, EventArgs e) { this.RegStartTime.Enabled = this.RegEndTime.Enabled = this.chkRegTime.Checked; } private void chkJudgeNo_CheckedChanged(object sender, EventArgs e) { this.txtJudgeNo.Enabled = this.chkJudgeNo.Checked; } private void ultraGrid2_CellChange(object sender, CellEventArgs e) { this.ultraGrid2.UpdateData(); int m = 0; if (e.Cell.Column.Key == "PhyCodeMin") { ultraGrid2.ActiveRow.Cells["PhyCode"].Value = ""; var list1 = new ValueList(); DataTable ds = PublicServer.GetData("com.steering.mes.port.vrp.FrmPhyOutsourcing.doQueryPhyCodeP", new object[] { e.Cell.Value }, ob); foreach (DataRow row in ds.Rows) { list1.ValueListItems.Add(row["PHY_CODE"].ToString(), row["PHY_NAME"].ToString()); } ultraGrid2.ActiveRow.Cells["PhyCode"].ValueList = list1; } } /// /// 加载尺寸 /// /// private void doQueryPhyS() { ultraComboEditor5.DataSource = null; DataTable ds = PublicServer.GetData("com.steering.mes.port.vrp.FrmPhyOutsourcing.doQueryItemC", new object[] { }, ob); ultraComboEditor5.DataSource = ds; ultraComboEditor5.ValueMember = "ITEM_CODE_C"; } /// /// 加载方向 /// /// private void doQueryPhyF() { ultraComboEditor3.DataSource = null; DataTable ds = PublicServer.GetData("com.steering.mes.port.vrp.FrmPhyOutsourcing.doQueryItemF", new object[] { }, ob); ultraComboEditor3.DataSource = ds; ultraComboEditor3.ValueMember = "ITEM_CODE_F"; } /// /// 加载温度 /// private void doQueryPhyW() { ultraComboEditor4.DataSource = null; DataTable ds = PublicServer.GetData("com.steering.mes.port.vrp.FrmPhyOutsourcing.doQueryItemW", new object[] { }, ob); ultraComboEditor4.DataSource = ds; ultraComboEditor4.ValueMember = "ITEM_CODE_W"; } private void ultraGrid2_InitializeRow(object sender, InitializeRowEventArgs e) { var list1 = new ValueList(); DataTable ds = PublicServer.GetData("com.steering.mes.port.vrp.FrmPhyOutsourcing.doQueryPhyCodeP", new object[] {e.Row.Cells["PhyCodeMin"].Value}, ob); foreach (DataRow row in ds.Rows) { list1.ValueListItems.Add(row["PHY_CODE"].ToString(), row["PHY_NAME"].ToString()); } e.Row.Cells["PhyCode"].ValueList = list1; } private object ConvertDataType(Type type, object objValue) { if (type == typeof(bool)) { bool result; if (bool.TryParse(objValue.ToString(), out result)) { return result; } else { return false; } } else if (type == typeof(bool?)) { bool result; if (bool.TryParse(objValue.ToString(), out result)) { return result; } else { return null; } } else if (type == typeof(int?)) { if (objValue.ToString2() == "") { return null; } else { return int.Parse(objValue.ToString()); } } else if (type == typeof(long?)) { if (objValue.ToString2() == "") { return null; } else { return long.Parse(objValue.ToString()); } } else if (type == typeof(short?)) { if (objValue.ToString2() == "") { return null; } else { return short.Parse(objValue.ToString()); } } else if (type == typeof(float?)) { if (objValue.ToString2() == "") { return null; } else { return float.Parse(objValue.ToString()); } } else if (type == typeof(double?)) { if (objValue.ToString2() == "") { return null; } else { return double.Parse(objValue.ToString()); } } else if (type == typeof(decimal?)) { if (objValue.ToString2() == "") { return null; } else { return decimal.Parse(objValue.ToString()); } } else if (type == typeof(DateTime?)) { if (objValue.ToString2() == "") { return null; } else { return DateTime.Parse(objValue.ToString()); } } else { return objValue == null ? "" : objValue.ToString(); } } } }