FrmComBaseWell.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  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 Core.StlMes.Client.Qcm.model;
  6. using CoreFS.CA06;
  7. using Infragistics.Win.UltraWinEditors;
  8. using Infragistics.Win.UltraWinGrid;
  9. using System;
  10. using System.Collections;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Windows.Forms;
  15. namespace Core.StlMes.Client.Qcm
  16. {
  17. public partial class FrmComBaseWell : FrmBase
  18. {
  19. int _jic = 1;
  20. string _wellname = "";
  21. string errMessage = "";
  22. private UltraComboEditor _cmbProcess = new UltraComboEditor();
  23. public FrmComBaseWell()
  24. {
  25. InitializeComponent();
  26. ExceptionHelper.RegistException();
  27. }
  28. private void InitUi()
  29. {
  30. _cmbProcess.Visible = false;
  31. this.Controls.Add(_cmbProcess);
  32. QcmBaseQuery.NitializeProcess(_cmbProcess, false, ob);
  33. ultraGrid1.DisplayLayout.Bands[0].Columns["PROCESS_CDOE"].EditorComponent = _cmbProcess;
  34. ultraGrid1.DisplayLayout.Bands[0].Columns["PROCESS_CDOE"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  35. }
  36. public override void ToolBar_Click(object sender, string ToolbarKey)
  37. {
  38. switch (ToolbarKey)
  39. {
  40. case "Query":
  41. DoQuery(true);
  42. break;
  43. case "Save":
  44. DoSave();
  45. break;
  46. case "Delete":
  47. DeleteOrResume(true);
  48. break;
  49. case "Resume":
  50. DeleteOrResume(false);
  51. break;
  52. case "Invalid":
  53. DoQuery(false);
  54. break;
  55. case "Close":
  56. this.Close();
  57. break;
  58. }
  59. }
  60. /// <summary>
  61. /// 查询
  62. /// </summary>
  63. private void DoQuery(Boolean flag)
  64. {
  65. string validFlag = "1";
  66. if (!flag)
  67. validFlag = "0";
  68. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.getComBaseWellData", new Object[] { validFlag }, this.ob);
  69. GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
  70. SetUltraGridStyle();
  71. UltraGridColumn[] col = new UltraGridColumn[] { ultraGrid1.DisplayLayout.Bands[0].Columns["MEMO"] };
  72. GridHelper.RefreshAndAutoSizeExceptColumns(ultraGrid1, col);
  73. UltraGridRow[] rows = GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "WELL_NAME" }, new string[] { _wellname });
  74. if (rows.Length > 0)
  75. {
  76. rows[0].Activate();
  77. }
  78. foreach (UltraGridRow row in ultraGrid1.Rows)
  79. {
  80. ControlGrid1Edit(row);
  81. }
  82. _wellname = "";
  83. }
  84. private void DoSave()
  85. {
  86. ultraGrid1.UpdateData();
  87. ultraGrid2.UpdateData();
  88. UltraGridRow ugr = ultraGrid1.ActiveRow;
  89. ArrayList baseWell = new ArrayList();
  90. ArrayList monthWell = new ArrayList();
  91. int grid1Cnt = ultraGrid1.Rows.AsQueryable().Where("CHK = 'True'").Count();
  92. int grid2Cnt = ultraGrid2.Rows.AsQueryable().Where("CHK = 'True'").Count();
  93. if ((grid1Cnt + grid2Cnt) == 0)
  94. {
  95. MessageUtil.ShowWarning("请选择你要操作的记录!");
  96. return;
  97. }
  98. ComBaseWellEntity com = GetBaseWell(ugr);
  99. if (com == null) return;
  100. if (!CheckWellData(com))
  101. {
  102. MessageUtil.ShowWarning(errMessage);
  103. return;
  104. }
  105. _wellname = com.WellName;
  106. baseWell.Add(JSONFormat.Format(com));
  107. foreach (UltraGridRow row in ultraGrid2.Rows)
  108. {
  109. if (row.Cells["CHK"].Value.ToString() == "True")
  110. {
  111. ComBaseWellMonthEntity comm = GetMonthWell(row);
  112. if (comm != null)
  113. {
  114. if (!CheckMonthData(comm, row))
  115. {
  116. MessageUtil.ShowWarning(errMessage);
  117. return;
  118. }
  119. monthWell.Add(JSONFormat.Format(comm));
  120. }
  121. else
  122. {
  123. return;
  124. }
  125. }
  126. }
  127. if (MessageBox.Show("是否保存选择记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  128. {
  129. return;
  130. }
  131. if (baseWell.Count > 0 || monthWell.Count > 0)
  132. {
  133. int count = ServerHelper.SetData("com.steering.pss.qcm.ComBaseWell.saveWell", new Object[] { baseWell, monthWell }, this.ob);
  134. if (count > 0)
  135. {
  136. MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  137. DoQuery(true);
  138. }
  139. }
  140. }
  141. private ComBaseWellEntity GetBaseWell(UltraGridRow row)
  142. {
  143. if (row.Cells["WELL_NAME"].Value.ToString() == "")
  144. {
  145. MessageUtil.ShowWarning("请输入产能井描述!");
  146. return null;
  147. }
  148. if (row.Cells["WEIGHT"].Value.ToString() == "")
  149. {
  150. MessageUtil.ShowWarning("请输入最大产能!");
  151. return null;
  152. }
  153. ComBaseWellEntity com = new ComBaseWellEntity();
  154. com.WellCode = row.Cells["WELL_CODE"].Value.ToString();
  155. com.WellName = row.Cells["WELL_NAME"].Value.ToString();
  156. com.Weight = row.Cells["WEIGHT"].Value.ToString();
  157. com.CreateName = this.UserInfo.GetUserName();
  158. com.Validflag = row.Cells["VALIDFLAGNAME"].Value.ToString();
  159. com.UpdateName = UserInfo.GetUserName();
  160. com.Memo = row.Cells["MEMO"].Value.ToString();
  161. com.ProcessCdoe = row.GetValue("PROCESS_CDOE");
  162. com.ProcessDesc = row.GetText("PROCESS_CDOE");
  163. return com;
  164. }
  165. /// <summary>
  166. /// 检查标准数据
  167. /// </summary>
  168. /// <param name="com"></param>
  169. /// <returns></returns>
  170. private bool CheckWellData(ComBaseWellEntity com)
  171. {
  172. if (com.Validflag.Equals("无效"))
  173. {
  174. errMessage = "无效记录不能操作";
  175. return false;
  176. }
  177. //验证标准名称在ultraGrid1是否重复
  178. UltraGridRow[] rows = GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "WELL_NAME", "CHK" }, new string[] { com.WellName, "True" });
  179. if (rows.Length > 1)
  180. {
  181. errMessage = "产能井描述:" + com.WellName + " 重复,请重新输入";
  182. return false;
  183. }
  184. if (com.Validflag.Equals(""))
  185. {
  186. //验证标准名称在数据表是否重复
  187. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.checkComBaseWell", new Object[] { com.WellName }, this.ob);
  188. if (dt != null && dt.Rows.Count > 0)
  189. {
  190. errMessage = "产能井描述:" + com.WellName + " 重复,请重新输入";
  191. return false;
  192. }
  193. }
  194. else
  195. {
  196. //验证标准名称是否重复
  197. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.checkBaseWellUpdate", new Object[] { com.WellName, com.WellCode }, this.ob);
  198. if (dt != null && dt.Rows.Count > 0)
  199. {
  200. errMessage = "产能井描述:" + com.WellName + " 重复,请重新输入";
  201. return false;
  202. }
  203. }
  204. return true;
  205. }
  206. private bool CheckMonthData(ComBaseWellMonthEntity com, UltraGridRow row)
  207. {
  208. ultraGrid1.UpdateData();
  209. UltraGridRow ugr = ultraGrid1.ActiveRow;
  210. if (com.Validflag.Equals("无效"))
  211. {
  212. errMessage = "无效记录不能操作";
  213. return false;
  214. }
  215. //验证标准名称在ultraGrid2是否重复
  216. UltraGridRow[] rows = GridHelper.GetRowsWithKey(ultraGrid2, new string[] { "YEAR", "CHK" }, new string[] { com.Year, "True" });
  217. if (rows.Length > 1)
  218. {
  219. errMessage = "年份:" + com.Year + " 重复,请重新输入";
  220. return false;
  221. }
  222. if (com.Validflag.Equals(""))
  223. {
  224. //验证标准名称在数据表是否重复
  225. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.checkYear", new Object[] { com.WellCode, com.Year }, this.ob);
  226. if (dt != null && dt.Rows.Count > 0)
  227. {
  228. errMessage = "年份:" + com.Year + " 重复,请重新输入";
  229. return false;
  230. }
  231. }
  232. else
  233. {
  234. //验证标准名称是否重复
  235. if (com.Year != row.GetValue("YEAR_OLD"))
  236. {
  237. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.checkYear", new Object[] { com.WellCode, com.Year }, this.ob);
  238. if (dt != null && dt.Rows.Count > 0)
  239. {
  240. errMessage = "年份:" + com.Year + " 重复,请重新输入";
  241. return false;
  242. }
  243. }
  244. }
  245. string weight = ugr.Cells["WEIGHT"].Value.ToString();
  246. if (weight != "")
  247. {
  248. double wellNum = Convert.ToDouble(weight);
  249. if (com.Month1 != "")
  250. {
  251. if (!StringUtil.IsNumber(com.Month1))
  252. {
  253. errMessage = "1月份的产能值请输入数字!";
  254. return false;
  255. }
  256. if (Convert.ToDouble(com.Month1) > wellNum)
  257. {
  258. errMessage = "1月份的产能值不能超过最大产能值!";
  259. return false;
  260. }
  261. }
  262. if (com.Month2 != "")
  263. {
  264. if (!StringUtil.IsNumber(com.Month2))
  265. {
  266. errMessage = "2月份的产能值请输入数字!";
  267. return false;
  268. }
  269. if (Convert.ToDouble(com.Month2) > wellNum)
  270. {
  271. errMessage = "2月份的产能值不能超过最大产能值!";
  272. return false;
  273. }
  274. }
  275. if (com.Month3 != "")
  276. {
  277. if (!StringUtil.IsNumber(com.Month3))
  278. {
  279. errMessage = "3月份的产能值请输入数字!";
  280. return false;
  281. }
  282. if (Convert.ToDouble(com.Month3) > wellNum)
  283. {
  284. errMessage = "3月份的产能值不能超过最大产能值!";
  285. return false;
  286. }
  287. }
  288. if (com.Month4 != "")
  289. {
  290. if (!StringUtil.IsNumber(com.Month4))
  291. {
  292. errMessage = "4月份的产能值请输入数字!";
  293. return false;
  294. }
  295. if (Convert.ToDouble(com.Month4) > wellNum)
  296. {
  297. errMessage = "4月份的产能值不能超过最大产能值!";
  298. return false;
  299. }
  300. }
  301. if (com.Month5 != "")
  302. {
  303. if (!StringUtil.IsNumber(com.Month5))
  304. {
  305. errMessage = "5月份的产能值请输入数字!";
  306. return false;
  307. }
  308. if (Convert.ToDouble(com.Month5) > wellNum)
  309. {
  310. errMessage = "5月份的产能值不能超过最大产能值!";
  311. return false;
  312. }
  313. }
  314. if (com.Month6 != "")
  315. {
  316. if (!StringUtil.IsNumber(com.Month6))
  317. {
  318. errMessage = "6月份的产能值请输入数字!";
  319. return false;
  320. }
  321. if (Convert.ToDouble(com.Month6) > wellNum)
  322. {
  323. errMessage = "6月份的产能值不能超过最大产能值!";
  324. return false;
  325. }
  326. }
  327. if (com.Month7 != "")
  328. {
  329. if (!StringUtil.IsNumber(com.Month7))
  330. {
  331. errMessage = "7月份的产能值请输入数字!";
  332. return false;
  333. }
  334. if (Convert.ToDouble(com.Month7) > wellNum)
  335. {
  336. errMessage = "7月份的产能值不能超过最大产能值!";
  337. return false;
  338. }
  339. }
  340. if (com.Month8 != "")
  341. {
  342. if (!StringUtil.IsNumber(com.Month8))
  343. {
  344. errMessage = "8月份的产能值请输入数字!";
  345. return false;
  346. }
  347. if (Convert.ToDouble(com.Month8) > wellNum)
  348. {
  349. errMessage = "8月份的产能值不能超过最大产能值!";
  350. return false;
  351. }
  352. }
  353. if (com.Month9 != "")
  354. {
  355. if (!StringUtil.IsNumber(com.Month9))
  356. {
  357. errMessage = "9月份的产能值请输入数字!";
  358. return false;
  359. }
  360. if (Convert.ToDouble(com.Month9) > wellNum)
  361. {
  362. errMessage = "9月份的产能值不能超过最大产能值!";
  363. return false;
  364. }
  365. }
  366. if (com.Month10 != "")
  367. {
  368. if (!StringUtil.IsNumber(com.Month10))
  369. {
  370. errMessage = "10月份的产能值请输入数字!";
  371. return false;
  372. }
  373. if (Convert.ToDouble(com.Month10) > wellNum)
  374. {
  375. errMessage = "10月份的产能值不能超过最大产能值!";
  376. return false;
  377. }
  378. }
  379. if (com.Month11 != "")
  380. {
  381. if (!StringUtil.IsNumber(com.Month11))
  382. {
  383. errMessage = "11月份的产能值请输入数字!";
  384. return false;
  385. }
  386. if (Convert.ToDouble(com.Month11) > wellNum)
  387. {
  388. errMessage = "11月份的产能值不能超过最大产能值!";
  389. return false;
  390. }
  391. }
  392. if (com.Month12 != "")
  393. {
  394. if (!StringUtil.IsNumber(com.Month12))
  395. {
  396. errMessage = "12月份的产能值请输入数字!";
  397. return false;
  398. }
  399. if (Convert.ToDouble(com.Month12) > wellNum)
  400. {
  401. errMessage = "12月份的产能值不能超过最大产能值!";
  402. return false;
  403. }
  404. }
  405. }
  406. else
  407. {
  408. errMessage = "请维护产能井的最大产能!";
  409. return false;
  410. }
  411. return true;
  412. }
  413. private ComBaseWellMonthEntity GetMonthWell(UltraGridRow row)
  414. {
  415. ComBaseWellMonthEntity com = new ComBaseWellMonthEntity();
  416. if (row.Cells["YEAR"].Value.ToString() == "")
  417. {
  418. MessageUtil.ShowWarning("请选择年份!");
  419. return null;
  420. }
  421. com.WellCode = row.Cells["Well_CODE"].Value.ToString();
  422. com.WellName = row.Cells["WELL_NAME"].Value.ToString();
  423. com.Year = row.Cells["YEAR"].Value.ToString();
  424. com.Month1 = row.Cells["MONTH_1"].Value.ToString();
  425. com.Month2 = row.Cells["MONTH_2"].Value.ToString();
  426. com.Month3 = row.Cells["MONTH_3"].Value.ToString();
  427. com.Month4 = row.Cells["MONTH_4"].Value.ToString();
  428. com.Month5 = row.Cells["MONTH_5"].Value.ToString();
  429. com.Month6 = row.Cells["MONTH_6"].Value.ToString();
  430. com.Month7 = row.Cells["MONTH_7"].Value.ToString();
  431. com.Month8 = row.Cells["MONTH_8"].Value.ToString();
  432. com.Month9 = row.Cells["MONTH_9"].Value.ToString();
  433. com.Month10 = row.Cells["MONTH_10"].Value.ToString();
  434. com.Month11 = row.Cells["MONTH_11"].Value.ToString();
  435. com.Month12 = row.Cells["MONTH_12"].Value.ToString();
  436. com.CreateName = UserInfo.GetUserName();
  437. com.UpdateName = UserInfo.GetUserName();
  438. com.Validflag = row.GetValue("VALIDFLAG");
  439. com.Memo = row.GetValue("MEMO");
  440. com.YearOld = row.GetValue("YEAR_OLD");
  441. return com;
  442. }
  443. /// <summary>
  444. /// 设置ultraGrid1行颜色
  445. /// </summary>
  446. private void SetUltraGridStyle()
  447. {
  448. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  449. {
  450. Infragistics.Win.UltraWinGrid.UltraGridRow row = ultraGrid1.Rows[i];
  451. if (!row.Cells["VALIDFLAGNAME"].Value.ToString().Equals("有效"))
  452. {
  453. row.Appearance.ForeColor = Color.Red;
  454. }
  455. else
  456. {
  457. row.Appearance.ForeColor = Color.Black;
  458. }
  459. }
  460. }
  461. private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
  462. {
  463. ultraGrid1.UpdateData();
  464. UltraGridRow ugr = ultraGrid1.ActiveRow;
  465. DataRow[] dr = dataTable1.Select("", "WELL_CODE DESC");
  466. string jic = "";
  467. string jicStr = "";
  468. if (dr.Length > 0)
  469. {
  470. jic = dr[0]["WELL_CODE"].ToString();
  471. }
  472. if (!jic.Equals(""))
  473. {
  474. int number = int.Parse(jic.Substring(1, 3));
  475. jicStr = "J" + string.Format("{0:000}", number + 1);
  476. _jic = number + 1;
  477. }
  478. else
  479. {
  480. jicStr = "J" + string.Format("{0:000}", _jic);
  481. _jic = _jic + 1;
  482. }
  483. //赋值理化索引号
  484. ugr.Cells["WELL_CODE"].Value = jicStr;
  485. ControlGrid1Edit(e.Row);
  486. }
  487. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  488. {
  489. ultraGrid1.UpdateData();
  490. UltraGridRow ugr = ultraGrid1.ActiveRow;
  491. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  492. {
  493. if (!ultraGrid1.Rows[i].Equals(ugr))
  494. {
  495. ultraGrid1.Rows[i].Cells["CHK"].Value = false;
  496. }
  497. }
  498. if (ugr == null || ugr.GetValue("VALIDFLAGNAME") != "有效")
  499. {
  500. ultraGrid2.Enabled = false;
  501. dataTable2.Clear();
  502. return;
  503. }
  504. else
  505. ultraGrid2.Enabled = true;
  506. string wellcode = ugr.Cells["WELL_CODE"].Value.ToString();
  507. QueryMonthWell(wellcode);
  508. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  509. {
  510. Infragistics.Win.UltraWinGrid.UltraGridRow row = ultraGrid2.Rows[i];
  511. if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("有效"))
  512. {
  513. row.Appearance.ForeColor = Color.Red;
  514. }
  515. else
  516. {
  517. row.Appearance.ForeColor = Color.Black;
  518. }
  519. }
  520. }
  521. private void QueryMonthWell(string wellcode)
  522. {
  523. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.getMonthWell", new Object[] { wellcode }, this.ob);
  524. GridHelper.CopyDataToDatatable(ref dt, ref dataTable2, true);
  525. foreach (UltraGridRow row in ultraGrid2.Rows)
  526. {
  527. for (int i = 0; i < row.Cells.Count; i++)
  528. {
  529. if (!row.Cells[i].Column.Key.Equals("CHK"))
  530. row.Cells[i].Activation = Activation.ActivateOnly;
  531. }
  532. }
  533. }
  534. private void ultraGrid2_AfterRowInsert(object sender, RowEventArgs e)
  535. {
  536. UltraGridRow ugr1 = ultraGrid1.ActiveRow;
  537. UltraGridRow ugr2 = ultraGrid2.ActiveRow;
  538. ugr2.Cells["WELL_CODE"].Value = ugr1.Cells["WELL_CODE"].Value.ToString();
  539. ugr2.Cells["WELL_NAME"].Value = ugr1.Cells["WELL_NAME"].Value.ToString();
  540. //增加行如果没有勾选则不可编辑
  541. if (!Convert.ToBoolean(ugr2.Cells["CHK"].Value))
  542. {
  543. for (int i = 0; i < ugr2.Cells.Count; i++)
  544. {
  545. if (!ugr2.Cells[i].Column.Key.Equals("CHK"))
  546. ugr2.Cells[i].Activation = Activation.ActivateOnly;
  547. }
  548. }
  549. }
  550. private void ultraGrid2_CellChange(object sender, CellEventArgs e)
  551. {
  552. ultraGrid2.UpdateData();
  553. if (e.Cell.Column.Key.Equals("CHK"))
  554. {
  555. if (e.Cell.Value.ToString() == "True")
  556. {
  557. CellsCollection cells = e.Cell.Row.Cells;
  558. for (int i = 0; i < cells.Count; i++)
  559. {
  560. if (!cells[i].Column.Key.Equals("CHK"))
  561. {
  562. e.Cell.Row.Cells[i].Activation = Activation.AllowEdit;
  563. }
  564. }
  565. }
  566. else
  567. {
  568. CellsCollection cells = e.Cell.Row.Cells;
  569. for (int i = 0; i < cells.Count; i++)
  570. {
  571. if (!cells[i].Column.Key.Equals("CHK"))
  572. {
  573. e.Cell.Row.Cells[i].Activation = Activation.ActivateOnly;
  574. }
  575. }
  576. }
  577. }
  578. }
  579. private void InitYear()
  580. {
  581. UltraComboEditor uce = new UltraComboEditor();
  582. DataTable dt = new DataTable();
  583. dt.Columns.Add("YEAR", Type.GetType("System.Int32"));
  584. for (int i = 2000; i <= 2100; i++)
  585. dt.Rows.Add(new object[] { i });
  586. uce.DataSource = dt;
  587. uce.ValueMember = "YEAR";
  588. uce.DisplayMember = "YEAR";
  589. this.Controls.Add(uce);
  590. uce.Visible = false;
  591. ultraGrid2.DisplayLayout.Bands[0].Columns["YEAR"].EditorComponent = uce;
  592. ultraGrid2.DisplayLayout.Bands[0].Columns["YEAR"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  593. }
  594. private void FrmComBaseWell_Load(object sender, EventArgs e)
  595. {
  596. InitYear();
  597. ultraGrid2.Enabled = false;
  598. InitUi();
  599. }
  600. private int IsSelected()
  601. {
  602. int i = 0;
  603. foreach (UltraGridRow row in ultraGrid1.Rows)
  604. {
  605. if (row.Cells["CHK"].Value.ToString() == "True")
  606. i++;
  607. }
  608. foreach (UltraGridRow row in ultraGrid2.Rows)
  609. {
  610. if (row.Cells["CHK"].Value.ToString() == "True")
  611. i++;
  612. }
  613. if (i > 0)
  614. return 0;
  615. else
  616. return -1;
  617. }
  618. /// <summary>
  619. /// 检验作废或者恢复
  620. /// </summary>
  621. /// <param name="valid">有效标识</param>
  622. /// <param name="flag"></param>
  623. /// <returns></returns>
  624. private bool CheckDeleteOrResume(string valid, bool flag)
  625. {
  626. if (valid.Equals(""))
  627. {
  628. errMessage = "记录未保存,不能" + (flag ? "作废" : "恢复");
  629. return false;
  630. }
  631. if (flag)
  632. {
  633. if (valid.Equals("无效"))
  634. {
  635. errMessage = "无效记录不能作废";
  636. return false;
  637. }
  638. }
  639. else
  640. {
  641. if (valid.Equals("有效"))
  642. {
  643. errMessage = "有效记录不能恢复";
  644. return false;
  645. }
  646. }
  647. return true;
  648. }
  649. private void DeleteOrResume(bool flag)
  650. {
  651. ultraGrid1.UpdateData();
  652. ultraGrid2.UpdateData();
  653. if (IsSelected() == -1)
  654. {
  655. MessageUtil.ShowWarning("请选择你要操作的记录!");
  656. return;
  657. }
  658. //标准基础
  659. ArrayList wellData = new ArrayList();
  660. UltraGridRow[] rows = GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "CHK" }, new string[] { "True" });
  661. if (rows.Length > 0)
  662. {
  663. foreach (UltraGridRow ugr in rows)
  664. {
  665. ComBaseWellEntity com = GetBaseWell(ugr);
  666. com.DeleteName = UserInfo.GetUserName();
  667. wellData.Add(JSONFormat.Format(com));
  668. if (!CheckDeleteOrResume(com.Validflag, flag))
  669. {
  670. MessageBox.Show(errMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  671. return;
  672. }
  673. _wellname = com.WellName;
  674. if (flag)
  675. {
  676. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.checkWellDelete", new Object[] { com.WellCode }, this.ob);
  677. if (dt != null && dt.Rows.Count > 0 && Convert.ToInt32(dt.Rows[0][0]) > 0)
  678. {
  679. MessageBox.Show("产能井[ " + com.WellName + " ]已经被引用,不能作废!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  680. return;
  681. }
  682. }
  683. }
  684. }
  685. //产能井月量
  686. ArrayList monthData = new ArrayList();
  687. rows = GridHelper.GetRowsWithKey(ultraGrid2, new string[] { "CHK" }, new string[] { "True" });
  688. if (rows.Length > 0)
  689. {
  690. foreach (UltraGridRow ugr in rows)
  691. {
  692. ComBaseWellMonthEntity com = GetMonthWell(ugr);
  693. com.DeleteName = UserInfo.GetUserName();
  694. monthData.Add(JSONFormat.Format(com));
  695. if (!CheckDeleteOrResume(com.Validflag, flag))
  696. {
  697. MessageBox.Show(errMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  698. return;
  699. }
  700. if (flag)
  701. {
  702. //预留判断是否被引用
  703. }
  704. _wellname = com.WellName;
  705. if (!flag)
  706. {
  707. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.checkFromResume", new Object[] { com.WellCode }, this.ob);
  708. if (dt != null && dt.Rows.Count > 0)
  709. {
  710. MessageBox.Show("产能井 [ " + com.WellName + " ]已经作废,不能恢复!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  711. return;
  712. }
  713. }
  714. }
  715. }
  716. if (MessageBox.Show("是否" + (flag ? "作废" : "恢复") + "选择记录", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  717. {
  718. return;
  719. }
  720. if (wellData.Count > 0 || monthData.Count > 0)
  721. {
  722. int count = ServerHelper.SetData("com.steering.pss.qcm.ComBaseWell.deleteOrResume", new Object[] { wellData, monthData, flag }, this.ob);
  723. if (count > 0)
  724. {
  725. MessageBox.Show((flag ? "作废" : "恢复") + "成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
  726. DoQuery(true);
  727. }
  728. }
  729. }
  730. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  731. {
  732. ultraGrid1.UpdateData();
  733. if (e.Cell.Column.Key == "CHK")
  734. {
  735. ControlGrid1Edit(e.Cell.Row);
  736. }
  737. }
  738. private void ControlGrid1Edit(UltraGridRow row)
  739. {
  740. if (row.GetValue("CHK") == "True")
  741. {
  742. row.Cells["WELL_NAME"].Activation = Activation.AllowEdit;
  743. row.Cells["WEIGHT"].Activation = Activation.AllowEdit;
  744. row.Cells["PROCESS_CDOE"].Activation = Activation.AllowEdit;
  745. row.Cells["MEMO"].Activation = Activation.AllowEdit;
  746. }
  747. else
  748. {
  749. row.Cells["WELL_NAME"].Activation = Activation.ActivateOnly;
  750. row.Cells["WEIGHT"].Activation = Activation.ActivateOnly;
  751. row.Cells["PROCESS_CDOE"].Activation = Activation.ActivateOnly;
  752. row.Cells["MEMO"].Activation = Activation.ActivateOnly;
  753. }
  754. }
  755. }
  756. }