F_PM_2302.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /*******************************************************************************
  2. * Copyright(c) 2017 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_2302.cs
  5. * 2.功能描述:生产订单新建/编辑界面
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2017/02/07 1.00 新建
  9. *******************************************************************************/
  10. using Dongke.IBOSS.PRD.Basics.BaseControls;
  11. using Dongke.IBOSS.PRD.Basics.BaseResources;
  12. using Dongke.IBOSS.PRD.Basics.Library;
  13. using Dongke.IBOSS.PRD.Client.CommonModule;
  14. using Dongke.IBOSS.PRD.WCF.DataModels;
  15. using Dongke.IBOSS.PRD.WCF.Proxys;
  16. using System;
  17. using System.Data;
  18. using System.Windows.Forms;
  19. namespace Dongke.IBOSS.PRD.Client.PMModule
  20. {
  21. public partial class F_PM_2302 : FormBase
  22. {
  23. #region 成员变量
  24. // 存储窗口的编辑状态
  25. private Constant.FormMode _editStatus;
  26. // 修改生产订单时存储上个窗口传过来的ID
  27. private int _orderID;
  28. private OrderEntity _orderEntity = new OrderEntity();
  29. #endregion
  30. #region 构造函数
  31. /// <summary>
  32. /// 构造函数
  33. /// </summary>
  34. public F_PM_2302()
  35. : this(Constant.FormMode.Add)
  36. {
  37. }
  38. /// <summary>
  39. /// 构造函数
  40. /// </summary>
  41. public F_PM_2302(Constant.FormMode editStatus)
  42. : this(editStatus, 0)
  43. {
  44. }
  45. /// <summary>
  46. /// 构造函数
  47. /// </summary>
  48. public F_PM_2302(Constant.FormMode editStatus, int orderID)
  49. {
  50. InitializeComponent();
  51. this._editStatus = editStatus;
  52. // 根据新建、编辑状态为标题赋值
  53. if (editStatus == Constant.FormMode.Add)
  54. {
  55. this.Text = FormTitles.F_PM_2302_ADD;
  56. }
  57. else
  58. {
  59. this.Text = FormTitles.F_PM_2302_EDIT;
  60. // 存储上个窗口传过来的生产订单ID
  61. this._orderID = orderID;
  62. }
  63. // 按钮文本
  64. this.btnSave.Text = ButtonText.BTN_SAVE;
  65. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  66. }
  67. #endregion
  68. #region 事件
  69. /// <summary>
  70. /// 窗体加载事件
  71. /// </summary>
  72. /// <param name="sender"></param>
  73. /// <param name="e"></param>
  74. private void F_PM_2302_Load(object sender, EventArgs e)
  75. {
  76. try
  77. {
  78. //this.dgvOrderDetail.AutoGenerateColumns = false;
  79. //this.dgvOrderDetail.IsSetInputColumnsColor = true;
  80. this.dtpOrderDateFrom.Value = DateTime.Now.Date;
  81. // 若状态是添加,则有效标志为可用并且不显示
  82. if (this._editStatus == Constant.FormMode.Edit)
  83. {
  84. this.SetOrganizationData();
  85. //txtOrderNo.ReadOnly = true;
  86. }
  87. //else
  88. //{
  89. // DataTable dt = new DataTable("OrderDetail");
  90. // dt.Columns.Add("materialcode");
  91. // //dgvOrderDetail.DataSource = dt;
  92. //}
  93. this.txtVBELN.Focus();
  94. }
  95. catch (Exception ex)
  96. {
  97. // 对异常进行共通处理
  98. ExceptionManager.HandleEventException(this.ToString(),
  99. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  100. }
  101. }
  102. /// <summary>
  103. /// 保存按钮事件
  104. /// </summary>
  105. /// <param name="sender"></param>
  106. /// <param name="e"></param>
  107. private void btnSave_Click(object sender, EventArgs e)
  108. {
  109. try
  110. {
  111. // 验证信息是否完整
  112. bool validResult = IsValidData();
  113. if (validResult)
  114. {
  115. this.btnSave.Enabled = false;
  116. this.btnCancel.Enabled = false;
  117. ClientRequestEntity cre = new ClientRequestEntity();
  118. cre.NameSpace = "F_PM_2302";
  119. cre.Name = "SaveOrder";
  120. OrderEntity order = GetOrderEntity();
  121. cre.Request = JsonHelper.ToJson(order);
  122. ServiceResultEntity sre = (ServiceResultEntity)DoAsync(() =>
  123. {
  124. return PMModuleProxyNew.Service.HandleRequest(cre);
  125. });
  126. this.btnSave.Enabled = true;
  127. this.btnCancel.Enabled = true;
  128. if (Convert.ToInt32(sre.Result) > Constant.INT_IS_ZERO)
  129. {
  130. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "生产订单", "保存"),
  131. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  132. //this._organizationIDList.Add(Convert.ToInt32(result));
  133. this.DialogResult = DialogResult.OK;
  134. }
  135. else if (!string.IsNullOrEmpty(sre.Message))
  136. {
  137. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, sre.Message),
  138. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  139. return;
  140. }
  141. else
  142. {
  143. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "生产订单", "保存"),
  144. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  145. return;
  146. }
  147. if (this._editStatus == Constant.FormMode.Edit)
  148. {
  149. this.Close();
  150. }
  151. else
  152. {
  153. // 重置窗口数据
  154. this.ResetFormData();
  155. }
  156. }
  157. }
  158. catch (Exception ex)
  159. {
  160. this.btnSave.Enabled = true;
  161. this.btnCancel.Enabled = true;
  162. // 对异常进行共通处理
  163. ExceptionManager.HandleEventException(this.ToString(),
  164. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  165. }
  166. }
  167. /// <summary>
  168. /// 关闭按钮事件
  169. /// </summary>
  170. /// <param name="sender"></param>
  171. /// <param name="e"></param>
  172. private void btnClose_Click(object sender, EventArgs e)
  173. {
  174. this.Close();
  175. }
  176. /// <summary>
  177. /// 订单号拼接事件
  178. /// </summary>
  179. /// <param name="sender"></param>
  180. /// <param name="e"></param>
  181. private void txtVBELN_TextChanged(object sender, EventArgs e)
  182. {
  183. txtOrderNo.Text = txtVBELN.Text.Trim() + "/" + txtPOSNR.Text.Trim() + "#" + txtSummary.Text.Trim();
  184. }
  185. ///// <summary>
  186. ///// 获取组织机构结果集
  187. ///// </summary>
  188. ///// <returns></returns>
  189. //private DataSet GetOrganizationDataSource()
  190. //{
  191. // try
  192. // {
  193. // OrganizationEntity organization = new OrganizationEntity();
  194. // //// 票号开头字母
  195. // //organization.LetterMarket = this.LetterMarket.Text.Trim();
  196. // //// 联系电话
  197. // //organization.Telephone = this.txtTelephone.Text.Trim();
  198. // //// 地址
  199. // //organization.Address = this.txtAddress.Text;
  200. // //// 备注
  201. // //organization.Remarks = this.txtRemarks.Text;
  202. // //// 正常标识
  203. // //organization.ValueFlags = null;
  204. // //organization.in_UserID = LogInUserInfo.CurrentUser.CurrentUserEntity.UserID;
  205. // //organization.in_AccountID = LogInUserInfo.CurrentUser.CurrentUserEntity.AccountID;
  206. // //this._organization = organization;
  207. // return SystemModuleProxy.Service.SelectOrganizationData(organization);
  208. // }
  209. // catch (Exception ex)
  210. // {
  211. // throw ex;
  212. // }
  213. //}
  214. ///// <summary>
  215. ///// 物料编码改变事件
  216. ///// </summary>
  217. ///// <param name="sender"></param>
  218. ///// <param name="e"></param>
  219. //private void scbSAPCode1_TextValueChanged(object sender, WinForm.Controls.ScbSearchBox.TextChangeEventArgs e)
  220. //{
  221. // dgvOrderDetail.DataSource = scbSAPCode1.CheckedData;
  222. //}
  223. #endregion
  224. #region 私有方法
  225. /// <summary>
  226. /// 为窗体各个控赋值
  227. /// </summary>
  228. private void SetOrganizationData()
  229. {
  230. try
  231. {
  232. // 获取生产订单信息
  233. this._orderEntity = new OrderEntity();
  234. this._orderEntity.OrderID = this._orderID;
  235. DataSet result = (DataSet)DoAsync(new BaseAsyncMethod(this.GetOrderList));
  236. if (result != null && result.Tables.Count > Constant.INT_IS_ZERO && result.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  237. {
  238. DataRow orderRow = result.Tables[0].Rows[0];
  239. // 生产号
  240. this.txtOrderNo.Text = orderRow["OrderNo"].ToString();
  241. // 订单日期
  242. this.dtpOrderDateFrom.Value = Convert.ToDateTime(orderRow["OrderDate"]);
  243. // 备注
  244. this.txtRemarks.Text = orderRow["Remarks"].ToString();
  245. this.txtDisplayNo.DataValue = Convert.ToInt32(orderRow["DisplayNo"]);
  246. txtVBELN.Text = orderRow["VBELN"].ToString();
  247. txtPOSNR.Text = orderRow["POSNR"].ToString();
  248. txtSummary.Text = orderRow["Summary"].ToString();
  249. //// 条码串
  250. //string[] arr = result.Tables[1].AsEnumerable().Select(d => d.Field<string>("guid")).ToArray();
  251. //string guids = string.Join(",", arr);
  252. //arr = result.Tables[1].AsEnumerable().Select(d => d.Field<string>("materialcode")).ToArray();
  253. //string materialcodes = string.Join(",", arr);
  254. //scbSAPCode1.Text = materialcodes;
  255. //scbSAPCode1.CheckedData = result.Tables[1];
  256. //dgvOrderDetail.DataSource = result.Tables[1];
  257. }
  258. }
  259. catch (Exception ex)
  260. {
  261. throw ex;
  262. }
  263. }
  264. /// <summary>
  265. /// 获取生产订单数据
  266. /// </summary>
  267. /// <returns></returns>
  268. private DataSet GetOrderList()
  269. {
  270. try
  271. {
  272. return PMModuleProxy.Service.GetOrderList(this._orderEntity);
  273. }
  274. catch (Exception ex)
  275. {
  276. throw ex;
  277. }
  278. }
  279. /// <summary>
  280. /// 验证输入是否完整
  281. /// </summary>
  282. /// <returns></returns>
  283. private bool IsValidData()
  284. {
  285. try
  286. {
  287. // 生产订单号不能为空
  288. if (string.IsNullOrEmpty(this.txtOrderNo.Text.Trim()))
  289. {
  290. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "生产订单号"),
  291. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  292. this.txtVBELN.Focus();
  293. return false;
  294. }
  295. // 如果不是hegii开头的订单,必须天订单号和行号
  296. if (!txtOrderNo.Text.StartsWith("HEGII"))
  297. {
  298. // SAP销售订单号不能为空
  299. if (string.IsNullOrEmpty(this.txtVBELN.Text.Trim()))
  300. {
  301. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "SAP销售订单号"),
  302. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  303. this.txtVBELN.Focus();
  304. return false;
  305. }
  306. // 行号不能为空
  307. if (string.IsNullOrEmpty(this.txtPOSNR.Text.Trim()))
  308. {
  309. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "行号"),
  310. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  311. this.txtPOSNR.Focus();
  312. return false;
  313. }
  314. }
  315. return true;
  316. }
  317. catch (Exception ex)
  318. {
  319. throw ex;
  320. }
  321. }
  322. ///// <summary>
  323. ///// 保存组织机构
  324. ///// </summary>
  325. ///// <returns>影响的行数</returns>
  326. //private ServiceResultEntity SaveOrder()
  327. //{
  328. // try
  329. // {
  330. // OrderEntity order = GetOrderEntity();
  331. // return PMModuleProxy.Service.SaveOrder(order);
  332. // }
  333. // catch (Exception ex)
  334. // {
  335. // throw ex;
  336. // }
  337. //}
  338. /// <summary>
  339. /// 给订单体类传值
  340. /// </summary>
  341. /// <returns></returns>
  342. private OrderEntity GetOrderEntity()
  343. {
  344. OrderEntity order = new OrderEntity();
  345. // 生产订单ID
  346. order.OrderID = this._orderID;
  347. // 生产订单号
  348. order.OrderNo = this.txtOrderNo.Text.Trim();
  349. // 生产订单日期
  350. order.OrderDate = this.dtpOrderDateFrom.Value;
  351. // 备注
  352. order.Remarks = this.txtRemarks.Text.Trim();
  353. order.ValueFlag = 1;
  354. order.DisplayNo = (int)(this.txtDisplayNo.DataValue ?? 0);
  355. // sap销售订单号
  356. order.VBELN = this.txtVBELN.Text.Trim();
  357. // 行号
  358. order.POSNR = this.txtPOSNR.Text.Trim();
  359. // 描述
  360. order.Summary = this.txtSummary.Text.Trim();
  361. //DataTable dt = dgvOrderDetail.DataSource as DataTable;
  362. //if (dt != null)
  363. //{
  364. // dt.AcceptChanges();
  365. // DataView dv = new DataView(dt);
  366. // order.OrderDetail = dv.ToTable(true, new string[] { "materialcode" });
  367. //}
  368. return order;
  369. }
  370. /// <summary>
  371. /// 重置窗口数据
  372. /// </summary>
  373. private void ResetFormData()
  374. {
  375. this._orderID = Constant.INT_IS_ZERO;
  376. txtVBELN.Text = string.Empty;
  377. txtPOSNR.Text = string.Empty;
  378. txtSummary.Text = string.Empty;
  379. this.txtOrderNo.Text = string.Empty;
  380. this.dtpOrderDateFrom.Value = DateTime.Now;
  381. this.txtRemarks.Text = string.Empty;
  382. this.txtVBELN.Focus();
  383. }
  384. #endregion
  385. }
  386. }