CraftFileApplyCtrl.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Core.StlMes.Client.SaleOrder.BLL;
  10. using CoreFS.CA06;
  11. using Infragistics.Win.UltraWinGrid;
  12. using Core.Mes.Client.Comm.Tool;
  13. using Infragistics.Win.UltraWinEditors;
  14. using Core.StlMes.Client.Qcm;
  15. using CoreFS.SA06;
  16. using Core.StlMes.Client.SaleOrder.Dialog;
  17. namespace Core.StlMes.Client.SaleOrder.Control
  18. {
  19. public partial class CraftFileApplyCtrl : UserControl
  20. {
  21. private CraftFileApplyBLL _craftFileApplyBLL;
  22. private CraftFileApplyEntity _queryCondition;
  23. private UltraComboEditor[] _cmbs = new UltraComboEditor[2];
  24. private OpeBase ob;
  25. public CraftFileApplyCtrl(System.Windows.Forms.Control container, OpeBase ob)
  26. {
  27. InitializeComponent();
  28. this.ob = ob;
  29. _craftFileApplyBLL = new CraftFileApplyBLL(ob);
  30. container.Controls.Add(this);
  31. this.Dock = DockStyle.Fill;
  32. EntityHelper.ShowGridCaption<CraftFileApplyEntity>(ultraGrid1.DisplayLayout.Bands[0]);
  33. InitData();
  34. }
  35. private void InitData()
  36. {
  37. for(int i = 0; i < _cmbs.Length; i++)
  38. {
  39. _cmbs[i] = new UltraComboEditor();
  40. _cmbs[i].DropDownListWidth = -1;
  41. _cmbs[i].Visible = false;
  42. this.Controls.Add(_cmbs[i]);
  43. }
  44. ultraGrid1.DisplayLayout.Bands[0].Columns["MscDesc"].EditorComponent = ultraTextEditor1;
  45. ultraGrid1.DisplayLayout.Bands[0].Columns["ModelDesc"].EditorComponent = ultraTextEditor1;
  46. //QcmBaseQuery.NitializePsc(_cmbs[0], false, ob);
  47. //ultraGrid1.DisplayLayout.Bands[0].Columns["MSC"].EditorComponent = _cmbs[0];
  48. //ultraGrid1.DisplayLayout.Bands[0].Columns["MSC"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDown;
  49. //ultraGrid1.DisplayLayout.Bands[0].Columns["MSC"].AutoCompleteMode = Infragistics.Win.AutoCompleteMode.SuggestAppend;
  50. QcmBaseQuery.NitializeSpec(_cmbs[1], "C", false, ob);
  51. ultraGrid1.DisplayLayout.Bands[0].Columns["SpecCode"].EditorComponent = _cmbs[1];
  52. ultraGrid1.DisplayLayout.Bands[0].Columns["SpecCode"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  53. }
  54. public void Query(CraftFileApplyEntity queryCondition)
  55. {
  56. this._queryCondition = queryCondition;
  57. this.craftFileApplyEntityBindingSource.DataSource = _craftFileApplyBLL.Query(queryCondition);
  58. foreach (UltraGridRow row in ultraGrid1.Rows)
  59. {
  60. ControlCellEdite(row);
  61. }
  62. }
  63. public void Save()
  64. {
  65. this.ultraGrid1.UpdateData();
  66. IQueryable<UltraGridRow> rows = ultraGrid1.Rows.AsQueryable().Where("CHK = 'True'");
  67. if (rows.Count() == 0)
  68. {
  69. MessageUtil.ShowWarning("请选择一条适用范围!");
  70. return;
  71. }
  72. List<CraftFileApplyEntity> list = new List<CraftFileApplyEntity>();
  73. CraftFileApplyEntity relocate = new CraftFileApplyEntity();
  74. foreach (UltraGridRow row in rows)
  75. {
  76. CraftFileApplyEntity craftFileApply = (CraftFileApplyEntity)row.ListObject;
  77. if (CheckData(craftFileApply, row) == false) return;
  78. CraftFileApplyEntity parm = EntityHelper.CopyEntity<CraftFileApplyEntity>(craftFileApply);
  79. foreach(string model in parm.ModelCode.Split('|'))
  80. {
  81. parm.ModelCode = model;
  82. DataTable dtSampeCnt = _craftFileApplyBLL.GetSampeCnt(parm);
  83. if (int.Parse(dtSampeCnt.Rows[0]["COUNT"].ToString()) > 0)
  84. {
  85. MessageUtil.ShowWarning(string.Format("与工艺文件号{0}版本号{1}的适用范围存在交集,不允许保存!",
  86. dtSampeCnt.Rows[0]["CRAFT_NO"].ToString(), dtSampeCnt.Rows[0]["CRAFT_NO_V"].ToString()));
  87. return;
  88. }
  89. }
  90. craftFileApply.CreateName = CoreUserInfo.UserInfo.GetUserName();
  91. list.Add(craftFileApply);
  92. relocate = craftFileApply;
  93. }
  94. if (MessageUtil.ShowYesNoAndQuestion("是否确认保存适用范围?") == DialogResult.No)
  95. {
  96. return;
  97. }
  98. _craftFileApplyBLL.Save(list);
  99. MessageUtil.ShowTips("保存成功!");
  100. Relocate(relocate);
  101. }
  102. private void Relocate(CraftFileApplyEntity relocate)
  103. {
  104. Query(_queryCondition);
  105. IQueryable<UltraGridRow> rows = ultraGrid1.Rows.AsQueryable().Where(
  106. a => a.GetValue("Msc") == relocate.Msc && a.GetValue("MinD") == relocate.MinD
  107. && a.GetValue("MaxD") == relocate.MaxD && a.GetValue("MinH") == relocate.MinH
  108. && a.GetValue("MaxH") == relocate.MaxH && a.GetValue("SpecCode") == relocate.SpecCode
  109. && a.GetValue("ModelCode") == relocate.ModelCode);
  110. if (rows.Count() > 0)
  111. {
  112. rows.First().Activate();
  113. }
  114. }
  115. private bool CheckData(CraftFileApplyEntity craftFileApply, UltraGridRow row)
  116. {
  117. if (craftFileApply.Msc == "")
  118. {
  119. MessageUtil.ShowWarning("请选择冶金规范!");
  120. return false;
  121. }
  122. if (craftFileApply.SpecCode == ""
  123. && craftFileApply.MinD == "" && craftFileApply.MaxD == ""
  124. && craftFileApply.MinH == "" && craftFileApply.MaxH == "")
  125. {
  126. MessageUtil.ShowWarning("请输入适用规格!");
  127. row.Cells["MinD"].Activate();
  128. return false;
  129. }
  130. if (craftFileApply.SpecCode == "")
  131. {
  132. if (craftFileApply.MinD == "")
  133. {
  134. MessageUtil.ShowWarning("请输入适用外径最小值!");
  135. row.Cells["MinD"].Activate();
  136. return false;
  137. }
  138. else if (craftFileApply.MaxD == "")
  139. {
  140. MessageUtil.ShowWarning("请输入适用外径最大值!");
  141. row.Cells["MaxD"].Activate();
  142. return false;
  143. }
  144. else if (craftFileApply.MinH == "")
  145. {
  146. MessageUtil.ShowWarning("请输入适用壁厚最小值!");
  147. row.Cells["MinH"].Activate();
  148. return false;
  149. }
  150. else if (craftFileApply.MaxH == "")
  151. {
  152. MessageUtil.ShowWarning("请输入适用壁厚最大值!");
  153. row.Cells["MaxH"].Activate();
  154. return false;
  155. }
  156. }
  157. if (craftFileApply.SpecCode == "")
  158. {
  159. if (decimal.Parse(craftFileApply.MinD) > decimal.Parse(craftFileApply.MaxD))
  160. {
  161. MessageUtil.ShowWarning("适用外径最小值不能大于适用外径最大值!");
  162. row.Cells["MinD"].Activate();
  163. return false;
  164. }
  165. if (decimal.Parse(craftFileApply.MinH) > decimal.Parse(craftFileApply.MaxH))
  166. {
  167. MessageUtil.ShowWarning("适用壁厚最小值不能大于适用壁厚最大值!");
  168. row.Cells["MinH"].Activate();
  169. return false;
  170. }
  171. }
  172. return true;
  173. }
  174. private void ultraTextEditor1_EditorButtonClick(object sender, EditorButtonEventArgs e)
  175. {
  176. UltraGridRow row = this.ultraGrid1.DisplayLayout.ActiveRow;
  177. if (ultraGrid1.ActiveCell.Column.Key == "ModelDesc")
  178. {
  179. FrmModel frms = new FrmModel();
  180. frms.FormClosed += new FormClosedEventHandler((a, b)=>
  181. {
  182. row.Cells["ModelCode"].Value = frms.Code;
  183. row.Cells["ModelDesc"].Value = frms.Desc;
  184. });
  185. frms.Desc = row.Cells["ModelDesc"].Value.ToString();
  186. frms.FrmOb = this.ob;
  187. frms.Show();
  188. }
  189. else if (ultraGrid1.ActiveCell.Column.Key == "MscDesc")
  190. {
  191. this.Cursor = Cursors.WaitCursor;
  192. PscMscPopup pscMscPopup = new PscMscPopup(row.GetValue("Msc"), ob);
  193. pscMscPopup.FormClosed += new FormClosedEventHandler((a, b) =>
  194. {
  195. if (pscMscPopup.DialogResult == DialogResult.OK)
  196. {
  197. row.Cells["Msc"].Value = pscMscPopup.ChoiceMsc;
  198. row.Cells["MscDesc"].Value = pscMscPopup.ChoiceMscDesc;
  199. }
  200. });
  201. this.Cursor = Cursors.Default;
  202. pscMscPopup.Show();
  203. }
  204. }
  205. private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
  206. {
  207. e.Row.Cells["CraftNo"].Value = _queryCondition.CraftNo;
  208. e.Row.Cells["CraftNoV"].Value = _queryCondition.CraftNoV;
  209. e.Row.Cells["CraftKey"].Value = _queryCondition.CraftKey;
  210. }
  211. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  212. {
  213. //ultraGrid1.UpdateData();
  214. if(e.Cell.Column.Key == "CHK")
  215. {
  216. ultraGrid1.UpdateData();
  217. ControlCellEdite(e.Cell.Row);
  218. }
  219. }
  220. private void ControlCellEdite(UltraGridRow row)
  221. {
  222. Activation activation;
  223. if (row.Cells["CHK"].Value.ToString() == "True")
  224. {
  225. activation = Activation.AllowEdit;
  226. }
  227. else
  228. {
  229. activation = Activation.ActivateOnly;
  230. }
  231. row.Cells["MinH"].Activation = activation;
  232. row.Cells["MaxH"].Activation = activation;
  233. row.Cells["MinD"].Activation = activation;
  234. row.Cells["MaxD"].Activation = activation;
  235. row.Cells["SpecCode"].Activation = activation;
  236. row.Cells["ModelDesc"].Activation = activation;
  237. }
  238. }
  239. }