frmBaseGradePrice.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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.PnCost.Models;
  6. using CoreFS.CA06;
  7. using Infragistics.Win.UltraWinGrid;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Windows.Forms;
  16. namespace Core.StlMes.Client.PnCost
  17. {
  18. public partial class frmBaseGradePrice : FrmBase
  19. {
  20. #region 定义变量
  21. public frmBaseGradePrice()
  22. {
  23. InitializeComponent();
  24. }
  25. #endregion
  26. #region 初始化
  27. private void frmBaseGradePrice_Load(object sender, EventArgs e)
  28. {
  29. EntityHelper.ShowGridCaption<CostBaseGradePriceEntity>(ultraGrid1.DisplayLayout.Bands[0]);
  30. for (int i = 2000; i < 2051; i++)
  31. {
  32. yeardrop.Items.Add(i);
  33. }
  34. string str1 = "";
  35. for (int i = 1; i < 10; i++)
  36. {
  37. str1 = "0" + i.ToString2();
  38. monthdrop.Items.Add(str1);
  39. }
  40. monthdrop.Items.Add(10);
  41. monthdrop.Items.Add(11);
  42. monthdrop.Items.Add(12);
  43. yeardrop.Value = System.DateTime.Now.Year.ToString2();
  44. monthdrop.Value = System.DateTime.Now.Month.ToString2();
  45. Query();
  46. }
  47. #endregion
  48. #region 方法
  49. public override void ToolBar_Click(object sender, string ToolbarKey)
  50. {
  51. base.ToolBar_Click(sender, ToolbarKey);
  52. switch (ToolbarKey)
  53. {
  54. case "Query":
  55. Query();
  56. break;
  57. case "Update":
  58. Save();
  59. break;
  60. case "Delete":
  61. Delete();
  62. break;
  63. case "Resume":
  64. Resume();
  65. break;
  66. case "Close":
  67. this.Close();
  68. break;
  69. }
  70. }
  71. /// 查询方法
  72. /// <summary>
  73. /// 查询方法
  74. /// </summary>
  75. private void Query()
  76. {
  77. #region 条件验证
  78. string nianyue = yeardrop.Value.ToString2() + monthdrop.Value.ToString2();
  79. string nian_yue = yeardrop.Value.ToString2() + "-" + monthdrop.Value.ToString2();
  80. #endregion
  81. DataTable data = ServerHelper.GetData("com.steering.pss.pncost.base.ComBaseGradePrice.query2",
  82. new object[] { nianyue }, ob);
  83. GridHelper.CopyDataToDatatable(data, dataTable1, true);
  84. //GridHelper.RefreshAndAutoSize(ultraGrid1);
  85. //管子:PLN_REQINF_GP表IFBUYPLAN ='1' 年月暂时没加;坯子:PLN_ORDER_ZG_S表 PRO_MONTH管控年月 PLINE_CODE必须是C065,C065
  86. //List<CostBaseGradePriceEntity> datanew = EntityHelper.GetData<CostBaseGradePriceEntity>(
  87. // "com.steering.pss.pncost.base.ComBaseGradePrice.query2", new object[] { nianyue, nian_yue }, ob);
  88. //costBaseGradePriceEntityBindingSource.DataSource = datanew;
  89. if (ultraGrid1.Rows.Count == 0)
  90. {
  91. return;
  92. }
  93. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  94. {
  95. if (ultraGrid1.Rows[i].Cells["VALIDFLAG"].Value.ToString() == "无效")
  96. {
  97. ultraGrid1.Rows[i].Appearance.ForeColor = Color.Red;
  98. }
  99. ultraGrid1.Rows[i].Cells["CHK"].Value = false;
  100. GridEdite(ultraGrid1.Rows[i]);
  101. }
  102. ultraGrid1.UpdateData();
  103. ultraGrid1.ActiveRow = ultraGrid1.Rows[0];
  104. }
  105. /// 保存方法
  106. /// <summary>
  107. /// 保存方法
  108. /// </summary>
  109. private void Save()
  110. {
  111. string wuliao = "";
  112. string xuanze = "false";
  113. try
  114. {
  115. #region 验证信息
  116. ultraGrid1.UpdateData();
  117. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  118. {
  119. if (ultraGrid1.Rows[i].Cells["CHK"].Value.ToString() == "True")
  120. {
  121. if (ultraGrid1.Rows[i].Cells["COST_PRICE"].Value.ToString2() == "")
  122. {
  123. MessageUtil.ShowWarning("采购单价不能为空!请重新输入");
  124. return;
  125. }
  126. xuanze = "true";
  127. }
  128. }
  129. if (xuanze == "false")
  130. {
  131. MessageUtil.ShowWarning("请选择你要保存的记录!");
  132. return;
  133. }
  134. if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == System.Windows.Forms.DialogResult.No)
  135. {
  136. return;
  137. }
  138. #endregion
  139. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  140. {
  141. if (ultraGrid1.Rows[i].Cells["CHK"].Value.ToString() == "True")
  142. {
  143. wuliao = ultraGrid1.Rows[i].Cells["WLBM"].Value.ToString2();
  144. CostBaseGradePriceEntity parm = new CostBaseGradePriceEntity();
  145. parm.WlId = ultraGrid1.Rows[i].Cells["WLBM"].Value.ToString2();
  146. parm.WlDesc = ultraGrid1.Rows[i].Cells["WLMS"].Value.ToString2();
  147. parm.BalYearMonth = ultraGrid1.Rows[i].Cells["YEAR_MONTH"].Value.ToString2();
  148. parm.CostPrice = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["COST_PRICE"].Value.ToString3());
  149. parm.Memo = ultraGrid1.Rows[i].Cells["MEMO"].Value.ToString();
  150. if (ultraGrid1.Rows[i].Cells["create_name"].Value.ToString() == "")//判断是新增还是修改的保存
  151. {
  152. parm.CreateName = this.UserInfo.GetUserName();//新增保存
  153. string JsonStr = JSONFormat.Format(parm);
  154. ServerHelper.SetData("com.steering.pss.pncost.base.ComBaseGradePrice.isave", new object[] { JsonStr }, ob);
  155. }
  156. else
  157. {
  158. parm.UpdateName = this.UserInfo.GetUserName();//修改保存
  159. string JsonStr = JSONFormat.Format(parm);
  160. ServerHelper.SetData("com.steering.pss.pncost.base.ComBaseGradePrice.usave", new object[] { JsonStr }, ob);
  161. }
  162. }
  163. }
  164. }
  165. catch (Exception ex)
  166. {
  167. MessageUtil.ShowError("保存失败!'" + ex.Message + "'");
  168. return;
  169. }
  170. MessageUtil.ShowTips("保存成功!");
  171. Query();
  172. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  173. {
  174. if (ultraGrid1.Rows[i].Cells["WLBM"].Value.ToString() == wuliao)
  175. {
  176. ultraGrid1.Rows[i].Activate();
  177. }
  178. }
  179. }
  180. /// 删除方法
  181. /// <summary>
  182. /// 删除方法
  183. /// </summary>
  184. private void Delete()
  185. {
  186. string wuliao = "";
  187. string xuanze = "false";
  188. try
  189. {
  190. #region 验证信息
  191. ultraGrid1.UpdateData();
  192. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  193. {
  194. if (ultraGrid1.Rows[i].Cells["CHK"].Value.ToString() == "True")
  195. {
  196. //是否已经是无效方案
  197. if (ultraGrid1.Rows[i].Cells["VALIDFLAG"].Value.ToString() != "有效")
  198. {
  199. MessageUtil.ShowWarning("选择了已经作废的数据!");
  200. return;
  201. }
  202. xuanze = "true";
  203. }
  204. }
  205. if (xuanze == "false")
  206. {
  207. MessageUtil.ShowWarning("请选择你要删除的记录!");
  208. return;
  209. }
  210. if (MessageUtil.ShowYesNoAndQuestion("是否确认删除?") == System.Windows.Forms.DialogResult.No)
  211. {
  212. return;
  213. }
  214. #endregion
  215. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  216. {
  217. if (ultraGrid1.Rows[i].Cells["CHK"].Value.ToString() == "True")
  218. {
  219. wuliao = ultraGrid1.Rows[i].Cells["WLBM"].Value.ToString2();
  220. CostBaseGradePriceEntity parm = new CostBaseGradePriceEntity();
  221. parm.WlId = ultraGrid1.Rows[i].Cells["WLBM"].Value.ToString2();
  222. parm.BalYearMonth = ultraGrid1.Rows[i].Cells["YEAR_MONTH"].Value.ToString2();
  223. parm.UpdateName = this.UserInfo.GetUserName();
  224. parm.DeleteName = this.UserInfo.GetUserName();
  225. string JsonStr = JSONFormat.Format(parm);
  226. ServerHelper.SetData("com.steering.pss.pncost.base.ComBaseGradePrice.delete", new object[] { JsonStr }, ob);
  227. }
  228. }
  229. }
  230. catch (Exception ex)
  231. {
  232. MessageUtil.ShowError("删除失败!'" + ex.Message + "'");
  233. return;
  234. }
  235. MessageUtil.ShowTips("删除成功!");
  236. Query();
  237. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  238. {
  239. if (ultraGrid1.Rows[i].Cells["WLBM"].Value.ToString() == wuliao)
  240. {
  241. ultraGrid1.Rows[i].Activate();
  242. }
  243. }
  244. }
  245. /// 恢复方法
  246. /// <summary>
  247. /// 恢复方法
  248. /// </summary>
  249. private void Resume()
  250. {
  251. string wuliao = "";
  252. string xuanze = "false";
  253. try
  254. {
  255. #region 验证信息
  256. ultraGrid1.UpdateData();
  257. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  258. {
  259. if (ultraGrid1.Rows[i].Cells["CHK"].Value.ToString() == "True")
  260. {
  261. //是否是无效方案
  262. if (ultraGrid1.Rows[i].Cells["VALIDFLAG"].Value.ToString() == "有效")
  263. {
  264. MessageUtil.ShowWarning("选择了没有作废的数据!");
  265. return;
  266. }
  267. xuanze = "true";
  268. }
  269. }
  270. if (xuanze == "false")
  271. {
  272. MessageUtil.ShowWarning("请选择你要恢复的记录!");
  273. return;
  274. }
  275. if (MessageUtil.ShowYesNoAndQuestion("是否确认恢复?") == System.Windows.Forms.DialogResult.No)
  276. {
  277. return;
  278. }
  279. #endregion
  280. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  281. {
  282. if (ultraGrid1.Rows[i].Cells["CHK"].Value.ToString() == "True")
  283. {
  284. wuliao = ultraGrid1.Rows[i].Cells["WLBM"].Value.ToString2();
  285. CostBaseGradePriceEntity parm = new CostBaseGradePriceEntity();
  286. parm.WlId = ultraGrid1.Rows[i].Cells["WLBM"].Value.ToString2();
  287. parm.BalYearMonth = ultraGrid1.Rows[i].Cells["YEAR_MONTH"].Value.ToString2();
  288. parm.UpdateName = this.UserInfo.GetUserName();
  289. string JsonStr = JSONFormat.Format(parm);
  290. ServerHelper.SetData("com.steering.pss.pncost.base.ComBaseGradePrice.resume", new object[] { JsonStr }, ob);
  291. }
  292. }
  293. }
  294. catch (Exception ex)
  295. {
  296. MessageUtil.ShowError("恢复失败!'" + ex.Message + "'");
  297. return;
  298. }
  299. MessageUtil.ShowTips("恢复成功!");
  300. Query();
  301. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  302. {
  303. if (ultraGrid1.Rows[i].Cells["WLBM"].Value.ToString() == wuliao)
  304. {
  305. ultraGrid1.Rows[i].Activate();
  306. }
  307. }
  308. }
  309. #endregion
  310. #region 事件
  311. /// 选择事件
  312. /// <summary>
  313. /// 选择事件
  314. /// </summary>
  315. private void ultraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  316. {
  317. ultraGrid1.UpdateData();
  318. if (e.Cell.Column.Key == "CHK")
  319. {
  320. GridEdite(e.Cell.Row);
  321. }
  322. }
  323. /// 选择判断
  324. /// <summary>
  325. /// 选择判断
  326. /// </summary>
  327. private void GridEdite(UltraGridRow row)
  328. {
  329. if (row.GetValue("CHK") == "True")
  330. {
  331. foreach (UltraGridCell cell in row.Cells)
  332. {
  333. if (cell.Column.CellActivation == Activation.AllowEdit)
  334. {
  335. cell.Activation = Activation.AllowEdit;
  336. }
  337. }
  338. }
  339. else
  340. {
  341. foreach (UltraGridCell cell in row.Cells)
  342. {
  343. if (cell.Column.Key == "CHK") continue;
  344. if (cell.Column.CellActivation == Activation.AllowEdit)
  345. {
  346. cell.Activation = Activation.ActivateOnly;
  347. }
  348. }
  349. }
  350. }
  351. #endregion
  352. }
  353. }