示例#1
0
        private void picExit_Click(object sender, EventArgs e)
        {
            this.Close();
            GC.Collect();
            adminMain admin = new adminMain();

            admin.Visible       = true;
            admin.ShowInTaskbar = true;
        }
示例#2
0
        private void pictureLogin_Click(object sender, EventArgs e)
        {
            if (txtLogin.Text != "")
            {
                if (txtPassword.Text != "")
                {
                    using (SqlConnection conn = new SqlConnection(@"Data Source=AYE\SQLEXPRESS;Initial Catalog=SmartWorkouts;Integrated Security=True"))
                    {
                        string login    = txtLogin.Text;
                        string password = txtPassword.Text;
                        string sql_1    = "SELECT Password FROM [Users] WHERE Login = @Login";
                        string sql_2    = "SELECT RoleID FROM [Users] WHERE Login = @Login";
                        string sql_3    = "SELECT ID FROM [Users] WHERE Login = @Login";
                        string sql_4    = "SELECT Name FROM [Users] WHERE Login = @Login";
                        string sql_5    = "SELECT Surname FROM [Users] WHERE Login = @Login";
                        string sql_6    = "SELECT ProfileImagePath FROM [Users] WHERE Login = @Login";
                        string sql_7    = "SELECT PremiumNumber FROM [Users] WHERE Login = @Login";
                        string sql_8    = "SELECT Email FROM [Users] WHERE Login = @Login";

                        string password_orig = "";

                        try
                        {
                            conn.Open();
                            SqlCommand cmd = new SqlCommand(sql_1, conn);
                            cmd.Parameters.AddWithValue("@Login", login);
                            if (cmd.ExecuteScalar() != null)
                            {
                                password_orig = cmd.ExecuteScalar().ToString();


                                if (password == password_orig)
                                {
                                    SqlCommand cmd_2 = new SqlCommand(sql_2, conn);
                                    cmd_2.Parameters.AddWithValue("@Login", login);
                                    string roleid = cmd_2.ExecuteScalar().ToString();
                                    txtPassword.Text = "";
                                    Hide();
                                    switch (roleid)
                                    {
                                    case "A":

                                        this.Hide();
                                        adminMain adminMain = new adminMain();
                                        adminMain.Show();

                                        break;

                                    case "U":
                                        SqlCommand cmd_1 = new SqlCommand(sql_3, conn);
                                        cmd_1.Parameters.AddWithValue("@Login", login);
                                        userID.ID = Convert.ToInt32(cmd_1.ExecuteScalar());
                                        CheckSubscription();
                                        SqlCommand cmd_3 = new SqlCommand(sql_4, conn);
                                        cmd_3.Parameters.AddWithValue("@Login", login);
                                        userName.name = cmd_3.ExecuteScalar().ToString();
                                        SqlCommand cmd_4 = new SqlCommand(sql_5, conn);
                                        cmd_4.Parameters.AddWithValue("@Login", login);
                                        userSurname.surname = cmd_4.ExecuteScalar().ToString();
                                        SqlCommand cmd_5 = new SqlCommand(sql_6, conn);
                                        cmd_5.Parameters.AddWithValue("@Login", login);
                                        userPicture.path = cmd_5.ExecuteScalar().ToString();
                                        SqlCommand cmd_6 = new SqlCommand(sql_7, conn);
                                        cmd_6.Parameters.AddWithValue("@Login", login);
                                        userPremWork.PremWork = Convert.ToInt32(cmd_6.ExecuteScalar());
                                        SqlCommand cmd_7 = new SqlCommand(sql_8, conn);
                                        cmd_7.Parameters.AddWithValue("@Login", login);
                                        userEmail.Email = cmd_7.ExecuteScalar().ToString();
                                        this.Hide();
                                        MainUser mainUser = new MainUser();
                                        mainUser.Show();
                                        break;
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Неверный логин или пароль!!!");
                                }
                            }
                            else
                            {
                                MessageBox.Show("Неверный логин!!!");
                            }
                        }

                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        finally
                        {
                            conn.Close();
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Введите пароль!!!");
                }
            }
            else
            {
                MessageBox.Show("Введите логин!!!");
            }
        }