예제 #1
0
 private void button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         int id = (idlist.SelectionBoxItem as Trainee).Id;
         MessageBoxResult answer = MessageBox.Show("do you sure you want delete trainee " + id + "?", "Verify deletion", MessageBoxButton.YesNo, MessageBoxImage.Warning);
         if (answer == MessageBoxResult.Yes)
         {
             bl.DeleteTrainee(id);
             MessageBox.Show("deleted successfully");
         }
         else
         {
             MessageBox.Show("deleted cancaled");
         }
     }
     catch (Exception ex)
     {
         MainWindow.ErrorMessage(ex.Message);
     }
     finally
     {
         initializeData();
         idlist.SelectedIndex = -1;
     }
 }
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         bool error = false;
         //if the id is invalid - label error and out.
         if (!CheckIfIDisValid(int.Parse(idTextBox.Text)))
         {
             errorIdMessage.Visibility = Visibility.Visible;
             error = true;
         }
         //if the phone number is invalid - label error and out.
         if (phoneNumberTextBox.Text.ToString().Length != 9)
         {
             errorPhoneMessage.Visibility = Visibility.Visible;
             error = true;
         }
         //if was problem.
         if (error)
         {
             addTesterButton.Background = new SolidColorBrush(Colors.Red);
             return;
         }
         bool oneOrMoreEmpty = false;
         foreach (UIElement txtbxs in this.grid1.Children)
         {
             if (txtbxs is TextBox)
             {
                 var TBox = (TextBox)txtbxs;
                 if (TBox.Text == string.Empty)
                 {
                     TBox.Background = new SolidColorBrush(Colors.Red);
                     oneOrMoreEmpty  = true;
                 }
             }
         }
         if (oneOrMoreEmpty)
         {
             MainWindow.ErrorMessage("you have a cells empty, fill all and try again");
             return;
         }
         tester.Address  = new Address(street.Text, int.Parse(building_number.Text), city.Text);
         tester.WorkDays = new bool[5, 6];
         for (int i = 0; i < 5; i++)
         {
             for (int j = 0; j < 6; j++)
             {
                 tester.WorkDays[i, j] = WorkHours.Children.OfType <CheckBox>().Where(box => box.Name == "checkBox" + i + "_" + j).Select(box => (bool)box.IsChecked).First();
             }
         }
         bl.AddTester(tester);
         clearAll();
     }
     catch (Exception ex)
     {
         errorMessage.Text = $"Error! {ex.Message}";
     }
 }
 private void AddTraineeUsercontol_traineeAdded(object sender, EventArgs e)
 {
     createTrainee.Visibility = Visibility.Hidden;
     create1.Visibility       = Visibility.Visible;
     this.MinHeight          -= 30;
     this.MaxHeight          -= 80;
     this.Height -= 30;
     MainWindow.ErrorMessage("the trainee created. you can register now as user");
 }
예제 #4
0
        /// <summary>
        /// Event that start when change-password button clicked. and try to change than
        /// </summary>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            User user = factoryBL.FactoryBL.GetBL().GetUser(username.Text, OldPassword.Password);

            if (user == null)
            {
                MainWindow.ErrorMessage("username or password is valid. try again!");
            }
            else if (NewPassword.Password != NewPassword2.Password)
            {
                MainWindow.ErrorMessage("Make sure you've entered the same password twice");
            }
            else
            {
                bool done = factoryBL.FactoryBL.GetBL().ChangePassword(user, OldPassword.Password, NewPassword.Password);
                if (done)
                {
                    MessageBox.Show("Password changed successfully.");
                    string message = "";
                    switch (user.role)
                    {
                    case User.RoleTypes.Trainee:
                        message = " teacher";
                        break;

                    case User.RoleTypes.Teacher:
                        message = " school administrator";
                        break;

                    case User.RoleTypes.Tester:
                    case User.RoleTypes.School:
                        message = " contact at the Driving system";
                        break;

                    case User.RoleTypes.Admin:
                        message = "self";
                        break;
                    }
                    MailSender.MailSender.sendMail(user.EmailAddress, user.Username, "Driving system - Password changed alert",
                                                   "If it wasn't you who changed tyhe password, please contact your" + message);
                    this.Close();
                }
                else
                {
                    MainWindow.ErrorMessage("Something happened. Failed to change password.");
                }
            }
        }
