Beispiel #1
0
        private void suppBtn_Click(object sender, RoutedEventArgs e)
        {
            if (dataGridEtud.SelectedItem == null)
            {
                MessageBox.Show("Veuillez selectionner une ligne de grille pour supprimer", "Message", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBoxResult result2 = MessageBox.Show("Voulez vraiment supprimer cet étudiant", "Message Important", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);

                if (result2 == MessageBoxResult.Yes)
                {
                    //var index = dataGridEtud.SelectedIndex;
                    ////here we get the actual row at selected index
                    //DataGridRow row = dataGridEtud.ItemContainerGenerator.ContainerFromIndex(index) as DataGridRow;
                    //DataRowView MyRow = (DataRowView)row.Item ;


                    Etudiant etu = (Etudiant)dataGridEtud.SelectedItem;

                    var deletedEtud = _db.Etudiants.Where <Etudiant>(et => et.ID_Etudiant == etu.ID_Etudiant).Single();
                    // dataGridEtud.Items.RemoveAt(dataGridEtud.SelectedIndex);
                    _db.Etudiants.Remove(deletedEtud);
                    _db.SaveChanges();
                    MessageBox.Show("Etudiant supprimé avec succè ", "Message", MessageBoxButton.OK, MessageBoxImage.Information);

                    //Refresh the datagrid after deleting
                    String fili      = this.filiereComboBox.SelectedItem.ToString();
                    var    comboFili = _db.Filieres.Where <Filiere>(fi => fi.FiliereName == fili).Single();
                    var    etudiants = _db.Etudiants.Where <Etudiant>(et => et.ID_Filiere == comboFili.ID_Filiere);
                    obse = new ObservableCollection <Etudiant>(etudiants.ToList());
                    dataGridEtud.ItemsSource = obse;
                }
            }
        }
        public UpdatePage(Etudiant et)
        {
            this.et = et;
            InitializeComponent();
            ID = (int)et.ID_Filiere;
            openFileDialog1 = new OpenFileDialog
            {
                InitialDirectory = @"E:\",
                Title            = "Browse Student jpg File",

                CheckFileExists = true,
                CheckPathExists = true,

                Filter           = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif",
                FilterIndex      = 2,
                RestoreDirectory = true,
                ReadOnlyChecked  = true,
                ShowReadOnly     = true
            };

            cneTxt.Text    = et.CNE;
            nomTxt.Text    = et.FirstName;
            prenomTxt.Text = et.LastName;
            genderTxt.Text = et.gender;
            adressTxt.Text = et.adresse;
            telephTxt.Text = et.tele;
        }
Beispiel #3
0
 private void modifBtn_Click(object sender, RoutedEventArgs e)
 {
     if (dataGridEtud.SelectedItem == null)
     {
         MessageBox.Show("Veuillez selectionner une ligne de grille pour modifier", "Message", MessageBoxButton.OK, MessageBoxImage.Information);
     }
     else
     {
         Etudiant   etu     = (Etudiant)dataGridEtud.SelectedItem;
         UpdatePage updPage = new UpdatePage(etu);
         updPage.ShowDialog();
     }
 }
        private void insererBtn_Click(object sender, RoutedEventArgs e)
        {
            if (cneTxt.Text == "" || nomTxt.Text == "" || prenomTxt.Text == "" || genderTxt.Text == "" || birthTxt.SelectedDate == null || adressTxt.Text == "" || telephTxt.Text == "" || ageTxt.Text == "" || filierTxt.Text == "")
            {
                MessageBox.Show("Veillez remplir tous les champs ", "Message", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                //*************************************************************//

                //Partie insertion de photo dans le repertoire

                if (imgSiteLogo.Source == null)
                {
                    MessageBox.Show("image is required.");
                    return;
                }
                string sourceFile = (imgSiteLogo.Source as BitmapImage).UriSource.AbsolutePath;
                string targetPath = @"E:\pictures";
                // for the name of student image set its name to "firstName-lastName-CNE.jpg"
                MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory);
                string fileName = String.Format("{0}-{1}-{2}.jpg", nomTxt.Text, prenomTxt.Text, cneTxt.Text);
                // Use Path class to manipulate file and directory paths.
                string destFile = System.IO.Path.Combine(targetPath, fileName);
                //MessageBox.Show("sourceFile : " + sourceFile);
                // To copy a folder's contents to a new location:
                // Create a new target folder.
                // If the directory already exists, this method does not create a new directory.
                System.IO.Directory.CreateDirectory(targetPath);
                // To copy a file to another location and
                // overwrite the destination file if it already exist
                System.IO.File.Copy(sourceFile, destFile, true);

                // - then insert to student table imageName =  fileName or destFile
                // - to show it in datagrid view do this
                // =====> _____.source =  $"{AppDomain.CurrentDomain.BaseDirectory}pictures/{row[imageName]}"

                etu = new Etudiant()
                {
                    CNE        = cneTxt.Text,
                    FirstName  = nomTxt.Text,
                    LastName   = prenomTxt.Text,
                    gender     = genderTxt.Text,
                    DOB        = birthTxt.SelectedDate,
                    adresse    = adressTxt.Text,
                    tele       = telephTxt.Text,
                    age        = Int32.Parse(ageTxt.Text),
                    photo      = destFile,
                    ID_Filiere = filierTxt.SelectedIndex + 1
                };

                _db.Etudiants.Add(etu);
                _db.SaveChanges();

                //AccueilEtudiant.datagrid.ItemsSource = _db.Etudiants.ToList();   Remplissage automatique de la base de donnees

                // Permet de fermer la fenetre d'ajout
                this.Hide();
                MessageBox.Show("Etudiant ajouté avec succès", "Message", MessageBoxButton.OK, MessageBoxImage.Information);
                // Permer de rafraichir la datagrid par la nouvelle insertion
            }
        }