diff --git a/Business/Manager.cs b/Business/Manager.cs index 2bfcaf4..78db1cd 100644 --- a/Business/Manager.cs +++ b/Business/Manager.cs @@ -197,5 +197,15 @@ namespace Business } return nvReq; } + + public bool verifierRequin(string nom, string nomSci, string description, string photo, string video, string photoCarte) + { + if (string.IsNullOrWhiteSpace(nom) || string.IsNullOrWhiteSpace(nomSci) || string.IsNullOrWhiteSpace(description) || string.IsNullOrWhiteSpace(photo) + || string.IsNullOrWhiteSpace(video) || string.IsNullOrWhiteSpace(photoCarte)) + { + return false; + } + return true; + } } } \ No newline at end of file diff --git a/Modèle/Conservation.cs b/Modèle/Conservation.cs index de1bac8..66405ca 100644 --- a/Modèle/Conservation.cs +++ b/Modèle/Conservation.cs @@ -21,4 +21,6 @@ namespace Modèle DD, NE } + + } diff --git a/Modèle/Requin.cs b/Modèle/Requin.cs index bc4ca4c..2ad495e 100644 --- a/Modèle/Requin.cs +++ b/Modèle/Requin.cs @@ -63,43 +63,6 @@ namespace Modèle } - public void ModiferRequin(string description, string photo, string video, string photoCarte, Conservation statutCons, List repartition, string funFact) - { - if (! string.IsNullOrWhiteSpace(description)) - { - Description = description; - } - if(! string.IsNullOrWhiteSpace(photo)) - { - Photo = photo; - } - if(!string.IsNullOrWhiteSpace(video)) - { - Video = video; - } - if (!string.IsNullOrWhiteSpace(photoCarte)) - { - Photo = photoCarte; - } - if (statutCons != Conservation.NE) - { - StatutCons = statutCons; - } - if (!string.IsNullOrWhiteSpace(funFact)) - { - FunFact = funFact; - } - if (repartition.Count()!= 0){ - Repartition.Clear(); - foreach(Zone z in repartition) - { - Repartition.Add(z); - } - } - } - - - public bool Equals(Requin r) { @@ -120,39 +83,5 @@ namespace Modèle } - - } - - - /* - public List RechercheParNom(List requins, string rech) - { - List nvRequins = new List(); - foreach (Requin req in requins) - { - if (req.Nom.StartsWith(rech) || req.NomSci.StartsWith(rech)) - { - nvRequins.Add(req); - } - } - return nvRequins; - } - - public List RechercheParZone(List requins, Zone zone) - { - List nvRequins = new List(); - foreach (Requin req in requins) - { - foreach (Zone laZone in req.Repartition) - { - if (laZone == zone) - { - nvRequins.Add(req); - break; - } - } - } - return nvRequins; } - */ } diff --git a/WpfApp1/AddAShark.xaml b/WpfApp1/AddAShark.xaml index 69e1b25..49af0b2 100644 --- a/WpfApp1/AddAShark.xaml +++ b/WpfApp1/AddAShark.xaml @@ -59,7 +59,7 @@ - + diff --git a/WpfApp1/AddAShark.xaml.cs b/WpfApp1/AddAShark.xaml.cs index d45074d..6d629f2 100644 --- a/WpfApp1/AddAShark.xaml.cs +++ b/WpfApp1/AddAShark.xaml.cs @@ -33,7 +33,18 @@ namespace WpfApp1 public Manager Mgr => (Application.Current as App).LeManager; - + private List consList = new List + { + Conservation.EX, + Conservation.EW, + Conservation.CR, + Conservation.EN, + Conservation.VU, + Conservation.NT, + Conservation.LC, + Conservation.DD, + Conservation.NE + }; private void exit_Click(object sender, RoutedEventArgs e) @@ -55,52 +66,30 @@ namespace WpfApp1 string fun = funny.LeContenu.Text; - if (ex.IsChecked==true) - { - cons = Conservation.EX; - testCons++; - } - else if (ew.IsChecked == true) - { - cons = Conservation.EW; - testCons++; - } - else if (cr.IsChecked == true) - { - cons = Conservation.CR; - testCons++; - } - else if (en.IsChecked == true) - { - cons = Conservation.EN; - testCons++; - } - else if (vu.IsChecked == true) - { - cons = Conservation.VU; - testCons++; - } - else if (nt.IsChecked == true) + foreach (Control control in this.radioButtons.Children) { - cons = Conservation.NT; - testCons++; - } - else if (lc.IsChecked == true) - { - cons = Conservation.LC; - } - else if (dd.IsChecked == true) - { - cons = Conservation.DD; - testCons++; - } - else if (ne.IsChecked == true) - { - cons = Conservation.NE; - testCons++; + if (control is RadioButton) + { + RadioButton radio = control as RadioButton; + if (radio.IsChecked == true) + { + if (radio.Content is string radString) + { + foreach (Conservation conserv in consList) + { + if (radString == conserv.ToString()) + { + cons = conserv; + goto loopEnd; + } + } + } + } + } } + loopEnd: + - if (Arct.IsChecked == true) { @@ -121,9 +110,8 @@ namespace WpfApp1 if (testCons == 0 || lesZones.Count() == 0 || string.IsNullOrWhiteSpace(nom) || string.IsNullOrWhiteSpace(sciNam) || string.IsNullOrWhiteSpace(descri) || string.IsNullOrWhiteSpace(photo) || string.IsNullOrWhiteSpace(video) || string.IsNullOrWhiteSpace(map) || string.IsNullOrWhiteSpace(fun)) - - { - return; + { + return; } else { diff --git a/WpfApp1/App.xaml.cs b/WpfApp1/App.xaml.cs index 4ae0600..aedfbdc 100644 --- a/WpfApp1/App.xaml.cs +++ b/WpfApp1/App.xaml.cs @@ -17,8 +17,8 @@ namespace WpfApp1 { public static IPersistanceManager strat { get; private set; } = new DataContractPersistance(); - public Manager LeManager { get; private set; } = new Manager(strat); - public ManagerUsers LeManagerUsers { get; private set; } = new ManagerUsers(strat); + public Manager LeManager { get; private set; } = new Manager(new StubLib.Stub()); + public ManagerUsers LeManagerUsers { get; private set; } = new ManagerUsers(new StubLib.Stub()); public void Temp() { @@ -35,5 +35,6 @@ namespace WpfApp1 LeManagerUsers.Pers = new DataContractPersistance(); LeManagerUsers.SaveUsers(); } + } } diff --git a/WpfApp1/CreerCompte.xaml.cs b/WpfApp1/CreerCompte.xaml.cs index 749fb30..6d6ac05 100644 --- a/WpfApp1/CreerCompte.xaml.cs +++ b/WpfApp1/CreerCompte.xaml.cs @@ -49,6 +49,10 @@ namespace WpfApp1 { MessageBox.Show("Les mots de passe doivent être identiques"); } + if (string.IsNullOrWhiteSpace(mail) && string.IsNullOrWhiteSpace(password)) + { + MessageBox.Show("Veuillez remplir toutes les cases"); + } else { Utilisateur user = new Utilisateur(mail, password); diff --git a/WpfApp1/DescriptionAdd.xaml.cs b/WpfApp1/DescriptionAdd.xaml.cs index 2b9b462..6a5fd66 100644 --- a/WpfApp1/DescriptionAdd.xaml.cs +++ b/WpfApp1/DescriptionAdd.xaml.cs @@ -67,11 +67,13 @@ namespace WpfApp1 { Mgr.AjouterRequin(requin); Mgr.SupprimerRequinAdd(requin); + Close(); } private void refuser_Click(object sender, RoutedEventArgs e) { Mgr.SupprimerRequinAdd(requin); + Close(); } } diff --git a/WpfApp1/MainWindow.xaml.cs b/WpfApp1/MainWindow.xaml.cs index 954d505..68c9716 100644 --- a/WpfApp1/MainWindow.xaml.cs +++ b/WpfApp1/MainWindow.xaml.cs @@ -42,14 +42,16 @@ namespace WpfApp1 DataContext = Mgr; - chargerUC(); - } - - + Mgr.Requins.CollectionChanged += Requins_CollectionChanged; + } + private void Requins_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + { + chargerUC(); + } private void Region_SelectionChanged(object sender, SelectionChangedEventArgs e) { diff --git a/WpfApp1/UserControlEdit.xaml b/WpfApp1/UserControlEdit.xaml index 66a3736..b325439 100644 --- a/WpfApp1/UserControlEdit.xaml +++ b/WpfApp1/UserControlEdit.xaml @@ -62,7 +62,7 @@ - + diff --git a/WpfApp1/UserControlEdit.xaml.cs b/WpfApp1/UserControlEdit.xaml.cs index ccc63db..d18b3a5 100644 --- a/WpfApp1/UserControlEdit.xaml.cs +++ b/WpfApp1/UserControlEdit.xaml.cs @@ -25,14 +25,15 @@ namespace WpfApp1 public UserControlEdit() { InitializeComponent(); - Manager.LoadRequins(); - DataContext = Manager; + DataContext = Mgr; } - public Manager Manager => (Application.Current as App).LeManager; - public ManagerUsers ManagerUser => (Application.Current as App).LeManagerUsers; + + + public Manager Mgr => (Application.Current as App).LeManager; + public ManagerUsers MgrUser => (Application.Current as App).LeManagerUsers; private Requin _requin; public Requin requin @@ -46,6 +47,18 @@ namespace WpfApp1 } + private List consList = new List + { + Conservation.EX, + Conservation.EW, + Conservation.CR, + Conservation.EN, + Conservation.VU, + Conservation.NT, + Conservation.LC, + Conservation.DD, + Conservation.NE + }; @@ -58,42 +71,25 @@ namespace WpfApp1 LienVid.Contenu = requin.Video; LienMap.Contenu = requin.PhotoCarte; funFact.Contenu = requin.FunFact; - if (requin.StatutCons == Conservation.EX) - { - ex.IsChecked = true; - } - else if (requin.StatutCons == Conservation.EW) - { - ew.IsChecked = true; - } - else if (requin.StatutCons == Conservation.CR) - { - cr.IsChecked = true; - } - else if (requin.StatutCons == Conservation.EN) - { - en.IsChecked = true; - } - else if (requin.StatutCons == Conservation.VU) - { - vu.IsChecked = true; - } - else if (requin.StatutCons == Conservation.NT) - { - nt.IsChecked = true; - } - else if (requin.StatutCons == Conservation.LC) - { - lc.IsChecked = true; - } - else if (requin.StatutCons == Conservation.DD) - { - dd.IsChecked = true; - } - else if (requin.StatutCons == Conservation.NE) + + + foreach (Control control in this.radioButtons.Children) { - ne.IsChecked = true; + if (control is RadioButton) + { + RadioButton radio = control as RadioButton; + if (radio.Content is string radString) + { + if (radString == requin.StatutCons.ToString()) + { + radio.IsChecked = true; + goto loopEnd; + } + } + } } + loopEnd: + foreach (Zone z in requin.Repartition) { @@ -123,6 +119,7 @@ namespace WpfApp1 private void submit_Click(object sender, RoutedEventArgs e) { + int test = 0; List lesZones = new List(); Conservation cons = new Conservation(); string nom = leNom.LeContenu.Text; @@ -133,73 +130,69 @@ namespace WpfApp1 string map = LienMap.LeContenu.Text; string fun = funFact.LeContenu.Text; - if (ex.IsChecked == true) + foreach (Control control in this.radioButtons.Children) { - cons = Conservation.EX; - } - else if (ew.IsChecked == true) - { - cons = Conservation.EW; - } - else if (cr.IsChecked == true) - { - cons = Conservation.CR; - } - else if (en.IsChecked == true) - { - cons = Conservation.EN; - } - else if (vu.IsChecked == true) - { - cons = Conservation.VU; - } - else if (nt.IsChecked == true) - { - cons = Conservation.NT; - } - else if (lc.IsChecked == true) - { - cons = Conservation.LC; - } - else if (dd.IsChecked == true) - { - cons = Conservation.DD; - } - else if (ne.IsChecked == true) - { - cons = Conservation.NE; + if (control is RadioButton) + { + RadioButton radio = control as RadioButton; + if (radio.IsChecked == true) + { + if (radio.Content is string radString) + { + foreach (Conservation conserv in consList) + { + if (radString == conserv.ToString()) + { + cons = conserv; + goto loopEnd ; + } + } + } + } + } } + loopEnd: if (Arct.IsChecked == true) { + test++; lesZones.Add(Zone.ARCTIQUE); } if (Atla.IsChecked == true) { + test++; lesZones.Add(Zone.ATLANTIQUE); } if (Indi.IsChecked == true) { + test++; lesZones.Add(Zone.INDIEN); } if (Paci.IsChecked == true) { + test++; lesZones.Add(Zone.PACIFIQUE); } + if (test == 0 || lesZones==null || Mgr.verifierRequin(nom, sciNam, descri, photo, video, map)==false) + { + MessageBox.Show("Veuillez remplir tout les champs obligatoires"); + } + else if (string.IsNullOrWhiteSpace(fun)) + { + Requin req = new Requin(nom, sciNam, descri, photo, video, map, cons, lesZones, fun); + Mgr.AjouterRequinEdit(req); + } + else + { + Requin req = new Requin(nom, sciNam, descri, photo, video, map, cons, lesZones, fun); + Mgr.AjouterRequinEdit(req); + } - Requin requin = new Requin(nom, sciNam, descri, photo, video, map, cons, lesZones, fun); + - foreach (Requin req in Manager.Requins) - { - if (req.Equals(requin)) - { - Manager.ModifieRequin(req, requin); - break; - } - } ((MainWindow)System.Windows.Application.Current.MainWindow).ContentControlSwapDes(requin); } diff --git a/WpfApp1/userControlAcceuil.xaml.cs b/WpfApp1/userControlAcceuil.xaml.cs index 9ad785c..8f80bf0 100644 --- a/WpfApp1/userControlAcceuil.xaml.cs +++ b/WpfApp1/userControlAcceuil.xaml.cs @@ -39,6 +39,9 @@ namespace WpfApp1 private void add_Click(object sender, RoutedEventArgs e) { + var addSharkWindow = new AddAShark(); + addSharkWindow.ShowDialog(); + /* if (MgrUser.SelectedUser == null) { MessageBox.Show("Vous avez besoin d'être connecté pour accéder à cette fonctionnalité"); @@ -55,6 +58,7 @@ namespace WpfApp1 var validerSumbit = new ValiderSubmit(); validerSumbit.ShowDialog(); } + */ } diff --git a/WpfApp1/userControlDescription.xaml.cs b/WpfApp1/userControlDescription.xaml.cs index 7fe8635..2b5a348 100644 --- a/WpfApp1/userControlDescription.xaml.cs +++ b/WpfApp1/userControlDescription.xaml.cs @@ -50,6 +50,8 @@ namespace WpfApp1 private void edit_Click(object sender, RoutedEventArgs e) { + ((MainWindow)System.Windows.Application.Current.MainWindow).ContentControlSwapEdit(requin); + /* if (MgrUser.SelectedUser == null) { MessageBox.Show("Vous avez besoin d'être connecté pour accéder à cette fonctionnalité"); @@ -60,6 +62,7 @@ namespace WpfApp1 { ((MainWindow)System.Windows.Application.Current.MainWindow).ContentControlSwapEdit(requin); } + */ }