FrmDeviceCycleManage.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Core.Mes.Client.Common;
  10. using Infragistics.Win.UltraWinGrid;
  11. using System.Diagnostics;
  12. using CoreFS.CA06;
  13. using System.Collections;
  14. using System.IO;
  15. namespace Core.LgMes.Client.LgDeviceManager
  16. {
  17. public partial class FrmDeviceCycleManage : frmStyleBase
  18. {
  19. public FrmDeviceCycleManage()
  20. {
  21. InitializeComponent();
  22. }
  23. private bool bEditNow;
  24. private UltraGridRow currRow = null;
  25. private void FrmDeviceCycleManage_Load(object sender, EventArgs e)
  26. {
  27. proc_SetToolbarButtons();
  28. _UpdateAfter = new Hashtable();
  29. _UpdateBefore = new Hashtable();
  30. _UpdateColumnName = new Hashtable();
  31. }
  32. public override void ToolBar_Click(object sender, string ToolbarKey)
  33. {
  34. switch (ToolbarKey)
  35. {
  36. case "Query":
  37. {
  38. if (bEditNow)
  39. return;
  40. proc_Query();
  41. proc_SetToolbarButtons();
  42. break;
  43. }
  44. case "Edit":
  45. {
  46. if ((ultraGrid1.ActiveRow == null && ultraGrid2.ActiveRow == null) || bEditNow)
  47. return;
  48. if (tabControl1.SelectedIndex == 0)
  49. currRow = ultraGrid1.ActiveRow;
  50. else
  51. currRow = ultraGrid2.ActiveRow;
  52. this.proc_setCellReadOnly(currRow, false);
  53. bEditNow = true;
  54. this.proc_SetToolbarButtons();
  55. break;
  56. }
  57. case "Save":
  58. {
  59. if (bEditNow)
  60. {
  61. proc_Add("Edit");
  62. }
  63. proc_Query();
  64. break;
  65. }
  66. case "Export":
  67. {
  68. try
  69. {
  70. if (ultraGrid1.Rows.Count == 0 && ultraGrid2.Rows.Count == 0) return;
  71. string strFileName = "设备周期管理" + DateTime.Now.ToString("yyyyMMdd");
  72. SaveFileDialog dlg = new SaveFileDialog();
  73. dlg.Title = "保存";
  74. dlg.OverwritePrompt = true;
  75. dlg.Filter = "Excel文件(*.xls)|*.xls";
  76. dlg.AddExtension = true;
  77. dlg.FileName = strFileName;
  78. if (dlg.ShowDialog() == DialogResult.OK)
  79. {
  80. strFileName = dlg.FileName;
  81. if (tabControl1.SelectedIndex == 0)
  82. ultraGridExcelExporter1.Export(ultraGrid1, strFileName);
  83. else
  84. ultraGridExcelExporter1.Export(ultraGrid2, strFileName);
  85. if (MessageBox.Show("数据导出成功!\r\n需要打开所导出文件吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  86. {
  87. if (tabControl1.SelectedIndex == 0)
  88. ultraGridExcelExporter1.Export(ultraGrid1, strFileName);
  89. else
  90. ultraGridExcelExporter1.Export(ultraGrid2, strFileName);
  91. ProcessStartInfo p = new ProcessStartInfo(strFileName);
  92. p.WorkingDirectory = Path.GetDirectoryName(strFileName);
  93. Process.Start(p);
  94. }
  95. }
  96. }
  97. catch (Exception ex)
  98. {
  99. MessageBox.Show(ex.Message);
  100. }
  101. break;
  102. }
  103. case "Cancel":
  104. {
  105. if (!(bEditNow)) return;
  106. if (MessageBox.Show("确定要取消[修改]操作吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  107. return;
  108. if (bEditNow)
  109. {
  110. this.proc_setCellReadOnly(currRow, true);
  111. currRow = null;
  112. bEditNow = false;
  113. }
  114. this.proc_SetToolbarButtons();
  115. break;
  116. }
  117. case "Close":
  118. {
  119. this.Close();
  120. break;
  121. }
  122. }
  123. }
  124. public void proc_Query()
  125. {
  126. Cursor oldCursor = this.Cursor;
  127. this.Cursor = Cursors.WaitCursor;
  128. try
  129. {
  130. string ccmid = "";
  131. if (tabControl1.SelectedIndex == 0)
  132. ccmid = " in ('5','6')";
  133. else
  134. ccmid = " = '7'";
  135. string sqlStr = string.Format(@"SELECT * FROM DEV_SXD_USE_INFO WHERE CCMID {0} ORDER BY SEQ_NO", ccmid);
  136. //调用服务端方法
  137. CoreClientParam CCP_LgEts = new CoreClientParam();
  138. DataTable dt = new DataTable();
  139. CCP_LgEts.ServerName = "Core.LgMes.Server.Common.ComDBExecute";
  140. CCP_LgEts.MethodName = "doSimpleQuery";
  141. CCP_LgEts.ServerParams = new object[] { sqlStr };
  142. CCP_LgEts.SourceDataTable = dt;
  143. this.ExecuteQueryToDataTable(CCP_LgEts, CoreInvokeType.Internal);
  144. DataSet ds = new DataSet();
  145. if (tabControl1.SelectedIndex == 0)
  146. {
  147. if (dt != null && dt.Rows.Count > 0)
  148. {
  149. this.dataTable1.Rows.Clear();
  150. DataRow dr;
  151. for (int iRow = 0; iRow < dt.Rows.Count; iRow++)
  152. {
  153. dr = this.dataTable1.NewRow();
  154. for (int jCol = 0; jCol < dt.Columns.Count; jCol++)
  155. {
  156. if (this.dataTable1.Columns.Contains(dt.Columns[jCol].ColumnName))
  157. {
  158. dr[dt.Columns[jCol].ColumnName] = dt.Rows[iRow][jCol];
  159. }
  160. }
  161. this.dataTable1.Rows.Add(dr);
  162. }
  163. }
  164. ultraGrid1.UpdateData();
  165. if (ultraGrid1.Rows.Count > 0)
  166. {
  167. ultraGrid1.ActiveCell = ultraGrid1.Rows[0].Cells["SEQ_NO"];
  168. ultraGrid1.Rows[0].Cells["SEQ_NO"].Selected = false;
  169. }
  170. this.proc_SetUltraGridReadOnly(ultraGrid1);
  171. if (this.ultraGrid1 != null && ultraGrid1.Rows.Count > 0)
  172. {
  173. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in this.ultraGrid1.Rows)
  174. {
  175. if (row.Cells["SEQ_NO"].Value.ToString().Equals("#强制更换周期"))
  176. {
  177. row.Cells["SEQ_NO"].Appearance.BackColor = Color.Red;
  178. continue;
  179. }
  180. if (row.Cells["SEQ_NO"].Value.ToString().Equals("#正常更换周期"))
  181. {
  182. row.Cells["SEQ_NO"].Appearance.BackColor = Color.Yellow;
  183. continue;
  184. }
  185. if (Double.Parse(row.Cells["JJQLJZM"].Value.ToString()) > 180000)
  186. row.Cells["JJQLJZM"].Appearance.BackColor = Color.Red;
  187. else if (Double.Parse(row.Cells["JJQLJZM"].Value.ToString()) > 150000)
  188. row.Cells["JJQLJZM"].Appearance.BackColor = Color.Yellow;
  189. else
  190. row.Cells["JJQLJZM"].Appearance.BackColor = Color.LightGreen;
  191. if (Double.Parse(row.Cells["JJQLJKM"].Value.ToString()) > 180000)
  192. row.Cells["JJQLJKM"].Appearance.BackColor = Color.Red;
  193. else if (Double.Parse(row.Cells["JJQLJKM"].Value.ToString()) > 150000)
  194. row.Cells["JJQLJKM"].Appearance.BackColor = Color.Yellow;
  195. else
  196. row.Cells["JJQLJKM"].Appearance.BackColor = Color.LightGreen;
  197. for (int i = 0; i < 15; i++)
  198. {
  199. if (row.Cells["SEQ_NO"].Value.ToString().Contains("周期"))
  200. break;
  201. if (i == 0)
  202. {
  203. if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 110000)
  204. row.Cells[i + "GGL"].Appearance.BackColor = Color.Red;
  205. else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 100000)
  206. row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow;
  207. else
  208. row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen;
  209. }
  210. if (i > 0 && i < 7)
  211. {
  212. if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 520000)
  213. row.Cells[i + "GGL"].Appearance.BackColor = Color.Red;
  214. else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 460000)
  215. row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow;
  216. else
  217. row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen;
  218. }
  219. if (i > 6 && i < 9)
  220. {
  221. if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 410000)
  222. row.Cells[i + "GGL"].Appearance.BackColor = Color.Red;
  223. else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 350000)
  224. row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow;
  225. else
  226. row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen;
  227. }
  228. if (i == 9)
  229. {
  230. if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 750000)
  231. row.Cells[i + "GGL"].Appearance.BackColor = Color.Red;
  232. else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 690000)
  233. row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow;
  234. else
  235. row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen;
  236. }
  237. if (i > 9 && i < 13)
  238. {
  239. if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 870000)
  240. row.Cells[i + "GGL"].Appearance.BackColor = Color.Red;
  241. else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 810000)
  242. row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow;
  243. else
  244. row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen;
  245. }
  246. if (i > 12 && i < 15)
  247. {
  248. if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 1150000)
  249. row.Cells[i + "GGL"].Appearance.BackColor = Color.Red;
  250. else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 1040000)
  251. row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow;
  252. else
  253. row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen;
  254. }
  255. }
  256. }
  257. }
  258. }
  259. else
  260. {
  261. if (dt != null && dt.Rows.Count > 0)
  262. {
  263. this.dataTable2.Rows.Clear();
  264. DataRow dr;
  265. for (int iRow = 0; iRow < dt.Rows.Count; iRow++)
  266. {
  267. dr = this.dataTable2.NewRow();
  268. for (int jCol = 0; jCol < dt.Columns.Count; jCol++)
  269. {
  270. if (this.dataTable2.Columns.Contains(dt.Columns[jCol].ColumnName))
  271. {
  272. dr[dt.Columns[jCol].ColumnName] = dt.Rows[iRow][jCol];
  273. }
  274. }
  275. this.dataTable2.Rows.Add(dr);
  276. }
  277. }
  278. ultraGrid2.UpdateData();
  279. if (ultraGrid2.Rows.Count > 0)
  280. {
  281. ultraGrid2.ActiveCell = ultraGrid2.Rows[0].Cells["SEQ_NO"];
  282. ultraGrid2.Rows[0].Cells["SEQ_NO"].Selected = false;
  283. }
  284. this.proc_SetUltraGridReadOnly(ultraGrid2);
  285. if (this.ultraGrid2 != null && ultraGrid2.Rows.Count > 0)
  286. {
  287. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in this.ultraGrid2.Rows)
  288. {
  289. if (row.Cells["SEQ_NO"].Value.ToString().Equals("#强制更换周期"))
  290. {
  291. row.Cells["SEQ_NO"].Appearance.BackColor = Color.Red;
  292. continue;
  293. }
  294. if (row.Cells["SEQ_NO"].Value.ToString().Equals("#正常更换周期"))
  295. {
  296. row.Cells["SEQ_NO"].Appearance.BackColor = Color.Yellow;
  297. continue;
  298. }
  299. if (Double.Parse(row.Cells["JJQLJZM"].Value.ToString()) > 110000)
  300. row.Cells["JJQLJZM"].Appearance.BackColor = Color.Red;
  301. else if (Double.Parse(row.Cells["JJQLJZM"].Value.ToString()) > 100000)
  302. row.Cells["JJQLJZM"].Appearance.BackColor = Color.Yellow;
  303. else
  304. row.Cells["JJQLJZM"].Appearance.BackColor = Color.LightGreen;
  305. if (Double.Parse(row.Cells["JJQLJKM"].Value.ToString()) > 110000)
  306. row.Cells["JJQLJKM"].Appearance.BackColor = Color.Red;
  307. else if (Double.Parse(row.Cells["JJQLJKM"].Value.ToString()) > 100000)
  308. row.Cells["JJQLJKM"].Appearance.BackColor = Color.Yellow;
  309. else
  310. row.Cells["JJQLJKM"].Appearance.BackColor = Color.LightGreen;
  311. for (int i = 1; i < 19; i++)
  312. {
  313. if (row.Cells["SEQ_NO"].Value.ToString().Contains("周期"))
  314. break;
  315. if (i > 0 && i < 7)
  316. {
  317. if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 320000)
  318. row.Cells[i + "GGL"].Appearance.BackColor = Color.Red;
  319. else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 300000)
  320. row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow;
  321. else
  322. row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen;
  323. }
  324. if (i > 6 && i < 11)
  325. {
  326. if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 270000)
  327. row.Cells[i + "GGL"].Appearance.BackColor = Color.Red;
  328. else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 250000)
  329. row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow;
  330. else
  331. row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen;
  332. }
  333. if (i > 10 && i < 17)
  334. {
  335. if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 600000)
  336. row.Cells[i + "GGL"].Appearance.BackColor = Color.Red;
  337. else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 550000)
  338. row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow;
  339. else
  340. row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen;
  341. }
  342. if (i == 17)
  343. {
  344. if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 70000)
  345. row.Cells[i + "GGL"].Appearance.BackColor = Color.Red;
  346. else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 60000)
  347. row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow;
  348. else
  349. row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen;
  350. }
  351. if (i == 18)
  352. {
  353. if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 80000)
  354. row.Cells[i + "GGL"].Appearance.BackColor = Color.Red;
  355. else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 70000)
  356. row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow;
  357. else
  358. row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen;
  359. }
  360. }
  361. }
  362. }
  363. }
  364. }
  365. catch
  366. { }
  367. finally
  368. {
  369. this.Cursor = oldCursor;
  370. }
  371. }
  372. public void proc_Add(string flag)
  373. {
  374. try
  375. {
  376. this.ultraGrid1.UpdateData();
  377. this.ultraGrid2.UpdateData();
  378. if (dataTable1.Rows.Count > 0 || dataTable2.Rows.Count > 0)
  379. {
  380. string strErr = "";
  381. string strMess = "";
  382. if (flag == "Edit")
  383. {
  384. ArrayList arryColumn = new ArrayList();
  385. ArrayList arryValue = new ArrayList();
  386. string strCCMID, strSEQ = "";
  387. if (tabControl1.SelectedIndex == 0)
  388. {
  389. strCCMID = this.ultraGrid1.ActiveRow.Cells["CCMID"].Text.Trim();
  390. strSEQ = this.ultraGrid1.ActiveRow.Cells["SEQ_NO"].Text.Trim();
  391. for (int intCount = 0; intCount < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; intCount++)
  392. {
  393. string strKey = ultraGrid1.DisplayLayout.Bands[0].Columns[intCount].Key.ToString();
  394. //判断是否修改过
  395. if (_UpdateColumnName.ContainsKey(strKey) &&
  396. _UpdateColumnName.ContainsValue(ultraGrid1.DisplayLayout.Bands[0].Columns[intCount].Header.Caption))
  397. {
  398. arryColumn.Add(strKey);
  399. arryValue.Add((this.ultraGrid1.ActiveRow.Cells[strKey].Value.ToString().Trim().Length > 0) ? this.ultraGrid1.ActiveRow.Cells[strKey].Value.ToString() : "Empty");
  400. }
  401. }
  402. }
  403. else
  404. {
  405. strCCMID = this.ultraGrid2.ActiveRow.Cells["CCMID"].Text.Trim();
  406. strSEQ = this.ultraGrid2.ActiveRow.Cells["SEQ_NO"].Text.Trim();
  407. for (int intCount = 0; intCount < ultraGrid2.DisplayLayout.Bands[0].Columns.Count; intCount++)
  408. {
  409. string strKey = ultraGrid2.DisplayLayout.Bands[0].Columns[intCount].Key.ToString();
  410. //判断是否修改过
  411. if (_UpdateColumnName.ContainsKey(strKey) &&
  412. _UpdateColumnName.ContainsValue(ultraGrid2.DisplayLayout.Bands[0].Columns[intCount].Header.Caption))
  413. {
  414. arryColumn.Add(strKey);
  415. arryValue.Add((this.ultraGrid2.ActiveRow.Cells[strKey].Value.ToString().Trim().Length > 0) ? this.ultraGrid2.ActiveRow.Cells[strKey].Value.ToString() : "Empty");
  416. }
  417. }
  418. }
  419. string strSqlID = "SaveSxdData.Update";
  420. object[] sArgs = new object[4];
  421. sArgs[0] = strCCMID; //熔炼号
  422. sArgs[1] = strSEQ; //岗位
  423. sArgs[2] = arryColumn; //作业字段名
  424. sArgs[3] = arryValue; //作业数据值
  425. string strError = "";
  426. DialogResult result = DialogResult.No;
  427. result = MessageBox.Show(this, "确实要保存信息吗?", "提示", MessageBoxButtons.YesNo,
  428. MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
  429. if (result == DialogResult.Yes)
  430. {
  431. Cursor oldCursor = this.Cursor;
  432. this.Cursor = Cursors.WaitCursor;//等待光标
  433. try
  434. {
  435. CommonClientToServer ccTs = new CommonClientToServer();
  436. ccTs.ob = ob;
  437. string strRCode = ccTs.ExecuteProcedureFunctions("Core.LgMes.Server.Common.ComDBProcedure",
  438. "ExecProcWithCollParam", strSqlID, sArgs, out strError);
  439. if (strError != "")
  440. {
  441. _UpdateColumnName.Clear();
  442. _UpdateBefore.Clear();
  443. _UpdateAfter.Clear();
  444. this.Cursor = oldCursor;
  445. MessageBox.Show("保存不成功!\n" + strError, "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  446. }
  447. else
  448. {
  449. this.Cursor = oldCursor;
  450. if (_UpdateColumnName != null && _UpdateColumnName.Count > 0)
  451. {
  452. _UpdateColumnName.Clear();
  453. _UpdateBefore.Clear();
  454. _UpdateAfter.Clear();
  455. }
  456. }
  457. }
  458. catch (System.Exception exp)
  459. {
  460. _UpdateColumnName.Clear();
  461. _UpdateBefore.Clear();
  462. _UpdateAfter.Clear();
  463. this.Cursor = oldCursor;
  464. MessageBox.Show("保存不成功!\n" + exp.ToString(), "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  465. }
  466. }
  467. this.proc_setCellReadOnly(currRow, true);
  468. currRow = null;
  469. bEditNow = false;
  470. }
  471. if (strErr == "")
  472. {
  473. dataTable1.AcceptChanges();
  474. //JJBStaticFunction.SetRowEdit(ultraGrid1);
  475. if (!string.IsNullOrEmpty(strMess))
  476. MessageBox.Show(strMess, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  477. }
  478. else
  479. {
  480. MessageBox.Show("保存失败!输入信息已经存在或数据无效。", "错误");
  481. }
  482. if (ultraGrid1.ActiveCell != null)
  483. ultraGrid1.ActiveCell.Activated = false;
  484. this.proc_SetToolbarButtons();
  485. }
  486. }
  487. catch (System.Exception ex)
  488. {
  489. Console.WriteLine(ex.ToString());
  490. }
  491. }
  492. private void proc_SetToolbarButtons()
  493. {
  494. try
  495. {
  496. this.ToolBarItemEnable(this, "Query", !bEditNow);
  497. this.ToolBarItemEnable(this, "Edit", (!bEditNow && (ultraGrid1.ActiveRow != null || ultraGrid2.ActiveRow != null)));
  498. this.ToolBarItemEnable(this, "Export", (!(bEditNow) && (ultraGrid1.Rows.Count > 0 || ultraGrid2.Rows.Count > 0)));
  499. this.ToolBarItemEnable(this, "Save", bEditNow);
  500. this.ToolBarItemEnable(this, "Cancel", bEditNow);
  501. }
  502. catch { }
  503. }
  504. private void proc_setCellReadOnly(UltraGridRow row, bool bReadOnly)
  505. {
  506. try
  507. {
  508. if (row == null)
  509. return;
  510. if (bReadOnly)
  511. {
  512. row.Activation = Activation.ActivateOnly;
  513. row.CellAppearance.BackColor = Color.White;
  514. foreach (Infragistics.Win.UltraWinGrid.UltraGridCell cell in row.Cells)
  515. {
  516. cell.CancelUpdate();
  517. }
  518. }
  519. else
  520. {
  521. row.Activation = Activation.AllowEdit;
  522. row.CellAppearance.BackColor = Color.Khaki;
  523. }
  524. }
  525. catch (Exception ex)
  526. {
  527. MessageBox.Show(ex.Message);
  528. }
  529. }
  530. private void proc_SetUltraGridReadOnly(Infragistics.Win.UltraWinGrid.UltraGridBase ultGrid)
  531. {
  532. foreach (UltraGridRow row in ultGrid.Rows)
  533. {
  534. row.Activation = Activation.ActivateOnly;
  535. }
  536. }
  537. private Hashtable _UpdateBefore; //修改之前值
  538. private Hashtable _UpdateAfter; //修改之后值
  539. private Hashtable _UpdateColumnName; //修改字段名
  540. private void ultraGrid1_BeforeCellUpdate(object sender, BeforeCellUpdateEventArgs e)
  541. {
  542. if (!string.IsNullOrEmpty(e.Cell.Column.Header.Caption.Trim()))
  543. {
  544. if (_UpdateBefore != null && _UpdateBefore.Contains(e.Cell.Column.Key))
  545. {
  546. _UpdateBefore.Remove(e.Cell.Column.Key);
  547. _UpdateColumnName.Remove(e.Cell.Column.Key);
  548. }
  549. _UpdateBefore.Add(e.Cell.Column.Key, e.Cell.Value.ToString());
  550. _UpdateColumnName.Add(e.Cell.Column.Key, e.Cell.Column.Header.Caption);
  551. }
  552. }
  553. private void ultraGrid2_BeforeCellUpdate(object sender, BeforeCellUpdateEventArgs e)
  554. {
  555. if (!string.IsNullOrEmpty(e.Cell.Column.Header.Caption.Trim()))
  556. {
  557. if (_UpdateBefore != null && _UpdateBefore.Contains(e.Cell.Column.Key))
  558. {
  559. _UpdateBefore.Remove(e.Cell.Column.Key);
  560. _UpdateColumnName.Remove(e.Cell.Column.Key);
  561. }
  562. _UpdateBefore.Add(e.Cell.Column.Key, e.Cell.Value.ToString());
  563. _UpdateColumnName.Add(e.Cell.Column.Key, e.Cell.Column.Header.Caption);
  564. }
  565. }
  566. private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
  567. {
  568. _UpdateAfter = new Hashtable();
  569. _UpdateBefore = new Hashtable();
  570. _UpdateColumnName = new Hashtable();
  571. }
  572. }
  573. }