FrmPriceDoc.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using com.steering.pss.sale.price.entity;
  2. using Core.Mes.Client.Comm.Server;
  3. using Core.Mes.Client.Comm.Tool;
  4. using CoreFS.CA06;
  5. using Infragistics.Win.UltraWinEditors;
  6. using Infragistics.Win.UltraWinGrid;
  7. using System;
  8. using System.Collections;
  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. using Core.Mes.Client.Comm.Format;
  17. using Core.Mes.Client.Comm.Control;
  18. namespace Core.StlMes.Client.SalePrice.BaseForm
  19. {
  20. public partial class FrmPriceDoc : FrmBase
  21. {
  22. string isValid = "1";
  23. public FrmPriceDoc()
  24. {
  25. InitializeComponent();
  26. }
  27. private void FrmPriceDoc_Load(object sender, EventArgs e)
  28. {
  29. EntityHelper.ShowGridCaption<SlmPriceDocEntity>(gdPriceDoc.DisplayLayout.Bands[0]);
  30. // InitForm();
  31. }
  32. public override void ToolBar_Click(object sender, string ToolbarKey)
  33. {
  34. switch (ToolbarKey)
  35. {
  36. case "Query":
  37. QueryData();
  38. break;
  39. case "Save":
  40. SaveFormData();
  41. break;
  42. case "Delete":
  43. DeleteOrResume(true);
  44. break;
  45. case "Resume":
  46. DeleteOrResume(false);
  47. break;
  48. case "Close":
  49. this.Close();
  50. break;
  51. }
  52. }
  53. /// <summary>
  54. /// 删除或恢复
  55. /// </summary>
  56. /// <param name="flag"></param>
  57. private void DeleteOrResume(bool flag)
  58. {
  59. gdPriceDoc.UpdateData();
  60. UltraGridRow[] row = gdPriceDoc.Rows.AsQueryable().Where(a => a.Cells["CHK"].Value.ToString() == "True").ToArray();
  61. if (row.Length <= 0)
  62. {
  63. MessageUtil.ShowWarning("请选择需要" + (flag ? "删除" : "恢复") + "的数据!");
  64. return;
  65. }
  66. ArrayList parm = new ArrayList();
  67. if (flag)
  68. {
  69. foreach (var uRow in row)
  70. {
  71. SlmPriceDocEntity spf = (SlmPriceDocEntity)uRow.ListObject;
  72. if (spf.Validflag == "无效")
  73. {
  74. MessageUtil.ShowWarning("您勾选的数据中存在已删除的数据,不必重复删除!");
  75. return;
  76. }
  77. spf.Createname = UserInfo.GetUserName();
  78. spf.Updatename = UserInfo.GetUserName();
  79. parm.Add(JSONFormat.Format(spf));
  80. }
  81. }
  82. else
  83. {
  84. foreach (var uRow in row)
  85. {
  86. SlmPriceDocEntity spf = (SlmPriceDocEntity)uRow.ListObject;
  87. if (spf.Validflag == "有效")
  88. {
  89. MessageUtil.ShowWarning("您勾选的数据中存在有效的数据,不必进行恢复!");
  90. return;
  91. }
  92. spf.Createname = UserInfo.GetUserName();
  93. spf.Updatename = UserInfo.GetUserName();
  94. parm.Add(JSONFormat.Format(spf));
  95. }
  96. }
  97. if (MessageUtil.ShowYesNoAndQuestion("是否" + (flag ? "删除" : "恢复") + "所选的数据!") == DialogResult.No) return;
  98. int i = ServerHelper.SetData("com.steering.pss.sale.price.server.CorePriceBaseDoc.deleteOrResume", new object[] { parm, flag }, this.ob);
  99. if (i >= 0)
  100. {
  101. MessageUtil.ShowTips("数据" + (flag ? "删除" : "恢复") + "成功!");
  102. QueryData();
  103. }
  104. else
  105. {
  106. MessageUtil.ShowTips("数据" + (flag ? "删除" : "恢复") + "失败!");
  107. QueryData();
  108. }
  109. }
  110. private void SaveFormData()
  111. {
  112. gdPriceDoc.UpdateData();
  113. UltraGridRow[] row = gdPriceDoc.Rows.AsQueryable().Where(a => a.Cells["CHK"].Value.ToString().ToUpper() == "TRUE").ToArray();
  114. if (row.Length <= 0)
  115. {
  116. MessageUtil.ShowWarning("请选择需要保存的数据!");
  117. return;
  118. }
  119. if (row.Length > 0)
  120. {
  121. ArrayList parm = CheckFormData(row);
  122. if (parm == null || parm.Count <= 0)
  123. {
  124. return;
  125. }
  126. if (MessageUtil.ShowYesNoAndQuestion("是否确认保存数据!") == DialogResult.No) return;
  127. int i = ServerHelper.SetData("com.steering.pss.sale.price.server.CorePriceBaseDoc.save",
  128. new object[] { parm }, this.ob);
  129. if (i > 0)
  130. {
  131. MessageUtil.ShowTips("数据保存成功!");
  132. QueryData();
  133. }
  134. else
  135. {
  136. MessageUtil.ShowTips("数据保存失败!");
  137. QueryData();
  138. }
  139. }
  140. }
  141. private ArrayList CheckFormData(UltraGridRow[] row)
  142. {
  143. ArrayList parm = new ArrayList();
  144. List<string> list = new List<string>();
  145. foreach (var uRow in row)
  146. {
  147. SlmPriceDocEntity spf = (SlmPriceDocEntity)uRow.ListObject;
  148. if (spf.Validflag == "无效" && spf.Updatename != "")
  149. {
  150. MessageUtil.ShowWarning("【" + spf.PriceVerId + "】的因素已经无效,不能修改!");
  151. return null;
  152. }
  153. spf.ValiddateBegin = Convert.ToDateTime(spf.ValiddateBegin).ToString("yyyy-MM-dd");
  154. spf.ValiddateEnd = Convert.ToDateTime(spf.ValiddateEnd).ToString("yyyy-MM-dd");
  155. ; spf.Createname= UserInfo.GetUserName();
  156. spf.Updatename = UserInfo.GetUserName();
  157. parm.Add(JSONFormat.Format(spf));
  158. }
  159. return parm;
  160. }
  161. /// <summary>
  162. /// 查询数据
  163. /// </summary>
  164. private void QueryData()
  165. {
  166. string priceVerId = "";
  167. string priceVerDesc = "";
  168. if (labelTextBox1.Checked)
  169. priceVerDesc = labelTextBox1.Text.Trim();
  170. if (labelTextBox2.Checked)
  171. priceVerId = labelTextBox2.Text.Trim();
  172. List<SlmPriceDocEntity> list = EntityHelper.GetData<SlmPriceDocEntity>(
  173. "com.steering.pss.sale.price.server.CorePriceBaseDoc.query", new object[] { priceVerId, priceVerDesc, isValid }, this.ob);
  174. slmPriceDocEntityBindingSource.DataSource = list;
  175. UltraGridBand ugb = this.gdPriceDoc.DisplayLayout.Bands[0];
  176. UltraGridColumn[] col = new UltraGridColumn[] { ugb.Columns["priceVerDesc"] };
  177. GridHelper.RefreshAndAutoSizeExceptColumns(gdPriceDoc, col);
  178. }
  179. private void gdPriceDoc_InitializeRow(object sender, InitializeRowEventArgs e)
  180. {
  181. if (e.Row != null)
  182. {
  183. if (e.Row.Cells["VALIDFLAG"].Value.ToString() == "无效")
  184. {
  185. e.Row.Appearance.ForeColor = Color.Red;
  186. }
  187. else
  188. {
  189. e.Row.Appearance.ForeColor = Color.Black;
  190. }
  191. }
  192. }
  193. private void gdPriceDoc_AfterRowInsert(object sender, RowEventArgs e)
  194. {
  195. string maxId = gdPriceDoc.Rows.AsQueryable().Max(a => a.Cells["PriceVerId"].Value.ToString());
  196. if (maxId == "")
  197. {
  198. e.Row.Cells["PriceVerId"].Value = "D000001";
  199. }
  200. else
  201. {
  202. string str = "D" + (Convert.ToInt32(maxId.Substring(1, 6)) + 1).ToString().PadLeft(6, '0');
  203. e.Row.Cells["PriceVerId"].Value = str;
  204. }
  205. }
  206. private void chkValid_CheckedChanged(object sender, EventArgs e)
  207. {
  208. if (chkValid.Checked)
  209. {
  210. isValid = "0";
  211. }
  212. else
  213. {
  214. isValid = "1";
  215. }
  216. }
  217. }
  218. }