FrmWaterRatioStd.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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.UltraWinEditors;
  6. using Infragistics.Win.UltraWinGrid;
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Windows.Forms;
  14. namespace Core.StlMes.Client.Qcm
  15. {
  16. public partial class FrmWaterRatioStd : FrmBase
  17. {
  18. public FrmWaterRatioStd()
  19. {
  20. InitializeComponent();
  21. ExceptionHelper.RegistException();
  22. }
  23. private OpeBase _ob;
  24. public OpeBase Ob
  25. {
  26. get { return _ob; }
  27. set { _ob = value; }
  28. }
  29. //UltraComboEditor stdUce = new UltraComboEditor();
  30. //UltraComboEditor stdUcec = new UltraComboEditor();
  31. UltraCombo stdCombo = new UltraCombo();
  32. UltraCombo stdComboRep = new UltraCombo();
  33. string stdName = "";
  34. private void FrmWaterRatioStd_Load(object sender, EventArgs e)
  35. {
  36. Init();
  37. DoQuery(false);
  38. }
  39. private void InitDrop(UltraCombo uce, string methodID, string showName, string value, Boolean isNull, OpeBase ob)
  40. {
  41. DataTable dt = ServerHelper.GetData(methodID, new Object[] { }, ob);
  42. if (dt != null && dt.Rows.Count > 0 && isNull)
  43. {
  44. DataRow dr = dt.NewRow();
  45. for (int i = 0; i < dt.Columns.Count; i++)
  46. {
  47. dr[i] = "";
  48. }
  49. dt.Rows.InsertAt(dr, 0);
  50. }
  51. uce.DataSource = dt;
  52. uce.DisplayMember = showName;
  53. uce.ValueMember = value;
  54. }
  55. private void Init()
  56. {
  57. //this.Controls.Add(stdCombo);
  58. //this.Controls.Add(stdComboRep);
  59. //stdCombo.Visible = false;
  60. //stdComboRep.Visible = false;
  61. //InitDrop(stdCombo, "com.steering.pss.qcm.WaterRatioRStd.getStd", "STD_NAME", "ID_CODE", true, this._ob);
  62. //InitDrop(stdComboRep, "com.steering.pss.qcm.WaterRatioRStd.getStdReplace", "STD_NAME", "IDCODE", true, this._ob);
  63. //ultraGrid1.DisplayLayout.Bands[0].Columns["STD_NAME_C"].EditorComponent = stdCombo;
  64. //ultraGrid1.DisplayLayout.Bands[0].Columns["STD_NAME_C"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  65. //ultraGrid1.DisplayLayout.Bands[0].Columns["STD_NAME"].EditorComponent = stdComboRep;
  66. //ultraGrid1.DisplayLayout.Bands[0].Columns["STD_NAME"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  67. //stdCombo.DisplayLayout.Bands[0].Columns["ID_CODE"].Hidden = true;
  68. //stdCombo.DisplayLayout.Bands[0].Columns["STD_NAME"].Header.Caption = "标准名称";
  69. //stdCombo.DisplayLayout.Bands[0].Columns["STD_STYLE_DESC"].Header.Caption = "标准类别";
  70. //stdComboRep.DisplayLayout.Bands[0].Columns["IDCODE"].Hidden = true;
  71. //stdComboRep.DisplayLayout.Bands[0].Columns["STD_NAME"].Header.Caption = "标准名称";
  72. //stdComboRep.DisplayLayout.Bands[0].Columns["STD_STYLE_DESC"].Header.Caption = "标准类别";
  73. //stdCombo.DisplayLayout.Bands[0].Columns["STD_NAME"].Width = 240;
  74. //stdComboRep.DisplayLayout.Bands[0].Columns["STD_NAME"].Width = 240;
  75. //ultraGrid1.UpdateData();
  76. }
  77. private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  78. {
  79. if (e.Tool.Key == "ButtonTool1") //保存
  80. {
  81. DoSave();
  82. }
  83. if (e.Tool.Key == "ButtonTool2") //删除
  84. {
  85. DeleteOrResume(true);
  86. }
  87. if (e.Tool.Key == "ButtonTool3") //恢复
  88. {
  89. DeleteOrResume(false);
  90. }
  91. if (e.Tool.Key == "ButtonTool5") //刷新
  92. {
  93. DoRefresh();
  94. }
  95. if (e.Tool.Key == "ButtonTool6") //查询
  96. {
  97. DoQuery(false);
  98. }
  99. if (e.Tool.Key == "ButtonTool7") //查询
  100. {
  101. DoQuery(true);
  102. }
  103. if (e.Tool.Key == "ButtonTool4") //关闭
  104. {
  105. if (MessageBox.Show("是否关闭本窗口?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  106. {
  107. return;
  108. }
  109. this.Close();
  110. }
  111. }
  112. private void DoSave()
  113. {
  114. if (GetData() == -1)
  115. {
  116. return;
  117. }
  118. if (param.Count <= 0 && paramUpdate.Count <= 0)
  119. {
  120. MessageUtil.ShowWarning("请选择要保存的记录!");
  121. return;
  122. }
  123. List<string> list = stdList.Distinct().ToList();
  124. if (list.Count < stdList.Count)
  125. {
  126. MessageUtil.ShowWarning("有重复的标准名称,请重新选择!");
  127. return;
  128. }
  129. if (MessageBox.Show("是否保存所选记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  130. return;
  131. // int count = ServerHelper.SetData("com.steering.pss.qcm.WaterRatioRStd.save", new object[] { param, paramUpdate }, this._ob);
  132. //一个标准只能引用一个水压标准,一个水压标准可被多个标准引用
  133. CoreClientParam ccp = new CoreClientParam();
  134. ccp.ServerName = "com.steering.pss.qcm.WaterRatioRStd";
  135. ccp.MethodName = "save";
  136. ccp.ServerParams = new object[] { param, paramUpdate };
  137. ccp = this._ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  138. if (ccp != null && ccp.ReturnInfo == "FALSE###") //服务端传来的错误信息
  139. {
  140. MessageUtil.ShowWarning("您所选标准已存在引用标准\n或者为水压系数维护的基础标准,无法保存!");
  141. return;
  142. }
  143. if (ccp.ReturnCode == -1)
  144. return;
  145. MessageUtil.ShowTips("保存成功!");
  146. DoQuery(false);
  147. }
  148. ArrayList param = new ArrayList();
  149. ArrayList paramUpdate = new ArrayList();
  150. List<string> stdList = new List<string>();
  151. private int GetData()
  152. {
  153. ultraGrid1.UpdateData();
  154. param = new ArrayList();
  155. paramUpdate = new ArrayList();
  156. stdList.Clear();
  157. foreach (UltraGridRow row in ultraGrid1.Rows)
  158. {
  159. if (row.Cells["CHK"].Value.ToString().ToUpper() == "TRUE")
  160. {
  161. if (row.Cells["STD_NAME_C"].Text.Trim() == "")
  162. {
  163. MessageUtil.ShowWarning("请选择标准名称!");
  164. return -1;
  165. }
  166. if (row.Cells["STD_NAME"].Text.Trim() == "")
  167. {
  168. MessageUtil.ShowWarning("请选择引用标准名称!");
  169. return -1;
  170. }
  171. if (row.Cells["STD_CODE_C"].Value.ToString() == row.Cells["STD_CODE"].Value.ToString())
  172. {
  173. MessageUtil.ShowWarning("标准不能引用自身!");
  174. return -1;
  175. }
  176. if (row.Cells["VALIDFLAG"].Value.ToString() == "")
  177. {
  178. ArrayList list = new ArrayList();
  179. list.Add(row.Cells["ID_"].Value.ToString());
  180. list.Add(row.Cells["STD_CODE_C"].Value.ToString());
  181. list.Add(row.Cells["STD_NAME_C"].Text.Trim());
  182. list.Add(row.Cells["STD_STYLE_C"].Value.ToString());
  183. list.Add(row.Cells["STD_STYLE_DESC_C"].Value.ToString());
  184. list.Add(row.Cells["STD_CODE"].Value.ToString());
  185. list.Add(row.Cells["STD_NAME"].Text.Trim());
  186. list.Add(row.Cells["STD_STYLE"].Value.ToString());
  187. list.Add(row.Cells["STD_STYLE_DESC"].Value.ToString());
  188. list.Add(this.UserInfo.GetUserName());
  189. list.Add(row.Cells["MEMO"].Value.ToString());
  190. param.Add(list);
  191. stdName = row.Cells["STD_NAME_C"].Value.ToString();
  192. }
  193. else
  194. {
  195. ArrayList list = new ArrayList();
  196. list.Add(row.Cells["ID_"].Value.ToString());
  197. list.Add(row.Cells["STD_CODE_C"].Value.ToString());
  198. list.Add(row.Cells["STD_NAME_C"].Text.Trim());
  199. list.Add(row.Cells["STD_STYLE_C"].Value.ToString());
  200. list.Add(row.Cells["STD_STYLE_DESC_C"].Value.ToString());
  201. list.Add(row.Cells["STD_CODE"].Value.ToString());
  202. list.Add(row.Cells["STD_NAME"].Text.Trim());
  203. list.Add(row.Cells["STD_STYLE"].Value.ToString());
  204. list.Add(row.Cells["STD_STYLE_DESC"].Value.ToString());
  205. list.Add(this.UserInfo.GetUserName());
  206. list.Add(row.Cells["MEMO"].Value.ToString());
  207. list.Add(row.Cells["STD_CODE_OLD"].Value.ToString());
  208. paramUpdate.Add(list);
  209. stdName = row.Cells["STD_NAME_C"].Value.ToString();
  210. }
  211. stdList.Add(row.Cells["STD_NAME_C"].Text.Trim());
  212. }
  213. }
  214. return 0;
  215. }
  216. private void DoQuery(bool flag)
  217. {
  218. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.WaterRatioRStd.query", new object[] { flag }, this._ob);
  219. GridHelper.CopyDataToDatatable(ref dt, ref dataTable1, true);
  220. foreach (UltraGridRow row in ultraGrid1.Rows)
  221. {
  222. if (row.Cells["STD_NAME_C"].Value.ToString() == stdName)
  223. {
  224. row.Activate();
  225. break;
  226. }
  227. }
  228. stdName = "";
  229. }
  230. private void DoRefresh()
  231. {
  232. Init();
  233. }
  234. private void DeleteOrResume(bool flag)
  235. {
  236. ultraGrid1.UpdateData();
  237. UltraGridRow[] dr = GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "CHK" }, new string[] { "True" });
  238. if (dr.Length <= 0)
  239. {
  240. MessageUtil.ShowWarning("请选择你要操作的记录!");
  241. return;
  242. }
  243. ArrayList deleteParm = new ArrayList();
  244. foreach (UltraGridRow row in ultraGrid1.Rows)
  245. {
  246. if (row.Cells["CHK"].Value.ToString().ToUpper() == "TRUE")
  247. {
  248. if (flag) //删除
  249. {
  250. if (row.Cells["VALIDFLAG"].Value.ToString() == "")
  251. {
  252. MessageUtil.ShowTips("数据尚未写进数据库!");
  253. return;
  254. }
  255. deleteParm.Add(row.Cells["ID_"].Value.ToString());
  256. }
  257. }
  258. }
  259. if (MessageBox.Show("是否确认" + (flag ? "删除" : "恢复") + "所选数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  260. {
  261. return;
  262. }
  263. int count = ServerHelper.SetData("com.steering.pss.qcm.WaterRatioRStd.delete",
  264. new object[] { deleteParm }, this._ob);
  265. if (count > 0)
  266. {
  267. MessageUtil.ShowTips("数据" + (flag ? "删除" : "恢复") + "成功!");
  268. DoQuery(false);
  269. }
  270. }
  271. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  272. {
  273. ultraGrid1.UpdateData();
  274. UltraGridRow ugr = ultraGrid1.DisplayLayout.ActiveRow;
  275. if (ugr == null)
  276. return;
  277. //if (e.Cell.Column.Key.Equals("STD_NAME_C"))
  278. //{
  279. // if (e.Cell.Text != "")
  280. // {
  281. // DataRow[] dr = ((DataTable)stdCombo.DataSource).Select("ID_CODE ='" + e.Cell.Value.ToString() + "'");
  282. // if (dr.Length > 0)
  283. // {
  284. // ugr.Cells["STD_NAME_C"].Value= e.Cell.Value;
  285. // //ugr.Cells["STD_STYLE_C"].Value = dr[0][2];
  286. // string[] str = null;
  287. // if (dr[0][0].ToString().Contains("#####"))
  288. // {
  289. // str = dr[0][0].ToString().Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
  290. // // _stdCodeC = str[0];
  291. // ugr.Cells["STD_CODE_C"].Value = str[0];
  292. // if (str.Length == 2)
  293. // {
  294. // ugr.Cells["STD_STYLE_C"].Value = str[1];
  295. // }
  296. // }
  297. // ugr.Cells["STD_STYLE_DESC_C"].Value = dr[0][2];
  298. // }
  299. // // ugr.Cells["ID_"].Value = ugr.Cells["STD_CODE_C"].Value.ToString() + ugr.Cells["STD_STYLE_C"].Value.ToString();
  300. // }
  301. // else
  302. // {
  303. // ugr.Cells["STD_NAME_C"].Value = "";
  304. // ugr.Cells["STD_STYLE_C"].Value = "";
  305. // ugr.Cells["STD_STYLE_DESC_C"].Value = "";
  306. // }
  307. //}
  308. //else if (e.Cell.Column.Key.Equals("STD_NAME"))
  309. //{
  310. // if (e.Cell.Text != "")
  311. // {
  312. // DataRow[] dr = ((DataTable)stdComboRep.DataSource).Select("IDCODE ='" + e.Cell.Value.ToString() + "'" );
  313. // if (dr.Length > 0)
  314. // {
  315. // ugr.Cells["STD_NAME"].Value = e.Cell.Value;
  316. // //ugr.Cells["STD_STYLE"].Value = dr[0][2];
  317. // string[] str = null;
  318. // if (dr[0][0].ToString().Contains("#####"))
  319. // {
  320. // str=dr[0][0].ToString().Split(new char[]{'#'},StringSplitOptions.RemoveEmptyEntries);
  321. // //_stdCode = str[0];
  322. // ugr.Cells["STD_CODE"].Value = str[0];
  323. // if(str.Length==2)
  324. // {
  325. // ugr.Cells["STD_STYLE"].Value = str[1];
  326. // }
  327. // }
  328. // ugr.Cells["STD_STYLE_DESC"].Value = dr[0][2];
  329. // }
  330. // // ugr.Cells["ID_"].Value = ugr.Cells["STD_CODE_C"].Value.ToString() + ugr.Cells["STD_STYLE_C"].Value.ToString();
  331. // }
  332. // else
  333. // {
  334. // ugr.Cells["STD_NAME"].Value = "";
  335. // ugr.Cells["STD_STYLE"].Value = "";
  336. // ugr.Cells["STD_STYLE_DESC"].Value = "";
  337. // }
  338. //}
  339. else if (e.Cell.Column.Key.Equals("CHK"))
  340. {
  341. if (e.Cell.Value.ToString().ToUpper() != "TRUE")
  342. {
  343. ugr.Cells["STD_NAME_C"].Activation = Activation.ActivateOnly;
  344. ugr.Cells["STD_NAME"].Activation = Activation.ActivateOnly;
  345. ugr.Cells["MEMO"].Activation = Activation.ActivateOnly;
  346. }
  347. else
  348. {
  349. ugr.Cells["STD_NAME_C"].Activation = Activation.AllowEdit;
  350. ugr.Cells["STD_NAME"].Activation = Activation.AllowEdit;
  351. ugr.Cells["MEMO"].Activation = Activation.AllowEdit;
  352. }
  353. }
  354. }
  355. private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
  356. {
  357. if (e.Row.Cells["VALIDFLAG"].Value.ToString() == "无效")
  358. {
  359. e.Row.Appearance.ForeColor = Color.Red;
  360. }
  361. }
  362. private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
  363. {
  364. ultraGrid1.UpdateData();
  365. UltraGridRow ugr = ultraGrid1.ActiveRow;
  366. if (ugr == null)
  367. return;
  368. if (ugr.Cells["CHK"].Value.ToString().ToUpper() == "TRUE")
  369. {
  370. ugr.Cells["STD_NAME_C"].Activation = Activation.AllowEdit;
  371. ugr.Cells["STD_NAME"].Activation = Activation.AllowEdit;
  372. ugr.Cells["MEMO"].Activation = Activation.AllowEdit;
  373. }
  374. else
  375. {
  376. ugr.Cells["STD_NAME_C"].Activation = Activation.ActivateOnly;
  377. ugr.Cells["STD_NAME"].Activation = Activation.ActivateOnly;
  378. ugr.Cells["MEMO"].Activation = Activation.ActivateOnly;
  379. }
  380. }
  381. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  382. {
  383. ultraGrid1.UpdateData();
  384. UltraGridRow ugr = ultraGrid1.ActiveRow;
  385. if (ugr == null)
  386. return;
  387. if (ugr.Cells["CHK"].Value.ToString().ToUpper() == "TRUE")
  388. {
  389. ugr.Cells["STD_NAME_C"].Activation = Activation.AllowEdit;
  390. ugr.Cells["STD_NAME"].Activation = Activation.AllowEdit;
  391. ugr.Cells["MEMO"].Activation = Activation.AllowEdit;
  392. }
  393. else
  394. {
  395. ugr.Cells["STD_NAME_C"].Activation = Activation.ActivateOnly;
  396. ugr.Cells["STD_NAME"].Activation = Activation.ActivateOnly;
  397. ugr.Cells["MEMO"].Activation = Activation.ActivateOnly;
  398. }
  399. }
  400. private void ultraTextEditor1_EditorButtonClick(object sender, EditorButtonEventArgs e)
  401. {
  402. BaseInfoPopup popup;
  403. string key = ultraGrid1.ActiveCell.Column.Key;
  404. if (key == "STD_NAME_C")
  405. {
  406. this.Cursor = Cursors.WaitCursor;
  407. string stdCode = ultraGrid1.ActiveRow.GetValue("STD_CODE_C");
  408. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.WaterRatioRStd.getStd",
  409. new object[] { }, _ob);
  410. dt.Columns["STD_NAME"].Caption = "标准名称";
  411. dt.Columns["STD_STYLE_DESC"].Caption = "标准类别";
  412. popup = new BaseInfoPopup(dt, "STD_NAME", "STD_CODE", "STD_STYLE");
  413. popup.Load += ((a, b) =>
  414. {
  415. var row = popup.UltraGrid1.Rows.Where(c => c.GetValue("STD_CODE") == stdCode).FirstOrDefault();
  416. if (row != null)
  417. {
  418. row.Activate();
  419. }
  420. this.Cursor = Cursors.Default;
  421. });
  422. if (popup.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  423. {
  424. ultraGrid1.SetActiveRowValue("STD_NAME_C", popup.ChoicedRow.GetValue("STD_NAME"));
  425. ultraGrid1.SetActiveRowValue("STD_CODE_C", popup.ChoicedRow.GetValue("STD_CODE"));
  426. ultraGrid1.SetActiveRowValue("STD_STYLE_DESC_C", popup.ChoicedRow.GetValue("STD_STYLE_DESC"));
  427. ultraGrid1.SetActiveRowValue("STD_STYLE_C", popup.ChoicedRow.GetValue("STD_STYLE"));
  428. ultraGrid1.ActiveRow.Update();
  429. }
  430. }
  431. else if (key == "STD_NAME")
  432. {
  433. this.Cursor = Cursors.WaitCursor;
  434. string stdCode = ultraGrid1.ActiveRow.GetValue("STD_CODE");
  435. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.WaterRatioRStd.getStdReplace",
  436. new object[] { }, _ob);
  437. dt.Columns["STD_NAME"].Caption = "引用标准名称";
  438. dt.Columns["STD_STYLE_DESC"].Caption = "标准类别";
  439. popup = new BaseInfoPopup(dt, "STD_NAME", "STD_CODE", "STD_STYLE");
  440. popup.Load += ((a, b) =>
  441. {
  442. var row = popup.UltraGrid1.Rows.Where(c => c.GetValue("STD_CODE") == stdCode).FirstOrDefault();
  443. if (row != null)
  444. {
  445. row.Activate();
  446. }
  447. this.Cursor = Cursors.Default;
  448. });
  449. if (popup.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  450. {
  451. ultraGrid1.SetActiveRowValue("STD_NAME", popup.ChoicedRow.GetValue("STD_NAME"));
  452. ultraGrid1.SetActiveRowValue("STD_CODE", popup.ChoicedRow.GetValue("STD_CODE"));
  453. ultraGrid1.SetActiveRowValue("STD_STYLE_DESC", popup.ChoicedRow.GetValue("STD_STYLE_DESC"));
  454. ultraGrid1.SetActiveRowValue("STD_STYLE", popup.ChoicedRow.GetValue("STD_STYLE"));
  455. ultraGrid1.ActiveRow.Update();
  456. }
  457. }
  458. }
  459. }
  460. }