using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Windows.Forms; using CoreFS.CA06; using Core.Mes.Client.Comm.Tool; using Infragistics.Win.UltraWinEditors; using Core.StlMes.Client.Qcm; using Core.Mes.Client.Comm.Server; using Infragistics.Win.UltraWinGrid; using CoreFS.SA06; using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Format; using System.Reflection; namespace Core.StlMes.Client.SaleOrder.Control { public partial class CraftOrdFdWicCtrl : UserControl { private OpeBase _ob; UltraComboEditor Wics = new UltraComboEditor(); private string ordLnPk = ""; private string designKey = ""; public CraftOrdFdWicCtrl(System.Windows.Forms.Control container, string ordLnPk, string designKey, OpeBase ob) { InitializeComponent(); _ob = ob; this.ordLnPk = ordLnPk; this.designKey = designKey; container.Controls.Add(this); this.Dock = DockStyle.Fill; LoadBaseData(); } private void LoadBaseData() { UltraComboEditor ultraComPsc = new UltraComboEditor(); UltraComboEditor ultraComProcess = new UltraComboEditor(); UltraComboEditor ultraComJG = new UltraComboEditor(); UltraComboEditor cmbProBigType = new UltraComboEditor(); this.Controls.Add(ultraComPsc); this.Controls.Add(ultraComProcess); this.Controls.Add(ultraComJG); this.Controls.Add(cmbProBigType); ultraComPsc.Visible = false; ultraComProcess.Visible = false; ultraComJG.Visible = false; cmbProBigType.Visible = false; this.Controls.Add(Wics); Wics.Visible = false; //绑定数据源 产品规范描述 QcmBaseCommon.InitDropUltraComEditor(ultraComPsc, "com.steering.pss.qcm.ComBaseQuery.getPsc", "PscDesc", _ob, false); //不可编辑 UltraComboEditor cmbWtr = new UltraComboEditor(); cmbWtr.DropDownListWidth = -1; this.Controls.Add(cmbWtr); cmbWtr.Visible = false; ClsBaseInfo.FillWtrExpress(cmbWtr, _ob, true); entityGrid1.DisplayLayout.Bands[0].Columns["Formula"].EditorComponent = cmbWtr; entityGrid1.DisplayLayout.Bands[0].Columns["Formula"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList; QcmBaseQuery.NitializeProductBigType(cmbProBigType, false, _ob); ClsBaseInfo.SetComboItemHeight(cmbProBigType); ClsBaseInfo.FillComBaseInfo(ultraComboEditor3, "4107", _ob, false); ((DataTable)ultraComboEditor3.DataSource).DefaultView.Sort = "BASECODE ASC"; } /// /// 查询质量设计水压 /// /// public void Query() { CraftOrdDesignStdWicEntityBindingSource.Clear(); DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CraftOrdFdWic.queryM", new object[]{ ordLnPk }, _ob); GridHelper.CopyDataToDatatable(dt, dataTable1, true); } public void Clear() { this.CraftOrdDesignStdWicEntityBindingSource.Clear(); } public void Save() { List parms = new List(); var mRow = ultraGrid1.Rows.Where(a => a.GetValue("Chk") == "True").FirstOrDefault(); var rows = entityGrid1.Rows.Where(a => a.GetValue("Chk") == "True"); if (mRow == null && rows.Count() == 0) { MessageUtil.ShowWarning("请选择一条记录!"); return; } string mscPline = ultraGrid1.ActiveRow.GetValue("MSC_PLINE"); string processCode = ultraGrid1.ActiveRow.GetValue("PROCESS_CODE"); string wic = ultraGrid1.ActiveRow.GetValue("WIC"); foreach (var row in rows) { var parm = EntityHelper.CopyEntity(row.ListObject); if (parm.PressureY == "" && parm.Pressure == "" && parm.Formula == "") { MessageUtil.ShowWarning("请输入试验压力或者试验压力公式"); return; } if (parm.OutputStyle == "") { MessageUtil.ShowWarning("请选择工艺文件输出方式"); return; } string formula = parm.Formula.Replace("f", "1").Replace("YS", "1").Replace("TS", "1").Replace("D", "2").Replace("t", "1"); if (!parm.Formula.Equals("") && formula.CompileFormula() == null) { MessageUtil.ShowWarning("公式不合法,请重新输入"); return; } if (parm.SaveTime.Equals("")) { MessageUtil.ShowWarning("请输入保压时间"); return; } if ((parm.Pressure != "" || parm.PressureY != "") && parm.Formula != "") { if (parm.GetMaxvalue == null && parm.GetMinvalue == null) { MessageUtil.ShowWarning("请选择取大值或取小值"); return; } } parm.CreateName = CoreUserInfo.UserInfo.GetUserName(); parm.UpdateName = CoreUserInfo.UserInfo.GetUserName(); parm.DeleteName = CoreUserInfo.UserInfo.GetUserName(); parm.SpeclFl = "2"; parm.DesginKey = designKey; parm.OrdLnPk = ordLnPk; parm.WicMemo = ultraGrid1.ActiveRow.GetValue("WIC_MEMO"); parm.MscPline = ultraGrid1.ActiveRow.GetValue("MSC_PLINE"); parm.ProcessCode = ultraGrid1.ActiveRow.GetValue("PROCESS_CODE"); parm.Wic = ultraGrid1.ActiveRow.GetValue("WIC"); parms.Add(parm); } if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == DialogResult.No) { return; } List jsons = new List(); foreach (var craftOrdFdWicEntity in parms) { jsons.Add(JSONFormat.Format(craftOrdFdWicEntity)); } string chkMscPline = mRow == null ? "" : mRow.GetValue("MSC_PLINE"); string chkProcessCode = mRow == null ? "" : mRow.GetValue("PROCESS_CODE"); string chkMemo = mRow == null ? "" : mRow.GetValue("WIC_MEMO"); ServerHelper.SetData("com.steering.pss.sale.order.CraftOrdFdWic.save", new object[] { jsons, ordLnPk, chkMscPline, chkProcessCode, chkMemo }, _ob); MessageUtil.ShowTips("保存成功!"); Relocate(mscPline, processCode, wic); } public void Delete() { List parms = new List(); var mRow = ultraGrid1.Rows.Where(a => a.GetValue("CHK") == "True").FirstOrDefault(); var rows = entityGrid1.Rows.Where(a => a.GetValue("Chk") == "True"); if (mRow == null && rows.Count() == 0) { MessageUtil.ShowWarning("请选择一条记录!"); return; } string mscPline = ultraGrid1.ActiveRow.GetValue("MSC_PLINE"); string processCode = ultraGrid1.ActiveRow.GetValue("PROCESS_CODE"); string wic = ultraGrid1.ActiveRow.GetValue("WIC"); foreach (var row in rows) { var parm = EntityHelper.CopyEntity(row.ListObject); parm.CreateName = CoreUserInfo.UserInfo.GetUserName(); parm.UpdateName = CoreUserInfo.UserInfo.GetUserName(); parm.DeleteName = CoreUserInfo.UserInfo.GetUserName(); parm.SpeclFl = "2"; parm.DesginKey = designKey; parms.Add(parm); } if (MessageUtil.ShowYesNoAndQuestion("是否确认删除?") == DialogResult.No) { return; } List jsons = new List(); foreach (var craftOrdDesignStdWicEntity in parms) { jsons.Add(JSONFormat.Format(craftOrdDesignStdWicEntity)); } string parmMscPline = mRow == null ? "" : mRow.GetValue("MSC_PLINE"); string parmProcessCode = mRow == null ? "" : mRow.GetValue("PROCESS_CODE"); ServerHelper.SetData("com.steering.pss.sale.order.CraftOrdFdWic.delete", new object[] { jsons, ordLnPk, parmMscPline, parmProcessCode }, _ob); MessageUtil.ShowTips("删除成功!"); Relocate(mscPline, processCode, wic); } public void CopyNkStd() { var mRow = ultraGrid1.Rows.Where(a => a.GetValue("CHK") == "True").FirstOrDefault(); if (mRow == null) { MessageUtil.ShowWarning("请选择一条水压标准索引码!"); return; } if (mRow.GetValue("WIC") == "") { MessageUtil.ShowWarning("请选择一条水压标准索引码!"); return; } if (MessageUtil.ShowYesNoAndQuestion("是否确认复制内控索引码" + mRow.GetValue("WIC") + "?") == DialogResult.No) { return; } ServerHelper.SetData("com.steering.pss.sale.order.CraftOrdFdWic.copyNkStd", new object[] { designKey, ordLnPk, mRow.GetValue("MSC_PLINE"), mRow.GetValue("PROCESS_CODE"), mRow.GetValue("WIC") }, _ob); MessageUtil.ShowTips("复制成功!"); Query(); } private void GridEdite(UltraGridRow row) { 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 == "Chk") continue; if (cell.Column.CellActivation == Activation.AllowEdit) { cell.Activation = Activation.ActivateOnly; } } } } private void entityGrid1_CellChange(object sender, CellEventArgs e) { e.Cell.Row.Update(); GridEdite(e.Cell.Row); if (e.Cell.Column.Key == "PressureY") { if (e.Cell.Value.ToString() != "") { //英制压力转公制压力系数为0.00689476 e.Cell.Row.Cells["Pressure"].Value = Math.Round(double.Parse(e.Cell.Value.ToString()) * 0.00689476, 2); } else { e.Cell.Row.Cells["Pressure"].Value = 0; } } else if (e.Cell.Column.Key == "Pressure") { if (e.Cell.Value.ToString() != "") { if (double.Parse(e.Cell.Value.ToString()) > 6894.76) { MessageUtil.ShowWarning("公制压力上限为68900"); e.Cell.Row.Cells["Pressure"].Value = 6894.76; } //公制压力转英制压力系数为14.5 e.Cell.Row.Cells["PressureY"].Value = Math.Round(double.Parse(e.Cell.Value.ToString()) / 0.00689476, 2); } else { e.Cell.Row.Cells["PressureY"].Value = 0; } } } private void Relocate(string mscPline, string processCode, string pic) { Query(); var mRow = ultraGrid1.Rows.Where(a => a.GetValue("MSC_PLINE") == mscPline && a.GetValue("PROCESS_CODE") == processCode && a.GetValue("WIC") == pic).FirstOrDefault(); if (mRow != null) { mRow.Activate(); } } private void entityGrid1_AfterRowInsert(object sender, RowEventArgs e) { var mRow = ultraGrid1.ActiveRow; e.Row.SetValue("mscPline", mRow.GetValue("MSC_PLINE")); e.Row.SetValue("processCode", mRow.GetValue("PROCESS_CODE")); e.Row.SetValue("processDesc", mRow.GetValue("PROCESS_DESC")); e.Row.SetValue("wic", mRow.GetValue("WIC")); e.Row.Cells["GetMaxvalue"].Value = true; e.Row.Cells["GetMinvalue"].Value = false; e.Row.Cells["CraftSource"].Value = "1"; e.Row.Cells["SpeclFl"].Value = "2"; e.Row.Cells["OrdLnPk"].Value = ordLnPk; } private void ultraTextEditor1_EditorButtonClick(object sender, EditorButtonEventArgs e) { } private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e) { } private void ultraGrid1_AfterRowActivate(object sender, EventArgs e) { var mRow = ultraGrid1.ActiveRow; string wic = mRow.GetValue("WIC"); string mscPline = mRow.GetValue("MSC_PLINE"); string processCode = mRow.GetValue("PROCESS_CODE"); this.CraftOrdDesignStdWicEntityBindingSource.DataSource = EntityHelper.GetData( "com.steering.pss.sale.order.CraftOrdFdWic.query", new object[] { ordLnPk, mscPline, processCode, wic }, _ob); foreach (var row in entityGrid1.Rows) { GridEdite(row); } } private void ultraTextEditor2_EditorButtonClick(object sender, EditorButtonEventArgs e) { if (ultraGrid1.ActiveCell.Column.Key == "MSC_PLINE") { if (entityGrid1.Rows.Count != 0) { MessageUtil.ShowWarning("已维护首日检数据,不能修改!"); } else { UltraGridRow row = ultraGrid1.ActiveRow; string key = ultraGrid1.ActiveCell.Column.Key; DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CraftOrdFdWic.getMscPlineProcess", new object[] { designKey }, _ob); dt.Columns["MSC_PLINE"].Caption = "制程号"; dt.Columns["WHOLE_BACKLOG"].Caption = "全程途径码"; dt.Columns["WHOLE_BACKLOG_DESC"].Caption = "全程途径描述"; dt.Columns["PROCESS_DESC"].Caption = "工序"; BaseInfoPopup popup = new BaseInfoPopup(dt, "MSC_PLINE", "PROCESS_CODE"); GridHelper.RefreshAndAutoSize(popup.UltraGrid1); popup.LabelTextBox1.Caption = "制程号"; if (popup.ShowDialog() == DialogResult.OK) { row.SetValue("MSC_PLINE", popup.ChoicedRow.GetValue("MSC_PLINE")); row.SetValue("PROCESS_DESC", popup.ChoicedRow.GetValue("PROCESS_DESC")); row.SetValue("PROCESS_CODE", popup.ChoicedRow.GetValue("PROCESS_CODE")); row.SetValue("WIC", popup.ChoicedRow.GetValue("WIC")); row.Update(); } } } } private void entityGrid1_BeforeRowInsert(object sender, BeforeRowInsertEventArgs e) { if (ultraGrid1.ActiveRow == null || ultraGrid1.ActiveRow.GetValue("WIC") == "") { e.Cancel = true; } } private void ultraGrid1_CellChange(object sender, CellEventArgs e) { e.Cell.Row.Update(); if (e.Cell.Column.Key == "CHK") { UltraGridRow chkRow = e.Cell.Row; foreach (UltraGridRow row in ultraGrid1.Rows) { if (row.Cells["CHK"].Value.ToString() == "True" && row != chkRow) { row.Cells["CHK"].Value = "False"; row.Update(); } } } } private void ultraGrid1_ClickCellButton(object sender, CellEventArgs e) { } /// /// 复制 /// public void Copy() { var chkRows = entityGrid1.Rows.Where(a => a.GetValue("chk") == "True"); if (chkRows.Count() == 0) { MessageUtil.ShowWarning("请选择记录后,再进行操作!"); return; } ultraGrid1.UpdateData(); DataTable copyTable = CreateTableByEntity((CraftOrdFdWicEntity)chkRows.FirstOrDefault().ListObject); foreach (UltraGridRow row in entityGrid1.Rows) { if (row.GetValue("Chk") != "True") continue; DataRow dr = copyTable.NewRow(); CopyEntityToRow((CraftOrdFdWicEntity)row.ListObject, dr); copyTable.Rows.Add(dr); } DataTable[] copyTabs = new DataTable[] { copyTable, new DataTable() }; Clipboard.SetData("Wic", copyTabs); } /// /// 粘贴 /// public void Paste() { if (ultraGrid1.ActiveRow == null || ultraGrid1.ActiveRow.GetValue("WIC") == "") { MessageUtil.ShowWarning("请选择一条成分标准索引码!"); return; } DataTable[] copyTabs = (DataTable[])Clipboard.GetData("Wic"); if (copyTabs == null) { MessageUtil.ShowWarning("没有数据,请复制后再进行操作!"); return; } DataTable copyTab = copyTabs[0]; DataTable copyTab2 = copyTabs[1]; if (copyTab == null || copyTab.Rows.Count == 0) { MessageUtil.ShowWarning("没有数据,请复制后再进行操作!"); return; } dataTable1.BeginInit(); List data = (List)CraftOrdDesignStdWicEntityBindingSource.DataSource; CraftOrdFdWicEntity activeFd = null; foreach (DataRow row in copyTab.Rows) { CraftOrdFdWicEntity fd = new CraftOrdFdWicEntity(); fd.Chk = true; CopyRowToEntity(row, fd); data.Add(fd); activeFd = fd; } CraftOrdDesignStdWicEntityBindingSource.ResetBindings(false); //CraftOrdDesignStdCicEntityBindingSource.DataSource = data; dataTable1.EndInit(); entityGrid1.UpdateData(); if (entityGrid1.Rows.Count > 0) { entityGrid1.Rows[entityGrid1.Rows.Count - 1].Activate(); } } private string GetLineName(string name) { string lineName = ""; for (int i = 0; i < name.Length; i++) { if (i == 0) { lineName += name[i]; } else { if (name[i] >= 'A' && name[i] <= 'Z') { lineName += '_'; lineName += name[i]; } else { lineName += name[i]; } } } return lineName.ToUpper(); } private string GetName(string lineName) { string[] strs = lineName.Split('_'); string name = ""; for (int i = 0; i < strs.Length; i++) { name += strs[i].Substring(0, 1).ToUpper() + strs[i].Substring(1).ToLower(); } return name; } private DataTable CreateTableByEntity(CraftOrdFdWicEntity fdEntity) { DataTable dt = new DataTable(); PropertyInfo[] srcPropertyInfos = fdEntity.GetType().GetProperties(); foreach (PropertyInfo srcPropertyInfo in srcPropertyInfos) { dt.Columns.Add(GetLineName(srcPropertyInfo.Name)); } return dt; } private void CopyEntityToRow(CraftOrdFdWicEntity fdEntity, DataRow desRow) { PropertyInfo[] pros = fdEntity.GetType().GetProperties(); foreach (PropertyInfo pro in pros) { desRow[GetLineName(pro.Name)] = pro.GetValue(fdEntity, null); } } private void CopyRowToEntity(DataRow row, CraftOrdFdWicEntity fdEntity) { PropertyInfo[] pros = fdEntity.GetType().GetProperties(); foreach (DataColumn dc in row.Table.Columns) { if (dc.ColumnName == "CREATE_TIME") continue; PropertyInfo pro = fdEntity.GetType().GetProperty(GetName(dc.ColumnName)); if (pro != null) { pro.SetValue(fdEntity, ConvertDataType(pro.PropertyType, row[dc.ColumnName].ToString()), null); } } } 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(); } } private void ultraGrid1_BeforeRowInsert(object sender, BeforeRowInsertEventArgs e) { if (ultraGrid1.Rows.Count > 0) { e.Cancel = true; } } } }