public ProductsPage() { InitializeComponent(); SmartMarktDatabase database = new SmartMarktDatabase(); _database = database; Title = "Productos"; var Products = _database.GetProducts(); productsList = this.FindByName <ListView>("productsList"); var layoutAddButton = this.FindByName <StackLayout>("addButton"); var addButton = new ActionButton(); addButton.ButtonIcon = "Nuevo"; layoutAddButton.Children.Add(addButton); productsList.ItemsSource = Products; this.CurrentPageChanged += (sender, e) => { Refresh(); }; var aceptar = new Button { Text = "Aceptar" }; var buscar = this.FindByName <Button>("buscar"); var buscarEntry = this.FindByName <Entry>("buscarEntry"); var addEntry = new Entry(); var addBarcode = new Entry(); addButton.OnTouchesBegan += (sender, e) => { Type TargetType = typeof(FichaProducto); NavigationTo(new FichaProducto(null)); }; aceptar.Clicked += (sender, e) => { var Product = addEntry.Text; var address = addEntry.Text; long newBarCode = 0; var barCodeAdd = long.TryParse(addBarcode.Text, out newBarCode);; addEntry.Text = ""; Refresh(); returnToList(); }; buscar.Clicked += async(sender, e) => { String result = null; try { var scanner = DependencyService.Get <IQrCodeScanningService>(); result = await scanner.ScanAsync(); } catch (Exception ex) { Console.Write(ex.ToString()); } if (result != null) { buscarEntry.Text = result; } }; buscarEntry.TextChanged += (object sender, TextChangedEventArgs e) => { var newText = e.NewTextValue; long barCode = 0; long.TryParse(newText, out barCode); productsList.ItemsSource = _database.GetProduct(newText, barCode); }; var ProductEntryContentPage = new ContentPage { Padding = new Thickness(20), Content = new StackLayout { Children = { addEntry, addBarcode, aceptar } } }; Children.Add(ProductEntryContentPage); SelectedItem = Children.ElementAt <ContentPage>(0); productsList.ItemTapped += (sender, e) => { Type TargetType = typeof(FichaProducto); NavigationTo(new FichaProducto((Product)e.Item)); }; }
public FichaProducto(Product product) { InitializeComponent(); database = new SmartMarktDatabase(); if (product == null) { product = new Product(); } Title = "Editar productos"; var layoutButton = this.FindByName <StackLayout>("layoutButton"); var editButton = new ActionButton(); editButton.ButtonColor = Color.FromHex("#E91E63"); editButton.ButtonIcon = "Editar"; Entry barCodeEntry = this.FindByName <Entry>("BarCodeEntry"); barCodeEntry.IsEnabled = false; Entry nameEntry = this.FindByName <Entry>("NameEntry"); nameEntry.IsEnabled = false; Label name = new Label(); name.Text = product.name; var cerrar = new Button { Text = "Cerrar" }; cerrar.Clicked += async(sender, e) => { try { await((RootPage)App.Current.MainPage).Detail.Navigation.PopAsync(); } catch (Exception ex) { Console.Write(ex.ToString()); } }; editButton.OnTouchesBegan += (sender, e) => { BarCodeEntry.IsEnabled = !BarCodeEntry.IsEnabled; NameEntry.IsEnabled = !NameEntry.IsEnabled; PriceEntry.IsEnabled = !PriceEntry.IsEnabled; CategoryEntry.IsEnabled = !CategoryEntry.IsEnabled; FamilyEntry.IsEnabled = !FamilyEntry.IsEnabled; ValorEnergeticoEntry.IsEnabled = !ValorEnergeticoEntry.IsEnabled; GrasasSaturadasEntry.IsEnabled = !GrasasSaturadasEntry.IsEnabled; GrasasMonoinsaturadasEntry.IsEnabled = !GrasasMonoinsaturadasEntry.IsEnabled; GrasasPolisaturadasEntry.IsEnabled = !GrasasPolisaturadasEntry.IsEnabled; HidratosDeCarbonoEntry.IsEnabled = !HidratosDeCarbonoEntry.IsEnabled; HidratosDeCarbonoAzucaresEntry.IsEnabled = !HidratosDeCarbonoAzucaresEntry.IsEnabled; FibraEntry.IsEnabled = !FibraEntry.IsEnabled; ProteinasEntry.IsEnabled = !ProteinasEntry.IsEnabled; SalEntry.IsEnabled = !SalEntry.IsEnabled; if (NameEntry.IsEnabled) { editButton.ButtonIcon = "Guardar"; } else { database.AddProduct(NameEntry.Text, Convert.ToDouble(PriceEntry.Text), Convert.ToInt64(BarCodeEntry.Text)); editButton.ButtonIcon = "Editar"; } }; layoutButton.Children.Add(editButton); }