using Comal.Classes; using InABox.Clients; using InABox.Core; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using XF.Material.Forms.UI.Dialogs; namespace comal.timesheets { public class JobFormsGrid : MobileDataGrid { Guid JobID = Guid.Empty; public JobFormsGrid(Guid jobid, DataGridSaveType savetype) { JobID = jobid; OnItemSelected += JobFormsGrid_OnItemSelected; LoadItems(savetype); } private object JobFormsGrid_OnItemSelected(DataGridViewModelItem item) { return null; } private void LoadItems(DataGridSaveType savetype) { Task.Run(async () => { using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading")) { CoreTable table = DoQuery(); while (table == null) table = DoQuery(); if (!table.Rows.Any()) return; List shells = new List(); foreach (CoreRow row in table.Rows) { List> tuples = new List> { new Tuple("Name", row.Get(x => x.Form.Description)), new Tuple("Started", row.Get(x => x.FormStarted).ToString("dd MMM yy")), new Tuple("Completed", row.Get(x => x.FormCompleted) == DateTime.MinValue? " " : row.Get(x => x.FormCompleted).ToString("dd MMM yy")), new Tuple("User", row.Get(x => x.FormCompletedBy.UserID)) }; shells.Add(new DataGridViewModelItem ( id: row.Get(x => x.ID), data: tuples )); } Setup(shells, typeof(JobForm), savetype); } }); } private CoreTable DoQuery() { try { return new Client().Query( new Filter(x => x.Parent.ID).IsEqualTo(JobID), new Columns( x => x.ID, x => x.FormCompleted, x => x.Form.Description, x => x.FormCompletedBy.UserID, x => x.FormStarted, x => x.Form.ID )); } catch (Exception ex) { MobileLogging.Log(LogType.Query, "Job Forms Grid", ex.Message + ex.StackTrace, this.GetType().Name); return null; } } } }