frmBasePrice.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. using Core.Mes.Client.Comm.Format;
  2. using Core.Mes.Client.Comm.Server;
  3. using Core.Mes.Client.Comm.Tool;
  4. using Core.StlMes.Client.PnCost.Models;
  5. using CoreFS.CA06;
  6. using Infragistics.Win.UltraWinGrid;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Windows.Forms;
  15. namespace Core.StlMes.Client.PnCost
  16. {
  17. public partial class frmBasePrice : FrmBase
  18. {
  19. #region 定义变量
  20. public frmBasePrice()
  21. {
  22. InitializeComponent();
  23. }
  24. #endregion
  25. #region 初始化
  26. private void frmBasePrice_Load(object sender, EventArgs e)
  27. {
  28. EntityHelper.ShowGridCaption<CostBasePriceEntity>(ultraGrid1.DisplayLayout.Bands[0]);
  29. DataTable dt = ServerHelper.GetData("com.steering.pss.pncost.base.ComBasePrice.queryPliao",
  30. new object[] { }, ob);
  31. for (int i = 2000; i < 2051; i++)
  32. {
  33. year.Items.Add(i);
  34. }
  35. for (int i = 2000; i < 2051; i++)
  36. {
  37. ultraComboYear.Items.Add(i);
  38. }
  39. ultraComboYear.Value = System.DateTime.Now.Year.ToString2();
  40. Query();
  41. }
  42. #endregion
  43. #region 方法
  44. public override void ToolBar_Click(object sender, string ToolbarKey)
  45. {
  46. base.ToolBar_Click(sender, ToolbarKey);
  47. switch (ToolbarKey)
  48. {
  49. case "Query":
  50. Query();
  51. break;
  52. case "Update":
  53. Save();
  54. break;
  55. case "Delete":
  56. Delete();
  57. break;
  58. case "Resume":
  59. Resume();
  60. break;
  61. case "Close":
  62. this.Close();
  63. break;
  64. }
  65. }
  66. /// 查询方法
  67. /// <summary>
  68. /// 查询方法
  69. /// </summary>
  70. private void Query()
  71. {
  72. #region 条件验证
  73. string gang = ultraComboYear.Value.ToString2();
  74. #endregion
  75. List<CostBasePriceEntity> data = EntityHelper.GetData<CostBasePriceEntity>(
  76. "com.steering.pss.pncost.base.ComBasePrice.query", new object[] { gang }, ob);
  77. costBasePriceEntityBindingSource.DataSource = data;
  78. if (ultraGrid1.Rows.Count == 0)
  79. {
  80. return;
  81. }
  82. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  83. {
  84. if (ultraGrid1.Rows[i].Cells["VALIDFLAG"].Value.ToString() == "无效")
  85. {
  86. ultraGrid1.Rows[i].Appearance.ForeColor = Color.Red;
  87. }
  88. ultraGrid1.Rows[i].Cells["xuanze"].Value = false;
  89. ultraGrid1.Rows[i].Cells["YEAR"].Value = ultraComboYear.Value.ToString2();
  90. GridEdite(ultraGrid1.Rows[i]);
  91. }
  92. ultraGrid1.UpdateData();
  93. ultraGrid1.ActiveRow = ultraGrid1.Rows[0];
  94. }
  95. /// 保存方法
  96. /// <summary>
  97. /// 保存方法
  98. /// </summary>
  99. private void Save()
  100. {
  101. string stringnew = "";
  102. string year = "";
  103. string xuanze = "false";
  104. try
  105. {
  106. #region 验证信息
  107. ultraGrid1.UpdateData();
  108. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  109. {
  110. if (ultraGrid1.Rows[i].Cells["xuanze"].Value.ToString() == "True")
  111. {
  112. if (ultraGrid1.Rows[i].Cells["ARCCODE"].Value.ToString() == "")
  113. {
  114. MessageUtil.ShowWarning("分类描述不能为空!请选择分类");
  115. return;
  116. }
  117. if (ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString() == "")
  118. {
  119. MessageUtil.ShowWarning("物料名称不能为空!请选择物料");
  120. return;
  121. }
  122. if (ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString2() == "")
  123. {
  124. MessageUtil.ShowWarning("年份不能为空!请选择年份");
  125. return;
  126. }
  127. if (ultraGrid1.Rows[i].Cells["CREATENAME"].Value.ToString() == "")//判断是新增还是修改的保存
  128. {
  129. stringnew = ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString();
  130. year = ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString();
  131. DataTable dt = ServerHelper.GetData("com.steering.pss.pncost.base.ComBasePrice.queryNum", new Object[] { stringnew, year }, ob);
  132. if (dt.Rows[0][0].ToString() == "1")
  133. {
  134. MessageUtil.ShowWarning("年份'" + year + "'重复!,请重新输入");
  135. return;
  136. }
  137. }
  138. else //修改
  139. {
  140. stringnew = ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString();
  141. year = ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString();
  142. if (ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString2() != ultraGrid1.Rows[i].Cells["YEARNEW"].Value.ToString2())
  143. {
  144. DataTable dt = ServerHelper.GetData("com.steering.pss.pncost.base.ComBasePrice.queryNum", new Object[] { stringnew, year }, ob);
  145. if (dt.Rows[0][0].ToString() == "1")
  146. {
  147. MessageUtil.ShowWarning("年份'" + year + "'重复!,请重新输入");
  148. return;
  149. }
  150. }
  151. }
  152. xuanze = "true";
  153. }
  154. }
  155. if (xuanze == "false")
  156. {
  157. MessageUtil.ShowWarning("请选择你要保存的记录!");
  158. return;
  159. }
  160. if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == System.Windows.Forms.DialogResult.No)
  161. {
  162. return;
  163. }
  164. #endregion
  165. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  166. {
  167. if (ultraGrid1.Rows[i].Cells["xuanze"].Value.ToString() == "True")
  168. {
  169. CostBasePriceEntity parm = new CostBasePriceEntity();
  170. parm.ItemCode = ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString();
  171. parm.ItemName = ultraGrid1.Rows[i].Cells["ITEMNAME"].Value.ToString();
  172. parm.ArcCode = ultraGrid1.Rows[i].Cells["ARCCODE"].Value.ToString();
  173. parm.ArcItem = ultraGrid1.Rows[i].Cells["ARCITEM"].Value.ToString();
  174. parm.Memo = ultraGrid1.Rows[i].Cells["MEMO"].Value.ToString();
  175. parm.Year = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString());
  176. parm.Month1 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH1"].Value.ToString3());
  177. parm.Month2 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH2"].Value.ToString3());
  178. parm.Month3 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH3"].Value.ToString3());
  179. parm.Month4 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH4"].Value.ToString3());
  180. parm.Month5 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH5"].Value.ToString3());
  181. parm.Month6 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH6"].Value.ToString3());
  182. parm.Month7 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH7"].Value.ToString3());
  183. parm.Month8 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH8"].Value.ToString3());
  184. parm.Month9 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH9"].Value.ToString3());
  185. parm.Month10 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH10"].Value.ToString3());
  186. parm.Month11 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH11"].Value.ToString3());
  187. parm.Month12 = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["MONTH12"].Value.ToString3());
  188. if (ultraGrid1.Rows[i].Cells["CREATENAME"].Value.ToString() == "")//判断是新增还是修改的保存
  189. {
  190. parm.CreateName = this.UserInfo.GetUserName();//新增保存
  191. string JsonStr = JSONFormat.Format(parm);
  192. ServerHelper.SetData("com.steering.pss.pncost.base.ComBasePrice.isave", new object[] { JsonStr }, ob);
  193. }
  194. else
  195. {
  196. parm.UpdateName = this.UserInfo.GetUserName();//修改保存
  197. string JsonStr = JSONFormat.Format(parm);
  198. string yeranew = "";
  199. yeranew = ultraGrid1.Rows[i].Cells["YEARNEW"].Value.ToString();
  200. ServerHelper.SetData("com.steering.pss.pncost.base.ComBasePrice.usave", new object[] { JsonStr, yeranew }, ob);
  201. }
  202. }
  203. }
  204. }
  205. catch (Exception ex)
  206. {
  207. MessageUtil.ShowError("保存失败!'" + ex.Message + "'");
  208. return;
  209. }
  210. MessageUtil.ShowTips("保存成功!");
  211. Query();
  212. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  213. {
  214. if (ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString() == stringnew)
  215. {
  216. if (ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString() == year)
  217. {
  218. ultraGrid1.Rows[i].Activate();
  219. }
  220. }
  221. }
  222. }
  223. /// 删除方法
  224. /// <summary>
  225. /// 删除方法
  226. /// </summary>
  227. private void Delete()
  228. {
  229. string stringnew = "";
  230. string year = "";
  231. string xuanze = "false";
  232. try
  233. {
  234. #region 验证信息
  235. ultraGrid1.UpdateData();
  236. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  237. {
  238. if (ultraGrid1.Rows[i].Cells["xuanze"].Value.ToString() == "True")
  239. {
  240. if (ultraGrid1.Rows[i].Cells["VALIDFLAG"].Value.ToString() != "有效")
  241. {
  242. MessageUtil.ShowWarning("选择的数据已经作废!");
  243. return;
  244. }
  245. xuanze = "true";
  246. }
  247. }
  248. if (xuanze == "false")
  249. {
  250. MessageUtil.ShowWarning("请选择你要删除的记录!");
  251. return;
  252. }
  253. if (MessageUtil.ShowYesNoAndQuestion("是否确认删除?") == System.Windows.Forms.DialogResult.No)
  254. {
  255. return;
  256. }
  257. #endregion
  258. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  259. {
  260. if (ultraGrid1.Rows[i].Cells["xuanze"].Value.ToString() == "True")
  261. {
  262. stringnew = ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString();
  263. year = ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString();
  264. CostBasePriceEntity parm = new CostBasePriceEntity();
  265. parm.ItemCode = ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString();
  266. parm.Year = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString());
  267. parm.UpdateName = this.UserInfo.GetUserName();
  268. parm.DeleteName = this.UserInfo.GetUserName();
  269. string JsonStr = JSONFormat.Format(parm);
  270. ServerHelper.SetData("com.steering.pss.pncost.base.ComBasePrice.delete", new object[] { JsonStr }, ob);
  271. }
  272. }
  273. }
  274. catch (Exception ex)
  275. {
  276. MessageUtil.ShowError("删除失败!'" + ex.Message + "'");
  277. return;
  278. }
  279. MessageUtil.ShowTips("删除成功!");
  280. Query();
  281. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  282. {
  283. if (ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString() == stringnew)
  284. {
  285. if (ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString() == year)
  286. {
  287. ultraGrid1.Rows[i].Activate();
  288. }
  289. }
  290. }
  291. }
  292. /// 恢复方法
  293. /// <summary>
  294. /// 恢复方法
  295. /// </summary>
  296. private void Resume()
  297. {
  298. string stringnew = "";
  299. string year = "";
  300. string xuanze = "false";
  301. try
  302. {
  303. #region 验证信息
  304. ultraGrid1.UpdateData();
  305. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  306. {
  307. if (ultraGrid1.Rows[i].Cells["xuanze"].Value.ToString() == "True")
  308. {
  309. if (ultraGrid1.Rows[i].Cells["VALIDFLAG"].Value.ToString() != "无效")
  310. {
  311. MessageUtil.ShowWarning("选择的数据没有作废!");
  312. return;
  313. }
  314. xuanze = "true";
  315. }
  316. }
  317. if (xuanze == "false")
  318. {
  319. MessageUtil.ShowWarning("请选择你要恢复的记录!");
  320. return;
  321. }
  322. if (MessageUtil.ShowYesNoAndQuestion("是否确认恢复?") == System.Windows.Forms.DialogResult.No)
  323. {
  324. return;
  325. }
  326. #endregion
  327. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  328. {
  329. if (ultraGrid1.Rows[i].Cells["xuanze"].Value.ToString() == "True")
  330. {
  331. stringnew = ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString();
  332. year = ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString();
  333. CostBasePriceEntity parm = new CostBasePriceEntity();
  334. parm.ItemCode = ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString();
  335. parm.Year = Convert.ToDecimal(ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString());
  336. parm.UpdateName = this.UserInfo.GetUserName();
  337. string JsonStr = JSONFormat.Format(parm);
  338. ServerHelper.SetData("com.steering.pss.pncost.base.ComBasePrice.resume", new object[] { JsonStr }, ob);
  339. }
  340. }
  341. }
  342. catch (Exception ex)
  343. {
  344. MessageUtil.ShowError("恢复失败!'" + ex.Message + "'");
  345. return;
  346. }
  347. MessageUtil.ShowTips("恢复成功!");
  348. Query();
  349. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  350. {
  351. if (ultraGrid1.Rows[i].Cells["ITEMCODE"].Value.ToString() == stringnew)
  352. {
  353. if (ultraGrid1.Rows[i].Cells["YEAR"].Value.ToString() == year)
  354. {
  355. ultraGrid1.Rows[i].Activate();
  356. }
  357. }
  358. }
  359. }
  360. #endregion
  361. #region 事件
  362. /// 选择事件
  363. /// <summary>
  364. /// 选择事件
  365. /// </summary>
  366. private void ultraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  367. {
  368. ultraGrid1.UpdateData();
  369. if (e.Cell.Column.Key == "xuanze")
  370. {
  371. GridEdite(e.Cell.Row);
  372. }
  373. }
  374. /// 选择判断
  375. /// <summary>
  376. /// 选择判断
  377. /// </summary>
  378. private void GridEdite(UltraGridRow row)
  379. {
  380. if (row.GetValue("xuanze") == "True")
  381. {
  382. row.Cells["YEARNEW"].Value = row.Cells["YEAR"].Value;
  383. foreach (UltraGridCell cell in row.Cells)
  384. {
  385. if (cell.Column.CellActivation == Activation.AllowEdit)
  386. {
  387. cell.Activation = Activation.AllowEdit;
  388. }
  389. }
  390. }
  391. else
  392. {
  393. foreach (UltraGridCell cell in row.Cells)
  394. {
  395. if (cell.Column.Key == "xuanze") continue;
  396. if (cell.Column.CellActivation == Activation.AllowEdit)
  397. {
  398. cell.Activation = Activation.ActivateOnly;
  399. }
  400. }
  401. }
  402. }
  403. #endregion
  404. }
  405. }