public void ChangeEndTime(int id, DateTime newEndDate) { if (id >= wtrs.Count) { throw new Exception("This WorktimeRecord does not exist: Index out of bounds"); } var current = wtrs.Where(wtr => wtr.storageID == id).FirstOrDefault(); if (current.End.Date != newEndDate.Date) { throw new Exception("Only times (not dates, i.e. overnighters) can be changed"); } if (newEndDate < current.Start) { throw new Exception("Begin time cannot be greater than end time"); } if (newEndDate.TimeOfDay < current.End.TimeOfDay) //shortening { var newWtr = new WorktimeRecord(newEndDate, current.End, "undefined", current.Comment); newWtr.storageID = wtrs.Count; var index = wtrs.FindIndex(wtr => wtr.storageID == id); wtrs.Insert(index + 1, newWtr); current.End = newEndDate; } else //lengthening { throw new Exception("Lengthening not implemented"); } }
public void addWorktimeRecord(WorktimeRecord worktimeRecord) { using (var db = new LiteDatabase(DATABASE_FILE)) { var wtrs = db.GetCollection <WorktimeRecord>("worktimeRecords"); wtrs.Insert(worktimeRecord); } }
public void addWorktimeRecord(WorktimeRecord wtr) { if (wtr != null) { var csv = generateCSVEntry((long)System.Math.Abs((wtr.End - wtr.Start).TotalSeconds), wtr.ProjectName, wtr.Start, wtr.End, wtr.Comment, isScreentime(wtr)); pendingCSVEntries.Enqueue(csv); } writeOutAllPendingCSVEntries(); }
public void addWorktimeRecord(WorktimeRecord worktimeRecord) { if (worktimeRecord == null) { return; } wtrs.Add(worktimeRecord); wtrs.Last().storageID = wtrs.Count - 1; }
public void ChangeEndTime(int id, DateTime newEndDate) { using (var db = new LiteDatabase(DATABASE_FILE)) { var wtrs = db.GetCollection <WorktimeRecord>("worktimeRecords"); var current = wtrs.Find(wtr2 => wtr2.storageID == id).FirstOrDefault(); if (current == null) { throw new Exception("This WorktimeRecord does not exist"); } if (current.End.Date != newEndDate.Date) { throw new Exception("Only times (not dates, i.e. overnighters) can be changed"); } if (newEndDate < current.Start) { throw new Exception("Begin time cannot be greater than end time"); } if (newEndDate.TimeOfDay < current.End.TimeOfDay) //shortening { var newWtr = new WorktimeRecord(newEndDate, current.End, "undefined", current.Comment); wtrs.Insert(newWtr); current.End = newEndDate; wtrs.Update(current); } else //lengthening { //TODO support overnighters var nextDay = current.End.Date.Add(new TimeSpan(1, 0, 0, 0)); var next = wtrs.Find(wtr => wtr.storageID != id && wtr.Start >= current.End && wtr.Start < nextDay) //weird same day conditions because comparing .Date for some reason doesn't work .OrderBy(wtr => wtr.Start) .FirstOrDefault(); if (next != null) { if (next.Start < newEndDate) { throw new Exception("Lengthening only allowed in gaps"); } } current.End = newEndDate; wtrs.Update(current); } } }
/* * very hacky implementation to determine whether something should be marked as Screentime t/f which is solely important for the CSV export/analysis spreadsheet * e.g. does not account for times on private screen, should be declared in settings * */ private bool isScreentime(WorktimeRecord wtr) { if (wtr.ProjectName == ProjectChangeHandler.PROJECT_PAUSE || wtr.ProjectName == ProjectChangeHandler.PROJECT_WORKTIMEBREAK) { return(false); } else { return(true); } }
public void ChangeStartTime(int id, DateTime newStartDate) { using (var db = new LiteDatabase(DATABASE_FILE)) { var wtrs = db.GetCollection <WorktimeRecord>("worktimeRecords"); var current = wtrs.Find(wtr2 => wtr2.storageID == id).FirstOrDefault(); if (current.Start.Date != newStartDate.Date) { throw new Exception("Only times (not dates, i.e. overnighters) can be changed"); } if (newStartDate > current.End) { throw new Exception("Begin time cannot be greater than end time"); } if (newStartDate.TimeOfDay > current.Start.TimeOfDay) //shortening { var newWtr = new WorktimeRecord(current.Start, newStartDate, "undefined", current.Comment); wtrs.Insert(newWtr); current.Start = newStartDate; wtrs.Update(current); } else //lengthening { if (newStartDate.Hour < 4) { throw new Exception("Day must not start before 4am"); } var previous = wtrs.Find(wtr => wtr.storageID != id && wtr.End <= current.Start && wtr.End >= current.Start.Date) //weird same day conditions because comparing .Date for some reason doesn't work .OrderByDescending(wtr => wtr.End) .FirstOrDefault(); if (previous != null) { if (previous.End > newStartDate) { throw new Exception("Lengthening only allowed in gaps"); } } current.Start = newStartDate; wtrs.Update(current); } } }
public void ChangeStartTime(int id, DateTime newStartDate) { if (id >= wtrs.Count) { throw new Exception("This WorktimeRecord does not exist: Index out of bounds"); } var current = wtrs.Where(wtr => wtr.storageID == id).FirstOrDefault(); if (current.Start.Date != newStartDate.Date) { throw new Exception("Only times (not dates, i.e. overnighters) can be changed"); } if (newStartDate > current.End) { throw new Exception("Begin time cannot be greater than end time"); } if (newStartDate.TimeOfDay > current.Start.TimeOfDay) //shortening { var newWtr = new WorktimeRecord(current.Start, newStartDate, "undefined", current.Comment); newWtr.storageID = wtrs.Count; var index = wtrs.FindIndex(wtr => wtr.storageID == id); wtrs.Insert(index, newWtr); current.Start = newStartDate; } else //lengthening { var minTimeOfDay = wtrs.Where(wtr => wtr.Start.Date == newStartDate.Date && wtr.Start.Hour >= 4).Min(wtr => wtr.Start); var firstOfDay = wtrs.Where(wtr => wtr.Start == minTimeOfDay).FirstOrDefault(); if (current != firstOfDay) //in the middle { throw new Exception("Lengthening in the middle not implemented"); } if (newStartDate.Hour < 4) { throw new Exception("Day must not start before 4am"); } current.Start = newStartDate; } }
public ProjectChangeEvent(Types type, string newProject, string newComment, WorktimeRecord wtr, Boolean processed = false, TimeSpan availableWorktimebreak = new TimeSpan()) : this(type, newProject, newComment, new List <WorktimeRecord>(), processed, availableWorktimebreak) { WorktimeRecords.Add(wtr); }
public WorktimeRecord(WorktimeRecord wtr) : this(wtr.Start, wtr.End, wtr.ProjectName, wtr.Comment) { }
public void refreshGrid() { if (storage == null) { return; } try { int firstDisplayed = Form.dataGridView1.FirstDisplayedScrollingRowIndex; int displayed = Form.dataGridView1.DisplayedRowCount(true); int lastVisible = (firstDisplayed + displayed) - 1; int lastIndex = Form.dataGridView1.RowCount - 1; bool shouldAutoscroll = lastVisible == lastIndex; Form.dataGridView1.SuspendLayout(); Form.dataGridView1.Rows.Clear(); WorktimeRecord lastWtr = null; DateTime from, to; ProjectUtilities.getWorkDayByDate(Form.dateTimePicker1.Value, out from, out to); var wtrs = storage.getAllWorktimeRecords(from, to); foreach (var wtr in wtrs) { //TODO overnighters Form.dataGridView1.Rows.Add( wtr.Start.Date.ToShortDateString(), wtr.Start.ToLongTimeString(), wtr.End.ToLongTimeString(), Math.Round((wtr.End - wtr.Start).TotalMinutes, 1), wtr.ProjectName, wtr.Comment, wtr.storageID); if (lastWtr != null && lastWtr.End.ToLongTimeString() != wtr.Start.ToLongTimeString()) { Form.dataGridView1.Rows[Form.dataGridView1.Rows.Count - 2].DividerHeight = 2; } lastWtr = wtr; } // If we need to show current project if (currentProject != null && DateTime.Now >= from && DateTime.Now <= to) { //Add current project Form.dataGridView1.Rows.Add( wtrs.Last().Start.Date.ToShortDateString(), wtrs.Last().End.ToLongTimeString(), "", "", currentProject, currentProjectComment, ""); //Make all cells except comment readonly int lastRow = Form.dataGridView1.Rows.Count - 1; foreach (DataGridViewCell cell in Form.dataGridView1.Rows[lastRow].Cells) { if (cell.OwningColumn.HeaderText != "Comment") { cell.ReadOnly = true; } } Form.dataGridView1.Rows[lastRow].DefaultCellStyle.BackColor = Color.Gold; Form.dataGridView1.Rows[lastRow].DefaultCellStyle.SelectionBackColor = Color.Gold; Form.dataGridView1.Rows[lastRow].DefaultCellStyle.ForeColor = Color.Gray; Form.dataGridView1.Rows[lastRow].DefaultCellStyle.SelectionForeColor = Color.Gray; } if (Form.dataGridView1.Rows.Count > 0) { if (shouldAutoscroll) { Form.dataGridView1.FirstDisplayedScrollingRowIndex = Form.dataGridView1.RowCount - Form.dataGridView1.DisplayedRowCount(true) + 1; } else if (Form.dataGridView1.FirstDisplayedScrollingRowIndex != -1 && firstDisplayed != -1) { Form.dataGridView1.FirstDisplayedScrollingRowIndex = firstDisplayed; //not actually true if not same day shown } } AnalyzeWorktimes(); Form.dataGridView1.ResumeLayout(); } catch (Exception) { //swallow TODO } }