ManufacturingStatusWidget.xaml.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.ComponentModel;
  3. using System.Data;
  4. using System.Windows.Controls;
  5. using Comal.Classes;
  6. using InABox.Clients;
  7. using InABox.Configuration;
  8. using InABox.Core;
  9. using PRSDesktop.WidgetGroups;
  10. namespace PRSDesktop
  11. {
  12. public class ManufacturingStatusDashboardProperties : IUserConfigurationSettings, IDashboardProperties { }
  13. public class ManufacturingStatusDashboardElement : DashboardElement<ManufacturingStatusWidget, Manufacturing, ManufacturingStatusDashboardProperties> { }
  14. /// <summary>
  15. /// Interaction logic for ManufacturingStatusWidget.xaml
  16. /// </summary>
  17. public partial class ManufacturingStatusWidget : UserControl, IDashboardWidget<Manufacturing, ManufacturingStatusDashboardProperties>
  18. {
  19. private DateTime _date = DateTime.Today;
  20. private Guid _groupid = CoreUtils.FullGuid;
  21. private CoreTable packets;
  22. private readonly DataTable report = new();
  23. public ManufacturingStatusWidget()
  24. {
  25. InitializeComponent();
  26. report.Columns.Add("ID", typeof(Guid));
  27. report.Columns.Add("Setout", typeof(string));
  28. report.Columns.Add("Serial", typeof(string));
  29. report.Columns.Add("Description", typeof(string));
  30. report.Columns.Add("Estimated", typeof(double));
  31. report.Columns.Add("Actual", typeof(double));
  32. report.Columns.Add("Overdue", typeof(int));
  33. report.PrimaryKey = new[] { report.Columns[0] };
  34. }
  35. public DateTime Date
  36. {
  37. get => _date;
  38. set
  39. {
  40. _date = value;
  41. LoadPackets();
  42. }
  43. }
  44. public Guid GroupID
  45. {
  46. get => _groupid;
  47. set
  48. {
  49. _groupid = value;
  50. LoadPackets();
  51. }
  52. }
  53. public ManufacturingStatusDashboardProperties Properties { get; set; }
  54. public event LoadSettings<ManufacturingStatusDashboardProperties>? LoadSettings;
  55. public event SaveSettings<ManufacturingStatusDashboardProperties>? SaveSettings;
  56. public void Setup()
  57. {
  58. }
  59. public void Refresh()
  60. {
  61. }
  62. public void Shutdown(CancelEventArgs? cancel)
  63. {
  64. }
  65. private void LoadPackets()
  66. {
  67. Report.ItemsSource = null;
  68. packets = null;
  69. var filter = new Filter<ManufacturingPacket>(x => x.Completed).IsGreaterThanOrEqualTo(Date.Date).And(x => x.Completed)
  70. .IsLessThan(Date.Date.AddDays(1));
  71. new Client<ManufacturingPacket>().Query(
  72. filter,
  73. null,
  74. new SortOrder<ManufacturingPacket>(x => x.SetoutLink.Number),
  75. CoreRange.All,
  76. (o, e) =>
  77. {
  78. packets = o;
  79. CheckData();
  80. }
  81. );
  82. }
  83. private void CheckData()
  84. {
  85. if (packets != null)
  86. ProcessData();
  87. }
  88. private void ProcessData()
  89. {
  90. try
  91. {
  92. report.Rows.Clear();
  93. foreach (var packet in packets.Rows)
  94. {
  95. var pktid = packet.Get<ManufacturingPacket, Guid>(x => x.ID);
  96. var setout = packet.Get<ManufacturingPacket, string>(x => x.SetoutLink.Number);
  97. var serial = packet.Get<ManufacturingPacket, string>(x => x.Serial);
  98. var description = packet.Get<ManufacturingPacket, string>(x => x.Description);
  99. var est = packet.Get<ManufacturingPacket, TimeSpan>(x => x.Time).TotalHours;
  100. var act = packet.Get<ManufacturingPacket, TimeSpan>(x => x.ActualTime).TotalHours;
  101. report.Rows.Add(pktid, setout, serial, description, est, act);
  102. }
  103. }
  104. catch (Exception e)
  105. {
  106. Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
  107. }
  108. Dispatcher.Invoke(() =>
  109. {
  110. Report.ItemsSource = new CoreTableAdapter<ManufacturingPacket>(packets); //report;
  111. });
  112. }
  113. }
  114. }