using Comal.Classes; using InABox.Core; using InABox.Mobile; using Xamarin.Forms; using Xamarin.Forms.Xaml; namespace PRS.Mobile { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class PurchaseOrderDetails { private readonly PurchaseOrderItemModel _poitems; public PurchaseOrderDetails(PurchaseOrderShell shell) { _poitems = new PurchaseOrderItemModel(App.Data, () => new Filter(x => x.PurchaseOrderLink.ID).IsEqualTo(shell.ID) ); InitializeComponent(); Title = $"PO #{shell.PONumber}"; _items.Columns .BeginUpdate() .Clear() .Add(new MobileGridTextColumn() { Column = x => x.JobNumber, Width = GridLength.Auto, Caption = "Job" }) .Add(new MobileGridTextColumn() { Column = x => x.Description, Width = GridLength.Star, Alignment = TextAlignment.Start}) .Add(new MobileGridDoubleColumn() { Column = x => x.Qty, Width = GridLength.Auto }) .Add(new MobileGridDateColumn() { Column = x => x.ReceivedDate, Format = "dd MMM yy", Caption="Rec'd" }) .EndUpdate(); RefreshData(false, true); } private void RefreshData(bool force, bool async) { if (async) _poitems.Refresh(force, () => Dispatcher.BeginInvokeOnMainThread(Refresh)); else { _poitems.Refresh(force); Refresh(); } } private void Refresh() { _items.ItemsSource ??= _poitems.Items; } private void _items_OnRefreshRequested(object sender, MobileGridRefreshRequestArgs args) { RefreshData(true, false); } } }