예제 #1
0
        public DataTable getMaterii()
        {
            DataTable data = new DataTable();

            MyData.readTable("TabelMaterii", "Nume_Materie", ref data);
            return(data);
        }
예제 #2
0
        public void LoadDataStudenti()
        {
            if (studenti_dgv.DataSource != null)
            {
                studenti_dgv.Columns.Clear();
            }
            string data = string.Empty;

            switch (tip)
            {
            case 1:
                mesaj_lbl.Text   = "Lista studenti inscrisi";
                nume_cmb.Visible = false;
                data             = string.Format("SELECT Grades.ID_Student,Grades.Nume,Grades.Prenume,Studenti.Nick,Studenti.Parola,Studenti.Ultima_logare FROM Grades,Studenti WHERE Grades.ID_Student = Studenti.ID_Student AND Grades.ID_Profesor LIKE '%{0}%';", Main_form.id_user);
                dt = MyData.readTable(data);
                studenti_dgv.DataSource = dt;
                for (int i = 0; i < studenti_dgv.Columns.Count; i++)
                {
                    studenti_dgv.Columns[i].ReadOnly = true;
                }
                break;

            case 2:
                nume_cmb.Visible = true;
                mesaj_lbl.Text   = "Lista studenti promovati";
                data             = string.Format("SELECT Grades.ID_Student,Grades.Nume,Grades.Prenume,Teste_Materii.Nota,Teste_Materii.Nume_fisier,Teste_Materii.Nota_finala FROM Grades,Teste_Materii WHERE Teste_Materii.ID_Student={1} AND Grades.ID_Student = Teste_Materii.ID_Student AND Teste_Materii.ID_Prof={0} AND Teste_Materii.Promovat_Anul=true AND Teste_Materii.Nota <> 0;", Main_form.id_user, getStudentID());
                dt = MyData.readTable(data);
                dt.Columns["Nume_fisier"].ColumnName = "Nume test";
                dt.AcceptChanges();
                studenti_dgv.DataSource = dt;
                for (int i = 0; i < studenti_dgv.Columns.Count; i++)
                {
                    if (studenti_dgv.Columns[i].Name == "Nota")
                    {
                        continue;
                    }
                    studenti_dgv.Columns[i].ReadOnly = true;
                }
                break;

            case 3:
                nume_cmb.Visible = true;
                mesaj_lbl.Text   = "Lista studenti nepromovati";
                data             = string.Format("SELECT Grades.ID_Student,Grades.Nume,Grades.Prenume,Teste_Materii.Nota,Teste_Materii.Nume_fisier,Teste_Materii.Nota_finala FROM Grades,Teste_Materii WHERE Teste_Materii.ID_Student={1} AND Grades.ID_Student = Teste_Materii.ID_Student AND Teste_Materii.ID_Prof={0} AND Teste_Materii.Promovat_Anul=false AND Teste_Materii.Nota <> 0;", Main_form.id_user, getStudentID());
                dt = MyData.readTable(data);
                dt.Columns["Nume_fisier"].ColumnName = "Nume test";
                dt.AcceptChanges();
                studenti_dgv.DataSource = dt;
                for (int i = 0; i < studenti_dgv.Columns.Count; i++)
                {
                    if (studenti_dgv.Columns[i].Name == "Nota")
                    {
                        continue;
                    }
                    studenti_dgv.Columns[i].ReadOnly = true;
                }
                break;
            }
        }
예제 #3
0
        public void LoadDateTeste()
        {
            teste_dgv.Columns.Clear();
            string    sql = string.Format("SELECT Teste_Materii.ID_Test,Teste_Materii.Nume_fisier,Teste_Materii.Materie,Teste_Materii.ID_Prof FROM Teste_Materii WHERE Teste_Materii.ID_Student={0} AND Teste_Materii.Nota=0;", Main_form.id_user);
            DataTable dt  = MyData.readTable(sql);

            if (dt.Rows.Count != 0)
            {
                teste_dgv.DataSource = dt;
                teste_dgv.Columns["Nume_fisier"].HeaderText = "Nume test";
            }
        }
