So that when choosing in it, they are entered into a new list in order to make calculations with them. Thank you in advance for your help

namespace Calorizator1 { public partial class App : Application { public const string DATABASE_NAME = "products.db"; public static ProductRepository database; public static ProductRepository Database { get { if (database == null) { database = new ProductRepository(DATABASE_NAME); } return database; } } public App() { InitializeComponent(); MainPage = new NavigationPage(new MainPage()); } public partial class MainPage : MasterDetailPage { public MainPage() { InitializeComponent(); } private void ButtonProductsList_Clicked(object sender, EventArgs e) { Detail = new NavigationPage(new ProductsList()); IsPresented = false; } private void ButtonCalorizator_Clicked(object sender, EventArgs e) { Detail = new NavigationPage(new MainPage()); IsPresented = false; } } namespace Calorizator1 { public partial class ProductsList: ContentPage { public ProductsList() { InitializeComponent(); ToolbarItem tb = new ToolbarItem { Text = "Добавить", Order = ToolbarItemOrder.Secondary, Priority = 0, }; tb.Clicked += async (e, c) => { Product product = new Product(); ProductPage productPage = new ProductPage { BindingContext = product }; await Navigation.PushAsync(productPage); }; ToolbarItems.Add(tb); } protected override void OnAppearing() { productsList.ItemsSource = App.Database.GetItems(); base.OnAppearing(); } //обработка нажатия элемента в списке private async void OnItemSelected(object sender, SelectedItemChangedEventArgs e) { Product selectedProduct = (Product)e.SelectedItem; ProductPage productPage = new ProductPage { BindingContext = selectedProduct }; await Navigation.PushAsync(productPage); } } } namespace Calorizator1 { [Table ("Products")] public class Product { [PrimaryKey, AutoIncrement, Column("_id")] public int Id { get; set; } public string Name { get; set; } public double Belki { get; set; } public double Ziri { get; set; } public double Ugli { get; set; } public double Calorii { get; set; } } } public partial class ProductPage : ContentPage { public ProductPage() { InitializeComponent(); } private void SaveProduct(object sender, EventArgs e) { var product = (Product)BindingContext; if (!String.IsNullOrEmpty(product.Name)) { App.Database.SaveItem(product); } this.Navigation.PopAsync(); } private void DeleteProduct(object sender, EventArgs e) { var product = (Product)BindingContext; App.Database.DeleteItem(product.Id); this.Navigation.PopAsync(); } private void Cancel(object sender, EventArgs e) { this.Navigation.PopAsync(); } } } namespace Calorizator1 { public class ProductRepository { SQLiteConnection database; public ProductRepository(string filename) { string databasePath = DependencyService.Get<ISQLite>().GetDatabasePath(filename); database = new SQLiteConnection(databasePath); database.CreateTable<Product>(); } public IEnumerable<Product> GetItems() { return (from i in database.Table<Product>() select i).ToList(); } public Product GetItem(int id) { return database.Get<Product>(id); } public int DeleteItem(int id) { return database.Delete<Product>(id); } public int SaveItem(Product item) { if (item.Id != 0) { database.Update(item); return item.Id; } else { return database.Insert(item); } } } } 
  • Give a link to the GitHub repository of this project, then I will try to help. - Bulson pm
  • Not a You've got a repository curve. My studio cannot open this solution. You are on the decision to make a right click. -> Add solution to version control. Then look at the right. Lower corner of the studio window, on the lowest bar will be an up arrow with a number, click on it and push to create a new repository. Or use the command line and launch to another new repository. - Bulson
  • Damn ... I do not understand anything. I did something and the project retired. Everything is so difficult - Vanek wow wow wow
  • Next week I will restore everything and try again - Vanek wow wow wow

0