private void SuppAdd_Click(object sender, RoutedEventArgs e) { if (SupplierID.Text == "" || CompanyName.Text == "" || Address.Text == "" || City.Text == "" || Region.Text == "" || Postal.Text == "" || Country.Text == "" || Email.Text == "" || Phone.Text == "") { MessageBox.Show("All Fields are required"); } else { dataAccess data = new dataAccess(); if (MessageBox.Show("Continue to add a new supplier ??", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { //do no stuff } else { //if Yes if (SupplierID.IsEnabled == false && SupplierID.IsReadOnly == true) { MessageBox.Show("Supplier Identity Number Field is Enabled now Enter the Employee Number of a new Employee"); SupplierID.IsEnabled = true; SupplierID.IsReadOnly = false; CompanyName.IsEnabled = false; CompanyName.IsReadOnly = true; Address.IsEnabled = false; Address.IsReadOnly = true; City.IsEnabled = false; City.IsReadOnly = true; Region.IsEnabled = false; Region.IsReadOnly = true; Postal.IsEnabled = false; Postal.IsReadOnly = true; Country.IsEnabled = false; Country.IsReadOnly = true; Email.IsEnabled = false; Email.IsReadOnly = true; Phone.IsEnabled = false; Phone.IsReadOnly = true; SuppEdit.IsEnabled = false; SuppDelete.IsEnabled = false; btnClear.IsEnabled = false; } else if (SupplierID.IsEnabled == true && SupplierID.IsReadOnly == false) { if (Email.Text.Length == 0) { MessageBox.Show("Enter an email."); Email.Focus(); } else if (!Regex.IsMatch(Email.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")) { MessageBox.Show("Enter a valid email."); Email.Select(0, Email.Text.Length); Email.Focus(); Email.IsEnabled = true; Email.IsReadOnly = false; } else { string status = data.insertSupplier(int.Parse(SupplierID.Text), CompanyName.Text, Address.Text, City.Text, Region.Text, int.Parse(Postal.Text), Country.Text, Int64.Parse(Phone.Text), Email.Text); if (status.Equals("Successful")) { MessageBox.Show("New Supplier Inserted"); SupplierID.IsEnabled = false; SupplierID.IsReadOnly = true; CompanyName.IsEnabled = true; CompanyName.IsReadOnly = false; Address.IsEnabled = true; Address.IsReadOnly = false; City.IsEnabled = true; City.IsReadOnly = false; Region.IsEnabled = true; Region.IsReadOnly = false; Postal.IsEnabled = true; Postal.IsReadOnly = false; Country.IsEnabled = true; Country.IsReadOnly = false; Email.IsEnabled = true; Email.IsReadOnly = false; Phone.IsEnabled = true; Phone.IsReadOnly = false; SuppEdit.IsEnabled = true; SuppDelete.IsEnabled = true; btnClear.IsEnabled = true; SupplierID.Text = ""; CompanyName.Text = ""; Address.Text = ""; City.Text = ""; Region.Text = ""; Postal.Text = ""; Country.Text = ""; Email.Text = ""; Phone.Text = ""; } else if (status.Equals("Unsuccessful")) { MessageBox.Show("The supplier already exist "); } } } } } }