private void btnDelete_Click(object sender, EventArgs e) { var controls = panelDetails.Controls.Cast <Control>(); if (controls.Any()) { var confirmResult = MessageBox.Show("Jesteś pewien, że chcesz usunąć tą aktywność?", "Potwierdź", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { if (Delete.Handler(Convert.ToInt32(controls.First().Name), out exception) && exception == null) { panelDetails.Controls.Clear(); panelEdit.Visible = false; panelRefresh.Refresh(); } else { exception = null; } } } }
private void MainForm_Load(object sender, EventArgs e) { Details.panel = panelDetails; panelRefresh = new PanelRefresh(panelTodoList, panelDoneList); ChangeStatus.PanelRefresh = panelRefresh; dateTimePickerAddActivity.MinDate = DateTime.Today; dateTimePickerEditActivity.MinDate = DateTime.Today; using (var context = new DataContext()) { try { context.Database.Migrate(); } catch (Exception ex) { MessageBox.Show("Database problem: " + ex); } } panelRefresh.Refresh(); List notifications = new List(); notifications.SoonActivitesNotification().ForEach(x => x.Show()); }
public static bool Handler(Activity activity) { using (DataContext dataContext = new DataContext()) { var newStatus = (activity.Status == Status.DoZrobienia) ? Status.Gotowe : Status.DoZrobienia; if (activity == null) { return(false); } activity.Status = newStatus; dataContext.Activities.Update(activity); dataContext.SaveChanges(); } PanelRefresh.Refresh(); return(true); }