private void FillComboBox()
        {
            if (TitleCB.Items.IsEmpty == true || TypeCB.Items.IsEmpty == true)
            {
                EmployeeController controller = new EmployeeController();
                List<string> titles = controller.GetListOfTitles();
                foreach (string title in titles)
                {
                    string[] titleArray = title.Split(',');
                    ComboBoxItem item = new ComboBoxItem();
                    item.Tag = titleArray[0];
                    item.Content = titleArray[1];
                    TitleCB.Items.Add(item);
                }

                List<string> types = controller.GetListOfTypes();
                foreach (string type in types)
                {
                    string[] typeArray = type.Split(',');
                    ComboBoxItem item = new ComboBoxItem();
                    item.Tag = typeArray[0];
                    item.Content = typeArray[1];
                    TypeCB.Items.Add(item);
                }
                List<string> emails = controller.GetListOfEmails();
                foreach (string email in emails)
                {
                    ComboBoxItem item = new ComboBoxItem();
                    item.Content = email;
                    item.Tag = email;
                    EmailCB.Items.Add(item);
                }
            }
        }
 private void PickEmailEvent(object sender, EventArgs e)
 {
     if (EmailCB.Text != string.Empty)
     {
         EmployeeController controller = new EmployeeController();
         Employee emp = controller.GetEmployeeByEmail(EmailCB.Text);
         NameTB.Text = emp.Name;
         AdressTB.Text = emp.Address;
         TypeCB.Text = emp.Type;
         TitleCB.Text = emp.Title;
         WorkHoursTB.Text = emp.WorkHours.ToString();
         DateTime date = DateTime.Parse(emp.DateOfEmployment);
         DateEmploymentTB.Text = date.ToString("dd-MM-yyyy");
     }
 }
 private void UpdateEmployeeBtn_Click(object sender, RoutedEventArgs e)
 {
     #region ErrorHandling
     string errorString = String.Empty;
     int test;
     bool valid = true;
     if (NameTB.Text == String.Empty || NameTB.Text.Length > 128)
     {
         valid = false;
         errorString += ("\nName must be filled out and shorter than 128 characters.");
     }
     if (AdressTB.Text == String.Empty || AdressTB.Text.Length > 256)
     {
         valid = false;
         errorString += ("\nAddress must be filled out and shorter than 256 characters.");
     }
     if (WorkHoursTB.Text == String.Empty || int.TryParse(WorkHoursTB.Text, out test) == false)
     {
         valid = false;
         errorString += ("\nWork hours must be filled out and only be in numbers.");
     }
     #endregion
     if (valid)
     {
         string TitleId = ((ComboBoxItem)TitleCB.SelectedItem).Tag.ToString();
         string TypeId = ((ComboBoxItem)TypeCB.SelectedItem).Tag.ToString();
         EmployeeController EC = new EmployeeController();
         MessageBox.Show(EC.UpdateEmployee(NameTB.Text, AdressTB.Text, EmailCB.Text, TypeId, TitleId, WorkHoursTB.Text, EndEmploymentDP.Text));
     }
     else
         MessageBox.Show("The following needs to be fixed:\n" + errorString);
 }
 private void DeleteEmployeeBtn_Click(object sender, RoutedEventArgs e)
 {
     EmployeeController EC = new EmployeeController();
     MessageBox.Show(EC.DeleteEmployee(EmailCB.Text));
     NameTB.Text = string.Empty;
     AdressTB.Text = string.Empty;
     EmailCB.Text = string.Empty;
     TypeCB.Text = string.Empty;
     TitleCB.Text = string.Empty;
     WorkHoursTB.Text = string.Empty;
     DateEmploymentTB.Text = string.Empty;
     EndEmploymentDP.Text = string.Empty;
     FillComboBox();
 }
 private void RefreshTable()
 {
     EmployeeController cont = new EmployeeController();
     this.EmployeeLv.ItemsSource = cont.employees;
 }
 private void CreateEmployeeBtn_Click(object sender, RoutedEventArgs e)
 {
     #region ErrorHandling
     string errorString = String.Empty;
     int test;
     bool valid = true;
     if (NameTB.Text == String.Empty || NameTB.Text.Length > 128)
     {
         valid = false;
         errorString += ("\nName must be filled out and shorter than 128 characters.");
     }
     if (AddressTB.Text == String.Empty || AddressTB.Text.Length > 256)
     {
         valid = false;
         errorString += ("\nAddress must be filled out and shorter than 256 characters.");
     }
     if (EmailTB.Text == String.Empty || EmailTB.Text.Length > 128 || EmailTB.Text.Contains('@') != true || EmailTB.Text.Contains('.') != true)
     {
         valid = false;
         errorString += ("\nE-mail must be filled out, be under 128 characters and contain '.' and '@'.");
     }
     if (TitleCB.Text == String.Empty)
     {
         valid = false;
         errorString += ("\nYou must choose a title.");
     }
     if (TypeCB.Text == String.Empty)
     {
         valid = false;
         errorString += ("\nYou must choose a type.");
     }
     if (WorkHoursTB.Text == String.Empty || int.TryParse(WorkHoursTB.Text, out test) == false)
     {
         valid = false;
         errorString += ("\nWork hours must be filled out and only be in numbers.");
     }
     if (DateEmploymentDP.Text == String.Empty)
     {
         valid = false;
         errorString += ("\nYou must choose a date.");
     }
     #endregion 
     if (valid)
     {
         string TitleId = ((ComboBoxItem)TitleCB.SelectedItem).Tag.ToString();
         string TypeId = ((ComboBoxItem)TypeCB.SelectedItem).Tag.ToString();
         EmployeeController EC = new EmployeeController();
         MessageBox.Show(EC.CreateEmployee(NameTB.Text, AddressTB.Text, EmailTB.Text, TypeId, TitleId, WorkHoursTB.Text, DateEmploymentDP.Text));
     }
     else
         MessageBox.Show("The following needs to be fixed:\n" + errorString);
     NameTB.Text = String.Empty;
     AddressTB.Text = String.Empty;
     EmailTB.Text = String.Empty;
     WorkHoursTB.Text = String.Empty;
     DateEmploymentDP.Text = String.Empty;
     TitleCB.Text = String.Empty;
     TypeCB.Text = String.Empty;
 }