ManufacturingStatusWidget.xaml.cs 4.1 KB

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