Esempio n. 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            UserApp win = new UserApp();

            this.Close();
            win.Show();
        }
Esempio n. 2
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            UserApp app = new UserApp();

            app.Show();
            this.Close();
        }
Esempio n. 3
0
        public MainWindow()
        {
            InitializeComponent();

            DataTable dt_user1 = Select("SELECT * FROM login_data ORDER BY  id");

            for (int i = 0; i < dt_user1.Rows.Count; i++)
            {
                if (dt_user1.Rows[i][3].ToString() == "+")
                {
                    UserApp userApp = new UserApp();
                    this.Close();
                    userApp.Show();
                    break;
                }
            }
        }
Esempio n. 4
0
        private void save_button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                bool   correct = true;
                string sex     = "";
                if (sexm_field.IsChecked.ToString() == "True" && sexf_field.IsChecked.ToString() == "False" && sexo_field.IsChecked.ToString() == "False")
                {
                    sex = "Male";
                    correct_sex.Content = "";
                }
                else
                {
                    if (sexm_field.IsChecked.ToString() == "False" && sexf_field.IsChecked.ToString() == "True" && sexo_field.IsChecked.ToString() == "False")
                    {
                        sex = "Female";
                        correct_sex.Content = "";
                    }
                    else
                    {
                        if (sexm_field.IsChecked.ToString() == "False" && sexf_field.IsChecked.ToString() == "False" && sexo_field.IsChecked.ToString() == "True")
                        {
                            sex = "Other";
                            correct_sex.Content = "";
                        }
                        else
                        {
                            if (sexm_field.IsChecked.ToString() == "False" && sexf_field.IsChecked.ToString() == "False" && sexo_field.IsChecked.ToString() == "False")
                            {
                                correct_sex.Content = "Choose sex";
                                correct             = false;
                            }
                            else
                            {
                                if (sexm_field.IsChecked.ToString() == "True" && sexf_field.IsChecked.ToString() == "True" && sexo_field.IsChecked.ToString() == "False")
                                {
                                    correct_sex.Content = "Choose one sex";
                                    correct             = false;
                                }
                                else
                                {
                                    if (sexm_field.IsChecked.ToString() == "False" && sexf_field.IsChecked.ToString() == "True" && sexo_field.IsChecked.ToString() == "True")
                                    {
                                        correct_sex.Content = "Choose one sex";
                                        correct             = false;
                                    }
                                    else
                                    {
                                        if (sexm_field.IsChecked.ToString() == "True" && sexf_field.IsChecked.ToString() == "False" && sexo_field.IsChecked.ToString() == "True")
                                        {
                                            correct_sex.Content = "Choose one sex";
                                            correct             = false;
                                        }
                                        else
                                        {
                                            if (sexm_field.IsChecked.ToString() == "True" && sexf_field.IsChecked.ToString() == "True" && sexo_field.IsChecked.ToString() == "True")
                                            {
                                                correct_sex.Content = "Choose one sex";
                                                correct             = false;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                string data_birtgh = $"{day_birth.Text}" + " of " + $"{month_birth.Text}" + " in " + $"{year_birth.Text}";

                bool micro_correct = true;
                /////
                Regex regex = new Regex("^[A-Z][a-zA-Z]*$");
                Match match = regex.Match(surname_field.Text);
                correct_surname.Content = "Enter correct surname";
                if (!match.Success)
                {
                    correct       = false;
                    micro_correct = false;
                }
                while (match.Success)
                {
                    match = match.NextMatch();
                    correct_surname.Content = "";
                }

                if (surname_field.Text != "" && micro_correct && surname_field.Text.Length < 50)
                {
                    correct_surname.Content = "";
                }
                else
                {
                    correct_surname.Content = "Enter correct surname";
                    correct = false;
                }
                /////
                micro_correct = true;
                Regex regex1 = new Regex("^[A-Z][a-zA-Z]*$");
                Match match1 = regex1.Match(name_field.Text);
                correct_name.Content = "Enter correct name";
                if (!match1.Success)
                {
                    correct       = false;
                    micro_correct = false;
                }
                while (match1.Success)
                {
                    match1 = match1.NextMatch();
                    correct_name.Content = "";
                }

                if (name_field.Text != "" && micro_correct && name_field.Text.Length < 50)
                {
                    correct_name.Content = "";
                }
                else
                {
                    correct_name.Content = "Enter correct name";
                    correct = false;
                }
                /////
                micro_correct = true;
                Regex regex2 = new Regex("^[a-zA-Z0-9][a-zA-Z0-9]*$");
                Match match2 = regex2.Match(nickname_field.Text);
                correct_nickname.Content = "Enter correct nickname";
                if (!match2.Success)
                {
                    correct       = false;
                    micro_correct = false;
                }
                while (match2.Success)
                {
                    match2 = match2.NextMatch();
                    correct_nickname.Content = "";
                }

                if (nickname_field.Text != "" && micro_correct && nickname_field.Text.Length < 50)
                {
                    correct_nickname.Content = "";
                }
                else
                {
                    correct_nickname.Content = "Enter correct nickname";
                    correct = false;
                }
                /////
                micro_correct = true;
                Regex regex11 = new Regex("^[0-9][0-9]*$");
                Match match11 = regex11.Match(day_birth.Text);
                correct_birthday.Content = "Enter correct birthday";
                if (!match11.Success)
                {
                    correct       = false;
                    micro_correct = false;
                }
                while (match11.Success)
                {
                    match11 = match11.NextMatch();
                    correct_birthday.Content = "";
                }

                if (day_birth.Text != "" && micro_correct && day_birth.Text.Length < 50)
                {
                    correct_birthday.Content = "";
                }
                else
                {
                    correct_birthday.Content = "Enter correct birthday";
                    correct = false;
                }

                micro_correct = true;
                Regex regex12 = new Regex("^[0-9][0-9][0-9][0-9]*$");
                Match match12 = regex12.Match(year_birth.Text);
                correct_birthday.Content = "Enter correct birthday";
                if (!match12.Success)
                {
                    correct       = false;
                    micro_correct = false;
                }
                while (match12.Success)
                {
                    match12 = match12.NextMatch();
                    correct_birthday.Content = "";
                }

                if (year_birth.Text != "" && micro_correct && year_birth.Text.Length < 50)
                {
                    correct_birthday.Content = "";
                }
                else
                {
                    correct_birthday.Content = "Enter correct birthday";
                    correct = false;
                }

                if (micro_correct)
                {
                    if (day_birth.Text == "" || Convert.ToInt32(day_birth.Text.ToString()) > 31 || Convert.ToInt32(day_birth.Text.ToString()) < 1 || month_birth.Text.ToString() == "" || Convert.ToInt32(year_birth.Text.ToString()) < 1875 || Convert.ToInt32(year_birth.Text.ToString()) > 2002)
                    {
                        correct_birthday.Content = "Enter correct birthday";
                        correct = false;
                    }
                    else
                    {
                        correct_birthday.Content = "";
                    }
                }

                /////

                micro_correct = true;
                Regex regex9 = new Regex(@"^[a-zA-Z0-9]+@[a-z]+\.[a-z]*$");
                Match match9 = regex9.Match(email_field.Text);
                correct_email.Content = "Enter correct email";
                if (!match9.Success)
                {
                    correct       = false;
                    micro_correct = false;
                }
                while (match9.Success)
                {
                    match9 = match9.NextMatch();
                    correct_email.Content = "";
                }

                if (email_field.Text != "" && micro_correct && email_field.Text.Length < 50)
                {
                    correct_email.Content = "";
                }
                else
                {
                    correct_email.Content = "Enter correct email";
                    correct = false;
                }
                //////
                micro_correct = true;
                Regex regex6 = new Regex("^[a-zA-Z0-9][a-zA-Z0-9]*$");
                Match match6 = regex6.Match(login_field.Text);
                correct_login.Content = "Enter correct login";
                if (!match6.Success)
                {
                    correct       = false;
                    micro_correct = false;
                }
                while (match6.Success)
                {
                    match6 = match6.NextMatch();
                    correct_login.Content = "";
                }

                if (login_field.Text != "" && micro_correct && login_field.Text.Length < 50)
                {
                    correct_login.Content = "";
                }
                else
                {
                    correct_login.Content = "Enter correct login";
                    correct = false;
                }
                //////
                if (password_field.Text != "Enter new passsword" && confirm_field.Text != "Confirm new password")
                {
                    micro_correct = true;
                    Regex regex7 = new Regex("^[a-zA-Z0-9][a-zA-Z0-9]*$");
                    Match match7 = regex7.Match(password_field.Text);
                    correct_password.Content = "Enter correct password";
                    if (!match7.Success)
                    {
                        correct       = false;
                        micro_correct = false;
                    }
                    while (match7.Success)
                    {
                        match7 = match7.NextMatch();
                        correct_password.Content = "";
                    }

                    if (password_field.Text != "" && micro_correct && password_field.Text.Length < 50)
                    {
                        correct_password.Content = "";
                    }
                    else
                    {
                        correct_password.Content = "Enter correct password";
                        correct = false;
                    }
                    /////
                    if (password_field.Text != confirm_field.Text || confirm_field.Text == "")
                    {
                        correct_confirm.Content = "Passwords mismatch";
                        correct = false;
                    }
                    else
                    {
                        correct_confirm.Content = "";
                    }
                    /////
                }
                micro_correct = true;
                Regex regex8 = new Regex("^[0-9+][0-9]*$");
                Match match8 = regex8.Match(phone_field.Text);
                correct_phone.Content = "Enter correct phone";
                if (!match8.Success)
                {
                    correct       = false;
                    micro_correct = false;
                }
                while (match8.Success)
                {
                    match8 = match8.NextMatch();
                    correct_phone.Content = "";
                }

                if (phone_field.Text != "" && micro_correct && phone_field.Text.Length < 50)
                {
                    correct_phone.Content = "";
                }
                else
                {
                    correct_phone.Content = "Enter correct phone";
                    correct = false;
                }
                /////


                if (correct)
                {
                    try
                    {
                        string connectionString = @"server=DIMAMLIN-PC\QQQQ;database=kp;Integrated Security=true;";
                        string sqlExpression1   = $"UPDATE login_data SET login = '******' where id = '{id_of_user}' ";
                        using (SqlConnection connection = new SqlConnection(connectionString))
                        {
                            connection.Open();
                            SqlCommand command = new SqlCommand(sqlExpression1, connection);
                            int        number  = command.ExecuteNonQuery();
                            Console.WriteLine("Добавлено объектов: {0}", number);
                            connection.Close();
                        }
                        string sqlExpression2 = $"UPDATE user_data set surname = '{surname_field.Text}', name = '{name_field.Text}', nickname = '{nickname_field.Text}', birthday = '{data_birtgh}',email = '{email_field.Text}', sex = '{sex}', phone = '{phone_field.Text}', photo = '{user_ava.imagepath_file}' where id = '{id_of_user}'";
                        using (SqlConnection connection = new SqlConnection(connectionString))
                        {
                            connection.Open();
                            SqlCommand command = new SqlCommand(sqlExpression2, connection);
                            int        number  = command.ExecuteNonQuery();
                            Console.WriteLine("Добавлено объектов: {0}", number);
                            connection.Close();
                        }

                        string GetHashString(string s)
                        {
                            //переводим строку в байт-массим
                            byte[] bytes = Encoding.Unicode.GetBytes(s);

                            //создаем объект для получения средст шифрования
                            MD5CryptoServiceProvider CSP =
                                new MD5CryptoServiceProvider();

                            //вычисляем хеш-представление в байтах
                            byte[] byteHash = CSP.ComputeHash(bytes);

                            string hash = string.Empty;

                            //формируем одну цельную строку из массива
                            foreach (byte b in byteHash)
                            {
                                hash += string.Format("{0:x2}", b);
                            }

                            return(hash);
                        }

                        if (password_field.Text != "Enter new passsword" && confirm_field.Text != "Confirm new password")
                        {
                            string sqlExpression3 = $"UPDATE login_data SET password = '******' where id = '{id_of_user}' ";
                            using (SqlConnection connection = new SqlConnection(connectionString))
                            {
                                connection.Open();
                                SqlCommand command = new SqlCommand(sqlExpression3, connection);
                                int        number  = command.ExecuteNonQuery();
                                Console.WriteLine("Добавлено объектов: {0}", number);
                                connection.Close();
                            }
                        }
                    }
                    catch (Exception er)
                    {
                        MessageBox.Show(er.Message);
                    }

                    UserApp win = new UserApp();
                    this.Close();
                    win.Show();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
Esempio n. 5
0
        private void add_training_button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                bool correct       = true;
                bool micro_correct = true;

                Regex regex = new Regex(@"\d{2}");
                Match match = regex.Match(day_field.Text);
                day_correct.Content = "Enter correct day";
                if (!match.Success)
                {
                    correct       = false;
                    micro_correct = false;
                }
                while (match.Success)
                {
                    match = match.NextMatch();
                    day_correct.Content = "";
                }

                if (day_field.Text != "" && micro_correct && day_field.Text.Length == 2)
                {
                    if (Convert.ToInt32(day_field.Text) > 0 && Convert.ToInt32(day_field.Text) < 32)
                    {
                        day_correct.Content = "";
                    }
                    else
                    {
                        day_correct.Content = "Enter correct day";
                        correct             = false;
                    }
                }
                else
                {
                    day_correct.Content = "Enter correct day";
                    correct             = false;
                }


                if (month_field.Text == "")
                {
                    month_correct.Content = "Choose correct month";
                    correct = false;
                }
                else
                {
                    month_correct.Content = "";
                }

                micro_correct = true;
                Regex regex1 = new Regex(@"\d{2}");
                Match match1 = regex1.Match(hours_field.Text);
                time_correct.Content = "Enter correct time";
                if (!match1.Success)
                {
                    correct       = false;
                    micro_correct = false;
                }
                while (match1.Success)
                {
                    match1 = match1.NextMatch();
                    time_correct.Content = "";
                }

                if (hours_field.Text != "" && micro_correct && hours_field.Text.Length == 2)
                {
                    if (Convert.ToInt32(hours_field.Text) >= 0 && Convert.ToInt32(hours_field.Text) < 24)
                    {
                        time_correct.Content = "";
                    }
                    else
                    {
                        time_correct.Content = "Enter correct time";
                        correct = false;
                    }
                }
                else
                {
                    time_correct.Content = "Enter correct time";
                    correct       = false;
                    micro_correct = false;
                }


                Regex regex2 = new Regex(@"\d{2}");
                Match match2 = regex2.Match(minutes_field.Text);
                time_correct.Content = "Enter correct time";
                if (!match2.Success)
                {
                    correct       = false;
                    micro_correct = false;
                }
                while (match2.Success)
                {
                    match2 = match2.NextMatch();
                    time_correct.Content = "";
                }

                if (minutes_field.Text != "" && micro_correct && minutes_field.Text.Length == 2)
                {
                    if (Convert.ToInt32(minutes_field.Text) >= 0 && Convert.ToInt32(minutes_field.Text) < 60)
                    {
                        time_correct.Content = "";
                    }
                    else
                    {
                        time_correct.Content = "Enter correct time";
                        correct = false;
                    }
                }
                else
                {
                    time_correct.Content = "Enter correct time";
                    correct = false;
                }

                if (Convert.ToInt32(your_trains.SelectedIndex.ToString()) == -1)
                {
                    correct = false;
                    correct_plan.Content = "Choose one plan";
                }
                else
                {
                    correct_plan.Content = "";
                }

                if (Convert.ToInt32(trainers.SelectedIndex.ToString()) == -1 && is_trainer.IsChecked == false)
                {
                    correct = false;
                    trainer_correct.Content = "Choose one trainer or check \"without trainer\"";
                }
                else
                {
                    trainer_correct.Content = "";
                }

                if (correct)
                {
                    int    choose_train_id;
                    int    choose_trainer_id;
                    string choose        = your_trains.SelectedItem.ToString();
                    string sqlExpression = $"SELECT id FROM trains WHERE train_name LIKE '{choose}%'";
                    using (SqlConnection connection = new SqlConnection(connectionString))
                    {
                        connection.Open();
                        SqlCommand    command = new SqlCommand(sqlExpression, connection);
                        SqlDataReader reader  = command.ExecuteReader();
                        reader.Read();
                        choose_train_id = Convert.ToInt32(reader[0]);
                        reader.Close();
                        connection.Close();
                    }

                    choose = trainers.SelectedItem.ToString();
                    string sqlExpression1 = $"SELECT id FROM trainers WHERE trainer LIKE '{choose}%'";
                    using (SqlConnection connection = new SqlConnection(connectionString))
                    {
                        connection.Open();
                        SqlCommand    command = new SqlCommand(sqlExpression1, connection);
                        SqlDataReader reader1 = command.ExecuteReader();
                        reader1.Read();
                        choose_trainer_id = Convert.ToInt32(reader1[0]);
                        reader1.Close();
                        connection.Close();
                    }

                    if (is_trainer.IsChecked == true)
                    {
                        choose_trainer_id = 0;
                    }

                    string date = $"{day_field.Text} of {month_field.Text}";

                    string time = hours_field.Text + ":" + minutes_field.Text;

                    string sqlExpression3 = $"INSERT INTO user_trainings (user_id, train_id, trainer_id, date, time) VALUES ('{id_of_user}', '{choose_train_id}', '{choose_trainer_id}', '{date}', '{time}' ); ";
                    using (SqlConnection connection = new SqlConnection(connectionString))
                    {
                        connection.Open();
                        SqlCommand command = new SqlCommand(sqlExpression3, connection);
                        int        number  = command.ExecuteNonQuery();
                        Console.WriteLine("Добавлено объектов: {0}", number);
                        connection.Close();
                    }

                    string email          = "";
                    string sqlExpression6 = $"SELECT email FROM user_data WHERE id = '{id_of_user}';";
                    using (SqlConnection connection = new SqlConnection(connectionString))
                    {
                        connection.Open();
                        SqlCommand    command = new SqlCommand(sqlExpression6, connection);
                        SqlDataReader reader1 = command.ExecuteReader();
                        while (reader1.Read())
                        {
                            email = reader1[0].ToString();
                            email = email.Trim();
                        }
                        reader1.Close();
                        connection.Close();
                    }

                    // отправитель - устанавливаем адрес и отображаемое в письме имя
                    MailAddress from = new MailAddress("*****@*****.**", "Gym24");
                    // кому отправляем
                    MailAddress to = new MailAddress($"{email}");
                    // создаем объект сообщения
                    MailMessage m = new MailMessage(from, to);
                    // тема письма
                    m.Subject = "Training is near!";
                    // текст письма
                    m.Body = "<h2>Do not forget about your training!!!</h2>";
                    // письмо представляет код html
                    m.IsBodyHtml = true;
                    // адрес smtp-сервера и порт, с которого будем отправлять письмо
                    SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
                    // логин и пароль
                    smtp.Credentials = new NetworkCredential("*****@*****.**", "31012001mss");
                    smtp.EnableSsl   = true;
                    smtp.Send(m);
                    Console.Read();

                    UserApp win = new UserApp();
                    this.Close();
                    win.Show();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
Esempio n. 6
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string GetHashString(string s)
                {
                    //переводим строку в байт-массим
                    byte[] bytes = Encoding.Unicode.GetBytes(s);

                    //создаем объект для получения средст шифрования
                    MD5CryptoServiceProvider CSP =
                        new MD5CryptoServiceProvider();

                    //вычисляем хеш-представление в байтах
                    byte[] byteHash = CSP.ComputeHash(bytes);

                    string hash = string.Empty;

                    //формируем одну цельную строку из массива
                    foreach (byte b in byteHash)
                    {
                        hash += string.Format("{0:x2}", b);
                    }

                    return(hash);
                }

                if (login.Text == "admin" && password.Password == "admin")
                {
                    Administrator window = new Administrator();
                    window.Show();
                    this.Close();
                }
                else
                {
                    bool      authorixation = false;
                    DataTable dt_user       = Select("SELECT * FROM login_data ORDER BY  id");
                    for (int i = 0; i < dt_user.Rows.Count; i++)
                    {
                        string logins    = dt_user.Rows[i][1].ToString();
                        string passwords = dt_user.Rows[i][2].ToString();
                        logins    = logins.Trim();
                        passwords = passwords.Trim();
                        if (login.Text == logins && GetHashString(password.Password) == passwords)
                        {
                            string connectionString = @"server=DIMAMLIN-PC\QQQQ;database=kp;Integrated Security=true;";
                            string sqlExpression1   = $"UPDATE login_data SET isenabled='+' where login = '******'";
                            using (SqlConnection connection = new SqlConnection(connectionString))
                            {
                                connection.Open();
                                SqlCommand command = new SqlCommand(sqlExpression1, connection);
                                int        number  = command.ExecuteNonQuery();
                                Console.WriteLine("Добавлено объектов: {0}", number);
                                connection.Close();
                            }

                            UserApp userApp = new UserApp();
                            this.Close();
                            userApp.Show();
                            authorixation = true;
                            break;
                        }
                    }
                    if (!authorixation)
                    {
                        authorization.Content = "Incorrect login or password!";
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }