Exemple #1
0
 private void btnAddServiceFormSaveChanges_Click(object sender, EventArgs e)
 {
     service.ServiceName        = serviceNameTextBox.Text;
     service.ServiceDescription = serviceDescriptionTextBox.Text;
     service.ServiceCostPerHour = Convert.ToDecimal(serviceCostPerHourTextBox.Text);
     addServiceDb.Services.Add(service);
     addServiceDb.SaveChanges();
     servicesListForm = new ServicesListForm();
     servicesListForm.Show();
     this.Close();
 }
Exemple #2
0
 private void btnServicesFormDeleteService_Click(object sender, EventArgs e)
 {
     if (serviceIDTextBox.Text == "")
     {
         MessageBox.Show("No service selected. Please select a service to delete.", "Delete Error");
     }
     else
     {
         int currentService = Convert.ToInt32(serviceIDTextBox.Text);
         var editedService  = (from service in ServiceDb.Services
                               where service.ServiceID == currentService
                               select service).Single();
         DialogResult result = MessageBox.Show($"Delete Service ID: {editedService.ServiceID} | Name: {editedService.ServiceName}?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (result == DialogResult.Yes)
         {
             try
             {
                 ServiceDb.Services.Remove(editedService);
                 ServiceDb.SaveChanges();
             }
             catch (DbUpdateConcurrencyException)
             {
                 this.Close();
                 if (ServiceDb.Entry(editedService).State == EntityState.Detached)
                 {
                     MessageBox.Show("Another user has deleted that employee.", "Concurrency Error");
                 }
                 else
                 {
                     MessageBox.Show("Another user has updated that employee.", "Concurrency Error");
                 }
             }
             catch (DbUpdateException)
             {
                 this.Close();
                 MessageBox.Show("Unable to delete service. The service is shown to be used on invoices.", "Service Not Deleted");
                 ServicesListForm newForm = new ServicesListForm();
                 newForm.Show();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, ex.GetType().ToString());
             }
         }
     }
 }
Exemple #3
0
 private void btnAddServiceFormCancel_Click(object sender, EventArgs e)
 {
     servicesListForm = new ServicesListForm();
     servicesListForm.Show();
     this.Close();
 }