private void BackToMenu(object sender, RoutedEventArgs e)
        {
            MainMenuEmployee mainMenuEmployee = new MainMenuEmployee();

            mainMenuEmployee.Show();
            this.Close();
        }
예제 #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string userLogin    = loginField.Text;
            string userPassword = passwordField.Password.ToString();

            string myConnectionString = @"Data Source=(local)\SQLEXPRESS; Initial Catalog = Journal; Integrated Security=True";
            string mySelectQuery      = "SELECT * FROM Users WHERE [UserLogin] = '" + userLogin + "'and [UserPassword]='" + userPassword + "'";

            using (SqlDataAdapter dataAdapter = new SqlDataAdapter(mySelectQuery, myConnectionString))
            {
                DataTable table = new DataTable();
                dataAdapter.Fill(table);
                if (table.Rows.Count > 0)
                {
                    StreamWriter loginFile = new StreamWriter("UserLogin.txt");
                    loginFile.Write(userLogin);
                    loginFile.Close();
                    MainMenuEmployee mainMenu = new MainMenuEmployee();
                    this.Close();
                    mainMenu.Show();
                }
                else if (table.Rows.Count == 0)
                {
                    System.Windows.MessageBox.Show("Неверный логин или пароль");
                    return;
                }
            }
        }
예제 #3
0
        private void BackToMenu(object sender, RoutedEventArgs e)
        {
            string       login        = string.Empty;
            StreamReader streamReader = new StreamReader("UserLogin.txt");

            login = streamReader.ReadLine();
            streamReader.Close();
            string mySelectQuery = "SELECT * FROM Users WHERE [UserLogin] = '" + login + "'";

            using (SqlDataAdapter dataAdapter = new SqlDataAdapter(mySelectQuery, connectionString))
            {
                DataTable table = new DataTable();
                dataAdapter.Fill(table);
                if (table.Rows.Count > 0)
                {
                    MainMenuEmployee mainMenuEmployee = new MainMenuEmployee();
                    mainMenuEmployee.Show();
                    this.Close();
                }
                else if (table.Rows.Count == 0)
                {
                    MainMenuGuest mainMenuGuest = new MainMenuGuest();
                    mainMenuGuest.Show();
                    this.Close();
                }
            }
        }
