using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Format; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using Infragistics.Win.UltraWinGrid; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Windows.Forms; namespace Core.StlMes.Client.Qcm { class DtSpecificationsBasicsNew2 : DtBaseQcm { private FrmSpecificationsBasicsNew2 _frm = null; public DtSpecificationsBasicsNew2(FrmSpecificationsBasicsNew2 frm) : base() { _frm = frm; RegistQuery(GetDataChild, "Child"); RegistQuery(Query, "DefaultQuery"); RegistAction(Add, ActionType.Add); RegistAction(Modify, ActionType.Modify); RegistAction(Save, ActionType.Save); RegistAction(Delete, ActionType.Delete); RegistAction(Resume, ActionType.Resume); RegistAction(SubMitAudit, ActionType.SubMitAudit); RegistAction(Audit, ActionType.Audit); RegistAction(Group, ActionType.Group); } protected void Query() { try { _frm.Cursor = Cursors.WaitCursor; bool validFlag = _frm.chkValid.Checked; string titleName = _frm.txtTitleName.Text.Trim(); string mscType = _frm.MscStyle; DataTable dt = null; dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecBasicsNew.getLineList", new object[] { validFlag, titleName, mscType }, _frm.ob); GridHelper.CopyDataToDatatable(dt, _frm.dataTable1, true); //GridHelper.RefreshAndAutoSize(_frm.ultraGrid1); _frm.dataTable1.AcceptChanges(); } finally { _frm.Cursor = Cursors.Default; } } protected bool Add() { throw new NotImplementedException(); } protected bool Group() { throw new NotImplementedException(); } protected bool Modify() { throw new NotImplementedException(); } protected bool Save() { ArrayList specList; ArrayList specOrderList; ArrayList[] parms = GetParms(ActionType.Save); specList = parms[0]; specOrderList = parms[1]; ServerHelper.SetData("com.steering.pss.qcm.CoreSpecBasicsNew.save", new object[] { specList, specOrderList }, _frm.ob); return true; } protected bool Delete() { return DeleteOrResumeData(true); } protected bool Resume() { return DeleteOrResumeData(false); } protected bool SubMitAudit() { throw new NotImplementedException(); } protected bool Audit() { throw new NotImplementedException(); } public void GetDataChild() { bool validFlag = _frm.chkValid.Checked; string spec_code = _frm.UltraGrid1.ActiveRow.Cells["SPEC_CODE"].Value.ToString(); DataTable dt = null; dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecOrderBasics.getLineList", new object[] { spec_code, validFlag }, _frm.ob); GridHelper.CopyDataToDatatable(dt, _frm.dataTable2, true); //GridHelper.RefreshAndAutoSize(_frm.ultraGrid2); _frm.dataTable2.AcceptChanges(); } private bool DeleteOrResumeData(bool isDelete) { ArrayList param = new ArrayList(); ArrayList minParam = new ArrayList(); DataRow[] drs = _frm.dataTable1.Select("CHK = 'True'"); DataRow[] drs2 = _frm.dataTable2.Select("CHK = 'True'"); foreach (DataRow dr in drs) { param.Add(dr["SPEC_CODE"].ToString()); } foreach (DataRow dr in drs2) { minParam.Add(dr["ORDER_SPEC_CODE"].ToString()); } if (param.Count > 0) { ServerHelper.SetData("com.steering.pss.qcm.CoreSpecBasicsNew.deleteLineInfo", new Object[] { param, _frm.UserInfo.GetUserName(), isDelete }, _frm.ob); } if (minParam.Count > 0) { ServerHelper.SetData("com.steering.pss.qcm.CoreSpecOrderBasics.deleteLineInfo", new Object[] { minParam, _frm.UserInfo.GetUserName(), isDelete }, _frm.ob); } return true; } protected override bool IsSelectData(ActionType actionType, out string msg) { msg = ""; DataRow[] drs = _frm.dataTable1.Select("CHK = 'True'"); DataRow[] drs2 = _frm.dataTable2.Select("CHK = 'True'"); if (drs.Length == 0 && drs2.Length == 0) { return false; } return true; } protected ArrayList[] GetParms(ActionType actionType) { ArrayList[] lists = new ArrayList[] { new ArrayList(), new ArrayList() }; if (actionType == ActionType.Save) { FrmDtConverter convert = new FrmDtConverter(); UltraGridRow[] rows = GridHelper.GetRowsWithKey(_frm.UltraGrid1, new string[] { "CHK" }, new string[] { "True" }); foreach (UltraGridRow row in rows) { ComBaseSpecEntity comBaseSpecEntity = convert.Convert(row, _frm.UserInfo, FieldAttributeType.NoQueryField); if (comBaseSpecEntity == null) return null; AdjustData(comBaseSpecEntity); string strObj = JSONFormat.Format(comBaseSpecEntity); lists[0].Add(strObj); } FrmDtConverter convert2 = new FrmDtConverter(); UltraGridRow[] rows2 = GridHelper.GetRowsWithKey(_frm.UltraGrid2, new string[] { "CHK" }, new string[] { "True" }); foreach (UltraGridRow row in rows2) { ComBaseSpecOrderEntity comBaseSpecOrderEntity = convert2.Convert(row, _frm.UserInfo, FieldAttributeType.NoQueryField); if (comBaseSpecOrderEntity == null) return null; string strObj = JSONFormat.Format(comBaseSpecOrderEntity); lists[1].Add(strObj); } } return lists; } private void AdjustData(ComBaseSpecEntity comBaseSpecEntity) { if (comBaseSpecEntity.MscStyle == "A") { comBaseSpecEntity.Dimater = Decimal.Parse(comBaseSpecEntity.Dimater).ToString("F2"); comBaseSpecEntity.Height = Decimal.Parse(comBaseSpecEntity.Height).ToString("F2"); comBaseSpecEntity.SpecName = comBaseSpecEntity.Dimater + "x" + comBaseSpecEntity.Height; } if (comBaseSpecEntity.Weight != "") { comBaseSpecEntity.Weight = Math.Round(Convert.ToDouble(comBaseSpecEntity.Weight), 4).ToString(); } } protected override bool CheckData(ActionType actionType, out ArrayList parm, out string msg) { msg = ""; parm = new ArrayList(); UltraGridRow[] rows = GridHelper.GetRowsWithKey(_frm.UltraGrid1, new string[] { "CHK" }, new string[] { "True" }); UltraGridRow[] rows2 = GridHelper.GetRowsWithKey(_frm.UltraGrid2, new string[] { "CHK" }, new string[] { "True" }); if (actionType == ActionType.Resume) { if (rows2.Length > 0) { if (_frm.UltraGrid1.ActiveRow.Cells["VALIDFLAG"].Value.ToString() == "0" && _frm.UltraGrid1.ActiveRow.Cells["GRD_CHK"].Value.ToString() == "False") { MessageUtil.ShowWarning("请恢复产品规格后,再进行订货规格操作!"); return false; } } } else if (actionType == ActionType.Delete) { return true; } else { return CheckSave(rows, rows2); } return true; } private bool CheckSave(UltraGridRow[] rows, UltraGridRow[] rows2) { List insertSpecNames = new List(); List insertOrder_SpecNames = new List(); foreach (UltraGridRow row in rows) { //if (dr["MSC_STYLE"].ToString() == "") //{ // MessageUtil.ShowWarning("您所要保存的数据中,类型不能为空!"); // return false; //} if (row.Cells["MSC_STYLE"].Value.ToString() == "A" && row.Cells["DIMATER"].Value.ToString() == "") { MessageUtil.ShowWarning("您所要保存的数据中,外径不能为空!"); row.Cells["DIMATER"].Activate(); return false; } else if (row.Cells["MSC_STYLE"].Value.ToString() == "A" && row.Cells["HEIGHT"].Value.ToString() == "") { MessageUtil.ShowWarning("您所要保存的数据中,壁厚不能为空!"); row.Cells["HEIGHT"].Activate(); return false; } if (row.Cells["DIMATER"].Value.ToString() != "" && row.Cells["HEIGHT"].Value.ToString() != "") { if (Convert.ToDouble(row.Cells["DIMATER"].Value) < Convert.ToDouble(row.Cells["HEIGHT"].Value)) { MessageUtil.ShowWarning("您要保存的数据,外径不能小于壁厚"); row.Cells["DIMATER"].Activate(); return false; } } decimal dcm = 0.0M; if (row.Cells["DIMATER"].Value.ToString() != "" && decimal.TryParse(row.Cells["DIMATER"].Value.ToString(), out dcm) == false) { MessageUtil.ShowWarning("您所要保存的数据中,外径输入的不是数字类型!"); row.Cells["DIMATER"].Activate(); return false; } if (row.Cells["HEIGHT"].Value.ToString() != "" && decimal.TryParse(row.Cells["HEIGHT"].Value.ToString(), out dcm) == false) { MessageUtil.ShowWarning("您所要保存的数据中,壁厚输入的不是数字类型!"); row.Cells["HEIGHT"].Activate(); return false; } if (row.Cells["WEIGHT"].Value.ToString() != "" && decimal.TryParse(row.Cells["WEIGHT"].Value.ToString(), out dcm) == false) { MessageUtil.ShowWarning("您所要保存的数据中,米单重输入的不是数字类型!"); row.Cells["WEIGHT"].Activate(); return false; } if (row.Cells["SPEC_NAME"].Value.ToString() == "") { MessageUtil.ShowWarning("您所要保存的数据中,产品规格描述不能为空!"); return false; } if (IsExistSpec(row.Cells["SPEC_NAME"].Value.ToString(), row.Cells["SPEC_CODE"].Value.ToString()) == true) { MessageUtil.ShowWarning("已存在产品规格描述-[" + row.Cells["SPEC_NAME"].Value.ToString() + "]!"); row.Cells["SPEC_NAME"].Activate(); return false; } if (insertSpecNames.Contains(row.Cells["SPEC_NAME"].Value.ToString())) { MessageUtil.ShowWarning("您所要保存的数据中,出现重复的产品规格描述-[" + row.Cells["SPEC_NAME"].Value.ToString() + "]!"); row.Cells["SPEC_NAME"].Activate(); return false; } insertSpecNames.Add(row.Cells["SPEC_NAME"].Value.ToString()); } foreach (UltraGridRow row in rows2) { if (_frm.UltraGrid1.ActiveRow.Cells["VALIDFLAG"].Value.ToString() == "0") { MessageUtil.ShowWarning("请恢复产品规格后,再进行订货规格操作!"); return false; } //if (dr["ORDER_SPEC_DESC"].ToString() == "") //{ // MessageUtil.ShowWarning("您所要保存的数据中,订货规格描述不能为空!"); // return false; //} //else if(IsExistOrderSpec(dr["ORDER_SPEC_DESC"].ToString(), dr["ORDER_SPEC_CODE"].ToString()) // == true) //{ // MessageUtil.ShowWarning("已存在订货规格描述-"+dr["ORDER_SPEC_DESC"].ToString()+"!"); // return false; //} //if(insertOrder_SpecNames.Contains(dr["ORDER_SPEC_DESC"].ToString())) //{ // MessageUtil.ShowWarning("您所要保存的数据中,出现重复的订货规格描述-["+ dr["ORDER_SPEC_DESC"].ToString() +"]!"); // return false; //} //insertOrder_SpecNames.Add(dr["ORDER_SPEC_DESC"].ToString()); } return true; } private bool IsExistSpec(string spec, string specCode) { if (specCode == "") { specCode = "NoCode"; } ArrayList list = new ArrayList(); list.Add(spec); list.Add(specCode); DataTable dt = null; dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecBasicsNew.isExistSpec", new object[] { list }, _frm.ob); if (dt != null && dt.Rows[0][0].ToString() == "0") { return false; } return true; } private bool IsExistOrderSpec(string orderSpec, string orderSpecCode) { if (orderSpecCode == "") { orderSpecCode = "NoCode"; } ArrayList list = new ArrayList(); list.Add(orderSpec); list.Add(orderSpecCode); DataTable dt = null; dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecBasicsNew.isExistOrderSpec", new object[] { list }, _frm.ob); if (dt != null && dt.Rows[0][0].ToString() == "0") { return false; } return true; } } }