F_RPT_01040501.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /*******************************************************************************
  2. * Copyright(c) 2014 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_RPT_01040501.cs
  5. * 2.功能描述:单值名
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2015/11/12 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.ReportModule
  21. {
  22. /// <summary>
  23. /// 单值名
  24. /// </summary>
  25. public partial class F_RPT_01040501 : FormBase
  26. {
  27. #region 成员变量
  28. // 窗体的单例模式
  29. private static F_RPT_01040501 _instance;
  30. // 工种数据源
  31. private DataTable _dtSourse;
  32. #endregion
  33. #region 构造函数
  34. /// <summary>
  35. /// 构造函数
  36. /// </summary>
  37. public F_RPT_01040501()
  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_RPT_01040501 Instance
  50. {
  51. get
  52. {
  53. if (_instance == null)
  54. {
  55. _instance = new F_RPT_01040501();
  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_RPT_01040501_Load(object sender, System.EventArgs e)
  68. {
  69. try
  70. {
  71. // 设置datagridview不自动创建列
  72. this.dgvData.AutoGenerateColumns = false;
  73. this.dgvData.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
  74. // 加载商标管理数据
  75. this.GetAllData();
  76. this.RefreshDataGridViewData();
  77. }
  78. catch (Exception ex)
  79. {
  80. // 对异常进行共通处理
  81. ExceptionManager.HandleEventException(this.ToString(),
  82. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  83. }
  84. }
  85. /// <summary>
  86. /// 点击右上角关闭按钮
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. private void F_RPT_01040501_FormClosing(object sender, FormClosingEventArgs e)
  91. {
  92. try
  93. {
  94. // 关闭的时候需要判断是否有数据变化
  95. if (DataJudge.IsChange((DataTable)this.dgvData.DataSource))
  96. {
  97. DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
  98. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  99. // 保存改变的数据
  100. if (dialogResult == DialogResult.Yes)
  101. {
  102. DataGridViewRow row = dgvData.CurrentRow;
  103. if (!row.IsNewRow)
  104. {
  105. // 判断商标编码不能为空
  106. if (row.Cells["name"].Value == null
  107. || string.IsNullOrEmpty(row.Cells["name"].Value + string.Empty))
  108. {
  109. // 错误消息
  110. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "单值名称"),
  111. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  112. e.Cancel = true;
  113. this.btnSave.Enabled = false;
  114. return;
  115. }
  116. }
  117. // 异步处理
  118. object result = DoAsync(new BaseAsyncMethod(SaveData));
  119. this.chkDisplayDisabledData.Enabled = true;
  120. // 如果保存出错,不关闭窗体
  121. if (Convert.ToInt32(result) > Constant.INT_IS_ZERO)
  122. {
  123. e.Cancel = true;
  124. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "单值名", "保存"),
  125. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  126. this.btnSave.Enabled = false;
  127. this._dtSourse.AcceptChanges();
  128. }
  129. else
  130. {
  131. e.Cancel = true;
  132. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "单值名", "保存"),
  133. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  134. }
  135. }
  136. else if (dialogResult == DialogResult.Cancel)
  137. {
  138. e.Cancel = true;
  139. }
  140. }
  141. }
  142. catch (Exception ex)
  143. {
  144. // 对异常进行共通处理
  145. ExceptionManager.HandleEventException(this.ToString(),
  146. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  147. }
  148. }
  149. /// <summary>
  150. /// 窗体关闭后,释放单例资源
  151. /// </summary>
  152. /// <param name="sender"></param>
  153. /// <param name="e"></param>
  154. private void F_RPT_01040501_FormClosed(object sender, FormClosedEventArgs e)
  155. {
  156. _instance = null;
  157. }
  158. /// <summary>
  159. /// 选中新行时,设置默认值
  160. /// </summary>
  161. /// <param name="sender"></param>
  162. /// <param name="e"></param>
  163. private void dgvDataJobs_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
  164. {
  165. // 设置有效属性为选中状态
  166. e.Row.Cells["valueflag"].Value = "1";
  167. e.Row.Cells["DisplayNo"].Value = e.Row.Index + 1;
  168. }
  169. /// <summary>
  170. /// 根据数据是否变化,设置保存按钮的可用状态
  171. /// </summary>
  172. /// <param name="sender"></param>
  173. /// <param name="e"></param>
  174. private void dgvDataJobs_CellValidated(object sender, DataGridViewCellEventArgs e)
  175. {
  176. try
  177. {
  178. this.SetSaveBtnStatus();
  179. }
  180. catch (Exception ex)
  181. {
  182. // 对异常进行共通处理
  183. ExceptionManager.HandleEventException(this.ToString(),
  184. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  185. }
  186. }
  187. /// <summary>
  188. /// 行校验
  189. /// </summary>
  190. /// <param name="sender"></param>
  191. /// <param name="e"></param>
  192. private void dgvDataJobs_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
  193. {
  194. try
  195. {
  196. // 按Esc键时不校验
  197. if (!dgvData.IsCurrentRowDirty)
  198. {
  199. this.dgvData.IsSetInputColumnsColor = true;
  200. return;
  201. }
  202. if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name))
  203. {
  204. // 清除单元格的错误消息
  205. this.dgvData.CurrentRow.ErrorText = string.Empty;
  206. return;
  207. }
  208. DataGridViewRow row = dgvData.CurrentRow;
  209. if (!row.IsNewRow)
  210. {
  211. // 判断商标编码能为空
  212. if (row.Cells["name"].Value == null
  213. || string.IsNullOrEmpty(row.Cells["name"].Value + string.Empty))
  214. {
  215. // 单元格的错误消息
  216. this.dgvData.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "单值名称");
  217. e.Cancel = true;
  218. this.btnSave.Enabled = false;
  219. return;
  220. }
  221. // 清除单元格的错误消息
  222. this.dgvData.CurrentRow.ErrorText = string.Empty;
  223. }
  224. }
  225. catch (Exception ex)
  226. {
  227. // 对异常进行共通处理
  228. ExceptionManager.HandleEventException(this.ToString(),
  229. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  230. }
  231. }
  232. /// <summary>
  233. /// 根据数据是否变化,设置保存按钮的可用状态
  234. /// </summary>
  235. /// <param name="sender"></param>
  236. /// <param name="e"></param>
  237. private void dgvDataJobs_RowValidated(object sender, DataGridViewCellEventArgs e)
  238. {
  239. try
  240. {
  241. this.SetSaveBtnStatus();
  242. }
  243. catch (Exception ex)
  244. {
  245. // 对异常进行共通处理
  246. ExceptionManager.HandleEventException(this.ToString(),
  247. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  248. }
  249. }
  250. /// <summary>
  251. /// 根据是否选中停用数据,加载数据
  252. /// </summary>
  253. /// <param name="sender"></param>
  254. /// <param name="e"></param>
  255. private void chkDisplayDisabledData_CheckedChanged(object sender, EventArgs e)
  256. {
  257. try
  258. {
  259. this.RefreshDataGridViewData();
  260. this.SetSaveBtnStatus();
  261. this.dgvData.IsSetInputColumnsColor = true;
  262. }
  263. catch (Exception ex)
  264. {
  265. // 对异常进行共通处理
  266. ExceptionManager.HandleEventException(this.ToString(),
  267. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  268. }
  269. }
  270. /// <summary>
  271. /// 单元格输入时,给自动生成的行设置颜色
  272. /// </summary>
  273. /// <param name="sender"></param>
  274. /// <param name="e"></param>
  275. private void dgvDataJobs_UserAddedRow(object sender, DataGridViewRowEventArgs e)
  276. {
  277. this.dgvData.IsSetInputColumnsColor = true;
  278. }
  279. /// <summary>
  280. /// 删除
  281. /// </summary>
  282. /// <param name="sender"></param>
  283. /// <param name="e"></param>
  284. private void dgvData_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
  285. {
  286. try
  287. {
  288. DataRowView item = e.Row.DataBoundItem as DataRowView;
  289. if (item == null || item.Row.RowState !=DataRowState.Added)
  290. {
  291. e.Cancel = true;
  292. }
  293. }
  294. catch (Exception ex)
  295. {
  296. // 对异常进行共通处理
  297. ExceptionManager.HandleEventException(this.ToString(),
  298. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  299. }
  300. }
  301. /// <summary>
  302. /// 保存工种数据
  303. /// </summary>
  304. /// <param name="sender"></param>
  305. /// <param name="e"></param>
  306. private void btnSave_Click(object sender, EventArgs e)
  307. {
  308. try
  309. {
  310. int results = Conservation();
  311. if (results == Constant.INT_IS_ONE)
  312. {
  313. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "单值名"),
  314. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  315. this.btnSave.Enabled = false;
  316. return;
  317. }
  318. // 异步处理
  319. this.btnSave.Enabled = false;
  320. this.btnCancel.Enabled = false;
  321. int result = (int)DoAsync(new BaseAsyncMethod(SaveData));
  322. this.btnSave.Enabled = true;
  323. this.btnCancel.Enabled = true;
  324. this.chkDisplayDisabledData.Enabled = true;
  325. if (result == Constant.INT_IS_TWO)
  326. {
  327. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "单值名", "保存"),
  328. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  329. this._dtSourse.AcceptChanges();
  330. this.btnSave.Enabled = false;
  331. }
  332. this.dgvData.IsSetInputColumnsColor = true;
  333. }
  334. catch (Exception ex)
  335. {
  336. this.btnSave.Enabled = true;
  337. this.btnCancel.Enabled = true;
  338. // 对异常进行共通处理
  339. ExceptionManager.HandleEventException(this.ToString(),
  340. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  341. }
  342. }
  343. /// <summary>
  344. /// 设置排序时列表的颜色
  345. /// </summary>
  346. private void dgvDataJobs_Sorted(object sender, EventArgs e)
  347. {
  348. this.dgvData.IsSetInputColumnsColor = true;
  349. }
  350. /// <summary>
  351. /// 点击关闭按钮
  352. /// </summary>
  353. /// <param name="sender"></param>
  354. /// <param name="e"></param>
  355. private void btnCancel_Click(object sender, EventArgs e)
  356. {
  357. this.Close();
  358. }
  359. #endregion
  360. #region 私有方法
  361. /// <summary>
  362. /// 获取工种管理的全部数据
  363. /// </summary>
  364. /// <param name="sUserInfo">用户信息</param>
  365. /// <returns></returns>
  366. /// <remarks>
  367. /// 2014.10.30 任海 新建
  368. /// </remarks>
  369. private void GetAllData()
  370. {
  371. try
  372. {
  373. ClientRequestEntity cre = new ClientRequestEntity();
  374. cre.NameSpace = "R01";
  375. cre.Name = "R01040501Get";
  376. ServiceResultEntity result = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
  377. {
  378. return ReportModuleProxy.Service.DoRequest(cre);
  379. }));
  380. if (result.Data != null && result.Data.Tables.Count > 0)
  381. {
  382. this._dtSourse = result.Data.Tables[0];
  383. }
  384. }
  385. catch (Exception ex)
  386. {
  387. throw ex;
  388. }
  389. }
  390. /// <summary>
  391. /// 保存
  392. /// </summary>
  393. /// <param name="sUserInfo">用户信息</param>
  394. /// <returns></returns>
  395. /// <remarks>
  396. /// </remarks>
  397. private object SaveData()
  398. {
  399. try
  400. {
  401. ClientRequestEntity cre = new ClientRequestEntity();
  402. cre.NameSpace = "R01";
  403. cre.Name = "R01040501Set";
  404. if (this._dtSourse.DataSet != null)
  405. {
  406. cre.Data = this._dtSourse.DataSet;
  407. }
  408. else
  409. {
  410. cre.Data = new DataSet();
  411. cre.Data.Tables.Add(this._dtSourse);
  412. }
  413. ServiceResultEntity result = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
  414. {
  415. return ReportModuleProxy.Service.DoRequest(cre);
  416. }));
  417. this._dtSourse.AcceptChanges();
  418. return 2;
  419. }
  420. catch (Exception ex)
  421. {
  422. throw ex;
  423. }
  424. }
  425. /// <summary>
  426. /// 得到工种信息
  427. /// </summary>
  428. /// <returns></returns>
  429. private void RefreshDataGridViewData()
  430. {
  431. try
  432. {
  433. if (this.chkDisplayDisabledData.Checked == false)
  434. {
  435. this._dtSourse.DefaultView.RowFilter = "ValueFlag=1";
  436. }
  437. else
  438. {
  439. this._dtSourse.DefaultView.RowFilter = null;
  440. }
  441. this.dgvData.DataSource = _dtSourse;
  442. this.dgvData.IsSetInputColumnsColor = true;
  443. this.btnSave.Enabled = false;
  444. }
  445. catch (Exception ex)
  446. {
  447. throw ex;
  448. }
  449. }
  450. /// <summary>
  451. /// 设置保存按钮的可用状态
  452. /// </summary>
  453. private void SetSaveBtnStatus()
  454. {
  455. if (DataJudge.IsChange((DataTable)this.dgvData.DataSource))
  456. {
  457. this.btnSave.Enabled = true;
  458. }
  459. else
  460. {
  461. this.btnSave.Enabled = false;
  462. }
  463. }
  464. /// <summary>
  465. /// 保存时单元格必输项不能为空
  466. /// </summary>
  467. private int Conservation()
  468. {
  469. int isConservation = Constant.INT_IS_ZERO;
  470. DataTable datatJobsData = (DataTable)this.dgvData.DataSource;
  471. foreach (DataRow drproductionData in datatJobsData.Rows)
  472. {
  473. if (drproductionData["name"].ToString() == string.Empty)
  474. {
  475. isConservation = Constant.INT_IS_ONE;
  476. break;
  477. }
  478. }
  479. return isConservation;
  480. }
  481. #endregion
  482. }
  483. }