F_HR_1202.cs 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_HR_1202.cs
  5. * 2.功能描述:工资结算记录查询
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 庄天威 2014/09/12 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Windows.Forms;
  13. using System.Text;
  14. using Dongke.IBOSS.PRD.Basics.BaseControls;
  15. using Dongke.IBOSS.PRD.Basics.BaseResources;
  16. using Dongke.IBOSS.PRD.Basics.Library;
  17. using Dongke.IBOSS.PRD.Client.CommonModule;
  18. using Dongke.IBOSS.PRD.Client.DataModels;
  19. using Dongke.IBOSS.PRD.WCF.Proxys;
  20. using Dongke.IBOSS.PRD.WCF.Proxys.HRModuleService;
  21. using Dongke.IBOSS.PRD.WCF.DataModels;
  22. namespace Dongke.IBOSS.PRD.Client.HRModule
  23. {
  24. public partial class F_HR_1202 : FormBase
  25. {
  26. #region 成员变量
  27. /// <summary>
  28. /// 主信息ID
  29. /// </summary>
  30. public int _mainId;
  31. /// <summary>
  32. /// 结算月
  33. /// </summary>
  34. public DateTime? _smouth;
  35. /// <summary>
  36. /// 窗体模式
  37. /// </summary>
  38. public Constant.FormMode _formType;
  39. /// <summary>
  40. /// 基础信息数据集
  41. /// </summary>
  42. public DataSet _dsBase;
  43. /// <summary>
  44. /// 策略明细数据集
  45. /// </summary>
  46. public DataSet _dsStrategy;
  47. /// <summary>
  48. /// 结算起始日
  49. /// </summary>
  50. public DateTime? _salaryDateS;
  51. /// <summary>
  52. /// 结算终止日
  53. /// </summary>
  54. public DateTime? _salaryDateE;
  55. /// <summary>
  56. /// 结算天数
  57. /// </summary>
  58. public int _mouthDay;
  59. /// <summary>
  60. /// 结算金额
  61. /// </summary>
  62. public decimal _salaryTotalMoney;
  63. /// <summary>
  64. /// 调整金额
  65. /// </summary>
  66. public decimal _adjustmentAmount;
  67. /// <summary>
  68. /// 顶端显示模式
  69. /// </summary>
  70. public int _topMode = 0;
  71. /// <summary>
  72. /// 当前页面是否结算
  73. /// </summary>
  74. public int _nowSettlement = 0;
  75. public DataTable _dtStaffSalary;
  76. public DataTable _dtBasicSalary;
  77. public DataTable _dtAttendance;
  78. public DataTable _dtWages;
  79. public DataTable _dtDefectFine;
  80. public DataTable _dtScrapFine;
  81. public DataTable _dtAdmin;
  82. public DataTable _dtAdminDetail;
  83. public DataTable _dtProgress;
  84. public DataTable _dtProgressDetail;
  85. public DataTable _dtManagerSalary;
  86. public DataTable _dtMain;
  87. #endregion
  88. #region 构造函数
  89. /// <summary>
  90. /// 构造函数
  91. /// </summary>
  92. public F_HR_1202(int mainId,Constant.FormMode formType)
  93. {
  94. InitializeComponent();
  95. _mainId = mainId;
  96. _formType = formType;
  97. }
  98. #endregion
  99. private void F_HR_1202_Load(object sender, EventArgs e)
  100. {
  101. try
  102. {
  103. CreateTable();
  104. BindPage();
  105. if(_formType == Constant.FormMode.Edit)
  106. {
  107. this.tsbtnSettlement.Text = "结算or筛选(&J)";
  108. //根据主ID获取全部明细信息
  109. this.tsbtnSettlement.Enabled = false;
  110. this.dtpStartTime.Enabled = false;
  111. _nowSettlement = 1;
  112. //已经通过审批的则不可以修改
  113. foreach(DataGridViewRow gvrFor in this.dgvSettlement.Rows)
  114. {
  115. int AuditValue = Convert.ToInt32(gvrFor.Cells["AuditStatus"].Value);
  116. if (AuditValue == 1)
  117. {
  118. gvrFor.Cells["AdjustmentAmount"].ReadOnly = true;
  119. gvrFor.Cells["Remarks"].ReadOnly = true;
  120. }
  121. }
  122. }
  123. else if(_formType == Constant.FormMode.Display)
  124. {
  125. this.tsbtnSettlement.Text = "结算or筛选(&J)";
  126. //根据主ID获取全部明细信息
  127. //控件除提交外全部不可用
  128. //列表内复选框列可见
  129. this.dgvSettlement.Columns["AuditStatus"].Visible = true;
  130. this.dgvSettlement.Columns["AdjustmentAmount"].ReadOnly = true;
  131. this.dgvSettlement.Columns["Remarks"].ReadOnly = true;
  132. //已经被选中的要设置为只读
  133. foreach(DataGridViewRow gvrFor in this.dgvSettlement.Rows)
  134. {
  135. int AuditValue = Convert.ToInt32(gvrFor.Cells["AuditStatus"].Value);
  136. if(AuditValue == 1)
  137. {
  138. gvrFor.Cells["AuditStatus"].ReadOnly = true;
  139. }
  140. }
  141. this.dtpStartTime.Enabled = false;
  142. this.btnSettlement.Enabled = false;
  143. this.txtRemarks.Enabled = false;
  144. _nowSettlement = 1;
  145. }
  146. this.dgvSettlement.IsSetInputColumnsColor = true;
  147. }
  148. catch(Exception ex)
  149. {
  150. // 对异常进行共通处理
  151. ExceptionManager.HandleEventException(this.ToString(),
  152. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  153. }
  154. }
  155. private void tsbtnSettlement_Click(object sender, EventArgs e)
  156. {
  157. try
  158. {
  159. if(_topMode == 0)
  160. {
  161. if (_nowSettlement == 0)
  162. {
  163. MessageBox.Show("请先进行结算操作!",
  164. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  165. return;
  166. }
  167. _topMode = 1;
  168. this.cgbSelect.Visible = true;
  169. this.cgbBase.Visible = false;
  170. }
  171. else
  172. {
  173. _topMode = 0;
  174. this.cgbSelect.Visible = false;
  175. this.cgbBase.Visible = true;
  176. }
  177. }
  178. catch(Exception ex)
  179. {
  180. // 对异常进行共通处理
  181. ExceptionManager.HandleEventException(this.ToString(),
  182. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  183. }
  184. }
  185. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  186. {
  187. this.dgvSettlement.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  188. }
  189. private void btnSubmit_Click(object sender, EventArgs e)
  190. {
  191. try
  192. {
  193. GetAdjustmentAmount();
  194. if (_formType == Constant.FormMode.Add)
  195. {
  196. if (_nowSettlement == 0)
  197. {
  198. MessageBox.Show("当前页未成功进行结算,无法提交!",
  199. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  200. return;
  201. }
  202. //创建主信息实体
  203. GetSalaryEntity gsEntity = new GetSalaryEntity();
  204. gsEntity.AccountMonth = _smouth;
  205. gsEntity.SalaryDateS = _salaryDateS;
  206. gsEntity.SalaryDateE = _salaryDateE;
  207. gsEntity.SettlementAmount = _salaryTotalMoney;
  208. gsEntity.AdjustmentAmount = _adjustmentAmount;
  209. gsEntity.TotalAmount = gsEntity.SettlementAmount + gsEntity.AdjustmentAmount;
  210. gsEntity.Remarks = this.txtRemarks.Text;
  211. //创建各明细信息数据集
  212. DataSet dsStaffSalary = new DataSet();
  213. dsStaffSalary.Tables.Add(_dtStaffSalary.Copy());
  214. dsStaffSalary.Tables.Add(_dtBasicSalary.Copy());
  215. dsStaffSalary.Tables.Add(_dtWages.Copy());
  216. dsStaffSalary.Tables.Add(_dtDefectFine.Copy());
  217. dsStaffSalary.Tables.Add(_dtScrapFine.Copy());
  218. dsStaffSalary.Tables.Add(_dtAdmin.Copy());
  219. dsStaffSalary.Tables.Add(_dtAdminDetail.Copy());
  220. dsStaffSalary.Tables.Add(_dtProgress.Copy());
  221. dsStaffSalary.Tables.Add(_dtProgressDetail.Copy());
  222. dsStaffSalary.Tables.Add(_dtManagerSalary.Copy());
  223. int SalaryReturn = HRModuleProxy.Service.AddSalarySettlement(gsEntity, dsStaffSalary, _dsBase);
  224. if (SalaryReturn > 0)
  225. {
  226. // 提示信息
  227. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "工资结算", "保存"),
  228. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  229. }
  230. else
  231. {
  232. // 提示信息
  233. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "工资结算", "保存"),
  234. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  235. }
  236. }
  237. else if(_formType == Constant.FormMode.Edit)
  238. {
  239. GetSalaryEntity gsEntity = new GetSalaryEntity();
  240. gsEntity.AdjustmentAmount = _adjustmentAmount;
  241. gsEntity.TotalAmount = _salaryTotalMoney + _adjustmentAmount;
  242. gsEntity.Remarks = this.txtRemarks.Text;
  243. gsEntity.SalarySettlementID = _mainId;
  244. int SalaryReturn = HRModuleProxy.Service.EditSalarySettlement(gsEntity, _dtStaffSalary);
  245. if (SalaryReturn > 0)
  246. {
  247. // 提示信息
  248. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "工资结算", "调整"),
  249. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  250. }
  251. else
  252. {
  253. // 提示信息
  254. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "工资结算", "调整"),
  255. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  256. }
  257. }
  258. else if(_formType == Constant.FormMode.Display)
  259. {
  260. int SalaryReturn = HRModuleProxy.Service.AuditSalarySettlement(_dtStaffSalary);
  261. if (SalaryReturn > 0)
  262. {
  263. // 提示信息
  264. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "工资结算", "审批"),
  265. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  266. }
  267. else
  268. {
  269. // 提示信息
  270. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "工资结算", "审批"),
  271. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  272. }
  273. }
  274. }
  275. catch (Exception ex)
  276. {
  277. // 对异常进行共通处理
  278. ExceptionManager.HandleEventException(this.ToString(),
  279. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  280. }
  281. }
  282. private void btnClose_Click(object sender, EventArgs e)
  283. {
  284. this.Close();
  285. }
  286. private void BindPage()
  287. {
  288. try
  289. {
  290. if (_formType == Constant.FormMode.Add)
  291. {
  292. DataSet dsSMouth = SystemModuleProxy.Service.GetSettlementTime();
  293. if (dsSMouth != null)
  294. {
  295. this.dtpStartTime.Enabled = false;
  296. this.dtpStartTime.Value = Convert.ToDateTime(dsSMouth.Tables[0].Rows[0]["DateValue"]);
  297. _smouth = Convert.ToDateTime(dsSMouth.Tables[0].Rows[0]["DateValue"]);
  298. }
  299. else
  300. {
  301. this.dtpStartTime.Enabled = true;
  302. }
  303. }
  304. else if(_formType == Constant.FormMode.Edit || _formType == Constant.FormMode.Display)
  305. {
  306. this.dgvSettlement.AutoGenerateColumns = false;
  307. this.dgvSettlement.DataSource = _dtStaffSalary;
  308. this.txtRemarks.Text = _dtMain.Rows[0]["Remarks"].ToString();
  309. this.dtpStartTime.Value = Convert.ToDateTime(_dtMain.Rows[0]["AccountMonth"]);
  310. }
  311. }
  312. catch(Exception ex)
  313. {
  314. throw ex;
  315. }
  316. }
  317. private void GetBaseData()
  318. {
  319. try
  320. {
  321. GetSalaryEntity gsEntity = new GetSalaryEntity();
  322. //首先获取结算日期
  323. int SDay = 0;
  324. DataTable dtSysData = SystemModuleProxy.Service.GetSystemData().Tables[0];
  325. foreach (DataRow drFor in dtSysData.Rows)
  326. {
  327. if (drFor["SettingCode"].ToString().Trim() == "S_CMN_0003")
  328. {
  329. if (drFor["SettingValue"].ToString() == "月末")
  330. {
  331. SDay = Convert.ToInt32(DateTime.DaysInMonth(this.dtpStartTime.Value.Year, this.dtpStartTime.Value.Month));
  332. }
  333. }
  334. }
  335. //然后获取结算月,如果有取那个月,如果没有界面获取的月
  336. DateTime dtSMouth;
  337. if (_smouth != null)
  338. {
  339. dtSMouth = Convert.ToDateTime(_smouth).AddDays(-Convert.ToDateTime(_smouth).Day + 1);
  340. }
  341. else
  342. {
  343. dtSMouth = this.dtpStartTime.Value.Date.AddDays(-this.dtpStartTime.Value.Date.Day + 1);
  344. _smouth = dtSMouth;
  345. }
  346. //计算出结算起始日和终止日
  347. DateTime SalaryDateS = dtSMouth;
  348. DateTime SalaryDateE = dtSMouth.AddDays(SDay);
  349. gsEntity.SalaryDateS = SalaryDateS;
  350. gsEntity.SalaryDateE = SalaryDateE.AddHours(23).AddMinutes(59).AddSeconds(59).AddDays(-1);
  351. _salaryDateS = SalaryDateS;
  352. _salaryDateE = SalaryDateE;
  353. //因为要算上结算最后一天的本体,所以要+1
  354. _mouthDay = ((TimeSpan)(SalaryDateE - SalaryDateS)).Days;
  355. //获取全部策略明细信息
  356. DataSet dsStrategy = TATModuleProxy.Service.GetAllUseStrategy(SalaryDateS);
  357. _dsStrategy = dsStrategy;
  358. if (_dsStrategy.Tables[2].Rows.Count != 0 && _dsStrategy.Tables[3].Rows.Count != 0)
  359. {
  360. gsEntity.WagesMainId = Convert.ToInt32(_dsStrategy.Tables[2].Rows[0]["WagesId"]);
  361. gsEntity.WagesMainIdE = Convert.ToInt32(_dsStrategy.Tables[3].Rows[0]["WagesId"]);
  362. }
  363. else
  364. {
  365. //没有对应的工价明细
  366. return;
  367. }
  368. //最后获取全部基础信息
  369. DataSet dsBase = HRModuleProxy.Service.GetSalaryData(gsEntity);
  370. _dsBase = dsBase;
  371. //进行结算
  372. Settlement();
  373. }
  374. catch(Exception ex)
  375. {
  376. throw ex;
  377. }
  378. }
  379. private void Settlement()
  380. {
  381. int row = 0;
  382. try
  383. {
  384. //获取全部员工并遍历
  385. DataTable dtStaff = _dsBase.Tables[6];
  386. foreach (DataRow drStaff in dtStaff.Rows)
  387. {
  388. //if (row > 10)
  389. //{
  390. // break;
  391. //}
  392. row++;
  393. //if(row==1564)
  394. //{
  395. // int a = 0;
  396. //}
  397. //员工ID
  398. int StaffId = Convert.ToInt32(drStaff["StaffId"]);
  399. //员工工种
  400. int StaffJobsId = Convert.ToInt32(drStaff["Jobs"]);
  401. //员工状态
  402. int StaffStatus = Convert.ToInt32(drStaff["StaffStatus"]);
  403. //员工入职时间
  404. if (drStaff["EntryDate"] != DBNull.Value)
  405. {
  406. DateTime StaffEntryDate = Convert.ToDateTime(drStaff["EntryDate"]);
  407. }
  408. //员工离职时间
  409. DateTime? StaffTurnoverDate = null;
  410. if (drStaff["TurnoverDate"] != DBNull.Value)
  411. {
  412. StaffTurnoverDate = Convert.ToDateTime(drStaff["TurnoverDate"]);
  413. }
  414. #region 基本工资 + 行政奖惩 + 进度奖惩
  415. //该员工基本工资(基本工资+出勤考核)
  416. decimal BSalary = 0;
  417. //该员工行政考核总额
  418. decimal ASalary = 0;
  419. //该员工进度考核总额
  420. decimal PSalary = 0;
  421. //基本工资部分,首先查看该人员是否有人事变动
  422. DataTable dtRecord = _dsBase.Tables[7].Copy();
  423. dtRecord.DefaultView.RowFilter = " StaffId = " + StaffId;
  424. DataTable dtRecordNow = dtRecord.DefaultView.ToTable();
  425. //如果有人事变动的话
  426. if (dtRecordNow.Rows.Count != 0)
  427. {
  428. //遍历人事变动,从结算开始日起,到第一条记录的审批日期,为该员工担当该履历调整前工种
  429. //后面的以此类推,第一条记录的审批日期至第二条记录的审批日期,为该员工担当第二条履历的调整前工种
  430. //当然,存储过程获取的是结算时间段内审批通过的信息,所以无需担心审批日大于结算终止日
  431. //结算每一条履历完毕后要把已结算日期(RecordStartTime)保存起来,履历遍历结束后如果记录时间小于结算终止日,还要计算员工当前工种的工资
  432. //计算当前工种工资为最后一条履历的审批时间至结算终止日
  433. DateTime RecordStartTime = Convert.ToDateTime(_salaryDateS);
  434. int LastTargetJobs = 0;
  435. int LastStatus = 0;
  436. foreach (DataRow drRecordFor in dtRecordNow.Rows)
  437. {
  438. //首先查看该履历中的变动前状态,如果是未入职/离职的话,直接下一条信息
  439. if (Convert.ToInt32(drRecordFor["OriginalStaffStatus"]) == 0
  440. || Convert.ToInt32(drRecordFor["OriginalStaffStatus"]) == 3)
  441. {
  442. RecordStartTime = Convert.ToDateTime(drRecordFor["ApprovalDate"]);
  443. LastStatus = Convert.ToInt32(drRecordFor["TargetStaffStatus"]);
  444. LastTargetJobs = Convert.ToInt32(drRecordFor["TargetJobs"]);
  445. continue;
  446. }
  447. //其次获取该履历中的变动前工种,即该员工从开始结算日-审批日中间的工种
  448. int RFJobsId = Convert.ToInt32(drRecordFor["OriginalJobs"]);
  449. //获取变动前状态,分辨是试用还是正式
  450. int RFStatus = Convert.ToInt32(drRecordFor["OriginalStaffStatus"]);
  451. //获取审批通过时间(即变化工种时间)
  452. DateTime UpdateTime = Convert.ToDateTime(drRecordFor["ApprovalDate"]);
  453. //计算该工种担当时间的工资,累加(-1天是因为审核当天就变成另一个工种了,那一天是下次结算的)
  454. BSalary += this.GetBSalaryByJobsId(StaffId, RFJobsId, RFStatus, RecordStartTime, UpdateTime);
  455. //并同时计算该时间段的行政奖惩金额
  456. ASalary += this.GetASalaryByJobsId(StaffId, RFJobsId, RFStatus, RecordStartTime, UpdateTime);
  457. //并同时计算该时间段的进度奖惩金额
  458. PSalary += this.GetPSalaryByJobsId(StaffId, RFJobsId, RFStatus, RecordStartTime, UpdateTime);
  459. //更新已结算日期,循环
  460. RecordStartTime = UpdateTime;
  461. LastStatus = Convert.ToInt32(drRecordFor["TargetStaffStatus"]);
  462. if (LastStatus == 0 || LastStatus == 3)//同上,保护后面的值不会取空
  463. {
  464. continue;
  465. }
  466. LastTargetJobs = Convert.ToInt32(drRecordFor["TargetJobs"]);
  467. }
  468. //如果循环完毕后,如果已结算日期不等于结算终止日
  469. //那么要算出已结算日期-结算终止日的循环完毕后遗留的“变动后工种”的工资
  470. //步骤同上
  471. if (LastStatus != 0 && LastStatus != 3)
  472. {
  473. BSalary += this.GetBSalaryByJobsId(StaffId, LastTargetJobs, LastStatus, RecordStartTime, Convert.ToDateTime(_salaryDateE));
  474. ASalary += this.GetASalaryByJobsId(StaffId, LastTargetJobs, LastStatus, RecordStartTime, Convert.ToDateTime(_salaryDateE));
  475. PSalary += this.GetPSalaryByJobsId(StaffId, LastTargetJobs, LastStatus, RecordStartTime, Convert.ToDateTime(_salaryDateE));
  476. }
  477. }
  478. else
  479. {
  480. //当段时间内没有人事变动的话,要获取结算日期前的最后一次履历,进行相关逻辑结算
  481. DataTable dtUpRecord = _dsBase.Tables[8];
  482. dtUpRecord.DefaultView.RowFilter = " StaffId = " + StaffId;
  483. DataTable dtUpRecordNow = dtRecord.DefaultView.ToTable();
  484. if (dtUpRecordNow.Rows.Count != 0)
  485. {
  486. DataRow drUpRecord = dtUpRecord.Rows[0];
  487. BSalary += this.GetBSalaryByJobsId(StaffId, Convert.ToInt32(drUpRecord["TargetJobs"]),
  488. Convert.ToInt32(drUpRecord["TargetStaffStatus"]), Convert.ToDateTime(_salaryDateS),
  489. Convert.ToDateTime(_salaryDateE));
  490. ASalary += this.GetASalaryByJobsId(StaffId, Convert.ToInt32(drUpRecord["TargetJobs"]),
  491. Convert.ToInt32(drUpRecord["TargetStaffStatus"]), Convert.ToDateTime(_salaryDateS),
  492. Convert.ToDateTime(_salaryDateE));
  493. PSalary += this.GetPSalaryByJobsId(StaffId, Convert.ToInt32(drUpRecord["TargetJobs"]),
  494. Convert.ToInt32(drUpRecord["TargetStaffStatus"]), Convert.ToDateTime(_salaryDateS),
  495. Convert.ToDateTime(_salaryDateE));
  496. }
  497. else //直接取员工本身的
  498. {
  499. BSalary += this.GetBSalaryByJobsId(StaffId, StaffJobsId, StaffStatus,
  500. Convert.ToDateTime(_salaryDateS), Convert.ToDateTime(_salaryDateE));
  501. ASalary += this.GetASalaryByJobsId(StaffId, StaffJobsId, StaffStatus,
  502. Convert.ToDateTime(_salaryDateS), Convert.ToDateTime(_salaryDateE));
  503. PSalary += this.GetPSalaryByJobsId(StaffId, StaffJobsId, StaffStatus,
  504. Convert.ToDateTime(_salaryDateS), Convert.ToDateTime(_salaryDateE));
  505. }
  506. }
  507. #endregion
  508. #region 计件工资
  509. //该员工计件工资
  510. decimal CSalary = 0;
  511. //获取该员工参与的全部生产数据(计条码,计件,计窑车)
  512. DataTable dtBarCode = _dsBase.Tables[9].Copy();
  513. dtBarCode.DefaultView.RowFilter = " StaffId = " + StaffId;
  514. DataTable dtBarCodeNow = dtBarCode.DefaultView.ToTable();
  515. foreach (DataRow drNowFor in dtBarCodeNow.Rows)
  516. {
  517. //计条码的,直接累加对应商品的工价*计价单位数量即可
  518. if (drNowFor["PieceNum"] != DBNull.Value || drNowFor["Wages"] != DBNull.Value)
  519. {
  520. CSalary += Convert.ToDecimal(drNowFor["PieceNum"]) * Convert.ToDecimal(drNowFor["Wages"]);
  521. }
  522. //添加计件工资明细
  523. DataRow drWages = _dtWages.NewRow();
  524. drWages["WagesJobs"] = drNowFor["UJobsID"];
  525. drWages["StaffID"] = StaffId;
  526. drWages["SalaryType"] = drNowFor["StaffStatus"];
  527. drWages["PriceType"] = drNowFor["PriceType"];
  528. drWages["AccountDateFrom"] = _salaryDateS;
  529. drWages["AccountDateTo"] = _salaryDateE;
  530. drWages["BarCode"] = drNowFor["BarCode"];
  531. drWages["GoodsId"] = drNowFor["GoodsId"];
  532. drWages["GoodsLevelTypeID"] = drNowFor["GoodsLevelTypeID"];
  533. drWages["Wages"] = drNowFor["Wages"];
  534. drWages["Salary"] = Convert.ToDecimal(drNowFor["PieceNum"]) * Convert.ToDecimal(drNowFor["Wages"]);
  535. _dtWages.Rows.Add(drWages);
  536. }
  537. DataTable dtCount = _dsBase.Tables[0].Copy();
  538. dtCount.DefaultView.RowFilter = " StaffId = " + StaffId;
  539. DataTable dtCountNow = dtCount.DefaultView.ToTable();
  540. foreach (DataRow drNowFor in dtCountNow.Rows)
  541. {
  542. //计件同理,直接累加对应商品的工价*计价单位数量即可
  543. if (drNowFor["PieceNum"] != DBNull.Value || drNowFor["Wages"] != DBNull.Value)
  544. {
  545. CSalary += Convert.ToDecimal(drNowFor["PieceNum"]) * Convert.ToDecimal(drNowFor["Wages"]);
  546. }
  547. //添加计件工资明细
  548. DataRow drWages = _dtWages.NewRow();
  549. drWages["WagesJobs"] = drNowFor["UJobsID"];
  550. drWages["StaffID"] = StaffId;
  551. drWages["SalaryType"] = drNowFor["StaffStatus"];
  552. drWages["PriceType"] = drNowFor["PriceType"];
  553. drWages["AccountDateFrom"] = _salaryDateS;
  554. drWages["AccountDateTo"] = _salaryDateE;
  555. drWages["BarCode"] = drNowFor["BarCode"];
  556. drWages["GoodsId"] = drNowFor["GoodsId"];
  557. drWages["GoodsLevelTypeID"] = drNowFor["GoodsLevelTypeID"];
  558. drWages["Wages"] = drNowFor["Wages"];
  559. drWages["Salary"] = Convert.ToDecimal(drNowFor["PieceNum"]) * Convert.ToDecimal(drNowFor["Wages"]);
  560. _dtWages.Rows.Add(drWages);
  561. }
  562. DataTable dtCar = _dsBase.Tables[5].Copy();
  563. dtCar.DefaultView.RowFilter = " StaffId = " + StaffId;
  564. DataTable dtCarNow = dtCar.DefaultView.ToTable();
  565. foreach (DataRow drNowFor in dtCarNow.Rows)
  566. {
  567. //计车的,累加每车单价以及计车单位数
  568. CSalary += Convert.ToDecimal(drNowFor["KilnCarNum"]) * Convert.ToDecimal(drNowFor["CarPricing"]);
  569. //添加计件工资明细
  570. DataRow drWages = _dtWages.NewRow();
  571. drWages["WagesJobs"] = drNowFor["UJobsID"];
  572. drWages["StaffID"] = StaffId;
  573. drWages["SalaryType"] = drNowFor["StaffStatus"];
  574. drWages["PriceType"] = drNowFor["PriceType"];
  575. drWages["AccountDateFrom"] = _salaryDateS;
  576. drWages["AccountDateTo"] = _salaryDateE;
  577. drWages["KilnID"] = drNowFor["KilnID"];
  578. drWages["KilnCarID"] = drNowFor["KilnCarID"];
  579. drWages["IntoKilnTime"] = drNowFor["IntoKilnTime"];
  580. drWages["OutKilnTime"] = drNowFor["OutKilnTime"];
  581. drWages["Wages"] = drNowFor["CarPricing"];
  582. drWages["Salary"] = Convert.ToDecimal(drNowFor["KilnCarNum"]) * Convert.ToDecimal(drNowFor["CarPricing"]);
  583. _dtWages.Rows.Add(drWages);
  584. }
  585. DataTable dtWeight = _dsBase.Tables[11].Copy();
  586. dtWeight.DefaultView.RowFilter = " StaffId = " + StaffId;
  587. DataTable dtWeightNow = dtWeight.DefaultView.ToTable();
  588. foreach(DataRow drNowFor in dtWeightNow.Rows)
  589. {
  590. //计重量的,用重量乘单价乘单位数
  591. CSalary += Convert.ToDecimal(drNowFor["Lusterwareweight"]) * Convert.ToDecimal(drNowFor["WeightPricing"])
  592. * Convert.ToDecimal(drNowFor["Weight"]);
  593. //添加计件工资明细
  594. DataRow drWages = _dtWages.NewRow();
  595. drWages["WagesJobs"] = drNowFor["UJobsID"];
  596. drWages["StaffID"] = StaffId;
  597. drWages["SalaryType"] = drNowFor["StaffStatus"];
  598. drWages["PriceType"] = drNowFor["PriceType"];
  599. drWages["AccountDateFrom"] = _salaryDateS;
  600. drWages["AccountDateTo"] = _salaryDateE;
  601. drWages["Wages"] = drNowFor["WeightPricing"];
  602. drWages["Salary"] = Convert.ToDecimal(drNowFor["Lusterwareweight"]) * Convert.ToDecimal(drNowFor["WeightPricing"])
  603. * Convert.ToDecimal(drNowFor["Weight"]);
  604. _dtWages.Rows.Add(drWages);
  605. }
  606. #endregion
  607. #region 缺陷扣罚
  608. //该员工缺陷扣罚总额
  609. decimal DSalary = 0;
  610. //获取该员工相关的缺陷扣罚信息
  611. DataTable dtDefect = _dsBase.Tables[3].Copy();
  612. dtDefect.DefaultView.RowFilter = " StaffId = " + StaffId;
  613. DataTable dtDefectNow = dtDefect.DefaultView.ToTable();
  614. //获取全部缺陷扣罚明细
  615. DataTable dtDefectDetail = _dsStrategy.Tables[4].Copy();
  616. foreach (DataRow drFor in dtDefectNow.Rows)
  617. {
  618. //首先根据缺陷扣罚类别,获取明细
  619. dtDefectDetail.DefaultView.RowFilter = " DefectFine = " + drFor["DefectFine"].ToString()
  620. + " and SalaryType = " + (Convert.ToInt32(drFor["StaffStatus"]) - 1);
  621. DataTable dtDefectDetailNow = dtDefectDetail.DefaultView.ToTable();
  622. if (dtDefectDetailNow.Rows.Count != 0)
  623. {
  624. //那么首先获取第一行,如果是按金额扣罚,直接获取金额即可
  625. //如果是按工价比例扣罚,那么还要进一步根据产品来匹配工价以及策略扣罚比例
  626. DataRow drDetailTop = dtDefectDetailNow.Rows[0];
  627. DataRow drDefect = _dtDefectFine.NewRow();
  628. drDefect["StaffID"] = StaffId;
  629. drDefect["StaffStatus"] = drFor["StaffStatus"];
  630. drDefect["JobsID"] = drFor["UJobsID"];
  631. drDefect["SalaryType"] = (Convert.ToInt32(drFor["StaffStatus"]) - 1);
  632. drDefect["BeginDate"] = _salaryDateS; ;
  633. drDefect["EndDate"] = _salaryDateE;
  634. drDefect["BarCode"] = drFor["BarCode"];
  635. drDefect["DefectFine"] = drFor["DefectFine"];
  636. drDefect["FineType"] = drDetailTop["FineType"];
  637. if (Convert.ToInt32(drDetailTop["FineType"]) == 2)
  638. {
  639. //筛选条件包含工种,状态,产品
  640. dtDefectDetailNow.DefaultView.RowFilter = " JobsID = " + drFor["UJobsID"] + " and GoodsID = " + drFor["GoodsID"]
  641. + " and SalaryType = " + (Convert.ToInt32(drFor["StaffStatus"]) - 1);
  642. DataTable dtDefectGoods = dtDefectDetailNow.DefaultView.ToTable();
  643. if (dtDefectGoods.Rows.Count != 0)
  644. {
  645. DSalary += Convert.ToDecimal(dtDefectGoods.Rows[0]["FineAmount"]);
  646. drDefect["FineAmount"] = Convert.ToDecimal(dtDefectGoods.Rows[0]["FineAmount"]);
  647. }
  648. }
  649. else
  650. {
  651. //借用结算计件工资时的两个数据集,因为这时候不清楚缺陷扣罚的那个生产数据是根据什么计的,所以要分别在两个数据集中找
  652. //找到了之后,用工价乘以缺陷扣罚中的百分比即可
  653. dtBarCodeNow.DefaultView.RowFilter = " BarCode = " + drFor["BarCode"] + " and UJobsID = " + drFor["UJobsID"]
  654. + " and StaffStatus = " + drFor["StaffStatus"];
  655. DataTable dtWagesByBarCode = dtBarCodeNow.DefaultView.ToTable();
  656. dtCountNow.DefaultView.RowFilter = " BarCode = " + drFor["BarCode"] + " and UJobsID = " + drFor["UJobsID"]
  657. + " and StaffStatus = " + drFor["StaffStatus"];
  658. DataTable dtWagesByCount = dtCountNow.DefaultView.ToTable();
  659. if (dtWagesByBarCode.Rows.Count != 0)
  660. {
  661. DSalary += Convert.ToDecimal(dtWagesByBarCode.Rows[0]["Wages"]) * Convert.ToDecimal(drDetailTop["Coefficient"]) / 100;
  662. drDefect["FineAmount"] = Convert.ToDecimal(dtWagesByBarCode.Rows[0]["Wages"]) * Convert.ToDecimal(drDetailTop["Coefficient"]) / 100;
  663. }
  664. else if (dtWagesByCount.Rows.Count != 0)
  665. {
  666. DSalary += Convert.ToDecimal(dtWagesByCount.Rows[0]["Wages"]) * Convert.ToDecimal(drDetailTop["Coefficient"]) / 100;
  667. drDefect["FineAmount"] = Convert.ToDecimal(dtWagesByCount.Rows[0]["Wages"]) * Convert.ToDecimal(drDetailTop["Coefficient"]) / 100;
  668. }
  669. else
  670. {
  671. drDefect["FineAmount"] = 0;
  672. }
  673. }
  674. _dtDefectFine.Rows.Add(drDefect);
  675. }
  676. else
  677. {
  678. continue;
  679. }
  680. }
  681. #endregion
  682. #region 损坯扣罚
  683. //损坯扣罚金额
  684. decimal SSalary = 0;
  685. //获取该员工相关的缺陷扣罚信息
  686. DataTable dtScrapProduct = _dsBase.Tables[10].Copy();
  687. dtScrapProduct.DefaultView.RowFilter = " StaffId = " + StaffId;
  688. DataTable dtScrapProductNow = dtScrapProduct.DefaultView.ToTable();
  689. foreach (DataRow drFor in dtScrapProductNow.Rows)
  690. {
  691. SSalary += Convert.ToDecimal(drFor["ScrapFine"]);
  692. DataRow drScrapFine = _dtScrapFine.NewRow();
  693. drScrapFine["StaffID"] = StaffId;
  694. drScrapFine["StaffStatus"] = drFor["StaffStatus"];
  695. drScrapFine["JobsID"] = drFor["UJobsID"];
  696. drScrapFine["BeginDate"] = _salaryDateS;
  697. drScrapFine["EndDate"] = _salaryDateE;
  698. drScrapFine["BarCode"] = drFor["BarCode"];
  699. drScrapFine["GoodsID"] = drFor["GoodsID"];
  700. drScrapFine["ScrapTime"] = drFor["ScrapDate"];
  701. drScrapFine["ScrapFine"] = drFor["ScrapFine"];
  702. _dtScrapFine.Rows.Add(drScrapFine);
  703. }
  704. #endregion
  705. #region 工资总计
  706. DataRow drStaffSalary = _dtStaffSalary.NewRow();
  707. drStaffSalary["StaffID"] = StaffId;
  708. drStaffSalary["StaffName"] = drStaff["StaffName"];
  709. drStaffSalary["OrganizationName"] = drStaff["OrganizationName"];
  710. drStaffSalary["PostName"] = drStaff["PostName"];
  711. drStaffSalary["AccountMonth"] = _smouth;
  712. drStaffSalary["AccountDateFrom"] = _salaryDateS;
  713. drStaffSalary["AccountDateTo"] = _salaryDateE;
  714. drStaffSalary["BasicSalary"] = BSalary;
  715. drStaffSalary["WagesSalary"] = CSalary;
  716. drStaffSalary["DefectFine"] = DSalary;
  717. drStaffSalary["ScrapFine"] = SSalary;
  718. drStaffSalary["AdminSalary"] = ASalary;
  719. drStaffSalary["ProgressSalary"] = PSalary;
  720. drStaffSalary["AuditStatus"] = 0;
  721. drStaffSalary["TotalAmount"] = BSalary + CSalary - DSalary - SSalary + ASalary + PSalary;
  722. drStaffSalary["SettlementAmount"] = BSalary + CSalary - DSalary - SSalary + ASalary + PSalary;
  723. drStaffSalary["AdjustmentAmount"] = 0;
  724. _dtStaffSalary.Rows.Add(drStaffSalary);
  725. #endregion
  726. _salaryTotalMoney += BSalary + CSalary - DSalary - SSalary + ASalary + PSalary;
  727. }
  728. #region 管理者工资
  729. //全部结算完毕后,重新循环一次页面列表数据源
  730. foreach(DataRow drFor in _dtStaffSalary.Rows)
  731. {
  732. decimal MSalary = 0;
  733. //过程就是,获取每一个已结算的员工,查询该员工在管理者策略中是否担当管理者
  734. //如果是,那么查询该管理者所属的所有组员,获取他们的已结算工资,并根据管理者策略明细计算出该管理者的工资
  735. //如果否,进入下一个员工的循环
  736. int StaffId = Convert.ToInt32(drFor["StaffID"]);
  737. DataTable dtManagersDetail = _dsStrategy.Tables[7];
  738. dtManagersDetail.DefaultView.RowFilter = " Manager = " + StaffId;
  739. DataTable dtManagerToMember = dtManagersDetail.DefaultView.ToTable();
  740. //如果筛选后依然存在信息,那么该员工就是管理者
  741. if(dtManagerToMember.Rows.Count != 0)
  742. {
  743. //首先获取第一行,查看该管理者工资的计算方式
  744. int SalaryType = Convert.ToInt32(dtManagerToMember.Rows[0]["SalaryType"]);
  745. int MemberId = Convert.ToInt32(dtManagerToMember.Rows[0]["ManagersID"]);
  746. int ManagerSalaryID = Convert.ToInt32(dtManagerToMember.Rows[0]["ManagerSalaryID"]);
  747. if(SalaryType == 1) //平均工资的话,遍历所有组员,找到对应结算信息,累加工资,并算出平均数
  748. {
  749. int MemberCount = 0;
  750. decimal MemberTotalSalary = 0;
  751. foreach(DataRow drMemberFor in dtManagerToMember.Rows)
  752. {
  753. _dtStaffSalary.DefaultView.RowFilter = " StaffId = " + drMemberFor["Member"];
  754. DataTable dtMemberSalary = _dtStaffSalary.DefaultView.ToTable();
  755. if(dtMemberSalary.Rows.Count != 0)
  756. {
  757. MemberTotalSalary += Convert.ToDecimal(dtMemberSalary.Rows[0]["SettlementAmount"]);
  758. MemberCount++;
  759. }
  760. }
  761. MSalary = MemberTotalSalary / MemberCount;
  762. }
  763. else if (SalaryType == 2) //最高工资的话,遍历所有组员,获取最高的金额
  764. {
  765. decimal MemberMaxSalary = 0;
  766. foreach (DataRow drMemberFor in dtManagerToMember.Rows)
  767. {
  768. _dtStaffSalary.DefaultView.RowFilter = " StaffId = " + drMemberFor["Member"];
  769. DataTable dtMemberSalary = _dtStaffSalary.DefaultView.ToTable();
  770. if (dtMemberSalary.Rows.Count != 0)
  771. {
  772. decimal MemberSalaryFor = Convert.ToDecimal(dtMemberSalary.Rows[0]["SettlementAmount"]);
  773. if(MemberMaxSalary < MemberSalaryFor)
  774. {
  775. MemberMaxSalary = MemberSalaryFor;
  776. }
  777. }
  778. }
  779. MSalary = MemberMaxSalary;
  780. }
  781. else if(SalaryType == 3)
  782. {
  783. decimal MemberMinSalary = 0;
  784. foreach (DataRow drMemberFor in dtManagerToMember.Rows)
  785. {
  786. _dtStaffSalary.DefaultView.RowFilter = " StaffId = " + drMemberFor["Member"];
  787. DataTable dtMemberSalary = _dtStaffSalary.DefaultView.ToTable();
  788. if (dtMemberSalary.Rows.Count != 0)
  789. {
  790. decimal MemberSalaryFor = Convert.ToDecimal(dtMemberSalary.Rows[0]["SettlementAmount"]);
  791. if (MemberMinSalary > MemberSalaryFor)
  792. {
  793. MemberMinSalary = MemberSalaryFor;
  794. }
  795. }
  796. }
  797. MSalary = MemberMinSalary;
  798. }
  799. //保存管理者工资明细
  800. DataRow drManagerSalary = _dtManagerSalary.NewRow();
  801. drManagerSalary["StaffID"] = StaffId;
  802. drManagerSalary["Member"] = MemberId;
  803. drManagerSalary["Salary"] = MSalary;
  804. _dtManagerSalary.Rows.Add(drManagerSalary);
  805. //并修改界面数据源的值
  806. drFor["ManagerSalary"] = MSalary;
  807. drFor["TATManagersID"] = ManagerSalaryID;
  808. drFor["TotalAmount"] = Convert.ToDecimal(drFor["TotalAmount"]) + MSalary;
  809. drFor["SettlementAmount"] = Convert.ToDecimal(drFor["SettlementAmount"]) + MSalary;
  810. _salaryTotalMoney += MSalary;
  811. }
  812. else
  813. {
  814. drFor["ManagerSalary"] = 0;
  815. continue;
  816. }
  817. }
  818. #endregion
  819. //清空筛选条件
  820. _dtStaffSalary.DefaultView.RowFilter = "";
  821. this.dgvSettlement.AutoGenerateColumns = false;
  822. this.dgvSettlement.DataSource = _dtStaffSalary;
  823. this.dgvSettlement.IsSetInputColumnsColor = true;
  824. _nowSettlement = 1;
  825. }
  826. catch(Exception ex)
  827. {
  828. int errorrow = row;
  829. throw ex;
  830. }
  831. }
  832. ///<summary>
  833. /// 统计一段时间内有多少个星期几
  834. ///</summary>
  835. ///<param name= "TimeStart"> 开始日期 </param>
  836. ///<param name= "TimeEnd"> 结束日期 </param>
  837. ///<param name= "AWeek "> 星期几 </param>
  838. ///<returns> 返回个数 </returns>
  839. public int TotalWeeks(DateTime TimeStart, DateTime TimeEnd, DayOfWeek AWeek)
  840. {
  841. TimeSpan vTimeSpan = new TimeSpan(TimeEnd.Ticks - TimeStart.Ticks);
  842. int Result = (int)vTimeSpan.TotalDays / 7;
  843. for (int i = 0; i <= vTimeSpan.TotalDays % 7; i++)
  844. if (TimeStart.AddDays(i).DayOfWeek == AWeek)
  845. return Result + 1;
  846. return Result;
  847. }
  848. /// <summary>
  849. /// 计算基本工资
  850. /// </summary>
  851. /// <param name="StaffId">员工ID</param>
  852. /// <param name="JobsId">工种ID</param>
  853. /// <param name="JobsStatus">状态(正式或实习)</param>
  854. /// <param name="StartTime">开始时间</param>
  855. /// <param name="EndTime">结束时间</param>
  856. /// <returns></returns>
  857. public decimal GetBSalaryByJobsId(int StaffId,int JobsId,int JobsStatus,DateTime StartTime,DateTime EndTime)
  858. {
  859. try
  860. {
  861. decimal BisicSalary = 0;
  862. //变动前工种持续时间(天数)
  863. int JobsDay = ((TimeSpan)(EndTime - StartTime)).Days;
  864. //查询该工种的基本工资策略明细,以获取基本工资(月)以及补贴
  865. decimal BasicSalaryMouth = 0; //基本工资(月)
  866. decimal Subsidy = 0; //补贴
  867. DataTable dtBasic = _dsStrategy.Tables[0].Copy();
  868. dtBasic.DefaultView.RowFilter = "salarytype = " + (JobsStatus - 1) + " and JobsID = " + JobsId;//筛选条件为工种+状态
  869. DataTable dtBasicNow = dtBasic.DefaultView.ToTable();
  870. if (dtBasicNow.Rows.Count == 0)
  871. {
  872. //没有对应工资策略,返回
  873. return 0;
  874. }
  875. else
  876. {
  877. BasicSalaryMouth = Convert.ToDecimal(dtBasicNow.Rows[0]["BasicSalary"]);
  878. Subsidy = Convert.ToDecimal(dtBasicNow.Rows[0]["Subsidy"]);
  879. }
  880. //然后要获取该工种的出勤策略明细,以计算该工种的日工资和每月可休息天数
  881. decimal daySalrty = 0; //日工资
  882. int restDaysMouth = 0; //每月可休息天数
  883. int restDaysNow = 0; //担当该工种时间内可休息天数
  884. int PunishMode = 0; //扣罚方式 1:比例 2:阶梯
  885. int RestmMode = 0; //休息方式 1:星期某 2:天数
  886. DataTable dtAttendance = _dsStrategy.Tables[1].Copy();
  887. dtAttendance.DefaultView.RowFilter = " JobsId = " + JobsId;
  888. DataTable dtAttendanceNow = dtAttendance.DefaultView.ToTable();
  889. //查看该策略明细的休息方式
  890. //如果取出多条,是因为阶梯扣罚的关系,取第一条即可
  891. if (dtAttendanceNow.Rows.Count != 0)
  892. {
  893. DataRow drAttendanceNow = dtAttendanceNow.Rows[0];
  894. PunishMode = Convert.ToInt32(drAttendanceNow["PunishMode"]);
  895. RestmMode = Convert.ToInt32(drAttendanceNow["RestmMode"]);
  896. if (Convert.ToInt32(drAttendanceNow["RestmMode"]) == 1) //如果是按照星期某休
  897. {
  898. //遍历7个星期字段,如果星期某是休息,那么算出该段时间内有几个星期某,累加在休息天数上
  899. //-1是因为要算改变前的那一天。
  900. //同时算出该月可休多少天,以及担当该工种时间内可休多少天
  901. if (Convert.ToInt32(drAttendanceNow["Monday"]) == 0)
  902. {
  903. restDaysMouth += TotalWeeks(Convert.ToDateTime(_salaryDateS),
  904. Convert.ToDateTime(_salaryDateE).AddDays(-1), DayOfWeek.Monday);
  905. restDaysNow += TotalWeeks(StartTime, EndTime.AddDays(-1), DayOfWeek.Monday);
  906. }
  907. if (Convert.ToInt32(drAttendanceNow["Tuesday"]) == 0)
  908. {
  909. restDaysMouth += TotalWeeks(Convert.ToDateTime(_salaryDateS),
  910. Convert.ToDateTime(_salaryDateE).AddDays(-1), DayOfWeek.Tuesday);
  911. restDaysNow += TotalWeeks(StartTime, EndTime.AddDays(-1), DayOfWeek.Tuesday);
  912. }
  913. if (Convert.ToInt32(drAttendanceNow["Wednesday"]) == 0)
  914. {
  915. restDaysMouth += TotalWeeks(Convert.ToDateTime(_salaryDateS),
  916. Convert.ToDateTime(_salaryDateE).AddDays(-1), DayOfWeek.Wednesday);
  917. restDaysNow += TotalWeeks(StartTime, EndTime.AddDays(-1), DayOfWeek.Wednesday);
  918. }
  919. if (Convert.ToInt32(drAttendanceNow["Thursday"]) == 0)
  920. {
  921. restDaysMouth += TotalWeeks(Convert.ToDateTime(_salaryDateS),
  922. Convert.ToDateTime(_salaryDateE).AddDays(-1), DayOfWeek.Thursday);
  923. restDaysNow += TotalWeeks(StartTime, EndTime.AddDays(-1), DayOfWeek.Thursday);
  924. }
  925. if (Convert.ToInt32(drAttendanceNow["Friday"]) == 0)
  926. {
  927. restDaysMouth += TotalWeeks(Convert.ToDateTime(_salaryDateS),
  928. Convert.ToDateTime(_salaryDateE).AddDays(-1), DayOfWeek.Friday);
  929. restDaysNow += TotalWeeks(StartTime, EndTime.AddDays(-1), DayOfWeek.Friday);
  930. }
  931. if (Convert.ToInt32(drAttendanceNow["Saturday"]) == 0)
  932. {
  933. restDaysMouth += TotalWeeks(Convert.ToDateTime(_salaryDateS),
  934. Convert.ToDateTime(_salaryDateE).AddDays(-1), DayOfWeek.Saturday);
  935. restDaysNow += TotalWeeks(StartTime, EndTime.AddDays(-1), DayOfWeek.Saturday);
  936. }
  937. if (Convert.ToInt32(drAttendanceNow["Sunday"]) == 0)
  938. {
  939. restDaysMouth += TotalWeeks(Convert.ToDateTime(_salaryDateS),
  940. Convert.ToDateTime(_salaryDateE).AddDays(-1), DayOfWeek.Sunday);
  941. restDaysNow += TotalWeeks(StartTime, EndTime.AddDays(-1), DayOfWeek.Sunday);
  942. }
  943. }
  944. else //反之,无论月可休息日以及阶段可休息日统一为可休息天数
  945. {
  946. restDaysNow = Convert.ToInt32(drAttendanceNow["RestDays"]);
  947. restDaysMouth = Convert.ToInt32(drAttendanceNow["RestDays"]);
  948. }
  949. }
  950. else
  951. {
  952. //如果没有考核策略,那么直接月基本工资/月应出勤天数*履历天数
  953. return 0;
  954. }
  955. //用结算天数-休息天数(月),得出应出勤天数(月)
  956. int AttendanceDayMouth = _mouthDay - restDaysMouth;
  957. //基本工资(月)/应出勤天数(月),得出日工资
  958. daySalrty = Math.Round(Convert.ToDecimal(BasicSalaryMouth / AttendanceDayMouth), 2);
  959. //获取该工种持续时间的出勤情况
  960. DataTable dtStaffAttendance = _dsBase.Tables[1].Copy();
  961. dtStaffAttendance.DefaultView.RowFilter = " StaffID = " + StaffId;
  962. DataTable dtStaffAttendanceNow = dtStaffAttendance.DefaultView.ToTable();
  963. double realDay = 0; //实际出勤天数
  964. foreach (DataRow drFor in dtStaffAttendanceNow.Rows)
  965. {
  966. int Status = Convert.ToInt32(drFor["AttendanceStatus"]);
  967. DateTime AttendanceDate = Convert.ToDateTime(drFor["AttendanceDate"]);
  968. if (AttendanceDate >= StartTime && AttendanceDate < EndTime) //必须是此工种持续时间范围内的
  969. {
  970. if (Status == 1)
  971. {
  972. realDay += 1;
  973. }
  974. else if (Status == 2)
  975. {
  976. realDay += 0.5;
  977. }
  978. }
  979. }
  980. double QDay = JobsDay - realDay; //缺勤天数
  981. double SQDay = QDay - restDaysNow; //实际缺勤天数(缺勤天数 - 休息天数)
  982. decimal KMoney = 0;
  983. //最终判断
  984. //如果出勤扣罚的类型是工资百分比,那么直接计算出勤天数即可
  985. //反之如果是阶梯扣罚,那么就要用日工资*工种阶段天数 - 缺勤天数对应的阶梯扣罚单价*缺勤天数
  986. if (PunishMode == 1)
  987. {
  988. //如果实际出勤天数大于等于应出勤天数,直接满勤即可。
  989. if (AttendanceDayMouth <= Convert.ToDecimal(realDay))
  990. {
  991. BisicSalary += BasicSalaryMouth;
  992. }
  993. else
  994. {
  995. BisicSalary += Convert.ToDecimal(realDay) * daySalrty;
  996. }
  997. if (SQDay > 0)
  998. {
  999. KMoney = Convert.ToDecimal(SQDay) * daySalrty;
  1000. }
  1001. else
  1002. {
  1003. KMoney += 0;
  1004. }
  1005. }
  1006. else
  1007. {
  1008. //阶梯扣罚单价
  1009. decimal ladderPrice = 0;
  1010. //遍历获取到的阶梯扣罚区间,当实际缺勤天数小于零,要计算缺勤阶梯价格
  1011. if (SQDay > 0)
  1012. {
  1013. foreach (DataRow drFor in dtAttendanceNow.Rows)
  1014. {
  1015. int StartDay = Convert.ToInt32(drFor["BeginAbsentDays"]);
  1016. int EndDay = Convert.ToInt32(drFor["EndAbsentDays"]);
  1017. if (SQDay >= StartDay && SQDay <= EndDay)
  1018. {
  1019. ladderPrice = Convert.ToDecimal(drFor["PunishAmount"]);
  1020. }
  1021. }
  1022. BisicSalary += BasicSalaryMouth - ladderPrice * Convert.ToDecimal(SQDay);
  1023. KMoney += ladderPrice * Convert.ToDecimal(SQDay);
  1024. }
  1025. else //如果没有缺勤甚至还存在加班的话,暂不算加班时间,即(应出勤天数 - 应休息天数) * 日工资
  1026. {
  1027. BisicSalary += BasicSalaryMouth;
  1028. KMoney += 0;
  1029. }
  1030. }
  1031. #region 此阶段结算完毕后,要向数据集中添加数据(基本工资明细)。
  1032. //基本工资明细
  1033. DataRow drBasicSalary = _dtBasicSalary.NewRow();
  1034. drBasicSalary["StaffID"] = StaffId;
  1035. drBasicSalary["JobsID"] = JobsId;
  1036. drBasicSalary["SalaryType"] = JobsStatus;
  1037. drBasicSalary["BeginDate"] = StartTime;
  1038. drBasicSalary["EndDate"] = EndTime;
  1039. drBasicSalary["BasicSalary"] = BisicSalary;
  1040. drBasicSalary["Subsidy"] = Subsidy;
  1041. drBasicSalary["CheckedDays"] = AttendanceDayMouth;
  1042. drBasicSalary["AttendanceDays"] = realDay;
  1043. drBasicSalary["AbsenceDays"] = SQDay > 0 ? SQDay : 0;
  1044. drBasicSalary["FineAmount"] = KMoney;
  1045. drBasicSalary["TotalAmount"] = BisicSalary + Subsidy;
  1046. _dtBasicSalary.Rows.Add(drBasicSalary);
  1047. #endregion
  1048. return BisicSalary + Subsidy;
  1049. }
  1050. catch(Exception ex)
  1051. {
  1052. throw ex;
  1053. }
  1054. }
  1055. public decimal GetASalaryByJobsId(int StaffId, int JobsId, int JobsStatus, DateTime StartTime, DateTime EndTime)
  1056. {
  1057. try
  1058. {
  1059. //该员工行政考核总额
  1060. decimal ASalary = 0;
  1061. //获取该员工相关的行政奖惩信息
  1062. DataTable dtAdmin = _dsBase.Tables[2].Copy();
  1063. dtAdmin.DefaultView.RowFilter = " StaffId = " + StaffId;
  1064. DataTable dtAdminNow = dtAdmin.DefaultView.ToTable();
  1065. //获取全部行政考核策略明细,并根据工种和员工状态筛选
  1066. DataTable dtAdminDetail = _dsStrategy.Tables[5].Copy();
  1067. dtAdminDetail.DefaultView.RowFilter = " JobsID = " + JobsId + " and SalaryType = " + (JobsStatus - 1);
  1068. DataTable dtAdminDetailNow = dtAdminDetail.DefaultView.ToTable();
  1069. if (dtAdminDetailNow.Rows.Count != 0)
  1070. {
  1071. //如果有对应策略,那么遍历这些策略明细
  1072. foreach (DataRow drAdminDetailFor in dtAdminDetailNow.Rows)
  1073. {
  1074. //获取该策略明细的基础金额以及是否扣完的标签
  1075. decimal BaseAmount = Convert.ToDecimal(drAdminDetailFor["BaseAmount"]);
  1076. int IsEnd = Convert.ToInt32(drAdminDetailFor["IsEnd"]);
  1077. decimal TotalAmount = BaseAmount;
  1078. decimal RAPAmount = 0;
  1079. //并进一步过滤行政奖惩信息(根据该策略的行政考核类别)
  1080. dtAdminNow.DefaultView.RowFilter = " AdministrationType = " + drAdminDetailFor["AdministrationType"];
  1081. DataTable dtAdminNowByAType = dtAdminNow.DefaultView.ToTable();
  1082. //然后遍历该时间段内的该策略对应的考核类别的奖惩信息,进行加减运算
  1083. foreach (DataRow drFor in dtAdminNowByAType.Rows)
  1084. {
  1085. //遍历每一条奖惩信息,如果在该履历变动时间范围内并且奖惩类别相同的话,就根据字段进行加减运算
  1086. DateTime dtAuditDate = Convert.ToDateTime(drFor["AccountDate"]);
  1087. if (dtAuditDate >= StartTime && dtAuditDate <= EndTime)
  1088. {
  1089. RAPAmount += Convert.ToDecimal(drFor["RAPType"]) * Convert.ToDecimal(drFor["RAPAmount"]);
  1090. //添加明细
  1091. DataRow drAddSsmAdminDetail = _dtAdminDetail.NewRow();
  1092. drAddSsmAdminDetail["AdminRAPID"] = drFor["RAPID"];
  1093. drAddSsmAdminDetail["StaffID"] = StaffId;
  1094. //在AdminID字段中存一个策略ID,以便在后台插入时,区分哪些明细对应哪个策略
  1095. drAddSsmAdminDetail["AdminID"] = drAdminDetailFor["AdministrationID"];
  1096. drAddSsmAdminDetail["AccountId"] = drAdminDetailFor["SalaryType"];
  1097. drAddSsmAdminDetail["StaffSalaryID"] = drAdminDetailFor["JobsId"];
  1098. _dtAdminDetail.Rows.Add(drAddSsmAdminDetail);
  1099. }
  1100. }
  1101. //遍历完成后,根据结果以及扣完为止的标签,对总值进行相加
  1102. TotalAmount = BaseAmount + RAPAmount;
  1103. if (IsEnd == 1 && TotalAmount < 0)
  1104. {
  1105. TotalAmount = 0;
  1106. }
  1107. ASalary += TotalAmount;
  1108. //保存行政考核结算信息
  1109. DataRow drAddSsmAdmin = _dtAdmin.NewRow();
  1110. drAddSsmAdmin["StaffID"] = StaffId;
  1111. drAddSsmAdmin["JobsID"] = JobsId;
  1112. drAddSsmAdmin["SalaryType"] = JobsStatus - 1;
  1113. drAddSsmAdmin["BeginDate"] = _salaryDateS;
  1114. drAddSsmAdmin["EndDate"] = _salaryDateE;
  1115. drAddSsmAdmin["TATAdminID"] = drAdminDetailFor["AdministrationID"];
  1116. drAddSsmAdmin["AdministrationType"] = drAdminDetailFor["AdministrationType"];
  1117. drAddSsmAdmin["BaseAmount"] = BaseAmount;
  1118. drAddSsmAdmin["IsEnd"] = IsEnd;
  1119. drAddSsmAdmin["RAPAmount"] = RAPAmount;
  1120. drAddSsmAdmin["TotalAmount"] = TotalAmount;
  1121. _dtAdmin.Rows.Add(drAddSsmAdmin);
  1122. }
  1123. }
  1124. else
  1125. {
  1126. return 0;
  1127. }
  1128. return ASalary;
  1129. }
  1130. catch(Exception ex)
  1131. {
  1132. throw ex;
  1133. }
  1134. }
  1135. public decimal GetPSalaryByJobsId(int StaffId, int JobsId, int JobsStatus, DateTime StartTime, DateTime EndTime)
  1136. {
  1137. try
  1138. {
  1139. //该员工进度考核总额
  1140. decimal PSalary = 0;
  1141. //获取该员工相关的进度奖惩信息
  1142. DataTable dtProgress = _dsBase.Tables[4].Copy();
  1143. dtProgress.DefaultView.RowFilter = " StaffId = " + StaffId;
  1144. DataTable dtProgressNow = dtProgress.DefaultView.ToTable();
  1145. //获取全部行政考核策略明细,并根据工种和员工状态筛选
  1146. DataTable dtProgressDetail = _dsStrategy.Tables[6].Copy();
  1147. dtProgressDetail.DefaultView.RowFilter = " JobsID = " + JobsId + " and SalaryType = " + (JobsStatus - 1);
  1148. DataTable dtProgressDetailNow = dtProgressDetail.DefaultView.ToTable();
  1149. if (dtProgressDetailNow.Rows.Count != 0)
  1150. {
  1151. //如果有对应策略,那么遍历这些策略明细
  1152. foreach (DataRow drProgressDetailFor in dtProgressDetailNow.Rows)
  1153. {
  1154. //获取该策略明细的基础金额以及是否扣完的标签
  1155. decimal BaseAmount = Convert.ToDecimal(drProgressDetailFor["BaseAmount"]);
  1156. int IsEnd = Convert.ToInt32(drProgressDetailFor["IsEnd"]);
  1157. decimal TotalAmount = BaseAmount;
  1158. decimal RAPAmount = 0;
  1159. //然后遍历该时间段内的该策略对应的奖惩信息,进行加减运算
  1160. foreach (DataRow drFor in dtProgressNow.Rows)
  1161. {
  1162. //遍历每一条奖惩信息,如果在该履历变动时间范围内并且奖惩类别相同的话,就根据字段进行加减运算
  1163. DateTime dtAuditDate = Convert.ToDateTime(drFor["AccountDate"]);
  1164. if (dtAuditDate >= StartTime && dtAuditDate <= EndTime)
  1165. {
  1166. RAPAmount += Convert.ToDecimal(drFor["RAPType"]) * Convert.ToDecimal(drFor["RAPAmount"]);
  1167. //添加明细
  1168. DataRow drAddSsmProgressDetail = _dtProgressDetail.NewRow();
  1169. drAddSsmProgressDetail["ProgressRAPID"] = drFor["RAPID"];
  1170. drAddSsmProgressDetail["StaffID"] = StaffId;
  1171. //将工种以及状态保存起来,后台录入时,区分明细归属于哪个主体信息
  1172. drAddSsmProgressDetail["ProgressID"] = drProgressDetailFor["JobsId"];
  1173. drAddSsmProgressDetail["AccountID"] = drProgressDetailFor["SalaryType"];
  1174. _dtProgressDetail.Rows.Add(drAddSsmProgressDetail);
  1175. }
  1176. }
  1177. //遍历完成后,根据结果以及扣完为止的标签,对总值进行相加
  1178. TotalAmount = BaseAmount + RAPAmount;
  1179. if (IsEnd == 1 && TotalAmount < 0)
  1180. {
  1181. continue;
  1182. }
  1183. else
  1184. {
  1185. PSalary += TotalAmount;
  1186. }
  1187. //保存行政考核结算信息
  1188. DataRow drAddSsmProgress = _dtProgress.NewRow();
  1189. drAddSsmProgress["StaffID"] = StaffId;
  1190. drAddSsmProgress["JobsID"] = JobsId;
  1191. drAddSsmProgress["SalaryType"] = JobsStatus - 1;
  1192. drAddSsmProgress["BeginDate"] = _salaryDateS;
  1193. drAddSsmProgress["EndDate"] = _salaryDateE;
  1194. drAddSsmProgress["TATProgressID"] = drProgressDetailFor["ProgressID"];
  1195. drAddSsmProgress["BaseAmount"] = BaseAmount;
  1196. drAddSsmProgress["IsEnd"] = IsEnd;
  1197. drAddSsmProgress["RAPAmount"] = RAPAmount;
  1198. drAddSsmProgress["TotalAmount"] = TotalAmount;
  1199. _dtProgress.Rows.Add(drAddSsmProgress);
  1200. }
  1201. }
  1202. else
  1203. {
  1204. return 0;
  1205. }
  1206. return PSalary;
  1207. }
  1208. catch(Exception ex)
  1209. {
  1210. throw ex;
  1211. }
  1212. }
  1213. private void CreateTable()
  1214. {
  1215. try
  1216. {
  1217. //首先根据主ID查询工资总汇数据集,如果是新建结算那么主ID会等于零,即查回一个空集。
  1218. //(包括其他各项工资明细的集合,目的是在添加时可直接向表中添加内容)
  1219. DataSet dsSourse = HRModuleProxy.Service.GetSettlementDetail(_mainId);
  1220. _dtStaffSalary = dsSourse.Tables[0];
  1221. if (_mainId == 0) //只有在新建时,才带回这些表结构,调整时是不允许修改这些的
  1222. {
  1223. _dtBasicSalary = dsSourse.Tables[1];
  1224. _dtAttendance = dsSourse.Tables[2];
  1225. _dtWages = dsSourse.Tables[3];
  1226. _dtDefectFine = dsSourse.Tables[4];
  1227. _dtScrapFine = dsSourse.Tables[5];
  1228. _dtAdmin = dsSourse.Tables[6];
  1229. _dtAdminDetail = dsSourse.Tables[7];
  1230. _dtProgress = dsSourse.Tables[8];
  1231. _dtProgressDetail = dsSourse.Tables[9];
  1232. _dtManagerSalary = dsSourse.Tables[10];
  1233. }
  1234. else
  1235. {
  1236. _dtMain = dsSourse.Tables[1];
  1237. }
  1238. }
  1239. catch(Exception ex)
  1240. {
  1241. throw ex;
  1242. }
  1243. }
  1244. private void dgvSettlement_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  1245. {
  1246. try
  1247. {
  1248. if (this.dgvSettlement.Rows[e.RowIndex].Cells["StaffSalaryID"].Value != DBNull.Value &&
  1249. this.dgvSettlement.Rows[e.RowIndex].Cells["StaffSalaryID"].Value != null)
  1250. {
  1251. int StaffSalaryId = Convert.ToInt32(this.dgvSettlement.Rows[e.RowIndex].Cells["StaffSalaryID"].Value);
  1252. int StaffId = Convert.ToInt32(this.dgvSettlement.Rows[e.RowIndex].Cells["StaffId"].Value);
  1253. string StaffName = this.dgvSettlement.Rows[e.RowIndex].Cells["StaffName"].Value.ToString();
  1254. //以新建模式打开信息窗体
  1255. F_HR_1203 frmHR1203 = new F_HR_1203(StaffSalaryId, StaffId, StaffName);
  1256. DialogResult dialogResult = frmHR1203.ShowDialog();
  1257. }
  1258. }
  1259. catch (Exception ex)
  1260. {
  1261. // 对异常进行共通处理
  1262. ExceptionManager.HandleEventException(this.ToString(),
  1263. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1264. }
  1265. }
  1266. private void dgvSettlement_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  1267. {
  1268. try
  1269. {
  1270. if (e.RowIndex != -1)
  1271. {
  1272. DataGridViewRow gvrNow = this.dgvSettlement.Rows[e.RowIndex];
  1273. //调整金额改变
  1274. if (this.dgvSettlement.Columns[e.ColumnIndex].Name == "AdjustmentAmount")
  1275. {
  1276. gvrNow.Cells["TotalAmount"].Value = Convert.ToDecimal(gvrNow.Cells["SettlementAmount"].Value)
  1277. + Convert.ToDecimal(gvrNow.Cells["AdjustmentAmount"].Value);
  1278. }
  1279. }
  1280. }
  1281. catch(Exception ex)
  1282. {
  1283. // 对异常进行共通处理
  1284. ExceptionManager.HandleEventException(this.ToString(),
  1285. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1286. }
  1287. }
  1288. /// <summary>
  1289. /// 获取调整总金额与合计总金额
  1290. /// </summary>
  1291. private void GetAdjustmentAmount()
  1292. {
  1293. foreach(DataGridViewRow gvrFor in this.dgvSettlement.Rows)
  1294. {
  1295. _adjustmentAmount += Convert.ToDecimal(gvrFor.Cells["AdjustmentAmount"].Value);
  1296. if (_formType == Constant.FormMode.Edit)
  1297. {
  1298. _salaryTotalMoney += Convert.ToDecimal(gvrFor.Cells["SettlementAmount"].Value);
  1299. }
  1300. }
  1301. }
  1302. private void btnSettlement_Click(object sender, EventArgs e)
  1303. {
  1304. try
  1305. {
  1306. GetBaseData();
  1307. if(_nowSettlement == 1)
  1308. {
  1309. this.btnSettlement.Enabled = false;
  1310. }
  1311. else
  1312. {
  1313. this.btnSettlement.Enabled = true;
  1314. }
  1315. }
  1316. catch (Exception ex)
  1317. {
  1318. // 对异常进行共通处理
  1319. ExceptionManager.HandleEventException(this.ToString(),
  1320. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1321. }
  1322. }
  1323. private void btnSelect_Click(object sender, EventArgs e)
  1324. {
  1325. try
  1326. {
  1327. if (_nowSettlement == 0)
  1328. {
  1329. MessageBox.Show("当前页未成功进行结算,无法进行筛选!",
  1330. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1331. return;
  1332. }
  1333. else
  1334. {
  1335. StringBuilder sbRow = new StringBuilder();
  1336. sbRow.Append (" 1=1");
  1337. if(!string.IsNullOrEmpty(this.txtName.Text))
  1338. {
  1339. sbRow.Append("and StaffName like '%" + this.txtName.Text + "%'");
  1340. }
  1341. if(!string.IsNullOrEmpty(this.txtOrg.Text))
  1342. {
  1343. sbRow.Append("and OrganizationName like '%" + this.txtOrg.Text + "%'");
  1344. }
  1345. _dtStaffSalary.DefaultView.RowFilter = sbRow.ToString();
  1346. this.dgvSettlement.IsSetInputColumnsColor = true;
  1347. }
  1348. }
  1349. catch(Exception ex)
  1350. {
  1351. // 对异常进行共通处理
  1352. ExceptionManager.HandleEventException(this.ToString(),
  1353. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1354. }
  1355. }
  1356. }
  1357. }