コード例 #1
0
ファイル: StudentPanel.cs プロジェクト: RD3luxe/Projects
 private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (tabControl1.SelectedIndex == 2 && teste_dgv.Columns.Count <= 4 && teste_dgv.Rows.Count > 0)
     {
         int    value = Convert.ToInt32(teste_dgv["ID_Prof", 0].Value);
         string sql   = string.Format("SELECT IDMaterie FROM Profesori WHERE ID_Prof={0};", value);
         int    ID    = MyData.selectData(sql, "IDMaterie");
         sql = string.Format("SELECT Nume,Prenume FROM Materii WHERE IDProfesor={0} AND IDMaterie={1};", value, ID);
         teste_dgv.Columns.Add("name", "Nume Profesor");
         teste_dgv.Columns.Add("prename", "Prenume Profesor");
         string[] data = MyData.getData(sql, new string[] { "Nume", "Prenume" });
         for (int i = 0; i < teste_dgv.Rows.Count; i++)
         {
             teste_dgv["name", i].Value    = data[0];
             teste_dgv["prename", i].Value = data[1];
         }
         DataGridViewButtonColumn button = new DataGridViewButtonColumn();
         button.HeaderText = "Test";
         button.ValueType  = typeof(Button);
         button.Text       = "Start";
         button.UseColumnTextForButtonValue = true;
         teste_dgv.Columns.Add(button);
         teste_dgv.Columns.RemoveAt(3);
     }
     else if (tabControl1.SelectedIndex == 2 && teste_dgv.Rows.Count <= 0 || tabControl1.SelectedIndex == 1 && mycourse_dgv.Rows.Count <= 0 || tabControl1.SelectedIndex == 3 && materii_cb.Items.Count <= 0)
     {
         MessageBox.Show("Nu ai nici un test disponibil sau nu esti inscris la nici un curs.", "Instintare", MessageBoxButtons.OK, MessageBoxIcon.Information);
         tabControl1.SelectTab(0);
     }
     KeepTrakingName();
 }
コード例 #2
0
ファイル: StudentPanel.cs プロジェクト: RD3luxe/Projects
 public void LoadDateMaterii()
 {
     mycourse_dgv.Columns.Clear();
     if (materii_db.Items.Count > 0)
     {
         string    selectDates = string.Format("SELECT ID_Test,Nume_fisier,Nota,Promovat FROM Teste_Materii WHERE ID_Student={0} AND Materie='{1}' AND Nota<>0;", Main_form.id_user, materii_db.SelectedItem.ToString());
         DataTable dt          = MyData.readTable(selectDates);
         if (dt.Rows.Count > 0)
         {
             mycourse_dgv.DataSource = dt;
             mycourse_dgv.Columns["Nume_fisier"].HeaderText = "Nume test";
             mycourse_dgv.Columns.Add("name", "Nume profesor");
             mycourse_dgv.Columns.Add("prename", "Prenume profesor");
             //select name and prename using profesor ID
             string IdProf = string.Format("SELECT Materii_inscris,Id_Profesor FROM Grades WHERE ID_Student={0};", Main_form.id_user);
             dt = MyData.readTable(IdProf);
             string   Id_materie = string.Format("SELECT ID_Materie FROM TabelMaterii WHERE Nume_Materie='{0}';", materii_db.SelectedItem.ToString());
             int      ID         = MyData.selectData(Id_materie, "ID_Materie");
             string[] splitData1 = dt.Rows[0][0].ToString().Split(',');
             string[] splitData2 = dt.Rows[0][1].ToString().Split(',');
             for (int i = 0; i < splitData1.Length; i++)
             {
                 int IDS = Convert.ToInt32(splitData1[i]);
                 if (ID == IDS)
                 {
                     //am gasit date le folosim
                     selectDates = string.Format("SELECT Nume,Prenume FROM Materii WHERE IDProfesor={0} AND IDMaterie={1};", splitData2[i], splitData1[i]);
                     data        = MyData.getData(selectDates, new string[] { "Nume", "Prenume" });
                 }
             }
             //setam daca e sau nu promovat
             for (int i = 0; i < mycourse_dgv.Rows.Count; i++)
             {
                 if (Convert.ToInt32(mycourse_dgv["Nota", i].Value) >= 5)
                 {
                     mycourse_dgv["Promovat", i].Value = true;
                 }
                 else
                 {
                     mycourse_dgv["Promovat", i].Value = false;
                 }
                 string update = string.Format("UPDATE Teste_Materii SET Promovat={2} WHERE Materie='{0}' AND ID_Test={1};", materii_db.SelectedItem.ToString(), mycourse_dgv["ID_Test", i].Value, mycourse_dgv["Promovat", i].Value);
                 MyData.execSql(update);
             }
             //calculam media + verificam daca e sau nu promovat
             if (mycourse_dgv.Rows.Count > 0)
             {
                 promovat_chk.Visible = true;
                 medie_txt.Visible    = true;
                 label3.Visible       = true;
                 float total = 0f, count = 0;
                 for (int i = 0; i < mycourse_dgv.Rows.Count; i++)
                 {
                     total += Convert.ToSingle(mycourse_dgv["Nota", i].Value);
                     count++;
                 }
                 double medie = total / count;
                 medie_txt.Text = string.Format("{0:0.00}", medie);
                 if (medie < 4.5)
                 {
                     promovat_chk.Checked = false;
                     medie = Math.Round(medie, 2);
                 }
                 else if (medie == 4.5)
                 {
                     promovat_chk.Checked = true;
                     medie = Math.Ceiling(medie);
                 }
                 else
                 {
                     promovat_chk.Checked = true;
                     medie = Math.Round(medie, 2);
                 }
                 string update = string.Format("UPDATE Teste_Materii SET Promovat_Anul={1} WHERE Materie='{0}';", materii_db.SelectedItem.ToString(), promovat_chk.Checked);
                 MyData.execSql(update);
                 update = string.Format("UPDATE Teste_Materii SET Nota_finala={0} WHERE ID_Student={1} AND Materie='{2}';", medie, Main_form.id_user, materii_db.SelectedItem.ToString());
                 MyData.execSql(update);
             }
             else
             {
                 promovat_chk.Visible = false;
                 medie_txt.Visible    = false;
                 label3.Visible       = false;
             }
         }
     }
 }
