/// <summary> /// 处理自动生成的加班单的人员信息 /// </summary> /// <param name="infoTable">人员信息列表</param> /// <param name="saveFlag">保存标志</param> public void AutoCreateOverTime_BatchOperation(DataTable infoTable, bool saveFlag) { string error = null; DepotManagementDataContext ctx = CommentParameter.DepotDataContext; ctx.Connection.Open(); ctx.Transaction = ctx.Connection.BeginTransaction(); try { infoTable.AcceptChanges(); DataTable tempTable = DataSetHelper.SelectDistinct("", infoTable, "单据号"); foreach (DataRow dr in tempTable.Rows) { var varData = from a in ctx.HR_OvertimePersonnel where a.BillID == Convert.ToInt32(dr["单据号"]) select a; ctx.HR_OvertimePersonnel.DeleteAllOnSubmit(varData); DataTable tempTable1 = DataSetHelper.SiftDataTable(infoTable, " 单据号 = " + Convert.ToInt32(dr["单据号"]), out error); foreach (DataRow dr1 in tempTable1.Rows) { if (Convert.ToBoolean(dr1["选"])) { HR_OvertimePersonnel personnel = new HR_OvertimePersonnel(); personnel.BillID = Convert.ToInt32(dr["单据号"]); personnel.WorkID = dr1["人员工号"].ToString(); ctx.HR_OvertimePersonnel.InsertOnSubmit(personnel); } } if (!saveFlag) { var varBill = from a in ctx.HR_OvertimeBill where a.ID == Convert.ToInt32(dr["单据号"]) select a; HR_OvertimeBill billInfo = varBill.Single(); billInfo.Authorize = true; billInfo.BillStatus = "已完成"; } } ctx.SubmitChanges(); ctx.Transaction.Commit(); } catch (Exception ex) { ctx.Transaction.Rollback(); throw new Exception(ex.Message); } }
/// <summary> /// 新增加班申请 /// </summary> /// <param name="overTime">加班申请主信息</param> /// <param name="personnel">加班人员</param> /// <param name="error">错误信息</param> /// <returns>成功返回新增的单据编号,失败返回-1</returns> public int AddOverTimeBill(HR_OvertimeBill overTime, List <HR_OvertimePersonnel> personnel, out string error) { DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext; dataContxt.Connection.Open(); dataContxt.Transaction = dataContxt.Connection.BeginTransaction(); error = ""; try { var result = from a in dataContxt.HR_OvertimeBill where a.Applicant == overTime.Applicant && a.BeginTime == overTime.BeginTime select a; if (result.Count() > 0) { if (result.Count() == 1) { var resultList = from c in dataContxt.HR_OvertimePersonnel where c.BillID == result.Single().ID select c; foreach (HR_OvertimePersonnel item in resultList) { foreach (HR_OvertimePersonnel list in personnel) { if (item.WorkID == list.WorkID) { error = "同一员工不能在同一时间申请多个单据!"; return(-1); } } } } } dataContxt.HR_OvertimeBill.InsertOnSubmit(overTime); dataContxt.SubmitChanges(); int billID = -1; var resultOvertime = from a in dataContxt.HR_OvertimeBill where a.Applicant == overTime.Applicant && a.Date == overTime.Date && a.BeginTime == overTime.BeginTime select a; if (resultOvertime.Count() == 1) { billID = resultOvertime.Single().ID; foreach (var item in personnel) { HR_OvertimePersonnel personnleList = item; personnleList.BillID = billID; personnleList.WorkID = item.WorkID; new AttendanceAnalysis().DataTimeIsRepeat <HR_OvertimeBill>(dataContxt, resultOvertime.Single(), personnleList.WorkID); dataContxt.HR_OvertimePersonnel.InsertOnSubmit(personnleList); } } dataContxt.SubmitChanges(); dataContxt.Transaction.Commit(); return(billID); } catch (Exception ex) { error = ex.Message; dataContxt.Transaction.Rollback(); return(-1); } }
/// <summary> /// 修改加班申请 /// </summary> /// <param name="overTime">加班申请主信息</param> /// <param name="personnel">加班人员</param> /// <param name="billID">单据号</param> /// <param name="error">错误信息</param> /// <returns>成功返回true,失败返回False</returns> public bool UpdateOverTimeBill(HR_OvertimeBill overTime, List <HR_OvertimePersonnel> personnel, int billID, out string error) { error = ""; try { DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext; var resultMain = from a in dataContxt.HR_OvertimeBill where a.ID == billID select a; if (resultMain.Count() != 1) { error = "信息有误,请查证后再操作!"; return(false); } else { HR_OvertimeBill bill = resultMain.Single(); bill.BeginTime = overTime.BeginTime; bill.EndTime = overTime.EndTime; bill.VerifyHours = overTime.VerifyHours; bill.RealHours = overTime.RealHours; bill.CompensateMode = overTime.CompensateMode; bill.OvertimeAddress = overTime.OvertimeAddress; bill.Date = overTime.Date; bill.Errand = overTime.Errand; bill.Hours = overTime.Hours; bill.NumberOfPersonnel = overTime.NumberOfPersonnel; bill.BillStatus = overTime.BillStatus; } var result = from c in dataContxt.HR_OvertimePersonnel where c.BillID == billID select c; if (result.Count() > 0) { dataContxt.HR_OvertimePersonnel.DeleteAllOnSubmit(result); foreach (var item in personnel) { HR_OvertimePersonnel personnleList = item; personnleList.BillID = billID; personnleList.WorkID = item.WorkID; dataContxt.HR_OvertimePersonnel.InsertOnSubmit(personnleList); } } dataContxt.SubmitChanges(); return(true); } catch (Exception ex) { error = ex.Message; return(false); } }
private void 修改单据ToolStripMenuItem_Click(object sender, EventArgs e) { if (BasicInfo.LoginID == txtApplicant.Tag.ToString()) { if (lblStatus.Text == "已完成") { MessageDialog.ShowPromptMessage("单据已完成,不能修改!"); return; } if (!CheckControl()) { return; } List <HR_OvertimePersonnel> lstPersonnel = new List <HR_OvertimePersonnel>(dataGridView2.Rows.Count); for (int i = 0; i < dataGridView2.Rows.Count; i++) { HR_OvertimePersonnel personnel = new HR_OvertimePersonnel(); DataGridViewCellCollection cells = dataGridView2.Rows[i].Cells; personnel.WorkID = dataGridView2.Rows[i].Cells["员工编号"].Value.ToString(); lstPersonnel.Add(personnel); } HR_OvertimeBill overTimeBill = new HR_OvertimeBill(); overTimeBill.ID = Convert.ToInt32(m_billNo); overTimeBill.Authorize = false; overTimeBill.BeginTime = dtpBeginTime.Value; overTimeBill.CompensateMode = cmbCompensateMode.Text; overTimeBill.Date = dtpDate.Value; overTimeBill.OvertimeAddress = cmbOvertimeAddress.Text; overTimeBill.Errand = txtErrand.Text; overTimeBill.Hours = numHours.Value; overTimeBill.RealHours = Convert.ToDouble(numHours.Value); overTimeBill.NumberOfPersonnel = Convert.ToInt32(txtNumOfPersonnel.Text); overTimeBill.EndTime = dtpEndTime.Value; overTimeBill.VerifyHours = numVerifyHours.Value; IQueryable <View_HR_PersonnelArchive> directorGroup1 = m_personnerServer.GetDeptDirector( m_personnerServer.GetPersonnelInfo(txtApplicant.Tag.ToString()).Dept, "1"); bool flagPri = false; //判断申请人是不是负责人 bool isDeptDirector = false; //申请部门有没有主管 if (directorGroup1 != null && directorGroup1.Count() > 0) { foreach (var item in directorGroup1) { if (BasicInfo.LoginID == item.员工编号) { flagPri = true; break; } } } IQueryable <View_HR_PersonnelArchive> directorGroup = m_personnerServer.GetDeptDirector( m_personnerServer.GetPersonnelInfo(txtApplicant.Tag.ToString()).Dept, "0"); bool flag = false;//判断申请人是不是主管 if (directorGroup != null && directorGroup.Count() > 0) { isDeptDirector = true; foreach (var item in directorGroup) { if (BasicInfo.LoginID == item.员工编号) { flag = true; break; } } } if (!flag && !flagPri) { if (isDeptDirector) { overTimeBill.BillStatus = OverTimeBillStatus.等待主管审核.ToString(); } else { overTimeBill.BillStatus = OverTimeBillStatus.等待部门负责人审核.ToString(); } } else if (flag && !flagPri) { overTimeBill.BillStatus = OverTimeBillStatus.等待部门负责人审核.ToString(); } else { overTimeBill.BillStatus = OverTimeBillStatus.等待分管领导审批.ToString(); } if (!m_overTimeServer.UpdateOverTimeBill(overTimeBill, lstPersonnel, Convert.ToInt32(m_billNo), out error)) { MessageDialog.ShowPromptMessage(error); return; } MessageDialog.ShowPromptMessage("修改成功!"); m_billMessageServer.DestroyMessage(m_billNo); if (overTimeBill.BillStatus.Equals(OverTimeBillStatus.等待主管审核.ToString())) { m_billMessageServer.PassFlowMessage(m_billNo, string.Format("{0}号加班申请单,请主管审核", m_billNo), BillFlowMessage_ReceivedUserType.角色, m_billMessageServer.GetDeptDirectorRoleName(m_personnerServer.GetPersonnelViewInfo( txtApplicant.Tag.ToString()).部门编号).ToList()); } else if (overTimeBill.BillStatus == OverTimeBillStatus.等待部门负责人审核.ToString()) { m_billMessageServer.PassFlowMessage(m_billNo, string.Format("{0}号加班申请单,请部门负责人审核", m_billNo), BillFlowMessage_ReceivedUserType.角色, m_billMessageServer.GetDeptPrincipalRoleName( m_personnerServer.GetPersonnelViewInfo(txtApplicant.Tag.ToString()).部门编号).ToList()); } else { m_billMessageServer.PassFlowMessage(m_billNo, string.Format("{0}号加班申请单,请分管领导审核", m_billNo), BillFlowMessage_ReceivedUserType.角色, m_billMessageServer.GetDeptLeaderRoleName( m_personnerServer.GetPersonnelViewInfo(txtApplicant.Tag.ToString()).部门编号).ToList()); } } this.Close(); }