private void OnAddAction(object o) { EventClick.GetClick().Handler += CloseAddView; Planete PlaneteAjout = new Planete(); add = new Fajout(PlaneteAjout); add.Name = "Ajout"; add.ShowDialog(); AlreadyExiste = false; if (add.ViewModelAjout.CLickOnAdd == true) { foreach (Planete p in Univers) { if (add.ViewModelAjout.Planete.Nom.ToLower().Equals(p.Nom.ToLower())) { AlreadyExiste = true; } } if (AlreadyExiste) { Info info = new Info("La planète fait déjà parti de l'univers et n'as donc pas été ajouté"); info.ShowDialog(); } else { string executable = System.Reflection.Assembly.GetExecutingAssembly().Location; string path = (System.IO.Path.GetDirectoryName(executable)); AppDomain.CurrentDomain.SetData("DataDirectory", path); SqlConnection conn = new SqlConnection(connectionString); conn.Open(); Planete planeteAdd = add.ViewModelAjout.Planete; string SQLcmdAdd = "INSERT INTO [UniversDATABase].[Planete] VALUES (@PNom,@PVol,@PMas,@PAnn,@PDec,@PSat,@PRev,@PIma);"; var command = new SqlCommand(SQLcmdAdd, conn); command.Parameters.AddWithValue("@PNom", planeteAdd.Nom); command.Parameters.AddWithValue("@PVol", planeteAdd.Volume); command.Parameters.AddWithValue("@PMas", planeteAdd.Masse); command.Parameters.AddWithValue("@PAnn", planeteAdd.Anneaux); command.Parameters.AddWithValue("@PDec", planeteAdd.AnnéeDecouverte); command.Parameters.AddWithValue("@PSat", planeteAdd.NbreSatellite); command.Parameters.AddWithValue("@PRev", planeteAdd.PeriodeRevo); command.Parameters.AddWithValue("@PIma", planeteAdd.PlanIm); command.ExecuteReader(); conn.Close(); NotifyPropertyChanged("Univers"); } Refresh(); } }
private void OnAddAction(object obj) { CLickOnAdd = true; if (Planete.Nom != null) { EventClick.GetClick().OnButtonPressedHandler(EventArgs.Empty); } else { Info iadd = new Info("Tous les champs doivent être completé pour ajouter une nouvelle planete"); iadd.ShowDialog(); } }
private void OnEditCommand(object o) { EventClick.GetClick().Handler += CloseEditView; edit = new Fajout(Planete); // Factorisation de code. on utilise la même fenetre que pour l'ajout de planete edit.ViewModelAjout.AddOrModify = "Valider"; // changement du contenu bouton edit.Name = "Edit"; edit.ShowDialog(); if (edit.ViewModelAjout.CLickOnAdd == true) { NotifyPropertyChanged("Planete"); Planete modifAApliquer = edit.ViewModelAjout.Planete; string executable = System.Reflection.Assembly.GetExecutingAssembly().Location; string path = (System.IO.Path.GetDirectoryName(executable)); AppDomain.CurrentDomain.SetData("DataDirectory", path); SqlConnection conn = new SqlConnection(connectionString); conn.Open(); string SQLcmdAdd = "UPDATE [UniversDATABase].[Planete] SET PlaneteVolume = @PVol,PlaneteMasse = @PMas,PlaneteAnneaux = @PAnn, PlaneteDecouverte = @PDec, PlaneteNBSat = @PSat, PlanetePeriodeRevo = @PRev, PlanetePathIm = @PIma WHERE PlaneteNom = @PNom"; var command = new SqlCommand(SQLcmdAdd, conn); command.Parameters.AddWithValue("@PNom", modifAApliquer.Nom); command.Parameters.AddWithValue("@PVol", modifAApliquer.Volume); command.Parameters.AddWithValue("@PMas", modifAApliquer.Masse); command.Parameters.AddWithValue("@PAnn", modifAApliquer.Anneaux); command.Parameters.AddWithValue("@PDec", modifAApliquer.AnnéeDecouverte); command.Parameters.AddWithValue("@PSat", modifAApliquer.NbreSatellite); command.Parameters.AddWithValue("@PRev", modifAApliquer.PeriodeRevo); command.Parameters.AddWithValue("@PIma", modifAApliquer.PlanIm); command.ExecuteReader(); conn.Close(); NotifyPropertyChanged("Planete"); NotifyPropertyChanged("Univers"); } Refresh(); }
private void OnDeleteCommand(object obj) { EventClick.GetClick().Handler += CloseBd; bd = new BoiteDeDialogue("supprimer cette planete ?"); bd.ShowDialog(); if (bd.ViewModelInfo._valid == true) { string executable = System.Reflection.Assembly.GetExecutingAssembly().Location; string path = (System.IO.Path.GetDirectoryName(executable)); AppDomain.CurrentDomain.SetData("DataDirectory", path); SqlConnection conn = new SqlConnection(connectionString); conn.Open(); string SQLcmdAdd = "DELETE FROM [UniversDATABase].[Planete] WHERE PlaneteNom = @PNom"; //test var command = new SqlCommand(SQLcmdAdd, conn); command.Parameters.AddWithValue("@PNom", Planete.Nom); command.ExecuteReader(); conn.Close(); NotifyPropertyChanged("Univers"); } Refresh(); }
private void CloseBd(object sender, EventArgs e) { bd.Close(); EventClick.GetClick().Handler -= CloseBd; }
private void CloseEditView(object sender, EventArgs e) { edit.Close(); EventClick.GetClick().Handler -= CloseEditView; }
private void CloseAddView(object sender, EventArgs e) { add.Close(); EventClick.GetClick().Handler -= CloseAddView; }
private void OnCancelCommand(object obj) { CLickOnAdd = false; // cas ou on clic sur cancel après l'affichage de iadd EventClick.GetClick().OnButtonPressedHandler(EventArgs.Empty); }
private void OnNoAction(object obj) { EventClick.GetClick().OnButtonPressedHandler(EventArgs.Empty); }
private void OnYesAction(object obj) { _valid = true; EventClick.GetClick().OnButtonPressedHandler(EventArgs.Empty); }