예제 #4
0
 private void modifica_dgv_Sorted(object sender, EventArgs e)
 {
     if (lista_modifica.SelectedItem.ToString() == lista_modifica.Items[0].ToString())
     {
         string sqlmodifica = string.Format("SELECT Materii.IDProfesor,Materii.Nume,Materii.Prenume,TabelMaterii.Nume_Materie,Profesori.Nick,Profesori.Pass FROM Materii,TabelMaterii,Profesori WHERE Profesori.IDMaterie=TabelMaterii.ID_Materie AND Profesori.ID_Prof=Materii.IDProfesor;");
         table = MyData.readTable(sqlmodifica);
         for (int i = 0; i < modifica_dgv.RowCount; i++)
         {
             modifica_dgv["lst_materii", i].Value = table.Rows[i]["Nume_Materie"];
         }
     }
 }
예제 #5
0
        public bool has_students(string profesor)
        {
            string    sql_materii = string.Format("SELECT Nume,Prenume FROM Grades WHERE ID_Profesor LIKE '%{0}%';", profesor);
            DataTable date        = MyData.readTable(sql_materii);

            if (date.Rows.Count <= 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #6
0
        private void materii_cb_SelectedIndexChanged(object sender, EventArgs e)
        {
            //index changed => redraw grafic
            //ia notele din baza de date si deseneaza
            materii_note.ChartAreas[0].AxisY.Maximum = 10;
            materii_note.Series["Teste"].Points.Clear();
            string    sql = string.Format("SELECT Nota,Nume_fisier FROM Teste_Materii WHERE Nota <> 0 AND ID_Student={0} AND Materie='{1}';", Main_form.id_user, materii_cb.SelectedItem.ToString());
            DataTable dt  = MyData.readTable(sql);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                double da = Convert.ToDouble(dt.Rows[i][0]);
                materii_note.Series["Teste"].Points.AddXY(dt.Rows[i][1].ToString(), Convert.ToDouble(dt.Rows[i][0]));
            }
        }
예제 #7
0
        public void saveTotal()
        {
            string    sql   = string.Format("SELECT Nota FROM Teste_Materii WHERE ID_Student={0} AND Materie='{1}';", data[2], box_materii.SelectedItem);
            DataTable dt    = MyData.readTable(sql);
            double    total = 0;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                total += Convert.ToInt32(dt.Rows[i][0]);
            }
            total = total / dt.Rows.Count;
            total = Math.Ceiling(total);
            sql   = string.Format("UPDATE Teste_Materii SET Nota_finala={0} WHERE ID_Student={1} AND Materie='{2}';", total, data[2], box_materii.SelectedItem);
            MyData.execSql(sql);
        }
예제 #8
0
        public void AddStudentiInBox(ComboBox box)
        {
            box.Items.Clear();
            string    sql_materii = string.Format("SELECT Nume,Prenume FROM Grades WHERE ID_Profesor LIKE '%{0}%';", data[3]);
            DataTable date        = MyData.readTable(sql_materii);

            if (date.Rows.Count > 0)
            {
                for (int i = 0; i < date.Rows.Count; i++)
                {
                    string item = $"{date.Rows[i]["Nume"].ToString()} {date.Rows[i]["Prenume"].ToString()}";
                    box.Items.Add(item);
                }
            }
            box.SelectedIndex = 0;
        }
