DtSpecificationsBasicsNew2.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. using Core.Mes.Client.Comm.Control;
  2. using Core.Mes.Client.Comm.Format;
  3. using Core.Mes.Client.Comm.Server;
  4. using Core.Mes.Client.Comm.Tool;
  5. using Infragistics.Win.UltraWinGrid;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Windows.Forms;
  11. namespace Core.StlMes.Client.Qcm
  12. {
  13. class DtSpecificationsBasicsNew2 : DtBaseQcm
  14. {
  15. private FrmSpecificationsBasicsNew2 _frm = null;
  16. public DtSpecificationsBasicsNew2(FrmSpecificationsBasicsNew2 frm) : base()
  17. {
  18. _frm = frm;
  19. RegistQuery(GetDataChild, "Child");
  20. RegistQuery(Query, "DefaultQuery");
  21. RegistAction(Add, ActionType.Add);
  22. RegistAction(Modify, ActionType.Modify);
  23. RegistAction(Save, ActionType.Save);
  24. RegistAction(Delete, ActionType.Delete);
  25. RegistAction(Resume, ActionType.Resume);
  26. RegistAction(SubMitAudit, ActionType.SubMitAudit);
  27. RegistAction(Audit, ActionType.Audit);
  28. RegistAction(Group, ActionType.Group);
  29. }
  30. protected void Query()
  31. {
  32. try
  33. {
  34. _frm.Cursor = Cursors.WaitCursor;
  35. bool validFlag = _frm.chkValid.Checked;
  36. string titleName = _frm.txtTitleName.Text.Trim();
  37. string mscType = _frm.MscStyle;
  38. DataTable dt = null;
  39. dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecBasicsNew.getLineList",
  40. new object[] { validFlag, titleName, mscType }, _frm.ob);
  41. GridHelper.CopyDataToDatatable(dt, _frm.dataTable1, true);
  42. //GridHelper.RefreshAndAutoSize(_frm.ultraGrid1);
  43. _frm.dataTable1.AcceptChanges();
  44. }
  45. finally
  46. {
  47. _frm.Cursor = Cursors.Default;
  48. }
  49. }
  50. protected bool Add()
  51. {
  52. throw new NotImplementedException();
  53. }
  54. protected bool Group()
  55. {
  56. throw new NotImplementedException();
  57. }
  58. protected bool Modify()
  59. {
  60. throw new NotImplementedException();
  61. }
  62. protected bool Save()
  63. {
  64. ArrayList specList;
  65. ArrayList specOrderList;
  66. ArrayList[] parms = GetParms(ActionType.Save);
  67. specList = parms[0];
  68. specOrderList = parms[1];
  69. ServerHelper.SetData("com.steering.pss.qcm.CoreSpecBasicsNew.save",
  70. new object[] { specList, specOrderList }, _frm.ob);
  71. return true;
  72. }
  73. protected bool Delete()
  74. {
  75. return DeleteOrResumeData(true);
  76. }
  77. protected bool Resume()
  78. {
  79. return DeleteOrResumeData(false);
  80. }
  81. protected bool SubMitAudit()
  82. {
  83. throw new NotImplementedException();
  84. }
  85. protected bool Audit()
  86. {
  87. throw new NotImplementedException();
  88. }
  89. public void GetDataChild()
  90. {
  91. bool validFlag = _frm.chkValid.Checked;
  92. string spec_code = _frm.UltraGrid1.ActiveRow.Cells["SPEC_CODE"].Value.ToString();
  93. DataTable dt = null;
  94. dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecOrderBasics.getLineList",
  95. new object[] { spec_code, validFlag }, _frm.ob);
  96. GridHelper.CopyDataToDatatable(dt, _frm.dataTable2, true);
  97. //GridHelper.RefreshAndAutoSize(_frm.ultraGrid2);
  98. _frm.dataTable2.AcceptChanges();
  99. }
  100. private bool DeleteOrResumeData(bool isDelete)
  101. {
  102. ArrayList param = new ArrayList();
  103. ArrayList minParam = new ArrayList();
  104. DataRow[] drs = _frm.dataTable1.Select("CHK = 'True'");
  105. DataRow[] drs2 = _frm.dataTable2.Select("CHK = 'True'");
  106. foreach (DataRow dr in drs)
  107. {
  108. param.Add(dr["SPEC_CODE"].ToString());
  109. }
  110. foreach (DataRow dr in drs2)
  111. {
  112. minParam.Add(dr["ORDER_SPEC_CODE"].ToString());
  113. }
  114. if (param.Count > 0)
  115. {
  116. ServerHelper.SetData("com.steering.pss.qcm.CoreSpecBasicsNew.deleteLineInfo",
  117. new Object[] { param, _frm.UserInfo.GetUserName(), isDelete }, _frm.ob);
  118. }
  119. if (minParam.Count > 0)
  120. {
  121. ServerHelper.SetData("com.steering.pss.qcm.CoreSpecOrderBasics.deleteLineInfo",
  122. new Object[] { minParam, _frm.UserInfo.GetUserName(), isDelete }, _frm.ob);
  123. }
  124. return true;
  125. }
  126. protected override bool IsSelectData(ActionType actionType, out string msg)
  127. {
  128. msg = "";
  129. DataRow[] drs = _frm.dataTable1.Select("CHK = 'True'");
  130. DataRow[] drs2 = _frm.dataTable2.Select("CHK = 'True'");
  131. if (drs.Length == 0 && drs2.Length == 0)
  132. {
  133. return false;
  134. }
  135. return true;
  136. }
  137. protected ArrayList[] GetParms(ActionType actionType)
  138. {
  139. ArrayList[] lists = new ArrayList[] { new ArrayList(), new ArrayList() };
  140. if (actionType == ActionType.Save)
  141. {
  142. FrmDtConverter<ComBaseSpecEntity> convert = new FrmDtConverter<ComBaseSpecEntity>();
  143. UltraGridRow[] rows = GridHelper.GetRowsWithKey(_frm.UltraGrid1, new string[] { "CHK" }, new string[] { "True" });
  144. foreach (UltraGridRow row in rows)
  145. {
  146. ComBaseSpecEntity comBaseSpecEntity = convert.Convert(row, _frm.UserInfo, FieldAttributeType.NoQueryField);
  147. if (comBaseSpecEntity == null) return null;
  148. AdjustData(comBaseSpecEntity);
  149. string strObj = JSONFormat.Format(comBaseSpecEntity);
  150. lists[0].Add(strObj);
  151. }
  152. FrmDtConverter<ComBaseSpecOrderEntity> convert2 = new FrmDtConverter<ComBaseSpecOrderEntity>();
  153. UltraGridRow[] rows2 = GridHelper.GetRowsWithKey(_frm.UltraGrid2, new string[] { "CHK" }, new string[] { "True" });
  154. foreach (UltraGridRow row in rows2)
  155. {
  156. ComBaseSpecOrderEntity comBaseSpecOrderEntity = convert2.Convert(row, _frm.UserInfo, FieldAttributeType.NoQueryField);
  157. if (comBaseSpecOrderEntity == null) return null;
  158. string strObj = JSONFormat.Format(comBaseSpecOrderEntity);
  159. lists[1].Add(strObj);
  160. }
  161. }
  162. return lists;
  163. }
  164. private void AdjustData(ComBaseSpecEntity comBaseSpecEntity)
  165. {
  166. if (comBaseSpecEntity.MscStyle == "A")
  167. {
  168. comBaseSpecEntity.Dimater = Decimal.Parse(comBaseSpecEntity.Dimater).ToString("F2");
  169. comBaseSpecEntity.Height = Decimal.Parse(comBaseSpecEntity.Height).ToString("F2");
  170. comBaseSpecEntity.SpecName = comBaseSpecEntity.Dimater + "x" + comBaseSpecEntity.Height;
  171. }
  172. if (comBaseSpecEntity.Weight != "")
  173. {
  174. comBaseSpecEntity.Weight = Math.Round(Convert.ToDouble(comBaseSpecEntity.Weight), 4).ToString();
  175. }
  176. }
  177. protected override bool CheckData(ActionType actionType, out ArrayList parm, out string msg)
  178. {
  179. msg = "";
  180. parm = new ArrayList();
  181. UltraGridRow[] rows = GridHelper.GetRowsWithKey(_frm.UltraGrid1, new string[] { "CHK" }, new string[] { "True" });
  182. UltraGridRow[] rows2 = GridHelper.GetRowsWithKey(_frm.UltraGrid2, new string[] { "CHK" }, new string[] { "True" });
  183. if (actionType == ActionType.Resume)
  184. {
  185. if (rows2.Length > 0)
  186. {
  187. if (_frm.UltraGrid1.ActiveRow.Cells["VALIDFLAG"].Value.ToString() == "0"
  188. && _frm.UltraGrid1.ActiveRow.Cells["GRD_CHK"].Value.ToString() == "False")
  189. {
  190. MessageUtil.ShowWarning("请恢复产品规格后,再进行订货规格操作!");
  191. return false;
  192. }
  193. }
  194. }
  195. else if (actionType == ActionType.Delete)
  196. {
  197. return true;
  198. }
  199. else
  200. {
  201. return CheckSave(rows, rows2);
  202. }
  203. return true;
  204. }
  205. private bool CheckSave(UltraGridRow[] rows, UltraGridRow[] rows2)
  206. {
  207. List<string> insertSpecNames = new List<string>();
  208. List<string> insertOrder_SpecNames = new List<string>();
  209. foreach (UltraGridRow row in rows)
  210. {
  211. //if (dr["MSC_STYLE"].ToString() == "")
  212. //{
  213. // MessageUtil.ShowWarning("您所要保存的数据中,类型不能为空!");
  214. // return false;
  215. //}
  216. if (row.Cells["MSC_STYLE"].Value.ToString() == "A" && row.Cells["DIMATER"].Value.ToString() == "")
  217. {
  218. MessageUtil.ShowWarning("您所要保存的数据中,外径不能为空!");
  219. row.Cells["DIMATER"].Activate();
  220. return false;
  221. }
  222. else if (row.Cells["MSC_STYLE"].Value.ToString() == "A" && row.Cells["HEIGHT"].Value.ToString() == "")
  223. {
  224. MessageUtil.ShowWarning("您所要保存的数据中,壁厚不能为空!");
  225. row.Cells["HEIGHT"].Activate();
  226. return false;
  227. }
  228. if (row.Cells["DIMATER"].Value.ToString() != "" && row.Cells["HEIGHT"].Value.ToString() != "")
  229. {
  230. if (Convert.ToDouble(row.Cells["DIMATER"].Value) < Convert.ToDouble(row.Cells["HEIGHT"].Value))
  231. {
  232. MessageUtil.ShowWarning("您要保存的数据,外径不能小于壁厚");
  233. row.Cells["DIMATER"].Activate();
  234. return false;
  235. }
  236. }
  237. decimal dcm = 0.0M;
  238. if (row.Cells["DIMATER"].Value.ToString() != "" && decimal.TryParse(row.Cells["DIMATER"].Value.ToString(), out dcm) == false)
  239. {
  240. MessageUtil.ShowWarning("您所要保存的数据中,外径输入的不是数字类型!");
  241. row.Cells["DIMATER"].Activate();
  242. return false;
  243. }
  244. if (row.Cells["HEIGHT"].Value.ToString() != "" && decimal.TryParse(row.Cells["HEIGHT"].Value.ToString(), out dcm) == false)
  245. {
  246. MessageUtil.ShowWarning("您所要保存的数据中,壁厚输入的不是数字类型!");
  247. row.Cells["HEIGHT"].Activate();
  248. return false;
  249. }
  250. if (row.Cells["WEIGHT"].Value.ToString() != "" && decimal.TryParse(row.Cells["WEIGHT"].Value.ToString(), out dcm) == false)
  251. {
  252. MessageUtil.ShowWarning("您所要保存的数据中,米单重输入的不是数字类型!");
  253. row.Cells["WEIGHT"].Activate();
  254. return false;
  255. }
  256. if (row.Cells["SPEC_NAME"].Value.ToString() == "")
  257. {
  258. MessageUtil.ShowWarning("您所要保存的数据中,产品规格描述不能为空!");
  259. return false;
  260. }
  261. if (IsExistSpec(row.Cells["SPEC_NAME"].Value.ToString(), row.Cells["SPEC_CODE"].Value.ToString()) == true)
  262. {
  263. MessageUtil.ShowWarning("已存在产品规格描述-[" + row.Cells["SPEC_NAME"].Value.ToString() + "]!");
  264. row.Cells["SPEC_NAME"].Activate();
  265. return false;
  266. }
  267. if (insertSpecNames.Contains(row.Cells["SPEC_NAME"].Value.ToString()))
  268. {
  269. MessageUtil.ShowWarning("您所要保存的数据中,出现重复的产品规格描述-[" + row.Cells["SPEC_NAME"].Value.ToString() + "]!");
  270. row.Cells["SPEC_NAME"].Activate();
  271. return false;
  272. }
  273. insertSpecNames.Add(row.Cells["SPEC_NAME"].Value.ToString());
  274. }
  275. foreach (UltraGridRow row in rows2)
  276. {
  277. if (_frm.UltraGrid1.ActiveRow.Cells["VALIDFLAG"].Value.ToString() == "0")
  278. {
  279. MessageUtil.ShowWarning("请恢复产品规格后,再进行订货规格操作!");
  280. return false;
  281. }
  282. //if (dr["ORDER_SPEC_DESC"].ToString() == "")
  283. //{
  284. // MessageUtil.ShowWarning("您所要保存的数据中,订货规格描述不能为空!");
  285. // return false;
  286. //}
  287. //else if(IsExistOrderSpec(dr["ORDER_SPEC_DESC"].ToString(), dr["ORDER_SPEC_CODE"].ToString())
  288. // == true)
  289. //{
  290. // MessageUtil.ShowWarning("已存在订货规格描述-"+dr["ORDER_SPEC_DESC"].ToString()+"!");
  291. // return false;
  292. //}
  293. //if(insertOrder_SpecNames.Contains(dr["ORDER_SPEC_DESC"].ToString()))
  294. //{
  295. // MessageUtil.ShowWarning("您所要保存的数据中,出现重复的订货规格描述-["+ dr["ORDER_SPEC_DESC"].ToString() +"]!");
  296. // return false;
  297. //}
  298. //insertOrder_SpecNames.Add(dr["ORDER_SPEC_DESC"].ToString());
  299. }
  300. return true;
  301. }
  302. private bool IsExistSpec(string spec, string specCode)
  303. {
  304. if (specCode == "")
  305. {
  306. specCode = "NoCode";
  307. }
  308. ArrayList list = new ArrayList();
  309. list.Add(spec);
  310. list.Add(specCode);
  311. DataTable dt = null;
  312. dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecBasicsNew.isExistSpec",
  313. new object[] { list }, _frm.ob);
  314. if (dt != null && dt.Rows[0][0].ToString() == "0")
  315. {
  316. return false;
  317. }
  318. return true;
  319. }
  320. private bool IsExistOrderSpec(string orderSpec, string orderSpecCode)
  321. {
  322. if (orderSpecCode == "")
  323. {
  324. orderSpecCode = "NoCode";
  325. }
  326. ArrayList list = new ArrayList();
  327. list.Add(orderSpec);
  328. list.Add(orderSpecCode);
  329. DataTable dt = null;
  330. dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecBasicsNew.isExistOrderSpec",
  331. new object[] { list }, _frm.ob);
  332. if (dt != null && dt.Rows[0][0].ToString() == "0")
  333. {
  334. return false;
  335. }
  336. return true;
  337. }
  338. }
  339. }