ManufacturingStatusWidget.xaml.cs 3.9 KB

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