Changements des if dans edit et add a shark pour que ce soit des boucles (c'est plus bo)

master
thchazot1 3 years ago
parent 2e8f77c413
commit cec8973b0c

@ -197,5 +197,15 @@ namespace Business
} }
return nvReq; 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;
}
} }
} }

@ -21,4 +21,6 @@ namespace Modèle
DD, DD,
NE NE
} }
} }

@ -63,43 +63,6 @@ namespace Modèle
} }
public void ModiferRequin(string description, string photo, string video, string photoCarte, Conservation statutCons, List<Zone> 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) public bool Equals(Requin r)
{ {
@ -120,39 +83,5 @@ namespace Modèle
} }
}
/*
public List<Requin> RechercheParNom(List<Requin> requins, string rech)
{
List<Requin> nvRequins = new List<Requin>();
foreach (Requin req in requins)
{
if (req.Nom.StartsWith(rech) || req.NomSci.StartsWith(rech))
{
nvRequins.Add(req);
}
}
return nvRequins;
}
public List<Requin> RechercheParZone(List<Requin> requins, Zone zone)
{
List<Requin> nvRequins = new List<Requin>();
foreach (Requin req in requins)
{
foreach (Zone laZone in req.Repartition)
{
if (laZone == zone)
{
nvRequins.Add(req);
break;
}
}
}
return nvRequins;
} }
*/
} }

@ -59,7 +59,7 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Text="Conservation" HorizontalAlignment="Center" Grid.Row="0" Foreground="{StaticResource Couleur3}"/> <TextBlock Text="Conservation" HorizontalAlignment="Center" Grid.Row="0" Foreground="{StaticResource Couleur3}"/>
</Grid> </Grid>
<Grid x:Name="radio" Grid.Column="1" Grid.Row="3" Margin="40,19,40,0" Width="320" Background="White"> <Grid x:Name="radioButtons" Grid.Column="1" Grid.Row="3" Margin="40,19,40,0" Width="320" Background="White">
<Grid.ColumnDefinitions > <Grid.ColumnDefinitions >
<ColumnDefinition/> <ColumnDefinition/>
<ColumnDefinition/> <ColumnDefinition/>

@ -33,7 +33,18 @@ namespace WpfApp1
public Manager Mgr => (Application.Current as App).LeManager; public Manager Mgr => (Application.Current as App).LeManager;
private List<Conservation> consList = new List<Conservation>
{
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) private void exit_Click(object sender, RoutedEventArgs e)
@ -55,50 +66,28 @@ namespace WpfApp1
string fun = funny.LeContenu.Text; string fun = funny.LeContenu.Text;
if (ex.IsChecked==true) foreach (Control control in this.radioButtons.Children)
{
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)
{
cons = Conservation.NT;
testCons++;
}
else if (lc.IsChecked == true)
{ {
cons = Conservation.LC; if (control is RadioButton)
} {
else if (dd.IsChecked == true) RadioButton radio = control as RadioButton;
{ if (radio.IsChecked == true)
cons = Conservation.DD; {
testCons++; if (radio.Content is string radString)
} {
else if (ne.IsChecked == true) foreach (Conservation conserv in consList)
{ {
cons = Conservation.NE; if (radString == conserv.ToString())
testCons++; {
cons = conserv;
goto loopEnd;
}
}
}
}
}
} }
loopEnd:
@ -121,9 +110,8 @@ namespace WpfApp1
if (testCons == 0 || lesZones.Count() == 0 || string.IsNullOrWhiteSpace(nom) || string.IsNullOrWhiteSpace(sciNam) || string.IsNullOrWhiteSpace(descri) 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)) || string.IsNullOrWhiteSpace(photo) || string.IsNullOrWhiteSpace(video) || string.IsNullOrWhiteSpace(map) || string.IsNullOrWhiteSpace(fun))
{
{ return;
return;
} }
else else
{ {

@ -17,8 +17,8 @@ namespace WpfApp1
{ {
public static IPersistanceManager strat { get; private set; } public static IPersistanceManager strat { get; private set; }
= new DataContractPersistance(); = new DataContractPersistance();
public Manager LeManager { get; private set; } = new Manager(strat); public Manager LeManager { get; private set; } = new Manager(new StubLib.Stub());
public ManagerUsers LeManagerUsers { get; private set; } = new ManagerUsers(strat); public ManagerUsers LeManagerUsers { get; private set; } = new ManagerUsers(new StubLib.Stub());
public void Temp() public void Temp()
{ {
@ -35,5 +35,6 @@ namespace WpfApp1
LeManagerUsers.Pers = new DataContractPersistance(); LeManagerUsers.Pers = new DataContractPersistance();
LeManagerUsers.SaveUsers(); LeManagerUsers.SaveUsers();
} }
} }
} }

@ -49,6 +49,10 @@ namespace WpfApp1
{ {
MessageBox.Show("Les mots de passe doivent être identiques"); MessageBox.Show("Les mots de passe doivent être identiques");
} }
if (string.IsNullOrWhiteSpace(mail) && string.IsNullOrWhiteSpace(password))
{
MessageBox.Show("Veuillez remplir toutes les cases");
}
else else
{ {
Utilisateur user = new Utilisateur(mail, password); Utilisateur user = new Utilisateur(mail, password);

@ -67,11 +67,13 @@ namespace WpfApp1
{ {
Mgr.AjouterRequin(requin); Mgr.AjouterRequin(requin);
Mgr.SupprimerRequinAdd(requin); Mgr.SupprimerRequinAdd(requin);
Close();
} }
private void refuser_Click(object sender, RoutedEventArgs e) private void refuser_Click(object sender, RoutedEventArgs e)
{ {
Mgr.SupprimerRequinAdd(requin); Mgr.SupprimerRequinAdd(requin);
Close();
} }
} }

