Exemplo n.º 1
0
        private void Ajouter_Enseignant_Load(object sender, EventArgs e)
        {
            DataTable       dt       = new DataTable();
            Dal_Departement Dal_Dept = new Dal_Departement();

            dt = Dal_Dept.GetAllDepartementsDataTable();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                this.Cbx_Dept.Items.Add(dt.Rows[i]["Code"]);
            }
        }
Exemplo n.º 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);
        }