예제 #1
0
        bool ExamenSet;                                 //daca e examen sau nu
        private void bunifuFlatButton3_Click(object sender, EventArgs e)
        {
            try
            {
                this.idProf1     = bunifuDropdown6.selectedIndex;//sunt indexii din table de profesori --> IndexiProfesori
                this.idProf2     = bunifuDropdown7.selectedIndex;
                this.idAsistent1 = bunifuDropdown8.selectedIndex;
                this.idAsistent2 = bunifuDropdown9.selectedIndex;
                //adaugam in baza de date
                if (idProf1 != -1 && idAsistent1 != -1 && bunifuMaterialTextbox6.Text != "" && bunifuDropdown10.selectedIndex != -1 && bunifuMaterialTextbox2.Text != "" && bunifuMaterialTextbox3.Text != "" && bunifuMaterialTextbox4.Text != "" && bunifuMaterialTextbox5.Text != "")
                {
                    if (bunifuCheckbox1.Checked)
                    {
                        ExamenSet = true;
                    }
                    else
                    {
                        ExamenSet = false;
                    }

                    int idProf2aux;//pentru a tine minte ce transmite mai departe
                    int idAsistent2aux;

                    //cautam daca mai exista aceasta materie
                    using (var catalog = new CatalogEntities1())
                    {
                        using (var dbCatalogTransaction = catalog.Database.BeginTransaction())
                        {
                            var materii = from c in catalog.Materies
                                          where c.NumeMaterie.Equals(this.NumeMaterieSelectata) && c.GrupaID == IdGrupaSelectata
                                          select c;
                            if (materii.Count() == 0)
                            { //daca nu mai exista o adaugam
                              //adaugam in baza de date
                                try
                                {
                                    if (bunifuCheckbox2.Checked == false)
                                    {
                                        idProf2aux = -1;//adica null
                                    }
                                    else
                                    {
                                        idProf2aux = IndexiProfesori.ElementAt(idProf2);
                                    }

                                    if (bunifuCheckbox3.Checked == false)
                                    {
                                        idAsistent2aux = -1;//adica e null
                                    }
                                    else
                                    {
                                        idAsistent2aux = IndexiProfesori.ElementAt(idAsistent2);
                                    }
                                    //apelam procedura stocata cu parametrii selectati pentru materie:

                                    catalog.Adaugare_Materie(IdGrupaSelectata, NumeMaterieSelectata, IndexiProfesori.ElementAt(idProf1), idProf2aux, IndexiProfesori.ElementAt(idAsistent1), idAsistent2aux, float.Parse(bunifuMaterialTextbox2.Text), float.Parse(bunifuMaterialTextbox3.Text), float.Parse(bunifuMaterialTextbox4.Text), float.Parse(bunifuMaterialTextbox5.Text), ExamenSet, Int32.Parse(bunifuMaterialTextbox6.Text), bunifuDropdown10.selectedIndex + 1);
                                    catalog.SaveChanges();
                                    dbCatalogTransaction.Commit();
                                    //end adaugare

                                    //adaugam in gridview
                                    AdaugareMateriiGridView(NumeMaterieSelectata);
                                }
                                catch (Exception ex)
                                {
                                    dbCatalogTransaction.Rollback();
                                    FormError newForm = new FormError();
                                    newForm.SetText(ex.ToString());
                                    newForm.ShowDialog();
                                }
                            }
                            else
                            {//semnalizam ca materia deja exista
                                Bitmap cale = new Bitmap("Failed_Exam.png");
                                bunifuFlatButton1.Iconimage = cale;
                                bunifuMaterialTextbox1.Text = "Aceasta Materie deja exsita!";
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                FormError newForm = new FormError();
                newForm.SetText(ex.ToString());
                newForm.ShowDialog();
            }
        }