123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using comal.timesheets.CustomControls;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using iText.Layout.Element;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- using PRSClasses;
- using PRSSecurity = InABox.Core.Security;
- namespace comal.timesheets
- {
- public static class CacheLoader
- {
- #region Jobs
- public static async Task LoadJobs()
- {
- await Task.Run(() =>
- {
- try
- {
- List<JobShell> jobShells = new List<JobShell>();
- Filter<Job> filter = AssignFilter();
- CoreTable table = DoJobsQuery(filter);
- foreach (CoreRow row in table.Rows)
- jobShells.Add(CreateJobShell(row));
- AssignJobShells(jobShells);
- }
- catch
- { }
- });
- }
- private static void AssignJobShells(List<JobShell> jobShells)
- {
- GlobalVariables.JobShells = jobShells;
- GlobalVariables.JobShells.Insert(0, new JobShell { ID = Guid.Empty, JobNumber = "No Job", Name = "Empty Job", JobStatusDescription = "Hidden" });
- GlobalVariables.JobsLoaded = true;
- }
- private static Filter<Job> AssignFilter()
- {
- Filter<Job> filter = new Filter<Job>(x => x.JobStatus.Active).IsEqualTo(true);
- if (!PRSSecurity.IsAllowed<CanViewAllJobs>())
- {
- List<Guid> jobIDs = new List<Guid>();
- CoreTable jobEmployees = new Client<JobEmployee>().Query(
- new Filter<JobEmployee>(x => x.EmployeeLink.ID).IsEqualTo(GlobalVariables.EmpID),
- new Columns<JobEmployee>(x => x.JobLink.ID)
- );
- foreach (CoreRow row in jobEmployees.Rows)
- {
- jobIDs.Add(row.Get<JobEmployee, Guid>(x => x.JobLink.ID));
- }
- filter = filter.And(x => x.ID).InList(jobIDs.ToArray());
- }
- return filter;
- }
- private static CoreTable DoJobsQuery(Filter<Job> filter)
- {
- return new Client<Job>().Query(
- filter,
- new Columns<Job>(x => x.ID, x => x.Name, x => x.JobNumber, x => x.JobStatus.Description, x => x.Color),
- new SortOrder<Job>(x => x.JobNumber)
- );
- }
- private static JobShell CreateJobShell(CoreRow row)
- {
- Job job = row.ToObject<Job>();
- if (job.Color == null)
- job.Color = "";
- JobShell jobshell = new JobShell
- {
- ID = job.ID,
- Name = job.Name,
- JobNumber = job.JobNumber,
- JobStatusDescription = job.JobStatus.Description,
- Color = Color.FromHex(job.Color)
- };
- if (jobshell.JobStatusDescription.Equals("Active Projects"))
- jobshell.JobStatusDescription = "Active";
- else if (jobshell.JobStatusDescription.Equals("Projects - Hidden from View"))
- jobshell.JobStatusDescription = "Hidden";
- else if (jobshell.JobStatusDescription.Equals("Projects in Defect Liability Period"))
- jobshell.JobStatusDescription = "Defect Liability";
- jobshell.DisplayName = "(" + jobshell.JobNumber + ") " + jobshell.Name;
- return jobshell;
- }
- #endregion
- }
- }
|