예제 #9
0
        public void ListaTeste()
        {
            if (studenti_dgv.DataSource != null)
            {
                studenti_dgv.Columns.Clear();
            }
            //teste all , delete , etc
            nume_cmb.Visible      = true;
            listaStudenti.Visible = true;
            add_pnl.Visible       = false;
            mesaj_lbl.Text        = "Lista teste";
            mesaj_lbl.TextAlign   = System.Drawing.ContentAlignment.TopCenter;
            string sql = string.Format("SELECT ID_Test,Nume_fisier,Promovat FROM Teste_Materii WHERE ID_Student={0} AND ID_Prof={1};", getStudentID(), Main_form.id_user);

            dt = MyData.readTable(sql);
            studenti_dgv.DataSource = dt;
            studenti_dgv.Columns["Nume_fisier"].HeaderText = "Nume test";
            //butoane delete , modifica and reset
            DataGridViewButtonColumn btn = new DataGridViewButtonColumn();

            btn.Name       = "delete";
            btn.HeaderText = "Sterge test";
            btn.Text       = "Sterge";
            btn.UseColumnTextForButtonValue = true;
            btn.ValueType = typeof(Button);
            studenti_dgv.Columns.Add(btn);
            btn            = new DataGridViewButtonColumn();
            btn.Name       = "modifica";
            btn.HeaderText = "Modifica test";
            btn.Text       = "Modifica";
            btn.UseColumnTextForButtonValue = true;
            btn.ValueType = typeof(Button);
            studenti_dgv.Columns.Add(btn);
            btn            = new DataGridViewButtonColumn();
            btn.Name       = "reset";
            btn.HeaderText = "Reseteaza test";
            btn.Text       = "Reset";
            btn.UseColumnTextForButtonValue = true;
            btn.ValueType = typeof(Button);
            studenti_dgv.Columns.Add(btn);
            for (int i = 0; i < studenti_dgv.Rows.Count; i++)
            {
                studenti_dgv.Columns[i].ReadOnly = true;
            }
        }
예제 #10
0
 private void adaugaTeste_Click(object sender, EventArgs e)
 {
     //add panel
     if (tip_intrebare.Items.Count <= 0)
     {
         tip_intrebare.Items.Add("Raspunsuri multiple");
         tip_intrebare.Items.Add("Raspunsuri unice");
     }
     if (studenti_lst.Items.Count <= 0)
     {
         studenti_lst.Items.Add("Toti");
         string    sql = string.Format("SELECT Nume,Prenume FROM Grades WHERE ID_Profesor LIKE '%{0}%';", Main_form.id_user);
         DataTable dt  = MyData.readTable(sql);
         for (int i = 0; i < dt.Rows.Count; i++)
         {
             string item_complet = string.Format($"{dt.Rows[i][0].ToString()} {dt.Rows[i][1].ToString()}");
             studenti_lst.Items.Add(item_complet);
         }
     }
     InitCreate();
 }
예제 #11
0
 public void InitListaStudenti(ComboBox cb)
 {
     if (cb.Items.Count <= 0)
     {
         string    sql = string.Format("SELECT Nume,Prenume FROM Grades WHERE ID_Profesor LIKE '%{0}%';", Main_form.id_user);
         DataTable dt  = MyData.readTable(sql);
         for (int i = 0; i < dt.Rows.Count; i++)
         {
             string item_complet = string.Format($"{dt.Rows[i][0].ToString()} {dt.Rows[i][1].ToString()}");
             cb.Items.Add(item_complet);
         }
         if (dt.Rows.Count > 0)
         {
             cb.SelectedIndex = 0;
         }
         else
         {
             MessageBox.Show("Nu ai nici un elev inscris la cursurile tale.", "Informatie", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
예제 #12
0
        public void getData()
        {
            DataTable dt;
            string    sql = string.Empty;

            switch (type)
            {
            case 0:
                sql                  = string.Format("SELECT ID_Test,Nume_fisier,Nota,Nota_finala FROM Teste_Materii WHERE ID_Student={0} AND Materie='{1}';", data[2], box_materii.SelectedItem.ToString());
                test_lbl.Text        = $"Notele elevului {data[0]} {data[1]}";
                dt                   = MyData.readTable(sql);
                lista_dgv.DataSource = dt;
                lista_dgv.Columns["Nota_finala"].ReadOnly = true;
                test_lbl.TextAlign = ContentAlignment.TopCenter;
                break;

            case 1:
                lista_dgv.Columns.Clear();
                string[] correct_name = box_materii.SelectedItem.ToString().Split(' ');
                string   sql_materii  = string.Format("SELECT ID_Student FROM Grades WHERE ID_Profesor LIKE '%{0}%' AND Nume='{1}' AND Prenume='{2}';", data[3], correct_name[0], correct_name[1]);
                int      id_student   = MyData.selectData(sql_materii, "ID_Student");
                sql                  = string.Format("SELECT ID_Test,Nume_fisier FROM Teste_Materii WHERE ID_Student={0} AND Materie='{1}';", id_student, data[2]);
                test_lbl.Text        = $"Modifica testele profesorului {data[0]} {data[1]}";
                dt                   = MyData.readTable(sql);
                lista_dgv.DataSource = dt;
                DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
                btn.Name       = "change";
                btn.HeaderText = "Modifica testul";
                btn.ValueType  = typeof(Button);
                btn.Text       = "Modifica";
                btn.UseColumnTextForButtonValue = true;
                lista_dgv.Columns.Add(btn);
                test_lbl.TextAlign = ContentAlignment.TopLeft;
                break;
            }
            lista_dgv.Columns["ID_Test"].ReadOnly     = true;
            lista_dgv.Columns["Nume_fisier"].ReadOnly = true;
        }
예제 #13
0
 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;
             }
         }
     }
 }
