private void GetAndSetAllInfoFromDatabase() { using (_dbContext = new WHTDbContext()) { YearMonth = new BindableCollection <YearMonthModel>(_dbContext.YearMonths); } }
private void VacationClosingEventHandler(object sender, DialogClosingEventArgs eventArgs) { if ((bool)eventArgs.Parameter == false) { return; } eventArgs.Cancel(); var dialogViewContent = (VacationDialogView)eventArgs.Content; var dialogData = (VacationDialogViewModel)dialogViewContent.DataContext; VacationModel tempVacation = new VacationModel { From = dialogData.DateFrom, To = dialogData.DateTo, Type = dialogData.SelectedVacationType, EmployeeId = dialogData.SelectedEmployee.Id }; eventArgs.Session.UpdateContent(new ProgressDialog()); using (_dbContext = new WHTDbContext()) { _dbContext.Vacations.Add(tempVacation); _dbContext.SaveChanges(); } NotifyOfPropertyChange(() => EmployeesVacations); Task.Delay(TimeSpan.FromSeconds(1)) .ContinueWith((t, _) => eventArgs.Session.Close(false), null, TaskScheduler.FromCurrentSynchronizationContext()); }
private void ConfirmationClosingEventHandler(object sender, DialogClosingEventArgs eventArgs) { if ((bool)eventArgs.Parameter == false) { return; } eventArgs.Cancel(); eventArgs.Session.UpdateContent(new ProgressDialog()); using (_dbContext = new WHTDbContext()) { var vacation = new VacationModel { Id = SelectedEmployeeVacation.VacationId }; _dbContext.Vacations.Attach(vacation); _dbContext.Vacations.Remove(vacation); _dbContext.SaveChanges(); } NotifyOfPropertyChange(() => EmployeesVacations); Task.Delay(TimeSpan.FromSeconds(1)) .ContinueWith((t, _) => eventArgs.Session.Close(false), null, TaskScheduler.FromCurrentSynchronizationContext()); }
private void VacationClosingEventHandler(object sender, DialogClosingEventArgs eventArgs) { if ((bool)eventArgs.Parameter == false) { return; } eventArgs.Cancel(); var dialogViewContent = (MonthOptionsDialogView)eventArgs.Content; var dialogData = (MonthOptionsDialogViewModel)dialogViewContent.DataContext; YearMonthModel tempYearMonth = new YearMonthModel { Year = dialogData.SelectedDate.Year, Month = dialogData.SelectedDate.Month, MonthsWorkingHours = dialogData.MonthsWorkingHours, MonthsWeekendDays = new HashSet <int>(Array.ConvertAll(dialogData.WeekendDays.Split(';'), int.Parse)) }; eventArgs.Session.UpdateContent(new ProgressDialog()); using (_dbContext = new WHTDbContext()) { if (_dbContext.YearMonths.Any(x => x.Year.Equals(tempYearMonth.Year) && x.Month.Equals(tempYearMonth.Month))) { _dbContext.Entry(tempYearMonth).State = System.Data.Entity.EntityState.Modified; } else { _dbContext.Entry(tempYearMonth).State = System.Data.Entity.EntityState.Added; } _dbContext.SaveChanges(); } Task.Delay(TimeSpan.FromSeconds(1)) .ContinueWith((t, _) => eventArgs.Session.Close(false), null, TaskScheduler.FromCurrentSynchronizationContext()); GetAndSetAllInfoFromDatabase(); NotifyOfPropertyChange(() => SelectedDate); }
public void TimeUpdate() { using (_dbContext = new WHTDbContext()) { if (_dbContext.Hours.Any(x => x.WorkingDate.Year.Equals(SelectedDate.Year) && x.WorkingDate.Month.Equals(SelectedDate.Month) && x.WorkingDate.Day.Equals(SelectedDate.Day) && x.EmployeeId.Equals(SelectedEmployee.Id))) { var toUpdate = _dbContext.Hours.Single(x => x.WorkingDate.Year.Equals(SelectedDate.Year) && x.WorkingDate.Month.Equals(SelectedDate.Month) && x.WorkingDate.Day.Equals(SelectedDate.Day) && x.EmployeeId.Equals(SelectedEmployee.Id)); toUpdate.From = TimeFrom.Value.TimeOfDay; toUpdate.To = TimeTo.Value.TimeOfDay; _dbContext.SaveChanges(); MessageQueue.Enqueue("ZAKTUALIZOWANO"); } else { HoursModel tempHours = new HoursModel(); tempHours.WorkingDate = SelectedDate; tempHours.From = TimeFrom.Value.TimeOfDay; tempHours.To = TimeTo.Value.TimeOfDay; tempHours.EmployeeId = SelectedEmployee.Id; var totalHours = (TimeTo - TimeFrom).Value.TotalHours; _dbContext.Hours.Add(tempHours); _dbContext.SaveChanges(); MessageQueue.Enqueue("DODANO"); } } NotifyOfPropertyChange(() => SelectedDateHoursSum); NormalAndOvertimeUpdate(); }
public ShellViewModel() { _dbContext = new WHTDbContext(); _dbContext.InitDummyData(); ActivateItem(new WorkingHoursViewModel()); }
public void BackUp(DateTime selectedDateTime, string filePath) { using (_dbContext = new WHTDbContext()) { Employees = new BindableCollection <EmployeeModel>(_dbContext.Employees); Hours = new BindableCollection <HoursModel>(_dbContext.Hours.Where(x => x.WorkingDate.Year.Equals(selectedDateTime.Year) && x.WorkingDate.Month.Equals(selectedDateTime.Month))); YearMonths = new BindableCollection <YearMonthModel>(_dbContext.YearMonths.Where(x => x.Year.Equals(selectedDateTime.Year) && x.Month.Equals(selectedDateTime.Month))); } var fileName = $"{selectedDateTime.ToShortDateString()}_backup.xlsx"; var daysInMonth = DateTime.DaysInMonth(selectedDateTime.Year, selectedDateTime.Month); var numOfEmployees = Employees.Count; var weekends = YearMonths.Select(x => x.MonthsWeekendDays).First(); using (var p = new ExcelPackage(new System.IO.FileInfo($"{filePath}/{fileName}"))) { var ws = p.Workbook.Worksheets.Add("BU"); #region SET BORDER/STYLE ON WHOLE WORKSHEET var tempRange = ws.Cells[1, 1, daysInMonth + 4, numOfEmployees + 1]; tempRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; tempRange.Style.Border.Left.Style = ExcelBorderStyle.Thin; tempRange.Style.Border.Right.Style = ExcelBorderStyle.Thin; tempRange.Style.Border.Top.Style = ExcelBorderStyle.Thin; tempRange.Style.Border.Bottom.Style = ExcelBorderStyle.Thin; tempRange.Style.Border.Left.Color.SetColor(Color.Black); tempRange.Style.Border.Right.Color.SetColor(Color.Black); tempRange.Style.Border.Top.Color.SetColor(Color.Black); tempRange.Style.Border.Bottom.Color.SetColor(Color.Black); #endregion #region SET WEEKENDS/HOLIDAYS for (int row = 1; row <= daysInMonth; row++) { var dt = new DateTime(selectedDateTime.Year, selectedDateTime.Month, row); ws.Cells[row + 1, 1].Value = dt.ToLongDateString(); if (weekends.Contains(dt.Day)) { var range = ws.Cells[row + 1, 1, row + 1, numOfEmployees + 1]; range.Style.Fill.PatternType = ExcelFillStyle.Solid; range.Style.Fill.BackgroundColor.SetColor(Color.Brown); //.Style.Font.Color.SetColor(System.Drawing.Color.Brown); } } ws.Cells[daysInMonth + 2, 1].Value = "Podstawowe"; ws.Cells[daysInMonth + 3, 1].Value = "Nadgodziny"; ws.Cells[daysInMonth + 4, 1].Value = "Suma"; ws.Cells[daysInMonth + 2, 1, daysInMonth + 4, 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Left; ws.Cells[daysInMonth + 2, 1, daysInMonth + 4, numOfEmployees + 1].Style.Fill.PatternType = ExcelFillStyle.Solid; ws.Cells[daysInMonth + 2, 1, daysInMonth + 4, numOfEmployees + 1].Style.Fill.BackgroundColor.SetColor(Color.Yellow); #endregion #region SET EMPLOYEES HOURS for (int employeeNo = 0; employeeNo < numOfEmployees; employeeNo++) { var emp = Employees[employeeNo]; var cell = ws.Cells[1, employeeNo + 2]; cell.Value = emp.FirstName; var empHours = Hours.Where(x => x.EmployeeId.Equals(emp.Id)).ToList(); double normalHoursSum = 0, overtimeHoursSum = 0, allHoursSum = 0; foreach (var workDay in empHours) { var day = workDay.WorkingDate.Day; TimeSpan interval = (TimeSpan)(workDay.To - workDay.From); var totalHours = interval.TotalHours; ws.Cells[day + 1, employeeNo + 2].Value = totalHours; allHoursSum += totalHours; if (weekends.Contains(day)) { overtimeHoursSum += totalHours; continue; } if (totalHours > 8) { normalHoursSum += 8; overtimeHoursSum += totalHours - 8; } else { normalHoursSum += totalHours; } } ws.Cells[daysInMonth + 2, employeeNo + 2].Value = normalHoursSum; ws.Cells[daysInMonth + 3, employeeNo + 2].Value = overtimeHoursSum; ws.Cells[daysInMonth + 4, employeeNo + 2].Value = allHoursSum; } #endregion ws.Cells[1, 1, daysInMonth, numOfEmployees + 1].AutoFitColumns(); p.Save(); } MessageQueue.Enqueue("Backup utworzony!"); }