public static bool NumeAlreadyExisted(string nume, string prenume) { string sqlQ = string.Format("SELECT ID_Student FROM Grades WHERE Nume='{0}' AND Prenume='{1}';", nume, prenume); string sqlprof = string.Format("SELECT IDProfesor FROM Materii WHERE Nume='{0}' AND Prenume='{1}';", nume, prenume); short countStudentNume = MyData.countData(sqlQ); short countprofNume = MyData.countData(sqlprof); if (countStudentNume >= 1 || countprofNume >= 1) { return(true); } else { return(false); } }
public static bool NickAlreadyExisted(string nick) { string sql = string.Format("SELECT Nick FROM Studenti WHERE Nick='{0}';", nick); string sql2 = string.Format("SELECT Nick FROM Profesori WHERE Nick='{0}';", nick); short countStudenti = MyData.countData(sql); short countProfesor = MyData.countData(sql2); if (countProfesor >= 1 || countStudenti >= 1) { return(true); } else { return(false); } }
private void log_in_Click(object sender, EventArgs e) { if (user_txt.Text == string.Empty || pass_txt.Text == string.Empty) { MessageBox.Show("Campuri invalide , te rog sa introduci campuri valide.", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); user_txt.Focus(); return; } IsLogged = false; IsProfessor = false; if (user_txt.Text == director_acc[0] && user_txt.Text == director_acc[1]) { //director control panel IsProfessor = false; IsLogged = true; directorpnl = new DirectorPanel(); directorpnl.main = this; directorpnl.TextMain[0] = user_txt; directorpnl.TextMain[1] = pass_txt; this.Hide(); directorpnl.Show(); } else { string sql = string.Format("SELECT Nick,Parola FROM Studenti WHERE Nick='{0}' AND Parola='{1}';", user_txt.Text, pass_txt.Text); string sql2 = string.Format("SELECT Nick,Pass FROM Profesori WHERE Nick='{0}' AND Pass='******';", user_txt.Text, pass_txt.Text); short countStudenti = MyData.countData(sql); short countProfesor = MyData.countData(sql2); if (countStudenti == 1) { IsProfessor = false; IsLogged = true; string sqlQ = string.Format("SELECT ID_Student FROM Studenti WHERE Nick='{0}' and Parola='{1}';", user_txt.Text, pass_txt.Text); id_user = MyData.selectData(sqlQ, "ID_Student"); string[] numestudent = new string[2] { "Nume", "Prenume" }; date = MyData.getData("Grades", numestudent, "ID_Student", id_user); string update = string.Format("UPDATE Studenti SET Ultima_logare='{0}' WHERE ID_Student={1};", DateTime.Now, id_user); MyData.execSql(update); MessageBox.Show("Bine ai venit " + date[0] + " " + date[1] + " !", "Bine ai revenit !", MessageBoxButtons.OK, MessageBoxIcon.Information); //show student form. studenpnl = new StudentPanel(); studenpnl.main = this; studenpnl.TextMain[0] = user_txt; studenpnl.TextMain[1] = pass_txt; studenpnl.Show(); this.Hide(); } else if (countProfesor == 1) { IsProfessor = true; IsLogged = true; string sqlQ = string.Format("SELECT ID_Prof FROM Profesori WHERE Nick='{0}' and Pass='******';", user_txt.Text, pass_txt.Text); id_user = MyData.selectData(sqlQ, "ID_Prof"); string[] numeprof = new string[2] { "Nume", "Prenume" }; string[] date = MyData.getData("Materii", numeprof, "IDProfesor", id_user); string update = string.Format("UPDATE Profesori SET Ultima_logare='{0}' WHERE ID_Prof={1};", DateTime.Now, id_user); MyData.execSql(update); MessageBox.Show("Bine ai venit , profesor " + date[0] + " " + date[1] + " !", "Bine ai revenit !", MessageBoxButtons.OK, MessageBoxIcon.Information); //show prof form. profesorpnl = new ProfesorPanel(); //set main profesorpnl.main = this; profesorpnl.Info[0] = user_txt; profesorpnl.Info[1] = pass_txt; profesorpnl.Show(); this.Hide(); } else { MessageBox.Show("Nume sau parola gresita, te rog sa introduci din nou campurile.", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); user_txt.Focus(); user_txt.Text = pass_txt.Text = string.Empty; } } }
private void adauga_btn_Click(object sender, EventArgs e) { //same ca la creare cont :) if (lista_modifica.SelectedItem.ToString() != lista_modifica.Items[0].ToString()) { if (nume_txt.Text == string.Empty || nick_txt.Text == string.Empty || prenume_txt.Text == string.Empty || pass_txt.Text == string.Empty) { MessageBox.Show("Toate campurile sunt obligatorii.", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (nick_txt.Text == Main_form.director_acc[0]) { MessageBox.Show("Nickname deja folosit,alege altul.", "Nick folosit", MessageBoxButtons.OK, MessageBoxIcon.Error); nume_txt.Text = string.Empty; return; } } else { if (nume_txt.Text == string.Empty || nick_txt.Text == string.Empty || prenume_txt.Text == string.Empty || pass_txt.Text == string.Empty || materii_combo.SelectedIndex == -1) { MessageBox.Show("Toate campurile sunt obligatorii.", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (nick_txt.Text == Main_form.director_acc[0]) { MessageBox.Show("Nickname deja folosit,alege altul.", "Nick folosit", MessageBoxButtons.OK, MessageBoxIcon.Error); nume_txt.Text = string.Empty; return; } } //verifica daca contul exista in baza de date Studenti si Profesori ( nickname-ul mai exact ) dupa verifica daca exista numele si prenumele in baza de date. string sql = string.Format("SELECT Nick,Parola FROM Studenti WHERE Nick='{0}';", nick_txt.Text); string sql2 = string.Format("SELECT Nick,Pass FROM Profesori WHERE Nick='{0}';", nick_txt.Text); short countStudenti = MyData.countData(sql); short countProfesor = MyData.countData(sql2); if (countProfesor >= 1 || countStudenti >= 1) { MessageBox.Show("Nickname deja folosit,alege altul.", "Nick folosit", MessageBoxButtons.OK, MessageBoxIcon.Error); nick_txt.Text = string.Empty; return; } string sqlQ = string.Format("SELECT ID_Student FROM Grades WHERE Nume='{0}' AND Prenume='{1}';", nume_txt.Text, prenume_txt.Text); string sqlprof = string.Format("SELECT IDProfesor FROM Materii WHERE Nume='{0}' AND Prenume='{1}';", nume_txt.Text, prenume_txt.Text); short countStudentNume = MyData.countData(sqlQ); short countprofNume = MyData.countData(sqlprof); if (countStudentNume >= 1 || countprofNume >= 1) { MessageBox.Show("Acel nume si prenume exista deja in baza de date.Poti avea doar un cont cu acealsi nume.", "Nume existent", MessageBoxButtons.OK, MessageBoxIcon.Error); nume_txt.Text = prenume_txt.Text = string.Empty; return; } if (lista_modifica.SelectedItem.ToString() != lista_modifica.Items[0].ToString()) //add student { string addsql = string.Format("INSERT INTO Studenti(Nick,Parola)VALUES('{0}','{1}');", nick_txt.Text, pass_txt.Text); MyData.execSql(addsql); string sqlID = string.Format("SELECT ID_Student FROM Studenti WHERE Nick='{0}' and Parola='{1}';", nick_txt.Text, pass_txt.Text); int id_student = MyData.selectData(sqlID, "ID_Student"); string addNume = string.Format("INSERT INTO Grades(ID_Student,Nume,Prenume)VALUES({0},'{1}','{2}');", id_student, nume_txt.Text, prenume_txt.Text); MyData.execSql(addNume); MessageBox.Show("Student adaugat !", "Adaugare cu succces", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); nume_txt.Text = pass_txt.Text = nick_txt.Text = prenume_txt.Text = string.Empty; } else //else add profesor { int id_materie = (Convert.ToInt32(materii_combo.SelectedIndex) + 1); string addprof = string.Format("INSERT INTO Profesori(Nick,Pass,IDMaterie)VALUES('{0}','{1}',{2});", nick_txt.Text, pass_txt.Text, id_materie); MyData.execSql(addprof); string sqlProfID = string.Format("SELECT ID_Prof FROM Profesori WHERE Nick='{0}' AND Pass='******';", nick_txt.Text, pass_txt.Text); int IdProf = MyData.selectData(sqlProfID, "ID_Prof"); string add = string.Format("INSERT INTO Materii(IDMaterie,IDProfesor,Nume,Prenume)VALUES('{0}','{1}','{2}','{3}');", id_materie, IdProf, nume_txt.Text, prenume_txt.Text); MyData.execSql(add); string new_id = string.Empty; string[] selectMaterii = MyData.getData("TabelMaterii", new string[] { "ID_Profesori" }, "ID_Materie", id_materie); if (selectMaterii[0].Length > 0) { new_id = selectMaterii[0] + "," + IdProf.ToString(); } else { new_id = IdProf.ToString(); } string addquery = string.Format("UPDATE TabelMaterii SET ID_Profesori='{0}' WHERE ID_Materie={1};", new_id, id_materie); MyData.execSql(addquery); MessageBox.Show("Profesor adaugat !", "Adaugare cu succces", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); nume_txt.Text = pass_txt.Text = nick_txt.Text = prenume_txt.Text = string.Empty; } }