You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.6 KiB

using Model;
using Persistance;
namespace Views;
public partial class DetailAnimal : ContentPage
{
public DetailAnimal()
{
InitializeComponent();
BindingContext = (App.Current as App).AnimalSelectionner;
Picker_especes.BindingContext = (App.Current as App).Theque;
if((App.Current as App).AnimalSelectionner.Espece != null)
{
if ((App.Current as App).AnimalSelectionner.Race != null)
{
PetAdvice.BindingContext = (App.Current as App).AnimalSelectionner.Race;
}
else PetAdvice.BindingContext = (App.Current as App).AnimalSelectionner.Espece;
}
}
public async void Button_OnClick(object sender, EventArgs e)
{
(App.Current as App).Theque.SupprimerAnimal((App.Current as App).AnimalSelectionner);
DataSerializerXML.Serializer((App.Current as App).SerializationPath, (App.Current as App).Theque);
await Shell.Current.GoToAsync("//Animaux");
}
private void EspeceClic(object sender, EventArgs e)
{
(App.Current as App).AnimalSelectionner.Espece = (sender as Picker).SelectedItem as Espece;
(App.Current as App).AnimalSelectionner.Race = null;
}
private void RaceClic(object sender, EventArgs e)
{
(App.Current as App).AnimalSelectionner.Race = (sender as Picker).SelectedItem as Race;
}
private void SexeClick(object sender, EventArgs e)
{
(App.Current as App).AnimalSelectionner.Sexe = (sender as Picker).SelectedItem as string;
}
public async void TakePhoto(object sender, EventArgs e)
{
if (MediaPicker.Default.IsCaptureSupported)
{
FileResult photo = await MediaPicker.Default.PickPhotoAsync();
if (photo != null)
{
string localFilePath = Path.Combine(FileSystem.AppDataDirectory, photo.FileName);
using Stream sourceStream = await photo.OpenReadAsync();
using FileStream localFileStream = File.OpenWrite(localFilePath);
await sourceStream.CopyToAsync(localFileStream);
(App.Current as App).AnimalSelectionner.Image = Path.Combine(FileSystem.AppDataDirectory, photo.FileName);
}
}
}
protected override bool OnBackButtonPressed()
{
if((App.Current as App).AnimalSelectionner.NomIsValid == true)
{
DataSerializerXML.Serializer((App.Current as App).SerializationPath, (App.Current as App).Theque);
return base.OnBackButtonPressed();
}
return true;
}
}