123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Controls;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- namespace PRSDesktop
- {
- /// <summary>
- /// Interaction logic for JobDetails.xaml
- /// </summary>
- public partial class JobDetails : UserControl, IPanel<Job>, IJobControl
- {
- private CoreTable Data;
- public JobDetails()
- {
- InitializeComponent();
- }
- public Guid ParentID { get; set; }
-
- public JobPanelSettings Settings { get; set; }
- public event DataModelUpdateEvent OnUpdateDataModel;
- public bool IsReady { get; set; }
- public void CreateToolbarButtons(IPanelHost host)
- {
- }
- public string SectionName => "Job Details";
- public DataModel DataModel(Selection selection)
- {
- return new JobDetailsDataModel(new Filter<Job>(x => x.ID).IsEqualTo(ParentID));
- }
- public void Heartbeat(TimeSpan time)
- {
- }
- public void Refresh()
- {
- //var cols = new Columns<Job>(col => col.Customer.Code);
- new Client<Job>().Query(
- new Filter<Job>(x => x.ID).IsEqualTo(ParentID),
- new Columns<Job>(
- col => col.JobNumber,
- col => col.Customer.Code,
- col => col.Customer.Name,
- col => col.SiteAddress.Street,
- col => col.SiteAddress.City,
- col => col.SiteAddress.State,
- col => col.SiteAddress.PostCode,
- col => col.Account.Code,
- col => col.Account.Name,
- col => col.Name,
- col => col.Notes,
- col => col.JobStatus.ID,
- col => col.ID
- ),
- null,
- (o, e) => { UpdateScreen(o); }
- );
- }
- public Dictionary<string, object[]> Selected()
- {
- var rows = Data != null ? Data.Rows.ToArray() : new CoreRow[] { };
- return new Dictionary<string, object[]> { { typeof(Job).EntityName(), rows } };
- }
- public void Setup()
- {
- UpdateScreen(null);
- var statuscodes = new Dictionary<Guid, string> { { Guid.Empty, "" } };
- var statuses = new Client<JobStatus>().Query();
- foreach (var row in statuses.Rows)
- statuscodes[row.Get<JobStatus, Guid>(x => x.ID)] = row.Get<JobStatus, string>(x => x.Description);
- Status.ItemsSource = statuscodes;
- }
- public void Shutdown()
- {
- }
- private void UpdateScreen(CoreTable o)
- {
- Data = o;
- Dispatcher.Invoke(() =>
- {
- CustomerCode.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.Customer.Code) : "";
- CustomerName.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.Customer.Name) : "";
- Address.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.SiteAddress.Street) : "";
- City.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.SiteAddress.City) : "";
- State.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.SiteAddress.State) : "";
- PostCode.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.SiteAddress.PostCode) : "";
- AccountCode.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.Account.Code) : "";
- AccountName.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.Account.Name) : "";
- Title.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.Name) : "";
- var notes = o != null && o.Rows.Any() ? o?.Rows.First()?.Get<Job, string[]>(col => col.Notes) : null;
- Notes.Text = notes != null ? string.Join("\n\n", notes)?.Replace("\r\n\r\n", "\r\n").Replace("\n\n", "\n") : "";
- var bIsReady = IsReady;
- IsReady = false;
- Status.SelectedValue = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, Guid>(col => col.JobStatus.ID) : Guid.Empty;
- IsReady = bIsReady;
- });
- }
- private void Status_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- var job = new Job { ID = ParentID };
- job.JobNumber = Data != null && Data.Rows.Any() ? Data.Rows.First().Get<Job, string>(col => col.JobNumber) : "";
- job.JobStatus.ID = Status.SelectedValue != null ? (Guid)Status.SelectedValue : Guid.Empty;
- if (IsReady)
- new Client<Job>().Save(job, "Updated Job Status", (j, err) => { });
- }
- }
- }
|