F_MST_1204.cs 21 KB

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