FrmChemistryElements.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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.Drawing;
  10. using System.Windows.Forms;
  11. namespace Core.StlMes.Client.Qcm
  12. {
  13. public partial class FrmChemistryElements : FrmBase
  14. {
  15. public FrmChemistryElements()
  16. {
  17. InitializeComponent();
  18. ExceptionHelper.RegistException();
  19. }
  20. private void FrmChemistryElements_Load(object sender, EventArgs e)
  21. {
  22. //bindcmbStyle();
  23. //this.ultraComboEditor1.SelectedIndex = 0;
  24. this.cmbStyle.SelectedIndex = 0;
  25. }
  26. /// <summary>
  27. /// 重写基类方法
  28. /// </summary>
  29. /// <param name="sender"></param>
  30. /// <param name="ToolbarKey"></param>
  31. public override void ToolBar_Click(object sender, string ToolbarKey)
  32. {
  33. switch (ToolbarKey)
  34. {
  35. case "doQuery":
  36. doQuery();
  37. break;
  38. case "doAdd":
  39. doAdd();
  40. break;
  41. case "doModify":
  42. doModify();
  43. break;
  44. case "doDelete":
  45. this.doDeleteOrResume(true);
  46. break;
  47. case "doResume":
  48. this.doDeleteOrResume(false);
  49. break;
  50. case "Close":
  51. this.Close();
  52. break;
  53. }
  54. }
  55. /// <summary>
  56. /// 验证非空字段
  57. /// </summary>
  58. /// <returns></returns>
  59. private bool ValidInput()
  60. {
  61. if (string.IsNullOrEmpty(txtName.Text.Trim()))
  62. {
  63. MessageBox.Show("请输入化学元素描述!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  64. return false;
  65. }
  66. if (txtRoundCount.Value.ToString() == "")
  67. {
  68. MessageUtil.ShowWarning("请输入修约位数!");
  69. txtRoundCount.Focus();
  70. return false;
  71. }
  72. if (complexIsValid() == false)
  73. {
  74. MessageUtil.ShowWarning("复合化学元素公式错误!");
  75. txtElementsGs.Focus();
  76. return false;
  77. }
  78. return true;
  79. }
  80. private bool complexIsValid()
  81. {
  82. //为化学公式去除+-*/
  83. string[] s = txtElementsGs.Text.Trim().Replace(" ", "").Split('*', '/', '+', '-', ')', '(');
  84. string elements = "''";
  85. int count = 0;
  86. for (int i = 0; i < s.Length; i++)
  87. {
  88. if (s[i].Trim() == "") continue;
  89. //判断是否为数字,如果不是纯数字,则表示是化学元素,添加到ArrayList中,传递到后台。
  90. if (!StringUtil.IsNumber(s[i]) && s[i] != "tanh")
  91. {
  92. if (s[i].ToUpper() == "AS")
  93. s[i] = "ASN";
  94. if (!elements.Contains("'" + s[i].ToUpper() + "'"))
  95. {
  96. elements += ", '" + s[i].ToUpper() + "'";
  97. count++;
  98. }
  99. }
  100. }
  101. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreChemistryElements.complexIsValid",
  102. new object[] { elements }, ob);
  103. if (dt.Rows[0][0].ToString() == count.ToString())
  104. {
  105. return true;
  106. }
  107. return false;
  108. }
  109. /// <summary>
  110. /// 获取Table中最大编号,自增1返回。
  111. /// </summary>
  112. /// <param name="dt"></param>
  113. /// <returns></returns>
  114. private static string AutoCode(DataTable dt)
  115. {
  116. int maxCode = 0;
  117. //substring去除S001中的S,得到001。
  118. string maxCodeString = dt.Rows[0][0].ToString().Substring(1);
  119. //是否为数字
  120. if (StringUtil.IsNumber(maxCodeString))
  121. {
  122. maxCode = Convert.ToInt32(maxCodeString);
  123. }
  124. else
  125. {
  126. MessageBox.Show("传入编号格式有误,请查看代码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  127. }
  128. //比较得出最大id。
  129. for (int i = 1; i < dt.Rows.Count; i++)
  130. {
  131. string maxCodeString_Two = dt.Rows[i][0].ToString().Substring(1);
  132. int maxCode_Two = 0;
  133. if (StringUtil.IsNumber(maxCodeString_Two))
  134. {
  135. maxCode_Two = Convert.ToInt32(maxCodeString_Two);
  136. if (maxCode_Two > maxCode)
  137. {
  138. maxCode = maxCode_Two;
  139. }
  140. }
  141. }
  142. //新增行
  143. maxCode += 1;
  144. string codeTop = "";
  145. if (maxCode < 10)
  146. {
  147. codeTop = "00";
  148. }
  149. else if (maxCode < 100)
  150. {
  151. codeTop = "0";
  152. }
  153. //获取头文字D。
  154. string d = dt.Rows[0][0].ToString().Substring(0, 1);
  155. //头文字+0+最大数字
  156. string newCode = d + codeTop + maxCode;
  157. return newCode;
  158. }
  159. /// <summary>
  160. /// 获取化学元素代码最大值
  161. /// </summary>
  162. /// <returns></returns>
  163. private string GetMaxCode()
  164. {
  165. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreChemistryElements.GetMaxCode", null, this.ob);
  166. string maxCode = "";
  167. if (dt.Rows.Count > 0)
  168. {
  169. if (!"".Equals(dt.Rows[0][0].ToString()))
  170. {
  171. maxCode = dt.Rows[0][0].ToString();
  172. }
  173. else
  174. {
  175. maxCode = "C000";
  176. }
  177. }
  178. return maxCode;
  179. }
  180. /// <summary>
  181. /// 新增
  182. /// </summary>
  183. private void doAdd()
  184. {
  185. if (ValidInput())
  186. {
  187. //验证描述不允许重复。
  188. string name = txtName.Text.Trim();
  189. if (isRepeatName(name))
  190. {
  191. MessageBox.Show("化学元素描述\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  192. return;
  193. }
  194. if ("B".Equals(cmbStyle.Value.ToString()))
  195. {
  196. if ("".Equals(txtElementsGs.Text.Trim()))
  197. {
  198. MessageBox.Show("化学元素类型为复合元素,复合元素计算公式不允许为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  199. return;
  200. }
  201. }
  202. if (MessageUtil.ShowYesNoAndQuestion("是否确认新增?") == DialogResult.No) return;
  203. ArrayList parm = new ArrayList();
  204. //string chenCode = AutoCode(this.dataTable1);
  205. //自动生成编号
  206. string chenCode = StringUtil.SequenceIncrease(GetMaxCode());
  207. parm.Add(chenCode);
  208. parm.Add(name);
  209. parm.Add(cmbStyle.Value.ToString());
  210. parm.Add(txtElementsGs.Text);
  211. parm.Add(this.UserInfo.GetUserName());
  212. parm.Add(txtMemo.Text);
  213. parm.Add(txtRoundCount.Value.ToString2());
  214. parm.Add(ultraNumericEditor1.Value.ToString2());
  215. CoreClientParam ccp = new CoreClientParam();
  216. ccp.ServerName = "com.steering.pss.qcm.CoreChemistryElements";
  217. ccp.MethodName = "doAdd";
  218. ccp.ServerParams = new object[] { parm };
  219. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  220. if (ccp.ReturnCode == -1)
  221. {
  222. return;
  223. }
  224. MessageUtil.ShowTips("新增成功!");
  225. doQuery();
  226. //高亮显示新增的数据
  227. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  228. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  229. {
  230. row = ultraGrid2.Rows[i];
  231. if (row.Cells["CHEM_CODE"].Value.ToString().Equals(chenCode))
  232. {
  233. row.Activate();
  234. break;
  235. }
  236. }
  237. }
  238. }
  239. /// <summary>
  240. /// 验证描述是否重复。
  241. /// </summary>
  242. /// <param name="name"></param>
  243. /// <returns></returns>
  244. private bool isRepeatName(string name)
  245. {
  246. DataTable dt = new DataTable();
  247. dt = ServerHelper.GetData("com.steering.pss.qcm.CoreChemistryElements.GetName", new Object[] { name }, this.ob);
  248. if (dt.Rows.Count > 0)
  249. {
  250. return true;
  251. }
  252. else
  253. {
  254. return false;
  255. }
  256. }
  257. /// <summary>
  258. /// 用于验证修改时,描述是否已存在
  259. /// </summary>
  260. private static string VName = "";
  261. /// <summary>
  262. /// 修改
  263. /// </summary>
  264. private void doModify()
  265. {
  266. if (ultraGrid2.ActiveRow == null)
  267. {
  268. MessageBox.Show("请选择需要修改的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  269. return;
  270. }
  271. string validflagStr = ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value.ToString();
  272. //无效数据不允许修改
  273. if ("0".Equals(validflagStr))
  274. {
  275. MessageBox.Show("无效数据不支持修改操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  276. return;
  277. }
  278. if (ValidInput())
  279. {
  280. //验证描述不允许重复。
  281. string name = txtName.Text.Trim();
  282. if (!VName.Equals(name))
  283. {
  284. if (isRepeatName(name))
  285. {
  286. MessageBox.Show("化学元素描述\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  287. return;
  288. }
  289. }
  290. if ("B".Equals(cmbStyle.Value.ToString()))
  291. {
  292. if ("".Equals(txtElementsGs.Text.Trim()))
  293. {
  294. MessageBox.Show("化学元素类型为复合元素,复合元素计算公式不允许为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  295. return;
  296. }
  297. }
  298. //确认修改吗?
  299. if (MessageBox.Show("是否确认修改选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  300. {
  301. return;
  302. }
  303. ArrayList parm = new ArrayList();
  304. string chenCode = ultraGrid2.ActiveRow.Cells["CHEM_CODE"].Value.ToString();
  305. parm.Add(name);
  306. parm.Add(cmbStyle.Value);
  307. parm.Add(txtElementsGs.Text);
  308. parm.Add(this.UserInfo.GetUserName());
  309. parm.Add(DateTime.Now.ToString());
  310. parm.Add(txtMemo.Text);
  311. parm.Add(txtRoundCount.Value.ToString2());
  312. parm.Add(ultraNumericEditor1.Value.ToString2());
  313. parm.Add(chenCode);
  314. CoreClientParam ccp = new CoreClientParam();
  315. ccp.ServerName = "com.steering.pss.qcm.CoreChemistryElements";
  316. ccp.MethodName = "doModify";
  317. ccp.ServerParams = new object[] { parm };
  318. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  319. if (ccp.ReturnCode == -1) return;
  320. MessageUtil.ShowTips("修改成功!");
  321. doQuery();
  322. //高亮显示新增的数据
  323. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  324. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  325. {
  326. row = ultraGrid2.Rows[i];
  327. if (row.Cells["CHEM_CODE"].Value.ToString().Equals(chenCode))
  328. {
  329. row.Activate();
  330. break;
  331. }
  332. }
  333. }
  334. }
  335. /// <summary>
  336. /// 查询
  337. /// </summary>
  338. private void doQuery()
  339. {
  340. //txtElementsGs
  341. if ("B".Equals(cmbStyle.Value.ToString().Trim()))
  342. {
  343. txtElementsGs.Enabled = true;
  344. }
  345. else
  346. {
  347. txtElementsGs.Enabled = false;
  348. }
  349. bool validFlag = chkValid.Checked;
  350. string titleName = txtTitleName.Text.Trim();
  351. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreChemistryElements.getLineList", new Object[] { validFlag, titleName }, this.ob);
  352. GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
  353. //不同颜色区分是否有效数据
  354. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  355. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  356. {
  357. row = ultraGrid2.Rows[i];
  358. if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
  359. {
  360. row.Appearance.ForeColor = Color.Red;
  361. }
  362. else
  363. {
  364. row.Appearance.ForeColor = Color.Black;
  365. }
  366. }
  367. //列自适应
  368. GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid2, new UltraGridColumn[] {
  369. ultraGrid2.DisplayLayout.Bands[0].Columns["MEMO"]
  370. });
  371. }
  372. /// <summary>
  373. /// GRID ROW激活时信息带至编辑区
  374. /// </summary>
  375. /// <param name="sender"></param>
  376. /// <param name="e"></param>
  377. private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
  378. {
  379. Infragistics.Win.UltraWinGrid.UltraGridRow row = ultraGrid2.ActiveRow;
  380. if (row != null)
  381. {
  382. txtName.Text = row.Cells["CHEM_NAME"].Value.ToString();
  383. VName = txtName.Text.Trim();
  384. cmbStyle.Value = row.Cells["CHEM_TYPE"].Value.ToString();
  385. txtElementsGs.Text = row.Cells["CHEM_FORMULA"].Value.ToString();
  386. txtMemo.Text = row.Cells["MEMO"].Value.ToString();
  387. txtRoundCount.Value = row.Cells["ROUNDING_DIGITS"].Value;
  388. ultraNumericEditor1.Value = row.Cells["CHEM_SEQ"].Value;
  389. }
  390. }
  391. /// <summary>
  392. /// 作废或恢复
  393. /// </summary>
  394. /// <param name="isDelete">true作废 false恢复</param>
  395. private void doDeleteOrResume(bool isDelete)
  396. {
  397. if (ultraGrid2.ActiveRow == null)
  398. {
  399. MessageBox.Show("请选择需要" + (isDelete ? "作废" : "恢复") + "的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  400. return;
  401. }
  402. string validflagStr = ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value.ToString();
  403. //无效数据不允许作废
  404. if ("0".Equals(validflagStr))
  405. {
  406. if (isDelete)
  407. {
  408. MessageBox.Show("无效数据不支持作废操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  409. return;
  410. }
  411. }
  412. else
  413. {
  414. //有效数据不允许恢复
  415. if (!isDelete)
  416. {
  417. MessageBox.Show("有效数据不支持恢复操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  418. return;
  419. }
  420. }
  421. ArrayList param = new ArrayList();
  422. string chemCode = ultraGrid2.ActiveRow.Cells["CHEM_CODE"].Value.ToString();
  423. param.Add(chemCode);
  424. if (param.Count > 0 && MessageBox.Show("是否确认" + (isDelete ? "作废" : "恢复") + "选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  425. {
  426. int count = ServerHelper.SetData("com.steering.pss.qcm.CoreChemistryElements.deleteLineInfo", new Object[] { param, UserInfo.GetUserName(), isDelete }, this.ob);
  427. if (count > 0)
  428. {
  429. MessageUtil.ShowTips((isDelete ? "作废" : "恢复") + "成功!");
  430. doQuery();
  431. Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null;
  432. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  433. {
  434. rowD = ultraGrid2.Rows[i];
  435. if (rowD.Cells["CHEM_CODE"].Value.ToString().Equals(chemCode))
  436. {
  437. rowD.Activate();
  438. break;
  439. }
  440. }
  441. }
  442. }
  443. }
  444. private void bindcmbStyle()
  445. {
  446. DataTable dt = new DataTable();
  447. dt.Columns.Add("id");
  448. dt.Columns.Add("name");
  449. DataRow dr = dt.NewRow();
  450. dr["id"] = "A";
  451. dr["name"] = "单一元素";
  452. DataRow drB = dt.NewRow();
  453. drB["id"] = "B";
  454. drB["name"] = "复合元素";
  455. dt.Rows.Add(dr);
  456. dt.Rows.Add(drB);
  457. dt.Columns["id"].Caption = "编号";
  458. dt.Columns["name"].Caption = "名称";
  459. cmbStyle.DataSource = dt;
  460. cmbStyle.DisplayMember = "name";
  461. cmbStyle.ValueMember = "id";
  462. }
  463. private void cmbStyle_ValueChanged(object sender, EventArgs e)
  464. {
  465. if (cmbStyle.Value.Equals("A"))
  466. {
  467. txtElementsGs.Text = "";
  468. txtElementsGs.Enabled = false;
  469. }
  470. else
  471. {
  472. txtElementsGs.Enabled = true;
  473. }
  474. }
  475. }
  476. }