private void TimeButton_OnClick(object sender, RoutedEventArgs e) { // show time edit window if (ShiftActive) { TimeSpan duration = _shift == null ? _time.Duration : _shift.Duration; TimeSelectWindow selectWindow = new TimeSelectWindow(_date, duration); selectWindow.ShowDialog(); if (selectWindow.Accepted) { if (_shift != null) { bool different = _shift.StartTime.TimeOfDay != selectWindow.Start.TimeOfDay || _shift.Duration != selectWindow.Duration; if (different) { _shift.ExceptionList.Add(ShiftTime.ShiftTimeFactory(selectWindow.Start, selectWindow.Duration, true, false, _shift)); } } else if (_time != null) { _time.StartTime = selectWindow.Start; _time.Duration = selectWindow.Duration; } } } }
public void CancelShift(DateTime date) { if (ExceptionList.All(exep => exep.StartTime != date)) // toggle shift as canceled { ExceptionList.Add(ShiftTime.ShiftTimeFactory(date, _duration, false, false, this)); } else // toggle shift to not canceled { ExceptionList.Remove(ExceptionList.FirstOrDefault(exep => exep.StartTime == date)); } }
public static Shift Load(BinaryReader reader, bool isCoating) { DateTime start = DateTime.Parse(reader.ReadString()); DateTime end = DateTime.Parse(reader.ReadString()); List <ShiftTime> exceptionList = new List <ShiftTime>(); for (Int32 numExeptions = reader.ReadInt32(); numExeptions > 0; --numExeptions) { ShiftTime newTime = ShiftTime.Load(reader); exceptionList.Add(newTime); } List <DayOfWeek> daysList = new List <DayOfWeek>(); for (Int32 numDays = reader.ReadInt32(); numDays > 0; --numDays) { DayOfWeek day = (DayOfWeek)reader.ReadInt32(); daysList.Add(day); } String name = reader.ReadString(); Color foreground = default(Color); Color background = default(Color); var convertFromString = ColorConverter.ConvertFromString(reader.ReadString()); if (convertFromString != null) { background = (Color)convertFromString; } convertFromString = ColorConverter.ConvertFromString(reader.ReadString()); if (convertFromString != null) { foreground = (Color)convertFromString; } DateTime startTime = DateTime.Parse(reader.ReadString()); TimeSpan duration = TimeSpan.Parse(reader.ReadString()); return(ShiftFactory(name, startTime, duration, start, end, exceptionList, daysList, isCoating, foreground, background)); }
public DayShiftControl(object shiftInfo, DateTime date) { InitializeComponent(); _date = date; ShiftInfo = shiftInfo; _shift = shiftInfo as Shift; _time = shiftInfo as ShiftTime; if (_shift != null) // if a shift { ShiftActive = !_shift.ExceptionList.Any(exep => !exep.IsActive && exep.StartTime == date); IsOvertime = false; ShiftLabel.Content = _shift.LabelName; ShiftLabel.Background = new SolidColorBrush(_shift.BackgroundColor); ShiftLabel.Foreground = new SolidColorBrush(_shift.ForegroundColor); } else if (_time != null) // if an exception { ShiftActive = _time.IsActive; IsOvertime = _time.IsOvertime; if (!ShiftActive) { MainPanel.Children.Remove(TimeButton); MainPanel.Children.Remove(OvertimeButton); } if (IsOvertime) { MainPanel.Children.Remove(OvertimeButton); } ShiftLabel.Content = _time.Shift.MakeLabel(_time); ShiftLabel.Background = new SolidColorBrush(_time.Shift.BackgroundColor); ShiftLabel.Foreground = new SolidColorBrush(_time.Shift.ForegroundColor); } }
private void AddDayLabel(DateTime date, ShiftTime source, string text, SolidColorBrush foreground, SolidColorBrush background) { DayControl day = DayControls.FirstOrDefault(x => x.Date.DayOfYear == date.DayOfYear && x.Date.Year == date.Year); if (day != null) { Label label = new Label(); if (text != null) { label.Content = text; } if (background != null) { label.Background = background; } if (foreground != null) { label.Foreground = foreground; } day.DayItems.Add(label); day.ShiftInfo.Add(source); } }
public string MakeLabel(ShiftTime excep) { return(String.Format("{0} ({1} - {2}){3}", Name, excep.StartTime.ToString("h:mm tt"), (excep.StartTime + excep.Duration).ToString("h:mm tt"), excep.IsOvertime ? "OT" : "")); }