async void OnDeleteButtonClicked(object sender, EventArgs e)
        {
            Cattle cattle = (Cattle)BindingContext;
            await App.CattleDatabase.DeleteCattleAsync(cattle);

            await Navigation.PopModalAsync();

            instance = null;
        }
Beispiel #2
0
 async void OnButtonAddClicked(object sender, EventArgs e)
 {
     if (CattleDetailPage.instance == null)
     {
         CattleDetailPage.buttonDeleteVisibility = false;
         var page = new NavigationPage(CattleDetailPage.GetInstance());
         page.BarBackgroundColor = Color.FromHex("0078D7");
         await Navigation.PushModalAsync(page);
     }
 }
        async void OnDeleteButtonClicked(object sender, EventArgs e)
        {
            Animal animal = (Animal)BindingContext;
            await manager.Delete(animal.id);

            //Cattle cattle = (Cattle)BindingContext;
            //await App.CattleDatabase.DeleteCattleAsync(cattle);
            await Navigation.PopModalAsync();

            instance = null;
        }
Beispiel #4
0
 async void OnItemEditClicked(object sender, EventArgs e)
 {
     if (CattleDetailPage.instance == null && listViewCattle.SelectedItem != null)
     {
         CattleDetailPage.buttonDeleteVisibility = true;
         var page = new NavigationPage(CattleDetailPage.GetInstance());
         page.BarBackgroundColor = Color.FromHex("0078D7");
         page.BindingContext     = App.SelectedAnimal;
         await Navigation.PushModalAsync(page);
     }
 }
        public static CattleDetailPage GetInstance()
        {
            lock (_lock)
            {
                if (instance == null)
                {
                    instance = new CattleDetailPage();
                }

                return(instance);
            }
        }
Beispiel #6
0
 async void OnButtonAddClicked(object sender, EventArgs e)
 {
     if (CattleDetailPage.instance == null)
     {
         CattleDetailPage.buttonDeleteVisibility = false;
         var page = new NavigationPage(CattleDetailPage.GetInstance());
         page.BarBackgroundColor = Color.FromHex("0078D7");
         MessagingCenter.Send(GenerateNewAnimalId(), "AddItem");
         await Navigation.PushModalAsync(page);
     }
     //if (CattleDetailPage.instance == null)
     //{
     //    CattleDetailPage.buttonDeleteVisibility = false;
     //    var page = new NavigationPage(CattleDetailPage.GetInstance());
     //    page.BarBackgroundColor = Color.FromHex("0078D7");
     //    await Navigation.PushModalAsync(page);
     //}
 }
        async void OnSaveButtonClicked(object sender, EventArgs e)
        {
            if (!identifierValidator.IsValid)
            {
                entryIdentifier.Focus();
                labelErrorIdentifier.IsVisible = true;
                return;
            }

            float weight;

            float.TryParse(entryWeight.Text, out weight);

            if (!string.IsNullOrWhiteSpace(entryID.Text))
            {
                await App.CattleDatabase.SaveCattleAsync(new Cattle
                {
                    ID         = int.Parse(entryID.Text),
                    Identifier = entryIdentifier.Text,
                    Specie     = (Specie)pickerSpecieSelectedIndex,
                    BirthDate  = datePickerBirthdate.Date,
                    Sex        = (Enums.Sex)pickerSexSelectedIndex,
                    //Weight = float.Parse(entryWeight.Text,System.Globalization.NumberStyles.Float),
                    Weight = weight,
                });
            }
            else
            {
                await App.CattleDatabase.SaveCattleAsync(new Cattle
                {
                    Identifier = entryIdentifier.Text,
                    Specie     = (Specie)pickerSpecieSelectedIndex,
                    BirthDate  = datePickerBirthdate.Date,
                    Sex        = (Enums.Sex)pickerSexSelectedIndex,
                    Weight     = weight,
                });
            }
            await Navigation.PopModalAsync();

            instance = null;
        }
        async void OnSaveButtonClicked(object sender, EventArgs e)
        {
            if (!identifierValidator.IsValid)
            {
                entryIdentifier.Focus();
                labelErrorIdentifier.IsVisible = true;
                return;
            }

            float weight;

            float.TryParse(entryWeight.Text, out weight);

            if (string.IsNullOrWhiteSpace(entryID.Text))
            {
                await manager.Add(new Animal
                {
                    id        = id,
                    type      = "Animal",
                    birthdate = new Birthdate {
                        type = "DateTime", value = datePickerBirthdate.Date.ToString("yyyy-MM-dd'T'HH:mm:ss.ff'Z'")
                    },
                    legalID = new LegalID {
                        value = entryIdentifier.Text
                    },
                    sex = new Models.Animal.Sex {
                        value = pickerSex.SelectedItem.ToString()
                    },
                    species = new Species {
                        value = pickerSpecie.SelectedItem.ToString()
                    },
                    weight = new Weight {
                        value = weight
                    }
                });
            }
            else
            {
                await manager.Update(new Animal
                {
                    id        = entryID.Text,
                    birthdate = new Birthdate {
                        type = "DateTime", value = datePickerBirthdate.Date.ToString("yyyy-MM-dd'T'HH:mm:ss.ff'Z'")
                    },
                    legalID = new LegalID {
                        value = entryIdentifier.Text
                    },
                    sex = new Models.Animal.Sex {
                        value = pickerSex.SelectedItem.ToString()
                    },
                    species = new Species {
                        value = pickerSpecie.SelectedItem.ToString()
                    },
                    weight = new Weight {
                        value = weight
                    }
                });
            }

            //if (!string.IsNullOrWhiteSpace(entryID.Text))
            //{
            //    await App.CattleDatabase.SaveCattleAsync(new Cattle
            //    {
            //        ID = int.Parse(entryID.Text),
            //        Identifier = entryIdentifier.Text,
            //        Specie = (Specie)pickerSpecieSelectedIndex,
            //        BirthDate = datePickerBirthdate.Date,
            //        Sex = (Enums.Sex)pickerSexSelectedIndex,
            //        //Weight = float.Parse(entryWeight.Text,System.Globalization.NumberStyles.Float),
            //        Weight = weight,
            //    });
            //}
            //else
            //{
            //    await App.CattleDatabase.SaveCattleAsync(new Cattle
            //    {
            //        Identifier = entryIdentifier.Text,
            //        Specie = (Specie)pickerSpecieSelectedIndex,
            //        BirthDate = datePickerBirthdate.Date,
            //        Sex = (Enums.Sex)pickerSexSelectedIndex,
            //        Weight = weight,
            //    });
            //}
            await Navigation.PopModalAsync();

            instance = null;
        }
        async void OnCancelButtonClicked(object sender, EventArgs e)
        {
            await Navigation.PopModalAsync();

            instance = null;
        }
 protected override bool OnBackButtonPressed()
 {
     instance = null;
     return(base.OnBackButtonPressed());
 }