FrmComMscPhyStdNote.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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.Collections.Generic;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Windows.Forms;
  12. namespace Core.StlMes.Client.Qcm
  13. {
  14. public partial class FrmComMscPhyStdNote : FrmBase
  15. {
  16. public FrmComMscPhyStdNote()
  17. {
  18. InitializeComponent();
  19. // this.MaximizeBox = false;
  20. this.MinimizeBox = false;
  21. }
  22. private string pic; //理化标准索引号
  23. public string Pic
  24. {
  25. get { return pic; }
  26. set { pic = value; }
  27. }
  28. private string index; //理化标准索引号-序号
  29. public string Index
  30. {
  31. get { return index; }
  32. set { index = value; }
  33. }
  34. private string phyCode; //检验项代码
  35. public string PhyCode
  36. {
  37. get { return phyCode; }
  38. set { phyCode = value; }
  39. }
  40. private string phyName; //检验项名称
  41. public string PhyName
  42. {
  43. get { return phyName; }
  44. set { phyName = value; }
  45. }
  46. private OpeBase newOb; //ob对象
  47. public OpeBase NewOb
  48. {
  49. get { return newOb; }
  50. set { newOb = value; }
  51. }
  52. private string sResult;
  53. public string SResult
  54. {
  55. get { return sResult; }
  56. set { sResult = value; }
  57. }
  58. private string sResult2; //预留
  59. public string SResult2
  60. {
  61. get { return sResult2; }
  62. set { sResult2 = value; }
  63. }
  64. private string noteIndex;
  65. public string NoteIndex
  66. {
  67. get { return noteIndex; }
  68. set { noteIndex = value; }
  69. }
  70. private string stdMin;
  71. public string StdMin
  72. {
  73. get { return stdMin; }
  74. set { stdMin = value; }
  75. }
  76. private string stdGuid;
  77. public string StdGuid
  78. {
  79. get { return stdGuid; }
  80. set { stdGuid = value; }
  81. }
  82. private bool isCustAlphaPopup = false;
  83. public bool IsCustAlphaPopup
  84. {
  85. get { return isCustAlphaPopup; }
  86. set { isCustAlphaPopup = value; }
  87. }
  88. string stdDesc = "";
  89. private void FrmComMscPhyStdNote_Load(object sender, EventArgs e)
  90. {
  91. if (isCustAlphaPopup)
  92. {
  93. ultraToolbarsManager1.Tools["ButtonTool2"].SharedProps.Visible = false;
  94. ultraToolbarsManager1.Tools["ButtonTool5"].SharedProps.Visible = false;
  95. ultraGroupBox1.Visible = false;
  96. }
  97. DoQuery();
  98. }
  99. private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  100. {
  101. if (e.Tool.Key.Equals("ButtonTool1")) //查询
  102. {
  103. DoQuery();
  104. }
  105. else if (e.Tool.Key.Equals("ButtonTool2")) //新增
  106. {
  107. DoAdd();
  108. }
  109. else if (e.Tool.Key.Equals("ButtonTool3")) //选择确定
  110. {
  111. DoChoose();
  112. }
  113. else if (e.Tool.Key.Equals("ButtonTool5")) //修改
  114. {
  115. DoUpdate();
  116. }
  117. else if (e.Tool.Key.Equals("ButtonTool6")) //关闭
  118. {
  119. if (MessageBox.Show("是否关闭本窗口?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  120. return;
  121. this.Close();
  122. }
  123. }
  124. private void DoQuery()
  125. {
  126. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreMscPhyStdNote.doQuery", new object[] { this.PhyCode }, this.newOb);
  127. GridHelper.CopyDataToDatatable(ref dt, ref dataTable1, true);
  128. //DataTable dt1 = ServerHelper.GetData("com.steering.pss.qcm.CoreMscPhyStdNote.queryGuid", new object[] { this.Pic, this.Index }, this.NewOb);
  129. //string strGuid = "";
  130. //if (dt1 != null && dt1.Rows.Count > 0)
  131. //{
  132. // strGuid = dt1.Rows[0][0].ToString();
  133. //}
  134. foreach (UltraGridRow row in ultraGrid1.Rows)
  135. {
  136. if (row.Cells["STD_DESC"].Value.ToString() == stdDesc)
  137. {
  138. row.Activate();
  139. break;
  140. }
  141. }
  142. if (stdGuid != "")
  143. {
  144. foreach (UltraGridRow row in ultraGrid1.Rows)
  145. {
  146. if (row.Cells["GUID"].Value.ToString() == stdGuid)
  147. {
  148. row.RowSelectorAppearance.BackColor = Color.Yellow;
  149. break;
  150. }
  151. }
  152. }
  153. stdDesc = "";
  154. }
  155. private void DoAdd()
  156. {
  157. if (GetData() == -1)
  158. {
  159. return;
  160. }
  161. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreMscPhyStdNote.isReapt", new object[] { ultraTextEditor2.Text.Trim(), this.PhyCode }, this.NewOb);
  162. if (dt != null && dt.Rows.Count > 0)
  163. {
  164. MessageUtil.ShowWarning("你输入的标准要求重复!");
  165. return;
  166. }
  167. stdDesc = ultraTextEditor2.Text.Trim();
  168. int count = ServerHelper.SetData("com.steering.pss.qcm.CoreMscPhyStdNote.doAdd", new object[] { parmList }, this.NewOb);
  169. if (count > 0)
  170. {
  171. MessageUtil.ShowTips("数据新增成功!");
  172. DoQuery();
  173. }
  174. }
  175. private void DoUpdate()
  176. {
  177. UltraGridRow ugr = ultraGrid1.ActiveRow;
  178. if (ugr == null)
  179. {
  180. MessageUtil.ShowWarning("请选择一条要修改的记录!");
  181. return;
  182. }
  183. if (GetData() == -1)
  184. {
  185. return;
  186. }
  187. //判断要修改的序号是否被组合。
  188. DataTable dtIndex = ServerHelper.GetData("com.steering.pss.qcm.CoreMscPhyStdNote.isGrouped", new object[] { this.PhyCode }, this.NewOb);
  189. if (dtIndex != null && dtIndex.Rows.Count > 0)
  190. {
  191. string indexStr = dtIndex.Rows[0][0].ToString();
  192. if (indexStr != "")
  193. {
  194. indexStr = indexStr.Replace("AND", "{");
  195. indexStr = indexStr.Replace("OR", "}");
  196. string[] arrIndex = indexStr.Split(new char[] { '{', '}', ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  197. for (int i = 0; i < arrIndex.Length; i++)
  198. {
  199. if (arrIndex[i].ToString() == ugr.Cells["INDEX_SEQ"].Value.ToString())
  200. {
  201. MessageUtil.ShowWarning("选择修改的标准说明已被用于组合新标准,无法修改!");
  202. return;
  203. }
  204. }
  205. }
  206. }
  207. //判断要修改的序号是否被引用。
  208. DataTable dtGuid = ServerHelper.GetData("com.steering.pss.qcm.CoreMscPhyStdNote.isRefenced", new object[] { ugr.Cells["GUID"].Value.ToString() }, this.NewOb);
  209. if (dtGuid != null && dtGuid.Rows.Count > 0)
  210. {
  211. MessageUtil.ShowWarning("选择修改的标准说明已被引用,无法修改!");
  212. return;
  213. }
  214. //判断组合的序号是否包含了自身序号。
  215. if (ultraTextEditor3.Text != "")
  216. {
  217. string group = ultraTextEditor3.Text;
  218. group = group.Replace("AND", "{");
  219. group = group.Replace("OR", "}");
  220. string[] arrGroup = group.Split(new char[] { '{', '}', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  221. for (int i = 0; i < arrGroup.Length; i++)
  222. {
  223. if (arrGroup[i] == ugr.Cells["INDEX_SEQ"].Value.ToString())
  224. {
  225. MessageUtil.ShowWarning("标准组合不能引用自身!");
  226. return;
  227. }
  228. }
  229. }
  230. //判断修改的标准要求,或组合的标准要求是否重复。
  231. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreMscPhyStdNote.isReaptUpdate", new object[] { ultraTextEditor2.Text.Trim(), this.PhyCode, ugr.Cells["INDEX_SEQ"].Value.ToString() }, this.NewOb);
  232. if (dt != null && dt.Rows.Count > 0)
  233. {
  234. MessageUtil.ShowWarning("你输入的标准要求重复!");
  235. return;
  236. }
  237. stdDesc = ultraTextEditor2.Text.Trim();
  238. if (MessageBox.Show("是否确认修改数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  239. return;
  240. parmList.RemoveAt(parmList.Count - 1);
  241. parmList.Add(ugr.Cells["PHY_CODE"].Value.ToString());
  242. parmList.Add(ugr.Cells["INDEX_SEQ"].Value.ToString());
  243. int count = ServerHelper.SetData("com.steering.pss.qcm.CoreMscPhyStdNote.doUpdate", new object[] { parmList }, this.NewOb);
  244. if (count > 0)
  245. {
  246. MessageUtil.ShowTips("数据修改成功!");
  247. DoQuery();
  248. }
  249. }
  250. private void DoChoose()
  251. {
  252. UltraGridRow ugr = ultraGrid1.ActiveRow;
  253. if (ugr == null)
  254. {
  255. MessageUtil.ShowWarning("请选择一条需要关联的记录!");
  256. return;
  257. }
  258. if (MessageBox.Show("是否确认关联?是,请到理化标准界面保存关联结果,否则不做处理", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  259. {
  260. return;
  261. }
  262. NoteIndex = ugr.Cells["STD_DESC"].Value.ToString();
  263. StdGuid = ugr.Cells["GUID"].Value.ToString();
  264. this.Close();
  265. // ArrayList list = new ArrayList();
  266. // list.Add(ugr.Cells["GUID"].Value.ToString());
  267. // list.Add(ugr.Cells["STD_DESC"].Value.ToString());
  268. // list.Add(this.Pic);
  269. // list.Add(this.Index);
  270. // int count = ServerHelper.SetData("com.steering.pss.qcm.CoreMscPhyStdNote.updateMaterial", new object[] { list }, this.NewOb);
  271. // if (count > 0)
  272. // {
  273. // MessageUtil.ShowTips("关联成功!");
  274. // DoQuery();
  275. // }
  276. }
  277. ArrayList parmList = new ArrayList();
  278. private int GetData()
  279. {
  280. parmList.Clear();
  281. bool isChecked = ultraCheckEditor1.Checked;
  282. if (isChecked == false && ultraTextEditor2.Text.Trim() == "" && ultraTextEditor3.Text.Trim() == "")
  283. {
  284. MessageUtil.ShowWarning("请输入标准要求!");
  285. return -1;
  286. }
  287. //标准组合序号---
  288. if (ultraCheckEditor1.Checked)
  289. {
  290. if (ultraTextEditor3.Text.Trim() == "")
  291. {
  292. MessageUtil.ShowWarning("请选择标准组合!");
  293. return -1;
  294. }
  295. }
  296. if (ultraTextEditor3.Text.Trim() != "")
  297. {
  298. string str = ultraTextEditor3.Text;
  299. str = str.Replace("AND", "+");
  300. str = str.Replace("OR", "-");
  301. //组合是否合乎数学公式性
  302. if (!TestFormula(str))
  303. {
  304. MessageUtil.ShowWarning("标准组合不合法!");
  305. return -1;
  306. }
  307. //组合的项目是否存在。
  308. if (!isExistNum(str))
  309. {
  310. MessageUtil.ShowWarning("标准组合序号有不存在的序号!");
  311. return -1;
  312. }
  313. }
  314. parmList.Add(this.PhyCode);
  315. parmList.Add(this.PhyName);
  316. parmList.Add(ultraTextEditor2.Text.Trim());
  317. parmList.Add(ultraTextEditor3.Text.Trim());
  318. parmList.Add(this.UserInfo.GetUserName());
  319. parmList.Add(ultraTextEditor4.Text.Trim());
  320. parmList.Add(System.Guid.NewGuid().ToString("N"));
  321. return 0;
  322. }
  323. /// <summary>
  324. /// 组合是否合法
  325. /// </summary>
  326. /// <param name="str"></param>
  327. /// <returns></returns>
  328. private bool TestFormula(string str)
  329. {
  330. decimal? result;
  331. result = str.CompileFormula();
  332. if (result == null)
  333. return false;
  334. return true;
  335. }
  336. string repStr = "A";
  337. /// <summary>
  338. /// 是否存在组合序号然后转化序号组合以及描述
  339. /// </summary>
  340. /// <returns></returns>
  341. private bool isExistNum(string str)
  342. {
  343. SResult = ultraTextEditor3.Text;
  344. string strGroup = sResult; //保留一份副本
  345. char[] ch = new char[] { '(', ')', '+', '-', ' ' };
  346. string[] arrStr = str.Split(ch, StringSplitOptions.RemoveEmptyEntries);
  347. Dictionary<string, string> dicValue = new Dictionary<string, string>(); //标准说明
  348. Dictionary<string, string> dicTemp = new Dictionary<string, string>(); //中间变量
  349. Dictionary<string, string> dicGroup = new Dictionary<string, string>(); //组合序号
  350. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreMscPhyStdNote.doQueryIndex", new object[] { this.PhyCode }, this.newOb);
  351. if (dt != null && dt.Rows.Count > 0)
  352. {
  353. for (int i = 0; i < arrStr.Length; i++)
  354. {
  355. DataRow[] dr = dt.Select("INDEX_SEQ = '" + arrStr[i] + "'");
  356. if (dr.Length <= 0)
  357. {
  358. return false;
  359. }
  360. if (!dicValue.ContainsKey(arrStr[i]))
  361. dicValue.Add(arrStr[i], dr[0]["STD_DESC"].ToString());
  362. if (!dr[0]["INDEX_SEQ_GROUP"].ToString().Equals("") && !dicGroup.ContainsKey(arrStr[i]))
  363. dicGroup.Add(arrStr[i], dr[0]["INDEX_SEQ_GROUP"].ToString());
  364. }
  365. int[] arrInt = StringToInt(arrStr);
  366. string[] tempStr = new string[arrStr.Length];
  367. sResult = sResult.Replace("AND", "且");
  368. sResult = sResult.Replace("OR", "或");
  369. for (int i = 0; i < arrInt.Length; i++)
  370. {
  371. if (dicTemp.ContainsKey(arrInt[i].ToString()))
  372. {
  373. sResult = sResult.Replace(arrInt[i].ToString(), "#" + dicTemp[arrInt[i].ToString()]);
  374. if (dicGroup.ContainsKey(arrInt[i].ToString()))
  375. strGroup = strGroup.Replace(arrInt[i].ToString(), "#" + dicTemp[arrInt[i].ToString()]);
  376. }
  377. else
  378. {
  379. sResult = sResult.Replace(arrInt[i].ToString(), "#" + repStr);
  380. if (dicGroup.ContainsKey(arrInt[i].ToString()))
  381. strGroup = strGroup.Replace(arrInt[i].ToString(), "#" + repStr);
  382. }
  383. dicTemp.Add(repStr, arrInt[i].ToString());
  384. tempStr[i] = repStr;
  385. char newCh = Convert.ToChar(Convert.ToChar(repStr) + 1);
  386. repStr = newCh.ToString();
  387. }
  388. for (int i = 0; i < tempStr.Length; i++)
  389. {
  390. sResult = sResult.Replace("#" + tempStr[i], dicValue[dicTemp[tempStr[i]]]);
  391. if (dicGroup.ContainsKey(dicTemp[tempStr[i]]))
  392. {
  393. strGroup = strGroup.Replace("#" + tempStr[i], dicGroup[dicTemp[tempStr[i]]]);
  394. }
  395. }
  396. ultraTextEditor2.Text = sResult;
  397. ultraTextEditor3.Text = strGroup;
  398. // MessageBox.Show(sResult+"\n"+strGroup);
  399. return true;
  400. }
  401. else
  402. {
  403. return false;
  404. }
  405. }
  406. private int[] StringToInt(string[] arrStr)
  407. {
  408. int[] arrInt = new int[arrStr.Length];
  409. for (int i = 0; i < arrStr.Length; i++)
  410. {
  411. arrInt[i] = Convert.ToInt32(arrStr[i]);
  412. }
  413. arrInt = ArrSort(arrInt);
  414. return arrInt;
  415. }
  416. private int[] ArrSort(int[] arr)
  417. {
  418. for (int i = 0; i < arr.Length; ++i)
  419. {
  420. int temp = arr[i]; //定义一个int变量,并使用获得的数组元素值赋值
  421. int j = i;
  422. while ((j > 0) && (arr[j - 1] < temp)) //判断数组中的元素是否小于获得的值
  423. {
  424. arr[j] = arr[j - 1]; //如果是,则将后一元素的的值提前
  425. --j;
  426. }
  427. arr[j] = temp; //最后将int变量存储的值赋值给最后一个元素
  428. }
  429. return arr;
  430. }
  431. private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e)
  432. {
  433. if (ultraCheckEditor1.Checked)
  434. {
  435. ultraTextEditor3.Enabled = true;
  436. ultraTextEditor3.ReadOnly = true;
  437. }
  438. else
  439. {
  440. ultraTextEditor3.Enabled = false;
  441. }
  442. }
  443. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  444. {
  445. UltraGridRow ugr = ultraGrid1.ActiveRow;
  446. if (ugr == null)
  447. return;
  448. ultraTextEditor2.Text = ugr.Cells["STD_DESC"].Value.ToString();
  449. ultraTextEditor3.Text = ugr.Cells["INDEX_SEQ_GROUP"].Value.ToString();
  450. ultraTextEditor4.Text = ugr.Cells["MEMO"].Value.ToString();
  451. }
  452. private void ultraTextEditor3_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  453. {
  454. UserControlCal usc = new UserControlCal();
  455. usc.CloseEvent += new CloseHandler(usc_CloseEvent);
  456. usc.OkEvent += new OkHandler(usc_OkEvent);
  457. ultraPopupControlContainer1.PopupControl = usc;
  458. int x = ultraGroupBox1.PointToScreen(ultraTextEditor3.Location).X;
  459. int y = ultraGroupBox1.PointToScreen(ultraTextEditor3.Location).Y - usc.Height;
  460. usc.TxtValue = ultraTextEditor3.Text;
  461. ultraPopupControlContainer1.Show(new Point(x, y));
  462. }
  463. void usc_OkEvent(string result, string result2)
  464. {
  465. this.SResult = result;
  466. ultraPopupControlContainer1.Close();
  467. ultraTextEditor3.Text = this.SResult;
  468. }
  469. void usc_CloseEvent()
  470. {
  471. ultraPopupControlContainer1.Close();
  472. }
  473. }
  474. }