예제 #14
0
        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();
        }
예제 #15
0
        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;
                }
            }
        }
예제 #16
0
        public void InitAllCourses()
        {
            dgv_allcourse.Columns.Clear();
            string    sql = string.Format("SELECT TabelMaterii.ID_Materie,TabelMaterii.Nume_Materie,Materii.Nume,Materii.Prenume,Materii.IDTesteAdaugate FROM TabelMaterii,Materii WHERE TabelMaterii.ID_Materie=Materii.IDMaterie;");
            DataTable dt  = MyData.readTable(sql);

            if (dt.Rows.Count > 0)
            {
                dgv_allcourse.DataSource = dt;
                dgv_allcourse.Columns["Nume"].HeaderText         = "Nume profesor";
                dgv_allcourse.Columns["ID_Materie"].HeaderText   = "ID Materie";
                dgv_allcourse.Columns["Nume_Materie"].HeaderText = "Nume Materie";
                DataGridViewTextBoxColumn nr_teste = new DataGridViewTextBoxColumn();
                nr_teste.Name       = "nr_teste";
                nr_teste.HeaderText = "Numar teste";
                nr_teste.ValueType  = typeof(string);
                dgv_allcourse.Columns.Add(nr_teste);
                int count = 0;
                for (int i = 0; i < dgv_allcourse.Rows.Count; i++)
                {
                    if (dt.Rows[i]["IDTesteAdaugate"].ToString().Contains(","))
                    {
                        count = Convert.ToInt32(dt.Rows[i]["IDTesteAdaugate"].ToString().Split(',').Length);
                    }
                    else
                    {
                        if (dt.Rows[i]["IDTesteAdaugate"].ToString().Length != 0)
                        {
                            count = 1;
                        }
                        else
                        {
                            count = 0;
                        }
                    }
                    dgv_allcourse["nr_teste", i].Value = count.ToString();
                }
                dgv_allcourse.Columns.Remove("IDTesteAdaugate");
                dgv_allcourse.Columns.Add("count_st", "Studenti inscrisi");
                //numara cati elevi are fiecare profesor | start counting
                DataTable tb = new DataTable();
                sql = string.Format("SELECT Numar_studenti FROM Materii;");
                tb  = MyData.readTable(sql);
                for (int i = 0; i < tb.Rows.Count; i++)
                {
                    if (!string.IsNullOrEmpty(tb.Rows[i][0].ToString()))
                    {
                        dgv_allcourse["count_st", i].Value = tb.Rows[i][0];
                    }
                    else
                    {
                        dgv_allcourse["count_st", i].Value = 0;
                    }
                }
                //button
                DataGridViewButtonColumn apply = new DataGridViewButtonColumn();
                apply.Name       = "apply_btn";
                apply.HeaderText = "Alege materiile";
                apply.Text       = "Aplica";
                apply.UseColumnTextForButtonValue = true;
                dgv_allcourse.Columns.Add(apply);
            }
        }
