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 comal.timesheets.Products; using System.Threading.Tasks; using Xamarin.Forms.Xaml; namespace comal.timesheets { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class RelocatePage : BasePage { Guid _warehouseid = Guid.Empty; String _warehousename = "Select Warehouse"; Guid _areaid = Guid.Empty; String _areaname = "Select Area / Rack"; Guid _locationid = Guid.Empty; String _locationname = "Select Location / Pack"; Job job = new Job(); public RelocatePage() { InitializeComponent(); } protected override void OnAppearing() { base.OnAppearing(); UpdateScreen(); } private void Relocate_Clicked(object sender, EventArgs e) { if (_locationid == Guid.Empty) return; Filter areafilter = new Filter(X => X.Active).IsEqualTo(true); GenericSelectionPage page = new GenericSelectionPage( "Move Stock Location to:", new SelectionViewModel( areafilter, new Expression>[] { X => X.Description }, new Expression>[] { x => x.Warehouse.ID, x => x.Warehouse.Description }, new SortOrder(x => x.Description) ) ); page.OnItemSelected += async (row) => { var area = row.ToObject(); if (_areaid != area.ID) { string chosenOption = await DisplayActionSheet("Change this Location's 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().Save(location, "Updated Stock Area", (o, err) => { }); _warehouseid = area.Warehouse.ID; _warehousename = area.Warehouse.Description; _areaid = area.ID; _areaname = area.Description; UpdateScreen(); await warehouseBtn.TranslateTo(0, -15, 150); await warehouseBtn.TranslateTo(0, 0, 150); await areaBtn.TranslateTo(0, -15, 150); await areaBtn.TranslateTo(0, 0, 150); await locationBtn.TranslateTo(0, -15, 150); await locationBtn.TranslateTo(0, 0, 150); break; default: break; } } }; Navigation.PushAsync(page); } #region Warehouse/Area/Location buttons clicked void Warehouse_Clicked(System.Object sender, System.EventArgs e) { GenericSelectionPage page = new GenericSelectionPage( "Select Warehouse", new SelectionViewModel( new Filter(X => X.Active).IsEqualTo(true), new Expression>[] { X => X.Description }, new Expression>[] { }, new SortOrder(x => x.Description) ) ); page.OnItemSelected += (row) => { var warehouse = row.ToObject(); 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 areafilter = new Filter(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( areafilter, new Expression>[] { X => X.Description }, new Expression>[] { x => x.Warehouse.ID, x => x.Warehouse.Description }, new SortOrder(x => x.Description) ) ); page.OnItemSelected += (row) => { var area = row.ToObject(); 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 filter = new Filter(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( filter, new Expression>[] { x => x.Code, X => X.Description }, new Expression>[] { 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(x => x.Description) ) ); page.OnItemSelected += (row) => { var location = row.ToObject(); 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 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 private void UpdateScreen() { warehouseBtn.Text = _warehousename; warehouseBtn.SetValue(Grid.ColumnSpanProperty, _warehouseid == Guid.Empty ? 3 : 2); warehouseBtn.Margin = new Thickness(10, 10, _warehouseid == Guid.Empty ? 5 : 0, 0); warehouse_ClearBtn.IsVisible = _warehouseid != Guid.Empty; warehouse_ClearBtn.Margin = new Thickness(0, 10, 5, 0); areaBtn.Text = _areaname; areaBtn.SetValue(Grid.ColumnSpanProperty, _areaid == Guid.Empty ? 3 : 2); areaBtn.Margin = new Thickness(10, 0, _areaid == Guid.Empty ? 5 : 0, 0); area_ClearBtn.IsVisible = _areaid != Guid.Empty; area_ClearBtn.Margin = new Thickness(0, 0, 5, 0); locationBtn.Text = _locationname; locationBtn.SetValue(Grid.ColumnSpanProperty, _locationid != Guid.Empty ? 2 : 3); locationBtn.Margin = new Thickness(10, 0, _locationid == Guid.Empty ? 5 : 0, 0); location_ClearBtn.IsVisible = _locationid != Guid.Empty; location_ClearBtn.Margin = new Thickness(0, 0, 5, 0); } } }