From b96d52dcf527339d4d1c43c06d49b375a5f42e0c Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 18 Mar 2020 18:30:55 +0200 Subject: Implemented machine counters on PPC maintenance. --- .../ViewModels/MaintenanceViewVM.cs | 40 ++++++++++++++++++++++ .../Views/MaintenanceView.xaml | 15 +++++++- 2 files changed, 54 insertions(+), 1 deletion(-) (limited to 'Software/Visual_Studio/PPC/Modules') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs index 8d221c3f3..759d43415 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/ViewModels/MaintenanceViewVM.cs @@ -2,9 +2,11 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Data.Entity; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL; using Tango.Core.Commands; using Tango.Explorer; using Tango.Integration.Operation; @@ -39,6 +41,20 @@ namespace Tango.PPC.Maintenance.ViewModels set { _overallTemperature = value; RaisePropertyChangedAuto(); } } + private String _totalDyeTime; + public String TotalDyeTime + { + get { return _totalDyeTime; } + set { _totalDyeTime = value; RaisePropertyChangedAuto(); } + } + + private String _totalDyeMeters; + public String TotalDyeMeters + { + get { return _totalDyeMeters; } + set { _totalDyeMeters = value; RaisePropertyChangedAuto(); } + } + public RelayCommand ExportLogsCommand { get; set; } public OpenCloseDyeingHeadCommand OpenCloseDyeingHeadCommand { get; set; } @@ -167,5 +183,29 @@ namespace Tango.PPC.Maintenance.ViewModels } } } + + public async override void OnNavigatedTo() + { + base.OnNavigatedTo(); + + try + { + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var jobRuns = await db.JobRuns.Select(x => new { x.StartDate, x.EndDate, x.EndPosition }).ToListAsync(); + + TotalDyeTime = TimeSpan.FromHours(jobRuns.Select(x => x.EndDate - x.StartDate).Sum(x => x.TotalHours)).ToString(@"hh\:mm\:ss"); + + int meters = (int)jobRuns.Select(x => x.EndPosition).Sum(); + TotalDyeMeters = $"{meters.ToString("N0")} meters"; + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error loading machine counters."); + TotalDyeTime = "error!"; + TotalDyeMeters = "error!"; + } + } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Views/MaintenanceView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Views/MaintenanceView.xaml index 538d4e96d..11e2dc663 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Views/MaintenanceView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Maintenance/Views/MaintenanceView.xaml @@ -11,7 +11,7 @@ xmlns:localControls="clr-namespace:Tango.PPC.Maintenance.Controls" xmlns:local="clr-namespace:Tango.PPC.Maintenance.Views" mc:Ignorable="d" - d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:MaintenanceViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MaintenanceViewVM}"> + d:DesignHeight="1380" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:MaintenanceViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MaintenanceViewVM}"> @@ -224,6 +224,19 @@ + + + + + Total Dye Time: + + + + + Total Dye Meters: + + + -- cgit v1.3.1