コード例 #3
0
ファイル: Main form.cs プロジェクト: RD3luxe/Projects
 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;
         }
     }
 }
コード例 #4
0
ファイル: DirectorPanel.cs プロジェクト: RD3luxe/Projects
        private void m_ComboBoxColumn_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox comboBox = (ComboBox)sender;

            if ((save_comboBox - 1) == comboBox.SelectedIndex)
            {
                return;
            }
            if (comboBox.Text != null)
            {
                int    index     = comboBox.SelectedIndex + 1;
                string updateSql = string.Empty;
                //Iau datele din TabelMaterii, verific daca exista userul la id-ul materiei respective folosind like dupa sterg din string id-ul si il adaug la indexul nou creat
                //exista id-ul returnam id-urile profesorilor.
                updateSql = string.Format("SELECT ID_Profesori FROM TabelMaterii WHERE ID_Materie={0};", save_comboBox);
                string myIds   = MyData.stringSelector(updateSql, "ID_Profesori");
                string new_ids = string.Empty;
                if (!(string.IsNullOrEmpty(myIds)))
                {
                    string[] breaked_ids = myIds.Split(',');
                    if (breaked_ids.Length > 0)
                    {
                        for (int i = 0; i < breaked_ids.Length; i++)
                        {
                            int id = Convert.ToInt32(breaked_ids[i]);
                            if (id != save_id)
                            {
                                if (new_ids == string.Empty)
                                {
                                    new_ids = breaked_ids[i] + ",";
                                }
                                else
                                {
                                    new_ids += breaked_ids[i] + ",";
                                }
                            }
                        }
                        if (new_ids.Length > 0)
                        {
                            new_ids = new_ids.Remove(new_ids.Length - 1);
                        }
                    }
                }
                //update tabelul pt a sterge id-ul profesorului de la materia respectiva
                updateSql = string.Format("UPDATE TabelMaterii SET ID_Profesori='{0}' WHERE ID_Materie={1};", new_ids, save_comboBox);
                MyData.execSql(updateSql);
                //adaugam id-ul in materia noua
                updateSql = string.Format("SELECT ID_Profesori FROM TabelMaterii WHERE ID_Materie={0};", index);
                myIds     = MyData.stringSelector(updateSql, "ID_Profesori");
                myIds     = myIds.Length > 0 ? $"{myIds},{save_id}" : save_id.ToString();
                updateSql = string.Format("UPDATE TabelMaterii SET ID_Profesori='{0}' WHERE ID_Materie={1};", myIds, index);
                MyData.execSql(updateSql);
                //update db
                updateSql = string.Format("UPDATE Profesori SET IDMaterie={0} WHERE ID_Prof={1};", index, save_id);
                MyData.execSql(updateSql);
                //stergem toate testele date inainte pentru a preveni anumite probleme
                //TODO:stergem toate testele pe care le-a pus la aceea materie si resetam indexurile testelor
                updateSql = string.Format("DELETE ID_Student,ID_Prof,Materie,ID_Test,Nume_fisier,Nota,Nota_finala,Promovat,Promovat_Anul FROM Teste_Materii WHERE ID_Prof={0};", save_id);
                MyData.execSql(updateSql);
                //materii and grades modifica
                updateSql = string.Format("UPDATE Materii SET IDMaterie={0} WHERE IDProfesor={1};", index, save_id);
                MyData.execSql(updateSql);
                updateSql = string.Format("UPDATE Materii SET IDTesteAdaugate='' AND Numar_studenti='' WHERE IDProfesor={0};", save_id);
                MyData.execSql(updateSql);
                //grades
                updateSql = string.Format("SELECT Materii_inscris,Id_Profesor,ID_Student FROM Grades WHERE Id_Profesor LIKE '%{0}%';", save_id);
                DataTable dt = MyData.readTable(updateSql);
                string[]  broken, materii_index;
                string    id_nou      = string.Empty;
                string    materii_noi = string.Empty;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    broken        = dt.Rows[i][1].ToString().Split(',');
                    materii_index = dt.Rows[i][0].ToString().Split(',');
                    id_nou        = materii_noi = string.Empty;
                    for (int j = 0; j < broken.Length; j++)
                    {
                        if (Convert.ToInt32(materii_index[j]) != index)
                        {
                            //rewrite it
                            if (materii_noi == string.Empty)
                            {
                                materii_noi = materii_index[j];
                            }
                            else
                            {
                                materii_noi += "," + materii_index[j];
                            }
                        }
                        if (Convert.ToInt32(broken[j]) != save_id)
                        {
                            //rewrite it without current ID
                            if (id_nou == string.Empty)
                            {
                                id_nou = broken[j];
                            }
                            else
                            {
                                id_nou += "," + broken[j];
                            }
                        }
                    }
                    updateSql = string.Format("UPDATE Grades SET Materii_inscris='{0}' , ID_Profesor='{1}' WHERE ID_Profesor LIKE '%{2}%' AND ID_Student={3};", materii_noi, id_nou, save_id, dt.Rows[i][2]); //add user ID
                    MyData.execSql(updateSql);
                }
                //delete directory file
                //teste/<nume materie>/<nume profesor>
                string[] date = MyData.getData("Materii", new string[] { "Nume", "Prenume" }, "IDProfesor", save_id);
                string   path = string.Format($"teste/{comboBox.SelectedItem.ToString()}/{date[0]}_{date[1]}");
                if (Directory.Exists(path))
                {
                    Directory.Delete(path, true);
                }
            }
            comboBox.SelectedIndexChanged -= new EventHandler(m_ComboBoxColumn_SelectedIndexChanged);
            btn_modifica.Focus();
            if (once)
            {
                btn_modifica.PerformClick();
                once = false;
            }
            modifica_dgv.Refresh();
        }
