| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using Comal.Classes;
- using comal.timesheets;
- using InABox.Core;
- using Syncfusion.Drawing;
- using Syncfusion.Pdf;
- using Xamarin.Forms.Internals;
- namespace comal.timesheets
- {
- public class AssignmentFormInstance : INotifyPropertyChanged
- {
- private Guid _id = Guid.Empty;
- public Guid ID
- {
- get => _id;
- set => SetField(ref _id, value);
- }
- private String _description = "";
- public String Description
- {
- get => _description;
- set => SetField(ref _description, value);
- }
- private bool _completed = false;
- public bool Completed
- {
- get => _completed;
- set => SetField(ref _completed, value);
- }
- public event PropertyChangedEventHandler PropertyChanged;
- protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
- {
- if (EqualityComparer<T>.Default.Equals(field, value)) return false;
- field = value;
- OnPropertyChanged(propertyName);
- return true;
- }
- }
- public class AssignmentEditDataModel : SingleDataModel<Assignment, AssignmentEditDataModelItem>
- {
- public Guid JobID { get; set; }
-
- public Guid EmployeeID { get; set; }
-
- public List<KeyValuePair<Guid, String>> Activities { get; private set; }
- public List<AssignmentFormInstance> Forms { get; private set; }
-
- public PointF Coordinates { get; set; }
-
- public override Columns<Assignment> Columns => new Columns<Assignment>(x => x.ID)
- .Add(x=>x.Number)
- .Add(x => x.Title)
- .Add(x => x.Description)
- .Add(x => x.Date)
- .Add(x => x.Start)
- .Add(x => x.Duration)
- .Add(x => x.Finish)
- .Add(c => c.JobLink.ID)
- .Add(c => c.JobLink.JobNumber)
- .Add(c => c.JobLink.Name)
- .Add(c => c.ActivityLink.ID)
- .Add(c => c.ActivityLink.Code)
- .Add(c => c.ActivityLink.Description)
- .Add(c => c.EmployeeLink.ID)
- .Add(c => c.ActivityLink.Color)
- .Add(c => c.Completed);
- public override void BeforeLoad(MultiQuery query, Guid id)
- {
- base.BeforeLoad(query, id);
- query.Add<EmployeeActivity>(
- new Filter<EmployeeActivity>(x => x.ID).IsEqualTo(EmployeeID),
- new Columns<EmployeeActivity>(x=>x.Activity.ID).Add(x=>x.Activity.Code).Add(x=>x.Activity.Description)
- );
-
- if (JobID != Guid.Empty)
- {
- query.Add<Job>(
- new Filter<Job>(x => x.ID).IsEqualTo(JobID),
- new Columns<Job>(x => x.SiteAddress.Location.Latitude)
- .Add(x => x.SiteAddress.Location.Longitude)
- );
- }
- query.Add<AssignmentForm>(
- new Filter<AssignmentForm>(x => x.Parent.ID).IsEqualTo(id),
- new Columns<AssignmentForm>(x => x.ID)
- .Add(x => x.Form.Code)
- .Add(x => x.Form.Description)
- .Add(x => x.FormCompleted)
- );
- }
- public override void AfterLoad(MultiQuery query, Guid id)
- {
- base.AfterLoad(query, id);
-
- Activities = query.Get<EmployeeActivity>().ToDictionary<EmployeeActivity, Guid, String>(
- x => x.Activity.ID,
- (row) => String.Format("{0}: {1}", row.Get<EmployeeActivity, String>(c => c.Activity.Code),
- row.Get<EmployeeActivity, String>(c => c.Activity.Description)),
- x => x.Activity.Code
- ).ToList();
- if (JobID != Guid.Empty)
- {
- Coordinates = query.Get<Job>().Rows.Select(r => new PointF(
- (float)r.Get<Job, double>(c => c.SiteAddress.Location.Longitude),
- (float)r.Get<Job, double>(c => c.SiteAddress.Location.Latitude)
- )).FirstOrDefault();
- }
- else
- Coordinates = PointF.Empty;
- Forms = query.Get<AssignmentForm>()
- .Rows
- .Select(row => new AssignmentFormInstance()
- {
- ID = row.Get<AssignmentForm,Guid>(c=>c.ID),
- Description = row.Get<AssignmentForm, String>(c => c.Form.Description),
- Completed = !row.Get<AssignmentForm,DateTime>(c=>c.FormCompleted).IsEmpty()
- }).ToList();
- //.ToDictionary<AssignmentForm, Guid, String>(
- //x => x.ID,
- //(row) => String.Format("{0}: {1}", row.Get<AssignmentForm, String>(c => c.Form.Code),
- //
- //x => x.Form.Code
- //).ToList();
- }
- }
- }
|