ComBaseWaterGroupFrm.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 Infragistics.Win.UltraWinGrid;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Windows.Forms;
  12. namespace Core.StlMes.Client.Qcm
  13. {
  14. public partial class ComBaseWaterGroupFrm : FrmBase
  15. {
  16. private ComBaseWaterGroupBLL _waterGroupBLL;
  17. private List<ComBaseWaterGroupEntity> _waterGroupGradeList;
  18. public ComBaseWaterGroupFrm()
  19. {
  20. InitializeComponent();
  21. EntityHelper.ShowGridCaption<ComBaseWaterGroupEntity>(ultraGrid1.DisplayLayout.Bands[0]);
  22. EntityHelper.ShowGridCaption<ComBaseWaterGroupEntity>(ultraGrid2.DisplayLayout.Bands[0]);
  23. }
  24. private void ComBaseWaterGroupFrm_Load(object sender, EventArgs e)
  25. {
  26. _waterGroupBLL = new ComBaseWaterGroupBLL(ob);
  27. QueryWaterGroup();
  28. }
  29. public override void ToolBar_Click(object sender, string ToolbarKey)
  30. {
  31. base.ToolBar_Click(sender, ToolbarKey);
  32. switch (ToolbarKey)
  33. {
  34. case "Query":
  35. QueryWaterGroup();
  36. break;
  37. case "Save":
  38. SaveWaterGroup();
  39. break;
  40. case "MoveUp":
  41. MoveUp();
  42. break;
  43. case "MoveDown":
  44. MoveDown();
  45. break;
  46. case "Close":
  47. this.Close();
  48. break;
  49. }
  50. }
  51. private void QueryWaterGroup()
  52. {
  53. this.comBaseWaterGroupEntityBindingSource.DataSource = _waterGroupBLL.QueryWaterGroup();
  54. ultraGrid1.UpdateData();
  55. }
  56. private void QueryWaterGroupGrade()
  57. {
  58. ComBaseWaterGroupEntity waterGroup = (ComBaseWaterGroupEntity)ultraGrid1.ActiveRow.ListObject;
  59. _waterGroupGradeList = _waterGroupBLL.QueryWaterGroupGrade(waterGroup.WaterGroupCode);
  60. this.comBaseWaterGroupEntityBindingSource1.DataSource = _waterGroupGradeList.AsQueryable()
  61. .OrderByDescending(a => a.Chk).ThenBy(a => a.GradeIndex, new NullMaxCompare()).ThenBy(a => a.Gradename);
  62. foreach (UltraGridRow row in ultraGrid2.Rows)
  63. {
  64. ComBaseWaterGroupEntity waterGroup2 = (ComBaseWaterGroupEntity)row.ListObject;
  65. if (waterGroup2.WaterGroupCode != "")
  66. {
  67. row.SetValue("Chk", "True");
  68. }
  69. }
  70. ultraGrid2.UpdateData();
  71. }
  72. /// <summary>
  73. /// 空认为是最大的值
  74. /// </summary>
  75. private class NullMaxCompare : IComparer<decimal?>
  76. {
  77. #region IComparer<string> 成员
  78. public int Compare(decimal? x, decimal? y)
  79. {
  80. if (x == y)
  81. {
  82. return 0;
  83. }
  84. else if (x == null)
  85. {
  86. return Convert.ToInt32(99999 - y);
  87. }
  88. else if (y == null)
  89. {
  90. return Convert.ToInt32(x - 99999);
  91. }
  92. else
  93. {
  94. return Convert.ToInt32(x - y);
  95. }
  96. }
  97. #endregion
  98. }
  99. ///// <summary>
  100. ///// 空认为是最小的值
  101. ///// </summary>
  102. //private class NullSmallCompare : IComparer<decimal?>
  103. //{
  104. // #region IComparer<string> 成员
  105. // public int Compare(decimal? x, decimal? y)
  106. // {
  107. // if (x == y)
  108. // {
  109. // return 0;
  110. // }
  111. // else if (x == null)
  112. // {
  113. // return 0;
  114. // }
  115. // else if (y == null)
  116. // {
  117. // return 0;
  118. // }
  119. // else if (x > y)
  120. // {
  121. // return 1;
  122. // }
  123. // else
  124. // {
  125. // return -1;
  126. // }
  127. // }
  128. // #endregion
  129. //}
  130. private void SaveWaterGroup()
  131. {
  132. ultraGrid2.UpdateData();
  133. if (ultraGrid1.ActiveRow == null)
  134. {
  135. MessageUtil.ShowWarning("请选择一行记录!");
  136. return;
  137. }
  138. if (ultraGrid1.ActiveRow.GetValue("WaterGroup") == "")
  139. {
  140. MessageUtil.ShowWarning("请输入连浇群组名称!");
  141. return;
  142. }
  143. var rows = ultraGrid2.Rows.AsQueryable().Where("CHK = 'True'");
  144. var waterGroups = rows.Select(a => (ComBaseWaterGroupEntity)a.ListObject);
  145. if (rows.Count() == 0)
  146. {
  147. MessageUtil.ShowWarning("请选择记录!");
  148. return;
  149. }
  150. string waterGroupDesc = ultraGrid1.ActiveRow.GetValue("WaterGroup");
  151. string waterGroupCode = ultraGrid1.ActiveRow.GetValue("WaterGroupCode");
  152. if (_waterGroupBLL.GetWaterGroupCnt(waterGroupDesc, waterGroupCode) > 0)
  153. {
  154. MessageUtil.ShowWarning("系统已连浇群组名称" + waterGroupDesc + "!");
  155. return;
  156. }
  157. var groupRows = waterGroups.GroupBy(a => a.GradeIndex).Where(a => a.Count() >= 2);
  158. foreach (var row in groupRows)
  159. {
  160. MessageUtil.ShowWarning("钢种序号:" + row.Key + "重复!");
  161. var repeatRow = rows.Where(a => a.GetValue("GradeIndex") == row.Key.ToString());
  162. if (repeatRow.Count() > 0)
  163. {
  164. repeatRow.First().Cells["GradeIndex"].Activate();
  165. }
  166. return;
  167. }
  168. List<ComBaseWaterGroupEntity> listWaterGroups = rows.Select(a => (ComBaseWaterGroupEntity)a.ListObject).ToList();
  169. string gradeCodes = "";
  170. foreach (ComBaseWaterGroupEntity waterGroup in listWaterGroups)
  171. {
  172. waterGroup.CreateName = UserInfo.GetUserName();
  173. waterGroup.WaterGroupCode = ultraGrid1.ActiveRow.GetValue("WaterGroupCode");
  174. waterGroup.WaterGroup = ultraGrid1.ActiveRow.GetValue("WaterGroup");
  175. if (gradeCodes == "")
  176. {
  177. gradeCodes = waterGroup.Gradecode;
  178. }
  179. else
  180. {
  181. gradeCodes += "," + waterGroup.Gradecode;
  182. }
  183. }
  184. string gradeWaterGroup = "";
  185. if (_waterGroupBLL.GetWaterGroupGradeCnt(gradeCodes, waterGroupCode, out gradeWaterGroup) > 0)
  186. {
  187. MessageUtil.ShowWarning("该连浇群组与连浇群组" + gradeWaterGroup + "的钢种组合重复!");
  188. return;
  189. }
  190. if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == System.Windows.Forms.DialogResult.No)
  191. {
  192. return;
  193. }
  194. waterGroupCode = _waterGroupBLL.SaveWaretGroupGrade(listWaterGroups);
  195. MessageUtil.ShowTips("保存成功!");
  196. Relocate(waterGroupCode);
  197. }
  198. private void Relocate(string waterGroupCode)
  199. {
  200. QueryWaterGroup();
  201. var row = ultraGrid1.Rows.Where(a => a.GetValue("waterGroupCode") == waterGroupCode).FirstOrDefault();
  202. if (row != null)
  203. {
  204. row.Activate();
  205. }
  206. }
  207. private void MoveUp()
  208. {
  209. ultraGrid2.BeginUpdate();
  210. IQueryable<UltraGridRow> rows = ultraGrid2.Rows.AsQueryable().Where(
  211. a => a.Activated || a.Selected);
  212. IQueryable<ComBaseWaterGroupEntity> queryableRows = _waterGroupGradeList.AsQueryable();
  213. foreach (UltraGridRow row in rows)
  214. {
  215. if (row.Index == 0) continue;
  216. ComBaseWaterGroupEntity waterGroup = (ComBaseWaterGroupEntity)row.ListObject;
  217. ComBaseWaterGroupEntity[] preWaterGroups = ultraGrid2.Rows.AsQueryable().Select(a => (ComBaseWaterGroupEntity)a.ListObject)
  218. .Where(a => a.Chk && a.GradeIndex < waterGroup.GradeIndex).OrderByDescending(a => a.GradeIndex).ToArray();
  219. if (preWaterGroups.Length > 0)
  220. {
  221. decimal? index = waterGroup.GradeIndex;
  222. waterGroup.GradeIndex = preWaterGroups[0].GradeIndex;
  223. preWaterGroups[0].GradeIndex = index;
  224. }
  225. else
  226. {
  227. continue;
  228. }
  229. }
  230. this.comBaseWaterGroupEntityBindingSource1.DataSource = queryableRows.OrderByDescending(a => a.Chk).ThenBy(
  231. a => a.GradeIndex, new NullMaxCompare()).ThenBy(a => a.Gradename);
  232. ultraGrid2.EndUpdate();
  233. }
  234. private void MoveDown()
  235. {
  236. ultraGrid2.BeginUpdate();
  237. IQueryable<ComBaseWaterGroupEntity> selectedRows = ultraGrid2.Rows.AsQueryable().Where(
  238. a => a.Activated || a.Selected).Select(a => (ComBaseWaterGroupEntity)a.ListObject).OrderByDescending(a => a.GradeIndex);
  239. IQueryable<ComBaseWaterGroupEntity> queryableRows = _waterGroupGradeList.AsQueryable();
  240. foreach (ComBaseWaterGroupEntity waterGroup in selectedRows)
  241. {
  242. ComBaseWaterGroupEntity[] preWaterGroups = ultraGrid2.Rows.AsQueryable().Select(a => (ComBaseWaterGroupEntity)a.ListObject)
  243. .Where(a => a.Chk && a.GradeIndex > waterGroup.GradeIndex).OrderBy(a => a.GradeIndex).ToArray();
  244. if (preWaterGroups.Length > 0)
  245. {
  246. decimal? index = waterGroup.GradeIndex;
  247. waterGroup.GradeIndex = preWaterGroups[0].GradeIndex;
  248. preWaterGroups[0].GradeIndex = index;
  249. }
  250. else
  251. {
  252. continue;
  253. }
  254. }
  255. this.comBaseWaterGroupEntityBindingSource1.DataSource = queryableRows.OrderByDescending(a => a.Chk).ThenBy(
  256. a => a.GradeIndex, new NullMaxCompare()).ThenBy(a => a.Gradename);
  257. ultraGrid2.EndUpdate();
  258. }
  259. private void ultraGrid2_InitializeRow(object sender, InitializeRowEventArgs e)
  260. {
  261. }
  262. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  263. {
  264. try
  265. {
  266. this.Cursor = Cursors.WaitCursor;
  267. QueryWaterGroupGrade();
  268. }
  269. finally
  270. {
  271. this.Cursor = Cursors.Default;
  272. }
  273. }
  274. private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
  275. {
  276. e.Layout.Override.TemplateAddRowPrompt = "点击新增一行记录!";
  277. e.Layout.Override.TemplateAddRowAppearance.BackColor = Color.FromArgb(255, 255, 128);
  278. }
  279. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  280. {
  281. ultraGrid1.UpdateData();
  282. }
  283. private void ultraGrid2_CellChange(object sender, CellEventArgs e)
  284. {
  285. ultraGrid2.UpdateData();
  286. ComBaseWaterGroupEntity waterGroup = (ComBaseWaterGroupEntity)e.Cell.Row.ListObject;
  287. if (e.Cell.Column.Key == "Chk" && waterGroup.GradeIndex == null)
  288. {
  289. IQueryable<ComBaseWaterGroupEntity> queryableRows = _waterGroupGradeList.AsQueryable();
  290. var waterGroups = queryableRows.Where(a => a.GradeIndex != null).OrderByDescending(
  291. a => a.GradeIndex, new NullMaxCompare());
  292. if (waterGroups.Count() > 0)
  293. {
  294. waterGroup.GradeIndex = waterGroups.First().GradeIndex + 1;
  295. }
  296. else
  297. {
  298. waterGroup.GradeIndex = 1;
  299. }
  300. ultraGrid2.Refresh();
  301. this.comBaseWaterGroupEntityBindingSource1.DataSource = queryableRows.OrderByDescending(a => a.Chk).ThenBy(
  302. a => a.GradeIndex, new NullMaxCompare()).ThenBy(a => a.Gradename);
  303. }
  304. }
  305. }
  306. }