예제 #4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            StreamReader readLogin        = new StreamReader("UserLogin.txt");
            string       currentUserLogin = readLogin.ReadLine();

            readLogin.Close();

            if (nameField.Text != "")
            {
                if (nameField.Text.Length > 2 && nameField.Text.Length <= 30)
                {
                    char[] nameArray = nameField.Text.ToCharArray();
                    for (int i = 0; i < nameArray.Length; i++)
                    {
                        if (!char.IsLetter(nameArray[i]) && nameArray[i] != '-')
                        {
                            System.Windows.MessageBox.Show("Вы указали в имени недопустимые символы.");
                            return;
                        }
                    }
                }
                else
                {
                    System.Windows.MessageBox.Show("Допустимая длина имени 3-30 символов.");
                    return;
                }

                using (SqlConnection changeName = new SqlConnection(connectionString))
                    using (SqlCommand command = changeName.CreateCommand())
                    {
                        command.CommandText = "UPDATE Users SET UserName = '******' WHERE UserLogin = '******'";
                        changeName.Open();
                        command.ExecuteNonQuery();
                        changeName.Close();
                    }
            }

            if (surnamField.Text != "")
            {
                if (surnamField.Text.Length > 2 && surnamField.Text.Length <= 30)
                {
                    char[] surnameArray = surnamField.Text.ToCharArray();
                    for (int i = 0; i < surnameArray.Length; i++)
                    {
                        if (!char.IsLetter(surnameArray[i]) && surnameArray[i] != '-')
                        {
                            System.Windows.MessageBox.Show("Вы указали в фамилии недопустимые символы.");
                            return;
                        }
                    }
                }
                else
                {
                    System.Windows.MessageBox.Show("Допустимая длина фамилии 3-30 символов.");
                    return;
                }

                using (SqlConnection changeSurname = new SqlConnection(connectionString))
                    using (SqlCommand command = changeSurname.CreateCommand())
                    {
                        command.CommandText = "UPDATE Users SET UserSurname = '" + surnamField.Text + "' WHERE UserLogin = '******'";
                        changeSurname.Open();
                        command.ExecuteNonQuery();
                        changeSurname.Close();
                    }
            }

            if (patronymicField.Text != "")
            {
                if (patronymicField.Text.Length > 2 && patronymicField.Text.Length <= 30)
                {
                    char[] patronymicArray = patronymicField.Text.ToCharArray();
                    for (int i = 0; i < patronymicArray.Length; i++)
                    {
                        if (!char.IsLetter(patronymicArray[i]) && patronymicArray[i] != '-')
                        {
                            System.Windows.MessageBox.Show("Вы указали в отчестве недопустимые символы.");
                            return;
                        }
                    }
                }
                else
                {
                    System.Windows.MessageBox.Show("Допустимая длина отчества 3-30 символов.");
                    return;
                }

                using (SqlConnection changeSurname = new SqlConnection(connectionString))
                    using (SqlCommand command = changeSurname.CreateCommand())
                    {
                        command.CommandText = "UPDATE Users SET UserPatronymic = '" + patronymicField.Text + "' WHERE UserLogin = '******'";
                        changeSurname.Open();
                        command.ExecuteNonQuery();
                        changeSurname.Close();
                    }
            }

            if (phoneField.Text != "")
            {
                if (phoneField.Text.Length == 17)
                {
                    if (!Regex.IsMatch(phoneField.Text.ToString(), @"(\+|)(375|)(\ |)(\(|)(29|25|33|44)\)\d{3}\-\d{2}\-\d{2}"))
                    {
                        System.Windows.MessageBox.Show("Вы указали в номере телефона недопустимые символы.");
                        return;
                    }
                }
                else
                {
                    System.Windows.MessageBox.Show("Номер телефона должен выглядеть следующим образом: '+375(25/29/33/44)***-**-**'.");
                    return;
                }

                using (SqlConnection changeSurname = new SqlConnection(connectionString))
                    using (SqlCommand command = changeSurname.CreateCommand())
                    {
                        command.CommandText = "UPDATE Users SET UserPhoneNumber = '" + phoneField.Text + "' WHERE UserLogin = '******'";
                        changeSurname.Open();
                        command.ExecuteNonQuery();
                        changeSurname.Close();
                    }
            }

            if (loginField.Text != "")
            {
                if (loginField.Text.Length > 2 && loginField.Text.Length <= 20)
                {
                    char[] loginArray = loginField.Text.ToCharArray();
                    for (int i = 0; i < loginArray.Length; i++)
                    {
                        if (!char.IsLetter(loginArray[i]) && !char.IsDigit(loginArray[i]) && loginArray[i] != '_')
                        {
                            System.Windows.MessageBox.Show("Вы указали в логине недопустимые символы.");
                            return;
                        }
                    }
                }
                else
                {
                    System.Windows.MessageBox.Show("Допустимая длина логина 3-20 символов.");
                    return;
                }

                using (SqlConnection changeLogin = new SqlConnection(connectionString))
                    using (SqlCommand command = changeLogin.CreateCommand())
                    {
                        StreamWriter writeLogin = new StreamWriter("UserLogin.txt");
                        writeLogin.Write(loginField.Text);
                        writeLogin.Close();
                        command.CommandText = "UPDATE Users SET UserLogin = '******' WHERE UserLogin = '******'";
                        changeLogin.Open();
                        command.ExecuteNonQuery();
                        changeLogin.Close();
                        currentUserLogin = loginField.Text;
                    }
            }

            if (passwordField.Password.ToString() != "")
            {
                if (passwordField.Password.ToString().Length > 2 && passwordField.Password.ToString().Length <= 20)
                {
                    char[] passwordArray = passwordField.Password.ToString().ToCharArray();
                    for (int i = 0; i < passwordArray.Length; i++)
                    {
                        if (!char.IsLetter(passwordArray[i]) && !char.IsDigit(passwordArray[i]) && passwordArray[i] != '_' && passwordArray[i] != '*')
                        {
                            System.Windows.MessageBox.Show("Вы указали в пароле недопустимые символы.");
                            return;
                        }
                    }
                }
                else
                {
                    System.Windows.MessageBox.Show("Допустимая длина пароля 3-20 символов.");
                    return;
                }

                using (SqlConnection changePassword = new SqlConnection(connectionString))
                    using (SqlCommand command = changePassword.CreateCommand())
                    {
                        command.CommandText = "UPDATE Users SET UserPassword = '******' WHERE UserLogin = '******'";
                        changePassword.Open();
                        command.ExecuteNonQuery();
                        changePassword.Close();
                    }
            }

            MessageBoxResult mboxResult = System.Windows.MessageBox.Show("Изменения сохранены. Желаете изменить что-нибудь еще?", "Предупреждение", MessageBoxButton.YesNo);

            if (mboxResult == MessageBoxResult.No)
            {
                MainMenuEmployee mainMenuEmployee = new MainMenuEmployee();
                mainMenuEmployee.Show();
                this.Close();
            }
        }