FrmPlnPassmodel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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.PlnSaleOrd.BaseMethod;
  6. using Core.StlMes.Client.PlnSaleOrd.工序排产;
  7. using Core.StlMes.Client.PlnSaleOrd.工序排产.entity;
  8. using CoreFS.CA06;
  9. using Infragistics.Win;
  10. using Infragistics.Win.UltraWinGrid;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using System.Data;
  15. using System.Drawing;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Windows.Forms;
  19. namespace Core.StlMes.Client.PlnSaleOrd
  20. {
  21. public partial class FrmPlnPassmodel : FrmBase
  22. {
  23. private string passmPlanId = "";
  24. public FrmPlnPassmodel()
  25. {
  26. InitializeComponent();
  27. }
  28. private void FrmPlnPassmodel_Load(object sender, EventArgs e)
  29. {
  30. BaseHelper.setOtherColumnReadOnly(ultraGridPassModel, new string[] { "" });
  31. BaseHelper.InitCellPosition(ultraGridPassModel, new string[] { "PlanNum", "GxProSeq", "PassName" });
  32. BaseHelper.GridColumnCount(ultraGridPassModel, new string[] { "PlanNum" });
  33. PlanHelper.InitDropPline("D", "", txtPline1,this.ob);
  34. PlanHelper.InitDropPline("D", "", txtPline2, this.ob);
  35. //BaseHelper.NitializeDropDownBox(txtPline1, "com.steering.pss.plnsaleord.processOrder.FrmPlnPassmodel.initPline", "PLINE_NAME", "PLINE_CODE", false, ob);
  36. // BaseHelper.NitializeDropDownBox(txtPline2, "com.steering.pss.plnsaleord.processOrder.FrmPlnPassmodel.initPline", "PLINE_NAME", "PLINE_CODE", false, ob);
  37. }
  38. public override void ToolBar_Click(object sender, string ToolbarKey)
  39. {
  40. base.ToolBar_Click(sender, ToolbarKey);
  41. switch (ToolbarKey)
  42. {
  43. case "Query"://查询
  44. Query();
  45. break;
  46. case "Add"://新增
  47. Add();
  48. break;
  49. case "Update"://修改 q
  50. Update();
  51. break;
  52. case "Delete"://删除
  53. Delete();
  54. break;
  55. case "Close"://关闭
  56. this. Close();
  57. break;
  58. case "Export": //导出
  59. GridHelper.ulGridToExcel(ultraGridPassModel, "孔型信息");
  60. break;
  61. default:
  62. break;
  63. }
  64. }
  65. private void Query()
  66. {
  67. string plineCode = "";
  68. if (chcPline.Checked && txtPline1.Value != null)
  69. { plineCode = txtPline1.Value.ToString(); }
  70. string year = "";
  71. if (chcYear.Checked && txtYear1.Value != null)
  72. { year = DateTime.Parse(txtYear1.Value.ToString()).ToString("yyyy-MM"); }
  73. List<PlnPassmodelEntity> listSource = EntityHelper.GetData<PlnPassmodelEntity>
  74. ("com.steering.pss.plnsaleord.processOrder.FrmPlnPassmodel.queryModel", new object[] { plineCode, year }, ob);
  75. plnPassmodelEntityBindingSource.DataSource = listSource;
  76. if (!passmPlanId.Equals("") && ultraGridPassModel.Rows.Count > 0)
  77. {
  78. foreach (UltraGridRow ugr in ultraGridPassModel.Rows)
  79. {
  80. if (ugr.Cells["PassmPlanId"].Text.Equals(passmPlanId))
  81. {
  82. ugr.Activate();
  83. break;
  84. }
  85. }
  86. }
  87. passmPlanId = "";
  88. }
  89. /// <summary>
  90. /// 新增验证时间
  91. /// </summary>
  92. /// <param name="plineCode"></param>
  93. /// <param name="planTimeB"></param>
  94. /// <returns></returns>
  95. private bool CheckEndTime(string plineCode, string planTimeB, string yearMonth)
  96. {
  97. DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.processOrder.FrmPlnPassmodel.getMaxEndTime", new object[] { plineCode, yearMonth }, ob);
  98. if (dt == null || dt.Rows.Count == 0)
  99. {
  100. return true;
  101. }
  102. else
  103. {
  104. string maxEndTime = dt.Rows[0][0].ToString();
  105. if (maxEndTime.Length == 0)
  106. { return true; }
  107. else
  108. {
  109. DateTime dt1 = Convert.ToDateTime(planTimeB);
  110. DateTime dt2 = Convert.ToDateTime(maxEndTime);
  111. if (DateTime.Compare(dt1, dt2) >= 0)
  112. {
  113. return true;
  114. }
  115. else
  116. {
  117. return false;
  118. }
  119. }
  120. }
  121. }
  122. /// <summary>
  123. /// 验证参数
  124. /// </summary>
  125. /// <returns></returns>
  126. private bool CheckParams()
  127. {
  128. if (txtPline2.Value == null) { MessageUtil.ShowWarning("请选择产线描述!", txtPline2); return false; }
  129. if (txtModel.Value == null) { MessageUtil.ShowWarning("请选择孔型描述!", txtModel); return false; }
  130. if (txtNum.Value == null || txtNum.Value.ToString().Equals("") || Convert.ToInt32(txtNum.Value.ToString()) <= 0) { MessageUtil.ShowWarning("请输入计划支数!", txtNum); return false; }
  131. if (txtYear2.Value == null) { MessageUtil.ShowWarning("请选择生产年月!", txtYear2); return false; }
  132. if (txtPlanTimeB.Value == null) { MessageUtil.ShowWarning("请选择开始时间!", txtPlanTimeB); return false; }
  133. if (txtPlanTimeE.Value == null) { MessageUtil.ShowWarning("请选择结束时间!", txtPlanTimeE); return false; }
  134. if (DateTime.Parse(txtPlanTimeB.Value.ToString()) > DateTime.Parse(txtPlanTimeE.Value.ToString())) { MessageUtil.ShowWarning("开始时间不能大于线束时间!", txtPlanTimeB); return false; }
  135. return true;
  136. }
  137. private void Add()
  138. {
  139. if (!CheckParams()) { return; }
  140. PlnPassmodelEntity entity = new PlnPassmodelEntity();
  141. string year = DateTime.Parse(txtYear2.Value.ToString()).ToString("yyyy-MM");
  142. int num = Convert.ToInt32(txtNum.Value.ToString());
  143. string modelCode = txtModel.Value.ToString();
  144. string modelName = txtModel.Text.Trim();
  145. string plineCode = txtPline2.Value.ToString();
  146. string plineName = txtPline2.Text.Trim();
  147. string planTimeB = DateTime.Parse(txtPlanTimeB.Value.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
  148. string planTimeE = DateTime.Parse(txtPlanTimeE.Value.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
  149. entity.PassCode = modelCode;
  150. entity.PassName = modelName;
  151. entity.PlineCode = plineCode;
  152. entity.PlineName = plineName;
  153. entity.ProMonth = year;
  154. entity.PlanNum = num;
  155. entity.BeginTime = planTimeB;
  156. entity.EndTime = planTimeE;
  157. entity.CreateName = UserInfo.GetUserName();
  158. if (!CheckEndTime(plineCode, planTimeB, year))
  159. {
  160. MessageUtil.ShowWarning("产线 " + plineName + " 新增记录的开始时间小于该产线的最大结束时间!", txtPlanTimeB);
  161. return;
  162. }
  163. string jsonStr = JSONFormat.Format(entity);
  164. if (MessageUtil.ShowYesNoAndQuestion("是否新增?") == DialogResult.No)
  165. {
  166. return;
  167. }
  168. int count = ServerHelper.SetData("com.steering.pss.plnsaleord.processOrder.FrmPlnPassmodel.add", new object[] { jsonStr }, ob);
  169. if (count == 0) { MessageUtil.ShowTips("服务端处理失败!"); return; }
  170. else
  171. {
  172. MessageUtil.ShowWarning("新增成功!", ultraGridPassModel);
  173. Query();
  174. }
  175. }
  176. private void Update()
  177. {
  178. UltraGridRow ugr=ultraGridPassModel.ActiveRow;
  179. if(ugr==null){
  180. MessageUtil.ShowWarning("请选择要修改的记录!", ultraGridPassModel);
  181. return;
  182. }
  183. if (!CheckParams()) { return; }
  184. PlnPassmodelEntity entity = (PlnPassmodelEntity)ugr.ListObject;
  185. string year = DateTime.Parse(txtYear2.Value.ToString()).ToString("yyyy-MM");
  186. int num = Convert.ToInt32(txtNum.Value.ToString());
  187. string modelCode = txtModel.Value.ToString();
  188. string modelName = txtModel.Text.Trim();
  189. string plineCode = txtPline2.Value.ToString();
  190. string plineName = txtPline2.Text.Trim();
  191. string planTimeB = DateTime.Parse(txtPlanTimeB.Value.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
  192. string planTimeE = DateTime.Parse(txtPlanTimeE.Value.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
  193. entity.PassCode = modelCode;
  194. entity.PassName = modelName;
  195. entity.ProMonth = year;
  196. entity.PlanNum = num;
  197. entity.BeginTime = planTimeB;
  198. entity.EndTime = planTimeE;
  199. entity.UpdateName = UserInfo.GetUserName();
  200. string jsonStr = JSONFormat.Format(entity);
  201. if (MessageUtil.ShowYesNoAndQuestion("是否修改?") == DialogResult.No)
  202. {
  203. return;
  204. }
  205. passmPlanId = entity.PassmPlanId;
  206. string[] param = PlanHelper.SetData("com.steering.pss.plnsaleord.processOrder.FrmPlnPassmodel.update", new object[] { jsonStr }, ob);
  207. if (param == null) { MessageUtil.ShowWarning("服务端处理失败!", ultraGridPassModel); }
  208. else
  209. {
  210. MessageUtil.ShowWarning(param[1], ultraGridPassModel);
  211. if ((bool.Parse(param[0]))) { Query(); }
  212. }
  213. }
  214. private void Delete()
  215. {
  216. UltraGridRow ugr = ultraGridPassModel.ActiveRow;
  217. if (ugr == null)
  218. {
  219. MessageUtil.ShowWarning("请选择要删除的记录!", ultraGridPassModel);
  220. return;
  221. }
  222. if (!CheckParams()) { return; }
  223. PlnPassmodelEntity entity = (PlnPassmodelEntity)ugr.ListObject;
  224. string jsonStr = JSONFormat.Format(entity);
  225. if (MessageUtil.ShowYesNoAndQuestion("是否删除?") == DialogResult.No)
  226. {
  227. return;
  228. }
  229. string[] param = PlanHelper.SetData("com.steering.pss.plnsaleord.processOrder.FrmPlnPassmodel.delete", new object[] { jsonStr }, ob);
  230. if (param == null) { MessageUtil.ShowWarning("服务端处理失败!", ultraGridPassModel); }
  231. else
  232. {
  233. MessageUtil.ShowWarning(param[1], ultraGridPassModel);
  234. if ((bool.Parse(param[0]))) { Query(); }
  235. }
  236. }
  237. private void chc_CheckedChanged(object sender, EventArgs e)
  238. {
  239. if (chcPline.Checked) { txtPline1.ReadOnly = false; } else { txtPline1.ReadOnly = true; }
  240. if (chcYear.Checked) { txtYear1.ReadOnly = false; } else { txtYear1.ReadOnly = true; }
  241. }
  242. private void ultraGridPassModel_AfterRowActivate(object sender, EventArgs e)
  243. {
  244. UltraGridRow ugr = ultraGridPassModel.ActiveRow;
  245. if (ugr == null)
  246. {
  247. return;
  248. }
  249. PlnPassmodelEntity entity = (PlnPassmodelEntity)ugr.ListObject;
  250. txtPline2.Value = entity.PlineCode;
  251. txtPline2.Text = entity.PlineName;
  252. txtModel.Value = entity.PassCode;
  253. txtModel.Text = entity.PassName;
  254. txtYear2.Value = DateTime.Parse(entity.ProMonth).ToString("yyyy-MM");
  255. txtNum.Value = Convert.ToInt32(entity.PlanNum.ToString());
  256. txtPlanTimeB.Value = DateTime.Parse(entity.BeginTime).ToString("yyyy-MM-dd HH:mm:ss");
  257. txtPlanTimeE.Value = DateTime.Parse(entity.EndTime).ToString("yyyy-MM-dd HH:mm:ss");
  258. }
  259. private void txtPline2_ValueChanged(object sender, EventArgs e)
  260. {
  261. if (txtPline2.Value == null)
  262. {
  263. txtModel.Clear();
  264. return;
  265. }
  266. BaseHelper.NitializeDropDownBox(txtModel, "com.steering.pss.plnsaleord.processOrder.FrmPlnPassmodel.initPassModel", new Object[] { txtPline2.Value.ToString() }, "PASS_NAME", "PASS_CODE", false, ob);
  267. }
  268. }
  269. }