123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- using comal.timesheets.Products;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- using XF.Material.Forms.UI.Dialogs;
- namespace comal.timesheets
- {
- public delegate void ProductsGridItemSelected(DataGridViewModelItem item);
- public delegate Task<string> ProductsGridShowOptions();
- public class ProductsGrid : MobileDataGrid
- {
- public event ProductsGridItemSelected ItemSelected;
- public event ProductsGridShowOptions ShowOptions;
- public ProductsGrid(DataGridSaveType savetype = DataGridSaveType.None)
- {
- OnItemSelected += ProductsGrid_OnItemSelected;
- LoadItems(savetype);
- }
- private void ProductsGrid_OnItemSelected(DataGridViewModelItem item)
- {
- ItemSelected?.Invoke(item);
- DisplayOptions(item);
- }
- private void LoadItems(DataGridSaveType savetype = DataGridSaveType.None)
- {
- Task.Run(async () =>
- {
- if (GlobalVariables.ProductsLoaded)
- {
- List<DataGridViewModelItem> shells = new List<DataGridViewModelItem>();
- foreach (var product in GlobalVariables.ProductShells)
- {
- List<Tuple<string, string>> tuples = new List<Tuple<string, string>>();
- tuples.Add(new Tuple<string, string>("Code", product.Code));
- tuples.Add(new Tuple<string, string>("Name", product.Name));
- tuples.Add(new Tuple<string, string>("Family", product.Group));
- shells.Add(new DataGridViewModelItem
- (
- id: product.ID,
- data: tuples,
- image: product.ImageID == Guid.Empty ? new Image() : new Image { Source = "productimage.png", HeightRequest = 30, WidthRequest = 30 },
- imageid: product.ImageID
- ));
- }
- Setup(shells, typeof(Product), savetype);
- }
- else
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading"))
- {
- CoreTable table = new Client<Product>().Query(null,
- new Columns<Product>(x => x.ID,
- x => x.Code,
- x => x.Name,
- x => x.Group.Description,
- x => x.Image.ID
- ));
- if (!table.Rows.Any())
- return;
- List<DataGridViewModelItem> shells = new List<DataGridViewModelItem>();
- foreach (var row in table.Rows)
- {
- List<Tuple<string, string>> tuples = new List<Tuple<string, string>>();
- tuples.Add(new Tuple<string, string>("Code", row.Get<Product, string>(x => x.Code)));
- tuples.Add(new Tuple<string, string>("Name", row.Get<Product, string>(x => x.Name)));
- tuples.Add(new Tuple<string, string>("Family", row.Get<Product, string>(x => x.Group.Description)));
- shells.Add(new DataGridViewModelItem
- (
- id: row.Get<Product, Guid>(x => x.ID),
- data: tuples,
- image: row.Get<Product, Guid>(x => x.Image.ID) == Guid.Empty ? new Image() : new Image { Source = "productimage.png", HeightRequest = 30, WidthRequest = 30 },
- imageid: row.Get<Product, Guid>(x => x.Image.ID)
- ));
- }
- Setup(shells, typeof(Product), savetype);
- }
- }
- });
- }
- public async void DisplayOptions(DataGridViewModelItem item)
- {
- ProductShell product = GlobalVariables.ProductShells.FirstOrDefault(x => x.ID == item.ID);
- ListSelectionPage page = new ListSelectionPage(new List<String> { "View Holdings", "View Movements" });
- page.OnSimpleListTapped += ((chosenOption) =>
- {
- Device.BeginInvokeOnMainThread(() =>
- {
- switch (chosenOption)
- {
- case "Cancel":
- return;
- case "View Holdings":
- HoldingViewer holdingViewer = new HoldingViewer(product.ID, product.Name, product.ImageID);
- holdingViewer.OnExitSelected += () =>
- {
- Navigation.PopAsync();
- };
- Navigation.PushAsync(holdingViewer);
- break;
- case "View Movements":
- MovementViewer movementViewer = new MovementViewer(product.ID, product.Name);
- Navigation.PushAsync(movementViewer);
- break;
- default: break;
- }
- });
- });
- Navigation.PushAsync(page);
- }
- }
- }
|