private void setInterruptionType(int interruptionIndex, WorkInterruption.WorkInterruptionType newType) { if (this.IsChangeByUserAllowed) { _dayData.WorkInterruptions[interruptionIndex].CorrectedType = newType; } else { _dayData.WorkInterruptions[interruptionIndex].Type = newType; } NotifyPropertyChanged(string.Format("Interrupt{0}Type", interruptionIndex)); NotifyPropertyChanged("Duration"); NotifyPropertyChanged("HasAutoDecrementedLunchTime"); NotifyPropertyChanged(string.Format("Interrupt{0}HasCorrections", interruptionIndex)); NotifyPropertyChanged(string.Format("Interrupt{0}ToolTip", interruptionIndex)); }
public bool SplitWorkInterruptionWithInterruption(int workInterruptionIndexToSplit, TimeSpan hhmmInsertedInterruptionStart, TimeSpan hhmmInsertedInterruptionEnd, WorkInterruption.WorkInterruptionType insertedInterruptionType) { // We shall turn interruptions like this... // 7:00 - 15:00 (PDOMA) 17:17 - 18:18 (SLUZ) // // ...into intervals like this: // 7:00 - 12:00 (PDOMA) 12:00 - 12:20 (OBED) 12:20 - 15:00 (PDOMA) 17:17 - 18:18 (SLUZ) bool success = false; DateTime intervalToSplitStart = this.WorkInterruptions[workInterruptionIndexToSplit].GetStartTimeIncludingCorrections(); DateTime intervalToSplitEnd = this.WorkInterruptions[workInterruptionIndexToSplit].GetEndTimeIncludingCorrections(); WorkInterruption.WorkInterruptionType intervalToSplitType = this.WorkInterruptions[workInterruptionIndexToSplit].GetTypeIncludingCorrections(); // Can't add an interruption of e.g. 12:00 - 12:20 when the interval actually ends before 12:20 or starts after 12:00 or it's exactly 12:00 - 12:20 ! if (intervalToSplitStart.TimeOfDay > hhmmInsertedInterruptionStart || (intervalToSplitEnd.TimeOfDay < hhmmInsertedInterruptionEnd && isTimeSpanSet(intervalToSplitEnd.TimeOfDay)) || (intervalToSplitStart.TimeOfDay == hhmmInsertedInterruptionStart && intervalToSplitEnd.TimeOfDay == hhmmInsertedInterruptionEnd)) { return(success); } if (!isTimeSpanSet(intervalToSplitStart.TimeOfDay) && !isTimeSpanSet(intervalToSplitEnd.TimeOfDay)) { return(success); } // Shift interruptions to the right, by 2 for (int interruptIndexToMoveOnto = this.WorkInterruptions.Length - 1; interruptIndexToMoveOnto > workInterruptionIndexToSplit + 1; interruptIndexToMoveOnto--) { var copiedStartTime = this.WorkInterruptions[interruptIndexToMoveOnto - 2].GetStartTimeIncludingCorrections(); var copiedEndTime = this.WorkInterruptions[interruptIndexToMoveOnto - 2].GetEndTimeIncludingCorrections(); var copiedType = this.WorkInterruptions[interruptIndexToMoveOnto - 2].GetTypeIncludingCorrections(); // If Source and Destination of the shift have the same data, then nothing to do for this one if (copiedStartTime == this.WorkInterruptions[interruptIndexToMoveOnto].GetStartTimeIncludingCorrections() && copiedEndTime == this.WorkInterruptions[interruptIndexToMoveOnto].GetEndTimeIncludingCorrections() && copiedType == this.WorkInterruptions[interruptIndexToMoveOnto].GetTypeIncludingCorrections()) { continue; } // Quasi-Clone, but do _not_ use Clone() for this; we want to set only corrections, nothing else, so that "Clear Correction" will really clear that cell out completely this.WorkInterruptions[interruptIndexToMoveOnto] = new WorkInterruption() { CorrectionStartTime = copiedStartTime, CorrectionEndTime = copiedEndTime, CorrectedType = copiedType }; } var dateBase = new DateTime(this.WorkInterruptions[workInterruptionIndexToSplit].GetStartTimeIncludingCorrections().Year, this.WorkInterruptions[workInterruptionIndexToSplit].GetStartTimeIncludingCorrections().Month, this.WorkInterruptions[workInterruptionIndexToSplit].GetStartTimeIncludingCorrections().Day); // Adjust the interruption being split this.WorkInterruptions[workInterruptionIndexToSplit].CorrectionEndTime = dateBase.AddMinutes(hhmmInsertedInterruptionStart.TotalMinutes); // Create an interruption into the middle of the split one this.WorkInterruptions[workInterruptionIndexToSplit + 1].CorrectionStartTime = dateBase.AddMinutes(hhmmInsertedInterruptionStart.TotalMinutes); this.WorkInterruptions[workInterruptionIndexToSplit + 1].CorrectionEndTime = dateBase.AddMinutes(hhmmInsertedInterruptionEnd.TotalMinutes); this.WorkInterruptions[workInterruptionIndexToSplit + 1].CorrectedType = insertedInterruptionType; // End the interruption being split as a new interval this.WorkInterruptions[workInterruptionIndexToSplit + 2].CorrectionStartTime = dateBase.AddMinutes(hhmmInsertedInterruptionEnd.TotalMinutes); this.WorkInterruptions[workInterruptionIndexToSplit + 2].CorrectionEndTime = intervalToSplitEnd; this.WorkInterruptions[workInterruptionIndexToSplit + 2].CorrectedType = intervalToSplitType; success = true; return(success); }
public bool SplitWorkSpanWithInterruption(int workSpanIndexToSplit, TimeSpan hhmmInsertedInterruptionStart, TimeSpan hhmmInsertedInterruptionEnd, WorkInterruption.WorkInterruptionType insertedInterruptionType) { // We shall turn intervals like this... // 7:00 - 15:00 17:17 - 18:18 // // ...into intervals like this: // 7:00 - 12:00 12:20 - 15:00 17:17 - 18:18 bool success = false; DateTime intervalToSplitStart = this.WorkSpans[workSpanIndexToSplit].GetStartTimeIncludingCorrections(); DateTime intervalToSplitEnd = this.WorkSpans[workSpanIndexToSplit].GetEndTimeIncludingCorrections(); // Can't add an interruption of e.g. 12:00 - 12:20 when the interval actually ends before 12:20 or starts after 12:00 or it's exactly 12:00 - 12:20 ! if (intervalToSplitStart.TimeOfDay > hhmmInsertedInterruptionStart || intervalToSplitEnd.TimeOfDay < hhmmInsertedInterruptionEnd || (intervalToSplitStart.TimeOfDay == hhmmInsertedInterruptionStart && intervalToSplitEnd.TimeOfDay == hhmmInsertedInterruptionEnd)) { return(success); } // Shift interruptions to the right, by one for (int workSpanIndexToMoveOnto = this.WorkSpans.Length - 1; workSpanIndexToMoveOnto > workSpanIndexToSplit; workSpanIndexToMoveOnto--) { var copiedStartTime = this.WorkSpans[workSpanIndexToMoveOnto - 1].GetStartTimeIncludingCorrections(); var copiedEndTime = this.WorkSpans[workSpanIndexToMoveOnto - 1].GetEndTimeIncludingCorrections(); // If Source and Destination of the shift have the same data, then nothing to do for this one if (copiedStartTime == this.WorkSpans[workSpanIndexToMoveOnto].GetStartTimeIncludingCorrections() && copiedEndTime == this.WorkSpans[workSpanIndexToMoveOnto].GetEndTimeIncludingCorrections()) { continue; } // Quasi-Clone, but do _not_ use Clone() for this; we want to set only corrections, nothing else, so that "Clear Correction" will really clear that cell out completely this.WorkSpans[workSpanIndexToMoveOnto] = new WorkSpan() { CorrectionStartTime = copiedStartTime, CorrectionEndTime = copiedEndTime }; } var dateBase = new DateTime(this.WorkSpans[workSpanIndexToSplit].GetEndTimeIncludingCorrections().Year, this.WorkSpans[workSpanIndexToSplit].GetEndTimeIncludingCorrections().Month, this.WorkSpans[workSpanIndexToSplit].GetEndTimeIncludingCorrections().Day); // Adjust the WorkSpan being split this.WorkSpans[workSpanIndexToSplit].CorrectionEndTime = dateBase.AddMinutes(hhmmInsertedInterruptionStart.TotalMinutes); // End the WorkSpan being split as a new WorkSpan this.WorkSpans[workSpanIndexToSplit + 1].CorrectionStartTime = dateBase.AddMinutes(hhmmInsertedInterruptionEnd.TotalMinutes); this.WorkSpans[workSpanIndexToSplit + 1].CorrectionEndTime = dateBase.AddMinutes(intervalToSplitEnd.Hour * 60 + intervalToSplitEnd.Minute); // Find out which interruptions to shift to right by one int interruptIndexToInsert = 0; foreach (WorkInterruption interrupt in this.WorkInterruptions) { if (interrupt.GetStartTimeIncludingCorrections().TimeOfDay.TotalMinutes == 0 && interrupt.GetEndTimeIncludingCorrections().TimeOfDay.TotalMinutes == 0) { break; } if (interrupt.GetStartTimeIncludingCorrections().TimeOfDay.TotalMinutes >= hhmmInsertedInterruptionStart.TotalMinutes) { break; } interruptIndexToInsert++; } // Intervals that need to be shifted to the right shall be shifted now for (int interruptIndexToMoveOnto = this.WorkInterruptions.Length - 1; interruptIndexToMoveOnto > workSpanIndexToSplit; interruptIndexToMoveOnto--) { var copiedStartTime = this.WorkInterruptions[interruptIndexToMoveOnto - 1].GetStartTimeIncludingCorrections(); var copiedEndTime = this.WorkInterruptions[interruptIndexToMoveOnto - 1].GetEndTimeIncludingCorrections(); var copiedType = this.WorkInterruptions[interruptIndexToMoveOnto - 1].GetTypeIncludingCorrections(); // If Source and Destination of the shift have the same data, then nothing to do for this one if (copiedStartTime == this.WorkInterruptions[interruptIndexToMoveOnto].GetStartTimeIncludingCorrections() && copiedEndTime == this.WorkInterruptions[interruptIndexToMoveOnto].GetEndTimeIncludingCorrections() && copiedType == this.WorkInterruptions[interruptIndexToMoveOnto].GetTypeIncludingCorrections()) { continue; } // Quasi-Clone, but do _not_ use Clone() for this; we want to set only corrections, nothing else, so that "Clear Correction" will really clear that cell out completely this.WorkInterruptions[interruptIndexToMoveOnto] = new WorkInterruption() { CorrectionStartTime = copiedStartTime, CorrectionEndTime = copiedEndTime, CorrectedType = copiedType }; } // Create an interruption that actually splits our desired WorkSpan this.WorkInterruptions[interruptIndexToInsert].CorrectionStartTime = dateBase.AddMinutes(hhmmInsertedInterruptionStart.TotalMinutes); this.WorkInterruptions[interruptIndexToInsert].CorrectionEndTime = dateBase.AddMinutes(hhmmInsertedInterruptionEnd.TotalMinutes); this.WorkInterruptions[interruptIndexToInsert].CorrectedType = insertedInterruptionType; success = true; return(success); }