FrmResBaseResourceAllocation.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. using Core.Mes.Client.Comm.Control;
  2. using Core.Mes.Client.Comm.Format;
  3. using Core.Mes.Client.Comm.Server;
  4. using Core.Mes.Client.Comm.Tool;
  5. using Core.StlMes.Client.Qcm.model;
  6. using CoreFS.CA06;
  7. using Infragistics.Win.UltraWinEditors;
  8. using Infragistics.Win.UltraWinGrid;
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Windows.Forms;
  15. namespace Core.StlMes.Client.Qcm
  16. {
  17. public partial class FrmResBaseResourceAllocation : FrmBase
  18. {
  19. public FrmResBaseResourceAllocation()
  20. {
  21. InitializeComponent();
  22. }
  23. private void FrmResBaseResourceAllocation_Load(object sender, EventArgs e)
  24. {
  25. Init();
  26. }
  27. public override void ToolBar_Click(object sender, string ToolbarKey)
  28. {
  29. switch (ToolbarKey)
  30. {
  31. case "Query":
  32. Query(true);
  33. break;
  34. case "Query1":
  35. Query(false);
  36. break;
  37. case "Save":
  38. DoSave();
  39. break;
  40. case "Delete":
  41. DeleteOrResume(true);
  42. break;
  43. case "Resume":
  44. DeleteOrResume(false);
  45. break;
  46. case "Refresh":
  47. Init();
  48. break;
  49. case "Close":
  50. this.Close();
  51. break;
  52. }
  53. }
  54. private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
  55. {
  56. EntityHelper.ShowGridCaption<ResBaseResourceAllocationEntity>(e.Layout.Bands[0]);
  57. // GridHelper.RefreshAndAutoSize(ultraGrid1);
  58. }
  59. private void Init()
  60. {
  61. UltraComboEditor uce = new UltraComboEditor();
  62. DataTable dt = new DataTable();
  63. dt.Columns.Add("YEAR", Type.GetType("System.Int32"));
  64. for (int i = 2000; i <= 2060; i++)
  65. dt.Rows.Add(new object[] { i });
  66. uce.DataSource = dt;
  67. uce.ValueMember = "YEAR";
  68. uce.DisplayMember = "YEAR";
  69. this.Controls.Add(uce);
  70. uce.Visible = false;
  71. ultraGrid1.DisplayLayout.Bands[0].Columns["YEAR"].EditorComponent = uce;
  72. ultraGrid1.DisplayLayout.Bands[0].Columns["YEAR"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  73. UltraComboEditor uceSale = new UltraComboEditor();
  74. UltraComboEditor uceProcess = new UltraComboEditor();
  75. QcmBaseCommon.InitDrop(uceSale, "com.steering.pss.qcm.CoreResBaseResourceAllocation.getSaleOrg", "BASENAME", "BASECODE", true, this.ob);
  76. QcmBaseCommon.InitDrop(uceProcess, "com.steering.pss.qcm.CoreResBaseResourceAllocation.getProcess", "PROCESS_DESC", "PROCESS_CODE", true, this.ob);
  77. this.Controls.Add(uceSale);
  78. this.Controls.Add(uceProcess);
  79. uceSale.Visible = false;
  80. uceProcess.Visible = false;
  81. ClsBaseInfo.SetComboItemHeight(uceSale);
  82. ClsBaseInfo.SetComboItemHeight(uceProcess);
  83. ultraGrid1.DisplayLayout.Bands[0].Columns["SaleOrg"].EditorComponent = uceSale;
  84. ultraGrid1.DisplayLayout.Bands[0].Columns["SaleOrg"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  85. ultraGrid1.DisplayLayout.Bands[0].Columns["ProcessCode"].EditorComponent = uceProcess;
  86. ultraGrid1.DisplayLayout.Bands[0].Columns["ProcessCode"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  87. }
  88. private void Query(bool flag)
  89. {
  90. List<ResBaseResourceAllocationEntity> list = EntityHelper.GetData<ResBaseResourceAllocationEntity>("com.steering.pss.qcm.CoreResBaseResourceAllocation.queryResourceData", new object[] { flag }, this.ob);
  91. resBaseResourceAllocationEntityBindingSource.DataSource = list;
  92. // GridHelper.RefreshAndAutoSize(ultraGrid1);
  93. }
  94. string errMsg = "";
  95. private void DoSave()
  96. {
  97. ultraGrid1.UpdateData();
  98. int i = 0;
  99. ArrayList list = new ArrayList();
  100. //ResBaseResourceAllocationEntity res = (ResBaseResourceAllocationEntity)ultraGrid1.ActiveRow.ListObject;
  101. //MessageUtil.ShowWarning(res.SaleOrg.ToString());
  102. foreach (UltraGridRow row in ultraGrid1.Rows)
  103. {
  104. if (Convert.ToBoolean(row.Cells["CHK"].Value))
  105. {
  106. i++;
  107. ResBaseResourceAllocationEntity res = (ResBaseResourceAllocationEntity)row.ListObject;
  108. if (res == null)
  109. return;
  110. if (!TestData(res))
  111. {
  112. MessageUtil.ShowWarning(errMsg);
  113. return;
  114. }
  115. res.CreateName = UserInfo.GetUserName();
  116. res.UpdateName = UserInfo.GetUserName();
  117. list.Add(JSONFormat.Format(res));
  118. }
  119. }
  120. if (i == 0)
  121. {
  122. MessageUtil.ShowWarning("请选择需要操作的记录!");
  123. return;
  124. }
  125. if (MessageBox.Show("是否确认保存数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  126. return;
  127. int count = ServerHelper.SetData("com.steering.pss.qcm.CoreResBaseResourceAllocation.save", new object[] { list }, this.ob);
  128. if (count > 0)
  129. {
  130. MessageUtil.ShowTips("数据保存成功!");
  131. Query(true);
  132. }
  133. }
  134. private bool TestData(ResBaseResourceAllocationEntity res)
  135. {
  136. if (res.Validflag.ToString() != "" && res.Validflag.ToString() != "有效")
  137. {
  138. errMsg = "无效数据无法保存!";
  139. return false;
  140. }
  141. if (res.SaleOrg.ToString() == "")
  142. {
  143. errMsg = "请选择销售组织!";
  144. return false;
  145. }
  146. if (res.ProcessCode.ToString() == "")
  147. {
  148. errMsg = "请选择工序名称!";
  149. return false;
  150. }
  151. if (res.Year.ToString() == "")
  152. {
  153. errMsg = "请选择年份!";
  154. return false;
  155. }
  156. if (!IsNum(res.Month1.ToString()))
  157. {
  158. errMsg = "1月资源量请输入数字!";
  159. return false;
  160. }
  161. if (!IsNum(res.Month2.ToString()))
  162. {
  163. errMsg = "2月资源量请输入数字!";
  164. return false;
  165. }
  166. if (!IsNum(res.Month3.ToString()))
  167. {
  168. errMsg = "3月资源量请输入数字!";
  169. return false;
  170. }
  171. if (!IsNum(res.Month4.ToString()))
  172. {
  173. errMsg = "4月资源量请输入数字!";
  174. return false;
  175. }
  176. if (!IsNum(res.Month5.ToString()))
  177. {
  178. errMsg = "5月资源量请输入数字!";
  179. return false;
  180. }
  181. if (!IsNum(res.Month6.ToString()))
  182. {
  183. errMsg = "6月资源量请输入数字!";
  184. return false;
  185. }
  186. if (!IsNum(res.Month7.ToString()))
  187. {
  188. errMsg = "7月资源量请输入数字!";
  189. return false;
  190. }
  191. if (!IsNum(res.Month8.ToString()))
  192. {
  193. errMsg = "8月资源量请输入数字!";
  194. return false;
  195. }
  196. if (!IsNum(res.Month9.ToString()))
  197. {
  198. errMsg = "9月资源量请输入数字!";
  199. return false;
  200. }
  201. if (!IsNum(res.Month10.ToString()))
  202. {
  203. errMsg = "10月资源量请输入数字!";
  204. return false;
  205. }
  206. if (!IsNum(res.Month11.ToString()))
  207. {
  208. errMsg = "11月资源量请输入数字!";
  209. return false;
  210. }
  211. if (!IsNum(res.Month12.ToString()))
  212. {
  213. errMsg = "12月资源量请输入数字!";
  214. return false;
  215. }
  216. if (res.Validflag.ToString() == "") //新增
  217. {
  218. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreResBaseResourceAllocation.isReapt", new object[] { res.SaleOrg.ToString(), res.ProcessCode.ToString(), res.Year.ToString() }, this.ob);
  219. if (dt != null && dt.Rows.Count > 0)
  220. {
  221. errMsg = "销售组织:" + res.SaleOrgDesc + ",工序名称:" + res.ProcessDesc + ",年份:" + res.Year + " 对应的记录已经存在!";
  222. return false;
  223. }
  224. }
  225. else //修改
  226. {
  227. if (res.SaleOrg.ToString() != res.SaleOrgOld.ToString() || res.ProcessCode.ToString() != res.ProcessCodeOld.ToString()
  228. || res.Year.ToString() != res.YearOld.ToString())
  229. {
  230. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreResBaseResourceAllocation.isReapt", new object[] { res.SaleOrg.ToString(), res.ProcessCode.ToString(), res.Year.ToString() }, this.ob);
  231. if (dt != null && dt.Rows.Count > 0)
  232. {
  233. errMsg = "销售组织:" + res.SaleOrgDesc + ",工序名称:" + res.ProcessDesc + ",年份:" + res.Year + " 对应的记录已经存在!";
  234. return false;
  235. }
  236. }
  237. }
  238. return true;
  239. }
  240. private bool IsNum(string str)
  241. {
  242. if (str != "")
  243. {
  244. return StringUtil.IsNumber(str);
  245. }
  246. return true;
  247. }
  248. private void DeleteOrResume(bool flag)
  249. {
  250. ultraGrid1.UpdateData();
  251. ArrayList list = new ArrayList();
  252. foreach (UltraGridRow row in ultraGrid1.Rows)
  253. {
  254. if (Convert.ToBoolean(row.Cells["CHK"].Value))
  255. {
  256. if (flag && row.Cells["VALIDFLAG"].Value.ToString() != "有效")
  257. {
  258. MessageUtil.ShowWarning("非有效记录无法作废!");
  259. return;
  260. }
  261. else if (flag == false && row.Cells["VALIDFLAG"].Value.ToString() != "无效")
  262. {
  263. MessageUtil.ShowWarning("非无效记录无法恢复!");
  264. return;
  265. }
  266. ResBaseResourceAllocationEntity res = (ResBaseResourceAllocationEntity)row.ListObject;
  267. res.DeleteName = UserInfo.GetUserName();
  268. list.Add(JSONFormat.Format(res));
  269. }
  270. }
  271. if (GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "CHK" }, new string[] { "True" }).Length <= 0)
  272. {
  273. MessageUtil.ShowWarning("请选择需要操作的记录!");
  274. return;
  275. }
  276. if (MessageBox.Show("是否确认" + (flag ? "作废" : "恢复") + "所选的记录", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  277. {
  278. return;
  279. }
  280. int count = ServerHelper.SetData("com.steering.pss.qcm.CoreResBaseResourceAllocation.deleteOrResume", new object[] { list, flag }, this.ob);
  281. if (count > 0)
  282. {
  283. MessageUtil.ShowWarning("数据" + (flag ? "作废" : "恢复") + "成功!");
  284. Query(true);
  285. }
  286. }
  287. private void ultraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  288. {
  289. ultraGrid1.UpdateData();
  290. UltraGridRow ugr = ultraGrid1.ActiveRow;
  291. if (ugr == null)
  292. return;
  293. ResBaseResourceAllocationEntity res = (ResBaseResourceAllocationEntity)ugr.ListObject;
  294. if (e.Cell.Column.Key.Equals("SaleOrg"))
  295. {
  296. res.SaleOrgDesc = e.Cell.Text;
  297. }
  298. else if (e.Cell.Column.Key.Equals("ProcessCode"))
  299. {
  300. res.ProcessDesc = e.Cell.Text;
  301. }
  302. else if (e.Cell.Column.Key.Equals("CHK"))
  303. {
  304. if (!Convert.ToBoolean(e.Cell.Value))
  305. {
  306. for (int i = 0; i < ugr.Cells.Count; i++)
  307. {
  308. if (!ugr.Cells[i].Column.Key.Equals("CHK"))
  309. ugr.Cells[i].Activation = Activation.ActivateOnly;
  310. }
  311. }
  312. else
  313. {
  314. for (int i = 0; i < ugr.Cells.Count; i++)
  315. {
  316. ugr.Cells[i].Activation = Activation.AllowEdit;
  317. }
  318. }
  319. }
  320. }
  321. private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
  322. {
  323. if (e.Row.Cells["VALIDFLAG"].Value.ToString().Equals("无效"))
  324. {
  325. e.Row.Appearance.ForeColor = Color.Red;
  326. }
  327. else
  328. {
  329. e.Row.Appearance.ForeColor = Color.Black;
  330. }
  331. }
  332. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  333. {
  334. ultraGrid1.Update();
  335. UltraGridRow ugr = ultraGrid1.ActiveRow;
  336. if (ugr == null)
  337. return;
  338. if (!Convert.ToBoolean(ugr.Cells["CHK"].Value))
  339. {
  340. for (int i = 0; i < ugr.Cells.Count; i++)
  341. {
  342. if (!ugr.Cells[i].Column.Key.Equals("CHK"))
  343. ugr.Cells[i].Activation = Activation.ActivateOnly;
  344. }
  345. }
  346. else
  347. {
  348. for (int i = 0; i < ugr.Cells.Count; i++)
  349. {
  350. ugr.Cells[i].Activation = Activation.AllowEdit;
  351. }
  352. }
  353. }
  354. private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
  355. {
  356. ultraGrid1.Update();
  357. UltraGridRow ugr = ultraGrid1.ActiveRow;
  358. if (!Convert.ToBoolean(ugr.Cells["CHK"].Value))
  359. {
  360. for (int i = 0; i < ugr.Cells.Count; i++)
  361. {
  362. if (!ugr.Cells[i].Column.Key.Equals("CHK"))
  363. ugr.Cells[i].Activation = Activation.ActivateOnly;
  364. }
  365. }
  366. else
  367. {
  368. for (int i = 0; i < ugr.Cells.Count; i++)
  369. {
  370. ugr.Cells[i].Activation = Activation.AllowEdit;
  371. }
  372. }
  373. }
  374. }
  375. }