FrmComMSCSample.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. using Core.Mes.Client.Comm.Control;
  2. using Core.Mes.Client.Comm.Server;
  3. using Core.Mes.Client.Comm.Tool;
  4. using CoreFS.CA06;
  5. using Infragistics.Win.UltraWinGrid;
  6. using System;
  7. using System.Collections;
  8. using System.Data;
  9. using System.Windows.Forms;
  10. namespace Core.StlMes.Client.Qcm
  11. {
  12. /// <summary>
  13. /// 取样要求管理
  14. /// </summary>
  15. public partial class FrmComMSCSample : FrmBase
  16. {
  17. //提示
  18. private string errMessage = "";
  19. //冶金规范码
  20. private string _msc = "";
  21. private int isSelect = 0;
  22. //自增序号
  23. private int _xh = 1;
  24. //用于定位
  25. private int expanl = -1;
  26. public FrmComMSCSample()
  27. {
  28. InitializeComponent();
  29. }
  30. public override void ToolBar_Click(object sender, string ToolbarKey)
  31. {
  32. switch (ToolbarKey)
  33. {
  34. case "Query":
  35. this.DoQuery(true);
  36. break;
  37. case "Save":
  38. this.DoSave();
  39. break;
  40. case "Delete":
  41. DoUpdateOrResume(true);
  42. break;
  43. case "Resume":
  44. DoUpdateOrResume(false);
  45. break;
  46. case "Close":
  47. this.Close();
  48. break;
  49. }
  50. }
  51. /// <summary>
  52. /// 传入冶金规范码(外部调用)
  53. /// </summary>
  54. /// <param name="msc">冶金规范码</param>
  55. public void SetMSC(string msc)
  56. {
  57. _msc = msc;
  58. DoQuery(true);
  59. }
  60. /// <summary>
  61. /// 查询
  62. /// </summary>
  63. private void DoQuery(Boolean flag)
  64. {
  65. string msc = _msc;
  66. string valid = "1";
  67. if (!flag)
  68. valid = "0";
  69. ArrayList list = new ArrayList();
  70. list.Add(_msc);
  71. list.Add(valid);
  72. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreComMSCSample.getComMSCSample", new Object[] { list }, this.ob);
  73. GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
  74. //不同颜色区分是否有效数据
  75. QcmBaseCommon.DistinguishColor(ultraGrid1, "VALIDFLAGNAME", "有效");
  76. _xh = 1;
  77. QcmBaseCommon.SetUltraGridNoEdit(ultraGrid1);
  78. isSelect = 0;
  79. if (expanl < ultraGrid1.Rows.Count && expanl >= 0)
  80. ultraGrid1.Rows[expanl].Activate();
  81. expanl = -1;
  82. }
  83. /// <summary>
  84. /// 操作数据项
  85. /// </summary>
  86. /// <returns></returns>
  87. private ArrayList GetOptionData(int i)
  88. {
  89. ArrayList list = new ArrayList();
  90. UltraGridRow rows = ultraGrid1.Rows[i];
  91. string msc = _msc;
  92. string xh = rows.Cells["XH"].Text.ToString().Trim();
  93. string minD = rows.Cells["MIN_D"].Value.ToString().Trim();
  94. if (!minD.Equals("") && !StringUtil.IsNumber(minD))
  95. {
  96. errMessage = "最小外径请输入数字";
  97. return null;
  98. }
  99. string maxD = rows.Cells["MAX_D"].Value.ToString().Trim();
  100. if (!maxD.Equals("") && !StringUtil.IsNumber(maxD))
  101. {
  102. errMessage = "最大外径请输入数字";
  103. return null;
  104. }
  105. if (!minD.Equals("") && !maxD.Equals("") && Convert.ToDouble(minD) > Convert.ToDouble(maxD))
  106. {
  107. errMessage = "最小外径不能大于最大外径";
  108. return null;
  109. }
  110. string minH = rows.Cells["MIN_H"].Value.ToString().Trim();
  111. if (!minH.Equals("") && !StringUtil.IsNumber(minH))
  112. {
  113. errMessage = "最小壁厚请输入数字";
  114. return null;
  115. }
  116. string maxH = rows.Cells["MAX_H"].Value.ToString().Trim();
  117. if (!maxH.Equals("") && !StringUtil.IsNumber(maxH))
  118. {
  119. errMessage = "最大壁厚请输入数字";
  120. return null;
  121. }
  122. if (!minH.Equals("") && !maxH.Equals("") && Convert.ToDouble(minH) > Convert.ToDouble(maxH))
  123. {
  124. errMessage = "最小壁厚不能大于最大壁厚";
  125. return null;
  126. }
  127. string length = rows.Cells["LENGTH"].Text.ToString().Trim();
  128. string descLength = rows.Cells["DESC_LENGTH"].Text.ToString().Trim();
  129. if (descLength.Equals(""))
  130. {
  131. errMessage = "请选择取样长度";
  132. return null;
  133. }
  134. string rate = rows.Cells["RATE"].Text.ToString().Trim();
  135. if (rate.Equals(""))
  136. {
  137. errMessage = "请选择取样频率";
  138. return null;
  139. }
  140. string descRate = rows.Cells["DESC_RATE"].Text.ToString().Trim();
  141. if (descRate.Equals(""))
  142. {
  143. errMessage = "请选择取样描述";
  144. return null;
  145. }
  146. string descCount = rows.Cells["DESC_COUNT"].Text.ToString().Trim();
  147. string position = rows.Cells["POSITION"].Text.ToString().Trim();
  148. if (position.Equals(""))
  149. {
  150. errMessage = "请选择位置描述";
  151. return null;
  152. }
  153. string descPosition = rows.Cells["DESC_POSITION"].Text.ToString().Trim();
  154. string userName = UserInfo.GetUserName();
  155. string userTime = System.DateTime.Now.ToString();
  156. string memo = rows.Cells["MEMO"].Text.ToString().Trim();
  157. string validflag = rows.Cells["VALIDFLAGNAME"].Value.ToString();
  158. if (validflag.Equals("无效"))
  159. {
  160. errMessage = "无效记录不能保存";
  161. return null;
  162. }
  163. list.Add(msc);
  164. list.Add(xh);
  165. list.Add(minD);
  166. list.Add(maxD);
  167. list.Add(minH);
  168. list.Add(maxH);
  169. list.Add(length);
  170. list.Add(descLength);
  171. list.Add(rate);
  172. list.Add(descRate);
  173. list.Add(descCount);
  174. list.Add(position);
  175. list.Add(descPosition);
  176. list.Add(userName);
  177. list.Add(userTime);
  178. list.Add(memo);
  179. return list;
  180. }
  181. /// <summary>
  182. /// 保存
  183. /// </summary>
  184. private void DoSave()
  185. {
  186. ultraGrid1.UpdateData();
  187. if (isSelect == 0)
  188. {
  189. MessageBox.Show("请选择记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  190. return;
  191. }
  192. if (MessageBox.Show("是否保存选择记录", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  193. {
  194. return;
  195. }
  196. ArrayList addList = new ArrayList();
  197. ArrayList updateList = new ArrayList();
  198. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  199. {
  200. if (Convert.ToBoolean(ultraGrid1.Rows[i].Cells["CHC"].Value.ToString()))
  201. {
  202. ArrayList list = GetOptionData(i);
  203. if (list == null)
  204. {
  205. MessageBox.Show(errMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  206. return;
  207. }
  208. if (ultraGrid1.Rows[i].Cells["CREATE_NAME"].Text.Equals(""))
  209. {
  210. addList.Add(list);
  211. }
  212. else
  213. {
  214. list.Add(ultraGrid1.Rows[i].Cells["MSC"].Text.Trim());
  215. list.Add(Convert.ToInt32(ultraGrid1.Rows[i].Cells["XH"].Text.Trim()));
  216. updateList.Add(list);
  217. }
  218. if (expanl == -1)
  219. expanl = i;
  220. }
  221. }
  222. if (addList.Count > 0 || updateList.Count > 0)
  223. {
  224. int count = ServerHelper.SetData("com.steering.pss.qcm.CoreComMSCSample.saveComMSCSample", new Object[] { addList, updateList }, this.ob);
  225. if (count > 0)
  226. {
  227. DoQuery(true);
  228. MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  229. }
  230. else
  231. MessageBox.Show("保存失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  232. }
  233. }
  234. /// <summary>
  235. /// 删除或者恢复
  236. /// </summary>
  237. private void DoUpdateOrResume(Boolean flag)
  238. {
  239. ultraGrid1.UpdateData();
  240. if (isSelect == 0)
  241. {
  242. MessageBox.Show("请选择记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  243. return;
  244. }
  245. if (flag)
  246. {
  247. if (MessageBox.Show("作废选中记录,您是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  248. {
  249. return;
  250. }
  251. }
  252. else
  253. {
  254. if (MessageBox.Show("恢复选中记录,您是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  255. {
  256. return;
  257. }
  258. }
  259. ArrayList listAll = new ArrayList();
  260. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  261. {
  262. if (Convert.ToBoolean(ultraGrid1.Rows[i].Cells["CHC"].Value.ToString()))
  263. {
  264. ArrayList list = new ArrayList();
  265. string validflag = "0";
  266. string userName = UserInfo.GetUserName();
  267. string userTime = System.DateTime.Now.ToString();
  268. if (!flag)
  269. {
  270. if (ultraGrid1.Rows[i].Cells["VALIDFLAGNAME"].Value.Equals("有效"))
  271. {
  272. MessageBox.Show("记录[" + (i + 1) + "]为有效记录,不能恢复", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  273. return;
  274. }
  275. validflag = "1";
  276. userName = "";
  277. userTime = "";
  278. }
  279. else
  280. {
  281. if (ultraGrid1.Rows[i].Cells["VALIDFLAGNAME"].Value.Equals("无效"))
  282. {
  283. MessageBox.Show("记录[" + (i + 1) + "]为无效记录,不能删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  284. return;
  285. }
  286. }
  287. string msc = _msc;
  288. int xh = Convert.ToInt32(ultraGrid1.Rows[i].Cells["XH"].Value.ToString());
  289. list.Add(validflag);
  290. list.Add(userName);
  291. list.Add(userTime);
  292. list.Add(msc);
  293. list.Add(xh);
  294. listAll.Add(list);
  295. if (expanl == -1)
  296. expanl = i;
  297. }
  298. }
  299. if (listAll.Count > 0)
  300. {
  301. int count = ServerHelper.SetData("com.steering.pss.qcm.CoreComMSCSample.deleteComMSCSample", new Object[] { listAll, flag }, this.ob);
  302. if (count > 0)
  303. {
  304. DoQuery(false);
  305. if (flag)
  306. MessageBox.Show("作废成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  307. else
  308. MessageBox.Show("恢复成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  309. }
  310. }
  311. }
  312. /// <summary>
  313. /// 初始化下拉框
  314. /// </summary>
  315. private void InitDownList()
  316. {
  317. QcmBaseCommon.InitDropUltraComEditor(ultraComboLength, "com.steering.pss.qcm.ComBaseQuery.geComBaseInfo4010", "BASENAME", this.ob, false);
  318. QcmBaseCommon.InitDropUltraComEditor(ultraComPosition, "com.steering.pss.qcm.ComBaseQuery.geComBaseInfo4011", "BASENAME", this.ob, false);
  319. QcmBaseCommon.InitDropUltraComEditor(ultraComboRace, "com.steering.pss.qcm.ComBaseQuery.geComBaseInfo4012", "BASENAME", this.ob, false);
  320. }
  321. /// <summary>
  322. /// 登陆页面事件
  323. /// </summary>
  324. /// <param name="sender"></param>
  325. /// <param name="e"></param>
  326. private void FrmComMSCSample_Load(object sender, EventArgs e)
  327. {
  328. SetMSC("MSC00001");
  329. InitDownList();
  330. }
  331. /// <summary>
  332. /// 行增加事件
  333. /// </summary>
  334. /// <param name="sender"></param>
  335. /// <param name="e"></param>
  336. private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
  337. {
  338. int xh = 1;
  339. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreComMSCSample.getMaxXH", new Object[] { _msc }, this.ob);
  340. if (dt != null && dt.Rows.Count > 0)
  341. {
  342. int xh1 = Convert.ToInt32(dt.Rows[0][0].ToString());
  343. if (xh1 > _xh)
  344. {
  345. xh = xh1 + 1;
  346. _xh = xh1 + 1;
  347. }
  348. else
  349. {
  350. xh = _xh + 1;
  351. _xh += 1;
  352. }
  353. }
  354. else
  355. {
  356. xh = _xh;
  357. _xh += 1;
  358. }
  359. UltraGridRow ugr = ultraGrid1.DisplayLayout.ActiveRow;
  360. ugr.Cells["XH"].Value = xh;
  361. if (!Convert.ToBoolean(ugr.Cells["CHC"].Value))
  362. {
  363. for (int i = 0; i < ugr.Cells.Count; i++)
  364. {
  365. if (!ugr.Cells[i].Column.Key.Equals("CHC"))
  366. ugr.Cells[i].Activation = Activation.ActivateOnly;
  367. }
  368. }
  369. }
  370. /// <summary>
  371. /// 值变化事件
  372. /// </summary>
  373. /// <param name="sender"></param>
  374. /// <param name="e"></param>
  375. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  376. {
  377. ultraGrid1.UpdateData();
  378. UltraGridRow ugr = ultraGrid1.DisplayLayout.ActiveRow;
  379. if (e.Cell.Column.Key.Equals("DESC_LENGTH")) /// 长度描述
  380. {
  381. ugr.Cells["LENGTH"].Value = ugr.Cells["DESC_LENGTH"].Value.ToString();
  382. }
  383. if (e.Cell.Column.Key.Equals("DESC_POSITION")) /// 位置描述
  384. {
  385. ugr.Cells["POSITION"].Value = ugr.Cells["DESC_POSITION"].Value.ToString();
  386. }
  387. if (e.Cell.Column.Key.Equals("DESC_RATE")) /// 频率描述
  388. {
  389. ugr.Cells["RATE"].Value = ugr.Cells["DESC_RATE"].Value.ToString();
  390. }
  391. if (e.Cell.Column.Key.Equals("CHC"))
  392. {
  393. Activation activation = Activation.ActivateOnly;
  394. if (Convert.ToBoolean(e.Cell.Value))
  395. {
  396. activation = Activation.AllowEdit;
  397. isSelect += 1;
  398. }
  399. else
  400. isSelect -= 1;
  401. CellsCollection cells = e.Cell.Row.Cells;
  402. for (int i = 0; i < cells.Count; i++)
  403. {
  404. if (!cells[i].Column.Key.Equals("CHC"))
  405. {
  406. e.Cell.Row.Cells[i].Activation = activation;
  407. }
  408. }
  409. }
  410. }
  411. }
  412. }