@ -42,14 +42,16 @@ namespace WpfApp1
DataContext = Mgr; DataContext = Mgr;
chargerUC(); 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) private void Region_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {

@ -62,7 +62,7 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Text="Conservation" HorizontalAlignment="Center" Grid.Row="0" Foreground="{StaticResource Couleur3}"/> <TextBlock Text="Conservation" HorizontalAlignment="Center" Grid.Row="0" Foreground="{StaticResource Couleur3}"/>
</Grid> </Grid>
<Grid Grid.Column="1" Grid.Row="3" Margin="40,19,40,0" Width="320" Background="White"> <Grid Grid.Column="1" Grid.Row="3" Margin="40,19,40,0" Width="320" Background="White" x:Name="radioButtons">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition/> <ColumnDefinition/>
<ColumnDefinition/> <ColumnDefinition/>

@ -25,14 +25,15 @@ namespace WpfApp1
public UserControlEdit() public UserControlEdit()
{ {
InitializeComponent(); 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; private Requin _requin;
public Requin requin public Requin requin
@ -46,6 +47,18 @@ namespace WpfApp1
} }
private List<Conservation> consList = new List<Conservation>
{
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; LienVid.Contenu = requin.Video;
LienMap.Contenu = requin.PhotoCarte; LienMap.Contenu = requin.PhotoCarte;
funFact.Contenu = requin.FunFact; funFact.Contenu = requin.FunFact;
if (requin.StatutCons == Conservation.EX)
{
ex.IsChecked = true; foreach (Control control in this.radioButtons.Children)
}
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)
{ {
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) foreach (Zone z in requin.Repartition)
{ {
@ -123,6 +119,7 @@ namespace WpfApp1
private void submit_Click(object sender, RoutedEventArgs e) private void submit_Click(object sender, RoutedEventArgs e)
{ {
int test = 0;
List<Zone> lesZones = new List<Zone>(); List<Zone> lesZones = new List<Zone>();
Conservation cons = new Conservation(); Conservation cons = new Conservation();
string nom = leNom.LeContenu.Text; string nom = leNom.LeContenu.Text;
@ -133,73 +130,69 @@ namespace WpfApp1
string map = LienMap.LeContenu.Text; string map = LienMap.LeContenu.Text;
string fun = funFact.LeContenu.Text; string fun = funFact.LeContenu.Text;
if (ex.IsChecked == true) foreach (Control control in this.radioButtons.Children)
{ {
cons = Conservation.EX; if (control is RadioButton)
} {
else if (ew.IsChecked == true) RadioButton radio = control as RadioButton;
{ if (radio.IsChecked == true)
cons = Conservation.EW; {
} if (radio.Content is string radString)
else if (cr.IsChecked == true) {
{ foreach (Conservation conserv in consList)
cons = Conservation.CR; {
} if (radString == conserv.ToString())
else if (en.IsChecked == true) {
{ cons = conserv;
cons = Conservation.EN; goto loopEnd ;
} }
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;
} }
loopEnd:
if (Arct.IsChecked == true) if (Arct.IsChecked == true)
{ {
test++;
lesZones.Add(Zone.ARCTIQUE); lesZones.Add(Zone.ARCTIQUE);
} }
if (Atla.IsChecked == true) if (Atla.IsChecked == true)
{ {
test++;
lesZones.Add(Zone.ATLANTIQUE); lesZones.Add(Zone.ATLANTIQUE);
} }
if (Indi.IsChecked == true) if (Indi.IsChecked == true)
{ {
test++;
lesZones.Add(Zone.INDIEN); lesZones.Add(Zone.INDIEN);
} }
if (Paci.IsChecked == true) if (Paci.IsChecked == true)
{ {
test++;
lesZones.Add(Zone.PACIFIQUE); 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); ((MainWindow)System.Windows.Application.Current.MainWindow).ContentControlSwapDes(requin);
} }

@ -39,6 +39,9 @@ namespace WpfApp1
private void add_Click(object sender, RoutedEventArgs e) private void add_Click(object sender, RoutedEventArgs e)
{ {
var addSharkWindow = new AddAShark();
addSharkWindow.ShowDialog();
/*
if (MgrUser.SelectedUser == null) if (MgrUser.SelectedUser == null)
{ {
MessageBox.Show("Vous avez besoin d'être connecté pour accéder à cette fonctionnalité"); MessageBox.Show("Vous avez besoin d'être connecté pour accéder à cette fonctionnalité");
@ -55,6 +58,7 @@ namespace WpfApp1
var validerSumbit = new ValiderSubmit(); var validerSumbit = new ValiderSubmit();
validerSumbit.ShowDialog(); validerSumbit.ShowDialog();
} }
*/
} }

@ -50,6 +50,8 @@ namespace WpfApp1
private void edit_Click(object sender, RoutedEventArgs e) private void edit_Click(object sender, RoutedEventArgs e)
{ {
((MainWindow)System.Windows.Application.Current.MainWindow).ContentControlSwapEdit(requin);
/*
if (MgrUser.SelectedUser == null) if (MgrUser.SelectedUser == null)
{ {
MessageBox.Show("Vous avez besoin d'être connecté pour accéder à cette fonctionnalité"); 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); ((MainWindow)System.Windows.Application.Current.MainWindow).ContentControlSwapEdit(requin);
} }
*/
} }

Loading…
Cancel
Save