F_MST_0408.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. /*******************************************************************************
  2. * Copyright(c) 2014 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_0408.cs
  5. * 2.功能描述:产品分级
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 任海 2014/10/18 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Windows.Forms;
  13. using Dongke.IBOSS.PRD.Client.CommonModule;
  14. using Dongke.IBOSS.PRD.Basics.BaseControls;
  15. using Dongke.IBOSS.PRD.Basics.Library;
  16. using Dongke.IBOSS.PRD.Basics.BaseResources;
  17. using Dongke.IBOSS.PRD.Client.DataModels;
  18. using Dongke.IBOSS.PRD.WCF.Proxys;
  19. namespace Dongke.IBOSS.PRD.Client.SystemModule
  20. {
  21. /// <summary>
  22. /// 产品分级
  23. /// </summary>
  24. public partial class F_MST_0408 : FormBase
  25. {
  26. #region 成员变量
  27. // 窗体的单例模式
  28. private static F_MST_0408 _instance;
  29. // 字节变量
  30. private byte _distinguish = 1;
  31. #endregion
  32. #region 构造函数
  33. /// <summary>
  34. /// 构造函数
  35. /// </summary>
  36. public F_MST_0408()
  37. {
  38. InitializeComponent();
  39. // 窗口标题
  40. this.Text = FormTitles.F_MST_0408;
  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_0408 Instance
  51. {
  52. get
  53. {
  54. if (_instance == null)
  55. {
  56. _instance = new F_MST_0408();
  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_0408_Load(object sender, EventArgs e)
  69. {
  70. try
  71. {
  72. // 设置datagridview不自动创建列
  73. this.dgvGoodsLevel.AutoGenerateColumns = false;
  74. // 设置datagridview不自动创建行
  75. this.dgvGoodsLevel.AllowUserToAddRows = false;
  76. //获取数据
  77. base.DataSource = (DataSet)DoAsync(new BaseAsyncMethod(GetGoodsLevelData));
  78. //绑定数据
  79. this.dgvGoodsLevel.DataSource = base.DataSource.Tables[0];
  80. this.btnSave.Enabled = false;
  81. this.SetCellColor();
  82. //设置可输入单元格颜色
  83. this.dgvGoodsLevel.IsSetInputColumnsColor = true;
  84. //权限
  85. FormPermissionManager.FormPermissionControl(this.Name, this,
  86. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  87. this.dgvGoodsLevel.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
  88. }
  89. catch (Exception ex)
  90. {
  91. // 对异常进行共通处理
  92. ExceptionManager.HandleEventException(this.ToString(),
  93. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  94. }
  95. }
  96. /// <summary>
  97. /// 窗体关闭后,释放单例资源
  98. /// </summary>
  99. /// <param name="sender"></param>
  100. /// <param name="e"></param>
  101. private void F_MST_0408_FormClosed(object sender, FormClosedEventArgs e)
  102. {
  103. _instance = null;
  104. }
  105. /// <summary>
  106. /// 点击关闭按钮
  107. /// </summary>
  108. /// <param name="sender"></param>
  109. /// <param name="e"></param>
  110. private void btnCancel_Click(object sender, EventArgs e)
  111. {
  112. this.Close();
  113. }
  114. /// <summary>
  115. /// 行校验
  116. /// </summary>
  117. /// <param name="sender"></param>
  118. /// <param name="e"></param>
  119. private void dgvGoodsLevel_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
  120. {
  121. try
  122. {
  123. // 按Esc键时不校验
  124. if (!dgvGoodsLevel.IsCurrentRowDirty)
  125. {
  126. this.dgvGoodsLevel.IsSetInputColumnsColor = true;
  127. return;
  128. }
  129. if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name))
  130. {
  131. // 清除单元格的错误消息
  132. this.dgvGoodsLevel.CurrentRow.ErrorText = string.Empty;
  133. return;
  134. }
  135. DataGridViewRow row = dgvGoodsLevel.CurrentRow;
  136. if (!row.IsNewRow)
  137. {
  138. // 判断产品分级名称不能为空
  139. if (row.Cells["GoodsLevelName"].Value == null
  140. || string.IsNullOrEmpty(row.Cells["GoodsLevelName"].Value + string.Empty))
  141. {
  142. // 单元格的错误消息
  143. this.dgvGoodsLevel.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "产品分级名称");
  144. e.Cancel = true;
  145. this.btnSave.Enabled = false;
  146. return;
  147. }
  148. // 清除单元格的错误消息
  149. this.dgvGoodsLevel.CurrentRow.ErrorText = string.Empty;
  150. }
  151. }
  152. catch (Exception ex)
  153. {
  154. // 对异常进行共通处理
  155. ExceptionManager.HandleEventException(this.ToString(),
  156. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  157. }
  158. }
  159. /// <summary>
  160. /// 根据数据是否变化,设置保存按钮的可用状态
  161. /// </summary>
  162. /// <param name="sender"></param>
  163. /// <param name="e"></param>
  164. private void dgvGoodsLevel_RowValidated(object sender, DataGridViewCellEventArgs e)
  165. {
  166. try
  167. {
  168. this.SetSaveBtnStatus();
  169. }
  170. catch (Exception ex)
  171. {
  172. // 对异常进行共通处理
  173. ExceptionManager.HandleEventException(this.ToString(),
  174. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  175. }
  176. }
  177. /// <summary>
  178. /// 点击右上角关闭按钮
  179. /// </summary>
  180. /// <param name="sender"></param>
  181. /// <param name="e"></param>
  182. private void F_MST_0408_FormClosing(object sender, FormClosingEventArgs e)
  183. {
  184. try
  185. {
  186. // 关闭的时候需要判断是否有数据变化
  187. if (DataJudge.IsChange((DataTable)this.dgvGoodsLevel.DataSource))
  188. {
  189. DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
  190. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  191. // 保存改变的数据
  192. if (dialogResult == DialogResult.Yes)
  193. {
  194. DataGridViewRow row = dgvGoodsLevel.CurrentRow;
  195. if (!row.IsNewRow)
  196. {
  197. // 判断产品分级名称不能为空
  198. if (row.Cells["GoodsLevelName"].Value == null
  199. || string.IsNullOrEmpty(row.Cells["GoodsLevelName"].Value + string.Empty))
  200. {
  201. // 错误消息
  202. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "产品分级名称"),
  203. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  204. e.Cancel = true;
  205. this.btnSave.Enabled = false;
  206. return;
  207. }
  208. }
  209. // 异步处理
  210. object result = DoAsync(new BaseAsyncMethod(SaveGoodsLevelData));
  211. }
  212. else if (dialogResult == DialogResult.Cancel)
  213. {
  214. e.Cancel = true;
  215. }
  216. }
  217. }
  218. catch (Exception ex)
  219. {
  220. // 对异常进行共通处理
  221. ExceptionManager.HandleEventException(this.ToString(),
  222. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  223. }
  224. }
  225. /// <summary>
  226. /// 单元格编辑开始时事件
  227. /// </summary>
  228. /// <param name="sender"></param>
  229. /// <param name="e"></param>
  230. private void dgvGoodsLevel_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
  231. {
  232. //判断单元checkbox控件是否选中
  233. if (e.ColumnIndex == Constant.INT_IS_FIVE && e.RowIndex != -Constant.INT_IS_ONE)
  234. {
  235. string value = this.dgvGoodsLevel.Rows[this.dgvGoodsLevel.CurrentCell.RowIndex].Cells["IsSemiFinishedEx"].Value.ToString();
  236. //如果未选中不可编辑,取消事件
  237. if (value == Constant.INT_IS_ZERO.ToString())
  238. {
  239. e.Cancel = true;
  240. }
  241. }
  242. if (e.ColumnIndex == Constant.INT_IS_SEVEN && e.RowIndex != -Constant.INT_IS_ONE)
  243. {
  244. string value = this.dgvGoodsLevel.Rows[this.dgvGoodsLevel.CurrentCell.RowIndex].Cells["IsFinishedEx"].Value.ToString();
  245. if (value == Constant.INT_IS_ZERO.ToString())
  246. {
  247. e.Cancel = true;
  248. }
  249. }
  250. if (e.ColumnIndex == Constant.INT_IS_ELEVEN && e.RowIndex != -Constant.INT_IS_ONE)
  251. {
  252. string value = this.dgvGoodsLevel.Rows[this.dgvGoodsLevel.CurrentCell.RowIndex].Cells["CanDisable"].Value.ToString();
  253. if (value == Constant.INT_IS_ZERO.ToString())
  254. {
  255. e.Cancel = true;
  256. }
  257. }
  258. }
  259. /// <summary>
  260. /// 保存产品分级数据
  261. /// </summary>
  262. /// <param name="sender"></param>
  263. /// <param name="e"></param>
  264. private void btnSave_Click(object sender, EventArgs e)
  265. {
  266. try
  267. {
  268. // 异步处理
  269. this.btnSave.Enabled = false;
  270. this.btnCancel.Enabled = false;
  271. int result = (int)DoAsync(new BaseAsyncMethod(SaveGoodsLevelData));
  272. this.btnSave.Enabled = true;
  273. this.btnCancel.Enabled = true;
  274. // 产品分级保存成功
  275. if (result == Constant.INT_IS_TWO)
  276. {
  277. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品分级", "保存"),
  278. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  279. // 加载产品分级数据
  280. base.DataSource = (DataSet)DoAsync(new BaseAsyncMethod(GetGoodsLevelData));
  281. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  282. {
  283. dgvGoodsLevel.DataSource = this.DataSource.Tables[0];
  284. }
  285. this.btnSave.Enabled = false;
  286. }
  287. else
  288. {
  289. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品分级", "保存"),
  290. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  291. }
  292. this.SetCellColor();
  293. this.dgvGoodsLevel.IsSetInputColumnsColor = true;
  294. }
  295. catch (Exception ex)
  296. {
  297. this.btnSave.Enabled = true;
  298. this.btnCancel.Enabled = true;
  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 chkDisplayDisabledData_CheckedChanged(object sender, EventArgs e)
  310. {
  311. try
  312. {
  313. base.DataSource = (DataSet)DoAsync(new BaseAsyncMethod(GetGoodsLevelData));
  314. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  315. {
  316. dgvGoodsLevel.DataSource = base.DataSource.Tables[0];
  317. }
  318. this.dgvGoodsLevel.IsSetInputColumnsColor = true;
  319. this.btnSave.Enabled = true;
  320. }
  321. catch (Exception ex)
  322. {
  323. // 对异常进行共通处理
  324. ExceptionManager.HandleEventException(this.ToString(),
  325. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  326. }
  327. }
  328. /// <summary>
  329. /// 设置排序时列表的颜色
  330. /// </summary>
  331. private void dgvGoodsLevel_Sorted(object sender, EventArgs e)
  332. {
  333. SetCellColor();
  334. this.dgvGoodsLevel.IsSetInputColumnsColor = true;
  335. this.dgvGoodsLevel.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
  336. }
  337. #endregion
  338. #region 私有方法
  339. /// <summary>
  340. /// 加载产品分级管理数据
  341. /// </summary>
  342. /// <returns></returns>
  343. private DataSet GetGoodsLevelData()
  344. {
  345. try
  346. {
  347. return SystemModuleProxy.Service.GetGoodsLevelData(_distinguish);
  348. }
  349. catch (Exception ex)
  350. {
  351. throw ex;
  352. }
  353. }
  354. /// <summary>
  355. /// 保存产品分级数据
  356. /// </summary>
  357. /// <returns>是否成功</returns>
  358. ///
  359. private object SaveGoodsLevelData()
  360. {
  361. try
  362. {
  363. DataTable datatGoodsLevelData = (DataTable)this.dgvGoodsLevel.DataSource;
  364. int result = SystemModuleProxy.Service.SaveGoodsLevelData(datatGoodsLevelData);
  365. return result;
  366. }
  367. catch (Exception ex)
  368. {
  369. throw ex;
  370. }
  371. }
  372. /// <summary>
  373. /// 设置保存按钮的可用状态
  374. /// </summary>
  375. private void SetSaveBtnStatus()
  376. {
  377. if (DataJudge.IsChange((DataTable)this.dgvGoodsLevel.DataSource))
  378. {
  379. this.btnSave.Enabled = true;
  380. }
  381. else
  382. {
  383. this.btnSave.Enabled = false;
  384. }
  385. }
  386. /// <summary>
  387. /// 设置单元格输入状态
  388. /// </summary>
  389. private void SetCellColor()
  390. {
  391. foreach (DataGridViewRow gvrFor in this.dgvGoodsLevel.Rows)
  392. {
  393. //判断可编辑单元格的颜色
  394. if (gvrFor.Cells["IsSemiFinishedEx"].Value.ToString() == Constant.INT_IS_ONE.ToString())
  395. {
  396. gvrFor.Cells["SFEDisplayNo"].ReadOnly = false;
  397. }
  398. else
  399. {
  400. gvrFor.Cells["SFEDisplayNo"].ReadOnly = true;
  401. }
  402. if (gvrFor.Cells["IsFinishedEx"].Value.ToString() == Constant.INT_IS_ONE.ToString())
  403. {
  404. gvrFor.Cells["FEDisplayNo"].ReadOnly = false;
  405. }
  406. else
  407. {
  408. gvrFor.Cells["FEDisplayNo"].ReadOnly = true;
  409. }
  410. if (gvrFor.Cells["GoodsLevelTypeID"].Value.ToString() == Constant.INT_IS_TWO.ToString()
  411. || gvrFor.Cells["GoodsLevelTypeID"].Value.ToString() == Constant.INT_IS_FIVE.ToString()
  412. || gvrFor.Cells["GoodsLevelTypeID"].Value.ToString() == Constant.INT_IS_SIX.ToString())
  413. {
  414. gvrFor.Cells["ValueFlag"].ReadOnly = false;
  415. }
  416. else
  417. {
  418. gvrFor.Cells["ValueFlag"].ReadOnly = true;
  419. }
  420. }
  421. }
  422. #endregion
  423. }
  424. }