123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- 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<DataGridViewModelItem> shells = new List<DataGridViewModelItem>();
- foreach (CoreRow row in table.Rows)
- {
- List<Tuple<string, string>> tuples = new List<Tuple<string, string>>
- {
- new Tuple<string, string>("Name", row.Get<JobForm, string>(x => x.Form.Description)),
- new Tuple<string, string>("Started", row.Get<JobForm, DateTime>(x => x.FormStarted).ToString("dd MMM yy")),
- new Tuple<string, string>("Completed", row.Get<JobForm, DateTime>(x => x.FormCompleted) == DateTime.MinValue? " " : row.Get<JobForm, DateTime>(x => x.FormCompleted).ToString("dd MMM yy")),
- new Tuple<string, string>("User", row.Get<JobForm, string>(x => x.FormCompletedBy.UserID))
- };
- shells.Add(new DataGridViewModelItem
- (
- id: row.Get<JobForm, Guid>(x => x.ID),
- data: tuples
- ));
- }
- Setup(shells, typeof(JobForm), savetype);
- }
- });
- }
- private CoreTable DoQuery()
- {
- try
- {
- return new Client<JobForm>().Query(
- new Filter<JobForm>(x => x.Parent.ID).IsEqualTo(JobID),
- new Columns<JobForm>(
- 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;
- }
- }
- }
- }
|