using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using Core.StlMes.Client.SaleOrder.BLL; using CoreFS.CA06; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.Qcm; using Infragistics.Win.UltraWinGrid; using Infragistics.Win.UltraWinEditors; using Core.Mes.Client.Comm.Server; using CoreFS.SA06; using Infragistics.Win; using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Format; using Core.StlMes.Client.SaleOrder.Dialog; using System.Reflection; namespace Core.StlMes.Client.SaleOrder.Control { public partial class CraftOrdFdPicCtrl : UserControl { private OpeBase _ob; private UltraComboEditor Pics = new UltraComboEditor(); public CraftOrdFdPicCtrl(System.Windows.Forms.Control container, string designKey, string ordLnPk, OpeBase ob) { InitializeComponent(); _ob = ob; this.designKey = designKey; this.ordLnPk = ordLnPk; container.Controls.Add(this); this.Dock = DockStyle.Fill; LoadBaseData(); } private void LoadBaseData() { QcmBaseCommon.InitSignMin(ultraComSignMin); QcmBaseCommon.InitSignMax(ultraComSignMax); //初始化理化检验项大类 ultraComPhyMax.DropDownListWidth = -1; QcmBaseQuery.NitializeDropDownBox(ultraComPhyMax, "com.steering.pss.qcm.ComBaseQuery.geComBasePhyRStd", "PHY_TYPE", "PHY_CODE", false, _ob); //初始化结箍名称 QcmBaseQuery.NitializeJG(ultraComJG, true, _ob); //初始化限制规格 QcmBaseCommon.InitDropUltraComEditor(ultraComSize, "com.steering.pss.qcm.ComBaseQuery.geComBaseInfo4003", "BASENAME", _ob, true); //交货标准 QcmBaseCommon.InitDropUltraComEditor(ultraComboDelivery, "com.steering.pss.qcm.ComBaseQuery.geComBaseInfo4060", "BASENAME", _ob, true); //内控标准 UltraGridBand ugc = entityGrid1.DisplayLayout.Bands[0]; //附加标准 UltraComboEditor uceAddStdCon = new UltraComboEditor(); this.Controls.Add(uceAddStdCon); uceAddStdCon.Visible = false; QcmBaseCommon.InitDropUltraComEditor(uceAddStdCon, "com.steering.pss.qcm.ComMaterial.getAddCondition", "BASENAME", _ob, false); entityGrid1.DisplayLayout.Bands[0].Columns["AddstdconCode"].EditorComponent = uceAddStdCon; entityGrid1.DisplayLayout.Bands[0].Columns["AddstdconCode"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList; ClsBaseInfo.SetComboItemHeight(uceAddStdCon); this.Controls.Add(Pics); Pics.Visible = false; //多标准选择分类 UltraComboEditor uceMultStd = new UltraComboEditor(); this.Controls.Add(uceMultStd); uceMultStd.Visible = false; QcmBaseCommon.InitDropUltraComEditor(uceMultStd, "com.steering.pss.qcm.ComMaterial.getMultStd", "BASENAME", _ob, true); entityGrid1.DisplayLayout.Bands[0].Columns["StdChoose"].EditorComponent = uceMultStd; entityGrid1.DisplayLayout.Bands[0].Columns["StdChoose"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList; ClsBaseInfo.SetComboItemHeight(uceMultStd); } private string designKey = ""; private string ordLnPk = ""; /// /// 查询质量设计理化 /// /// public void Query() { CraftOrdDesignStdPicEntityBindingSource.Clear(); DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CraftOrdFdPic.queryM", new object[] { ordLnPk }, _ob); GridHelper.CopyDataToDatatable(dt, dataTable1, true); foreach (var row in ultraGrid1.Rows) { row.Cells["SAMPLE"].Value = "维护"; row.Cells["SAMPLE"].ButtonAppearance.TextHAlign = HAlign.Center; } } private string[] _parms; public void Clear() { this.CraftOrdDesignStdPicEntityBindingSource.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 pic = ultraGrid1.ActiveRow.GetValue("PIC"); foreach (var row in rows) { var parm = EntityHelper.CopyEntity(row.ListObject); if (parm.PhyNameMax == "") { MessageUtil.ShowWarning("请选择检验项!"); row.SetCellActive("PhyNameMax"); return; } if (parm.PhyNameMin == "") { MessageUtil.ShowWarning("请选择试样组!"); row.SetCellActive("PhyNameMin"); return; } if (parm.PhyName == "") { MessageUtil.ShowWarning("请选择检验项目!"); row.SetCellActive("PhyName"); return; } if (parm.StdminSign == "=" && (parm.StdmaxSign != "" || parm.Stdmax != "")) { MessageUtil.ShowWarning("标准范围下限符号为'=',不能存在上限!"); row.SetCellActive("Stdmax"); return; } if (parm.Isjudge == true) { if (parm.StdminSign.Equals("") && parm.StdmaxSign.Equals("")) { MessageUtil.ShowWarning("请选择标准范围(默认)下限符号或者上限符号!"); row.SetCellActive("StdminSign"); return; } } if (!parm.StdminSign.Equals("") && parm.Stdmin.Equals("")) { MessageUtil.ShowWarning("请输入标准范围(默认)下限值!"); row.SetCellActive("Stdmin"); return; } if (parm.StdminSign.Equals("") && !parm.Stdmin.Equals("")) { MessageUtil.ShowWarning("请选择标准范围(默认)下限符号!"); row.SetCellActive("StdminSign"); return; } if (!parm.StdmaxSign.Equals("") && parm.Stdmax.Equals("")) { MessageUtil.ShowWarning("请输入标准范围(默认)上限值!"); row.SetCellActive("Stdmax"); return; } if (parm.StdmaxSign.Equals("") && !parm.Stdmax.Equals("")) { MessageUtil.ShowWarning("已有标准范围(默认)上限值,请选择标准范围(默认)上限符号!"); row.SetCellActive("StdmaxSign"); return; } if (parm.PhyType == false) { if (!parm.Stdmin.Equals("") && !StringUtil.IsNumber(parm.Stdmin) && !parm.StdminSign.Equals("=")) { MessageUtil.ShowWarning("标准范围(默认)下限值由数字组成!"); row.SetCellActive("Stdmin"); return; } if (!parm.Stdmax.Equals("") && !StringUtil.IsNumber(parm.Stdmax)) { MessageUtil.ShowWarning("标准范围(默认)上限值由数字组成!"); row.SetCellActive("Stdmax"); return; } } else { if (!parm.Stdmin.Equals("") && !parm.StdminSign.Equals("=") && !QcmBaseCommon.CheckCompositeFormula(parm.Stdmin)) { MessageUtil.ShowWarning("标准范围(默认)下限值,输入公式不合法,请重新输入!"); row.SetCellActive("Stdmin"); return; } if (!parm.Stdmax.Equals("") && !QcmBaseCommon.CheckCompositeFormula(parm.Stdmax)) { MessageUtil.ShowWarning("标准范围(默认)上限值,输入公式不合法,请重新输入!"); row.SetCellActive("Stdmax"); return; } } if (!parm.Stdmin.Equals("")) { if (parm.Stdmin.StartsWith(".")) parm.Stdmin = "0" + parm.Stdmin; } if (!parm.Stdmax.Equals("")) { if (parm.Stdmax.StartsWith(".")) parm.Stdmax = "0" + parm.Stdmax; } if (!parm.Stdmin.Equals("") && !parm.Stdmax.Equals("")) //&& Convert.ToDouble(stdmin) > Convert.ToDouble(stdmax) { int i = QcmBaseInfo.CheckStdData(parm.StdminSign, parm.StdmaxSign, parm.Stdmin, parm.Stdmax); if (i == 0) { MessageUtil.ShowWarning("输入的数据不完整!"); return; } if (i == 1) { MessageUtil.ShowWarning("标准范围(默认)下限值与上限值相等,上下限符号请选择<=和>=!"); row.SetCellActive("StdminSign"); return; } if (i == 2) { MessageUtil.ShowWarning("标准范围(默认)下限值不能大于上限值!"); row.SetCellActive("Stdmin"); return; } } if (parm.JudgeBasis.Equals("")) { MessageUtil.ShowWarning("判断依据不能为空!"); row.SetCellActive("JudgeBasis"); return; } if (parm.StdminSign2 == "=" && (parm.StdmaxSign2 != "" || parm.Stdmax2 != "")) { MessageUtil.ShowWarning("标准范围(二)下限符号为'=',不能存在上限!"); row.SetCellActive("Stdmax2"); return; } if (parm.StdChoose != "") //取大/小值 { if (parm.StdminSign2.Equals("") && parm.StdmaxSign2.Equals("")) { MessageUtil.ShowWarning("请选择标准范围(二)下限符号或者上限符号!"); row.SetCellActive("StdminSign2"); return; } if (!parm.StdminSign2.Equals("") && parm.Stdmin2.Equals("")) { MessageUtil.ShowWarning("请输入标准范围(二)下限值!"); row.SetCellActive("Stdmin2"); return; } if (parm.StdminSign2.Equals("") && !parm.Stdmin2.Equals("")) { MessageUtil.ShowWarning("标准范围(默认)不存在下限符号,则标准范围(二)下限不能存在值!"); row.SetCellActive("Stdmin2"); return; } if (!parm.StdmaxSign2.Equals("") && parm.Stdmax2.Equals("")) { MessageUtil.ShowWarning("请输入标准范围(二)上限值!"); row.SetCellActive("Stdmax2"); return; } if (parm.StdmaxSign2.Equals("") && !parm.Stdmax2.Equals("")) { MessageUtil.ShowWarning("标准范围(默认)不存在上限符号,则标准范围(二)上限不能存在值!"); row.SetCellActive("Stdmax2"); return; } if (parm.PhyType == false) { if (!parm.Stdmin2.Equals("") && !StringUtil.IsNumber(parm.Stdmin2) && !parm.StdminSign2.Equals("=")) { MessageUtil.ShowWarning("标准范围(二)下限值由数字组成!"); row.SetCellActive("Stdmin2"); return; } if (!parm.Stdmax2.Equals("") && !StringUtil.IsNumber(parm.Stdmax2)) { MessageUtil.ShowWarning("标准范围(二)上限值由数字组成!"); row.SetCellActive("Stdmax2"); return; } } else { if (!parm.Stdmin2.Equals("") && !parm.StdminSign2.Equals("=") && !StringUtil.IsNumber(parm.Stdmin2) && !QcmBaseCommon.CheckCompositeFormula(parm.Stdmin2)) { MessageUtil.ShowWarning("标准范围(二)下限值输入公式不合法,请重新输入!"); row.SetCellActive("Stdmin2"); return; } if (!parm.Stdmax2.Equals("") && !StringUtil.IsNumber(parm.Stdmax2) && !QcmBaseCommon.CheckCompositeFormula(parm.Stdmax2)) { MessageUtil.ShowWarning("标准范围(二)上限值输入公式不合法,请重新输入!"); row.SetCellActive("Stdmax2"); return; } } if (!parm.Stdmin2.Equals("")) { if (parm.Stdmin2.StartsWith(".")) parm.Stdmin2 = "0" + parm.Stdmin2; } if (!parm.Stdmax2.Equals("")) { if (parm.Stdmax2.StartsWith(".")) parm.Stdmax2 = "0" + parm.Stdmax2; } if (!parm.Stdmin2.Equals("") && !parm.Stdmax2.Equals("")) //&& Convert.ToDouble(stdmin2) > Convert.ToDouble(stdmax2) { int i = QcmBaseInfo.CheckStdData(parm.StdminSign2, parm.StdmaxSign2, parm.Stdmin2, parm.Stdmax2); if (i == 0) { MessageUtil.ShowWarning("输入的数据不完整!"); return; } if (i == 1) { MessageUtil.ShowWarning("标准范围(二)下限值与上限值相等,上下限符号请选择<=和>=!"); row.SetCellActive("StdminSign2"); return; } if (i == 2) { MessageUtil.ShowWarning("标准范围(二)下限值不能大于上限值!"); row.SetCellActive("Stdmin2"); return; } } } if (parm.SizeMinSign2 == "=" && (parm.SizeMaxSign2 != "" || parm.SizeMax2 != "")) { MessageUtil.ShowWarning("限制规格(一)下限符号为'=',不能存在上限!"); row.SetCellActive("SizeMax2"); return; } if (parm.SizeMinSign == "=" && (parm.SizeMaxSign != "" || parm.SizeMax != "")) { MessageUtil.ShowWarning("限制规格(二)下限符号为'=',不能存在上限!"); row.SetCellActive("SizeMax"); return; } if (!parm.SpecJg.Equals("") && !parm.SpecJgDesc.Equals("-1")) { if (!parm.SizeName2.Equals("") || !parm.SizeName.Equals("")) { MessageUtil.ShowWarning("接箍描述与限制规格不能同时存在!"); row.SetCellActive("SpecJg"); return; } } if (!parm.SizeName2.Equals("")) { if (parm.SizeMinSign2.Equals("") && parm.SizeMaxSign2.Equals("")) { MessageUtil.ShowWarning("请选择限制规格(一)下限符号或者上限符号!"); row.SetCellActive("SizeMinSign2"); return; } if (!parm.SizeMinSign2.Equals("") && parm.SizeMin2.Equals("")) { MessageUtil.ShowWarning("存在限制规格(一)下限符号,下限值不能为空!"); row.SetCellActive("SizeMin2"); return; } if (parm.SizeMinSign2.Equals("") && !parm.SizeMin2.Equals("")) { MessageUtil.ShowWarning("存在限制规格(一)下限值,下限符号不能为空!"); row.SetCellActive("SizeMinSign2"); return; } if (!parm.SizeMaxSign2.Equals("") && parm.SizeMax2.Equals("")) { MessageUtil.ShowWarning("存在限制规格(一)上限符号,上限值不能为空!"); row.SetCellActive("SizeMax2"); return; } if (parm.SizeMaxSign2.Equals("") && !parm.SizeMax2.Equals("")) { MessageUtil.ShowWarning("存在限制规格(一)上限值,上限符号不能为空!"); row.SetCellActive("SizeMaxSign2"); return; } if (!parm.SizeMin2.Equals("") && !StringUtil.IsNumber(parm.SizeMin2) && !parm.SizeMinSign2.Equals("=")) { MessageUtil.ShowWarning("限制规格(一)下限值由数字组成!"); row.SetCellActive("SizeMin2"); return; } if (!parm.SizeMax2.Equals("") && !StringUtil.IsNumber(parm.SizeMax2)) { MessageUtil.ShowWarning("限制规格(一)上限值由数字组成!"); row.SetCellActive("SizeMax2"); return; } if (!parm.SizeMin2.Equals("") && !parm.SizeMax2.Equals("")) //&& Convert.ToDouble(size_max2) < Convert.ToDouble(size_min2) { int i = QcmBaseInfo.CheckStdData(parm.SizeMinSign2, parm.SizeMaxSign2, parm.SizeMin2, parm.SizeMax2); if (i == 0) { MessageUtil.ShowWarning("输入的数据不完整!"); return; } if (i == 1) { MessageUtil.ShowWarning("限制规格(一)下限值与上限值相等,上下限符号请选择<=和>=!"); row.SetCellActive("SizeMinSign2"); return; } if (i == 2) { MessageUtil.ShowWarning("限制规格(一)下限值不能大于上限值!"); row.SetCellActive("SizeMin2"); return; } } } else { if (parm.SizeMaxSign2 != "" || parm.SizeMinSign2 != "" || parm.SizeMin2 != "" || parm.SizeMax2 != "") { MessageUtil.ShowWarning("限制规格(一)描述不存在!"); row.SetCellActive("SizeCode2"); return; } } if (!parm.SizeMin2.Equals("")) { if (parm.SizeMin2.StartsWith(".")) parm.SizeMin2 = "0" + parm.SizeMin2; } if (!parm.SizeMax2.Equals("")) { if (parm.SizeMax2.StartsWith(".")) parm.SizeMax2 = "0" + parm.SizeMax2; } if (!parm.SizeName.Equals("")) { if (parm.SizeMinSign.Equals("") && parm.SizeMaxSign.Equals("")) { MessageUtil.ShowWarning("限制规格(二)下限符号与上限符号必须存在一项!"); row.SetCellActive("SizeMinSign"); return; } if (!parm.SizeMinSign.Equals("") && parm.SizeMin.Equals("")) { MessageUtil.ShowWarning("存在限制规格(二)下限符号,下限值不能为空!"); row.SetCellActive("SizeMin"); return; } if (parm.SizeMinSign.Equals("") && !parm.SizeMin.Equals("")) { MessageUtil.ShowWarning("存在限制规格(二)下限值,下限符号不能为空!"); row.SetCellActive("SizeMinSign"); return; } if (!parm.SizeMaxSign.Equals("") && parm.SizeMax.Equals("")) { MessageUtil.ShowWarning("存在限制规格(二)上限符号,上限值不能为空!"); row.SetCellActive("SizeMax"); return; } if (parm.SizeMaxSign.Equals("") && !parm.SizeMax.Equals("")) { MessageUtil.ShowWarning("存在限制规格(二)上限值,上限符号不能为空!"); row.SetCellActive("SizeMaxSign"); return; } if (!parm.SizeMax.Equals("") && !StringUtil.IsNumber(parm.SizeMax)) { MessageUtil.ShowWarning("限制规格(二)上限值由数字组成!"); row.SetCellActive("SizeMax"); return; } if (!parm.SizeMin.Equals("") && !StringUtil.IsNumber(parm.SizeMin) && !parm.SizeMinSign.Equals("=")) { MessageUtil.ShowWarning("限制规格(二)下限值由数字组成!"); row.SetCellActive("SizeMin"); return; } if (!parm.SizeMin.Equals("") && !parm.SizeMax.Equals("")) //&& Convert.ToDouble(size_max) < Convert.ToDouble(size_min) { int i = QcmBaseInfo.CheckStdData(parm.SizeMinSign, parm.SizeMaxSign, parm.SizeMin, parm.SizeMax); if (i == 0) { MessageUtil.ShowWarning("输入的数据不完整!"); return; } if (i == 1) { MessageUtil.ShowWarning("限制规格(二)下限值与上限值相等,上下限符号请选择<=和>=!"); row.SetCellActive("SizeMinSign"); return; } if (i == 2) { MessageUtil.ShowWarning("限制规格(二)下限值不能大于上限值!"); row.SetCellActive("SizeMin"); return; } } } else { if (parm.SizeMaxSign != "" || parm.SizeMinSign != "" || parm.SizeMin != "" || parm.SizeMax != "") { MessageUtil.ShowWarning("限制规格(二)描述不存在!"); row.SetCellActive("SizeCode"); return; } } if (!parm.SizeName2.Equals("") && !parm.SizeName.Equals("") && parm.SizeName.Equals(parm.SizeName2)) { MessageUtil.ShowWarning("限制规格(一)与限制规格(二)描述不能相同!"); row.SetCellActive("SizeCode"); return; } if (!parm.SizeMax.Equals("")) { if (parm.SizeMax.StartsWith(".")) parm.SizeMax = "0" + parm.SizeMax; } if (!parm.SizeMin.Equals("")) { if (parm.SizeMin.StartsWith(".")) parm.SizeMin = "0" + parm.SizeMin; } if (parm.Addcondition != "") //存在附加标准约束 { if (parm.AddstdconCode == "") { MessageUtil.ShowWarning("请选择附加标准项!"); row.SetCellActive("AddstdconCode"); return; } if (parm.AddstdMinSign == "=" && (parm.AddstdMaxSign != "" || parm.AddstdMax != "")) { MessageUtil.ShowWarning("附加标准范围下限符号为'=',不能存在上限!"); row.SetCellActive("AddstdMax"); return; } if (parm.AddstdMinSign.Equals("") && parm.AddstdMaxSign.Equals("")) { MessageUtil.ShowWarning("请选择附加标准范围下限符号或者上限符号!"); row.SetCellActive("AddstdMinSign"); return; } if (!parm.AddstdMinSign.Equals("") && parm.AddstdMin.Equals("")) { MessageUtil.ShowWarning("请输入附加标准范围下限值!"); row.SetCellActive("AddstdMin"); return; } if (parm.AddstdMinSign.Equals("") && !parm.AddstdMin.Equals("")) { MessageUtil.ShowWarning("请选择附加标准范围下限符号!"); row.SetCellActive("AddstdMinSign"); return; } if (!parm.AddstdMinSign.Equals("") && parm.AddstdMin.Replace("Value", "1").CompileFormula() == null) { MessageUtil.ShowWarning("附加标准范围下限值,只能包含附加标准符号'Value'!"); row.SetCellActive("AddstdMin"); return; } if (!parm.AddstdMaxSign.Equals("") && parm.AddstdMax.Equals("")) { MessageUtil.ShowWarning("请输入附加标准范围上限值!"); row.SetCellActive("AddstdMax"); return; } if (!parm.AddstdMaxSign.Equals("") && parm.AddstdMax.Replace("Value", "1").CompileFormula() == null) { MessageUtil.ShowWarning("附加标准范围上限值,只能包含附加标准符号'Value'!"); row.SetCellActive("AddstdMax"); return; } if (parm.AddstdMaxSign.Equals("") && !parm.AddstdMax.Equals("")) { MessageUtil.ShowWarning("已有附加标准范围上限值,请选择附加标准范围上限符号!"); row.SetCellActive("AddstdMaxSign"); return; } if (!parm.AddstdMin.Equals("")) { if (parm.AddstdMin.StartsWith(".")) parm.AddstdMin = "0" + parm.AddstdMin; } if (!parm.AddstdMax.Equals("")) { if (parm.AddstdMax.StartsWith(".")) parm.AddstdMax = "0" + parm.AddstdMax; } if (!parm.AddstdMin.Equals("") && !parm.AddstdMax.Equals(""))//&& Convert.ToDouble(addstd_min) > Convert.ToDouble(addstd_max) { int i = QcmBaseInfo.CheckStdData(parm.AddstdMinSign, parm.AddstdMaxSign, parm.AddstdMin, parm.AddstdMax); if (i == 0) { MessageUtil.ShowWarning("输入的数据不完整!"); return; } if (i == 1) { MessageUtil.ShowWarning("附加标准范围下限值与上限值相等,上下限符号请选择<=和>=!"); row.SetCellActive("AddstdMinSign"); return; } if (i == 2) { MessageUtil.ShowWarning("附加标准范围下限值不能大于上限值!"); row.SetCellActive("AddstdMin"); return; } } } string[] strJudgeBiasis = new string[] { "A", "B", "C", "D" }; if (!strJudgeBiasis.Contains(parm.JudgeBasis)) //中文就是从交付或内控复制过来的,特殊处理。 { if (parm.JudgeBasis.Equals("最小值")) parm.JudgeBasis = "A"; else if (parm.JudgeBasis.Equals("最大值")) parm.JudgeBasis = "B"; else if (parm.JudgeBasis.Equals("平均值")) parm.JudgeBasis = "C"; else parm.JudgeBasis = "D"; } 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.PicMemo = ultraGrid1.ActiveRow.GetValue("PIC_MEMO"); parm.MscPline = ultraGrid1.ActiveRow.GetValue("MSC_PLINE"); parm.ProcessCode = ultraGrid1.ActiveRow.GetValue("PROCESS_CODE"); parm.Pic = ultraGrid1.ActiveRow.GetValue("PIC"); parms.Add(parm); } if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == DialogResult.No) { return; } List jsons = new List(); foreach (var craftOrdDesignStdPicEntity in parms) { jsons.Add(JSONFormat.Format(craftOrdDesignStdPicEntity)); } string chkMscPline = mRow == null ? "" : mRow.GetValue("MSC_PLINE"); string chkProcessCode = mRow == null ? "" : mRow.GetValue("PROCESS_CODE"); string chkMemo = mRow == null ? "" : mRow.GetValue("PIC_MEMO"); ServerHelper.SetData("com.steering.pss.sale.order.CraftOrdFdPic.save", new object[] { jsons, ordLnPk, mscPline, processCode, pic, chkMscPline, chkProcessCode, chkMemo }, _ob); MessageUtil.ShowTips("保存成功!"); Relocate(mscPline, processCode, pic); } public void CopyNkStd() { var mRow = ultraGrid1.Rows.Where(a=>a.GetValue("CHK") == "True").FirstOrDefault(); if (mRow == null) { MessageUtil.ShowWarning("请选择一条理化标准索引码!"); return; } if (mRow.GetValue("PIC") == "") { MessageUtil.ShowWarning("请选择一条理化标准索引码!"); return; } if (MessageUtil.ShowYesNoAndQuestion("是否确认复制内控索引码" + mRow.GetValue("PIC") + "?") == DialogResult.No) { return; } ServerHelper.SetData("com.steering.pss.sale.order.CraftOrdFdPic.copyNkStd", new object[] { designKey, ordLnPk, mRow.GetValue("MSC_PLINE"), mRow.GetValue("PROCESS_CODE"), mRow.GetValue("PIC") }, _ob); MessageUtil.ShowTips("复制成功!"); Query(); } public void Delete() { List parms = new List(); var pRow = ultraGrid1.Rows.Where(a=>a.GetValue("CHK") == "True").FirstOrDefault(); var rows = entityGrid1.Rows.Where(a => a.GetValue("Chk") == "True"); if (pRow == null && rows.Count() == 0) { MessageUtil.ShowWarning("请选择一条记录!"); return; } string mscPline = ultraGrid1.ActiveRow.GetValue("MSC_PLINE"); string processCode = ultraGrid1.ActiveRow.GetValue("PROCESS_CODE"); string pic = ultraGrid1.ActiveRow.GetValue("PIC"); 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 craftOrdDesignStdPicEntity in parms) { jsons.Add(JSONFormat.Format(craftOrdDesignStdPicEntity)); } string parmMscPline = pRow == null ? "" : pRow.GetValue("MSC_PLINE"); string parmProcessCode = pRow == null ? "" : pRow.GetValue("PROCESS_CODE"); ServerHelper.SetData("com.steering.pss.sale.order.CraftOrdFdPic.Delete", new object[] { ordLnPk, parmMscPline, parmProcessCode, jsons }, _ob); MessageUtil.ShowTips("删除成功!"); Relocate(mscPline, processCode, pic); } 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("PIC") == pic).FirstOrDefault(); if (mRow != null) { mRow.Activate(); } } private void entityGrid1_CellChange(object sender, CellEventArgs e) { e.Cell.Row.Update(); var ugr = e.Cell.Row; string deliverystate = ugr.Cells["DELIVERYSTATE"].Value.ToString(); ugr.Cells["SizeName2"].Value = ugr.Cells["SizeCode2"].Text; ugr.Cells["SizeName"].Value = ugr.Cells["SizeCode"].Text; ugr.Cells["SpecJgDesc"].Value = ugr.Cells["SpecJg"].Text; GridEdite(e.Cell.Row); } 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_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("pic", mRow.GetValue("PIC")); //将增加行的是否必选项置为默认选择 和 复合元素选择项置为默认不选 e.Row.Cells["PhyType"].Value = false; e.Row.Cells["BilletSample"].Value = false; e.Row.Cells["JudgeBasis"].Value = "D"; e.Row.Cells["IsJudge"].Value = true; e.Row.Cells["IsQuote"].Value = true; e.Row.Cells["Ischeck"].Value = true; e.Row.Cells["CraftSource"].Value = "1"; e.Row.Cells["SpeclFl"].Value = "2"; e.Row.Cells["OrdLnPk"].Value = ordLnPk; } private void ultraTextEditor3_EditorButtonClick(object sender, EditorButtonEventArgs e) { UltraGridRow row = entityGrid1.ActiveRow; string key = entityGrid1.ActiveCell.Column.Key; //if (key == "MscPline") //{ // DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CraftOrdFdPic.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("MscPline", popup.ChoicedRow.GetValue("MSC_PLINE")); // row.SetValue("ProcessDesc", popup.ChoicedRow.GetValue("PROCESS_DESC")); // row.SetValue("ProcessCode", popup.ChoicedRow.GetValue("PROCESS_CODE")); // } //} //else if (key == "ProcessDescC") //{ // string mscPline = entityGrid1.ActiveRow.GetValue("MscPline"); // DataTable dt = _designMscPlPrcBLL.queryProcess(designKey, mscPline); // dt.Columns["PROCESS_DESC"].Caption = "工序"; // dt.Columns["PROCESS_DESC_C"].Caption = "二级工序"; // BaseInfoPopup popup = new BaseInfoPopup(dt, "PROCESS_DESC_C", "PROCESS_CODE", "PROCESS_CODE_C"); // popup.LabelTextBox1.Caption = "二级工序"; // if (popup.ShowDialog() == DialogResult.OK) // { // row.SetValue("ProcessDescC", popup.ChoicedRow.GetValue("PROCESS_DESC_C")); // row.SetValue("ProcessCodeC", popup.ChoicedRow.GetValue("PROCESS_CODE_C")); // row.SetValue("ProcessDesc", popup.ChoicedRow.GetValue("PROCESS_DESC")); // row.SetValue("ProcessCode", popup.ChoicedRow.GetValue("PROCESS_CODE")); // } //} //else if (key == "Pic") //{ // string mscPline = entityGrid1.ActiveRow.GetValue("MscPline"); // string processCode = entityGrid1.ActiveRow.GetValue("ProcessCode"); // DataTable dt = _designMscPlPrcBLL.queryProcessNkIndex(designKey, mscPline, processCode); // dt.Columns["PIC"].Caption = "理化内控索引码"; // BaseInfoPopup popup = new BaseInfoPopup(dt, "PIC", "CIC", "SIC", "DIC", "WIC", "GIC"); // popup.LabelTextBox1.Caption = "理化内控索引码"; // if (popup.ShowDialog() == DialogResult.OK) // { // row.SetValue("Pic", popup.ChoicedRow.GetValue("PIC")); // } //} if (entityGrid1.ActiveCell.Column.Key == "PhyNameMax") { DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseQuery.geComBasePhyRStd", null, _ob); dt.Columns["PHY_TYPE"].Caption = "检验大项"; BaseInfoPopup baseInfoPopup = new BaseInfoPopup(dt, "PHY_TYPE", "PHY_CODE"); baseInfoPopup.Text = "检验大项"; baseInfoPopup.LabelTextBox1.Caption = "检验大项"; baseInfoPopup.Shown += new EventHandler((c, d) => { IQueryable rows = baseInfoPopup.UltraGrid1.Rows.AsQueryable().Where( a => a.GetValue("PHY_CODE") == entityGrid1.ActiveRow.GetValue("PhyCodeMax")); if (rows.Count() > 0) { rows.First().Activate(); } }); if (baseInfoPopup.ShowDialog() == System.Windows.Forms.DialogResult.OK) { entityGrid1.ActiveRow.SetValue("PhyNameMax", baseInfoPopup.ChoicedRow.GetValue("PHY_TYPE")); entityGrid1.ActiveRow.SetValue("PhyCodeMax", baseInfoPopup.ChoicedRow.GetValue("PHY_CODE")); entityGrid1.ActiveRow.SetValue("PhyNameMin", ""); entityGrid1.ActiveRow.SetValue("PhyCodeMin", ""); entityGrid1.ActiveRow.SetValue("PhyName", ""); entityGrid1.ActiveRow.SetValue("PhyCode", ""); entityGrid1.ActiveRow.SetValue("ItemNameF", ""); entityGrid1.ActiveRow.SetValue("ItemCodeF", ""); entityGrid1.ActiveRow.SetValue("ItemNameS", ""); entityGrid1.ActiveRow.SetValue("ItemCodeS", ""); entityGrid1.ActiveRow.SetValue("ItemNameW", ""); entityGrid1.ActiveRow.SetValue("ItemCodeW", ""); } } else if (entityGrid1.ActiveCell.Column.Key == "PhyNameMin") { string phyCodeMax = entityGrid1.ActiveRow.GetValue("PhyCodeMax"); if (phyCodeMax == "") { MessageUtil.ShowWarning("请选检验大项!"); return; } DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseQuery.geComBasePhyC", new object[] { phyCodeMax }, _ob); dt.Columns["PHY_TYPE"].Caption = "试样组"; BaseInfoPopup baseInfoPopup = new BaseInfoPopup(dt, "PHY_TYPE", "PHY_CODE"); baseInfoPopup.Text = "试样组"; baseInfoPopup.LabelTextBox1.Caption = "试样组"; baseInfoPopup.Shown += new EventHandler((c, d) => { IQueryable rows = baseInfoPopup.UltraGrid1.Rows.AsQueryable().Where( a => a.GetValue("PHY_CODE") == entityGrid1.ActiveRow.GetValue("PhyCodeMin")); if (rows.Count() > 0) { rows.First().Activate(); } }); if (baseInfoPopup.ShowDialog() == System.Windows.Forms.DialogResult.OK) { entityGrid1.ActiveRow.SetValue("PhyNameMin", baseInfoPopup.ChoicedRow.GetValue("PHY_TYPE")); entityGrid1.ActiveRow.SetValue("PhyCodeMin", baseInfoPopup.ChoicedRow.GetValue("PHY_CODE")); entityGrid1.ActiveRow.SetValue("PhyName", ""); entityGrid1.ActiveRow.SetValue("PhyCode", ""); entityGrid1.ActiveRow.SetValue("ItemNameF", ""); entityGrid1.ActiveRow.SetValue("ItemCodeF", ""); entityGrid1.ActiveRow.SetValue("ItemNameS", ""); entityGrid1.ActiveRow.SetValue("ItemCodeS", ""); entityGrid1.ActiveRow.SetValue("ItemNameW", ""); entityGrid1.ActiveRow.SetValue("ItemCodeW", ""); } } else if (entityGrid1.ActiveCell.Column.Key == "PhyName") { string phyCodeMax = entityGrid1.ActiveRow.GetValue("PhyCodeMax"); string phyCodeMin = entityGrid1.ActiveRow.GetValue("PhyCodeMin"); if (phyCodeMax == "") { MessageUtil.ShowWarning("请选择检验大项"); entityGrid1.ActiveRow.Cells["PhyNameMax"].Activate(); return; } else if (phyCodeMin == "") { MessageUtil.ShowWarning("请选择试样组"); entityGrid1.ActiveRow.Cells["PhyNameMin"].Activate(); return; } DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseQuery.geComBasePhy", new object[] { phyCodeMax, phyCodeMin }, _ob); dt.Columns["PHY_NAME"].Caption = "检验项"; BaseInfoPopup baseInfoPopup = new BaseInfoPopup(dt, "PHY_NAME", "PHY_CODE"); baseInfoPopup.Text = "检验项"; baseInfoPopup.LabelTextBox1.Caption = "检验项"; baseInfoPopup.Shown += new EventHandler((c, d) => { IQueryable rows = baseInfoPopup.UltraGrid1.Rows.AsQueryable().Where( a => a.GetValue("PHY_CODE") == entityGrid1.ActiveRow.GetValue("PhyCode")); if (rows.Count() > 0) { rows.First().Activate(); } }); if (baseInfoPopup.ShowDialog() == System.Windows.Forms.DialogResult.OK) { entityGrid1.ActiveRow.SetValue("PhyName", baseInfoPopup.ChoicedRow.GetValue("PHY_NAME")); entityGrid1.ActiveRow.SetValue("PhyCode", baseInfoPopup.ChoicedRow.GetValue("PHY_CODE")); entityGrid1.ActiveRow.SetValue("ItemNameW", ""); entityGrid1.ActiveRow.SetValue("ItemCodeW", ""); } } else if (entityGrid1.ActiveCell.Column.Key == "ItemNameF") { string phyTypeC = entityGrid1.ActiveRow.GetValue("PhyCodeMin"); if (phyTypeC == "") { MessageUtil.ShowWarning("请选择试样组"); entityGrid1.ActiveRow.Cells["PhyNameMin"].Activate(); return; } DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseQuery.geComBasePhyRItem", new object[] { phyTypeC }, _ob); dt.Columns["ITEM_NAME_F"].Caption = "试验方向"; dt.Columns["ITEM_NAME_C"].Caption = "试验尺寸"; BaseInfoPopup baseInfoPopup = new BaseInfoPopup(dt, "ITEM_NAME_F", "ITEM_CODE_F", "ITEM_CODE_C"); baseInfoPopup.Text = "试验选择"; baseInfoPopup.LabelTextBox1.Caption = "试验方向"; baseInfoPopup.Shown += new EventHandler((c, d) => { IQueryable rows = baseInfoPopup.UltraGrid1.Rows.AsQueryable().Where( a => a.GetValue("ITEM_CODE_F") == entityGrid1.ActiveRow.GetValue("ItemCodeF") && a.GetValue("ITEM_CODE_C") == entityGrid1.ActiveRow.GetValue("ItemCodeS")); if (rows.Count() > 0) { rows.First().Activate(); } }); if (baseInfoPopup.ShowDialog() == System.Windows.Forms.DialogResult.OK) { entityGrid1.ActiveRow.SetValue("ItemNameF", baseInfoPopup.ChoicedRow.GetValue("ITEM_NAME_F")); entityGrid1.ActiveRow.SetValue("ItemCodeF", baseInfoPopup.ChoicedRow.GetValue("ITEM_CODE_F")); entityGrid1.ActiveRow.SetValue("ItemNameS", baseInfoPopup.ChoicedRow.GetValue("ITEM_NAME_C")); entityGrid1.ActiveRow.SetValue("ItemCodeS", baseInfoPopup.ChoicedRow.GetValue("ITEM_CODE_C")); } } else if (entityGrid1.ActiveCell.Column.Key == "ItemNameW") { string phyCode = entityGrid1.ActiveRow.GetValue("PhyCode"); if (phyCode == "") { MessageUtil.ShowWarning("请选择检验项"); entityGrid1.ActiveRow.Cells["PhyName"].Activate(); return; } DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseQuery.geComBasePhyRPos", new object[] { phyCode }, _ob); dt.Columns["ITEM_NAME_W"].Caption = "试验温度"; BaseInfoPopup baseInfoPopup = new BaseInfoPopup(dt, "ITEM_NAME_W", "ITEM_CODE_W"); baseInfoPopup.Text = "试验选择"; baseInfoPopup.LabelTextBox1.Caption = "试验温度"; baseInfoPopup.Shown += new EventHandler((c, d) => { IQueryable rows = baseInfoPopup.UltraGrid1.Rows.AsQueryable().Where( a => a.GetValue("ITEM_CODE_W") == entityGrid1.ActiveRow.GetValue("ItemCodeW")); if (rows.Count() > 0) { rows.First().Activate(); } }); if (baseInfoPopup.ShowDialog() == System.Windows.Forms.DialogResult.OK) { entityGrid1.ActiveRow.SetValue("ItemNameW", baseInfoPopup.ChoicedRow.GetValue("ITEM_NAME_W")); entityGrid1.ActiveRow.SetValue("ItemCodeW", baseInfoPopup.ChoicedRow.GetValue("ITEM_CODE_W")); } } } private void ultraGrid1_AfterRowActivate(object sender, EventArgs e) { var row = ultraGrid1.ActiveRow; string pic = row.GetValue("PIC"); string mscPline = row.GetValue("MSC_PLINE"); string processCode = row.GetValue("PROCESS_CODE"); this.CraftOrdDesignStdPicEntityBindingSource.DataSource = EntityHelper.GetData( "com.steering.pss.sale.order.CraftOrdFdPic.query", new object[] { ordLnPk, mscPline, processCode, pic }, _ob); foreach (var row2 in entityGrid1.Rows) { GridEdite(row2); } } private void ultraTextEditor1_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; if (key == "MSC_PLINE") { DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CraftOrdFdPic.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 = "工序"; dt.Columns["PIC"].Caption = "理化索引码"; BaseInfoPopup popup = new BaseInfoPopup(dt, "MSC_PLINE", "PROCESS_CODE"); GridHelper.RefreshAndAutoSize(popup.UltraGrid1); popup.LabelTextBox1.Caption = "制程号"; if (popup.ShowDialog() == DialogResult.OK) { var mRow = ultraGrid1.Rows.Where(a => a.GetValue("MSC_PLINE") == popup.ChoicedRow.GetValue("MSC_PLINE") && a.GetValue("PROCESS_CODE") == popup.ChoicedRow.GetValue("PROCESS_CODE")).FirstOrDefault(); if (mRow != null) { MessageUtil.ShowWarning("同制程、同工序下只能维护一套首日检数据,请先删除制程" + popup.ChoicedRow.GetValue("MSC_PLINE") + " - 工序" + popup.ChoicedRow.GetValue("PROCESS_DESC") + "下的索引码" + mRow.GetValue("PIC") + "!"); return; } 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("PIC", popup.ChoicedRow.GetValue("PIC")); } } } } } private void entityGrid1_BeforeRowInsert(object sender, BeforeRowInsertEventArgs e) { if (ultraGrid1.ActiveRow == null) e.Cancel = true; if (ultraGrid1.ActiveRow.GetValue("PIC") == "") 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_AfterRowInsert(object sender, RowEventArgs e) { } private void ultraGrid1_BeforeRowInsert(object sender, BeforeRowInsertEventArgs e) { if (ultraGrid1.Rows.Count > 0) { e.Cancel = true; } } private void ultraGrid1_ClickCellButton(object sender, CellEventArgs e) { if (entityGrid1.Rows.Count == 0) { MessageUtil.ShowWarning("请先维护首日检数据!"); return; } string mscPline = ultraGrid1.ActiveRow.GetValue("MSC_PLINE"); string processCode = ultraGrid1.ActiveRow.GetValue("PROCESS_CODE"); CraftOrdFdPicSmpFrm picSmp = new CraftOrdFdPicSmpFrm(ordLnPk, mscPline, processCode, _ob); picSmp.ShowDialog(); } /// /// 复制 /// 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((CrafOrdFdPicEntity)chkRows.FirstOrDefault().ListObject); foreach (UltraGridRow row in entityGrid1.Rows) { if (row.GetValue("Chk") != "True") continue; DataRow dr = copyTable.NewRow(); CopyEntityToRow((CrafOrdFdPicEntity)row.ListObject, dr); dr["ORD_SEQ"] = ""; copyTable.Rows.Add(dr); } DataTable[] copyTabs = new DataTable[] { copyTable, new DataTable() }; Clipboard.SetData("Pic", copyTabs); } /// /// 粘贴 /// public void Paste() { if (ultraGrid1.ActiveRow == null || ultraGrid1.ActiveRow.GetValue("PIC") == "") { MessageUtil.ShowWarning("请选择一条成分标准索引码!"); return; } DataTable[] copyTabs = (DataTable[])Clipboard.GetData("Pic"); 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)CraftOrdDesignStdPicEntityBindingSource.DataSource; CrafOrdFdPicEntity activeFd = null; foreach (DataRow row in copyTab.Rows) { CrafOrdFdPicEntity fd = new CrafOrdFdPicEntity(); fd.Chk = true; CopyRowToEntity(row, fd); data.Add(fd); activeFd = fd; } CraftOrdDesignStdPicEntityBindingSource.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(CrafOrdFdPicEntity 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(CrafOrdFdPicEntity 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, CrafOrdFdPicEntity 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(); } } } }