F_PC_1102.cs 13 KB

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