コード例 #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            MeniuUser mu = new MeniuUser();

            mu.Show();

            this.Hide();
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection con = new SqlConnection(sqlCon);
                con.Open();

                if (con.State == ConnectionState.Open)
                {
                    if (!String.IsNullOrWhiteSpace(txtUN.Text.ToString()) && !String.IsNullOrWhiteSpace(txtPass.Text.ToString()) && !String.IsNullOrWhiteSpace(txtRPass.Text.ToString()))
                    {
                        // Conditii pentru un username valid
                        if (txtUN.Text.ToString().Length < 4)
                        {
                            MessageBox.Show("Username-ul trebuie să aibe cel puțin 4 caractere!");
                        }

                        // Conditie pentru o parola valida
                        if (txtPass.Text.ToString().Length < 4)
                        {
                            MessageBox.Show("Parola trebuie să aibe cel puțin 4 caractere!");
                        }

                        // Daca parola reintrodusa nu se potriveste cu cea initiala
                        if (!txtRPass.Text.ToString().Equals(txtPass.Text.ToString()))
                        {
                            MessageBox.Show("Parola nu se potrivește!");
                        }

                        // Verific existenta contului inainte de adaugare
                        string        verif = "SELECT Username, Password FROM Users WHERE Username = '******' AND Password = '******';";
                        SqlCommand    vrf   = new SqlCommand(verif, con);
                        SqlDataReader DR    = vrf.ExecuteReader();

                        if (DR.Read())
                        {
                            MessageBox.Show("Contul exista deja!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                            vrf.Dispose();
                            DR.Close();
                        }

                        else
                        {
                            DR.Close();
                            string     insert  = "INSERT INTO Users VALUES('" + txtUN.Text.ToString() + "', '" + txtPass.Text.ToString() + "');";
                            SqlCommand insUser = new SqlCommand(insert, con);
                            insUser.ExecuteNonQuery();
                            insUser.Dispose();

                            string        check     = "Select Username, Password FROM Users WHERE Username = '******' AND Password = '******';";
                            SqlCommand    checkUser = new SqlCommand(check, con);
                            SqlDataReader sqlDR     = checkUser.ExecuteReader(CommandBehavior.CloseConnection);

                            if (sqlDR.Read())
                            {
                                string hello = "Bine ați venit, " + txtUN.Text.ToString();
                                MessageBox.Show("Cont creat!\n" + hello);


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

                                this.Hide();
                            }
                            sqlDR.Close();
                            checkUser.Dispose();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Contul nu a putut fi creat!", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                con.Close();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "Eroare apărută la crearea contului!", 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");
             * }*/
        }