using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Comal.Classes; using InABox.Clients; using InABox.Core; using Xamarin.Forms; using Xamarin.Forms.Xaml; namespace PRS.Mobile { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class StoreRequiList { List requiShells = new List(); public StoreRequiList() { InitializeComponent(); RequiItems.HoldingsLoaded = true; 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 void LoadList() { Task.Run(() => { requiShells.Clear(); CoreTable table = DoRequisitionQuery(); while (table == null) table = DoRequisitionQuery(); foreach (var row in table.Rows) { RequiShell requiShell = new RequiShell(); requiShell.ID = row.Get(x => x.ID); requiShell.Number = "No. " + row.Get(x => x.Number); requiShell.Due = "Due " + row.Get(x => x.Due).ToString("dd MMM yy"); requiShell.Contact = "Contact: " + row.Get(x => x.RequestedBy.Name); requiShell.Job = "(" + row.Get(x => x.JobLink.JobNumber) + ") " + row.Get(x => x.JobLink.Name); requiShell.Request = row.Get(x => x.Request); string notes = CheckNotes(row.Get(x => x.Notes)); requiShell.Request = requiShell.Request + System.Environment.NewLine + notes; requiShells.Add(requiShell); } Device.BeginInvokeOnMainThread(() => { requisListView.ItemsSource = null; requisListView.ItemsSource = requiShells; listLbl.Text = "List of Unfilled Requis (" + requiShells.Count + ")"; }); }); } private CoreTable DoRequisitionQuery() { try { return new Client().Query( new Filter(x => x.Filled).IsEqualTo(DateTime.MinValue), new Columns(ColumnTypeFlags.None).Add( x => x.ID, x => x.Number, x => x.Due, x => x.RequestedBy.Name, x => x.JobLink.JobNumber, x => x.JobLink.Name, x => x.Request, x => x.Notes ), new SortOrder(x => x.Due) ); } catch (Exception ex) { InABox.Mobile.MobileLogging.Log(ex); return null; } } private string CheckNotes(string[] notes) { string combinednotes = "----------" + System.Environment.NewLine + "NOTES: " + System.Environment.NewLine; if (notes.Count() > 0) { foreach (var note in notes) { combinednotes = combinednotes + note + System.Environment.NewLine; } } return combinednotes; } 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); } } 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 = ""; } } }