Beispiel #1
0
 private void updateOfficeInfoButton_Click(object sender, EventArgs e)
 {
     using (insuranceEntities ie = new insuranceEntities())
     {
         var office = ie.Offices.Where(a => a.Id == this.loggedInId).FirstOrDefault();
         if (office != null)
         {
             bool somethingUpdated = false;
             if (office.Name != officeNameInput.Text)
             {
                 office.Name      = officeNameInput.Text;
                 somethingUpdated = true;
             }
             if (office.Location != officeLocationInput.Text)
             {
                 office.Location  = officeLocationInput.Text;
                 somethingUpdated = true;
             }
             if (office.Director != officeDirectorInput.Text)
             {
                 office.Director  = officeDirectorInput.Text;
                 somethingUpdated = true;
             }
             if (somethingUpdated == true)
             {
                 ie.SaveChanges();
                 MessageBox.Show("Office information updated successfully!");
             }
         }
     }
 }
Beispiel #2
0
 private void updateCustomerButton_Click(object sender, EventArgs e)
 {
     if (customerListDropdown.Items.Count > 0)
     {
         using (insuranceEntities ie = new insuranceEntities())
         {
             int      selectedCustomerId = Int32.Parse(customerListDropdown.SelectedValue.ToString());
             Customer selectedCustomer   = ie.Customers.Where(a => a.Id == selectedCustomerId).FirstOrDefault();
             if (selectedCustomer != null)
             {
                 bool somethingUpdated = false;
                 if (selectedCustomer.Status != customerStatusDropdown.SelectedItem.ToString())
                 {
                     selectedCustomer.Status = customerStatusDropdown.SelectedItem.ToString();
                     somethingUpdated        = true;
                 }
                 if (somethingUpdated == true)
                 {
                     ie.SaveChanges();
                     MessageBox.Show("Customer information updated successfully!");
                 }
             }
         }
     }
 }
