private async void BtnDelete_Click(object sender, EventArgs e) { try { var result = MessageBox.Show($"Are you sure you want to delete this record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); // If the no button was pressed ... if (result == DialogResult.No) { // cancel the closure of the form. } else { EventAndAppointmentModel eventModel = new EventAndAppointmentModel(db); int id = int.Parse(dvEvents.Rows[selectedRowIndex].Cells[0].Value.ToString()); await eventModel.DeleteEventAndAppointmentById(id); MessageBox.Show("Successfully deleted"); GetEventsAndAppointments(); btnEdit.Enabled = false; btnDelete.Enabled = false; } } catch (Exception ex) { MessageBox.Show("Failed to delete record"); } }
private async void GetEventsAndAppointments() { try { EventAndAppointmentModel eventAndAppointmentModel = new EventAndAppointmentModel(db); var events = await eventAndAppointmentModel.GetEventAndAppointments(); allEvents = events; LoadEventsAndAppointments(events); btnDelete.Enabled = false; btnEdit.Enabled = false; } catch (Exception ex) { Console.WriteLine(ex.ToString()); MessageBox.Show("Failed to get events"); } }
private async void LoadTodaysEvents() { try { EventAndAppointmentModel eventAndAppointmentModel = new EventAndAppointmentModel(db); var todaysEvents = await eventAndAppointmentModel.GetTodayEventAndAppointments(); BindingSource bs = new BindingSource(); bs.DataSource = todaysEvents; gvEventsDashboard.Columns.Clear(); gvEventsDashboard.AutoGenerateColumns = false; gvEventsDashboard.DataSource = bs; gvEventsDashboard.ReadOnly = true; gvEventsDashboard.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; DataGridViewColumn col1 = new DataGridViewTextBoxColumn(); col1.DataPropertyName = "Name"; col1.HeaderText = "Name"; gvEventsDashboard.Columns.Add(col1); DataGridViewColumn col2 = new DataGridViewTextBoxColumn(); col2.DataPropertyName = "Description"; col2.HeaderText = "Description"; gvEventsDashboard.Columns.Add(col2); DataGridViewColumn col3 = new DataGridViewTextBoxColumn(); col3.DataPropertyName = "Date"; col3.HeaderText = "Date"; gvEventsDashboard.Columns.Add(col3); DataGridViewColumn col4 = new DataGridViewTextBoxColumn(); col4.DataPropertyName = "Date"; col4.HeaderText = "Status"; gvEventsDashboard.Columns.Add(col4); } catch (Exception ex) { Console.WriteLine(ex.Message); MessageBox.Show("Failed to load todays events"); } }
private async void BtnAdd_Click(object sender, EventArgs e) { try { bool nameValid = false; if (string.IsNullOrEmpty(txtName.Text.ToString())) { errorProvider1.SetError(txtName, "Name required"); } else { nameValid = true; errorProvider1.SetError(txtName, ""); } if (!nameValid) { return; } EventAndAppointment curentEvent = new EventAndAppointment(); curentEvent.Name = txtName.Text; curentEvent.Description = txtDescription.Text; curentEvent.Date = dtpEvent.Value; RecursiveItem recItem = null; if (repeatToggle.Checked) { recItem = new RecursiveItem(); curentEvent.IsRepeat = true; recItem.Type = "Event"; recItem.Every = int.Parse(cbRepeatValues.SelectedItem.ToString()); recItem.Option = cbRepeatValuesType.SelectedItem.ToString(); if (recItem.Option.Equals("Month")) { recItem.Day = dtpRepeat.Value.Day; } } else { curentEvent.IsRepeat = false; } EventAndAppointmentModel eventAndAppointmentModel = new EventAndAppointmentModel(db); if (editingEventAndAppointment == null) { if (repeatToggle.Checked) { RecursiveItemModel recursiveItemModel = new RecursiveItemModel(db); await recursiveItemModel.SaveRecursiveItem(recItem); curentEvent.RecursiveItemId = recItem.Id; } await eventAndAppointmentModel.SaveEventAndAppointment(curentEvent); MessageBox.Show("Successfully created."); } else { curentEvent.Id = editingEventAndAppointment.Id; await eventAndAppointmentModel.UpdateEventAndAppointment(curentEvent); MessageBox.Show("Successfully updated."); } eventAndAppointment.HandleClose(); this.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); MessageBox.Show("Failed to add event"); } }