private void button1_Click(object sender, EventArgs e) { cmd = new SqlCommand(@"SELECT * FROM Users", conn); reader = cmd.ExecuteReader(); if (UserTextbox.Text == "") { MessageBox.Show("Introdu numele tau de utilizator!"); } else if (ParolaTextbox.Text == "") { MessageBox.Show("Indrodu parola"); } else { bool am_gasit = false; nr = 1; while (reader.Read()) { if (reader[3].ToString() == UserTextbox.Text) { am_gasit = true; break; } nr++; } if (am_gasit == false) { MessageBox.Show("UserName inexistent!"); groupBox1.Focus(); UserTextbox.Focus(); UserTextbox.SelectAll(); } else { reader.Close(); cmd = new SqlCommand(@"SELECT * FROM Users WHERE ID = " + nr, conn); reader = cmd.ExecuteReader(); reader.Read(); if (reader[4].ToString() == ParolaTextbox.Text) { MessageBox.Show("Autentificare cu succes!!"); this.Hide(); Form2 f = new Form2(nr); f.ShowDialog(); f.Close(); groupBox1.Focus(); UserTextbox.Focus(); UserTextbox.SelectAll(); ParolaTextbox.Text = ""; this.Show(); UserTextbox.SelectAll(); } else { MessageBox.Show("Parola gresita!!"); } } } reader.Close(); }
private void button1_Click(object sender, EventArgs e) { if (NumeTextbox.Text == "") { MessageBox.Show("Introdu numele tau!", "Atentie", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (PrenumeTextbox.Text == "") { MessageBox.Show("Introdu prenumele tau!", "Atentie", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (UserTextbox.Text == "") { MessageBox.Show("Introdu numele tau de utilizator!", "Atentie", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (ParolaTextbox.Text == "") { MessageBox.Show("Introdu o parola!", "Atentie", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (VerParolaTextbox.Text == "" && checkBox1.Checked == false) { MessageBox.Show("Introdu verificarea parolei!", "Atentie", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (checkBox1.Checked == false && ParolaTextbox.Text != VerParolaTextbox.Text) { MessageBox.Show("Parola nu se potriveste cu verificarea ei.\nReintrodu parola!", "Atentie", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ParolaTextbox.Clear(); VerParolaTextbox.Clear(); groupBox2.Focus(); ParolaTextbox.Focus(); } else { cale = Directory.GetCurrentDirectory(); SqlConnection conn = new SqlConnection(@"server = .\sqlexpress;Database=Utilizatori.mdf;trusted_connection=True;AttachDbFileName = " + cale + @"\Utilizatori.mdf"); conn.Open(); SqlCommand cmd = new SqlCommand(@"SELECT * FROM Users", conn); SqlDataReader reader = cmd.ExecuteReader(); bool exista = false; while (reader.Read()) { if (reader[3].ToString() == UserTextbox.Text) { exista = true; break; } } reader.Close(); if (exista) { MessageBox.Show("Un alt utilizator are acelasi Username.\nIncearca altul!", "Atentie", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); UserTextbox.Clear(); groupBox2.Focus(); UserTextbox.Focus(); } else { cmd = new SqlCommand(@"INSERT INTO Users (Nume, Prenume, UserName, Parola) VALUES ( '" + NumeTextbox.Text + "', '" + PrenumeTextbox.Text + "', '" + UserTextbox.Text + "', '" + ParolaTextbox.Text + "' )", conn); cmd.ExecuteReader(); conn.Close(); MessageBox.Show("Operatie reusita!"); } } }