F_PAM_0103.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PAM_0103.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. public partial class F_PAM_0103 : FormBase
  24. {
  25. #region 成员变量
  26. // 窗体模式ID
  27. private Constant.FormMode _formType;
  28. // 操作实体ID(方案)
  29. private int? _entityId;
  30. // 操作实体信
  31. private RptProcedureEntity _rptProcedureEntity = new RptProcedureEntity();
  32. // 工序数据源
  33. private DataTable _dtProcedure = new DataTable();
  34. // 工序
  35. private DataSet _dsProcedure = new DataSet();
  36. //记录数据来源Code
  37. private string _rptProcedureCode = string.Empty;
  38. // 工种编码值
  39. private string _JobsCodeValue;
  40. private bool _ShowFlag = true;
  41. // 数据源
  42. DataTable dt = null;
  43. // 当前工资方案ID
  44. private int? _currentPayPlanID = null;
  45. // 数据集
  46. DataTable dtAllData = null;
  47. #endregion
  48. #region 构造函数
  49. /// <summary>
  50. /// 窗体构造
  51. /// </summary>
  52. /// <param name="formType">窗体打开模式</param>
  53. /// <param name="entityId">操作实体ID</param>
  54. public F_PAM_0103(Constant.FormMode formType, int entityId)
  55. {
  56. InitializeComponent();
  57. this._formType = formType;
  58. this._entityId = entityId;
  59. // 窗体显示的Title
  60. if (this._formType == Constant.FormMode.Add)
  61. {
  62. this.Text = FormTitles.F_PAM_0103_ADD;
  63. }
  64. else if (this._formType == Constant.FormMode.Edit)
  65. {
  66. this.Text = FormTitles.F_PAM_0103_EDIT;
  67. }
  68. this.btnSave.Text = ButtonText.BTN_SAVE;
  69. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  70. }
  71. #endregion
  72. #region 事件处理
  73. /// <summary>
  74. /// 窗体加载
  75. /// </summary>
  76. /// <param name="sender"></param>
  77. /// <param name="e"></param>
  78. private void F_MST_0702_Load(object sender, EventArgs e)
  79. {
  80. try
  81. {
  82. this.dgvPayPlan.AutoGenerateColumns = false;
  83. this.dgvJobs.AutoGenerateColumns = false;
  84. //如果是修改,要绑定选中的信息
  85. if (this._formType == Constant.FormMode.Edit)
  86. {
  87. BindJobsData();//编辑工种数据源
  88. BindData();//绑定工资工种数据源
  89. }
  90. //如果是新建,选项默认值设定
  91. else if (this._formType == Constant.FormMode.Add)
  92. {
  93. //绑定全部的工资工种列表,用于过滤筛选
  94. DataSet dsProductionData = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  95. {
  96. return PAMModuleProxy.Service.GetJobsPayPlan("", "");
  97. }));
  98. BindData();//绑定工资方案数据源
  99. if (dsProductionData != null && dsProductionData.Tables[0].Rows.Count > 0)
  100. {
  101. this.dgvJobs.DataSource = dsProductionData.Tables[0];//新建时默认数据源
  102. }
  103. else
  104. {
  105. dt = new DataTable();
  106. dt.Columns.Add("JobsID");
  107. dt.Columns.Add("JobsCode");
  108. dt.Columns.Add("JobsName");
  109. dt.Columns.Add("PayPlanID");
  110. this.dgvJobs.DataSource = dt;//新建时默认数据源
  111. }
  112. dtAllData = this.dgvJobs.DataSource as DataTable;
  113. }
  114. if (dgvPayPlan.RowCount > 0)
  115. {
  116. dgvJobs.AllowUserToAddRows = true;
  117. }
  118. }
  119. catch (Exception ex)
  120. {
  121. // 对异常进行共通处理
  122. ExceptionManager.HandleEventException(this.ToString(),
  123. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  124. }
  125. }
  126. /// <summary>
  127. /// 窗体关闭
  128. /// </summary>
  129. /// <param name="sender"></param>
  130. /// <param name="e"></param>
  131. private void btnCancel_Click(object sender, EventArgs e)
  132. {
  133. this.Close();
  134. }
  135. /// <summary>
  136. /// 窗体释放
  137. /// </summary>
  138. /// <param name="sender"></param>
  139. /// <param name="e"></param>
  140. private void F_MST_0702_FormClosed(object sender, FormClosedEventArgs e)
  141. {
  142. this.Dispose();
  143. }
  144. /// <summary>
  145. /// 数据来源工序变更
  146. /// </summary>
  147. /// <param name="sender"></param>
  148. /// <param name="e"></param>
  149. private void dgvRptSProcedure_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  150. {
  151. try
  152. {
  153. }
  154. catch (Exception ex)
  155. {
  156. // 对异常进行共通处理
  157. ExceptionManager.HandleEventException(this.ToString(),
  158. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  159. }
  160. }
  161. /// <summary>
  162. /// 数据统计工序变更
  163. /// </summary>
  164. /// <param name="sender"></param>
  165. /// <param name="e"></param>
  166. private void dgvRptTProcedure_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  167. {
  168. try
  169. {
  170. if (this.dgvJobs.Rows.Count <= 1 || !_ShowFlag)
  171. {
  172. return;
  173. }
  174. DataGridViewRow rowItem = this.dgvJobs.Rows[e.RowIndex];
  175. DataGridViewColumn columnItem = this.dgvJobs.Columns[e.ColumnIndex];
  176. if ("JobsCode".Equals(columnItem.Name))
  177. {
  178. _ShowFlag = false; //BindJobsRowDataSource
  179. string JobsID = "";
  180. if (this.dgvJobs.Rows[e.RowIndex].Cells["JobsID"].Value != null)
  181. {
  182. JobsID = this.dgvJobs.Rows[e.RowIndex].Cells["JobsID"].Value.ToString();
  183. }
  184. DataTable dtDataSource = FormUtility.BindJobsRowDataSource(this.dgvJobs,
  185. e.RowIndex, columnItem.Name, _JobsCodeValue);
  186. int row = e.RowIndex;
  187. // 返回多少行,进而给每个单元格传值,为的以后多个工资方案进行筛选
  188. if (dtDataSource != null && dtDataSource.Rows.Count > 0)
  189. {
  190. for (int i = 0; i < dtDataSource.Rows.Count; i++)
  191. {
  192. //如果存在数据集中,此列标记删除
  193. this.dgvJobs.Rows[row].Cells["PayPlanID1"].Value = this._currentPayPlanID;
  194. if (dtAllData != null && JobsID != "")
  195. {
  196. DataRow[] drSel = dtAllData.Select(string.Format("PayPlanID={0} and JobsID={1}", this._currentPayPlanID, JobsID));
  197. if (drSel.Length > 0) //存在,需要更把此行删除
  198. {
  199. drSel[0].Delete();
  200. }
  201. }
  202. if (JobsID == "") //新增的时候,是否存在相同的工种编码
  203. {
  204. //DataRow[] drSel = dtAllData.Select(string.Format("PayPlanID={0} and JobsCode='{1}'", this._currentPayPlanID, dtDataSource.Rows[i]["JobsCode"]));
  205. //if (drSel.Length == 0) //不存在,把此行添加进来
  206. //{
  207. DataRow dr = this.dtAllData.NewRow();
  208. dr["JobsID"] = dtDataSource.Rows[i]["JobsID"];
  209. dr["JobsCode"] = dtDataSource.Rows[i]["JobsCode"];
  210. dr["JobsName"] = dtDataSource.Rows[i]["JobsName"];
  211. dr["PayPlanID"] = this._currentPayPlanID;
  212. dtAllData.Rows.Add(dr);
  213. row++;
  214. // }
  215. }
  216. else
  217. {
  218. DataRow dr = this.dtAllData.NewRow();
  219. dr["JobsID"] = dtDataSource.Rows[i]["JobsID"];
  220. dr["JobsCode"] = dtDataSource.Rows[i]["JobsCode"];
  221. dr["JobsName"] = dtDataSource.Rows[i]["JobsName"];
  222. dr["PayPlanID"] = this._currentPayPlanID;
  223. dtAllData.Rows.Add(dr);
  224. row++;
  225. }
  226. }
  227. this.dgvJobs.Rows[e.RowIndex].Selected = true;
  228. }
  229. // 设置可输入单元格的颜色
  230. this.dgvJobs.IsSetInputColumnsColor = true;
  231. }
  232. _ShowFlag = true;
  233. }
  234. catch (Exception ex)
  235. {
  236. _ShowFlag = true;
  237. // 对异常进行共通处理
  238. ExceptionManager.HandleEventException(this.ToString(),
  239. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  240. }
  241. }
  242. #endregion
  243. #region 私有方法
  244. /// <summary>
  245. /// 为实体绑定页面属性
  246. /// </summary>
  247. private bool BindEntity()
  248. {
  249. return false;
  250. }
  251. /// <summary>
  252. /// 绑定需要操作的实体信息
  253. /// </summary>
  254. private void BindPage()
  255. {
  256. try
  257. {
  258. DataTable dt_DataSource = new DataTable();
  259. dt_DataSource.Columns.Add("ProcedureID", typeof(int));
  260. dt_DataSource.Columns.Add("ProcedureCode", typeof(string));
  261. dt_DataSource.Columns.Add("ProcedureName", typeof(string));
  262. this.dgvPayPlan.DataSource = dt_DataSource;
  263. this.dgvJobs.DataSource = dt_DataSource.Copy();
  264. }
  265. catch (Exception ex)
  266. {
  267. throw ex;
  268. }
  269. }
  270. /// <summary>
  271. /// 绑定工资方案数据源
  272. /// </summary>
  273. private void BindData()
  274. {
  275. try
  276. {
  277. DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  278. {
  279. return PAMModuleProxy.Service.GetPayPlan();
  280. }));
  281. if (dsResultAccount != null && dsResultAccount.Tables[0].Rows.Count > 0)
  282. {
  283. if (this._formType == Constant.FormMode.Edit)
  284. {
  285. DataRow[] dr = dsResultAccount.Tables[0].Select("PayPlanID=" + this._entityId);
  286. if (dr.Length > 0)
  287. {
  288. this.dgvPayPlan.DataSource = dr.CopyToDataTable();
  289. }
  290. }
  291. else
  292. {
  293. this.dgvPayPlan.DataSource = dsResultAccount.Tables[0];
  294. }
  295. }
  296. }
  297. catch (Exception ex)
  298. {
  299. throw ex;
  300. }
  301. }
  302. /// <summary>
  303. /// 绑定工种工资方案数据源
  304. /// </summary>
  305. private void BindJobsData()
  306. {
  307. try
  308. {
  309. DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  310. {
  311. return PAMModuleProxy.Service.GetJobsPayPlanInfo(Convert.ToInt32(this._entityId));
  312. }));
  313. if (dsResultAccount != null && dsResultAccount.Tables[0].Rows.Count > 0)
  314. {
  315. this.dgvJobs.DataSource = dsResultAccount.Tables[0];
  316. }
  317. }
  318. catch (Exception ex)
  319. {
  320. throw ex;
  321. }
  322. }
  323. /// <summary>
  324. /// 与服务交互操作
  325. /// </summary>
  326. /// <returns></returns>
  327. private int EntityToServer()
  328. {
  329. int resultCount = Constant.INT_IS_ZERO;
  330. if (this._formType == Constant.FormMode.Add)
  331. {
  332. this._dsProcedure.Tables.Add(this.dgvPayPlan.GetDataTable());
  333. this._dsProcedure.Tables.Add(this.dgvJobs.GetDataTable());
  334. resultCount = (int)DoAsync(() =>
  335. {
  336. return SystemModuleProxy.Service.AddRptProcedure(this._rptProcedureEntity, this._dsProcedure);
  337. });
  338. }
  339. else if (this._formType == Constant.FormMode.Edit)
  340. {
  341. resultCount = (int)DoAsync(() =>
  342. {
  343. return SystemModuleProxy.Service.UpdateRptProcedure(this._rptProcedureEntity, this._dsProcedure);
  344. });
  345. }
  346. return resultCount;
  347. }
  348. #endregion
  349. private void dgvJobs_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
  350. {
  351. try
  352. {
  353. if (this.dgvJobs.Rows.Count <= 1)
  354. {
  355. return;
  356. }
  357. DataGridViewColumn columnItem = this.dgvJobs.Columns[e.ColumnIndex];
  358. if ("JobsCode".Equals(columnItem.Name))
  359. {
  360. _JobsCodeValue = this.dgvJobs.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
  361. }
  362. }
  363. catch (Exception ex)
  364. {
  365. // 对异常进行共通处理
  366. ExceptionManager.HandleEventException(this.ToString(),
  367. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  368. }
  369. }
  370. /// <summary>
  371. /// 选定项发生改变事件
  372. /// </summary>
  373. /// <param name="sender"></param>
  374. /// <param name="e"></param>
  375. private void dgvPayPlan_SelectionChanged(object sender, EventArgs e)
  376. {
  377. try
  378. {
  379. if (this.dgvPayPlan.CurrentCell != null)
  380. {
  381. this._currentPayPlanID = Convert.ToInt32(this.dgvPayPlan.Rows[this.dgvPayPlan.CurrentCell.RowIndex].Cells["PayPlanID"].Value);
  382. //DataTable dtJobs = this.dgvJobs.DataSource as DataTable;
  383. //if (dtJobs != null && dtJobs.Rows.Count > 0)
  384. //{
  385. // DataRow[] dr = dtJobs.Select("PayPlanID=" + this._currentPayPlanID);
  386. // if (dr.Length > 0)
  387. // {
  388. // this.dgvJobs.DataSource = dr.CopyToDataTable();
  389. // }
  390. //}
  391. DataTable dtJobs = this.dtAllData;
  392. if (dtJobs != null)
  393. {
  394. DataView dv = dtJobs.DefaultView;
  395. dv.RowFilter = "PayPlanID=" + this._currentPayPlanID;
  396. this.dgvJobs.DataSource = dv.ToTable();
  397. }
  398. }
  399. }
  400. catch (Exception ex)
  401. {
  402. // 对异常进行共通处理
  403. ExceptionManager.HandleEventException(this.ToString(),
  404. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  405. }
  406. }
  407. /// <summary>
  408. /// 保存按钮事件
  409. /// </summary>
  410. /// <param name="sender"></param>
  411. /// <param name="e"></param>
  412. private void btnSave_Click_1(object sender, EventArgs e)
  413. {
  414. try
  415. {
  416. DataTable dt = this.dtAllData;// this.dgvJobs.DataSource as DataTable;
  417. if (dt == null)
  418. {
  419. return;
  420. }
  421. dt.TableName = "Table1";
  422. int returnValue = (int)DoAsync(new BaseAsyncMethod(() =>
  423. {
  424. return PAMModuleProxy.Service.SaveJobsPayPlan(Convert.ToBoolean(this._entityId), dt);
  425. }));
  426. if (returnValue >= 0) //等于O,表示未修改数据,影响行为0
  427. {
  428. // 提示信息
  429. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, this.Text, "保存"),
  430. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  431. this.DialogResult = DialogResult.OK;
  432. }
  433. else if (returnValue == -3)
  434. {
  435. // 提示信息
  436. MessageBox.Show("工种编码不能重复",
  437. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  438. }
  439. }
  440. catch (Exception ex)
  441. {
  442. // 对异常进行共通处理
  443. ExceptionManager.HandleEventException(this.ToString(),
  444. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  445. }
  446. }
  447. /// <summary>
  448. /// 删除行时
  449. /// </summary>
  450. /// <param name="sender"></param>
  451. /// <param name="e"></param>
  452. private void dgvJobs_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
  453. {
  454. try
  455. {
  456. if (e.Row.Index != -1)
  457. {
  458. //ProductionDataID
  459. if (this.dgvJobs.CurrentCell != null)
  460. {
  461. string JobsID = this.dgvJobs.Rows[e.Row.Index].Cells["JobsID"].Value.ToString();
  462. DataRow[] drSel = dtAllData.Select(string.Format("PayPlanID={0} and JobsID={1}", this._currentPayPlanID, JobsID));
  463. if (drSel.Length > 0) //存在,需要更把此行删除
  464. {
  465. drSel[0].Delete();
  466. }
  467. }
  468. }
  469. }
  470. catch (Exception ex)
  471. {
  472. throw ex;
  473. }
  474. }
  475. }
  476. }