void GridDoubleClickHandler(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex == colNote.Index) { var time = (TimedEvent)grid.Rows[e.RowIndex].DataBoundItem; using (var form = new NoteWindow(time.Note)) if (form.ShowDialog(this) == DialogResult.OK) { time.Note = form.Note; } } }
void NewTimeNoteHandler(object sender, EventArgs e) { using (var form = new NoteWindow("")) if (form.ShowDialog(this) == DialogResult.OK) { using (var db = new DatabaseContext()) { var now = DateTime.Now; var last = m_user.GetTimes(db).OrderByDescending(fn => fn.Start).FirstOrDefault(); if (last.End == null) { last.End = now; } db.TimedEvents.Add(new TimedEvent { Start = now, UserId = m_user.UserId, Note = form.Note }); db.SaveChanges(); } } }
void EditNoteHandler(object sender, EventArgs e) { using (var db = new DatabaseContext()) { var last = m_user.GetTimes(db).OrderByDescending(fn => fn.Start).FirstOrDefault(); if (last == null) { return; } using (var form = new NoteWindow(last.Note)) { if (form.ShowDialog(this) != DialogResult.OK) { return; } last.Note = form.Note; db.SaveChanges(); } } }