Ejemplo n.º 1
0
        private void button7_Click(object sender, EventArgs e)
        {
            int index = 0;

            foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
            {
                index = cell.RowIndex;
            }
            string Login    = Convert.ToString(dataGridView1[1, index].Value);
            string Password = Convert.ToString(dataGridView1[2, index].Value);
            string Access   = Convert.ToString(dataGridView1[3, index].Value);

            connection = new SqlConnection(connectionString);
            connection.Open();
            string query = $"SELECT * FROM [Users] WHERE (Login=N'{Login}'COLLATE CYRILLIC_General_CS_AS)";

            cmd    = new SqlCommand(query, connection);
            reader = cmd.ExecuteReader();
            if (!reader.HasRows)
            {
                MessageBox.Show("Wrong Login", "Error");
                reader.Close();
                return;
            }
            else
            {
                reader.Close();
                query  = $"SELECT * FROM Users WHERE (Login=N'{Login}'COLLATE CYRILLIC_General_CS_AS) AND (Password= '******' COLLATE CYRILLIC_General_CS_AS) ";
                cmd    = new SqlCommand(query, connection);
                reader = cmd.ExecuteReader();
                if (!reader.HasRows)
                {
                    reader.Close();
                    MessageBox.Show("Wrong Password", "Error");
                    return;
                }
                else
                {
                    this.Hide();
                    reader.Close();
                    query  = $"SELECT * FROM Users WHERE (Login=N'{Login}'COLLATE CYRILLIC_General_CS_AS) AND (Password= '******' COLLATE CYRILLIC_General_CS_AS) AND Access=13";
                    cmd    = new SqlCommand(query, connection);
                    reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        reader.Close();
                        Admin        mainMenuForAdmin = new Admin(Login);
                        DialogResult dialogResult     = new DialogResult();
                        dialogResult = mainMenuForAdmin.ShowDialog();
                        if (dialogResult == DialogResult.OK)
                        {
                            this.Show();
                        }
                        else
                        {
                            connection.Close();
                            this.Close();
                        }
                    }
                    else
                    {
                        reader.Close();
                        query  = $"SELECT * FROM Users WHERE (Login=N'{Login}'COLLATE CYRILLIC_General_CS_AS) AND (Password= '******' COLLATE CYRILLIC_General_CS_AS) AND Access={Access}";
                        cmd    = new SqlCommand(query, connection);
                        reader = cmd.ExecuteReader();
                        if (reader.HasRows && Convert.ToInt32(Access) == 1)
                        {
                            reader.Close();
                            ForVet       forVet       = new ForVet(Login);
                            DialogResult dialogResult = new DialogResult();
                            dialogResult = forVet.ShowDialog();
                            if (dialogResult == DialogResult.OK)
                            {
                                this.Show();
                            }
                            else
                            {
                                connection.Close();
                                this.Close();
                            }
                        }
                        else
                        {
                            reader.Close();
                            query  = $"SELECT * FROM Users WHERE (Login=N'{Login}'COLLATE CYRILLIC_General_CS_AS) AND (Password= '******' COLLATE CYRILLIC_General_CS_AS) AND Access={Access}";
                            cmd    = new SqlCommand(query, connection);
                            reader = cmd.ExecuteReader();
                            if (reader.HasRows && Convert.ToInt32(Access) == 2)
                            {
                                reader.Close();
                                ForCleaner   forCleaner   = new ForCleaner(Login);
                                DialogResult dialogResult = new DialogResult();
                                dialogResult = forCleaner.ShowDialog();
                                if (dialogResult == DialogResult.OK)
                                {
                                    this.Show();
                                }
                                else
                                {
                                    connection.Close();
                                    this.Close();
                                }
                            }
                            else
                            {
                                reader.Close();
                                query  = $"SELECT * FROM Users WHERE (Login=N'{Login}'COLLATE CYRILLIC_General_CS_AS) AND (Password= '******' COLLATE CYRILLIC_General_CS_AS) AND Access={Access}";
                                cmd    = new SqlCommand(query, connection);
                                reader = cmd.ExecuteReader();
                                if (reader.HasRows && Convert.ToInt32(Access) == 3)
                                {
                                    reader.Close();
                                    ForTrainer   forTrainer   = new ForTrainer(Login);
                                    DialogResult dialogResult = new DialogResult();
                                    dialogResult = forTrainer.ShowDialog();
                                    if (dialogResult == DialogResult.OK)
                                    {
                                        this.Show();
                                    }
                                    else
                                    {
                                        connection.Close();
                                        this.Close();
                                    }
                                }
                                else
                                {
                                    reader.Close();
                                    query  = $"SELECT * FROM Users WHERE (Login=N'{Login}'COLLATE CYRILLIC_General_CS_AS) AND (Password= '******' COLLATE CYRILLIC_General_CS_AS) AND Access={Access}";
                                    cmd    = new SqlCommand(query, connection);
                                    reader = cmd.ExecuteReader();
                                    if (reader.HasRows && Convert.ToInt32(Access) == 4)
                                    {
                                        reader.Close();
                                        ForBuilder   forBuilder   = new ForBuilder(Login);
                                        DialogResult dialogResult = new DialogResult();
                                        dialogResult = forBuilder.ShowDialog();
                                        if (dialogResult == DialogResult.OK)
                                        {
                                            this.Show();
                                        }
                                        else
                                        {
                                            connection.Close();
                                            this.Close();
                                        }
                                    }
                                    else
                                    {
                                        reader.Close();
                                        MessageBox.Show("Wrong User access\nUse admin panel", "Error");
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string LoginTB, PasswordTB;

            LoginTB    = textBox1.Text;
            PasswordTB = textBox2.Text;
            connection = new SqlConnection(connectionString);
            connection.Open();
            string query = $"SELECT * FROM [Users] WHERE (Login=N'{LoginTB}'COLLATE CYRILLIC_General_CS_AS)";

            cmd    = new SqlCommand(query, connection);
            reader = cmd.ExecuteReader();
            if (!reader.HasRows)
            {
                MessageBox.Show("Wrong Login", "Error");
                reader.Close();
                return;
            }
            else
            {
                reader.Close();
                query  = $"SELECT * FROM Users WHERE (Login=N'{LoginTB}'COLLATE CYRILLIC_General_CS_AS) AND (Password= '******' COLLATE CYRILLIC_General_CS_AS) ";
                cmd    = new SqlCommand(query, connection);
                reader = cmd.ExecuteReader();
                if (!reader.HasRows)
                {
                    reader.Close();
                    MessageBox.Show("Wrong Password", "Error");
                    return;
                }
                else
                {
                    this.Hide();
                    reader.Close();
                    query  = $"SELECT * FROM Users WHERE (Login=N'{LoginTB}'COLLATE CYRILLIC_General_CS_AS) AND (Password= '******' COLLATE CYRILLIC_General_CS_AS) AND Access=13";
                    cmd    = new SqlCommand(query, connection);
                    reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        reader.Close();
                        Admin        mainMenuForAdmin = new Admin(LoginTB);
                        DialogResult dialogResult     = new DialogResult();
                        dialogResult = mainMenuForAdmin.ShowDialog();
                        if (dialogResult == DialogResult.OK)
                        {
                            this.Show();
                        }
                        else
                        {
                            connection.Close();
                            this.Close();
                        }
                    }
                    else
                    {
                        reader.Close();
                        query  = $"SELECT * FROM Users WHERE (Login=N'{LoginTB}'COLLATE CYRILLIC_General_CS_AS) AND (Password= '******' COLLATE CYRILLIC_General_CS_AS) AND Access=1";
                        cmd    = new SqlCommand(query, connection);
                        reader = cmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            reader.Close();
                            ForVet       forVet       = new ForVet(LoginTB);
                            DialogResult dialogResult = new DialogResult();
                            dialogResult = forVet.ShowDialog();
                            if (dialogResult == DialogResult.OK)
                            {
                                this.Show();
                            }
                            else
                            {
                                connection.Close();
                                this.Close();
                            }
                        }
                        else
                        {
                            reader.Close();
                            query  = $"SELECT * FROM Users WHERE (Login=N'{LoginTB}'COLLATE CYRILLIC_General_CS_AS) AND (Password= '******' COLLATE CYRILLIC_General_CS_AS) AND Access=2";
                            cmd    = new SqlCommand(query, connection);
                            reader = cmd.ExecuteReader();
                            if (reader.HasRows)
                            {
                                reader.Close();
                                ForCleaner   forCleaner   = new ForCleaner(LoginTB);
                                DialogResult dialogResult = new DialogResult();
                                dialogResult = forCleaner.ShowDialog();
                                if (dialogResult == DialogResult.OK)
                                {
                                    this.Show();
                                }
                                else
                                {
                                    connection.Close();
                                    this.Close();
                                }
                            }
                            else
                            {
                                reader.Close();
                                query  = $"SELECT * FROM Users WHERE (Login=N'{LoginTB}'COLLATE CYRILLIC_General_CS_AS) AND (Password= '******' COLLATE CYRILLIC_General_CS_AS) AND Access=3";
                                cmd    = new SqlCommand(query, connection);
                                reader = cmd.ExecuteReader();
                                if (reader.HasRows)
                                {
                                    reader.Close();
                                    ForTrainer   forTrainer   = new ForTrainer(LoginTB);
                                    DialogResult dialogResult = new DialogResult();
                                    dialogResult = forTrainer.ShowDialog();
                                    if (dialogResult == DialogResult.OK)
                                    {
                                        this.Show();
                                    }
                                    else
                                    {
                                        connection.Close();
                                        this.Close();
                                    }
                                }
                                else
                                {
                                    reader.Close();
                                    query  = $"SELECT * FROM Users WHERE (Login=N'{LoginTB}'COLLATE CYRILLIC_General_CS_AS) AND (Password= '******' COLLATE CYRILLIC_General_CS_AS) AND Access=4";
                                    cmd    = new SqlCommand(query, connection);
                                    reader = cmd.ExecuteReader();
                                    if (reader.HasRows)
                                    {
                                        reader.Close();
                                        ForBuilder   forBuilder   = new ForBuilder(LoginTB);
                                        DialogResult dialogResult = new DialogResult();
                                        dialogResult = forBuilder.ShowDialog();
                                        if (dialogResult == DialogResult.OK)
                                        {
                                            this.Show();
                                        }
                                        else
                                        {
                                            connection.Close();
                                            this.Close();
                                        }
                                    }
                                    else
                                    {
                                        reader.Close();
                                        MessageBox.Show("Wrong User access\nUse admin panel", "Error");
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }