F_PAM_0203.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PAM_0203.cs
  5. * 2.功能描述:新建/编辑产品工价分类
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2015/08/18 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Windows.Forms;
  13. using Dongke.IBOSS.PRD.Basics.BaseControls;
  14. using Dongke.IBOSS.PRD.Basics.BaseResources;
  15. using Dongke.IBOSS.PRD.Basics.DockPanel;
  16. using Dongke.IBOSS.PRD.Client.CommonModule;
  17. using Dongke.IBOSS.PRD.Client.Controls;
  18. using Dongke.IBOSS.PRD.WCF.DataModels;
  19. using Dongke.IBOSS.PRD.WCF.Proxys;
  20. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  21. namespace Dongke.IBOSS.PRD.Client.PAMModule
  22. {
  23. /// <summary>
  24. /// 产品工价分类
  25. /// </summary>
  26. public partial class F_PAM_0203 : FormBase
  27. {
  28. #region 成员变量
  29. // 窗体模式ID
  30. private Constant.FormMode _formType;
  31. // 操作实体ID(方案)
  32. private int? _entityId;
  33. // 工序
  34. private DataSet _dsProcedure = new DataSet();
  35. // 工种编码值
  36. private string _GoodsCodeValue;
  37. private bool _ShowFlag = true;
  38. // 数据源
  39. DataTable dt = null;
  40. // 当前工资方案ID
  41. private int? _currentWagesTypeID = null;
  42. // 数据集
  43. DataTable dtAllData = null;
  44. #endregion
  45. #region 构造函数
  46. /// <summary>
  47. /// 窗体构造
  48. /// </summary>
  49. /// <param name="formType">窗体打开模式</param>
  50. /// <param name="entityId">操作实体ID</param>
  51. public F_PAM_0203(Constant.FormMode formType, int entityId)
  52. {
  53. InitializeComponent();
  54. this._formType = formType;
  55. this._entityId = entityId;
  56. // 窗体显示的Title
  57. if (this._formType == Constant.FormMode.Add)
  58. {
  59. this.Text = FormTitles.F_PAM_0203_ADD;
  60. }
  61. else if (this._formType == Constant.FormMode.Edit)
  62. {
  63. this.Text = FormTitles.F_PAM_0203_EDIT;
  64. }
  65. this.btnSave.Text = ButtonText.BTN_SAVE;
  66. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  67. }
  68. #endregion
  69. #region 事件处理
  70. /// <summary>
  71. /// 窗体加载
  72. /// </summary>
  73. /// <param name="sender"></param>
  74. /// <param name="e"></param>
  75. private void F_MST_0702_Load(object sender, EventArgs e)
  76. {
  77. try
  78. {
  79. this.dgvPayPlan.AutoGenerateColumns = false;
  80. this.dgvGoods.AutoGenerateColumns = false;
  81. //如果是修改,要绑定选中的信息
  82. if (this._formType == Constant.FormMode.Edit)
  83. {
  84. BindJobsData();//编辑工种数据源
  85. BindData();//绑定工资工种数据源
  86. }
  87. //如果是新建,选项默认值设定
  88. else if (this._formType == Constant.FormMode.Add)
  89. {
  90. //绑定全部的工资工种列表,用于过滤筛选
  91. DataSet dsProductionData = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  92. {
  93. return PAMModuleProxy.Service.GetGoodsWagesType("", "");
  94. }));
  95. BindData();//绑定工价分类数据源
  96. if (dsProductionData != null && dsProductionData.Tables[0].Rows.Count > 0)
  97. {
  98. this.dgvGoods.DataSource = dsProductionData.Tables[0];//新建时默认数据源
  99. }
  100. else
  101. {
  102. dt = new DataTable();
  103. dt.Columns.Add("GoodsID");
  104. dt.Columns.Add("GoodsCode");
  105. dt.Columns.Add("GoodsName");
  106. dt.Columns.Add("WagesTypeID");
  107. this.dgvGoods.DataSource = dt;//新建时默认数据源
  108. }
  109. dtAllData = this.dgvGoods.DataSource as DataTable;
  110. }
  111. }
  112. catch (Exception ex)
  113. {
  114. // 对异常进行共通处理
  115. ExceptionManager.HandleEventException(this.ToString(),
  116. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  117. }
  118. }
  119. /// <summary>
  120. /// 窗体关闭
  121. /// </summary>
  122. /// <param name="sender"></param>
  123. /// <param name="e"></param>
  124. private void btnCancel_Click(object sender, EventArgs e)
  125. {
  126. this.Close();
  127. }
  128. /// <summary>
  129. /// 窗体释放
  130. /// </summary>
  131. /// <param name="sender"></param>
  132. /// <param name="e"></param>
  133. private void F_MST_0702_FormClosed(object sender, FormClosedEventArgs e)
  134. {
  135. this.Dispose();
  136. }
  137. /// <summary>
  138. /// 数据统计工序变更
  139. /// </summary>
  140. /// <param name="sender"></param>
  141. /// <param name="e"></param>
  142. private void dgvGoods_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  143. {
  144. try
  145. {
  146. if (this.dgvGoods.Rows.Count <= 1)
  147. {
  148. return;
  149. }
  150. DataGridViewRow rowItem = this.dgvGoods.Rows[e.RowIndex];
  151. DataGridViewColumn columnItem = this.dgvGoods.Columns[e.ColumnIndex];
  152. // 用编号获取产品信息
  153. if ("GoodsCode".Equals(columnItem.Name))
  154. {
  155. string GoodsID = "";
  156. if (this.dgvGoods.Rows[e.RowIndex].Cells["GoodsID"].Value != null)
  157. {
  158. GoodsID = this.dgvGoods.Rows[e.RowIndex].Cells["GoodsID"].Value.ToString();
  159. }
  160. DataTable dtDataSource = FormUtility.BindGoodsRowDataSource(this.dgvGoods,
  161. e.RowIndex, columnItem.Name, _GoodsCodeValue);
  162. int row = e.RowIndex;
  163. // 返回多少行,进而给每个单元格传值,为的以后多个工资方案进行筛选
  164. if (dtDataSource != null && dtDataSource.Rows.Count > 0)
  165. {
  166. for (int i = 0; i < dtDataSource.Rows.Count; i++)
  167. {
  168. //this.dgvGoods.Rows[row].Cells["WagesTypeID1"].Value = this._currentWagesTypeID;
  169. //DataRow dr = this.dtAllData.NewRow();
  170. //dr["GoodsID"] = dtDataSource.Rows[i]["GoodsID"];
  171. //dr["GoodsCode"] = dtDataSource.Rows[i]["GoodsCode"];
  172. //dr["GoodsName"] = dtDataSource.Rows[i]["GoodsName"];
  173. //dr["WagesTypeID"] = this._currentWagesTypeID;
  174. //dtAllData.Rows.Add(dr);
  175. //row++;
  176. //如果存在数据集中,此列标记删除
  177. this.dgvGoods.Rows[row].Cells["WagesTypeID1"].Value = this._currentWagesTypeID;
  178. if (dtAllData != null && GoodsID != "")
  179. {
  180. DataRow[] drSel = dtAllData.Select(string.Format("WagesTypeID={0} and GoodsID={1}", this._currentWagesTypeID, GoodsID));
  181. if (drSel.Length > 0) //存在,需要更把此行删除
  182. {
  183. drSel[0].Delete();
  184. }
  185. }
  186. if (GoodsID == "") //新增的时候,是否存在相同的工种编码
  187. {
  188. //DataRow[] drSel = dtAllData.Select(string.Format("WagesTypeID={0} and GoodsID='{1}'", this._currentWagesTypeID, GoodsID));
  189. //if (drSel.Length == 0) //不存在,把此行添加进来
  190. //{
  191. DataRow dr = this.dtAllData.NewRow();
  192. dr["GoodsID"] = dtDataSource.Rows[i]["GoodsID"];
  193. dr["GoodsCode"] = dtDataSource.Rows[i]["GoodsCode"];
  194. dr["GoodsName"] = dtDataSource.Rows[i]["GoodsName"];
  195. dr["WagesTypeID"] = this._currentWagesTypeID;
  196. dtAllData.Rows.Add(dr);
  197. row++;
  198. // }
  199. }
  200. else
  201. {
  202. DataRow dr = this.dtAllData.NewRow();
  203. dr["GoodsID"] = dtDataSource.Rows[i]["GoodsID"];
  204. dr["GoodsCode"] = dtDataSource.Rows[i]["GoodsCode"];
  205. dr["GoodsName"] = dtDataSource.Rows[i]["GoodsName"];
  206. dr["WagesTypeID"] = this._currentWagesTypeID;
  207. dtAllData.Rows.Add(dr);
  208. row++;
  209. }
  210. }
  211. this.dgvGoods.Rows[e.RowIndex].Selected = true;
  212. }
  213. // 设置可输入单元格的颜色
  214. this.dgvGoods.IsSetInputColumnsColor = true;
  215. }
  216. }
  217. catch (Exception ex)
  218. {
  219. // 对异常进行共通处理
  220. ExceptionManager.HandleEventException(this.ToString(),
  221. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  222. }
  223. }
  224. /// <summary>
  225. /// 单元格开始编辑事件
  226. /// </summary>
  227. /// <param name="sender"></param>
  228. /// <param name="e"></param>
  229. private void dgvGoods_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
  230. {
  231. try
  232. {
  233. if (this.dgvGoods.Rows.Count <= 1 || !_ShowFlag)
  234. {
  235. return;
  236. }
  237. DataGridViewColumn columnItem = this.dgvGoods.Columns[e.ColumnIndex];
  238. if ("GoodsCode".Equals(columnItem.Name))
  239. {
  240. _ShowFlag = false;
  241. _GoodsCodeValue = this.dgvGoods.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
  242. }
  243. _ShowFlag = true;
  244. }
  245. catch (Exception ex)
  246. {
  247. _ShowFlag = true;
  248. // 对异常进行共通处理
  249. ExceptionManager.HandleEventException(this.ToString(),
  250. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  251. }
  252. }
  253. /// <summary>
  254. /// 选定项发生改变事件
  255. /// </summary>
  256. /// <param name="sender"></param>
  257. /// <param name="e"></param>
  258. private void dgvWagesType_SelectionChanged(object sender, EventArgs e)
  259. {
  260. try
  261. {
  262. if (this.dgvPayPlan.CurrentCell != null)
  263. {
  264. this._currentWagesTypeID = Convert.ToInt32(this.dgvPayPlan.Rows[this.dgvPayPlan.CurrentCell.RowIndex].Cells["WagesTypeID"].Value);
  265. //DataTable dtJobs = this.dgvGoods.DataSource as DataTable;
  266. DataTable dtJobs = this.dtAllData;
  267. if (dtJobs != null)
  268. {
  269. DataView dv = dtJobs.DefaultView;
  270. dv.RowFilter = "WagesTypeID=" + this._currentWagesTypeID;
  271. this.dgvGoods.DataSource = dv.ToTable();
  272. }
  273. //if (dtJobs != null && dtJobs.Rows.Count > 0)
  274. //{
  275. // DataRow[] dr = dtJobs.Select("WagesTypeID=" + this._currentWagesTypeID);
  276. // if (dr.Length > 0)
  277. // {
  278. // this.dgvGoods.DataSource = dr.CopyToDataTable();
  279. // }
  280. //}
  281. //else
  282. //{
  283. // if (dtJobs != null)
  284. // {
  285. // DataView dv = dtJobs.DefaultView;
  286. // dv.RowFilter = "WagesTypeID=" + this._currentWagesTypeID;
  287. // this.dgvGoods.DataSource = dv.ToTable();
  288. // }
  289. //}
  290. }
  291. }
  292. catch (Exception ex)
  293. {
  294. // 对异常进行共通处理
  295. ExceptionManager.HandleEventException(this.ToString(),
  296. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  297. }
  298. }
  299. /// <summary>
  300. /// 保存按钮事件
  301. /// </summary>
  302. /// <param name="sender"></param>
  303. /// <param name="e"></param>
  304. private void btnSave_Click_1(object sender, EventArgs e)
  305. {
  306. try
  307. {
  308. DataTable dt = this.dtAllData;// this.dgvGoods.DataSource as DataTable;
  309. if (dt == null)
  310. {
  311. return;
  312. }
  313. dt.TableName = "Table1";
  314. int returnValue = (int)DoAsync(new BaseAsyncMethod(() =>
  315. {
  316. return PAMModuleProxy.Service.SaveGoodsWagesTypeData(Convert.ToBoolean(this._entityId), dt);
  317. }));
  318. if (returnValue >= 0) //等于O,表示未修改数据,影响行为0
  319. {
  320. // 提示信息
  321. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, this.Text, "保存"),
  322. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  323. this.DialogResult = DialogResult.OK;
  324. }
  325. else if (returnValue == -3)
  326. {
  327. // 提示信息
  328. MessageBox.Show("产品编码不能重复",
  329. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  330. }
  331. }
  332. catch (Exception ex)
  333. {
  334. // 对异常进行共通处理
  335. ExceptionManager.HandleEventException(this.ToString(),
  336. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  337. }
  338. }
  339. #endregion
  340. #region 私有方法
  341. /// <summary>
  342. /// 绑定工价分类
  343. /// </summary>
  344. private void BindData()
  345. {
  346. try
  347. {
  348. DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  349. {
  350. return PAMModuleProxy.Service.GetAllWagesType();
  351. }));
  352. if (dsResultAccount != null && dsResultAccount.Tables[0].Rows.Count > 0)
  353. {
  354. if (this._formType == Constant.FormMode.Edit)
  355. {
  356. DataRow[] dr = dsResultAccount.Tables[0].Select("WagesTypeID=" + this._entityId);
  357. if (dr.Length > 0)
  358. {
  359. this.dgvPayPlan.DataSource = dr.CopyToDataTable();
  360. }
  361. }
  362. else
  363. {
  364. DataView dv = dsResultAccount.Tables[0].DefaultView;
  365. dv.RowFilter = "valueflag=1";
  366. this.dgvPayPlan.DataSource = dv.ToTable();
  367. }
  368. }
  369. }
  370. catch (Exception ex)
  371. {
  372. throw ex;
  373. }
  374. }
  375. /// <summary>
  376. /// 绑定工种工资方案数据源
  377. /// </summary>
  378. private void BindJobsData()
  379. {
  380. try
  381. {
  382. DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  383. {
  384. return PAMModuleProxy.Service.GetJobsPayPlanInfo(Convert.ToInt32(this._entityId));
  385. }));
  386. if (dsResultAccount != null && dsResultAccount.Tables[0].Rows.Count > 0)
  387. {
  388. this.dgvGoods.DataSource = dsResultAccount.Tables[0];
  389. }
  390. }
  391. catch (Exception ex)
  392. {
  393. throw ex;
  394. }
  395. }
  396. #endregion
  397. /// <summary>
  398. /// 删除行时
  399. /// </summary>
  400. /// <param name="sender"></param>
  401. /// <param name="e"></param>
  402. private void dgvGoods_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
  403. {
  404. try
  405. {
  406. if (e.Row.Index != -1)
  407. {
  408. if (this.dgvGoods.CurrentCell != null)
  409. {
  410. string JobsID = this.dgvGoods.Rows[e.Row.Index].Cells["GoodsID"].Value.ToString();
  411. DataRow[] drSel = dtAllData.Select(string.Format("WagesTypeID={0} and GoodsID={1}", this._currentWagesTypeID, JobsID));
  412. if (drSel.Length > 0) //存在,需要更把此行删除
  413. {
  414. drSel[0].Delete();
  415. }
  416. }
  417. }
  418. }
  419. catch (Exception ex)
  420. {
  421. throw ex;
  422. }
  423. }
  424. }
  425. }