F_PC_1102.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PC_1102.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. using System.Collections.Generic;
  23. namespace Dongke.IBOSS.PRD.Client.PMModule
  24. {
  25. /// <summary>
  26. /// 新增盘点单
  27. /// </summary>
  28. public partial class F_PC_1102 : DKFormBase
  29. {
  30. #region 成员变量
  31. private DataTable _dtGrid = null;
  32. private int _checkedID = 0;
  33. private string _userCodeValue;
  34. private bool _ShowFlag = true;
  35. #endregion
  36. #region 构造函数
  37. public F_PC_1102()
  38. {
  39. InitializeComponent();
  40. this.btnClose.Text = ButtonText.BTN_CLOSE;
  41. this.btnSave.Text = ButtonText.BTN_SAVE;
  42. }
  43. public F_PC_1102(int id)
  44. {
  45. InitializeComponent();
  46. this.btnClose.Text = ButtonText.BTN_CLOSE;
  47. this.btnSave.Text = ButtonText.BTN_SAVE;
  48. this._checkedID = id;
  49. //this.dkProcedureSearchBox.Enabled = false;
  50. this.scbGoods.Enabled = false;
  51. this.scbGoodsType.Enabled = false;
  52. this.chkDateTime.Enabled = false;
  53. this.chkStatus1.Checked = false;
  54. this.chkStatus1.Enabled = false;
  55. this.chkStatus2.Enabled = false;
  56. this.chkStatus3.Enabled = false;
  57. }
  58. #endregion
  59. #region 事件
  60. /// <summary>
  61. /// 关闭按钮事件
  62. /// </summary>
  63. /// <param name="sender"></param>
  64. /// <param name="e"></param>
  65. private void tsbtnClose_Click(object sender, EventArgs e)
  66. {
  67. this.Close();
  68. }
  69. /// <summary>
  70. /// 窗体加载事件
  71. /// </summary>
  72. /// <param name="sender"></param>
  73. /// <param name="e"></param>
  74. private void F_PM_2102_Load(object sender, EventArgs e)
  75. {
  76. // 初始化时间控件为当前日期
  77. this.dtpDateStart.Value = DateTime.Now.Date;
  78. this.dtpDateEnd.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);
  79. this.dtpDateStart.ValueChanged += dtpDateStart_ValueChanged;
  80. this.dtpDateEnd.ValueChanged += dtpDateStart_ValueChanged;
  81. //this.dkProcedureSearchBox.TextChanged += new System.EventHandler(this.dkProcedureSearchBox_TextChanged);
  82. this.scbGoods.SearchedItemChanged += new System.EventHandler(this.dkProcedureSearchBox_TextChanged);
  83. this.scbGoodsType.SearchedItemChanged += new System.EventHandler(this.dkProcedureSearchBox_TextChanged);
  84. this.dgvFunctionUsers.AutoGenerateColumns = false;
  85. if (_checkedID > 0)
  86. {
  87. this.Text = "编辑盘点单";
  88. ClientRequestEntity cre = new ClientRequestEntity();
  89. cre.NameSpace = "FPC1101";
  90. cre.Name = "GetMouldCheckedInfoForUpdate";
  91. cre.Properties["CheckedID"] = _checkedID;
  92. ServiceResultEntity sre = PCModuleProxyNew.Service.HandleRequest(cre);
  93. if (sre != null && sre.Data != null && sre.Data.Tables.Count > 1 && sre.Data.Tables[0].Rows.Count > 0)
  94. {
  95. this.Text += "【" + sre.Data.Tables[0].Rows[0]["checkedno"] + "】";
  96. this.txtInvoiceName.Text = sre.Data.Tables[0].Rows[0]["checkname"].ToString();
  97. this.txtRemarks.Text = sre.Data.Tables[0].Rows[0]["remarks"].ToString();
  98. this._dtGrid = sre.Data.Tables[1];
  99. }
  100. }
  101. else
  102. {
  103. this._dtGrid = new DataTable("CheckedUser");
  104. this._dtGrid.Columns.Add("UserID", typeof(int));
  105. this._dtGrid.Columns.Add("UserCode", typeof(string));
  106. this._dtGrid.Columns.Add("UserName", typeof(string));
  107. dkProcedureSearchBox_TextChanged(null, null);
  108. }
  109. this.dgvFunctionUsers.DataSource = this._dtGrid;
  110. }
  111. /// <summary>
  112. ///
  113. /// </summary>
  114. /// <param name="sender"></param>
  115. /// <param name="e"></param>
  116. void dtpDateStart_ValueChanged(object sender, EventArgs e)
  117. {
  118. dkProcedureSearchBox_TextChanged(sender, e);
  119. }
  120. /// <summary>
  121. ///
  122. /// </summary>
  123. /// <param name="sender"></param>
  124. /// <param name="e"></param>
  125. void dkProcedureSearchBox_TextChanged(object sender, EventArgs e)
  126. {
  127. string remarks = null;
  128. //if (!string.IsNullOrWhiteSpace(this.dkProcedureSearchBox.Text))
  129. //{
  130. // remarks = "盘点工序: " + this.dkProcedureSearchBox.Text;
  131. //}
  132. if (chkDateTime.Checked)
  133. {
  134. if (remarks != null)
  135. {
  136. remarks += "\r\n";
  137. }
  138. remarks += "生产日期: " + this.dtpDateStart.Value.ToString("yyyy-MM-dd HH:mm:ss") + " 至 "
  139. + this.dtpDateEnd.Value.ToString("yyyy-MM-dd HH:mm:ss");
  140. }
  141. if (!string.IsNullOrWhiteSpace(this.scbGoodsType.Text))
  142. {
  143. if (remarks != null)
  144. {
  145. remarks += "\r\n";
  146. }
  147. remarks += "产品类别: " + this.scbGoodsType.Text;
  148. }
  149. if (!string.IsNullOrWhiteSpace(this.scbGoods.Text))
  150. {
  151. if (remarks != null)
  152. {
  153. remarks += "\r\n";
  154. }
  155. remarks += "产品编码: " + this.scbGoods.Text;
  156. }
  157. string status = null;
  158. if (this.chkStatus1.Checked)
  159. {
  160. if (status == null)
  161. {
  162. status = "在库";
  163. }
  164. else
  165. {
  166. status += ", 在库";
  167. }
  168. }
  169. if (this.chkStatus2.Checked)
  170. {
  171. if (status == null)
  172. {
  173. status += "在产";
  174. }
  175. else
  176. {
  177. status += ", 在产";
  178. }
  179. }
  180. if (this.chkStatus3.Checked)
  181. {
  182. if (status == null)
  183. {
  184. status = "待产";
  185. }
  186. else
  187. {
  188. status += ", 待产";
  189. }
  190. }
  191. if (status != null)
  192. {
  193. if (remarks != null)
  194. {
  195. remarks += "\r\n";
  196. }
  197. remarks += "模具状态: " + status;
  198. }
  199. this.txtRemarks.Text = remarks;
  200. }
  201. /// <summary>
  202. /// 保存按钮事件
  203. /// </summary>
  204. /// <param name="sender"></param>
  205. /// <param name="e"></param>
  206. private void btnSave_Click(object sender, EventArgs e)
  207. {
  208. try
  209. {
  210. // 自动生成的备注会超长
  211. if (this.txtRemarks.Text.Length > 500)
  212. {
  213. MessageBox.Show("备注的内容超过最大长度【500个字】,请重新输入", this.Text
  214. , MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  215. this.txtRemarks.Focus();
  216. return;
  217. }
  218. string status = null;
  219. if (_checkedID == 0)
  220. {
  221. if (this.chkStatus1.Checked)
  222. {
  223. if (status == null)
  224. {
  225. status = "1";
  226. }
  227. else
  228. {
  229. status += ",1";
  230. }
  231. }
  232. if (this.chkStatus2.Checked)
  233. {
  234. if (status == null)
  235. {
  236. status = "2";
  237. }
  238. else
  239. {
  240. status += ",2";
  241. }
  242. }
  243. if (this.chkStatus3.Checked)
  244. {
  245. if (status == null)
  246. {
  247. status = "3";
  248. }
  249. else
  250. {
  251. status += ",3";
  252. }
  253. }
  254. if (status == null)
  255. {
  256. MessageBox.Show("最少选择一个模具状态", this.Text
  257. , MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  258. this.chkStatus1.Focus();
  259. return;
  260. }
  261. }
  262. // 删除空白行
  263. DataRow[] rows = this._dtGrid.Select("userid is null");
  264. if (rows != null && rows.Length > 0)
  265. {
  266. foreach (DataRow item in rows)
  267. {
  268. item.Delete();
  269. }
  270. }
  271. ClientRequestEntity cre = new ClientRequestEntity();
  272. cre.NameSpace = "FPC1101";
  273. cre.Name = "SaveMouldChecked";
  274. cre.Data = new DataSet();
  275. cre.Data.Merge(this._dtGrid);
  276. cre.Properties["CheckedID"] = _checkedID;
  277. cre.Properties["CheckedName"] = this.txtInvoiceName.Text.Trim();
  278. cre.Properties["Remarks"] = this.txtRemarks.Text.Trim();
  279. if (_checkedID == 0)
  280. {
  281. cre.Properties["GoodsCodeList"] = this.scbGoods.CheckedPKMember;
  282. cre.Properties["GoodsTypeCode"] = scbGoodsType.SearchedValue + "";
  283. if (chkDateTime.Checked)
  284. {
  285. cre.Properties["DateBegin"] = this.dtpDateStart.Value;
  286. cre.Properties["DateEnd"] = this.dtpDateEnd.Value;
  287. }
  288. }
  289. cre.Properties["MouldStatus"] = status;
  290. ServiceResultEntity returnValue = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
  291. {
  292. return PCModuleProxyNew.Service.HandleRequest(cre);
  293. }));
  294. if (returnValue != null && returnValue.Status == Constant.ServiceResultStatus.Success)
  295. {
  296. // 提示信息
  297. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, this.Text, "保存"),
  298. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  299. this.DialogResult = DialogResult.OK;
  300. }
  301. else
  302. {
  303. // 提示信息
  304. MessageBox.Show("保存失败",
  305. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  306. }
  307. }
  308. catch (Exception ex)
  309. {
  310. // 对异常进行共通处理
  311. ExceptionManager.HandleEventException(this.ToString(),
  312. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  313. }
  314. }
  315. /// <summary>
  316. ///
  317. /// </summary>
  318. /// <param name="sender"></param>
  319. /// <param name="e"></param>
  320. private void chkStatus1_CheckedChanged(object sender, EventArgs e)
  321. {
  322. dkProcedureSearchBox_TextChanged(null, null);
  323. }
  324. /// <summary>
  325. /// 完成复选框改变事件
  326. /// </summary>
  327. /// <param name="sender"></param>
  328. /// <param name="e"></param>
  329. private void chkDateTime_CheckedChanged(object sender, EventArgs e)
  330. {
  331. dtpDateStart.Enabled = chkDateTime.Checked;
  332. dtpDateEnd.Enabled = chkDateTime.Checked;
  333. dkProcedureSearchBox_TextChanged(sender, e);
  334. }
  335. /// <summary>
  336. ///
  337. /// </summary>
  338. /// <param name="sender"></param>
  339. /// <param name="e"></param>
  340. private void dgvFunctionUsers_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
  341. {
  342. try
  343. {
  344. if (this.dgvFunctionUsers.Rows.Count <= 1)
  345. {
  346. return;
  347. }
  348. DataGridViewColumn columnItem = this.dgvFunctionUsers.Columns[e.ColumnIndex];
  349. if ("UserCode".Equals(columnItem.Name))
  350. {
  351. _userCodeValue = this.dgvFunctionUsers.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
  352. }
  353. }
  354. catch (Exception ex)
  355. {
  356. // 对异常进行共通处理
  357. ExceptionManager.HandleEventException(this.ToString(),
  358. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  359. }
  360. }
  361. /// <summary>
  362. ///
  363. /// </summary>
  364. /// <param name="sender"></param>
  365. /// <param name="e"></param>
  366. private void dgvFunctionUsers_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
  367. {
  368. //if (e.Row.Index != -1)
  369. //{
  370. // DataTable dt = this.dgvFunctionUsers.DataSource as DataTable;
  371. // string userID = dt.Rows[e.Row.Index]["userID"].ToString();
  372. // DataRow[] isR = this._dtGrid.Select("UserID=" + userID);
  373. // isR[0].Delete();
  374. // this.btnSave.Enabled = true;
  375. //}
  376. }
  377. /// <summary>
  378. ///
  379. /// </summary>
  380. /// <param name="sender"></param>
  381. /// <param name="e"></param>
  382. private void dgvFunctionUsers_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  383. {
  384. try
  385. {
  386. if (this.dgvFunctionUsers.Rows.Count <= 1 || !_ShowFlag)
  387. {
  388. return;
  389. }
  390. DataGridViewRow rowItem = this.dgvFunctionUsers.Rows[e.RowIndex];
  391. DataGridViewColumn columnItem = this.dgvFunctionUsers.Columns[e.ColumnIndex];
  392. //string OrganizationName = this.dgvFunctionUsers.Rows[e.RowIndex].Cells["OrganizationName"].Value.ToString();
  393. // 用编号获取产品信息
  394. if ("UserCode".Equals(columnItem.Name))
  395. {
  396. _ShowFlag = false;
  397. DataTable dtNew = FormUtility.BindUserRowDataSource(this.dgvFunctionUsers,
  398. e.RowIndex, columnItem.Name, _userCodeValue);
  399. if (dtNew != null && dtNew.Rows.Count > 0)
  400. {
  401. foreach (DataRow r in dtNew.Rows)
  402. {
  403. DataRow[] isR = _dtGrid.Select("UserID=" + r["UserID"]);
  404. if (isR.Length == 0)
  405. {
  406. DataRow drNew = _dtGrid.NewRow();
  407. drNew["UserID"] = r["UserID"];
  408. drNew["UserCode"] = r["UserCode"];
  409. drNew["UserName"] = r["UserName"];
  410. _dtGrid.Rows.Add(drNew);
  411. dgvFunctionUsers.Rows[e.RowIndex].Cells["UserCode"].ReadOnly = true;
  412. // BindReadOnly();
  413. }
  414. }
  415. }
  416. this.btnSave.Enabled = DataJudge.IsChange(_dtGrid);
  417. //this.dgvFunctionUsers.Rows[e.RowIndex].Cells["FunctionCode"].Value = this._functionCode;
  418. //this._dtDataGird.AcceptChanges();
  419. // 设置可输入单元格的颜色
  420. this.dgvFunctionUsers.IsSetInputColumnsColor = true;
  421. }
  422. _ShowFlag = true;
  423. }
  424. catch (Exception ex)
  425. {
  426. //_ShowFlag = true;
  427. // 对异常进行共通处理
  428. ExceptionManager.HandleEventException(this.ToString(),
  429. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  430. }
  431. }
  432. #endregion
  433. }
  434. }