FrmBaseSynchronizeRelation.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Windows.Forms;
  6. using Core.Mes.Client.Comm.Control;
  7. using Core.Mes.Client.Comm.Format;
  8. using Core.Mes.Client.Comm.Tool;
  9. using Core.StlMes.Client.Lims.Data.PipeAndOutdec.封装类.实体类;
  10. using CoreFS.CA06;
  11. using Infragistics.Win.UltraWinEditors;
  12. using Infragistics.Win.UltraWinTree;
  13. using Core.StlMes.Client.Lims.Data.PipeAndOutdec.数据管理.基础信息管理;
  14. namespace Core.StlMes.Client.Lims.Data.PipeAndOutdec
  15. {
  16. public partial class FrmBaseSynchronizeRelation : FrmBase
  17. {
  18. private ComBasePhyEntityFull _comBasePhyEntityFull = new ComBasePhyEntityFull();
  19. private bool isAdd = false;
  20. public FrmBaseSynchronizeRelation()
  21. {
  22. InitializeComponent();
  23. }
  24. private void FrmBaseSynchronizeRelation_Load(object sender, EventArgs e)
  25. {
  26. EntityHelper.ShowGridCaption<PipeCheckconsignPhyrelationEntity>(ugGrid.DisplayLayout.Bands[0]);
  27. doQuery2();
  28. }
  29. /// <summary>
  30. /// 重写基类方法
  31. /// </summary>
  32. /// <param name="sender"></param>
  33. /// <param name="ToolbarKey"></param>
  34. public override void ToolBar_Click(object sender, string ToolbarKey)
  35. {
  36. switch (ToolbarKey)
  37. {
  38. case "Query":
  39. doQuery();
  40. break;
  41. case "Add":
  42. doAdd();
  43. break;
  44. case "Update":
  45. doUpdate();
  46. break;
  47. case "Delete":
  48. doDelete();
  49. break;
  50. case "Close":
  51. Close();
  52. break;
  53. }
  54. }
  55. private void doUpdate()
  56. {
  57. if (upEdit.Visible)
  58. {
  59. btnSave_Click(null, null);
  60. }
  61. else
  62. {
  63. if (ugGrid.ActiveRow == null)
  64. {
  65. MessageBox.Show("请选择需要更新的数据!");
  66. return;
  67. }
  68. var pipeCheckconsignPhyrelationEntity = ugGrid.ActiveRow.ListObject as PipeCheckconsignPhyrelationEntity;
  69. if (pipeCheckconsignPhyrelationEntity == null) return;
  70. upEdit.Visible = true;
  71. upShow.Visible = false;
  72. SetValue(pipeCheckconsignPhyrelationEntity);
  73. }
  74. }
  75. private void doDelete()
  76. {
  77. if (ugGrid.ActiveRow == null)
  78. {
  79. MessageBox.Show("请选择需要删除的数据!");
  80. return;
  81. }
  82. var pipeCheckconsignPhyrelationEntity = ugGrid.ActiveRow.ListObject as PipeCheckconsignPhyrelationEntity;
  83. if (pipeCheckconsignPhyrelationEntity == null) return;
  84. var ccp = new CoreClientParam();
  85. ccp.ServerName = "com.steering.lims.data.base.FrmBaseSynchronizeRelation";
  86. ccp.MethodName = "doDelete";
  87. ccp.ServerParams = new object[] { pipeCheckconsignPhyrelationEntity.Relationkey };
  88. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  89. if (ccp.ReturnCode != -1)
  90. if (ccp.ReturnInfo.Equals("删除成功!"))
  91. {
  92. doQuery();
  93. MessageUtil.ShowTips(ccp.ReturnInfo);
  94. }
  95. else
  96. {
  97. MessageUtil.ShowTips(ccp.ReturnInfo);
  98. }
  99. }
  100. private void doAdd()
  101. {
  102. if (upEdit.Visible)
  103. {
  104. btnSave_Click(null, null);
  105. }
  106. else
  107. {
  108. upEdit.Visible = true;
  109. upShow.Visible = false;
  110. PipeCheckconsignPhyrelationEntity pipeCheckconsignPhyrelationEntity;
  111. if (ugGrid.ActiveRow == null)
  112. {
  113. pipeCheckconsignPhyrelationEntity = new PipeCheckconsignPhyrelationEntity();
  114. }
  115. else
  116. {
  117. pipeCheckconsignPhyrelationEntity = ugGrid.ActiveRow.ListObject as PipeCheckconsignPhyrelationEntity;
  118. }
  119. SetValue(pipeCheckconsignPhyrelationEntity, true);
  120. }
  121. }
  122. private void doQuery()
  123. {
  124. if (tbMain.SelectedTab.Index == 0)
  125. doQuery1();
  126. else if (tbMain.SelectedTab.Index == 1)
  127. doQuery2();
  128. }
  129. private void doQuery1()
  130. {
  131. var PhyCode = "";
  132. var PhyTypeC = "";
  133. var PhyType = "";
  134. if (chkPhyCode.Checked)
  135. PhyCode = cboPhyCodeQuery.Value.ToString();
  136. if (chkPhyTypeC.Checked)
  137. PhyTypeC = cboPhyTypeCQuery.Value.ToString();
  138. if (chkPhyType.Checked)
  139. PhyType = cboPhyTypeQuery.Value.ToString();
  140. List<PipeCheckconsignPhyrelationEntity> listSource = EntityHelper.GetData<PipeCheckconsignPhyrelationEntity>
  141. (
  142. "com.steering.lims.data.base.FrmBaseSynchronizeRelation.doQuery",
  143. new object[] {PhyCode, PhyTypeC, PhyType}, ob);
  144. pipeCheckconsignPhyrelationEntityBindingSource.DataSource = listSource;
  145. PublicPipeAndOutdec.RefreshAndAutoSizeColumns(ugGrid, new object[] {}, false);
  146. }
  147. private void doQuery2()
  148. {
  149. var wf = new WaitingForm2("正在查询,请稍候....");
  150. try
  151. {
  152. List<PipeCheckconsignPhyrelationEntity> listSource = EntityHelper.GetData<PipeCheckconsignPhyrelationEntity>
  153. (
  154. "com.steering.lims.data.base.FrmBaseSynchronizeRelation.doQuery",
  155. new object[] {}, ob);
  156. treeMain.Nodes.Clear();
  157. UltraTreeNode activeNode = null;
  158. treeMain.Nodes.AddRange(
  159. listSource.GroupBy(p => new {p.PhyType, p.PhyTypeName})
  160. .Select(
  161. p =>
  162. {
  163. var node = new UltraTreeNode
  164. {
  165. Text = string.Format(@"{0}-({1})", p.Key.PhyTypeName, p.Key.PhyType),
  166. Tag = p.Key.PhyType
  167. };
  168. if (_comBasePhyEntityFull != null && _comBasePhyEntityFull.PhyCodeC == p.Key.PhyType)
  169. {
  170. node.Expanded = true;
  171. }
  172. node.Nodes.AddRange(
  173. p.GroupBy(a => new {a.PhyTypeC, a.PhyTypeCName}).ToList().Select(a =>
  174. {
  175. var nodeC = new UltraTreeNode
  176. {
  177. Text = string.Format(@"{0}-({1})", a.Key.PhyTypeCName, a.Key.PhyTypeC),
  178. Tag = a.Key.PhyTypeC
  179. };
  180. if (_comBasePhyEntityFull != null && _comBasePhyEntityFull.PhyCodeC == p.Key.PhyType &&
  181. _comBasePhyEntityFull.PhyCodeB == a.Key.PhyTypeC)
  182. {
  183. nodeC.Expanded = true;
  184. }
  185. nodeC.Nodes.AddRange(
  186. a.GroupBy(b => new {b.PhyCode, b.PhyName}).Select(b =>
  187. {
  188. var nodeD = new UltraTreeNode
  189. {
  190. Text = string.Format(@"{0}-({1})", b.Key.PhyName, b.Key.PhyCode),
  191. Tag = b.ToList()
  192. };
  193. if (_comBasePhyEntityFull != null && _comBasePhyEntityFull.PhyCodeC == p.Key.PhyType &&
  194. _comBasePhyEntityFull.PhyCodeB == a.Key.PhyTypeC && _comBasePhyEntityFull.PhyCodeA == b.Key.PhyCode)
  195. {
  196. activeNode = nodeD;
  197. }
  198. return nodeD;
  199. }).ToArray());
  200. return nodeC;
  201. }).ToArray());
  202. return node;
  203. }
  204. ).ToArray());
  205. if (activeNode != null)
  206. {
  207. activeNode.Selected = true;
  208. treeMain.ActiveNode = activeNode;
  209. }
  210. wf.Close();
  211. Cursor = Cursors.Default;
  212. }
  213. catch (Exception ex)
  214. {
  215. wf.Close();
  216. Cursor = Cursors.Default;
  217. MessageBox.Show(ex.Message);
  218. }
  219. }
  220. private void treeMain_AfterActivate(object sender, NodeEventArgs e)
  221. {
  222. if (treeMain.ActiveNode == null) return;
  223. upShow.Visible = true;
  224. upEdit.Visible = false;
  225. if (treeMain.ActiveNode.HasNodes) return;
  226. ugGrid.DataSource = treeMain.ActiveNode.Tag as List<PipeCheckconsignPhyrelationEntity>;
  227. ugGrid.Update();
  228. PublicPipeAndOutdec.RefreshAndAutoSizeColumns(ugGrid, new object[] {}, false);
  229. }
  230. private void btnSave_Click(object sender, EventArgs e)
  231. {
  232. var data = GetEntity();
  233. if (data.PhyCode == "")
  234. {
  235. MessageUtil.ShowWarning("检验项不能为空");
  236. return;
  237. }
  238. if (data.PhyTypeC == "")
  239. {
  240. MessageUtil.ShowWarning("试样组不能为空");
  241. return;
  242. }
  243. if (data.PhyType == "")
  244. {
  245. MessageUtil.ShowWarning("检验大项不能为空");
  246. return;
  247. }
  248. if (string.IsNullOrWhiteSpace(data.Relationkey))
  249. {
  250. var ccp = new CoreClientParam();
  251. ccp.ServerName = "com.steering.lims.data.base.FrmBaseSynchronizeRelation";
  252. ccp.MethodName = "doAdd";
  253. ccp.ServerParams = new object[] {JSONFormat.Format(data)};
  254. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  255. if (ccp.ReturnCode != -1)
  256. if (ccp.ReturnInfo.Equals("新增成功!"))
  257. {
  258. MessageUtil.ShowTips(ccp.ReturnInfo);
  259. doQuery();
  260. }
  261. else
  262. {
  263. MessageUtil.ShowTips(ccp.ReturnInfo);
  264. }
  265. }
  266. else
  267. {
  268. var ccp = new CoreClientParam();
  269. ccp.ServerName = "com.steering.lims.data.base.FrmBaseSynchronizeRelation";
  270. ccp.MethodName = "doUpdate";
  271. ccp.ServerParams = new object[] {JSONFormat.Format(data)};
  272. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  273. if (ccp.ReturnCode != -1)
  274. if (ccp.ReturnInfo.Equals("修改成功!"))
  275. {
  276. MessageUtil.ShowTips(ccp.ReturnInfo);
  277. doQuery();
  278. }
  279. else
  280. {
  281. MessageUtil.ShowTips(ccp.ReturnInfo);
  282. }
  283. }
  284. }
  285. private void btnCancle_Click(object sender, EventArgs e)
  286. {
  287. upEdit.Visible = false;
  288. upShow.Visible = true;
  289. }
  290. private void SetValue(PipeCheckconsignPhyrelationEntity pipeCheckconsignPhyrelationEntity,bool isAdd = false)
  291. {
  292. _comBasePhyEntityFull = new ComBasePhyEntityFull
  293. {
  294. PhyCodeA = pipeCheckconsignPhyrelationEntity.PhyCode,
  295. PhyNameA = pipeCheckconsignPhyrelationEntity.PhyName,
  296. PhyCodeB = pipeCheckconsignPhyrelationEntity.PhyTypeC,
  297. PhyNameB = pipeCheckconsignPhyrelationEntity.PhyTypeCName,
  298. PhyCodeC = pipeCheckconsignPhyrelationEntity.PhyType,
  299. PhyNameC = pipeCheckconsignPhyrelationEntity.PhyTypeName
  300. };
  301. SetComBasePhyFull();
  302. cboPhyCodeDir.Tag = pipeCheckconsignPhyrelationEntity.PhyCodeDir;
  303. cboPhyCodeDir.Text = pipeCheckconsignPhyrelationEntity.PhyNameDir;
  304. cboValuename.Text = pipeCheckconsignPhyrelationEntity.Valuename;
  305. txtDbColumn1.Text = pipeCheckconsignPhyrelationEntity.DbColumn1;
  306. txtDbColumn2.Text = pipeCheckconsignPhyrelationEntity.DbColumn2;
  307. txtDbColumn3.Text = pipeCheckconsignPhyrelationEntity.DbColumn3;
  308. txtDbColumn4.Text = pipeCheckconsignPhyrelationEntity.DbColumn4;
  309. txtDbColumn5.Text = pipeCheckconsignPhyrelationEntity.DbColumn5;
  310. txtDbColumn6.Text = pipeCheckconsignPhyrelationEntity.DbColumn6;
  311. txtDbPara1.Text = pipeCheckconsignPhyrelationEntity.DbPara1;
  312. txtDbPara2.Text = pipeCheckconsignPhyrelationEntity.DbPara2;
  313. txtDbPara3.Text = pipeCheckconsignPhyrelationEntity.DbPara3;
  314. txtDbParaValue1.Text = pipeCheckconsignPhyrelationEntity.DbParaValue1;
  315. txtDbParaValue2.Text = pipeCheckconsignPhyrelationEntity.DbParaValue2;
  316. txtDbParaValue3.Text = pipeCheckconsignPhyrelationEntity.DbParaValue3;
  317. txtFormula1.Text = pipeCheckconsignPhyrelationEntity.Formula1;
  318. txtFormula2.Text = pipeCheckconsignPhyrelationEntity.Formula2;
  319. txtFormula3.Text = pipeCheckconsignPhyrelationEntity.Formula3;
  320. txtFormula4.Text = pipeCheckconsignPhyrelationEntity.Formula4;
  321. txtFormula5.Text = pipeCheckconsignPhyrelationEntity.Formula5;
  322. if (!isAdd)
  323. txtKey.Text = pipeCheckconsignPhyrelationEntity.Relationkey;
  324. }
  325. private void SetComBasePhyFull()
  326. {
  327. cboPhyCode.Tag = _comBasePhyEntityFull.PhyCodeA;
  328. cboPhyCode.Text = _comBasePhyEntityFull.PhyNameA;
  329. cboPhyTypeC.Tag = _comBasePhyEntityFull.PhyCodeB;
  330. cboPhyTypeC.Text = _comBasePhyEntityFull.PhyNameB;
  331. cboPhyType.Tag = _comBasePhyEntityFull.PhyCodeC;
  332. cboPhyType.Text = _comBasePhyEntityFull.PhyNameC;
  333. showButton();
  334. }
  335. public void showButton()
  336. {
  337. cboPhyCode.ButtonsRight["Edit"].Visible = true;
  338. cboPhyCode.ButtonsRight["Comm"].Visible = cboPhyCode.Tag.ToString2() != "0000";
  339. cboPhyTypeC.ButtonsRight["Edit"].Visible = cboPhyCode.Tag.ToString2() == "0000";
  340. cboPhyTypeC.ButtonsRight["Comm"].Visible = cboPhyTypeC.ButtonsRight["Edit"].Visible &&
  341. (cboPhyTypeC.Tag.ToString2() != "0000");
  342. cboPhyType.ButtonsRight["Edit"].Visible = cboPhyTypeC.Tag.ToString2() == "0000";
  343. cboPhyType.ButtonsRight["Comm"].Visible = cboPhyType.ButtonsRight["Edit"].Visible &&
  344. (cboPhyType.Tag.ToString2() != "0000");
  345. }
  346. private PipeCheckconsignPhyrelationEntity GetEntity()
  347. {
  348. var pipeCheckconsignPhyrelationEntity = new PipeCheckconsignPhyrelationEntity
  349. {
  350. PhyCode = cboPhyCode.Tag.ToString2(),
  351. PhyName = cboPhyCode.Text,
  352. PhyCodeDir = cboPhyCodeDir.Tag.ToString2(),
  353. PhyNameDir = cboPhyCodeDir.Text,
  354. PhyType = cboPhyType.Tag.ToString2(),
  355. PhyTypeName = cboPhyType.Text,
  356. PhyTypeC = cboPhyTypeC.Tag.ToString2(),
  357. PhyTypeCName = cboPhyTypeC.Text,
  358. Valuename = cboValuename.Text,
  359. DbColumn1 = txtDbColumn1.Text,
  360. DbColumn2 = txtDbColumn2.Text,
  361. DbColumn3 = txtDbColumn3.Text,
  362. DbColumn4 = txtDbColumn4.Text,
  363. DbColumn5 = txtDbColumn5.Text,
  364. DbColumn6 = txtDbColumn6.Text,
  365. DbPara1 = txtDbPara1.Text,
  366. DbPara2 = txtDbPara2.Text,
  367. DbPara3 = txtDbPara3.Text,
  368. DbParaValue1 = txtDbParaValue1.Text,
  369. DbParaValue2 = txtDbParaValue2.Text,
  370. DbParaValue3 = txtDbParaValue3.Text,
  371. Formula1 = " " + txtFormula1.Text,
  372. Formula2 = " " + txtFormula2.Text,
  373. Formula3 = " " + txtFormula3.Text,
  374. Formula4 = " " + txtFormula4.Text,
  375. Formula5 = " " + txtFormula5.Text,
  376. Relationkey = txtKey.Text
  377. };
  378. return pipeCheckconsignPhyrelationEntity;
  379. }
  380. private void cboPhyCode_EditorButtonClick(object sender, EditorButtonEventArgs e)
  381. {
  382. var ultraTextEditor = sender as UltraTextEditor;
  383. if (ultraTextEditor == null) return;
  384. if (e.Button.Key == "Comm")
  385. {
  386. ultraTextEditor.Tag = "0000";
  387. ultraTextEditor.Text = "通用";
  388. showButton();
  389. }
  390. else if (e.Button.Key == "Edit")
  391. {
  392. using (var PhyCodeSelect = new PhyCodeSelect(ob, _comBasePhyEntityFull, ultraTextEditor == cboPhyCode ? "1" : ultraTextEditor == cboPhyTypeC?"2":ultraTextEditor == cboPhyType?"3":"'"))
  393. {
  394. if (PhyCodeSelect.ShowDialog() == DialogResult.OK)
  395. {
  396. _comBasePhyEntityFull = PhyCodeSelect.SelectRow;
  397. SetComBasePhyFull();
  398. }
  399. }
  400. }
  401. }
  402. private void cboPhyCodeDir_EditorButtonClick(object sender, EditorButtonEventArgs e)
  403. {
  404. using (var phyCodeSelect = new PhyCodeSelect(ob, new ComBasePhyEntityFull(), "1"))
  405. {
  406. if (phyCodeSelect.ShowDialog() == DialogResult.OK)
  407. {
  408. cboPhyCodeDir.Tag = phyCodeSelect.SelectRow.PhyCodeA;
  409. cboPhyCodeDir.Text = phyCodeSelect.SelectRow.PhyNameA;
  410. }
  411. }
  412. }
  413. }
  414. }