コード例 #1
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!");
                 }
             }
         }
     }
 }
コード例 #2
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!");
             }
         }
     }
 }
コード例 #3
0
 public void setOfficeDropdownValues()
 {
     using (insuranceEntities ie = new insuranceEntities())
     {
         List <Office> offices = ie.Offices.ToList();
         officeListDropdown.DataSource    = offices;
         officeListDropdown.ValueMember   = "Id";
         officeListDropdown.DisplayMember = "DisplayName";
     }
 }
コード例 #4
0
 public void setCustomerDropdownValues()
 {
     using (insuranceEntities ie = new insuranceEntities())
     {
         List <Customer> customers = ie.Customers.Where(a => a.OfficeId == loggedInId).ToList();
         customerListDropdown.DataSource    = customers;
         customerListDropdown.ValueMember   = "Id";
         customerListDropdown.DisplayMember = "DisplayName";
         setCustomerStatus();
     }
 }
コード例 #5
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();
             }
         }
     }
 }
コード例 #6
0
 private void employeeLoginButton_Click(object sender, EventArgs e)
 {
     using (insuranceEntities ie = new insuranceEntities())
     {
         if (employeeUsernameInput.Text != string.Empty || employeePasswordInput.Text != string.Empty)
         {
             if (employeeUsernameInput.Text.Any(Char.IsWhiteSpace) || employeePasswordInput.Text.Any(Char.IsWhiteSpace))
             {
                 MessageBox.Show("No spaces allowed in username or password fields!");
             }
             else
             {
                 var user = ie.Offices.Where(a => a.Username.Equals(employeeUsernameInput.Text)).FirstOrDefault();
                 if (user != null)
                 {
                     if (user.Password.Equals(employeePasswordInput.Text))
                     {
                         employeeMainPage1.loggedInId = user.Id;
                         employeeMainPage1.Show();
                         employeeMainPage1.fixEmptyDatabaseFields();
                         employeeMainPage1.populateFields();
                         employeeMainPage1.setCustomerDropdownValues();
                         employeeMainPage1.BringToFront();
                         clearFields();
                     }
                     else
                     {
                         MessageBox.Show("Incorrect password!");
                     }
                 }
                 else
                 {
                     MessageBox.Show("Incorrect username!");
                 }
             }
         }
         else
         {
             MessageBox.Show("Please input username and password!");
         }
     }
 }
コード例 #7
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();
     }
 }
コード例 #8
0
 public void populateFields()
 {
     using (insuranceEntities ie = new insuranceEntities())
     {
         Customer customer = ie.Customers.Where(a => a.Id == loggedInId).FirstOrDefault();
         if (customer != null)
         {
             customerLicencePlateValue.Text = customer.LicencePlate;
             customerNameValue.Text         = customer.Name;
             customerPhoneValue.Text        = customer.Phone;
             List <Office> offices = ie.Offices.ToList();
             officeListDropdown.DataSource    = offices;
             officeListDropdown.ValueMember   = "Id";
             officeListDropdown.DisplayMember = "DisplayName";
             officeListDropdown.SelectedValue = customer.OfficeId;
             customerStatusValue.Text         = customer.Status;
             datePicker.Value = DateTime.Parse(customer.Date);
             timePicker.Value = DateTime.Parse(customer.Time);
         }
     }
 }
コード例 #9
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();
                 }
             }
         }
     }
 }
コード例 #10
0
 public void setCustomerStatus()
 {
     using (insuranceEntities ie = new insuranceEntities())
     {
         int selectedCustomerId;
         if (customerListDropdown.Items.Count > 0)
         {
             Int32.TryParse(customerListDropdown.SelectedValue.ToString(), out selectedCustomerId);
             if (selectedCustomerId != 0)
             {
                 Customer selectedCustomer = ie.Customers.Where(a => a.Id == selectedCustomerId).FirstOrDefault();
                 if (selectedCustomer != null)
                 {
                     customerStatusDropdown.SelectedItem = selectedCustomer.Status;
                 }
             }
         }
         else
         {
             customerStatusDropdown.SelectedItem = null;
         }
     }
 }
コード例 #11
0
        public void populateFields()
        {
            using (insuranceEntities ie = new insuranceEntities())
            {
                var office = ie.Offices.Where(a => a.Id == this.loggedInId).FirstOrDefault();
                if (office != null)
                {
                    if (office.Name != null)
                    {
                        officeNameInput.Text = office.Name;
                    }
                    else
                    {
                        officeNameInput.Text = "";
                    }

                    if (office.Location != null)
                    {
                        officeLocationInput.Text = office.Location;
                    }
                    else
                    {
                        officeLocationInput.Text = "";
                    }

                    if (office.Director != null)
                    {
                        officeDirectorInput.Text = office.Director;
                    }
                    else
                    {
                        officeDirectorInput.Text = "";
                    }
                }
                customerStatusDropdown.SelectedItem = null;
            }
        }
コード例 #12
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!");
             }
         }
     }
 }
コード例 #13
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!");
     }
 }
コード例 #14
0
 private void viewAppointmentButton_Click(object sender, EventArgs e)
 {
     if (RemoveWhitespace(licencePlateViewInput.Text) != string.Empty && RemoveWhitespace(customerPhoneViewInput.Text) != string.Empty)
     {
         bool isInputOK = true;
         if (RemoveWhitespace(licencePlateViewInput.Text).Length != 8)
         {
             MessageBox.Show("The licence plate consists of 8 symbols!");
             isInputOK = false;
         }
         else
         {
             string start       = RemoveWhitespace(licencePlateViewInput.Text).Substring(0, 2);
             string middle      = RemoveWhitespace(licencePlateViewInput.Text).Substring(2, 4);
             string end         = RemoveWhitespace(licencePlateViewInput.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(customerPhoneViewInput.Text).Length != 10)
         {
             MessageBox.Show("A valid mobile phone number consists of 10 digits!");
             isInputOK = false;
         }
         if (isInputOK == true)
         {
             string licencePlate = RemoveWhitespace(licencePlateViewInput.Text).ToUpper();
             string phoneNumber  = RemoveWhitespace(customerPhoneViewInput.Text);
             using (insuranceEntities ie = new insuranceEntities())
             {
                 Customer customer = ie.Customers.Where(a => a.LicencePlate.Equals(licencePlate, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                 if (customer != null)
                 {
                     if (customer.Phone.Equals(phoneNumber))
                     {
                         customerViewPage1.loggedInId = customer.Id;
                         customerViewPage1.Show();
                         customerViewPage1.populateFields();
                         customerViewPage1.BringToFront();
                         clearFields();
                     }
                     else
                     {
                         MessageBox.Show("Wrong phone number!");
                     }
                 }
                 else
                 {
                     MessageBox.Show("No appointment found!");
                 }
             }
         }
     }
     else
     {
         MessageBox.Show("Please input both fields!");
     }
 }