private void dataGrid1_PreviewKeyDown(object sender, KeyEventArgs e) { var Grid = (DataGrid)sender; if (e.Key == Key.Delete) { foreach (var row in Grid.SelectedItems) { PositionOfDay PosOfDay = row as PositionOfDay; if (PosOfDay != null) { ActionResult saveRes = Engine.RemoveNoteFromDB(PosOfDay.CurrentHour, PosOfDay.CurrentMinute); if (!saveRes.IsSuccess) { MessageBox.Show(saveRes.ErrorMsg, "Error"); } } } Engine.UpdateOfPositions(); } else if (e.Key == Key.Escape) { PositionOfDay PosOfDay = Grid.SelectedItem as PositionOfDay; if (PosOfDay != null) { ActionResult saveRes = Engine.RemoveNoteFromDB(PosOfDay.CurrentHour, PosOfDay.CurrentMinute); if (!saveRes.IsSuccess) { MessageBox.Show(saveRes.ErrorMsg, "Error"); } if (!string.IsNullOrWhiteSpace(PosOfDay.OldNote)) { var fodg = new FieldsOfDataGrid() { Hour = PosOfDay.OldHour, Minute = PosOfDay.OldMinute, Note = PosOfDay.OldNote, User = PosOfDay.OldUser }; ActionResult addNoteResult = Engine.AddNoteToDB(fodg); if (!addNoteResult.IsSuccess) { MessageBox.Show(addNoteResult.ErrorMsg, "Error"); } } Engine.UpdateOfPositions(); } } }
public WindowOfPositions(PositionOfDay position, CalendarEngine engine) : this() { _PositionOfDay = position; DataContext = _PositionOfDay; _CalendarEngine = engine; _Date = _CalendarEngine.Selected_Date; tbDate.Text = _Date.ToString().Remove(10) + _Date.ToString(" (dddd)"); tbUser.Text = _PositionOfDay.CurrentUser; }
public WindowOfPositions(PositionOfDay position, CalendarEngine engine) : this() { _PositionOfDay = position; DataContext = _PositionOfDay; _CalendarEngine = engine; _Date = _CalendarEngine.Selected_Date; tbDate.Text = _Date.ToString().Remove(10) + _Date.ToString(" (dddd)"); tbUser.Text = _PositionOfDay.CurrentUser; }