예제 #17
0
        public void CreateTable(int type)
        {
            table = new DataTable();
            switch (type)
            {
            case 1:
                string sqlselect = string.Empty;
                if (lista_modifica.SelectedItem.ToString() == lista_modifica.Items[0].ToString())
                {
                    sqlselect = string.Format("SELECT IDProfesor,Nume,Prenume FROM Materii;");
                    table     = MyData.readTable(sqlselect);
                    string sql = string.Format("SELECT ID_Materie,Nume_Materie FROM TabelMaterii;");
                    table_materii = MyData.readTable(sql);
                    table.Columns.Add("Materie");
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        string materie_sql = string.Format("SELECT IDMaterie FROM Materii WHERE IDProfesor={0};", table.Rows[i][0]);
                        int    materie_id  = MyData.selectData(materie_sql, "IDMaterie");
                        for (int j = 0; j < table_materii.Rows.Count; j++)
                        {
                            if (Convert.ToInt32(table_materii.Rows[j][0]) == materie_id)
                            {
                                table.Rows[i]["Materie"] = table_materii.Rows[j][1];
                            }
                        }
                    }
                }
                else
                {
                    sqlselect = string.Format("SELECT ID_Student,Nume,Prenume FROM Grades;");
                    table     = MyData.readTable(sqlselect);
                }
                date_dgv.Columns.Clear();
                date_dgv.DataSource = table;
                DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
                btn.HeaderText = "Sterge " + lista_modifica.SelectedItem.ToString();
                btn.Name       = "delete_btn";
                btn.Text       = "Sterge";
                btn.ValueType  = typeof(Button);
                btn.UseColumnTextForButtonValue = true;
                date_dgv.Columns.Add(btn);
                break;

            case 2:
                string sqlmodifica = string.Empty;
                if (lista_modifica.SelectedItem.ToString() == lista_modifica.Items[0].ToString())
                {
                    sqlmodifica = string.Format("SELECT Materii.IDProfesor,Materii.Nume,Materii.Prenume,TabelMaterii.Nume_Materie,Profesori.Nick,Profesori.Pass FROM Materii,TabelMaterii,Profesori WHERE Profesori.IDMaterie=TabelMaterii.ID_Materie AND Profesori.ID_Prof=Materii.IDProfesor;");
                    table       = MyData.readTable(sqlmodifica);
                    modifica_dgv.Columns.Clear();
                    modifica_dgv.DataSource = table;
                    //Remodelate coloana 4 intr-o lista dropdown
                    DataGridViewComboBoxColumn list_materii = new DataGridViewComboBoxColumn();
                    list_materii.HeaderText = "Materie";
                    list_materii.Name       = "lst_materii";
                    DataTable dt  = getMaterii();
                    object[]  obj = new object[dt.Rows.Count];
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        obj[i] = dt.Rows[i]["Nume_Materie"];
                    }
                    list_materii.Items.AddRange(obj);
                    modifica_dgv.Columns.RemoveAt(3);
                    modifica_dgv.Columns.Add(list_materii);
                    for (int i = 0; i < modifica_dgv.RowCount; i++)
                    {
                        modifica_dgv["lst_materii", i].Value = table.Rows[i]["Nume_Materie"];
                    }
                    //buton cu ce teste a adaugat
                    DataGridViewButtonColumn ts = new DataGridViewButtonColumn();
                    ts.Name       = "teste_btn";
                    ts.HeaderText = "Teste adaugate";
                    ts.Text       = "Editeaza";
                    ts.UseColumnTextForButtonValue = true;
                    ts.ValueType = typeof(Button);
                    modifica_dgv.Columns.Add(ts);
                    modifica_dgv.Columns["IDProfesor"].ReadOnly = true;
                }
                else
                {
                    sqlmodifica = string.Format("SELECT Grades.ID_Student,Grades.Nume,Grades.Prenume,Studenti.Nick,Studenti.Parola,Grades.Materii_inscris FROM Studenti,Grades WHERE Grades.ID_Student=Studenti.ID_Student;");
                    table       = MyData.readTable(sqlmodifica);
                    modifica_dgv.Columns.Clear();
                    modifica_dgv.DataSource = table;
                    modifica_dgv.Columns["Materii_inscris"].Name = "ID_Materii";
                    //buton teste windows
                    DataGridViewButtonColumn button = new DataGridViewButtonColumn();
                    button.Name       = "teste_btn";
                    button.HeaderText = "Teste";
                    button.Text       = "Vezi teste";
                    button.ValueType  = typeof(Button);
                    button.UseColumnTextForButtonValue = true;
                    modifica_dgv.Columns.Add(button);
                    modifica_dgv.Columns["ID_Student"].ReadOnly = true;
                }
                break;
            }
        }