Esempio n. 1
0
        private async void DeleteOrdeno()
        {
            var answer = await Application.Current.MainPage.DisplayAlert(Languages.Delete, Languages.DeleteConfirmation, Languages.Yes, Languages.No);

            if (!answer)
            {
                return;
            }

            var Conecction = await this.apiService.CheckConnection();

            if (!Conecction.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error, Conecction.Message, Languages.Accept);

                return;
            }

            var url        = Application.Current.Resources["UrlAPI"].ToString();
            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlOrdenosController"].ToString();
            var response   = await this.apiService.Delete(url, prefix, controller, this.OrdenoId, Settings.TokenType, Settings.AccessToken); //, Settings.TokenType, Settings.AccessToken);

            if (!response.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error, response.Message, Languages.Accept);

                return;
            }

            var ordeViewModel  = OrdeViewModel.GetInstance();
            var deleteProducto = ordeViewModel.OrdenosOVM.Where(o => o.OrdenoId == this.OrdenoId).FirstOrDefault();

            if (deleteProducto != null)
            {
                ordeViewModel.OrdenosOVM.Remove(deleteProducto);
            }

            //ordeViewModel.RefreshList();
        }
Esempio n. 2
0
        private async void Edit()
        {
            if (this.CodigoAnimal == null)
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.CodeAnimalError
                                                                , Languages.Accept);

                return;
            }
            else
            {
                this.ordeno.AnimalId = ((Ordenos)this.CodigoAnimal).AnimalId;
            }

            if (this.ordeno.NumeroOrdeno <= 0)
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.MilkingError
                                                                , Languages.Accept);

                return;
            }

            if (this.ordeno.NumeroOrdeno > 3 || this.ordeno.NumeroOrdeno < 1)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.MilkingValueError,
                    Languages.Accept);

                return;
            }

            if (this.ordeno.LitrosOrdeno <= 0)
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.MilkingLitersError
                                                                , Languages.Accept);

                return;
            }

            if (this.ordeno.LitrosOrdeno < 1)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.MilkingLitersError,
                    Languages.Accept);

                return;
            }

            if (this.ordeno.PesoOrdeno < 0)
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.MilkingWeightError
                                                                , Languages.Accept);

                return;
            }

            if (this.ordeno.GramosCuidoOrdeno < 0)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.GramsMilking,
                    Languages.Accept);

                return;
            }

            this.IsRunning = true;
            this.IsEnabled = false;

            var connection = await this.apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(Languages.Error, connection.Message, Languages.Accept);

                return;
            }

            var url        = Application.Current.Resources["UrlAPI"].ToString();
            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlOrdenosController"].ToString();
            var response   = await this.apiService.Put(url, prefix, controller, this.Ordeno, this.Ordeno.OrdenoId, Settings.TokenType, Settings.AccessToken);

            if (!response.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    response.Message,
                    Languages.Accept);

                return;
            }

            var newOrdeno        = (Ordenos)response.Result;
            var ordenosViewModel = OrdeViewModel.GetInstance();
            var oldOrdeno        = ordenosViewModel.myOrdenos.Where(p => p.OrdenoId == this.Ordeno.OrdenoId).FirstOrDefault();

            if (oldOrdeno != null)
            {
                ordenosViewModel.myOrdenos.Remove(oldOrdeno);
            }

            ordenosViewModel.myOrdenos.Add(this.Ordeno);
            ordenosViewModel.RefreshList();

            this.IsRunning = false;
            this.IsEnabled = true;
            await App.Navigator.PopAsync();

            //await App.Navigator.PopAsync();
        }
        private async void Save()
        {
            if (this.CodigoAnimal == null)
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.CodeAnimalError
                                                                , Languages.Accept);

                return;
            }

            if (String.IsNullOrEmpty(this.NumeroOrdeno))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.MilkingError
                                                                , Languages.Accept);

                return;
            }

            var numeroOrdeño = Int32.Parse(this.NumeroOrdeno);

            if (numeroOrdeño > 3 || numeroOrdeño < 1)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.MilkingValueError,
                    Languages.Accept);

                return;
            }

            if (String.IsNullOrEmpty(this.LitrosOrdeno))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.MilkingLitersError
                                                                , Languages.Accept);

                return;
            }

            Decimal litrosOrdeño = 0;

            Decimal.TryParse(this.LitrosOrdeno, out litrosOrdeño);

            if (litrosOrdeño < 1)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.MilkingLitersError,
                    Languages.Accept);

                return;
            }
            else
            {
                if (!String.IsNullOrEmpty(this.LitrosOrdenoDecimal))
                {
                    litrosOrdeño = Convert.ToDecimal(this.LitrosOrdeno + "," + this.LitrosOrdenoDecimal);
                }
            }

            if (String.IsNullOrEmpty(this.PesoOrdeno))
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.MilkingWeightError
                                                                , Languages.Accept);

                return;
            }

            var pesosOrdeño = Int32.Parse(this.PesoOrdeno);

            if (pesosOrdeño < 0)
            {
                await Application.Current.MainPage.DisplayAlert(Languages.Error
                                                                , Languages.MilkingWeightError
                                                                , Languages.Accept);

                return;
            }

            var gramosCuidoOrdeno = Int32.Parse(this.GramosCuidoOrdeno);

            if (gramosCuidoOrdeno < 0)
            {
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    Languages.GramsMilking,
                    Languages.Accept);

                return;
            }

            this.IsRunning = true;
            this.IsEnabled = false;

            var connection = await this.apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(Languages.Error, connection.Message, Languages.Accept);

                return;
            }

            var ordeno = new Ordenos
            {
                FechaOrdeno       = this.FechaOrdeno.ToUniversalTime(),
                LitrosOrdeno      = litrosOrdeño,
                NumeroOrdeno      = Convert.ToInt32(NumeroOrdeno),
                PesoOrdeno        = pesosOrdeño,
                GramosCuidoOrdeno = gramosCuidoOrdeno,
                AnimalId          = ((Ordenos)CodigoAnimal).AnimalId,
            };

            var url        = Application.Current.Resources["UrlAPI"].ToString();
            var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
            var controller = Application.Current.Resources["UrlOrdenosController"].ToString();
            var response   = await this.apiService.Post(url, prefix, controller, ordeno, Settings.TokenType, Settings.AccessToken);

            if (!response.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert(
                    Languages.Error,
                    response.Message,
                    Languages.Accept);

                return;
            }

            var newOrdeno        = (Ordenos)response.Result;
            var ordenosViewModel = OrdeViewModel.GetInstance();

            ordenosViewModel.myOrdenos.Add(newOrdeno);
            ordenosViewModel.RefreshList();

            //ordenosViewModel.OrdenosOVM.Add(new OrdenosItemViewModel
            //{
            //    CodigoAnimal = newOrdeno.CodigoAnimal,
            //    FechaOrdeno = newOrdeno.FechaOrdeno,
            //    LitrosOrdeno = newOrdeno.LitrosOrdeno,
            //    NumeroOrdeno = newOrdeno.NumeroOrdeno,
            //    PesoOrdeno = newOrdeno.PesoOrdeno,
            //    OrdenoId = newOrdeno.OrdenoId,
            //});
            //fincasViewModel.RefreshList();

            this.IsRunning = false;
            this.IsEnabled = true;
            await App.Navigator.PopAsync();

            //await App.Navigator.PopAsync();
        }