コード例 #5
0
ファイル: DirectorPanel.cs プロジェクト: RD3luxe/Projects
        private void date_dgv_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (date_dgv.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
            {
                //ask first
                string mesaj = string.Empty;
                mesaj = string.Format("Esti sigur ca vrei sa stergi {0} {1} {2} ?", lista_modifica.SelectedIndex == 0? "profesorul":"studentul", date_dgv["Nume", e.RowIndex].Value.ToString(), date_dgv["Prenume", e.RowIndex].Value.ToString());
                DialogResult result = MessageBox.Show(mesaj, "Stergere", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                switch (result)
                {
                case DialogResult.Yes:
                    //delete record
                    string sql = string.Empty;
                    if (lista_modifica.SelectedIndex == 0)
                    {
                        string   materie_sql   = string.Format("SELECT IDMaterie FROM Materii WHERE IDProfesor={0};", date_dgv["IDProfesor", e.RowIndex].Value);
                        int      id_materie    = MyData.selectData(materie_sql, "IDMaterie");
                        string[] selectMaterii = MyData.getData("TabelMaterii", new string[] { "ID_Profesori" }, "ID_Materie", id_materie);
                        sql = string.Format("DELETE ID_Prof,Nick,Pass,IDMaterie,Ultima_Logare FROM Profesori WHERE ID_Prof={0};", date_dgv["IDProfesor", e.RowIndex].Value);
                        MyData.execSql(sql);
                        sql = string.Format("DELETE IDMaterie,IDProfesor,Nume,Prenume,IDTesteAdaugate FROM Materii WHERE IDProfesor={0};", date_dgv["IDProfesor", e.RowIndex].Value);
                        MyData.execSql(sql);
                        string   id_nou      = string.Empty;
                        string[] new_idprofi = selectMaterii[0].Split(',');
                        for (int i = 0; i < new_idprofi.Length; i++)
                        {
                            if (new_idprofi[i] != date_dgv["IDProfesor", e.RowIndex].Value.ToString())
                            {
                                //daca nu e egal cu id-ul profului nostru pe care il stergem ii dam add in noul string
                                if (id_nou == string.Empty)
                                {
                                    id_nou = new_idprofi[i];
                                }
                                else
                                {
                                    id_nou += "," + new_idprofi[i];
                                }
                            }
                        }
                        sql = string.Format("UPDATE TabelMaterii SET ID_Profesori='{0}' WHERE ID_Materie={1};", id_nou, id_materie);
                        MyData.execSql(sql);
                        sql = string.Format("DELETE ID_Student,ID_Prof,Materie,ID_Test,Nume_fisier,Nota,Nota_finala,Promovat,Promovat_Anul FROM Teste_Materii WHERE ID_Prof={0};", date_dgv["IDProfesor", e.RowIndex].Value);
                        MyData.execSql(sql);
                        //TODO:delete index from grades too
                        sql = string.Format("SELECT Materii_inscris,Id_Profesor,ID_Student FROM Grades WHERE Id_Profesor LIKE '%{0}%';", date_dgv["IDProfesor", e.RowIndex].Value);
                        DataTable dt = MyData.readTable(sql);
                        string[]  broken, materii_index;
                        id_nou = string.Empty;
                        string materii_noi = string.Empty;
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            broken        = dt.Rows[i][1].ToString().Split(',');
                            materii_index = dt.Rows[i][0].ToString().Split(',');
                            id_nou        = materii_noi = string.Empty;
                            for (int j = 0; j < broken.Length; j++)
                            {
                                if (Convert.ToInt32(materii_index[j]) != id_materie)
                                {
                                    //rewrite it
                                    if (materii_noi == string.Empty)
                                    {
                                        materii_noi = materii_index[j];
                                    }
                                    else
                                    {
                                        materii_noi += "," + materii_index[j];
                                    }
                                }
                                if (Convert.ToInt32(broken[j]) != Convert.ToInt32(date_dgv["IDProfesor", e.RowIndex].Value))
                                {
                                    //rewrite it without current ID
                                    if (id_nou == string.Empty)
                                    {
                                        id_nou = broken[j];
                                    }
                                    else
                                    {
                                        id_nou += "," + broken[j];
                                    }
                                }
                            }
                            sql = string.Format("UPDATE Grades SET Materii_inscris='{0}' , ID_Profesor='{1}' WHERE ID_Profesor LIKE '%{2}%' AND ID_Student={3};", materii_noi, id_nou, date_dgv["IDProfesor", e.RowIndex].Value, dt.Rows[i][2]);    //add user ID
                            MyData.execSql(sql);
                            string path = string.Format($"teste/{modifica_dgv["Materie", e.RowIndex].Value.ToString()}/{modifica_dgv["Nume", e.RowIndex].Value.ToString()}_{modifica_dgv["Prenume", e.RowIndex].Value.ToString()}");
                            if (Directory.Exists(path))
                            {
                                Directory.Delete(path, true);
                            }
                        }
                    }
                    else
                    {
                        sql = string.Format("DELETE ID_Student,Nick,Parola,Ultima_logare FROM Studenti WHERE ID_Student={0};", date_dgv["ID_Student", e.RowIndex].Value);
                        MyData.execSql(sql);
                        sql = string.Format("DELETE ID_Student,Nume,Prenume,Materii_inscris FROM Grades WHERE ID_Student={0};", date_dgv["ID_Student", e.RowIndex].Value);
                        MyData.execSql(sql);
                        sql = string.Format("DELETE ID_Student,ID_Prof,Materie,ID_Test,Nume_fisier,Nota,Nota_finala,Promovat,Promovat_Anul FROM Teste_Materii WHERE ID_Student={0};", date_dgv["ID_Student", e.RowIndex].Value);
                        MyData.execSql(sql);
                    }
                    //mesaj
                    mesaj = string.Format("{0} {1} {2} a fost sters din baza de date !", lista_modifica.SelectedIndex == 0 ? "Profesorul" : "Studentul", date_dgv["Nume", e.RowIndex].Value.ToString(), date_dgv["Prenume", e.RowIndex].Value.ToString());
                    MessageBox.Show(mesaj, "Camp sters !", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //recreate table
                    CreateTable(1);
                    break;

                case DialogResult.No:
                    //nu se intampla nimic
                    break;
                }
            }
        }
コード例 #6
0
ファイル: DirectorPanel.cs プロジェクト: RD3luxe/Projects
        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;
            }
        }