private void button4_Click(object sender, EventArgs e)
        {
            MeniuPrincipal mp = new MeniuPrincipal();

            mp.Show();

            this.Hide();
        }
        private void button5_Click(object sender, EventArgs e)
        {
            if (Form1.UN == "Timotei")
            {
                MeniuPrincipal mp = new MeniuPrincipal();
                mp.Show();

                this.Hide();
            }

            else
            {
                MeniuUser mu = new MeniuUser();
                mu.Show();

                this.Hide();
            }
        }
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection(sqlCon);
                con.Open();

                if (con.State == ConnectionState.Open)
                {
                    MeniuPrincipal mp = new MeniuPrincipal();

                    mp.Show();

                    this.Hide();
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "Eroare aparuta in urma operatiunilor desfasurate", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            UN = txtId.Text.ToString();
            //Apasare pe Conectare

            // Daca se omite userul
            if (txtId.Text.ToString() == "")
            {
                MessageBox.Show("Introduceți username-ul", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtId.Focus();
                return;
            }

            // Daca se omite parola
            if (txtPass.Text.ToString() == "")
            {
                MessageBox.Show("Introduceți parola", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPass.Focus();
                return;
            }

            try
            {
                // Deschid o conexiune catre baza de date
                SqlConnection con = new SqlConnection(sqlCon);

                // Creez comanda
                SqlCommand comm = new SqlCommand("SELECT Username, Password FROM Users WHERE Username = '******' AND Password = '******';", con);

                //SqlParameter uname = new SqlParameter("@Username", SqlDbType.VarChar);
                //SqlParameter pass = new SqlParameter("@Password", SqlDbType.VarChar);

                //uname.Value = txtId.Text;
                //pass.Value = txtPass.Text;

                // Adaug parametrii comenzii
                //comm.Parameters.Add(uname);
                //comm.Parameters.Add(pass);


                comm.Connection.Open();

                SqlDataReader sdr = comm.ExecuteReader(CommandBehavior.CloseConnection);

                if (sdr.Read())
                {
                    MessageBox.Show("Bine ati venit, " + txtId.Text + "!");
                    if (txtId.Text.ToString() == "Timotei" && txtPass.Text.ToString() == "proiectBD")
                    {
                        MeniuPrincipal mp = new MeniuPrincipal();
                        mp.Show();

                        this.Hide();
                    }

                    else
                    {
                        MeniuUser mu = new MeniuUser();
                        mu.Show();

                        this.Hide();
                    }
                }

                else
                {
                    MessageBox.Show("Login esuat! Reincercati", "Neautorizat!", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // Sterg continutul
                    txtId.Clear();
                    txtPass.Clear();

                    txtId.Focus();
                }

                if (con.State == ConnectionState.Open)
                {
                    // Inchid conexiunea
                    con.Dispose();
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Eroare aparuta!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }



            /* Pentru test
             * // deschid o conexiune catre baza de date
             * SqlConnection con = new SqlConnection(sqlCon);
             * con.Open();
             *
             * // daca s-a conectat
             * if (con.State == System.Data.ConnectionState.Open)
             * {
             *  string query = "INSERT INTO Test(nume) VALUES ('" + txtPass.Text.ToString() + "')";
             *
             *  // execut comanda
             *  SqlCommand sqlCom = new SqlCommand(query, con);
             *  sqlCom.ExecuteNonQuery();
             *
             *  // testez comanda
             *  MessageBox.Show("Connection was successfull");
             * }*/
        }