Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Connection       conn    = new Connection();
            DataTable        dt      = new DataTable();
            MySqlDataAdapter adapter = new MySqlDataAdapter();
            MySqlCommand     command = new MySqlCommand();
            String           QuesLog = "SELECT * FROM `uzytkownicy` WHERE `LOGIN` = @usn AND `HASLO` = @pass";

            command.CommandText = QuesLog;
            command.Connection  = conn.GetConnection();
            command.Parameters.Add("@usn", MySqlDbType.VarChar).Value  = textBox1.Text;
            command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = textBox2.Text;

            adapter.SelectCommand = command;
            try
            {
                adapter.Fill(dt);

                if (dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];
                    Id_kli = row["ID_UZYT"].ToString();

                    this.Hide();
                    if (textBox1.Text.Equals("admin"))
                    {
                        admin ad = new admin();
                        this.Hide();
                        ad.Show();
                    }
                    else
                    {
                        Client cl = new Client();
                        this.Hide();
                        cl.Show();
                    }
                }

                else
                {
                    if (textBox1.Text.Trim().Equals("") && !textBox2.Text.Trim().Equals(""))
                    {
                        MessageBox.Show("Give your login!", "Empty login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        textBox2.Text = textBox1.Text = "";
                    }

                    else if (textBox2.Text.Trim().Equals("") && !textBox1.Text.Trim().Equals(""))
                    {
                        MessageBox.Show("Give your password!", "Empty password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        textBox2.Text = textBox1.Text = "";
                    }

                    else if (textBox1.Text.Trim().Equals("") && textBox2.Text.Trim().Equals(""))
                    {
                        MessageBox.Show("Give your password and login!", "Empty login and password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        textBox2.Text = textBox1.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("Wrong username or password!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        textBox2.Text = textBox1.Text = "";
                    }
                }
            }
            catch
            {
                MessageBox.Show("Unable to connect with database!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }