public editDayPopup(Workday day) { Day = day; InitializeComponent(); DateLabel.Text = day.getDate_S(); Starttimetextbox.Text = day.getStartofWorkday_S(); EndtimeTextbox.Text = day.getEndofWorkday_S(); checkBox_No15minbreak.Checked = day.no_15_minutes_break; checkBox_no30minBreak.Checked = day.no_30_minutes_break; checkBox_VacationAbsence.Checked = day.absent_through_vacation; checkBox_SickAbsence.Checked = day.absent_through_sickness; }
/*Determine if days are missing and add them to list of dayss*/ private List <Workday> findMissingDays(List <Workday> days) { Workday Day_before = days[0]; List <Workday> l = new List <Workday>(); l.Add(days[0]); Workday lastday = days[days.Count - 1]; int i = 1; while (days[i - 1] != lastday) { bool condition_for_adding_days = (days[i - 1].date.Date + new TimeSpan(24, 0, 0)).CompareTo(days[i].date.Date) != 0; if (condition_for_adding_days) { days.Insert(i, new Workday(days[i - 1].date.Date + new TimeSpan(24, 0, 0), config.getStandartWorkingTime())); } i++; } return(days); }
/**/ private List <Workday> ReadData(string path = null) { List <Workday> days = new List <Workday>(); if (path != null) { days = Serialization.ReadFromXmlFile <List <Workday> >(path); } else if (File.Exists(data_days_path[0])) { days = Serialization.ReadFromXmlFile <List <Workday> >(data_days_path[0]); } else { if (File.Exists(data_days_path[1])) { days = Serialization.ReadFromXmlFile <List <Workday> >(data_days_path[1]); //saveData(days); } } return(days); } /*Triggers a new event (updates data)*/ private void triggerEvent() { // Variables DateTime currentTime = DateTime.Now; bool file_created = false; bool day_changed = false; bool month_changed = false; bool year_changed = false; try { // try to load data from passed days days = ReadData(); // safe back parsed days to file in order to keep the ones which where missing saveData(days); current_day = getWorkdayByDateTime(DateTime.Now); } catch { // create new File if loading failed saveData(days); file_created = true; } // day of last activity is before now. // That means we have new day if (file_created == true) { day_changed = false; month_changed = false; year_changed = false; } else { if (current_day != null) { day_changed = (current_day.date.Day.CompareTo(currentTime.Day) < 0); // check if day has changed, month_changed = (current_day.date.Month.CompareTo(currentTime.Month) < 0); // check if month changed(at month change, daychange will be false) year_changed = (current_day.date.Year.CompareTo(currentTime.Year) < 0); // check if year changed } } if (day_changed || month_changed || year_changed || file_created || (current_day == null)) { /*Create a new day*/ days.Add(new Workday(currentTime, config.getStandartWorkingTime())); current_day = days.Last(); current_day.setStartofWorkday(currentTime); current_day.setEndofWorkday(currentTime); last_active = currentTime; } else { // write another activity last_active = currentTime; //set start of workday of this is a new workday created by the findMissingDays(..) function if (current_day.getStartofWorkday() == new DateTime()) { current_day.setStartofWorkday(currentTime); } current_day.setEndofWorkday(currentTime); } // parse days for missing ones(weekend, vacation, sickness...) days = findMissingDays(days); }