F_PM_2302.cs 12 KB

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