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 { } /// /// Interaction logic for ManufacturingStatusWidget.xaml /// public partial class ManufacturingStatusWidget : UserControl, IDashboardWidget { 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(x => x.Completed).IsGreaterThanOrEqualTo(Date.Date).And(x => x.Completed) .IsLessThan(Date.Date.AddDays(1)); new Client().Query( filter, null, new SortOrder(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(x => x.ID); var setout = packet.Get(x => x.SetoutLink.Number); var serial = packet.Get(x => x.Serial); var description = packet.Get(x => x.Description); var est = packet.Get(x => x.Time).TotalHours; var act = packet.Get(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(packets); //report; }); } } }