using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Comal.Classes; using InABox.Clients; using InABox.Core; using Xamarin.Forms; using Xamarin.Forms.Xaml; using ZXing.PDF417.Internal; using static comal.timesheets.RequiItems; namespace comal.timesheets.StoreRequis { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class StoreRequiList : ContentPage { List requiShells = new List(); public StoreRequiList() { InitializeComponent(); LoadHoldingsCache(); if (Device.RuntimePlatform.Equals(Device.iOS)) { imageBtn0.Margin = new Thickness(0); imageBtn0.VerticalOptions = LayoutOptions.FillAndExpand; imageBtn0.HeightRequest = 160; takerequinow.Margin = new Thickness(0); takerequinow.VerticalOptions = LayoutOptions.FillAndExpand; takerequinow.HeightRequest = 160; storereqimg.Margin = new Thickness(0); storereqimg.HeightRequest = 120; } } protected override void OnAppearing() { LoadList(); base.OnAppearing(); } private async void LoadList() { await Task.Run(() => { requiShells.Clear(); CoreTable table = new Client().Query( new Filter(x => x.Filled).IsEqualTo(DateTime.MinValue), new Columns( x => x.ID, //0 x => x.Number, //1 x => x.Due, //2 x => x.RequestedBy.Name, //3 x => x.JobLink.JobNumber, //4 x => x.JobLink.Name, //5 x => x.Request //6 ), new SortOrder(x => x.Due) ); foreach (var row in table.Rows) { List list = row.Values; if (list[0] == null) { list[0] = Guid.Empty; } //0 if (list[1] == null) { list[1] = 0; } //1 if (list[2] == null) { list[2] = DateTime.MinValue; } //2 if (list[3] == null) { list[3] = ""; } //3 if (list[4] == null) { list[4] = ""; } //4 if (list[5] == null) { list[5] = ""; } //5 if (list[6] == null) { list[6] = ""; } //6 RequiShell requiShell = new RequiShell(); requiShell.ID = Guid.Parse(list[0].ToString()); requiShell.Number = "No. " + list[1].ToString(); requiShell.Due = "Due " + DateTime.Parse(list[2].ToString()).ToString("dd MMM yy"); requiShell.Contact = "Contact: " + list[3].ToString(); requiShell.Job = "(" + list[4].ToString() + ") " + list[5].ToString(); requiShell.Request = list[6].ToString(); requiShells.Add(requiShell); } Device.BeginInvokeOnMainThread(() => { requisListView.ItemsSource = null; requisListView.ItemsSource = requiShells; listLbl.Text = "List of Unfilled Requis (" + requiShells.Count + ")"; }); }); } private void Requi_Clicked(object sender, EventArgs e) { RequiShell requiShell = requisListView.SelectedItem as RequiShell; StoreRequiScannerPage storeRequiScannerPage = new StoreRequiScannerPage(requiShell.ID); Navigation.PushAsync(storeRequiScannerPage); } private void TakeStockNow_Tapped(object sender, EventArgs e) { StoreRequiScannerPage page = new StoreRequiScannerPage(Guid.Empty); Navigation.PushAsync(page); } private void NewRequiRequest_Tapped(object sender, EventArgs e) { StoreRequiConfirmationPage storeRequiConfirmationPage = new StoreRequiConfirmationPage(); Navigation.PushAsync(storeRequiConfirmationPage); } #region Utilities private async void LoadHoldingsCache() { await Task.Run(() => { holdingsCache = new List(); CoreTable table = new Client().Query( new Filter(x => x.Qty).IsGreaterThan(0), new Columns( x => x.ID, x => x.Product.ID, x => x.Location.ID, x => x.Location.Description, x => x.Units, x => x.Job.ID, x => x.Job.JobNumber, x => x.Job.Name, x => x.Style.ID, x => x.Style.Code, x => x.Style.Description, x => x.Dimensions.Unit.ID, x => x.Dimensions.Unit.HasQuantity, x => x.Dimensions.Unit.HasLength, x => x.Dimensions.Unit.HasHeight, x => x.Dimensions.Unit.HasWeight, x => x.Dimensions.Unit.HasWidth, x => x.Dimensions.Quantity, x => x.Dimensions.Length, x => x.Dimensions.Height, x => x.Dimensions.Weight, x => x.Dimensions.Width, x => x.Dimensions.Unit.Format, x => x.Dimensions.Unit.Formula, x => x.Dimensions.UnitSize ) ); foreach (CoreRow row in table.Rows) { if (row.Get(x => x.Units) == 0.0) continue; HoldingsCacheShell holding = new HoldingsCacheShell() { ProductID = row.Get(x => x.Product.ID), LocationID = row.Get(x => x.Location.ID), LocationName = row.Get(x => x.Location.Description), Units = row.Get(x => x.Units).ToString(), JobID = row.Get(x => x.Job.ID), JobNumber = row.Get(x => x.Job.JobNumber), JobName = row.Get(x => x.Job.Name), StyleID = row.Get(x => x.Style.ID), StyleCode = row.Get(x => x.Style.Code), StyleDescription = row.Get(x => x.Style.Description) }; holding.Dimensions.Unit.ID = row.Get(x => x.Dimensions.Unit.ID); holding.Dimensions.Unit.HasQuantity = row.Get(x => x.Dimensions.Unit.HasQuantity); holding.Dimensions.Unit.HasLength = row.Get(x => x.Dimensions.Unit.HasLength); holding.Dimensions.Unit.HasHeight = row.Get(x => x.Dimensions.Unit.HasHeight); holding.Dimensions.Unit.HasWeight = row.Get(x => x.Dimensions.Unit.HasWeight); holding.Dimensions.Unit.HasWidth = row.Get(x => x.Dimensions.Unit.HasWidth); holding.Dimensions.Quantity = row.Get(x => x.Dimensions.Quantity); holding.Dimensions.Length = row.Get(x => x.Dimensions.Length); holding.Dimensions.Height = row.Get(x => x.Dimensions.Height); holding.Dimensions.Weight = row.Get(x => x.Dimensions.Weight); holding.Dimensions.Width = row.Get(x => x.Dimensions.Width); holding.Dimensions.Unit.Format = row.Get(x => x.Dimensions.Unit.Format); holding.Dimensions.Unit.Formula = row.Get(x => x.Dimensions.Unit.Formula); holding.Dimensions.UnitSize = row.Get(x => x.Dimensions.UnitSize); holding.LocationName = holding.LocationName + " (Units: " + holding.Units + ")" + Environment.NewLine + "Style: " + holding.StyleDescription + Environment.NewLine + "Job: " + holding.JobNumber + Environment.NewLine + "Size: " + holding.Dimensions.UnitSize; holdingsCache.Add(holding); } ; RequiItems.HoldingsLoaded = true; }); } #endregion } public class RequiShell { public Guid ID { get; set; } public string Number { get; set; } public string Due { get; set; } public string Contact { get; set; } public string Job { get; set; } public string Request { get; set; } public RequiShell() { ID = Guid.Empty; Number = ""; Due = ""; Due = ""; Job = ""; Request = ""; } } }