| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using Xamarin.Forms;
- using XF.Material.Forms.UI;
- using XF.Material.Forms.UI.Dialogs;
- using System.Threading.Tasks;
- namespace PRS.Mobile
- {
- public delegate void ExitWarehousingSelectedEvent();
- public partial class WarehouseSelectionPage
- {
- public event ExitWarehousingSelectedEvent OnExitSelected;
- #region Fields
- List<ProductShell> productShells = new List<ProductShell>();
- bool productsLoaded = false;
- bool loadedFromProducts = false;
- ScannerPage _scannerpage = null;
- Guid _warehouseid = Guid.Empty;
- String _warehousename = "Select Warehouse";
- Guid _areaid = Guid.Empty;
- String _areaname = "Select Area";
- Guid _locationid = Guid.Empty;
- String _locationname = "Select Location";
- bool _istransient = false;
- StockHoldingPage _holdingpage = null;
- Job job = new Job();
- #endregion
- #region Constructors
- public WarehouseSelectionPage() //(Employee employee)
- {
- InitializeComponent();
- AddToolbarItems();
- }
- public WarehouseSelectionPage(string locationCode) //For loading from Products Module
- {
- loadedFromProducts = true;
- InitializeComponent();
- AddToolbarItems();
- LoadFromProductsModule(locationCode);
- UpdateScreen();
- }
- private void AddToolbarItems()
- {
- Title = "Warehousing";
- NavigationPage.SetHasBackButton(this, false);
- ToolbarItems.Clear();
- ToolbarItems.Add(new ToolbarItem("Exit", "", () =>
- {
- OnExitSelected?.Invoke();
- Navigation.PopAsync();
- }));
- ToolbarItems.Add(new ToolbarItem("Back", "", () =>
- {
- Navigation.PopAsync();
- }));
- }
- #endregion
- #region OnAppearing and Update Screen
- protected override void OnAppearing()
- {
- base.OnAppearing();
- if (_scannerpage != null)
- _scannerpage = null;
- if (_holdingpage != null)
- _holdingpage = null;
- UpdateScreen();
- }
- private void UpdateScreen()
- {
- Warehouse.Text = _warehousename;
- Warehouse.SetValue(Grid.ColumnSpanProperty, _warehouseid == Guid.Empty ? 3 : 2);
- Warehouse.Margin = new Thickness(10, 10, _warehouseid == Guid.Empty ? 5 : 0, 0);
- Warehouse_Clear.IsVisible = _warehouseid != Guid.Empty;
- Warehouse_Clear.Margin = new Thickness(0, 10, 5, 0);
- Area.Text = _areaname;
- Area.SetValue(Grid.ColumnSpanProperty, _areaid == Guid.Empty ? 3 : 2);
- Area.Margin = new Thickness(10, 0, _areaid == Guid.Empty ? 5 : 0, 0);
- Area_Clear.IsVisible = _areaid != Guid.Empty;
- Area_Clear.Margin = new Thickness(0, 0, 5, 0);
- Location_New.IsVisible = (_areaid != Guid.Empty) && (_locationid == Guid.Empty);
- Location_New.Margin = new Thickness(10, 0, 0, 0);
- Location.Text = _locationname;
- Location.SetValue(Grid.ColumnProperty, (_areaid != Guid.Empty) && (_locationid == Guid.Empty) ? 1 : 0);
- Location.SetValue(Grid.ColumnSpanProperty, _locationid != Guid.Empty ? 2 : _areaid != Guid.Empty ? 2 : 3);
- Location.Margin = new Thickness(Location_New.IsVisible ? 0 : 10, 0, _locationid == Guid.Empty ? 5 : 0, 0);
- Location_Clear.IsVisible = _locationid != Guid.Empty;
- Location_Clear.Margin = new Thickness(0, 0, 5, 0);
- ReceiveGrid.Opacity = _locationid != Guid.Empty ? 1.0F : 0.3F;
- IssueGrid.Opacity = _locationid != Guid.Empty ? 1.0F : 0.3F;
- MoveGrid.Opacity = _locationid != Guid.Empty ? 1.0F : 0.3F;
- TransferGrid.Opacity = _locationid != Guid.Empty ? 1.0F : 0.3F;
- StocktakeGrid.Opacity = _locationid != Guid.Empty ? 1.0F : 0.3F;
- }
- void LoadFromProductsModule(string locationCode)
- {
- CoreTable table = new Client<StockLocation>().Query(
- new Filter<StockLocation>(x => x.Code).IsEqualTo(locationCode),
- new Columns<StockLocation>(
- x => x.ID,
- x => x.Description,
- x => x.Area.Warehouse.ID,
- x => x.Area.Warehouse.Description,
- x => x.Area.ID,
- x => x.Area.Description
- ),
- null
- );
- if (table.Rows.Any())
- {
- CoreRow row = table.Rows.FirstOrDefault();
- StockLocation location = row.ToObject<StockLocation>();
- _warehouseid = location.Area.Warehouse.ID;
- _warehousename = location.Area.Warehouse.Description;
- _areaid = location.Area.ID;
- _areaname = location.Area.Description;
- _locationid = location.ID;
- _locationname = location.Description;
- }
- }
- #endregion
- #region Warehouse/Area/Location buttons clicked
- void Warehouse_Clicked(System.Object sender, System.EventArgs e)
- {
- GenericSelectionPage page = new GenericSelectionPage(
- "Select Warehouse",
- new SelectionViewModel<StockWarehouse>(
- new Filter<StockWarehouse>(X => X.Active).IsEqualTo(true),
- new Expression<Func<StockWarehouse, object>>[] { X => X.Description },
- new Expression<Func<StockWarehouse, object>>[] { },
- new SortOrder<StockWarehouse>(x => x.Description)
- )
- );
- page.OnItemSelected += (o,e) =>
- {
- var warehouse = e.Row.ToObject<StockWarehouse>();
- if (_warehouseid != warehouse.ID)
- {
- _warehouseid = warehouse.ID;
- _warehousename = warehouse.Description;
- _areaid = Guid.Empty;
- _areaname = "Select Area";
- _locationid = Guid.Empty;
- _locationname = "Select Location";
- }
- };
- Navigation.PushAsync(page);
- }
- void Area_Clicked(System.Object sender, System.EventArgs e)
- {
- Filter<StockArea> areafilter = new Filter<StockArea>(X => X.Active).IsEqualTo(true);
- if (_warehouseid != Guid.Empty)
- areafilter = areafilter.And(x => x.Warehouse.ID).IsEqualTo(_warehouseid);
- GenericSelectionPage page = new GenericSelectionPage(
- "Select Area",
- new SelectionViewModel<StockArea>(
- areafilter,
- new Expression<Func<StockArea, object>>[] { X => X.Description },
- new Expression<Func<StockArea, object>>[] { x => x.Warehouse.ID, x => x.Warehouse.Description },
- new SortOrder<StockArea>(x => x.Description)
- )
- );
- page.OnItemSelected += (o,e) =>
- {
- var area = e.Row.ToObject<StockArea>();
- if (_areaid != area.ID)
- {
- _warehouseid = area.Warehouse.ID;
- _warehousename = area.Warehouse.Description;
- _areaid = area.ID;
- _areaname = area.Description;
- _locationid = Guid.Empty;
- _locationname = "Select Location";
- }
- };
- Navigation.PushAsync(page);
- }
- void Location_Clicked(System.Object sender, System.EventArgs e)
- {
- Filter<StockLocation> filter = new Filter<StockLocation>(X => X.Active).IsEqualTo(true);
- if (_warehouseid != Guid.Empty)
- filter = filter.And(x => x.Warehouse.ID).IsEqualTo(_warehouseid);
- if (_areaid != Guid.Empty)
- filter = filter.And(x => x.Area.ID).IsEqualTo(_areaid);
- GenericSelectionPage page = new GenericSelectionPage(
- "Select Location",
- new SelectionViewModel<StockLocation>(
- filter,
- new Expression<Func<StockLocation, object>>[] { x => x.Code, X => X.Description },
- new Expression<Func<StockLocation, object>>[] { x => x.Area.Warehouse.ID, x => x.Area.Warehouse.Description, x => x.Area.ID, x => x.Area.Description,
- x => x.Job.ID, x => x.Job.JobNumber, x => x.Job.Name},
- new SortOrder<StockLocation>(x => x.Description)
- )
- );
- page.OnItemSelected += (o,e) =>
- {
- var location = e.Row.ToObject<StockLocation>();
- if (_locationid != location.ID)
- {
- _warehouseid = location.Area.Warehouse.ID;
- _warehousename = location.Area.Warehouse.Description;
- _areaid = location.Area.ID;
- _areaname = location.Area.Description;
- _locationid = location.ID;
- _locationname = location.Description;
- job.ID = location.Job.ID;
- job.JobNumber = location.Job.JobNumber;
- job.Name = location.Job.Name;
- }
- };
- Navigation.PushAsync(page);
- }
- #endregion
- #region Scanner
- void Scan_Clicked(System.Object sender, System.EventArgs e)
- {
- _scannerpage = new ScannerPage();
- _scannerpage.ItemScanned = async (args) => OnScan(args);
- Navigation.PushModalAsync(_scannerpage);
- }
- private async void OnScan(ScannerPageItemScannedArgs args)
- {
- if (Guid.TryParse(args.Text, out Guid id))
- {
- CoreTable result = new Client<StockLocation>().Query(
- new Filter<StockLocation>(X => X.ID).IsEqualTo(id),
- new Columns<StockLocation>(
- x => x.Warehouse.ID,
- X => X.Warehouse.Description,
- X => X.Area.ID,
- X => X.Area.Description,
- x => x.ID,
- X => X.Description,
- x => x.Type
- )
- );
- if (result.Rows.Any())
- {
- CoreRow r = result.Rows.First();
- _warehouseid = r.Get<StockLocation, Guid>(c => c.Warehouse.ID);
- _warehousename = r.Get<StockLocation, String>(c => c.Warehouse.Description);
- _areaid = r.Get<StockLocation, Guid>(c => c.Area.ID);
- _areaname = r.Get<StockLocation, String>(c => c.Area.Description);
- _locationid = r.Get<StockLocation, Guid>(c => c.ID);
- _locationname = r.Get<StockLocation, String>(c => c.Description);
- _istransient = r.Get<StockLocation, StockLocationType>(x => x.Type) == StockLocationType.Transient;
- }
- }
- }
-
- #endregion
- #region Holding Page Load Types
- async void LoadHoldingPage(StockMovementBatchType type)
- {
- if (_locationid == Guid.Empty)
- return;
- var progress = await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading Stock Holding");
- _holdingpage = new StockHoldingPage(_locationid, _locationname, _istransient, type, job);
- await progress.DismissAsync();
- await Navigation.PushAsync(_holdingpage);
- }
- async void ReceiveTapped(System.Object sender, System.EventArgs e)
- {
- LoadHoldingPage(StockMovementBatchType.Receipt);
- }
- async void StockTakeTapped(System.Object sender, System.EventArgs e)
- {
- LoadHoldingPage(StockMovementBatchType.Stocktake);
- }
- async void IssueTapped(System.Object sender, System.EventArgs e)
- {
- LoadHoldingPage(StockMovementBatchType.Issue);
- }
- async void TransferTapped(System.Object sender, System.EventArgs e)
- {
- LoadHoldingPage(StockMovementBatchType.Transfer);
- }
- #endregion
- #region Warehouse/Area/Location Clear buttons
- void Warehouse_Clear_Clicked(System.Object sender, System.EventArgs e)
- {
- _warehouseid = Guid.Empty;
- _warehousename = "Select Warehouse";
- _areaid = Guid.Empty;
- _areaname = "Select Area";
- _locationid = Guid.Empty;
- _locationname = "Select Location";
- UpdateScreen();
- }
- void Area_Clear_Clicked(System.Object sender, System.EventArgs e)
- {
- _areaid = Guid.Empty;
- _areaname = "Select Area";
- _locationid = Guid.Empty;
- _locationname = "Select Location";
- UpdateScreen();
- }
- void Location_Clear_Clicked(System.Object sender, System.EventArgs e)
- {
- _locationid = Guid.Empty;
- _locationname = "Select Location";
- UpdateScreen();
- }
- #endregion
- #region Change/new Stock Location
- void NewLocationClicked(System.Object sender, System.EventArgs e)
- {
- StockLocation location = new StockLocation();
- location.Active = true;
- location.Warehouse.ID = _warehouseid;
- location.Warehouse.Description = _warehousename;
- location.Area.Warehouse.ID = _warehouseid;
- location.Area.Warehouse.Description = _warehousename;
- location.Area.ID = _areaid;
- location.Area.Description = _areaname;
- LocationDetailsPage page = new LocationDetailsPage(location);
- page.OnSave += (o, loc) =>
- {
- if (String.IsNullOrWhiteSpace(loc.Code))
- {
- MaterialDialog.Instance.AlertAsync(message: "Code may not be blank!");
- return false;
- }
- if (String.IsNullOrWhiteSpace(loc.Description))
- {
- MaterialDialog.Instance.AlertAsync(message: "Description may not be blank!");
- return false;
- }
- if (loc.Area.ID == Guid.Empty)
- {
- MaterialDialog.Instance.AlertAsync(message: "Area may not be blank!");
- return false;
- }
- CoreTable others = new Client<StockLocation>().Query(
- new Filter<StockLocation>(x => x.Code).IsEqualTo(loc.Code).And(x => x.ID).IsNotEqualTo(loc.ID),
- new Columns<StockLocation>(x => x.ID)
- );
- if (others.Rows.Any())
- {
- MaterialDialog.Instance.AlertAsync(message: "Location Code already exists!");
- return false;
- }
- try
- {
- new Client<StockLocation>().Save(loc, "Created Location");
- }
- catch (Exception err)
- {
- MaterialDialog.Instance.AlertAsync(message: "Unable to save Location\n" + err.Message);
- return false;
- }
- _warehouseid = loc.Area.Warehouse.ID;
- _warehousename = loc.Area.Warehouse.Description;
- _areaid = loc.Area.ID;
- _areaname = loc.Area.Description;
- _locationid = loc.ID;
- _locationname = loc.Description;
- try
- {
- job.ID = loc.Job.ID;
- job.JobNumber = loc.Job.JobNumber;
- job.Name = loc.Job.Name;
- }
- catch { }
- return true;
- };
- Navigation.PushAsync(page);
- }
- void MoveLocation(System.Object sender, System.EventArgs e)
- {
- if (_locationid == Guid.Empty)
- return;
- Filter<StockArea> areafilter = new Filter<StockArea>(X => X.Active).IsEqualTo(true);
- GenericSelectionPage page = new GenericSelectionPage(
- "Move Stock Location to:",
- new SelectionViewModel<StockArea>(
- areafilter,
- new Expression<Func<StockArea, object>>[] { X => X.Description },
- new Expression<Func<StockArea, object>>[] { x => x.Warehouse.ID, x => x.Warehouse.Description },
- new SortOrder<StockArea>(x => x.Description)
- )
- );
- page.OnItemSelected += async (o,e) =>
- {
- var area = e.Row.ToObject<StockArea>();
- if (_areaid != area.ID)
- {
- string chosenOption = await DisplayActionSheet("Change this Location Area?", "Cancel", null, "Yes", "No");
- switch (chosenOption)
- {
- case "No":
- break;
- case "Cancel":
- break;
- case "Yes":
- StockLocation location = new StockLocation();
- location.ID = _locationid;
- location.Area.ID = area.ID;
- location.Warehouse.ID = area.Warehouse.ID;
- new Client<StockLocation>().Save(location, "Updated Stock Area", (o, err) => { });
- _warehouseid = area.Warehouse.ID;
- _warehousename = area.Warehouse.Description;
- _areaid = area.ID;
- _areaname = area.Description;
- UpdateScreen();
- break;
- default:
- break;
- }
- }
- };
- Navigation.PushAsync(page);
- }
- #endregion
- void Find_Clicked(object sender, EventArgs e)
- {
- if (loadedFromProducts)
- {
- Navigation.PopAsync();
- }
- else
- {
- if (App.Data.Products.Loaded)
- {
- ProductList2 products = new ProductList2();
- products.OnExitSelected += () =>
- {
- Navigation.PopAsync();
- };
- Navigation.PushAsync(products);
- }
- else
- {
- ProductList2 products = new ProductList2();
- products.OnExitSelected += () =>
- {
- Navigation.PopAsync();
- };
- Navigation.PushAsync(products);
- }
- }
- }
- //being replaced
- //void Find_Clicked(System.Object sender, System.EventArgs e)
- //{
- // GenericSelectionPage products = new GenericSelectionPage(
- // "Select Product",
- // new SelectionViewModel<Product>(
- // new Filter<Product>(X => X.Expired).IsEqualTo(DateTime.MinValue),
- // new Expression<Func<Product, object>>[] { X => X.Code, X => X.Name },
- // new Expression<Func<Product, object>>[] { },
- // new SortOrder<Product>(x => x.Code)
- // )
- // );
- // products.AutoClose = false;
- // products.OnItemSelected += (p) =>
- // {
- // var product = p.ToObject<Product>();
- // GenericSelectionPage holdings = new GenericSelectionPage(
- // "Select Stock Holding",
- // new SelectionViewModel<StockHolding>(
- // new Filter<StockHolding>(X => X.Product.ID).IsEqualTo(product.ID),
- // new Expression<Func<StockHolding, object>>[] { },
- // new Expression<Func<StockHolding, object>>[] {
- // X => X.Location.Area.Warehouse.ID,
- // x=>x.Location.Area.Warehouse.Code,
- // x=>x.Location.Area.Warehouse.Description,
- // x => x.Location.Area.ID,
- // x=>x.Location.Area.Code,
- // x=>x.Location.Area.Description,
- // x => x.Location.ID,
- // x=>x.Location.Code,
- // x=>x.Location.Description,
- // x=>x.Style.Code,
- // x=>x.Units
- // },
- // new SortOrder<StockHolding>(x => x.Location.Area.Warehouse.Code).ThenBy(x=>x.Location.Area.Code).ThenBy(x=>x.Location.Code),
- // (r) => String.Format("{0} {1}: {2} ({3} {4})",
- // r.Get<StockHolding, String>(x => x.Location.Area.Warehouse.Code),
- // r.Get<StockHolding, String>(x => x.Location.Area.Code),
- // r.Get<StockHolding, String>(x => x.Location.Code),
- // r.Get<StockHolding, double>(x => x.Units),
- // r.Get<StockHolding, String>(x => x.Style.Code)
- // )
- // )
- // );
- // holdings.OnItemSelected += (h) =>
- // {
- // var holding = h.ToObject<StockHolding>();
- // _warehouseid = holding.Location.Area.Warehouse.ID;
- // _warehousename = holding.Location.Area.Warehouse.Description;
- // _areaid = holding.Location.Area.ID;
- // _areaname = holding.Location.Area.Description;
- // _locationid = holding.Location.ID;
- // _locationname = holding.Location.Description;
- // // Close the Product Page as well :=)
- // Navigation.PopAsync();
- // };
- // Navigation.PushAsync(holdings);
- // };
- // Navigation.PushAsync(products);
- //}
- }
- }
|