private void working_toggle_click(object sender, RoutedEventArgs e) { IClientDAO clientDAO = new ClientFileDAO(new ConfigMgr()); Client currentClient = clientDAO.GetClientById(currentClientInWorkScheduleTab.ContactForm.Person_1.Id, currentClientInWorkScheduleTab.ContactForm.Person_2.Id); try { if (currentClient.WorkingScheduleTime == null || currentClient.WorkingScheduleTime.WorkProperties == null) { currentClient.WorkingScheduleTime = new WorkingSchedule() { IsWorkingNow = false, WorkProperties = new List <WorkProperties>(), TotalWorkingTime = 0 }; } currentClient.WorkingScheduleTime.IsWorkingNow = !currentClient.WorkingScheduleTime.IsWorkingNow; if (currentClient.WorkingScheduleTime.IsWorkingNow) { currentClient.WorkingScheduleTime.LastWorkingStartTime = DateTime.Now; currentClient.WorkingScheduleTime.WorkProperties.Add(new WorkProperties() { StartTime = currentClient.WorkingScheduleTime.LastWorkingStartTime, EndTime = DateTime.Now, Comment = string.Empty, Owner = currentClient.ContactForm.CaseOwnerValue.Split(',')[0], PropIndex = currentClient.WorkingScheduleTime.WorkProperties.Count + 1 }); working_toggle.Content = "הפסקת עבודה על התיק"; } else { currentClient.WorkingScheduleTime.WorkProperties.Last().EndTime = DateTime.Now; double totalHours = currentClient.WorkingScheduleTime.WorkProperties.Aggregate(0.0, (acc, workTime) => acc + (workTime.EndTime - workTime.StartTime).TotalHours); currentClient.WorkingScheduleTime.TotalWorkingTime = Math.Round(totalHours, 3); total_working_schedule.Text = $"סך הכל זמן עבודה: {currentClient.WorkingScheduleTime.TotalWorkingTime}"; working_toggle.Content = "התחלת עבודה על התיק"; } working_schedule_data_grid.ItemsSource = currentClient.WorkingScheduleTime.WorkProperties; clientDAO.UpdateClient(currentClient); DisplaySnackbar("הנתונים נשמרו בהצלחה"); } catch (FileNotFoundException) { DisplaySnackbar("הקובץ לקוחות לא נמצא, בדוק בהגדרות מערכת את ההגדרות שלך"); } catch (Exception ex) { DisplaySnackbar("שגיאה כללית במערכת, אנא נסה שוב"); Logger log = new Logger(new ConfigMgr()); log.Error("general error on load tab", ex); } }
private void save_working_schedule_data_grid_Click(object sender, RoutedEventArgs e) { IClientDAO clientDAO = new ClientFileDAO(new ConfigMgr()); Client currentClient = clientDAO.GetClientById(currentClientInWorkScheduleTab.ContactForm.Person_1.Id, currentClientInWorkScheduleTab.ContactForm.Person_2.Id); List <WorkProperties> works = working_schedule_data_grid.ItemsSource as List <WorkProperties>; currentClient.WorkingScheduleTime.WorkProperties = works; double totalHours = currentClient.WorkingScheduleTime.WorkProperties.Aggregate(0.0, (acc, workTime) => acc + (workTime.EndTime - workTime.StartTime).TotalHours); currentClient.WorkingScheduleTime.TotalWorkingTime = Math.Round(totalHours, 3); total_working_schedule.Text = $"סך הכל זמן עבודה: {currentClient.WorkingScheduleTime.TotalWorkingTime}"; clientDAO.UpdateClient(currentClient); DisplaySnackbar("הנתונים נשמרו בהצלחה"); save_working_schedule_data_grid.IsEnabled = false; }