ComBaseInfoCtrl.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using Core.Mes.Client.Comm.Tool;
  2. using Core.StlMes.Client.Qcm.BLL;
  3. using Core.StlMes.Client.Qcm.model;
  4. using CoreFS.CA06;
  5. using CoreFS.SA06;
  6. using Infragistics.Win.UltraWinGrid;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Windows.Forms;
  13. namespace Core.StlMes.Client.Qcm.Control
  14. {
  15. public partial class ComBaseInfoCtrl : UserControl
  16. {
  17. private ComBaseInfoBLL _baseInfoBLL;
  18. private string _sortCode = "";
  19. private string _baseName = "";
  20. private string _validflag = "";
  21. public ComBaseInfoCtrl(System.Windows.Forms.Control container, OpeBase ob)
  22. {
  23. InitializeComponent();
  24. _baseInfoBLL = new ComBaseInfoBLL(ob);
  25. container.Controls.Add(this);
  26. this.Dock = DockStyle.Fill;
  27. EntityHelper.ShowGridCaption<ComBaseInfoEntity>(ultraGrid1.DisplayLayout.Bands[0]);
  28. }
  29. public void Query(string sortCode, string baseName, string validflag)
  30. {
  31. _sortCode = sortCode;
  32. _baseName = baseName;
  33. _validflag = validflag;
  34. List<ComBaseInfoEntity> baseInfoEntitys = _baseInfoBLL.Query(sortCode, baseName, validflag);
  35. comBaseInfoEntityBindingSource.DataSource = baseInfoEntitys;
  36. foreach (var row in ultraGrid1.Rows)
  37. {
  38. GridEdite(row);
  39. }
  40. }
  41. public void Relocat(string baseCode)
  42. {
  43. Query(_sortCode, _baseName, _validflag);
  44. var row = ultraGrid1.Rows.Where(a => a.GetValue("BASECODE") == baseCode).FirstOrDefault();
  45. if (row != null)
  46. {
  47. row.Activate();
  48. }
  49. }
  50. public void Save()
  51. {
  52. var chkRows = ultraGrid1.Rows.Where(a => a.GetValue("Chk") == "True");
  53. if (chkRows.Count() == 0)
  54. {
  55. MessageUtil.ShowWarning("请选择记录!");
  56. return;
  57. }
  58. var groupRows = chkRows.GroupBy(a => a.GetValue("BASENAME"));
  59. if (chkRows.Count() > groupRows.Count())
  60. {
  61. MessageUtil.ShowWarning("在保存的数据中,存在重复项!");
  62. return;
  63. }
  64. List<ComBaseInfoEntity> baseInfoEntitys = new List<ComBaseInfoEntity>();
  65. string baseCode = "";
  66. foreach (var chkRow in chkRows)
  67. {
  68. ComBaseInfoEntity parm = EntityHelper.CopyEntity<ComBaseInfoEntity>(chkRow.ListObject);
  69. if (parm.Validflag == "")
  70. {
  71. parm.Basecode = "N";
  72. }
  73. if (_baseInfoBLL.QueryBaseNameCnt(_sortCode, parm.Basename, parm.Basecode) > 0)
  74. {
  75. MessageUtil.ShowWarning("系统已经存在探伤级别——" + parm.Basename + "!");
  76. return;
  77. }
  78. parm.CreateName = CoreUserInfo.UserInfo.GetUserName();
  79. parm.UpdateName = CoreUserInfo.UserInfo.GetUserName();
  80. baseInfoEntitys.Add(parm);
  81. baseCode = parm.Basecode;
  82. }
  83. if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == DialogResult.No)
  84. {
  85. return;
  86. }
  87. _baseInfoBLL.Save(baseInfoEntitys);
  88. MessageUtil.ShowTips("保存成功!");
  89. Relocat(baseCode);
  90. }
  91. public void UpdateValidflag(string validflag)
  92. {
  93. var chkRows = ultraGrid1.Rows.Where(a => a.GetValue("Chk") == "True");
  94. if (chkRows.Count() == 0)
  95. {
  96. MessageUtil.ShowWarning("请选择记录!");
  97. return;
  98. }
  99. List<ComBaseInfoEntity> baseInfoEntitys = new List<ComBaseInfoEntity>();
  100. string baseCode = "";
  101. foreach (var chkRow in chkRows)
  102. {
  103. ComBaseInfoEntity parm = EntityHelper.CopyEntity<ComBaseInfoEntity>(chkRow.ListObject);
  104. parm.DeleteName = CoreUserInfo.UserInfo.GetUserName();
  105. parm.UpdateName = CoreUserInfo.UserInfo.GetUserName();
  106. baseInfoEntitys.Add(parm);
  107. baseCode = parm.Basecode;
  108. }
  109. if (MessageUtil.ShowYesNoAndQuestion("是否确认" + (validflag == "0" ? "作废" : "恢复") + "?") == DialogResult.No)
  110. {
  111. return;
  112. }
  113. _baseInfoBLL.UpdateValidflag(baseInfoEntitys, validflag);
  114. MessageUtil.ShowTips((validflag == "0" ? "作废" : "恢复") + "成功!");
  115. Relocat(baseCode);
  116. }
  117. private void GridEdite(UltraGridRow row)
  118. {
  119. if (row.GetValue("Chk") == "True")
  120. {
  121. foreach (UltraGridCell cell in row.Cells)
  122. {
  123. if (cell.Column.CellActivation == Activation.AllowEdit)
  124. {
  125. cell.Activation = Activation.AllowEdit;
  126. }
  127. }
  128. }
  129. else
  130. {
  131. foreach (UltraGridCell cell in row.Cells)
  132. {
  133. if (cell.Column.Key == "Chk") continue;
  134. if (cell.Column.CellActivation == Activation.AllowEdit)
  135. {
  136. cell.Activation = Activation.ActivateOnly;
  137. }
  138. }
  139. }
  140. }
  141. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  142. {
  143. ultraGrid1.UpdateData();
  144. GridEdite(e.Cell.Row);
  145. }
  146. private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
  147. {
  148. e.Row.Cells["SortCode"].Value = _sortCode;
  149. }
  150. private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
  151. {
  152. if (e.Row.GetValue("VALIDFLAG") == "无效")
  153. {
  154. e.Row.Appearance.ForeColor = Color.Red;
  155. }
  156. }
  157. }
  158. }