Beispiel #3
0
 private void deleteAppointmentButton_Click(object sender, EventArgs e)
 {
     using (insuranceEntities ie = new insuranceEntities())
     {
         Customer customer = ie.Customers.Where(a => a.Id == loggedInId).FirstOrDefault();
         if (customer != null)
         {
             if (MessageBox.Show("Are you sure you want to delete your appointment?", "Delete Appointment", MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
                 ie.Customers.Remove(customer);
                 ie.SaveChanges();
                 MessageBox.Show("Appointment successfully deleted!");
                 this.Hide();
             }
         }
     }
 }
Beispiel #4
0
 public void fixEmptyDatabaseFields()
 {
     using (insuranceEntities ie = new insuranceEntities())
     {
         var office = ie.Offices.Where(a => a.Id == this.loggedInId).FirstOrDefault();
         if (office.Name == null)
         {
             office.Name = "";
         }
         if (office.Location == null)
         {
             office.Location = "";
         }
         if (office.Director == null)
         {
             office.Director = "";
         }
         ie.SaveChanges();
     }
 }
Beispiel #5
0
 private void deleteCustomerButton_Click(object sender, EventArgs e)
 {
     if (customerListDropdown.Items.Count > 0)
     {
         using (insuranceEntities ie = new insuranceEntities())
         {
             int      selectedCustomerId = Int32.Parse(customerListDropdown.SelectedValue.ToString());
             Customer selectedCustomer   = ie.Customers.Where(a => a.Id == selectedCustomerId).FirstOrDefault();
             if (selectedCustomer != null)
             {
                 if (MessageBox.Show("Are you sure you want to remove the selected customer?", "Remove Customer", MessageBoxButtons.YesNo) == DialogResult.Yes)
                 {
                     ie.Customers.Remove(selectedCustomer);
                     ie.SaveChanges();
                     MessageBox.Show("Customer removed successfully!");
                     setCustomerDropdownValues();
                 }
             }
         }
     }
 }
Beispiel #6
0
 private void updateCustomerInfoButton_Click(object sender, EventArgs e)
 {
     using (insuranceEntities ie = new insuranceEntities())
     {
         Customer customer = ie.Customers.Where(a => a.Id == loggedInId).FirstOrDefault();
         if (customer != null)
         {
             bool somethingUpdated = false;
             if (customer.OfficeId != Int32.Parse(officeListDropdown.SelectedValue.ToString()))
             {
                 customer.OfficeId = Int32.Parse(officeListDropdown.SelectedValue.ToString());
                 somethingUpdated  = true;
             }
             if (customer.Date != datePicker.Value.ToString().Substring(0, 10))
             {
                 customer.Date    = datePicker.Value.ToString().Substring(0, 10);
                 somethingUpdated = true;
             }
             string hours = timePicker.Value.ToString().Substring(14, 5).Split(':')[0];
             if (hours.Length == 1)
             {
                 hours = "0" + hours;
             }
             string mins = timePicker.Value.ToString().Substring(14, 5).Split(':')[1];
             if (mins.Length == 1)
             {
                 mins = "0" + mins;
             }
             string          time = hours + ":" + mins;
             bool            canUpdateAppointment    = true;
             int             selectedOfficeId        = Int32.Parse(officeListDropdown.SelectedValue.ToString());
             List <Customer> selectedOfficeCustomers = ie.Customers.Where(a => a.OfficeId == selectedOfficeId).ToList();
             foreach (var item in selectedOfficeCustomers)
             {
                 if (item.Id != loggedInId)
                 {
                     if (item.Date == datePicker.Value.ToString().Substring(0, 10) && item.Time == time)
                     {
                         canUpdateAppointment = false;
                         break;
                     }
                 }
             }
             if (customer.Time != time)
             {
                 customer.Time    = time;
                 somethingUpdated = true;
             }
             if (canUpdateAppointment == true)
             {
                 if (somethingUpdated == true)
                 {
                     ie.SaveChanges();
                     MessageBox.Show("Appointment successfully updated!");
                 }
             }
             else
             {
                 MessageBox.Show("Selected date and time combination is taken in selected office!");
             }
         }
     }
 }
Beispiel #7
0
 private void setAppointmentButton_Click(object sender, EventArgs e)
 {
     if (RemoveWhitespace(licencePlateSetInput.Text) != string.Empty && customerNameInput.Text != string.Empty && customerPhoneSetInput.Text != string.Empty)
     {
         using (insuranceEntities ie = new insuranceEntities())
         {
             List <Customer> customers = ie.Customers.ToList();
             bool            found     = false;
             foreach (var item in customers)
             {
                 if (item.LicencePlate.Equals(RemoveWhitespace(licencePlateSetInput.Text), StringComparison.InvariantCultureIgnoreCase) && item.OfficeId == Int32.Parse(officeListDropdown.SelectedValue.ToString()))
                 {
                     found = true;
                     break;
                 }
             }
             if (found == true)
             {
                 MessageBox.Show("This licence plate is already registered in an insurance office!");
             }
             else
             {
                 bool isInputOK = true;
                 if (RemoveWhitespace(licencePlateSetInput.Text).Length != 8)
                 {
                     MessageBox.Show("The licence plate consists of 8 symbols!");
                     isInputOK = false;
                 }
                 else
                 {
                     string start       = RemoveWhitespace(licencePlateSetInput.Text).Substring(0, 2);
                     string middle      = RemoveWhitespace(licencePlateSetInput.Text).Substring(2, 4);
                     string end         = RemoveWhitespace(licencePlateSetInput.Text).Substring(6, 2);
                     bool   startRegex  = Regex.IsMatch(start, @"^[a-zA-Z]+$");
                     bool   middleRegex = Regex.IsMatch(middle, @"^[0-9]+$");
                     bool   endRegex    = Regex.IsMatch(end, @"^[a-zA-Z]+$");
                     if (!startRegex)
                     {
                         MessageBox.Show("First 2 licence plate symbols must be latin letters!");
                         isInputOK = false;
                     }
                     if (!middleRegex)
                     {
                         MessageBox.Show("Middle 4 licence plate symbols must be positive digits!");
                         isInputOK = false;
                     }
                     if (!endRegex)
                     {
                         MessageBox.Show("Last 2 licence plate symbols must be latin letters!");
                         isInputOK = false;
                     }
                 }
                 if (RemoveWhitespace(customerPhoneSetInput.Text).Length != 10)
                 {
                     MessageBox.Show("A valid mobile phone number consists of 10 digits!");
                     isInputOK = false;
                 }
                 if (isInputOK == true)
                 {
                     Customer customer = new Customer();
                     customer.LicencePlate = RemoveWhitespace(licencePlateSetInput.Text).ToUpper();
                     customer.Name         = customerNameInput.Text;
                     customer.Phone        = RemoveWhitespace(customerPhoneSetInput.Text);
                     customer.OfficeId     = Int32.Parse(officeListDropdown.SelectedValue.ToString());
                     customer.Status       = "Booked";
                     string hours = timePicker.Value.ToString().Substring(14, 5).Split(':')[0];
                     if (hours.Length == 1)
                     {
                         hours = "0" + hours;
                     }
                     string mins = timePicker.Value.ToString().Substring(14, 5).Split(':')[1];
                     if (mins.Length == 1)
                     {
                         mins = "0" + mins;
                     }
                     string          time = hours + ":" + mins;
                     bool            canSaveAppointment      = true;
                     List <Customer> selectedOfficeCustomers = ie.Customers.Where(a => a.OfficeId == customer.OfficeId).ToList();
                     foreach (var item in selectedOfficeCustomers)
                     {
                         if (item.Date == datePicker.Value.ToString().Substring(0, 10) && item.Time == time)
                         {
                             canSaveAppointment = false;
                             break;
                         }
                     }
                     customer.Date = datePicker.Value.ToString().Substring(0, 10);
                     customer.Time = time;
                     if (canSaveAppointment == true)
                     {
                         ie.Customers.Add(customer);
                         ie.SaveChanges();
                         MessageBox.Show("Appointment successfully booked!");
                         clearFields();
                     }
                     else
                     {
                         MessageBox.Show("Selected date and time combination is taken in selected office!");
                     }
                 }
             }
         }
     }
     else
     {
         MessageBox.Show("Please input all fields!");
     }
 }