public DtoMessage InsertExeptionsDay(DtoExceptionDay exceptionDay) { using (var db = new KadrDataContext()) { try { var exception = new Exception { DateException = exceptionDay.Date, ExceptionName = exceptionDay.Name, idDayStatus = exceptionDay.DayStatus.IdDayStatus, KolHourGNS = exceptionDay.GNS, KolHourGPS = exceptionDay.GPS, KolHourMNS = exceptionDay.MNS, KolHourMPS = exceptionDay.MPS, idPrikaz = 1, idWorkShedule = exceptionDay.WorkShedule.IdWorkShedule }; db.Exception.InsertOnSubmit(exception); db.SubmitChanges(); return(new DtoMessage { Result = true }); } catch (System.Exception ex) { return(new DtoMessage { Result = false, Message = ex.Message + " " + ex.TargetSite }); } } }
public DtoMessage DeleteExeptionsDay(int idExceptionDay) { using (var db = new KadrDataContext()) { try { var exceptionDay = db.Exception.FirstOrDefault(f => f.id == idExceptionDay); if (exceptionDay != null) { db.Exception.DeleteOnSubmit(exceptionDay); } db.SubmitChanges(); return(new DtoMessage { Result = true }); } catch (System.Exception ex) { return(new DtoMessage { Result = false, Message = ex.Message }); } } }
public DtoMessage EditExeptionsDay(DtoExceptionDay exceptionDay) { using (var db = new KadrDataContext()) { try { var exception = db.Exception.FirstOrDefault(f => f.id == exceptionDay.IdExceptionDay); if (exception != null) { exception.DateException = exceptionDay.Date; exception.ExceptionName = exceptionDay.Name; exception.idDayStatus = exceptionDay.DayStatus.IdDayStatus; exception.KolHourGNS = exceptionDay.GNS; exception.KolHourGPS = exceptionDay.GPS; exception.KolHourMNS = exceptionDay.MNS; exception.KolHourMPS = exceptionDay.MPS; exception.idPrikaz = 1; exception.idWorkShedule = exceptionDay.WorkShedule.IdWorkShedule; } db.SubmitChanges(); return(new DtoMessage { Result = true }); } catch (System.Exception ex) { return(new DtoMessage { Result = false, Message = ex.Message }); } } }
public bool AddApproverForDepartment(int idEmployee, int idDepartment, int approveNumber) { using (var db = new KadrDataContext()) { try { var currentApprover = db.Approver.Where( f => f.idDepartment == idDepartment & f.ApproverType.ApproveNumber == approveNumber & f.DateEnd == null).ToArray(); foreach (var approver in currentApprover) { approver.DateEnd = DateTime.Now; } var newApprover = new Approver { idApproverType = db.ApproverType.Where(w => w.ApproveNumber == approveNumber).Select( s => s.id).FirstOrDefault(), idDepartment = idDepartment, idEmployee = idEmployee, DateBegin = DateTime.Now, DateEnd = null }; db.Approver.InsertOnSubmit(newApprover); db.SubmitChanges(); return(true); } catch (System.Exception) { return(false); } } }
public bool EditEmployeeRegim(int IdFactStaff, int IdWorkShedule, bool isPersonalRegim, int HoursWeek) { using (var db = new KadrDataContext()) { try { var fs = db.FactStaffs.FirstOrDefault(f => f.id == IdFactStaff); if (isPersonalRegim) //если это персональный режим { fs.idTimeSheetSheduleType = IdWorkShedule; } else { db.PlanStaff.FirstOrDefault(p => p.id == fs.idPlanStaff.Value).IdWorkShedule = IdWorkShedule; } fs.CurrentChange.WorkHoursInWeek = HoursWeek; db.SubmitChanges(); return(true); } catch (System.Exception) { return(false); } } }
public bool EditTimeSheetRecords(DtoTimeSheetRecord[] recordsForEdit) { using (var db = new KadrDataContext()) { try { foreach (var recordForEdit in recordsForEdit) { var updeteItem = db.TimeSheetRecords.FirstOrDefault( f => f.IdTimeSheetRecord == recordForEdit.IdTimeSheetRecord); if (updeteItem == null) { continue; } updeteItem.JobTimeCount = recordForEdit.JobTimeCount; updeteItem.NightTimeCount = (recordForEdit.NightTimeCount != "")? Convert.ToDouble(recordForEdit.NightTimeCount) : 0; updeteItem.idDayStatus = recordForEdit.DayStays.IdDayStatus; } db.SubmitChanges(); } catch (System.Exception) { return(false); } return(true); } }
//Генерация табеля для работников private void InsertEmployees(FactStaffWithHistory[] employees) { try { var exeptions = _db.Exception.Where( w => w.DateException >= _timeSheet.DateBeginPeriod && w.DateException <= _timeSheet.DateEndPeriod).ToArray(); var factStaffIds = employees.Select(s => s.id).Distinct(); var otpusk = _db.OK_Otpusks.Where( w => factStaffIds.Contains(w.idFactStaff) && w.DateBegin <= _timeSheet.DateEndPeriod && w.DateEnd >= _timeSheet.DateBeginPeriod).ToArray(); foreach (var employee in employees) { var employeeOtpusk = otpusk.Where(w => w.DateBegin.HasValue && w.idFactStaff == employee.id && w.DateBegin <= _timeSheet.DateEndPeriod && w.DateEnd >= _timeSheet.DateBeginPeriod).ToArray(); _timeSheetRecordLList.AddRange(InsertEmployee(employee, exeptions, employeeOtpusk)); } } catch (System.Exception ex) { _db.TimeSheet.DeleteAllOnSubmit(_db.TimeSheet.Where(w => w.id == IdTimeSheet)); _db.SubmitChanges(); var sb = new StringBuilder(); sb.AppendLine("Формирование табеля завершилось неудачей"); if (employees.Any(a => a.PlanStaff.IdWorkShedule == null)) { foreach (var employee in employees.Where(w => w.PlanStaff.IdWorkShedule == null)) { sb.AppendLine(string.Format(" {0} {1} {2}", employee.Employee.LastName, employee.Employee.FirstName, employee.Employee.Otch)); } sb.AppendLine(); sb.AppendLine("Для устранения проблемы обратитесь в отдел управления кадрами."); } sb.AppendLine(ex.Message); throw new System.Exception(sb.ToString()); } }
public void DelFakeTimeSheet(int id) { using (var db = new KadrDataContext()) { var ts = db.TimeSheet.FirstOrDefault(f => f.id == id); if (ts == null || !ts.IsFake) { throw new System.Exception("Fake timeSheet delition proplems"); } db.TimeSheet.DeleteOnSubmit(ts); db.SubmitChanges(); } }
public bool UpdateDepartment(DtoDepartment department) { using (var db = new KadrDataContext()) { try { var dep = db.Dep.FirstOrDefault(f => f.id == department.IdDepartment); if (dep != null) { dep.HasTimeSheet = department.HasTimeSheet; db.SubmitChanges(); return(true); } return(false); } catch { return(false); } } }
public bool TimeSheetApproval(int idTimeSheet, DtoApprover employeeLogin, bool result, string comments, string appDominUrl) { using (var db = new KadrDataContext()) { if (!CanApprove(idTimeSheet, employeeLogin)) { return(false); } var approvalStep = GetTimeSheetApproveStep(idTimeSheet); var timeSheet = GetTimeSheet(idTimeSheet, true); var idDepartment = timeSheet.Department.IdDepartment; var departmentName = db.Department.First(f => f.id == idDepartment).DepartmentSmallName; //var approver = GetCurrentApproverByLogin(employeeLogin) // .GetDepartmentApproverNumbers(idDepartment) // .First(w => w.ApproveNumber == approvalStep + 1); var approver = employeeLogin.GetDepartmentApproverNumbers(idDepartment) .First(w => w.ApproveNumber == approvalStep + 1); try { var timeSheetApproval = new TimeSheetApproval { ApprovalDate = DateTime.Now, idTimeSheet = idTimeSheet, idApprover = approver.IdApprover, Result = result, Comment = comments }; db.TimeSheetApproval.InsertOnSubmit(timeSheetApproval); db.SubmitChanges(); Task.Run( () => EmailSending(employeeLogin.EmployeeLogin, idTimeSheet, result, comments, approvalStep, departmentName, appDominUrl)); return(true); } catch (System.Exception e) { var s = e.Message; return(false); } } }
public DtoTimeSheet CreateFakeTimeSheet(int idDepartment, DateTime dateStart, DtoApprover approver) { using (var db = new KadrDataContext()) { if (db.TimeSheet.Any(a => a.idDepartment == idDepartment && a.DateBeginPeriod == dateStart)) { throw new System.Exception("Табель на этот месяц уже сформирован."); } var dtoApproverDepartment = approver.DtoApproverDepartments.FirstOrDefault(w => w.IdDepartment == idDepartment); var ts = new TimeSheet { idDepartment = idDepartment, DateComposition = DateTime.Now, DateBeginPeriod = dateStart, DateEndPeriod = dateStart.AddMonths(1).AddDays(-1), ApproveStep = 0, IsFake = true, idCreater = dtoApproverDepartment.IdApprover }; db.TimeSheet.InsertOnSubmit(ts); db.SubmitChanges(); return(DtoClassConstructor.DtoTimeSheet(db.TimeSheetView.Single(s => s.id == ts.id))); } }
//Генерация табеля для работников private void InsertEmployees(FactStaffWithHistory[] employees) { try { FactStaffWithHistory previousEmpl = null; // переменная для хранения предыдущей FactStaffWithHistory var exeptions = _db.Exception.Where(w => w.DateException >= _timeSheet.DateBeginPeriod && w.DateException <= _timeSheet.DateEndPeriod).ToArray(); var factStaffIds = employees.Select(s => s.id).Distinct(); var otpusk = _db.OK_Otpusks.Where(w => factStaffIds.Contains(w.idFactStaff) && w.DateBegin <= _timeSheet.DateEndPeriod && w.DateEnd >= _timeSheet.DateBeginPeriod).ToArray(); var holspitals = _db.OK_Inkapacities.Where(w => employees.Select(s => s.idEmployee).Distinct().Contains(w.idEmployee) && w.DateBegin <= _timeSheet.DateEndPeriod && w.DateEnd >= _timeSheet.DateBeginPeriod); var trips = _db.Events.Where(w => employees.Select(x => x.idFactStaffHistory).Contains(w.idFactStaffHistory) && w.DateBegin <= _timeSheet.DateEndPeriod && w.idPrikazEnd == null && w.DateEnd >= _timeSheet.DateBeginPeriod && w.idEventKind == IdBusinessTripKind && w.idEventType == BeginEvent); foreach (var employee in employees) { var employeeOtpusk = otpusk.Where(w => w.DateBegin.HasValue && w.idFactStaff == employee.id && w.DateBegin <= _timeSheet.DateEndPeriod && w.DateEnd >= _timeSheet.DateBeginPeriod).ToArray(); var employeeHosp = holspitals.Where(w => w.idEmployee == employee.idEmployee && w.DateBegin <= _timeSheet.DateEndPeriod && w.DateEnd >= _timeSheet.DateBeginPeriod).ToArray(); var employeeTrips = trips.Where(w => w.FactStaffHistory.idFactStaff == employee.id && w.DateBegin <= _timeSheet.DateEndPeriod && w.DateEnd >= _timeSheet.DateBeginPeriod).ToArray(); _timeSheetRecordLList.AddRange(InsertEmployee(employee, exeptions, employeeOtpusk, employeeHosp, employeeTrips)); if (previousEmpl != null && //если имеются FactStaffWithHistory с одинаковыми idEmployee, StaffCount, idPlanStaff, id(idFactStaff) previousEmpl.idEmployee == employee.idEmployee && previousEmpl.StaffCount == employee.StaffCount && previousEmpl.idPlanStaff == employee.idPlanStaff && previousEmpl.id == employee.id) { var previousItems = _timeSheetRecordLList.Where(p => p.idFactStaffHistory == previousEmpl.idFactStaffHistory && p.idTimeSheet == _timeSheet.id).ToList(); // берем записи табеля с 1ым FactStaffWithHistory var currentItems = _timeSheetRecordLList.Where(p => p.idFactStaffHistory == employee.idFactStaffHistory && p.idTimeSheet == _timeSheet.id).ToList(); // берем записи табеля с 2ым FactStaffWithHistory foreach (var deletepreviousItem in previousItems) //удаляем первые FactStaffWithHistory из общей колекции записей _timeSheetRecordLList { _timeSheetRecordLList.Remove(deletepreviousItem); } foreach (var deletecurrentItem in currentItems) //удаляем вторые FactStaffWithHistory из общей колекции записей _timeSheetRecordLList { _timeSheetRecordLList.Remove(deletecurrentItem); } foreach (var currentItem in currentItems) //проходим по всем записям табеля с 2ым FactStaffWithHistory //и делаем слияние 1 и 2 FactStaffWithHistory записей табеля в общую { //также меняем idFactStaffHistory у записей табеля 1 на dFactStaffHistory записей табеля 2 //"чтобы не было 2ух строк с одинаковыми человеками"(актуально при продлении трудового договора) if (currentItem.RecordDate <= previousEmpl.DateEnd) { var previousItemWithDay = previousItems.Where(m => m.RecordDate == currentItem.RecordDate).SingleOrDefault(); previousItemWithDay.idFactStaffHistory = currentItem.idFactStaffHistory; _timeSheetRecordLList.Add(previousItemWithDay); } if (currentItem.RecordDate > previousEmpl.DateEnd) { _timeSheetRecordLList.Add(currentItem); } } } previousEmpl = employee; //сохраняем текущий элемент как предыдущую } } catch (System.Exception ex) { _db.TimeSheet.DeleteAllOnSubmit(_db.TimeSheet.Where(w => w.id == IdTimeSheet)); _db.SubmitChanges(); var sb = new StringBuilder(); sb.AppendLine("Формирование табеля завершилось неудачей"); if (employees.Any(a => a.PlanStaff.IdWorkShedule == null)) { foreach (var employee in employees.Where(w => w.PlanStaff.IdWorkShedule == null)) { sb.AppendLine(string.Format(" {0} {1} {2}", employee.Employee.LastName, employee.Employee.FirstName, employee.Employee.Otch)); } sb.AppendLine(); sb.AppendLine("Для устранения проблемы обратитесь в отдел управления кадрами."); } sb.AppendLine(ex.Message); throw new System.Exception(sb.ToString()); } }