private void grdListeMention_KeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Delete) { if (MessageBox.Show("Voulez-vous vraiment le supprimer ? ", "School : Confimation", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { if (grdListeMention.SelectedIndex == ListeMentions.Count - 1) { MentionBE mention = ListeMentions.ElementAt(grdListeMention.SelectedIndex); definirMentionBL.supprinerMention(mention); List <MentionBE> List = definirMentionBL.listerToutesLesMentions(); RemplirDataGrid(List); LMention = List; txtNoteMin.Text = ""; txtNoteMax.Text = ""; txtMention.Text = ""; } else { MessageBox.Show("Impossible de supprimer cet élément ! \n \n Vous ne pouvez supprimer que le dernier élément de la liste !"); } } grdListeMention.UnselectAll(); } }
public WindowDefinirMentionUI() { CultureInfo ci = CultureInfo.CreateSpecificCulture(CultureInfo.CurrentCulture.Name); ci.DateTimeFormat.ShortDatePattern = "dd-MM-yyyy"; Thread.CurrentThread.CurrentCulture = ci; InitializeComponent(); definirMentionBL = new DefinirMentionBL(); LMention = new List <MentionBE>(); etat = 0; etatGrid = 0; // A mettre pour que le binding avec le DataGrid fonctionne ! grdListeMention.DataContext = this; // Initialisation de la collection, qui va s'afficher dans la DataGrid : ListeMentions = new ObservableCollection <MentionBE>(); oldMention = new MentionBE(); //on charge la liste des mentions deja défines dans le dataGrid List <MentionBE> ListMention = definirMentionBL.listerToutesLesMentions(); RemplirDataGrid(ListMention); LMention = ListMention; }
// modifier une Mention public bool modifierMention(MentionBE mention, MentionBE newMention) { if (mentionDA.modifier(mention, newMention)) { journalDA.journaliser("suppression de la mention de noteMin : " + mention.noteMin + ", noteMax : " + mention.noteMax + ", mention : " + mention.mention + ". nouvelle noteMin : " + newMention.noteMin + ", nouvelle noteMax : " + newMention.noteMax + ", nouvelle mention : " + newMention.mention); return(true); } return(false); }
// supprimer une Mention public bool supprinerMention(MentionBE mention) { if (mentionDA.supprimer(mention)) { journalDA.journaliser("suppression de la mention de noteMin : " + mention.noteMin + ", noteMax : " + mention.noteMax + ", mention : " + mention.mention); return(true); } return(false); }
//creer une Mention public bool creerMention(int id, double noteMin, double noteMax, String mention) { MentionBE m = new MentionBE(id, noteMin, noteMax, mention); if (mentionDA.ajouter(m)) { journalDA.journaliser("enregistrement d'une mention de noteMin : " + noteMin + ", noteMax : " + noteMax + ", mention : " + mention); return(true); } return(false); }
// Fonction permettant de remplir le DataGrid avec les informations de la base de données // @param : - listObjet : la liste des objets à afficher dans le DataGrid public void RemplirDataGrid(List <MentionBE> listObjet) { // Ajout de données dans la DataTable : var table = new DataTable(); table.Columns.Add(new DataColumn("idMention", typeof(string))); table.Columns.Add(new DataColumn("noteMin", typeof(string))); table.Columns.Add(new DataColumn("noteMax", typeof(string))); table.Columns.Add(new DataColumn("mention", typeof(string))); if (listObjet != null) { for (int i = 0; i < listObjet.Count; i++) { DataRow dr = table.NewRow(); dr["idMention"] = listObjet.ElementAt(i).idMention; dr["noteMin"] = listObjet.ElementAt(i).noteMin; dr["noteMax"] = listObjet.ElementAt(i).noteMax; dr["mention"] = listObjet.ElementAt(i).mention; table.Rows.Add(dr); } } int vId = 0; double vNoteMin = 0; double vNoteMax = 0; string vMention = ""; ListeMentions.Clear(); foreach (DataRow row in table.Rows) { vId = Convert.ToInt16(row["idMention"]); vNoteMin = Convert.ToDouble(row["noteMin"]); vNoteMax = Convert.ToDouble(row["noteMax"]); vMention = Convert.ToString(row["mention"]); MentionBE mention = new MentionBE(vId, vNoteMin, vNoteMax, vMention); ListeMentions.Add(mention); } grdListeMention.ItemsSource = ListeMentions; }
private void grdListeMention_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (grdListeMention.SelectedIndex != -1) { if (grdListeMention.SelectedIndex == ListeMentions.Count - 1) { oldMention = ListeMentions.ElementAt(grdListeMention.SelectedIndex); txtNoteMin.Text = Convert.ToString(oldMention.noteMin); txtNoteMax.Text = Convert.ToString(oldMention.noteMax); txtMention.Text = oldMention.mention; etat = 1; } else { MessageBox.Show("Impossible de modifier cet élément ! \n \n Vous ne pouvez modifier que le dernier élément de la liste !"); } grdListeMention.UnselectAll(); } }
private void cmdAjouter_Click(object sender, RoutedEventArgs e) { if ((txtNoteMin.Text != null && txtNoteMax.Text != null && txtMention.Text != null) && (txtNoteMin.Text != "" && txtNoteMax.Text != "" && txtMention.Text != "")) { MentionBE mention = new MentionBE(0, Convert.ToDouble(txtNoteMin.Text), Convert.ToDouble(txtNoteMax.Text), txtMention.Text); if (etat == 1) { //modification //on vérifit si la noteMin est égale à la noteMax du dernier élément dans la liste if (LMention != null) { if (LMention.Count == 0) { definirMentionBL.creerMention(mention.idMention, mention.noteMin, mention.noteMax, mention.mention); txtNoteMin.Text = ""; txtNoteMax.Text = ""; txtMention.Text = ""; etat = 0; } else { int nb = LMention.Count; //le nombre d'élèment dans la liste if (mention.noteMin == LMention.ElementAt(nb - 2).noteMax) { definirMentionBL.modifierMention(oldMention, mention); txtNoteMin.Text = ""; txtNoteMax.Text = ""; txtMention.Text = ""; etat = 0; } else { MessageBox.Show("Echec : 'Note Min' doit être égale à 'Note Max' du dernier enregistrement ! \n Soit : " + LMention.ElementAt(nb - 2).noteMax); } } } else { definirMentionBL.creerMention(mention.idMention, mention.noteMin, mention.noteMax, mention.mention); txtNoteMin.Text = ""; txtNoteMax.Text = ""; txtMention.Text = ""; etat = 0; } } else //ajout //on vérifit si la noteMin est égale à la noteMax du dernier élément dans la liste { if (LMention != null) { if (LMention.Count == 0) { definirMentionBL.creerMention(mention.idMention, mention.noteMin, mention.noteMax, mention.mention); txtNoteMin.Text = ""; txtNoteMax.Text = ""; txtMention.Text = ""; etat = 0; } else { int nb = LMention.Count; //le nombre d'élèment dans la liste if (mention.noteMin == LMention.ElementAt(nb - 1).noteMax) { definirMentionBL.creerMention(mention.idMention, mention.noteMin, mention.noteMax, mention.mention); txtNoteMin.Text = ""; txtNoteMax.Text = ""; txtMention.Text = ""; etat = 0; } else { MessageBox.Show("Echec : 'Note Min' doit être égale à 'Note Max' du dernier enregistrement ! \n Soit : " + LMention.ElementAt(nb - 1).noteMax); } } } else { definirMentionBL.creerMention(mention.idMention, mention.noteMin, mention.noteMax, mention.mention); txtNoteMin.Text = ""; txtNoteMax.Text = ""; txtMention.Text = ""; etat = 0; } } //on charge la liste des mentions deja défines dans le dataGrid List <MentionBE> ListMention = definirMentionBL.listerToutesLesMentions(); RemplirDataGrid(ListMention); LMention = ListMention; } }
// rechercher une Mention public MentionBE rechercherMention(MentionBE mention) { return(mentionDA.rechercher(mention)); }