private void btn重新同步_Click(object sender, EventArgs e) { if (MessageBox.Show("重新同步后需重新审核,确实重新同步吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, 0, false) == DialogResult.Yes) { Thread.Sleep(200); CreateWaitDialog("正在同步...", "请耐心等待"); //删除历史数据 SalaryAuditingResult.ClearAuditingResult((string)cbb日历组.EditValue, (string)ccb薪资组.EditValue); //删除工资表 PrivateSalary.ClearPrivateSalary((string)cbb日历组.EditValue, (string)ccb薪资组.EditValue); //清除旧的抽查记录 PayCheckRecord.ClearPayCheckRecord((string)cbb日历组.EditValue, (string)ccb薪资组.EditValue); //同步基础工资 StringBuilder sb = SalaryResult.SychSalaryResult((string)cbb日历组.EditValue, (string)ccb薪资组.EditValue); //同步工资明细 StringBuilder sbItem = SalaryResultItem.SychSalaryResultItem((string)cbb日历组.EditValue, (string)ccb薪资组.EditValue); sb.Append(sbItem.ToString()); CloseWaitDialog(); MyHelper.WriteLog(LogType.信息, "重新同步上表工资", String.Format("日历组:{0}, {1} 薪资组: {2}, {3}", (string)cbb日历组.EditValue, cbb日历组.Text, (string)ccb薪资组.EditValue, ccb薪资组.Text)); string msg = sb.ToString(); if (string.IsNullOrEmpty(msg)) { LoadData(true); } else { MessageBox.Show(msg); } } SetButtonEnabled(); }
//产生抽查记录 private void GenerateCheckRecords() { int 最少抽查数 = (int)(员工工资计算器列表.Count * 0.1 + 0.9); var 薪等集合 = from p in 员工工资计算器列表 group p by p.评定职等 into g select g; List <PrivateSalary> 候选的记录 = GetWaiting(); List <PrivateSalary> 抽中的记录 = new List <PrivateSalary>(); //每个薪资组选择一条记录 foreach (var grade in 薪等集合) { List <PrivateSalary> items = 候选的记录.FindAll(a => a.评定职等 == grade.Key); if (items.Count > 0) { Random rdm = new Random(unchecked ((int)DateTime.Now.Ticks)); int x = (int)rdm.Next(0, items.Count); PrivateSalary selectedItem = items[x]; 抽中的记录.Add(selectedItem); //把选择的记录从候选表删除 候选的记录.Remove(selectedItem); } } //如果小于最少抽查数,继续抽查 while (抽中的记录.Count < 最少抽查数 && 候选的记录.Count > 0) { Random rdm = new Random(unchecked ((int)DateTime.Now.Ticks)); int x = (int)rdm.Next(0, 候选的记录.Count); PrivateSalary selectedItem = 候选的记录[x]; 抽中的记录.Add(selectedItem); //把选择的记录从候选表删除 候选的记录.Remove(selectedItem); } //清除旧的抽查记录 PayCheckRecord.ClearPayCheckRecord(日历组, 薪资组); //保存选中的记录 foreach (PrivateSalary item in 抽中的记录) { PayCheckRecord rec = PayCheckRecord.AddPayCheckRecord(item.标识); rec.抽取时间 = DateTime.Now; rec.薪资组 = item.薪资组; rec.日历组 = item.日历组; rec.Save(); } }