frmSteelCode.cs.svn-base 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Collections;
  9. using System.IO;
  10. using System.Diagnostics;
  11. using Infragistics.Win.UltraWinGrid;
  12. using CoreFS.CA06;
  13. using Core.Mes.Client.Common;
  14. namespace Core.LgMes.Client.LgIntegrationQuery
  15. {
  16. public partial class frmSteelCode : frmStyleBase
  17. {
  18. private bool bAddNow, bEditNow, bDelNow; //是否在进行新增、修改或者删除操作
  19. private UltraGridRow currRow = null;
  20. // private CallingMessage par;
  21. private string strReturn = "ExecuteCommand_Return", strNonReturn = "ExecuteCommand_NonReturn";
  22. public frmSteelCode()
  23. {
  24. InitializeComponent();
  25. }
  26. private void frmSteelCode_Load(object sender, EventArgs e)
  27. {
  28. proc_Init();
  29. proc_BindData();
  30. proc_Query("");
  31. proc_SetToolbarButtons();
  32. }
  33. private void proc_Init()
  34. {
  35. try
  36. {
  37. //hengxing
  38. //par = new CallingMessage();
  39. //par.ServerName = "Report";
  40. //par.AssemblyName = "Core.LgMes.Server.Report";
  41. //par.ClassName = "Core.LgMes.Server.Report.reportMethod";
  42. }
  43. catch (Exception ex)
  44. {
  45. MessageBox.Show("初始化失败!\r\n" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  46. if (MessageBox.Show("点击[是]将重新初始化,强烈建议执行此操作!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  47. {
  48. proc_Init();
  49. }
  50. }
  51. }
  52. private void proc_SetToolbarButtons()
  53. {
  54. try
  55. {
  56. ultraToolbarsManager1.Toolbars[0].Tools["QUERY"].SharedProps.Enabled = !(bAddNow || bEditNow || bDelNow);
  57. ultraToolbarsManager1.Toolbars[0].Tools["NEW"].SharedProps.Enabled = !(bAddNow || bEditNow || bDelNow);
  58. ultraToolbarsManager1.Toolbars[0].Tools["MODIFY"].SharedProps.Enabled = (!(bAddNow || bEditNow || bDelNow) && (ultraGrid1.ActiveRow != null));
  59. ultraToolbarsManager1.Toolbars[0].Tools["DEL"].SharedProps.Enabled = (!(bAddNow || bEditNow || bDelNow) && (ultraGrid1.ActiveRow != null));
  60. ultraToolbarsManager1.Toolbars[0].Tools["EXPORT"].SharedProps.Enabled = (!(bAddNow || bEditNow || bDelNow) && ultraGrid1.Rows.Count > 0);
  61. ultraToolbarsManager1.Toolbars[0].Tools["SAVE"].SharedProps.Enabled = (bAddNow || bEditNow);
  62. ultraToolbarsManager1.Toolbars[0].Tools["CANCEL"].SharedProps.Enabled = (bAddNow || bEditNow);
  63. ultraToolbarsManager1.Toolbars[0].Tools["SAVE"].SharedProps.Visible = (bAddNow || bEditNow);
  64. ultraToolbarsManager1.Toolbars[0].Tools["CANCEL"].SharedProps.Visible = (bAddNow || bEditNow);
  65. }
  66. catch { }
  67. }
  68. private void proc_SetUltraGridReadOnly(Infragistics.Win.UltraWinGrid.UltraGridBase ultGrid)
  69. {
  70. foreach (UltraGridRow row in ultGrid.Rows)
  71. {
  72. row.Activation = Activation.NoEdit;
  73. }
  74. }
  75. private void proc_setCellReadOnly(UltraGridRow row, bool bReadOnly)
  76. {
  77. try
  78. {
  79. if (row == null)
  80. return;
  81. if (bReadOnly)
  82. {
  83. row.Activation = Activation.NoEdit;
  84. row.Cells["STEELCODE"].CancelUpdate();
  85. row.Cells["STEELNAME"].CancelUpdate();
  86. }
  87. else
  88. {
  89. row.Activation = Activation.AllowEdit;
  90. row.Cells["STEELCODE"].Activation = Activation.AllowEdit;
  91. row.Cells["STEELNAME"].Activation = Activation.AllowEdit;
  92. row.Cells["RECORDER"].Activation = Activation.NoEdit;
  93. row.Cells["OPTDATE"].Activation = Activation.NoEdit;
  94. }
  95. }
  96. catch (Exception ex)
  97. {
  98. MessageBox.Show(ex.Message);
  99. }
  100. }
  101. private void cbxCode_CheckedChanged(object sender, EventArgs e)
  102. {
  103. cbbCode.Enabled = cbxCode.Checked;
  104. if (!cbxCode.Checked)
  105. {
  106. cbbCode.Text = "";
  107. }
  108. }
  109. private void cbxName_CheckedChanged(object sender, EventArgs e)
  110. {
  111. cbbName.Enabled = cbxName.Checked;
  112. if (!cbxName.Checked)
  113. {
  114. cbbName.Text = "";
  115. }
  116. }
  117. private void proc_BindData()
  118. {
  119. Cursor oldCursor = this.Cursor;
  120. this.Cursor = Cursors.WaitCursor;
  121. try
  122. {
  123. string strErr = "";
  124. string strSql = "select STEELCODE STEELCODE, STEELNAME STEELNAME from BSA_ISTEELCODE order by STEELNAME";
  125. //hengxing
  126. //par.MethodName = strReturn;
  127. //par.args = new object[] { strSql };
  128. DataSet ds = null;//hengxing ClientCommon._RemotingHelp.ExecuteMethod(par, out strErr) as DataSet;
  129. if (strErr != "" || !(ds != null && ds.Tables.Count > 0))
  130. {
  131. MessageBox.Show("查询条件加载失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  132. if (MessageBox.Show("是否重新加载查询条件?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  133. proc_BindData();
  134. return;
  135. }
  136. DataView dvCode = ds.Tables[0].DefaultView;
  137. DataView dvName = ds.Tables[0].Copy().DefaultView;
  138. dvCode.Sort = "STEELCODE";
  139. dvName.Sort = "STEELNAME";
  140. cbbCode.DataSource = dvCode;
  141. cbbCode.DisplayMember = "STEELCODE";
  142. cbbCode.SelectedIndex = -1;
  143. cbbName.DataSource = dvName;
  144. cbbName.DisplayMember = "STEELNAME";
  145. cbbName.SelectedIndex = -1;
  146. }
  147. catch (Exception ex)
  148. {
  149. MessageBox.Show(ex.Message);
  150. }
  151. finally
  152. {
  153. this.Cursor = oldCursor;
  154. }
  155. }
  156. private void proc_Query(string strCode)
  157. {
  158. Cursor oldCursor = this.Cursor;
  159. this.Cursor = Cursors.WaitCursor;
  160. try
  161. {
  162. string strWhere = "where 1 = 1";
  163. if (cbxCode.Checked && cbbCode.Text.Trim().Length > 0)
  164. {
  165. strWhere += " and STEELCODE = '" + cbbCode.Text.Trim() + "'";
  166. }
  167. if (cbxName.Checked && cbbName.Text.Trim().Length > 0)
  168. {
  169. strWhere += " and STEELNAME = '" + cbbName.Text.Trim() + "'";
  170. }
  171. string strErr = "";
  172. string strSql = "select STEELCODE STEELCODE, STEELNAME STEELNAME, "
  173. + "RECORDER RECORDER, to_char(OPTDATE,'yyyy-MM-dd HH24:mi:ss') OPTDATE "
  174. + "from BSA_ISTEELCODE " + strWhere + " order by STEELNAME";
  175. //hengxing
  176. //par.MethodName = strReturn;
  177. //par.args = new object[] { strSql };
  178. DataSet ds = null;//hengxing ClientCommon._RemotingHelp.ExecuteMethod(par, out strErr) as DataSet;
  179. if (strErr != "" || !(ds != null && ds.Tables.Count > 0))
  180. {
  181. MessageBox.Show("钢种信息加载失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  182. if (MessageBox.Show("是否重新加载钢种信息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  183. proc_Query(strCode);
  184. return;
  185. }
  186. if (ds != null && ds.Tables.Count > 0)
  187. {
  188. this.dataTable1.Rows.Clear();
  189. DataRow dr;
  190. for (int iRow = 0; iRow < ds.Tables[0].Rows.Count; iRow++)
  191. {
  192. dr = this.dataTable1.NewRow();
  193. for (int jCol = 0; jCol < ds.Tables[0].Columns.Count; jCol++)
  194. {
  195. dr[ds.Tables[0].Columns[jCol].ColumnName] = Convert.ToString(ds.Tables[0].Rows[iRow][jCol]);
  196. }
  197. this.dataTable1.Rows.Add(dr);
  198. }
  199. ultraGrid1.UpdateData();
  200. }
  201. this.proc_SetUltraGridReadOnly(ultraGrid1);
  202. if (ultraGrid1.Rows.Count > 0)
  203. {
  204. ultraGrid1.ActiveCell = ultraGrid1.Rows[0].Cells["STEELCODE"];
  205. ultraGrid1.Rows[0].Cells["STEELCODE"].Selected = false;
  206. }
  207. if (strCode.Trim().Length == 0) return;
  208. string str = "";
  209. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  210. {
  211. str = Convert.ToString(ultraGrid1.Rows[i].Cells["STEELCODE"].Value);
  212. if (str == strCode)
  213. {
  214. ultraGrid1.ActiveCell = ultraGrid1.Rows[i].Cells["STEELCODE"];
  215. ultraGrid1.Rows[i].Cells["STEELCODE"].Selected = false;
  216. return;
  217. }
  218. }
  219. }
  220. catch (Exception ex)
  221. {
  222. MessageBox.Show(ex.Message);
  223. }
  224. finally
  225. {
  226. this.Cursor = oldCursor;
  227. }
  228. }
  229. private void proc_Add()
  230. {
  231. try
  232. {
  233. if (currRow == null) return;
  234. ultraGrid1.UpdateData();
  235. string strCode = currRow.Cells["STEELCODE"].Text.Trim();
  236. string strName = currRow.Cells["STEELNAME"].Text.Trim();
  237. if (strCode.Length == 0)
  238. {
  239. MessageBox.Show("请输入钢种代码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  240. ultraGrid1.ActiveCell = currRow.Cells["STEELCODE"];
  241. currRow.Cells["STEELCODE"].Selected = false;
  242. return;
  243. }
  244. if (strName.Length == 0)
  245. {
  246. MessageBox.Show("请输入钢种名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  247. ultraGrid1.ActiveCell = currRow.Cells["STEELNAME"];
  248. currRow.Cells["STEELNAME"].Selected = false;
  249. return;
  250. }
  251. string strErr = "";
  252. string strSql = "select count(1) from BSA_ISTEELCODE where STEELCODE = '" + strCode + "'";
  253. //hengxing
  254. //par.MethodName = strReturn;
  255. //par.args = new object[] { strSql };
  256. DataSet ds = null;//hengxing ClientCommon._RemotingHelp.ExecuteMethod(par, out strErr) as DataSet;
  257. if (strErr != "" || !(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0))
  258. {
  259. MessageBox.Show("新增钢种代码[" + strCode + "/" + strName + "]失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  260. return;
  261. }
  262. int iCnt = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
  263. if (iCnt > 0)
  264. {
  265. MessageBox.Show("钢种代码[" + strCode + "]重复,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  266. ultraGrid1.ActiveCell = currRow.Cells["STEELCODE"];
  267. currRow.Cells["STEELCODE"].Selected = false;
  268. return;
  269. }
  270. strErr = "";
  271. strSql = "select count(1) from BSA_ISTEELCODE where STEELNAME = '" + strName + "'";
  272. //hengxing
  273. //par.MethodName = strReturn;
  274. //par.args = new object[] { strSql };
  275. ds = null;//hengxing ClientCommon._RemotingHelp.ExecuteMethod(par, out strErr) as DataSet;
  276. if (strErr != "" || !(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0))
  277. {
  278. MessageBox.Show("新增钢种代码[" + strCode + "/" + strName + "]失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  279. return;
  280. }
  281. iCnt = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
  282. if (iCnt > 0)
  283. {
  284. MessageBox.Show("钢种名称[" + strName + "]重复,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  285. ultraGrid1.ActiveCell = currRow.Cells["STEELNAME"];
  286. currRow.Cells["STEELNAME"].Selected = false;
  287. return;
  288. }
  289. strErr = "";
  290. strSql = "insert into BSA_ISTEELCODE (STEELCODE, STEELNAME, RECORDER, OPTDATE) values "
  291. + "('" + strCode + "', '" + strName + "', '" + this.UserInfo.GetUserName() + "', sysdate)";
  292. //hengxing
  293. //par.MethodName = strNonReturn;
  294. //par.args = new object[] { strSql };
  295. //ClientCommon._RemotingHelp.ExecuteMethod(par, out strErr);
  296. if (!(strErr == null || strErr == ""))
  297. {
  298. MessageBox.Show("新增钢种代码[" + strCode + "/" + strName + "]失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  299. return;
  300. }
  301. this.proc_setCellReadOnly(currRow, true);
  302. this.proc_Query(strCode);
  303. currRow = null;
  304. bAddNow = false;
  305. this.proc_SetToolbarButtons();
  306. MessageBox.Show("新增钢种代码[" + strCode + "/" + strName + "]成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  307. }
  308. catch (Exception ex)
  309. {
  310. MessageBox.Show(ex.Message);
  311. }
  312. }
  313. private void proc_Edit()
  314. {
  315. try
  316. {
  317. if (currRow == null) return;
  318. ultraGrid1.UpdateData();
  319. string strOldCode = Convert.ToString(currRow.Cells["STEELCODE"].Tag);
  320. string strOldName = Convert.ToString(currRow.Cells["STEELNAME"].Tag);
  321. string strCode = currRow.Cells["STEELCODE"].Text.Trim();
  322. string strName = currRow.Cells["STEELNAME"].Text.Trim();
  323. if (strCode.Length == 0)
  324. {
  325. MessageBox.Show("请输入钢种代码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  326. ultraGrid1.ActiveCell = currRow.Cells["STEELCODE"];
  327. currRow.Cells["STEELCODE"].Selected = false;
  328. return;
  329. }
  330. if (strName.Length == 0)
  331. {
  332. MessageBox.Show("请输入钢种名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  333. ultraGrid1.ActiveCell = currRow.Cells["STEELNAME"];
  334. currRow.Cells["STEELNAME"].Selected = false;
  335. return;
  336. }
  337. string strErr = "";
  338. string strSql = "select count(1) from BSA_ISTEELCODE "
  339. + "where STEELCODE = '" + strCode + "' and STEELCODE <> '" + strOldCode + "'";
  340. //par.MethodName = strReturn;
  341. //par.args = new object[] { strSql };
  342. DataSet ds = null;//hengxing ClientCommon._RemotingHelp.ExecuteMethod(par, out strErr) as DataSet;
  343. if (strErr != "" || !(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0))
  344. {
  345. MessageBox.Show("钢种代码[" + strOldCode + "/" + strOldName + "]信息修改失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  346. return;
  347. }
  348. int iCnt = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
  349. if (iCnt > 0)
  350. {
  351. MessageBox.Show("钢种代码[" + strCode + "]重复,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  352. ultraGrid1.ActiveCell = currRow.Cells["STEELCODE"];
  353. currRow.Cells["STEELCODE"].Selected = false;
  354. return;
  355. }
  356. strErr = "";
  357. strSql = "select count(1) from BSA_ISTEELCODE "
  358. + "where STEELNAME = '" + strName + "' and STEELCODE <> '" + strOldCode + "'";
  359. //hengxing
  360. //par.MethodName = strReturn;
  361. //par.args = new object[] { strSql };
  362. ds = null;//hengxing ClientCommon._RemotingHelp.ExecuteMethod(par, out strErr) as DataSet;
  363. if (strErr != "" || !(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0))
  364. {
  365. MessageBox.Show("钢种代码[" + strOldCode + "/" + strOldName + "]信息修改失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  366. return;
  367. }
  368. iCnt = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
  369. if (iCnt > 0)
  370. {
  371. MessageBox.Show("钢种名称[" + strName + "]重复,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  372. ultraGrid1.ActiveCell = currRow.Cells["STEELNAME"];
  373. currRow.Cells["STEELNAME"].Selected = false;
  374. return;
  375. }
  376. strErr = "";
  377. strSql = "update BSA_ISTEELCODE set "
  378. + "STEELCODE = '" + strCode + "', STEELNAME = '" + strName + "', "
  379. + "RECORDER = '" + this.UserInfo.GetUserName() + "', OPTDATE = sysdate "
  380. + "where STEELCODE = '" + strOldCode + "'";
  381. //hengxing
  382. //par.MethodName = strNonReturn;
  383. //par.args = new object[] { strSql };
  384. //ClientCommon._RemotingHelp.ExecuteMethod(par, out strErr);
  385. if (!(strErr == null || strErr == ""))
  386. {
  387. MessageBox.Show("钢种代码[" + strOldCode + "/" + strOldName + "]信息修改失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  388. return;
  389. }
  390. this.proc_setCellReadOnly(currRow, true);
  391. this.proc_Query(strCode);
  392. currRow = null;
  393. bEditNow = false;
  394. this.proc_SetToolbarButtons();
  395. MessageBox.Show("钢种代码[" + strOldCode + "/" + strOldName + "]信息修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  396. }
  397. catch (Exception ex)
  398. {
  399. MessageBox.Show(ex.Message);
  400. }
  401. }
  402. private void proc_Delete()
  403. {
  404. try
  405. {
  406. if (ultraGrid1.Rows.Count <= 0) return;
  407. if (ultraGrid1.ActiveRow == null)
  408. {
  409. MessageBox.Show("请选择要删除的钢种代码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  410. return;
  411. }
  412. UltraGridRow row = ultraGrid1.ActiveRow;
  413. string strCode = Convert.ToString(row.Cells["STEELCODE"].Value);
  414. string strName = Convert.ToString(row.Cells["STEELNAME"].Value);
  415. if (MessageBox.Show("确定要删除钢种代码[" + strCode + "/" + strName + "]信息吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  416. return;
  417. string strErr = "";
  418. string strSql = "select count(1) from BSA_ISTEELCODE where STEELCODE = '" + strCode + "' and STEELNAME = '" + strName + "'";
  419. //hengxing
  420. //par.MethodName = strReturn;
  421. //par.args = new object[] { strSql };
  422. DataSet ds = null;//hengxing ClientCommon._RemotingHelp.ExecuteMethod(par, out strErr) as DataSet;
  423. if (strErr != "" || !(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0))
  424. {
  425. MessageBox.Show("钢种代码[" + strCode + "/" + strName + "]信息删除失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  426. return;
  427. }
  428. int iCnt = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
  429. if (iCnt == 0)
  430. {
  431. MessageBox.Show("不存在钢种代码[" + strCode + "/" + strName + "]信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  432. proc_Query("");
  433. return;
  434. }
  435. strErr = "";
  436. strSql = "delete from BSA_ISTEELCODE where STEELCODE = '" + strCode + "' and STEELNAME = '" + strName + "'";
  437. //hengxing
  438. //par.MethodName = strNonReturn;
  439. //par.args = new object[] { strSql };
  440. //ClientCommon._RemotingHelp.ExecuteMethod(par, out strErr);
  441. if (!(strErr == null || strErr == ""))
  442. {
  443. MessageBox.Show("钢种代码[" + strCode + "/" + strName + "]信息删除失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  444. return;
  445. }
  446. this.proc_Query("");
  447. MessageBox.Show("钢种代码[" + strCode + "/" + strName + "]信息删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  448. }
  449. catch (Exception ex)
  450. {
  451. MessageBox.Show(ex.Message);
  452. }
  453. }
  454. private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  455. {
  456. switch (e.Tool.Key)
  457. {
  458. case "QUERY":
  459. {
  460. if (bAddNow || bEditNow || bDelNow)
  461. return;
  462. proc_Query("");
  463. proc_SetToolbarButtons();
  464. break;
  465. }
  466. case "NEW":
  467. {
  468. if (bAddNow || bEditNow || bDelNow)
  469. return;
  470. currRow = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
  471. this.proc_setCellReadOnly(currRow, false);
  472. ultraGrid1.ActiveCell = currRow.Cells["STEELCODE"];
  473. currRow.Cells["STEELCODE"].Selected = false;
  474. bAddNow = true;
  475. this.proc_SetToolbarButtons();
  476. break;
  477. }
  478. case "MODIFY":
  479. {
  480. if (ultraGrid1.ActiveRow == null || (bAddNow || bEditNow || bDelNow))
  481. return;
  482. currRow = ultraGrid1.ActiveRow;
  483. this.proc_setCellReadOnly(currRow, false);
  484. ultraGrid1.ActiveCell = currRow.Cells["STEELCODE"];
  485. currRow.Cells["STEELCODE"].Selected = false;
  486. currRow.Cells["STEELCODE"].Tag = currRow.Cells["STEELCODE"].Value;
  487. currRow.Cells["STEELNAME"].Tag = currRow.Cells["STEELNAME"].Value;
  488. bEditNow = true;
  489. this.proc_SetToolbarButtons();
  490. break;
  491. }
  492. case "DEL":
  493. {
  494. if (ultraGrid1.ActiveRow == null || (bAddNow || bEditNow || bDelNow))
  495. return;
  496. bDelNow = true;
  497. this.proc_SetToolbarButtons();
  498. proc_Delete();
  499. bDelNow = false;
  500. this.proc_SetToolbarButtons();
  501. break;
  502. }
  503. case "SAVE":
  504. {
  505. if (bAddNow)
  506. {
  507. proc_Add();
  508. }
  509. else if (bEditNow)
  510. {
  511. proc_Edit();
  512. }
  513. break;
  514. }
  515. case "CANCEL":
  516. {
  517. if (!(bAddNow || bEditNow)) return;
  518. string strOpt = " [" + (bAddNow ? "新增" : (bEditNow ? "修改" : "")) + "]";
  519. if (MessageBox.Show("确定要取消" + strOpt + "操作吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  520. return;
  521. if (bAddNow)
  522. {
  523. currRow.Delete(false);
  524. currRow = null;
  525. if (ultraGrid1.Rows.Count > 0)
  526. {
  527. ultraGrid1.ActiveCell = ultraGrid1.Rows[ultraGrid1.Rows.Count - 1].Cells["STEELCODE"];
  528. ultraGrid1.Rows[ultraGrid1.Rows.Count - 1].Cells["STEELCODE"].Selected = false;
  529. }
  530. bAddNow = false;
  531. }
  532. else if (bEditNow)
  533. {
  534. this.proc_setCellReadOnly(currRow, true);
  535. currRow.Cells["STEELCODE"].Value = currRow.Cells["STEELCODE"].Tag;
  536. currRow.Cells["STEELNAME"].Value = currRow.Cells["STEELNAME"].Tag;
  537. ultraGrid1.ActiveCell = currRow.Cells["STEELCODE"];
  538. currRow.Cells["STEELCODE"].Selected = false;
  539. currRow = null;
  540. bEditNow = false;
  541. }
  542. this.proc_SetToolbarButtons();
  543. break;
  544. }
  545. case "EXPORT":
  546. {
  547. if ((bAddNow || bEditNow || bDelNow) || ultraGrid1.Rows.Count <= 0)
  548. return;
  549. bool bInstalled = (Type.GetTypeFromProgID("Excel.Application") != null);
  550. if (!bInstalled)
  551. {
  552. MessageBox.Show("系统没有安装EXCEL组件,无法导出数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  553. return;
  554. }
  555. string strFileName = Application.StartupPath + "\\Report\\钢种代码.xls";
  556. ultraGridExcelExporter1.Export(ultraGrid1, strFileName);
  557. ProcessStartInfo p = new ProcessStartInfo(strFileName);
  558. p.WorkingDirectory = Path.GetDirectoryName(strFileName);
  559. Process.Start(p);
  560. break;
  561. }
  562. case "CLOSE":
  563. {
  564. this.Close();
  565. break;
  566. }
  567. }
  568. }
  569. private void frmSteelCode_FormClosing(object sender, FormClosingEventArgs e)
  570. {
  571. try
  572. {
  573. if (bAddNow)
  574. {
  575. if (MessageBox.Show("[新增]操作尚未完成,确定要关闭吗?", "提示", MessageBoxButtons.OKCancel,
  576. MessageBoxIcon.Question) == DialogResult.Cancel)
  577. e.Cancel = true;
  578. else
  579. {
  580. bAddNow = false;
  581. e.Cancel = false;
  582. }
  583. }
  584. else if (bEditNow)
  585. {
  586. if (MessageBox.Show("[修改]操作尚未完成,确定要关闭吗?", "提示", MessageBoxButtons.OKCancel,
  587. MessageBoxIcon.Question) == DialogResult.Cancel)
  588. e.Cancel = true;
  589. else
  590. {
  591. bEditNow = false;
  592. e.Cancel = false;
  593. }
  594. }
  595. }
  596. catch (Exception ex)
  597. {
  598. MessageBox.Show(ex.Message);
  599. }
  600. }
  601. }
  602. }