private void DeleteRegistrationBtn_Click(object sender, EventArgs e) { if (registrationListBox.SelectedIndex < 0) { MessageBox.Show("Please select a registration"); return; } Registration registration = (Registration)registrationListBox.SelectedItem; string message = $"Are you sure you want to delete Customer #{registration.CustomerID}'s registration?"; DialogResult result = MessageBox.Show(text: message, caption: "Delete?", buttons: MessageBoxButtons.YesNo, icon: MessageBoxIcon.Question); if (result == DialogResult.Yes) { try { BookRegistrationDB.Delete(registration.CustomerID); registrationListBox.Items.Remove(registration); MessageBox.Show("Registration deleted"); } catch (SqlException) { MessageBox.Show("We are having server issues. Try again later"); } catch (Exception) { MessageBox.Show("No registrations were deleted"); } } }
private void ShowAllRegisteredForm_Load(object sender, EventArgs e) { List <Registration> allRegistration = BookRegistrationDB.GetAllRegistration(); allRegistration = allRegistration .OrderBy(id => id.CustomerID) .ToList(); registrationListBox.Items.Clear(); foreach (Registration r in allRegistration) { registrationListBox.Items.Add(r); } }
/// <summary> /// Registers a single selected customer and book /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RegisterProductButton_Click(object sender, EventArgs e) { if (IsSelectionValid() == true) { //Create a RegistrationConfirmationForm object RegisterConfirmationForm confirm = new RegisterConfirmationForm(); //Gives the user an option to confirm their registration or not DialogResult result = confirm.ShowDialog(); //If user clicks yes if (result == DialogResult.OK) { //Get the selected customer Customer c = (Customer)customerComboBox.SelectedItem; //Grab the selected book Book b = (Book)bookComboBox.SelectedItem; //Create a registration object Registration regBook = new Registration() { //Get the selected customer's CustomerID CustomerID = c.CustomerID, //Get the selected book's ISBN ISBN = b.ISBN, //Get the register date RegDate = dateRegisteredPicker.Value }; //Once the registration object has been created //set the new registration into the property (Registration.cs) NewReg = regBook; //Add the registration to the database BookRegistrationDB.RegisterBook(regBook); bookComboBox.Text = ""; customerComboBox.Text = ""; } } }
private void btnRegBook_Click(object sender, EventArgs e) { if (cboCustomer.SelectedIndex < 0 || cboBook.SelectedIndex < 0) { MessageBox.Show("You must make a selection."); return; } try { Customer selectedCust = (Customer)cboCustomer.SelectedItem; Book selectedBook = (Book)cboBook.SelectedItem; DateTime DateReg = (DateTime)dtpRegDate.Value; Registration updateReg = new Registration(selectedCust.CustomerID, selectedBook.ISBN, DateReg); BookRegistrationDB.RegisterBook(updateReg); } catch (SqlException sqlex) { MessageBox.Show("We are having server issues, please try again later."); } }