F_MST_0414.cs 20 KB

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