JobDetails.xaml.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows.Controls;
  5. using Comal.Classes;
  6. using InABox.Clients;
  7. using InABox.Core;
  8. namespace PRSDesktop
  9. {
  10. /// <summary>
  11. /// Interaction logic for JobDetails.xaml
  12. /// </summary>
  13. public partial class JobDetails : UserControl, IPanel<Job>, IJobControl
  14. {
  15. private CoreTable Data;
  16. public JobDetails()
  17. {
  18. InitializeComponent();
  19. }
  20. public Guid ParentID { get; set; }
  21. public JobPanelSettings Settings { get; set; }
  22. public event DataModelUpdateEvent OnUpdateDataModel;
  23. public bool IsReady { get; set; }
  24. public void CreateToolbarButtons(IPanelHost host)
  25. {
  26. }
  27. public string SectionName => "Job Details";
  28. public DataModel DataModel(Selection selection)
  29. {
  30. return new JobDetailsDataModel(new Filter<Job>(x => x.ID).IsEqualTo(ParentID));
  31. }
  32. public void Heartbeat(TimeSpan time)
  33. {
  34. }
  35. public void Refresh()
  36. {
  37. //var cols = new Columns<Job>(col => col.Customer.Code);
  38. new Client<Job>().Query(
  39. new Filter<Job>(x => x.ID).IsEqualTo(ParentID),
  40. new Columns<Job>(
  41. col => col.JobNumber,
  42. col => col.Customer.Code,
  43. col => col.Customer.Name,
  44. col => col.SiteAddress.Street,
  45. col => col.SiteAddress.City,
  46. col => col.SiteAddress.State,
  47. col => col.SiteAddress.PostCode,
  48. col => col.Account.Code,
  49. col => col.Account.Name,
  50. col => col.Name,
  51. col => col.Notes,
  52. col => col.JobStatus.ID,
  53. col => col.ID
  54. ),
  55. null,
  56. (o, e) => { UpdateScreen(o); }
  57. );
  58. }
  59. public Dictionary<string, object[]> Selected()
  60. {
  61. var rows = Data != null ? Data.Rows.ToArray() : new CoreRow[] { };
  62. return new Dictionary<string, object[]> { { typeof(Job).EntityName(), rows } };
  63. }
  64. public void Setup()
  65. {
  66. UpdateScreen(null);
  67. var statuscodes = new Dictionary<Guid, string> { { Guid.Empty, "" } };
  68. var statuses = new Client<JobStatus>().Query();
  69. foreach (var row in statuses.Rows)
  70. statuscodes[row.Get<JobStatus, Guid>(x => x.ID)] = row.Get<JobStatus, string>(x => x.Description);
  71. Status.ItemsSource = statuscodes;
  72. }
  73. public void Shutdown()
  74. {
  75. }
  76. private void UpdateScreen(CoreTable o)
  77. {
  78. Data = o;
  79. Dispatcher.Invoke(() =>
  80. {
  81. CustomerCode.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.Customer.Code) : "";
  82. CustomerName.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.Customer.Name) : "";
  83. Address.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.SiteAddress.Street) : "";
  84. City.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.SiteAddress.City) : "";
  85. State.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.SiteAddress.State) : "";
  86. PostCode.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.SiteAddress.PostCode) : "";
  87. AccountCode.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.Account.Code) : "";
  88. AccountName.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.Account.Name) : "";
  89. Title.Text = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, string>(col => col.Name) : "";
  90. var notes = o != null && o.Rows.Any() ? o?.Rows.First()?.Get<Job, string[]>(col => col.Notes) : null;
  91. Notes.Text = notes != null ? string.Join("\n\n", notes)?.Replace("\r\n\r\n", "\r\n").Replace("\n\n", "\n") : "";
  92. var bIsReady = IsReady;
  93. IsReady = false;
  94. Status.SelectedValue = o != null && o.Rows.Any() ? o.Rows.First().Get<Job, Guid>(col => col.JobStatus.ID) : Guid.Empty;
  95. IsReady = bIsReady;
  96. });
  97. }
  98. private void Status_SelectionChanged(object sender, SelectionChangedEventArgs e)
  99. {
  100. var job = new Job { ID = ParentID };
  101. job.JobNumber = Data != null && Data.Rows.Any() ? Data.Rows.First().Get<Job, string>(col => col.JobNumber) : "";
  102. job.JobStatus.ID = Status.SelectedValue != null ? (Guid)Status.SelectedValue : Guid.Empty;
  103. if (IsReady)
  104. new Client<Job>().Save(job, "Updated Job Status", (j, err) => { });
  105. }
  106. }
  107. }