123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Comal.Classes;
- using InABox.Configuration;
- using InABox.Core;
- using InABox.Mobile;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace PRS.Mobile
- {
- public class ConsignmentModuleSettings : ILocalConfigurationSettings
- {
- public String FilterName { get; set; }
- }
-
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class ConsignmentsModule : MobilePage
- {
- private ConsignmentModuleSettings _settings;
-
- private CoreFilterDefinitions _filters;
- private ConsignmentModel _consignments = new ConsignmentModel(App.Data, () => null) { FileName = "consignments.index" };
-
- public ConsignmentsModule()
- {
- Task[] _setup = new Task[]
- {
- Task.Run(() => { _settings = new LocalConfiguration<ConsignmentModuleSettings>().Load(); }),
- Task.Run(() => { _filters = _consignments.AvailableFilters(); }),
- };
- InitializeComponent();
-
- Task.WaitAll(_setup);
-
- SetupFilters();
- }
- private void SetupFilters()
- {
- _filter.Items.Clear();
- foreach (var group in _filters)
- {
- var item = new MobileMenuItem() { Text = group.Name };
- item.Clicked += (sender, args) =>
- {
- var text = (sender as MobileMenuItem)?.Text ?? string.Empty;
- _settings.FilterName = text;
- new LocalConfiguration<ConsignmentModuleSettings>().Save(_settings);
- RefreshData(true, false);
- };
- _filter.Items.Add(item);
- }
- _filter.IsVisible = _filter.Items.Any();
- }
- private void RefreshData(bool force, bool async)
- {
- _consignments.SelectFilter(_settings.FilterName);
- if (async)
- {
- _consignments.Refresh(force, () => Device.BeginInvokeOnMainThread(Refresh));
- }
- else
- {
- _consignments.Refresh(true);
- Refresh();
- }
- }
-
- private void Refresh()
- {
- _consignmentlist.LastUpdated = _consignments.LastUpdated;
- Title = String.IsNullOrWhiteSpace(_settings.FilterName) ? "All Consignments" : _settings.FilterName;
- _consignments.Search(FilterShell);
- _consignmentlist.ItemsSource = _consignments.Items;
- }
- private string _currentfilter = "";
- private bool FilterShell(ConsignmentShell shell)
- {
- if (String.IsNullOrWhiteSpace(_currentfilter))
- return true;
- return shell.Number.ToUpper().Contains(_currentfilter.ToUpper())
- || shell.SupplierName.ToUpper().Contains(_currentfilter.ToUpper())
- || shell.TypeDescription.ToUpper().Contains(_currentfilter.ToUpper());
- }
-
- private void _search_OnTextChanged(object sender, MobileSearchBarTextChangedArgs args)
- {
- _currentfilter = args.Text;
- Refresh();
- }
-
- private void MobileList_OnRefresh(object sender, MobileListRefreshEventArgs args)
- {
- RefreshData(true, false);
- }
-
- private void Consignment_Clicked(object sender, EventArgs e)
- {
- if ((sender as MobileCard)?.BindingContext is ConsignmentShell shell)
- {
- var editor = new ConsignmentEdit(shell);
- Navigation.PushAsync(editor);
- }
- }
-
- private ConsignmentShell? _newshell;
-
- protected override void OnAppearing()
- {
- base.OnAppearing();
- if ((_newshell != null) && (_newshell.ID != Guid.Empty))
- _consignments.CommitItem(_newshell);
- _newshell = null;
- RefreshData(true, false);
- }
-
- private void AddConsignment_Clicked(object sender, MobileMenuButtonClickedEventArgs args)
- {
- ShowPopup(() => SelectionView.Execute<PurchaseOrderShell>(
- (columns) =>
- {
- columns.Add(new MobileGridTextColumn<PurchaseOrderShell>()
- {
- Column = x => x.PONumber,
- Width = GridLength.Auto,
- Caption = "Number",
- Alignment = TextAlignment.Start
- });
- columns.Add(new MobileGridTextColumn<PurchaseOrderShell>()
- {
- Column = x => x.SupplierName,
- Width = GridLength.Star,
- Caption = "Select Purchase Order",
- Alignment = TextAlignment.Start
- });
- },
- (refresh) =>
- {
- var model = new PurchaseOrderModel(App.Data,
- () => new Filter<PurchaseOrder>(x => x.IssuedDate).IsNotEqualTo(DateTime.MinValue)
- .And(x=>x.ClosedDate).IsEqualTo(DateTime.MinValue)
- .And(x=>x.CancelledDate).IsEqualTo(DateTime.MinValue)
- .And(x=>x.Unreceived).IsNotEqualTo(FilterConstant.Null)) { FileName = "consigment_orders.index" };
- return model.Refresh(false);
- },
- (orders) =>
- {
-
- _newshell = _consignments.CreateItem();
- Navigation.PushAsync(new ConsignmentEdit(_newshell));
-
-
- var model = new PurchaseOrderItemModel(App.Data,
- () => new Filter<PurchaseOrderItem>(x => x.PurchaseOrderLink.ID).IsEqualTo(orders.FirstOrDefault()?.ID ?? Guid.Empty));
- model.Refresh(false);
- foreach (var item in model.Items)
- {
- var newitem = ViewModel.Items.AddItem();
- newitem.Row.LoadValues(item.Row.Values);
- }
- Dispatcher.BeginInvokeOnMainThread(() =>
- {
- _itemsList.ItemsSource = null;
- _itemsList.ItemsSource = ViewModel.Items;
- });
- DismissPopup();
- }));
-
- }
- }
- }
|