1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using comal.timesheets.QAForms;
- using InABox.Clients;
- using InABox.Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace comal.timesheets
- {
- public class FormPickerQueryLoader<TEntity, TEntityLink, TInstance> : IFormPickerQueryLoader
- where TEntity : Entity, IRemotable, IPersistent, new()
- where TEntityLink : EntityLink<TEntity>, new()
- where TInstance : Entity, IRemotable, IPersistent, IDigitalFormInstance<TEntityLink>, new()
- {
- Filter<TInstance> incompleteFilter = new Filter<TInstance>(x => x.FormCompletedBy.ID).IsEqualTo(ClientFactory.UserGuid)
- .And(x => x.FormCompleted).IsEqualTo(DateTime.MinValue);
- Filter<TInstance> completeFilter = new Filter<TInstance>(x => x.FormCompletedBy.ID).IsEqualTo(ClientFactory.UserGuid)
- .And(x => x.FormCompleted).IsNotEqualTo(DateTime.MinValue);
- public List<ExistingFormShell> QueryIncomplete()
- {
- return DoQuery(incompleteFilter);
- }
- public List<ExistingFormShell> QueryComplete()
- {
- return DoQuery(completeFilter);
- }
- private List<ExistingFormShell> DoQuery(Filter<TInstance> filter)
- {
- List<ExistingFormShell> shells = new List<ExistingFormShell>();
- CoreTable table = new Client<TInstance>().Query
- (
- filter,
- new Columns<TInstance>
- (
- x => x.ID,
- x => x.Parent.ID,
- x => x.Form.Description,
- x => x.FormStarted,
- x => x.FormCompleted,
- x => x.Form.ID
- ));
- if (table.Rows.Any())
- {
- foreach (CoreRow row in table.Rows)
- {
- shells.Add(CreateShell(row));
- }
- //OrderShells(shells, filter);
- }
- return shells;
- }
- //private List<ExistingFormShell> OrderShells(List<ExistingFormShell> shells, Filter<TInstance> filter)
- //{
- // if (filter == completeFilter)
- // shells.Sort((x, y) => y.DateCompleted.CompareTo(x.DateCompleted)); //descending
- // else if (filter == incompleteFilter)
- // shells.Sort((x, y) => x.DateStarted.CompareTo(y.DateStarted));
- // return shells;
- //}
- private ExistingFormShell CreateShell(CoreRow row)
- {
- var instance = row.ToObject<TInstance>();
- ExistingFormShell shell = new ExistingFormShell();
- shell.ID = instance.ID;
- shell.Description = instance.Form.Description;
- if (shell.Description == null)
- shell.Description = "";
- shell.ParentID = instance.Parent.ID;
- shell.DateStarted = instance.FormStarted;
- shell.DateCompleted = instance.FormCompleted;
- shell.Started = "Started: " + shell.DateStarted.ToString("dd MMM yy hh:mm tt");
- if (shell.DateCompleted != DateTime.MinValue)
- shell.Completed = "Completed: " + shell.DateCompleted.ToString("dd MMM yy hh:mm tt");
- shell.Type = typeof(TInstance);
- shell.FormID = instance.Form.ID;
- return shell;
- }
- }
- }
|