예제 #5
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                bool oneOrMoreEmpty = false;
                foreach (UIElement txtbxs in this.grid1.Children)
                {
                    if (txtbxs is TextBox)
                    {
                        var TBox = (TextBox)txtbxs;
                        if (TBox.Text == string.Empty)
                        {
                            TBox.Background = new SolidColorBrush(Colors.Red);
                            oneOrMoreEmpty  = true;
                        }
                    }
                }
                if (oneOrMoreEmpty)
                {
                    MainWindow.ErrorMessage("you have a cells empty, fill all and try again");
                    return;
                }
                tester.Address  = new Address(street.Text, int.Parse(building_number.Text), city.Text);
                tester.WorkDays = new bool[5, 6];
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        tester.WorkDays[i, j] = WorkHours.Children.OfType <CheckBox>().Where(box => box.Name == "checkBox" + i + "_" + j).Select(box => (bool)box.IsChecked).First();
                    }
                }

                bl.UpdateTester(tester);
                MessageBox.Show(string.Format("tester {0} successfully updated", tester.Id));
                if (idTextBox.IsEnabled)
                {
                    clearAll();
                }
            }
            catch (Exception ex)
            {
                MainWindow.ErrorMessage(ex.Message);
            }
        }
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (role == null)
     {
         MainWindow.ErrorMessage("choose role");
         return;
     }
     try
     {
         bool empty = false;
         if (adminRadio.IsChecked == false && items.SelectionBoxItem.ToString() == string.Empty)
         {
             empty = true;
         }
         if (Username.Text == string.Empty)
         {
             empty = true;
             Username.Background = new SolidColorBrush(Colors.Red);
         }
         if (password.Password == string.Empty)
         {
             empty = true;
             password.Background = new SolidColorBrush(Colors.Red);
         }
         if (empty)
         {
             MainWindow.ErrorMessage("one or more from the nessery box empty");
         }
         else
         {
             bl.CreateUser(Username.Text, password.Password, (User.RoleTypes)role, items.SelectionBoxItem, email.Text);
             Username.Text     = string.Empty;
             password.Password = string.Empty;
             email.Text        = string.Empty;
             MessageBox.Show("successe", "new user created successfully", MessageBoxButton.OK, MessageBoxImage.Information);
         }
     }
     catch (Exception ex)
     {
         message.Content = ex.Message;
     }
 }
예제 #7
0
 private void IdTextBox_SelectionChanged(object sender, EventArgs e)
 {
     try
     {
         tester            = bl.GetTesterById(int.Parse(idTextBox.SelectedValue.ToString()));
         grid1.DataContext = tester;
         for (int i = 0; i < 5; i++)
         {
             for (int j = 0; j < 6; j++)
             {
                 WorkHours.Children.OfType <CheckBox>().Where(box => box.Name == "checkBox" + i + "_" + j).First().IsChecked = tester.WorkDays[i, j];
             }
         }
         city.Text            = tester.Address.city;
         street.Text          = tester.Address.street_name;
         building_number.Text = tester.Address.building_number.ToString();
     }
     catch (Exception ex)
     {
         MainWindow.ErrorMessage(ex.Message);
     }
 }
예제 #8
0
 /// <summary>
 /// event of create new trainee that happen when the button is click
 /// </summary>
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         bool   oneOrMoreEmpty = false;
         string whoEmpty       = "";
         foreach (Control txtbxs in this.input.Children)
         {
             if (txtbxs is TextBox)
             {
                 var TBox = (TextBox)txtbxs;
                 if (TBox.Text == string.Empty)
                 {
                     TBox.Background = new SolidColorBrush(Colors.Red);
                     oneOrMoreEmpty  = true;
                     whoEmpty       += TBox.Name + " ";
                 }
             }
         }
         if (oneOrMoreEmpty)
         {
             MainWindow.ErrorMessage(string.Format("you have a cells {0} is empty, fill all and try again", whoEmpty));
             return;
         }
         trainee.Address = new Address(street_name.Text, int.Parse(building_number.Text), city.Text);
         bl.AddTrainee(trainee);
         traineeAdded?.Invoke(sender, new EventArgs());
         trainee                 = new Trainee();
         DataContext             = trainee;
         city.Text               = ""; building_number.Text = ""; street_name.Text = "";
         errorMessage.Text       = "Successfully added!";
         errorMessage.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF3CBA54"));
     }
     catch (Exception ex)
     {
         errorMessage.Text       = ex.Message;
         errorMessage.Foreground = Brushes.Red;
     }
 }