F_MST_0412.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /*******************************************************************************
  2. * Copyright(c) 2014 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_0412.cs
  5. * 2.功能描述:条码打印机(PDA用)
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2017/03/27 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Windows.Forms;
  13. using Dongke.IBOSS.PRD.Basics.BaseResources;
  14. using Dongke.IBOSS.PRD.Basics.BaseControls;
  15. using Dongke.IBOSS.PRD.Client.CommonModule;
  16. using Dongke.IBOSS.PRD.Basics.Library;
  17. using Dongke.IBOSS.PRD.WCF.Proxys;
  18. using Dongke.IBOSS.PRD.Client.DataModels;
  19. using Dongke.IBOSS.PRD.WCF.DataModels;
  20. namespace Dongke.IBOSS.PRD.Client.SystemModule
  21. {
  22. public partial class F_MST_0412 : FormBase
  23. {
  24. #region 成员变量
  25. // 窗体的单例模式
  26. private static F_MST_0412 _instance;
  27. // 条码打印机数据源
  28. private DataTable _dtSourse;
  29. // 打印类型数据源 xuwei add 2019-11-21
  30. private DataTable _dtPrintType;
  31. #endregion
  32. #region 构造函数
  33. /// <summary>
  34. /// 构造函数
  35. /// </summary>
  36. public F_MST_0412()
  37. {
  38. InitializeComponent();
  39. // 窗口标题
  40. //this.Text = FormTitles.F_MST_0411;
  41. // 按钮
  42. this.btnSave.Text = ButtonText.BTN_SAVE;
  43. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  44. }
  45. #endregion
  46. #region 单例模式
  47. /// <summary>
  48. /// 单例模式,防止重复创建窗体
  49. /// </summary>
  50. public static F_MST_0412 Instance
  51. {
  52. get
  53. {
  54. if (_instance == null)
  55. {
  56. _instance = new F_MST_0412();
  57. }
  58. return _instance;
  59. }
  60. }
  61. #endregion
  62. #region 事件
  63. /// <summary>
  64. /// 窗体加载
  65. /// </summary>
  66. /// <param name="sender"></param>
  67. /// <param name="e"></param>
  68. private void F_MST_0411_Load(object sender, System.EventArgs e)
  69. {
  70. try
  71. {
  72. //xuwe add 2019-11-21 加载 打印类型
  73. ClientRequestEntity ptCre = new ClientRequestEntity();
  74. ptCre.NameSpace = "PrintInfo";
  75. ptCre.Name = "GetPrintType";
  76. _dtPrintType = SystemModuleProxy.Service.DoBarCodePrint(ptCre).Data.Tables[0];
  77. PrintType.DisplayMember = "PRINTTYPENAME";
  78. PrintType.ValueMember = "PRINTTYPEID";
  79. PrintType.DataSource = _dtPrintType;
  80. // 设置datagridview不自动创建列
  81. this.dgvPrinter.AutoGenerateColumns = false;
  82. // 加载打印机数据
  83. ClientRequestEntity cre = new ClientRequestEntity();
  84. cre.NameSpace = "MST0412";
  85. cre.Name = "GetAllBarcodePrinter";
  86. ServiceResultEntity sre = CommonModuleProxy.Service.DoRequest(cre);
  87. this._dtSourse = sre.Data.Tables[0];
  88. this.RefreshDataGridViewData();
  89. this.dgvPrinter.IsSetInputColumnsColor = true;
  90. //权限控制
  91. FormPermissionManager.FormPermissionControl(this.Name, this,
  92. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
  93. LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  94. this.dgvPrinter.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
  95. }
  96. catch (Exception ex)
  97. {
  98. // 对异常进行共通处理
  99. ExceptionManager.HandleEventException(this.ToString(),
  100. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  101. }
  102. }
  103. /// <summary>
  104. /// 点击右上角关闭按钮
  105. /// </summary>
  106. /// <param name="sender"></param>
  107. /// <param name="e"></param>
  108. private void F_MST_0411_FormClosing(object sender, FormClosingEventArgs e)
  109. {
  110. try
  111. {
  112. // 关闭的时候需要判断是否有数据变化
  113. if (DataJudge.IsChange((DataTable)this.dgvPrinter.DataSource))
  114. {
  115. DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
  116. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  117. // 保存改变的数据
  118. if (dialogResult == DialogResult.Yes)
  119. {
  120. DataGridViewRow row = dgvPrinter.CurrentRow;
  121. if (!row.IsNewRow)
  122. {
  123. // 判断产品缺陷名称不能为空
  124. if (row.Cells["PrinterName"].Value == null
  125. || string.IsNullOrEmpty(row.Cells["PrinterName"].Value + string.Empty))
  126. {
  127. // 单元格的错误消息
  128. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "打印机名"),
  129. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  130. e.Cancel = true;
  131. this.btnSave.Enabled = false;
  132. return;
  133. }
  134. }
  135. // 异步处理
  136. object result = DoAsync(new BaseAsyncMethod(SaveData));
  137. // 保存成功,不关闭窗体
  138. if (Convert.ToInt32(result) > Constant.INT_IS_ZERO)
  139. {
  140. e.Cancel = true;
  141. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, this.Text, "保存"),
  142. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  143. this.btnSave.Enabled = false;
  144. // 加载产品缺陷管理数据
  145. this._dtSourse.AcceptChanges();
  146. }
  147. else if (Convert.ToInt32(result) == -1)
  148. {
  149. e.Cancel = true;
  150. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "打印机名"),
  151. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  152. }
  153. else
  154. {
  155. e.Cancel = true;
  156. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, this.Text, "保存"),
  157. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  158. }
  159. }
  160. else if (dialogResult == DialogResult.Cancel)
  161. {
  162. e.Cancel = true;
  163. }
  164. }
  165. }
  166. catch (Exception ex)
  167. {
  168. // 对异常进行共通处理
  169. ExceptionManager.HandleEventException(this.ToString(),
  170. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  171. }
  172. }
  173. /// <summary>
  174. /// 窗体关闭后,释放单例资源
  175. /// </summary>
  176. /// <param name="sender"></param>
  177. /// <param name="e"></param>
  178. private void F_MST_0411_FormClosed(object sender, FormClosedEventArgs e)
  179. {
  180. _instance = null;
  181. }
  182. /// <summary>
  183. /// 选中新行时,设置默认值
  184. /// </summary>
  185. /// <param name="sender"></param>
  186. /// <param name="e"></param>
  187. private void dgvDataDefect_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
  188. {
  189. // 设置有效属性为选中状态
  190. e.Row.Cells["ValueFlag"].Value = Constant.INT_IS_ONE;
  191. e.Row.Cells["DisplayNo"].Value = e.Row.Index + 1;
  192. }
  193. /// <summary>
  194. /// 产品缺陷管理信息输入格式控制
  195. /// </summary>
  196. /// <param name="sender"></param>
  197. /// <param name="e"></param>
  198. private void dgvDataDefect_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
  199. {
  200. try
  201. {
  202. // 只对文本框做控制
  203. if (e.Control is DataGridViewTextBoxEditingControl)
  204. {
  205. DataGridViewTextBoxEditingControl EditingControl = (DataGridViewTextBoxEditingControl)e.Control;
  206. }
  207. }
  208. catch (Exception ex)
  209. {
  210. // 对异常进行共通处理
  211. ExceptionManager.HandleEventException(this.ToString(),
  212. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  213. }
  214. }
  215. /// <summary>
  216. /// 单元格验证,检查
  217. /// </summary>
  218. /// <param name="sender"></param>
  219. /// <param name="e"></param>
  220. private void dgvDataDefect_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
  221. {
  222. try
  223. {
  224. if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name))
  225. {
  226. return;
  227. }
  228. if (!dgvPrinter.CurrentRow.IsNewRow)
  229. {
  230. DataGridViewRow rowItem = dgvPrinter.Rows[e.RowIndex];
  231. DataGridViewColumn columnItem = dgvPrinter.Columns[e.ColumnIndex];
  232. object columnvalue = rowItem.Cells[columnItem.Name].EditedFormattedValue;
  233. // 打印机名
  234. if ("PrinterName".Equals(columnItem.Name))
  235. {
  236. if (columnvalue != null && !string.IsNullOrEmpty(columnvalue + string.Empty))
  237. {
  238. if (!Utility.IsUnique(columnvalue.ToString(),
  239. dgvPrinter.CurrentRow.Index, this.dgvPrinter, "PrinterName"))
  240. {
  241. // 单元格的错误消息
  242. this.dgvPrinter.CurrentRow.ErrorText = string.Format(
  243. Messages.MSG_CMN_W006, "打印机名");
  244. e.Cancel = true;
  245. this.btnSave.Enabled = false;
  246. return;
  247. }
  248. }
  249. }
  250. // 清除单元格的错误消息
  251. this.dgvPrinter.CurrentRow.ErrorText = string.Empty;
  252. }
  253. }
  254. catch (Exception ex)
  255. {
  256. // 对异常进行共通处理
  257. ExceptionManager.HandleEventException(this.ToString(),
  258. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  259. }
  260. }
  261. /// <summary>
  262. /// 根据数据是否变化,设置保存按钮的可用状态
  263. /// </summary>
  264. /// <param name="sender"></param>
  265. /// <param name="e"></param>
  266. private void dgvDataDefect_CellValidated(object sender, DataGridViewCellEventArgs e)
  267. {
  268. try
  269. {
  270. this.SetSaveBtnStatus();
  271. }
  272. catch (Exception ex)
  273. {
  274. // 对异常进行共通处理
  275. ExceptionManager.HandleEventException(this.ToString(),
  276. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  277. }
  278. }
  279. /// <summary>
  280. /// 行校验
  281. /// </summary>
  282. /// <param name="sender"></param>
  283. /// <param name="e"></param>
  284. private void dgvDataDefect_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
  285. {
  286. try
  287. {
  288. // 按Esc键时不校验
  289. if (!dgvPrinter.IsCurrentRowDirty)
  290. {
  291. this.dgvPrinter.IsSetInputColumnsColor = true;
  292. return;
  293. }
  294. if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name))
  295. {
  296. // 清除单元格的错误消息
  297. this.dgvPrinter.CurrentRow.ErrorText = string.Empty;
  298. return;
  299. }
  300. DataGridViewRow row = dgvPrinter.CurrentRow;
  301. if (!row.IsNewRow)
  302. {
  303. // 判断打印机名不能为空
  304. if (row.Cells["PrinterName"].Value == null
  305. || string.IsNullOrEmpty(row.Cells["PrinterName"].Value + string.Empty))
  306. {
  307. // 单元格的错误消息
  308. this.dgvPrinter.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "打印机名");
  309. e.Cancel = true;
  310. this.btnSave.Enabled = false;
  311. return;
  312. }
  313. // 判断打印类型不能为空 xuwei add 2019-11-26
  314. if (row.Cells["PrinterName"].Value == null
  315. || string.IsNullOrEmpty(row.Cells["PrintType"].Value + string.Empty))
  316. {
  317. // 单元格的错误消息
  318. this.dgvPrinter.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "打印类型");
  319. e.Cancel = true;
  320. this.btnSave.Enabled = false;
  321. return;
  322. }
  323. // 清除单元格的错误消息
  324. this.dgvPrinter.CurrentRow.ErrorText = string.Empty;
  325. }
  326. }
  327. catch (Exception ex)
  328. {
  329. // 对异常进行共通处理
  330. ExceptionManager.HandleEventException(this.ToString(),
  331. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  332. }
  333. }
  334. /// <summary>
  335. /// 根据数据是否变化,设置保存按钮的可用状态
  336. /// </summary>
  337. /// <param name="sender"></param>
  338. /// <param name="e"></param>
  339. private void dgvDataDefect_RowValidated(object sender, DataGridViewCellEventArgs e)
  340. {
  341. try
  342. {
  343. this.SetSaveBtnStatus();
  344. }
  345. catch (Exception ex)
  346. {
  347. // 对异常进行共通处理
  348. ExceptionManager.HandleEventException(this.ToString(),
  349. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  350. }
  351. }
  352. /// <summary>
  353. /// 根据是否选中停用数据,加载数据
  354. /// </summary>
  355. /// <param name="sender"></param>
  356. /// <param name="e"></param>
  357. private void chkDisplayDisabledData_CheckedChanged(object sender, EventArgs e)
  358. {
  359. try
  360. {
  361. this.RefreshDataGridViewData();
  362. this.SetSaveBtnStatus();
  363. this.dgvPrinter.IsSetInputColumnsColor = true;
  364. }
  365. catch (Exception ex)
  366. {
  367. // 对异常进行共通处理
  368. ExceptionManager.HandleEventException(this.ToString(),
  369. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  370. }
  371. }
  372. /// <summary>
  373. /// 单元格输入时,给自动生成的行设置颜色
  374. /// </summary>
  375. /// <param name="sender"></param>
  376. /// <param name="e"></param>
  377. private void dgvDataDefect_UserAddedRow(object sender, DataGridViewRowEventArgs e)
  378. {
  379. this.dgvPrinter.IsSetInputColumnsColor = true;
  380. }
  381. /// <summary>
  382. /// 设置排序时列表的颜色
  383. /// </summary>
  384. private void dgvDataDefect_Sorted(object sender, EventArgs e)
  385. {
  386. this.dgvPrinter.IsSetInputColumnsColor = true;
  387. }
  388. /// <summary>
  389. /// 保存
  390. /// </summary>
  391. /// <param name="sender"></param>
  392. /// <param name="e"></param>
  393. private void btnSave_Click(object sender, EventArgs e)
  394. {
  395. try
  396. {
  397. int results = Conservation();
  398. //判断单元格必输项不能为空
  399. if (results == Constant.INT_IS_TWO)
  400. {
  401. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "打印机名"),
  402. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  403. this.btnSave.Enabled = false;
  404. return;
  405. }
  406. // 异步处理
  407. this.btnSave.Enabled = false;
  408. this.btnCancel.Enabled = false;
  409. int result = (int)DoAsync(new BaseAsyncMethod(SaveData));
  410. this.btnSave.Enabled = true;
  411. this.btnCancel.Enabled = true;
  412. // 缺陷类别数据保存成功
  413. if (result == 1)
  414. {
  415. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, this.Text, "保存"),
  416. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  417. // 加载缺陷类别管理数据
  418. this._dtSourse.AcceptChanges();
  419. this.btnSave.Enabled = false;
  420. }
  421. else if (result == -1)
  422. {
  423. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "打印机名"),
  424. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  425. }
  426. else
  427. {
  428. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, this.Text, "保存"),
  429. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  430. }
  431. this.dgvPrinter.IsSetInputColumnsColor = true;
  432. }
  433. catch (Exception ex)
  434. {
  435. this.btnSave.Enabled = true;
  436. this.btnCancel.Enabled = true;
  437. // 对异常进行共通处理
  438. ExceptionManager.HandleEventException(this.ToString(),
  439. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  440. }
  441. }
  442. /// <summary>
  443. /// 点击关闭按钮
  444. /// </summary>
  445. /// <param name="sender"></param>
  446. /// <param name="e"></param>
  447. private void btnCancel_Click(object sender, EventArgs e)
  448. {
  449. this.Close();
  450. }
  451. #endregion
  452. #region 私有方法
  453. /// <summary>
  454. /// 得到显示数据
  455. /// </summary>
  456. /// <returns></returns>
  457. private void RefreshDataGridViewData()
  458. {
  459. try
  460. {
  461. if (this.chkDisplayDisabledData.Checked == false)
  462. {
  463. this._dtSourse.DefaultView.RowFilter = "ValueFlag=1";
  464. }
  465. else
  466. {
  467. this._dtSourse.DefaultView.RowFilter = null;
  468. }
  469. this.dgvPrinter.DataSource = _dtSourse;
  470. this.btnSave.Enabled = false;
  471. }
  472. catch (Exception ex)
  473. {
  474. throw ex;
  475. }
  476. }
  477. /// <summary>
  478. /// 保存数据
  479. /// </summary>
  480. /// <returns>是否成功</returns>
  481. private object SaveData()
  482. {
  483. try
  484. {
  485. // 获取当前数据源
  486. ClientRequestEntity cre = new ClientRequestEntity();
  487. cre.NameSpace = "MST0412";
  488. cre.Name = "SetBarcodePrinter";
  489. cre.Data = this._dtSourse.DataSet;
  490. ServiceResultEntity sre = CommonModuleProxy.Service.DoRequest(cre);
  491. if (sre.Status == Constant.ServiceResultStatus.Success)
  492. {
  493. return 1;
  494. }
  495. else if (sre.Status == Constant.ServiceResultStatus.DataDuplicated)
  496. {
  497. return -1;
  498. }
  499. else
  500. {
  501. return 0;
  502. }
  503. }
  504. catch (Exception ex)
  505. {
  506. throw ex;
  507. }
  508. }
  509. /// <summary>
  510. /// 设置保存按钮的可用状态
  511. /// </summary>
  512. private void SetSaveBtnStatus()
  513. {
  514. if (DataJudge.IsChange((DataTable)this.dgvPrinter.DataSource))
  515. {
  516. this.btnSave.Enabled = true;
  517. }
  518. else
  519. {
  520. this.btnSave.Enabled = false;
  521. }
  522. }
  523. /// <summary>
  524. /// 保存时单元格必输项不能为空
  525. /// </summary>
  526. private int Conservation()
  527. {
  528. int isConservation = Constant.INT_IS_ZERO;
  529. DataTable dataDefectData = (DataTable)this.dgvPrinter.DataSource;
  530. foreach (DataRow drproductionData in dataDefectData.Rows)
  531. {
  532. if (drproductionData["PrinterName"].ToString() == string.Empty)
  533. {
  534. isConservation = Constant.INT_IS_TWO;
  535. break;
  536. }
  537. }
  538. return isConservation;
  539. }
  540. #endregion
  541. }
  542. }