private void Btn_Ajouter_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(Txt_Nom.Text) || string.IsNullOrEmpty(Cbx_Dept.Text))
                {
                    MessageBox.Show("Une ou plusieurs entrées invalides", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    S.PropNom    = Txt_Nom.Text;
                    S.PropPrenom = Txt_Pren.Text;
                    S.PropEmail  = Txt_Email.Text;
                    S.PropDepartements.PropCode = Cbx_Dept.SelectedItem.ToString();

                    Dal_Ens.AddEnseignant(S);
                    MessageBox.Show("Ajouté avec succès", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);


                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
        private void Btn_Importer_Click(object sender, EventArgs e)
        {
            var fileContent = string.Empty;
            var filePath    = string.Empty;

            using (OpenFileDialog Ofd = new OpenFileDialog()
            {
                Filter = "Fichiers Excel | *.xls; *.xlsx; *.xlsm", ValidateNames = true, Multiselect = false
            })
            {
                if (Ofd.ShowDialog() == DialogResult.OK)
                {
                    //Get the path of specified file
                    filePath = Ofd.FileName;
                    Dal_Departement     Dal_Dept = new Dal_Departement();
                    List <Departements> DeptList = Dal_Dept.GetAllDepartementsList();

                    Dal_Ens.GetDataFromExcelFile(filePath, out MydataTabX, out MydataTabY, out MydataTabA, out MydataTabB, out MydataTabC);
                    for (int i = 0; i < MydataTabA.Length; i++)
                    {
                        Departements Dept = new Departements(MydataTabB[i], MydataTabC[i]);
                        if (!DeptList.Contains(Dept))
                        {
                            Dal_Dept.AddDepartement(Dept);
                        }
                        Enseignants Ens = new Enseignants(MydataTabX[i], MydataTabY[i], MydataTabA[i], "En cours", Dept);
                        Dal_Ens.AddEnseignant(Ens);
                        fillDgvEns();
                    }
                    MessageBox.Show("Données importées avec succès", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    /*   //Read the contents of the file into a stream
                     * var fileStream = Ofd.OpenFile();
                     *
                     * using (StreamReader reader = new StreamReader(fileStream))
                     * {
                     *     fileContent = reader.ReadToEnd();
                     * }
                     */
                }
            }

            // MessageBox.Show(fileContent, "File Content at path: " + filePath, MessageBoxButtons.OK);
        }