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(ref T field, T value, [CallerMemberName] string propertyName = null) { if (EqualityComparer.Default.Equals(field, value)) return false; field = value; OnPropertyChanged(propertyName); return true; } } public class AssignmentEditDataModel : SingleDataModel { public Guid JobID { get; set; } public Guid EmployeeID { get; set; } public List> Activities { get; private set; } public List Forms { get; private set; } public PointF Coordinates { get; set; } public override Columns Columns => new Columns(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( new Filter(x => x.ID).IsEqualTo(EmployeeID), new Columns(x=>x.Activity.ID).Add(x=>x.Activity.Code).Add(x=>x.Activity.Description) ); if (JobID != Guid.Empty) { query.Add( new Filter(x => x.ID).IsEqualTo(JobID), new Columns(x => x.SiteAddress.Location.Latitude) .Add(x => x.SiteAddress.Location.Longitude) ); } query.Add( new Filter(x => x.Parent.ID).IsEqualTo(id), new Columns(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().ToDictionary( x => x.Activity.ID, (row) => String.Format("{0}: {1}", row.Get(c => c.Activity.Code), row.Get(c => c.Activity.Description)), x => x.Activity.Code ).ToList(); if (JobID != Guid.Empty) { Coordinates = query.Get().Rows.Select(r => new PointF( (float)r.Get(c => c.SiteAddress.Location.Longitude), (float)r.Get(c => c.SiteAddress.Location.Latitude) )).FirstOrDefault(); } else Coordinates = PointF.Empty; Forms = query.Get() .Rows .Select(row => new AssignmentFormInstance() { ID = row.Get(c=>c.ID), Description = row.Get(c => c.Form.Description), Completed = !row.Get(c=>c.FormCompleted).IsEmpty() }).ToList(); //.ToDictionary( //x => x.ID, //(row) => String.Format("{0}: {1}", row.Get(c => c.Form.Code), // //x => x.Form.Code //).ToList(); } } }