F_PM_2102.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_2102.cs
  5. * 2.功能描述:新增在产盘点单
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2015/05/13 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Reflection;
  13. using System.Text;
  14. using System.Windows.Forms;
  15. using Dongke.IBOSS.PRD.Basics.BaseControls;
  16. using Dongke.IBOSS.PRD.Basics.BaseResources;
  17. using Dongke.IBOSS.PRD.Client.CommonModule;
  18. using Dongke.IBOSS.PRD.Client.Controls;
  19. using Dongke.IBOSS.PRD.WCF.DataModels;
  20. using Dongke.IBOSS.PRD.WCF.Proxys;
  21. using Dongke.IBOSS.PRD.Basics.Library;
  22. namespace Dongke.IBOSS.PRD.Client.PMModule
  23. {
  24. /// <summary>
  25. /// 新增在产盘点单
  26. /// </summary>
  27. public partial class F_PM_2102 : DKFormBase
  28. {
  29. #region 成员变量
  30. private DataTable _dtGrid = null;
  31. private int _InCheckedID = 0;
  32. private string _userCodeValue;
  33. private bool _ShowFlag = true;
  34. #endregion
  35. #region 构造函数
  36. public F_PM_2102()
  37. {
  38. InitializeComponent();
  39. this.btnClose.Text = ButtonText.BTN_CLOSE;
  40. this.btnSave.Text = ButtonText.BTN_SAVE;
  41. }
  42. public F_PM_2102(int id, string remarks, string incheckname)
  43. {
  44. InitializeComponent();
  45. this.btnClose.Text = ButtonText.BTN_CLOSE;
  46. this.btnSave.Text = ButtonText.BTN_SAVE;
  47. this._InCheckedID = id;
  48. this.dkProcedureSearchBox.Enabled = false;
  49. this.scbGoods.Enabled = false;
  50. this.scbGoodsType.Enabled = false;
  51. this.chkDateTime.Enabled = false;
  52. this.txtInvoiceName.Text = incheckname;
  53. this.txtRemarks.Text = remarks;
  54. }
  55. #endregion
  56. #region 事件
  57. /// <summary>
  58. /// 关闭按钮事件
  59. /// </summary>
  60. /// <param name="sender"></param>
  61. /// <param name="e"></param>
  62. private void tsbtnClose_Click(object sender, EventArgs e)
  63. {
  64. this.Close();
  65. }
  66. /// <summary>
  67. /// 窗体加载事件
  68. /// </summary>
  69. /// <param name="sender"></param>
  70. /// <param name="e"></param>
  71. private void F_PM_2102_Load(object sender, EventArgs e)
  72. {
  73. // 初始化时间控件为当前日期
  74. this.dtpDateStart.Value = DateTime.Now.Date;
  75. this.dtpDateEnd.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);
  76. this.dtpDateStart.ValueChanged += dtpDateStart_ValueChanged;
  77. this.dtpDateEnd.ValueChanged += dtpDateStart_ValueChanged;
  78. this.dkProcedureSearchBox.TextChanged += new System.EventHandler(this.dkProcedureSearchBox_TextChanged);
  79. this.scbGoods.SearchedItemChanged += new System.EventHandler(this.dkProcedureSearchBox_TextChanged);
  80. this.scbGoodsType.SearchedItemChanged += new System.EventHandler(this.dkProcedureSearchBox_TextChanged);
  81. this.dgvFunctionUsers.AutoGenerateColumns = false;
  82. DataSet dsInChecked = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  83. {
  84. return PMModuleProxy.Service.GetInCheckedUserList(_InCheckedID);
  85. }));
  86. if (_InCheckedID > 0)
  87. {
  88. this.Text = "编辑盘点单";
  89. }
  90. this.dgvFunctionUsers.DataSource = dsInChecked.Tables[0];
  91. this._dtGrid = dsInChecked.Tables[0];
  92. }
  93. void dtpDateStart_ValueChanged(object sender, EventArgs e)
  94. {
  95. dkProcedureSearchBox_TextChanged(sender, e);
  96. }
  97. void dkProcedureSearchBox_TextChanged(object sender, EventArgs e)
  98. {
  99. string remarks = null;
  100. if (!string.IsNullOrWhiteSpace(this.dkProcedureSearchBox.Text))
  101. {
  102. remarks = "盘点工序: " + this.dkProcedureSearchBox.Text;
  103. }
  104. if (chkDateTime.Checked)
  105. {
  106. if (remarks != null)
  107. {
  108. remarks += "\r\n";
  109. }
  110. remarks += "完成时间: " + this.dtpDateStart.Value.ToString("yyyy-MM-dd HH:mm:ss") + " 至 "
  111. + this.dtpDateEnd.Value.ToString("yyyy-MM-dd HH:mm:ss");
  112. }
  113. if (!string.IsNullOrWhiteSpace(this.scbGoodsType.Text))
  114. {
  115. if (remarks != null)
  116. {
  117. remarks += "\r\n";
  118. }
  119. remarks += "产品类别: " + this.scbGoodsType.Text;
  120. }
  121. if (!string.IsNullOrWhiteSpace(this.scbGoods.Text))
  122. {
  123. if (remarks != null)
  124. {
  125. remarks += "\r\n";
  126. }
  127. remarks += "产品编码: " + this.scbGoods.Text;
  128. }
  129. this.txtRemarks.Text = remarks;
  130. }
  131. /// <summary>
  132. /// 保存按钮事件
  133. /// </summary>
  134. /// <param name="sender"></param>
  135. /// <param name="e"></param>
  136. private void btnSave_Click(object sender, EventArgs e)
  137. {
  138. try
  139. {
  140. // 自动生成的备注会超长
  141. if (this.txtRemarks.Text.Length > 500)
  142. {
  143. MessageBox.Show("备注的内容超过最大长度【500个字】,请重新输入", this.Text
  144. , MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  145. this.txtRemarks.Focus();
  146. return;
  147. }
  148. // 删除空白行
  149. DataRow[] rows = this._dtGrid.Select("userid is null");
  150. if (rows != null && rows.Length > 0)
  151. {
  152. foreach (DataRow item in rows)
  153. {
  154. item.Delete();
  155. }
  156. }
  157. InProductionEntity[] inProductionEntitys = new InProductionEntity[1];
  158. InProductionEntity inProductionEntity = new InProductionEntity();
  159. inProductionEntity.ProcedureIDS = this.dkProcedureSearchBox.ProcedureIDS;
  160. inProductionEntity.CompleteProcedureName = this.txtInvoiceName.Text.Trim();
  161. inProductionEntity.ReworkProcedureID = this._InCheckedID;
  162. this._dtGrid.AcceptChanges();
  163. inProductionEntity.UserTable = this._dtGrid;
  164. if (chkDateTime.Checked)
  165. {
  166. inProductionEntity.StartCompleteDate = this.dtpDateStart.Value;
  167. inProductionEntity.EndCompleteDate = this.dtpDateEnd.Value;
  168. }
  169. inProductionEntity.GoodsCodeList = this.scbGoods.CheckedPKMember;
  170. inProductionEntity.GoodsTypeCode = scbGoodsType.SearchedValue + "";
  171. inProductionEntitys[0] = inProductionEntity;
  172. int returnValue = (int)DoAsync(new BaseAsyncMethod(() =>
  173. {
  174. return PMModuleProxy.Service.SaveInChecked(inProductionEntitys, this.txtRemarks.Text.Trim());
  175. }));
  176. if (returnValue > 0)
  177. {
  178. // 提示信息
  179. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "新建" + this.Text, "保存"),
  180. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  181. this.DialogResult = DialogResult.OK;
  182. }
  183. else if (returnValue == 0)
  184. {
  185. // 提示信息
  186. MessageBox.Show("保存失败",
  187. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  188. }
  189. }
  190. catch (Exception ex)
  191. {
  192. // 对异常进行共通处理
  193. ExceptionManager.HandleEventException(this.ToString(),
  194. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  195. }
  196. }
  197. /// <summary>
  198. /// 完成复选框改变事件
  199. /// </summary>
  200. /// <param name="sender"></param>
  201. /// <param name="e"></param>
  202. private void chkDateTime_CheckedChanged(object sender, EventArgs e)
  203. {
  204. dtpDateStart.Enabled = chkDateTime.Checked;
  205. dtpDateEnd.Enabled = chkDateTime.Checked;
  206. dkProcedureSearchBox_TextChanged(sender, e);
  207. }
  208. private void dgvFunctionUsers_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
  209. {
  210. try
  211. {
  212. if (this.dgvFunctionUsers.Rows.Count <= 1)
  213. {
  214. return;
  215. }
  216. DataGridViewColumn columnItem = this.dgvFunctionUsers.Columns[e.ColumnIndex];
  217. if ("UserCode".Equals(columnItem.Name))
  218. {
  219. _userCodeValue = this.dgvFunctionUsers.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
  220. }
  221. }
  222. catch (Exception ex)
  223. {
  224. // 对异常进行共通处理
  225. ExceptionManager.HandleEventException(this.ToString(),
  226. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  227. }
  228. }
  229. private void dgvFunctionUsers_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
  230. {
  231. //if (e.Row.Index != -1)
  232. //{
  233. // DataTable dt = this.dgvFunctionUsers.DataSource as DataTable;
  234. // string userID = dt.Rows[e.Row.Index]["userID"].ToString();
  235. // DataRow[] isR = this._dtGrid.Select("UserID=" + userID);
  236. // isR[0].Delete();
  237. // this.btnSave.Enabled = true;
  238. //}
  239. }
  240. private void dgvFunctionUsers_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  241. {
  242. try
  243. {
  244. if (this.dgvFunctionUsers.Rows.Count <= 1 || !_ShowFlag)
  245. {
  246. return;
  247. }
  248. DataGridViewRow rowItem = this.dgvFunctionUsers.Rows[e.RowIndex];
  249. DataGridViewColumn columnItem = this.dgvFunctionUsers.Columns[e.ColumnIndex];
  250. //string OrganizationName = this.dgvFunctionUsers.Rows[e.RowIndex].Cells["OrganizationName"].Value.ToString();
  251. // 用编号获取产品信息
  252. if ("UserCode".Equals(columnItem.Name))
  253. {
  254. _ShowFlag = false;
  255. DataTable dtNew = FormUtility.BindUserRowDataSource(this.dgvFunctionUsers,
  256. e.RowIndex, columnItem.Name, _userCodeValue);
  257. if (dtNew != null && dtNew.Rows.Count > 0)
  258. {
  259. foreach (DataRow r in dtNew.Rows)
  260. {
  261. DataRow[] isR = _dtGrid.Select("UserID=" + r["UserID"]);
  262. if (isR.Length == 0)
  263. {
  264. DataRow drNew = _dtGrid.NewRow();
  265. drNew["UserID"] = r["UserID"];
  266. drNew["UserCode"] = r["UserCode"];
  267. drNew["UserName"] = r["UserName"];
  268. _dtGrid.Rows.Add(drNew);
  269. dgvFunctionUsers.Rows[e.RowIndex].Cells["UserCode"].ReadOnly = true;
  270. // BindReadOnly();
  271. }
  272. }
  273. }
  274. this.btnSave.Enabled = DataJudge.IsChange(_dtGrid);
  275. //this.dgvFunctionUsers.Rows[e.RowIndex].Cells["FunctionCode"].Value = this._functionCode;
  276. //this._dtDataGird.AcceptChanges();
  277. // 设置可输入单元格的颜色
  278. this.dgvFunctionUsers.IsSetInputColumnsColor = true;
  279. }
  280. _ShowFlag = true;
  281. }
  282. catch (Exception ex)
  283. {
  284. //_ShowFlag = true;
  285. // 对异常进行共通处理
  286. ExceptionManager.HandleEventException(this.ToString(),
  287. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  288. }
  289. }
  290. #endregion
  291. }
  292. }