123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- using System;
- using System.Data;
- using System.Windows.Controls;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using PRSDesktop.WidgetGroups;
- namespace PRSDesktop
- {
- public class ManufacturingStatusDashboardProperties : IDashboardProperties { }
- public class ManufacturingStatusDashboardElement : DashboardElement<ManufacturingStatusWidget, Manufacturing, ManufacturingStatusDashboardProperties> { }
- /// <summary>
- /// Interaction logic for ManufacturingStatusWidget.xaml
- /// </summary>
- public partial class ManufacturingStatusWidget : UserControl, IDashboardWidget<Manufacturing, ManufacturingStatusDashboardProperties>
- {
- private DateTime _date = DateTime.Today;
- private Guid _groupid = CoreUtils.FullGuid;
- private CoreTable packets;
- private readonly DataTable report = new();
- public ManufacturingStatusWidget()
- {
- InitializeComponent();
- report.Columns.Add("ID", typeof(Guid));
- report.Columns.Add("Setout", typeof(string));
- report.Columns.Add("Serial", typeof(string));
- report.Columns.Add("Description", typeof(string));
- report.Columns.Add("Estimated", typeof(double));
- report.Columns.Add("Actual", typeof(double));
- report.Columns.Add("Overdue", typeof(int));
- report.PrimaryKey = new[] { report.Columns[0] };
- }
- public DateTime Date
- {
- get => _date;
- set
- {
- _date = value;
- LoadPackets();
- }
- }
- public Guid GroupID
- {
- get => _groupid;
- set
- {
- _groupid = value;
- LoadPackets();
- }
- }
- public ManufacturingStatusDashboardProperties Properties { get; set; }
- public void Setup()
- {
- }
- public void Refresh()
- {
- }
- public void Shutdown()
- {
- }
- private void LoadPackets()
- {
- Report.ItemsSource = null;
- packets = null;
- var filter = new Filter<ManufacturingPacket>(x => x.Completed).IsGreaterThanOrEqualTo(Date.Date).And(x => x.Completed)
- .IsLessThan(Date.Date.AddDays(1));
- new Client<ManufacturingPacket>().Query(
- filter,
- null,
- new SortOrder<ManufacturingPacket>(x => x.SetoutLink.Number),
- (o, e) =>
- {
- packets = o;
- CheckData();
- }
- );
- }
- private void CheckData()
- {
- if (packets != null)
- ProcessData();
- }
- private void ProcessData()
- {
- try
- {
- report.Rows.Clear();
- foreach (var packet in packets.Rows)
- {
- var pktid = packet.Get<ManufacturingPacket, Guid>(x => x.ID);
- var setout = packet.Get<ManufacturingPacket, string>(x => x.SetoutLink.Number);
- var serial = packet.Get<ManufacturingPacket, string>(x => x.Serial);
- var description = packet.Get<ManufacturingPacket, string>(x => x.Description);
- var est = packet.Get<ManufacturingPacket, TimeSpan>(x => x.Time).TotalHours;
- var act = packet.Get<ManufacturingPacket, TimeSpan>(x => x.ActualTime).TotalHours;
- report.Rows.Add(pktid, setout, serial, description, est, act);
- }
- }
- catch (Exception e)
- {
- Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
- }
- Dispatcher.Invoke(() =>
- {
- Report.ItemsSource = new CoreTableAdapter<ManufacturingPacket>(packets); //report;
- });
- }
- }
- }
|