public void Insert(Model.Leave leave, IList <Model.Employee> empList) { Validate(leave); //for (int i = 0; i < a; i++) //{ // if (i > 0) // { // leave.LeaveId = Guid.NewGuid().ToString(); // leave.LeaveDate = leave.LeaveDate.Value.Date.AddDays(1); // } // leave.LeaveRange = 0; // accessor.Insert(leave); //} //if (a < leave.LeaveDateCount.Value) //{ // leave.LeaveId = Guid.NewGuid().ToString(); // leave.LeaveDate = leave.LeaveDate.Value.Date.AddDays(1); // leave.LeaveRange = 1; // accessor.Insert(leave); //} IList <Model.Leave> mLeaveList; StringBuilder sb = new StringBuilder(); foreach (Model.Employee emp in empList) { sb.Append("'" + emp.EmployeeId + "',"); } mLeaveList = this.SelectLeaveListbyEmp(sb.ToString().Substring(0, sb.ToString().Length - 1)); //获得假期列表 IList <Model.AnnualHoliday> holidaylist = new BL.AnnualHolidayManager().SelectBigThanDate(DateTime.Parse(DateTime.Now.Date.AddMonths(-1).ToString("yyyy-MM-01"))); bool cando; try { BL.V.BeginTransaction(); Model.Leave model; int flag = 0; decimal a = Math.Truncate(leave.LeaveDateCount.Value); foreach (Model.Employee emp in empList) { if (a > 1) { for (int i = 0; i < a; i++) { cando = holidaylist.Any(mel => mel.HolidayDate.Value.Date == leave.LeaveDate.Value.AddDays(i).Date); if (cando) { continue; } cando = mLeaveList.Any(mle => mle.LeaveDate.Value.ToString("yyyy-MM-dd") == leave.LeaveDate.Value.AddDays(i).ToString("yyyy-MM-dd") && mle.LeaveRange.Value == leave.LeaveRange.Value && mle.EmployeeId == emp.EmployeeId); if (cando) { //continue; throw new Helper.MessageValueException(emp.EmployeeName + " " + leave.LeaveDate.Value.AddDays(i).ToString("yyyy-MM-dd") + " 已有請假記錄,請查證。"); } //if (hrDatilyManager.SelectByDateAndEmp(emp.EmployeeId, leave.LeaveDate.Value.AddDays(i)) != null && leave.LeaveRange == 0) // throw new Helper.MessageValueException(emp.EmployeeName + " " + leave.LeaveDate.Value.AddDays(i).ToString("yyyy-MM-dd") + " 已有出勤記錄,請查證。"); model = new Book.Model.Leave(); model.EmployeeId = emp.EmployeeId; model.LeaveDate = leave.LeaveDate.Value.Date.AddDays(i); model.LeaveDateCount = leave.LeaveDateCount; if (flag == 0) { model.LeaveId = leave.LeaveId; } else { model.LeaveId = Guid.NewGuid().ToString(); } model.LeaveRange = leave.LeaveRange; model.LeaveText = leave.LeaveText; model.LeaveTypeId = leave.LeaveTypeId; accessor.Insert(model); //增加列表 //mLeaveList.Add(model); if (DateTime.Now.Date > model.LeaveDate) { hrDatilyManager.ReCheck(leave.LeaveDate.Value.Date, leave.Employee); } flag = 1; } } else { //cando = holidaylist.Any(mel => mel.HolidayDate.Value.Date == leave.LeaveDate.Value.Date); //if (cando) // throw new Helper.InvalidValueException(Model.Leave.PRO_LeaveDate + "_IsHoliday"); cando = mLeaveList.Any(mle => mle.LeaveDate.Value.ToString("yyyy-MM-dd") == leave.LeaveDate.Value.ToString("yyyy-MM-dd") && mle.LeaveRange.Value == leave.LeaveRange.Value && mle.EmployeeId == emp.EmployeeId); if (cando) { //throw new Helper.InvalidValueException(Model.Leave.PRO_LeaveId + "_1"); throw new Helper.MessageValueException(emp.EmployeeName + " " + leave.LeaveDate.Value.ToString("yyyy-MM-dd") + " 已有請假記錄,請查證。"); } //if (hrDatilyManager.SelectByDateAndEmp(emp.EmployeeId, leave.LeaveDate.Value) != null && leave.LeaveRange == 0) // throw new Helper.MessageValueException(emp.EmployeeName + " " + leave.LeaveDate.Value.ToString("yyyy-MM-dd") + " 已有出勤記錄,請查證。"); model = new Book.Model.Leave(); model.EmployeeId = emp.EmployeeId; model.LeaveDate = leave.LeaveDate.Value.Date; model.LeaveDateCount = leave.LeaveDateCount; if (flag == 0) { model.LeaveId = leave.LeaveId; } else { model.LeaveId = Guid.NewGuid().ToString(); } model.LeaveRange = leave.LeaveRange; model.LeaveText = leave.LeaveText; model.LeaveTypeId = leave.LeaveTypeId; accessor.Insert(model); //增加列表项 //mLeaveList.Add(model); hrDatilyManager.ReCheck(leave.LeaveDate.Value.Date, leave.Employee); flag = 1; } } BL.V.CommitTransaction(); } catch (Exception ex) { BL.V.RollbackTransaction(); throw; } }
public void Insert(Model.Leave leave) { Validate(leave); Model.Leave model; int flag = 0; decimal a = Math.Truncate(leave.LeaveDateCount.Value); IList <Model.Leave> mLeaveList = this.SelectLeaveListbyEmp("'" + leave.EmployeeId + "'"); //获得假期列表 IList <Model.AnnualHoliday> holidaylist = new BL.AnnualHolidayManager().SelectBigThanDate(leave.LeaveDate.Value); bool cando; #region 注释 //decimal a = Math.Truncate(leave.LeaveDateCount.Value); //for (int i = 0; i < a; i++) //{ // if (i > 0) // { // leave.LeaveId = Guid.NewGuid().ToString(); // leave.LeaveDate = leave.LeaveDate.Value.Date.AddDays(1); // } // leave.LeaveRange = 0; // accessor.Insert(leave); //} //if (a < leave.LeaveDateCount.Value) //{ // leave.LeaveId = Guid.NewGuid().ToString(); // leave.LeaveDate = leave.LeaveDate.Value.Date.AddDays(1); // leave.LeaveRange = 1; // accessor.Insert(leave); //} #endregion try { BL.V.BeginTransaction(); if (a > 1) { for (int i = 0; i < a; i++) { cando = holidaylist.Any(mel => mel.HolidayDate.Value.Date == leave.LeaveDate.Value.AddDays(i).Date); if (cando) { continue; } cando = mLeaveList.Any(mle => mle.LeaveDate.Value.ToString("yyyy-MM-dd") == leave.LeaveDate.Value.AddDays(i).ToString("yyyy-MM-dd") && mle.LeaveRange.Value == leave.LeaveRange.Value); if (cando) { //continue; throw new Helper.MessageValueException(leave.LeaveDate.Value.AddDays(i).ToString("yyyy-MM-dd") + " 已有請假記錄,請查證。"); } //Model.HrDailyEmployeeAttendInfo hr = hrDatilyManager.SelectByDateAndEmp(leave.EmployeeId,leave.LeaveDate.Value.AddDays(i)); //if (hrDatilyManager.SelectByDateAndEmp(leave.EmployeeId, leave.LeaveDate.Value.AddDays(i)) != null && leave.LeaveRange == 0) // throw new Helper.MessageValueException(leave.LeaveDate.Value.AddDays(i).ToString("yyyy-MM-dd") + " 已有出勤記錄,請查證。"); model = new Book.Model.Leave(); model.EmployeeId = leave.EmployeeId; model.LeaveDate = leave.LeaveDate.Value.Date.AddDays(i); model.LeaveDateCount = leave.LeaveDateCount; if (flag == 0) { model.LeaveId = leave.LeaveId; } else { model.LeaveId = Guid.NewGuid().ToString(); } model.LeaveRange = leave.LeaveRange; model.LeaveText = leave.LeaveText; model.LeaveTypeId = leave.LeaveTypeId; accessor.Insert(model); //增加列表项 //mLeaveList.Add(model); if (DateTime.Now.Date > model.LeaveDate) { hrDatilyManager.ReCheck(leave.LeaveDate.Value.Date, leave.Employee); } flag = 1; } } else { //cando = holidaylist.Any(mel => mel.HolidayDate.Value.Date == leave.LeaveDate.Value.Date); //if (cando) // throw new Helper.InvalidValueException(Model.Leave.PRO_LeaveDate + "_IsHoliday"); cando = mLeaveList.Any(mle => mle.LeaveDate.Value.ToString("yyyy-MM-dd") == leave.LeaveDate.Value.ToString("yyyy-MM-dd") && mle.LeaveRange.Value == leave.LeaveRange.Value); if (cando) { //throw new Helper.InvalidValueException(Model.Leave.PRO_LeaveId + "_1"); throw new Helper.MessageValueException(leave.LeaveDate.Value.ToString("yyyy-MM-dd") + " 已有請假記錄,請查證。"); } //if (hrDatilyManager.SelectByDateAndEmp(leave.EmployeeId, leave.LeaveDate.Value) != null && leave.LeaveRange == 0) // throw new Helper.MessageValueException(leave.LeaveDate.Value.ToString("yyyy-MM-dd") + " 已有出勤記錄,請查證。"); accessor.Insert(leave); hrDatilyManager.ReCheck(leave.LeaveDate.Value.Date, leave.Employee); } BL.V.CommitTransaction(); } catch (Exception ex) { BL.V.RollbackTransaction(); throw ex; } }