public void Punch(PunchType p) { if (p.PunchCategory == Category.Meta) { if (p.StartorEnd == StartEnd.Start) { StartTime = DateTime.Now; } else { EndTime = DateTime.Now; } } else if (p.StartorEnd == StartEnd.Start) //we've started a project or break. { //check that there aren't any unended segments. if (WorkSegments.Count > 0) { PunchSegment segment = WorkSegments[WorkSegments.Count - 1]; if (!segment.Ended) { //auto-fill in the blank. segment.EndTime = DateTime.Now; segment.EndLabel = "End " + (p.PunchCategory == Category.Break ? "Break" : "Project"); } } //make a new segment and start it. PunchSegment newSeg = new PunchSegment(); newSeg.StartLabel = p.Label; newSeg.SegmentCategory = p.PunchCategory; newSeg.StartTime = DateTime.Now; WorkSegments.Add(newSeg); } else if (p.StartorEnd == StartEnd.End) { //if the segment types don't match throw an exception. PunchSegment segment = WorkSegments[WorkSegments.Count - 1]; if (segment.SegmentCategory != p.PunchCategory) { throw new Exception("Current Segment Type does not match the punch type."); } //otherwise if (!segment.Ended) { segment.EndLabel = p.Label; segment.EndTime = DateTime.Now; } } }
public void Punch(PunchType p) { if (p.PunchCategory == Category.Meta) { if (p.StartorEnd == StartEnd.Start) { StartTime = DateTime.Now; } else { EndTime = DateTime.Now; } } else if (p.StartorEnd == StartEnd.Start) //we've started a project or break. { //check that there aren't any unended segments. if (WorkSegments.Count > 0) { PunchSegment segment = WorkSegments[WorkSegments.Count - 1]; if (!segment.Ended) { //auto-fill in the blank. segment.EndTime = DateTime.Now; segment.EndLabel = "End " + (p.PunchCategory == Category.Break ? "Break" : "Project"); } } //make a new segment and start it. PunchSegment newSeg = new PunchSegment(); newSeg.StartLabel = p.Label; newSeg.SegmentCategory = p.PunchCategory; newSeg.StartTime = DateTime.Now; WorkSegments.Add(newSeg); } else if (p.StartorEnd == StartEnd.End) { //if the segment types don't match throw an exception. PunchSegment segment = WorkSegments[WorkSegments.Count - 1]; if (segment.SegmentCategory != p.PunchCategory) throw new Exception("Current Segment Type does not match the punch type."); //otherwise if (!segment.Ended) { segment.EndLabel = p.Label; segment.EndTime = DateTime.Now; } } }