Пример #1
0
        ///<summary>
        ///when users input all data to textBoxes clicked on this button user go to workWindow but before system will checked all data in textBoxes and checked if this user exist
        ///</summary>
        private void button_sign_in_Click(object sender, RoutedEventArgs e)
        {
            // here you will need to check that a username and password exist in dB it should be done in a separate function which will check it
            //a function that checks if there is a user with such data entered in the fields
            // здесь нужно будет проверить что такой логи и пароль существуют в бд это нужно сделать в отдельной фукции которая будет проверять это
            //функция которая проверяет если есть такой пользователь с такими данными введенными в поля
            if (InputFieldsManager.CheckPasswordValidity(passwordBox_enter))
            {
                //these functions return a string with the maintained data in their textbooks
                //данные функции возвращают строку с веденными данными в их текстБоксы
                string login    = InputFieldsManager.ReturnStringFromTextBox(textBox_login),
                       password = InputFieldsManager.ReturnPasswordFromTextBox(passwordBox_enter);

                //if all is OK, so we go to the Work window
                long userID = CredentialsManager.Authorize(login, password);
                if (userID != -1)
                {
                    using (StreamWriter writer = new StreamWriter("id.txt"))
                    {
                        writer.Write(userID);
                    }
                    GoToWork(LibrarianDataManager.GetUserById(userID));
                }
                else
                {
                    MessageBox.Show("Error. Can not find user with current login and password");
                }
            }
            else
            {
                MessageBox.Show("Such user doesn't exist");
            }
        }
Пример #2
0
        private void save_user_Click(object sender, RoutedEventArgs e)
        {
            if (name_of_new_user.Text != null &&
                lastname_of_new_user.Text != null &&
                phone_of_new_user.Text != null &&
                town_of_new_user.Text != null &&
                street_of_new_user.Text != null &&
                house_of_new_user.Text != null &&
                flat_of_new_user.Text != null &&
                InputFieldsManager.CheckPasswordValidity(user_new_password))
            {
                string firstName  = InputFieldsManager.ReturnStringFromTextBox(name_of_new_user),
                       secondName = InputFieldsManager.ReturnStringFromTextBox(lastname_of_new_user),
                       phone      = InputFieldsManager.ReturnStringFromTextBox(phone_of_new_user),
                       address    = InputFieldsManager.ReturnStringFromTextBox(town_of_new_user) + ' ' +
                                    InputFieldsManager.ReturnStringFromTextBox(street_of_new_user) + ' ' +
                                    InputFieldsManager.ReturnStringFromTextBox(house_of_new_user) + ' ' +
                                    InputFieldsManager.ReturnStringFromTextBox(flat_of_new_user) + ' ';
                string password = InputFieldsManager.ReturnPasswordFromTextBox(user_new_password);
                string login    = firstName.Substring(0, 1) + '.' + secondName;

                bool IsNewUserAdded = false;
                if (InstructorCheckBoxType.IsChecked == true)
                {
                    IsNewUserAdded = LibrarianDataManager.AddFaculty(
                        new Faculty(firstName, secondName, phone, address, "Instructor"), login, password);
                }
                else if (librarianCheckBoxType.IsChecked == true)
                {
                    IsNewUserAdded = LibrarianDataManager.AddLibrarian(
                        new Librarian(firstName, secondName, phone, address), login, password);
                }
                else if (studentCheckBoxType.IsChecked == true)
                {
                    IsNewUserAdded = LibrarianDataManager.AddStudent(
                        new Student(firstName, secondName, phone, address), login, password);
                }
                else if (taCheckBoxType.IsChecked == true)
                {
                    IsNewUserAdded = LibrarianDataManager.AddFaculty(
                        new Faculty(firstName, secondName, phone, address, "TA"), login, password);
                }
                else if (professorCheckBoxType.IsChecked == true)
                {
                    IsNewUserAdded = LibrarianDataManager.AddFaculty(
                        new Faculty(firstName, secondName, phone, address, "Professor"), login, password);
                }
                else if (visitingProfessorCheckBoxType.IsChecked == true)
                {
                    IsNewUserAdded = LibrarianDataManager.AddGuest(
                        new Guest(firstName, secondName, phone, address), login, password);
                }

                //if all checks good so open window
                if (IsNewUserAdded)
                {
                    using (StreamWriter writer = new StreamWriter("id.txt"))
                    {
                        writer.Write(CredentialsManager.Authorize(login, password));
                    }
                }
                else
                {
                    MessageBox.Show("Error! Can not create an account.");
                }
            }
            else
            {
                MessageBox.Show("Error! Invalid fields.");
            }
            this.Close();
        }
Пример #3
0
        private void button_register_Click(object sender, RoutedEventArgs e)
        {
            if (textBox_name.Text != null &&
                textBox_last_name.Text != null &&
                textBox_phone_number.Text != null &&
                textBox_Address_town.Text != null &&
                textBox_Address_street.Text != null &&
                textBox_Address_building.Text != null &&
                textBox_Address_flat.Text != null &&
                InputFieldsManager.CheckPasswordValidity(passwordBox_registration))
            {
                string firstName  = InputFieldsManager.ReturnStringFromTextBox(textBox_name),
                       secondName = InputFieldsManager.ReturnStringFromTextBox(textBox_last_name),
                       phone      = InputFieldsManager.ReturnStringFromTextBox(textBox_phone_number),
                       address    = InputFieldsManager.ReturnStringFromTextBox(textBox_Address_town) + ' ' +
                                    InputFieldsManager.ReturnStringFromTextBox(textBox_Address_street) + ' ' +
                                    InputFieldsManager.ReturnStringFromTextBox(textBox_Address_building) + ' ' +
                                    InputFieldsManager.ReturnStringFromTextBox(textBox_Address_flat) + ' ';
                string password = InputFieldsManager.ReturnPasswordFromTextBox(passwordBox_registration);
                string login    = firstName.Substring(0, 1) + '.' + secondName;

                bool IsNewUserAdded = false;

                if (professor_type.IsChecked == true)
                {
                    IsNewUserAdded = LibrarianDataManager.AddFaculty(
                        new Faculty(firstName, secondName, phone, address, Faculty.PROFESSOR_SUBTYPE), login, password);
                }
                else if (VP_professor_type.IsChecked == true)
                {
                    IsNewUserAdded = LibrarianDataManager.AddGuest(
                        new Guest(firstName, secondName, phone, address), login, password);
                }
                else if (TA_type.IsChecked == true)
                {
                    IsNewUserAdded = LibrarianDataManager.AddFaculty(
                        new Faculty(firstName, secondName, phone, address, Faculty.TA_SUBTYPE), login, password);
                }
                else if (instructor_type.IsChecked == true)
                {
                    IsNewUserAdded = LibrarianDataManager.AddFaculty(
                        new Faculty(firstName, secondName, phone, address, Faculty.INSTRUCTOR_SUBTYPE), login, password);
                }
                else if (student_type.IsChecked == true)
                {
                    IsNewUserAdded = LibrarianDataManager.AddStudent(
                        new Student(firstName, secondName, phone, address), login, password);
                }

                //if all checks good so open window
                if (IsNewUserAdded)
                {
                    WorkWindow workWindow = new WorkWindow(CredentialsManager.Authorize(login, password));
                    GoToWork(workWindow);
                }
                else
                {
                    MessageBox.Show("Error! Can not create an account.");
                }
            }
            else
            {
                MessageBox.Show("Error! Invalid fields.");
            }
        }