aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules
diff options
context:
space:
mode:
authorVictoria Plitt <Victoria.Plitt@twine-s.com>2020-05-24 14:35:45 +0300
committerVictoria Plitt <Victoria.Plitt@twine-s.com>2020-05-24 14:35:45 +0300
commit524804c73ecf09511d88598e30c3dd89f3a64efe (patch)
treee43ccb0cd8c31b63f3060c064d5a3bc26bda20b3 /Software/Visual_Studio/MachineStudio/Modules
parentaaf9291bed25209830f68a56e55234944b39d32b (diff)
downloadTango-524804c73ecf09511d88598e30c3dd89f3a64efe.tar.gz
Tango-524804c73ecf09511d88598e30c3dd89f3a64efe.zip
Added export to Excel button to Statistics report
Related Work Items: #2805
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/ExcelModel.cs34
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj5
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs94
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml9
4 files changed, 137 insertions, 5 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/ExcelModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/ExcelModel.cs
new file mode 100644
index 000000000..f06b9fe60
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/ExcelModel.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.MachineStudio.Statistics.Models
+{
+ public class ExcelModel
+ {
+ public String ID { get; set; }
+ public String Machine { get; set; }
+ public String User { get; set; }
+ public String JobName { get; set; }
+ public String Thread { get; set; }
+ public String Length { get; set; }
+ public String Source { get; set; }
+ public String UploadDuration { get; set; }
+ public String HeatingDuration { get; set; }
+ public String StartTime { get; set; }
+ public String IsGradient { get; set; }
+ public String GR { get; set; }
+ public String Status { get; set; }
+ public String EndTime { get; set; }
+ public String EndPosition { get; set; }
+ public String Cyan { get; set; }
+ public String Magenta { get; set; }
+ public String Yellow { get; set; }
+ public String Black { get; set; }
+ public String Transparent { get; set; }
+ public String Lubricant { get; set; }
+ public String Cleaner { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj
index f77dbd482..12c1faa7d 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj
@@ -84,6 +84,7 @@
<Compile Include="Converters\NanoLiterToLiterFormatConverter.cs" />
<Compile Include="Converters\StringToBoolYesNoNullConverter.cs" />
<Compile Include="Converters\StringToFirstLetterConverter.cs" />
+ <Compile Include="Models\ExcelModel.cs" />
<Compile Include="Models\TotalLiquidQuantityModel.cs" />
<Compile Include="Models\JobRunModel.cs" />
<Compile Include="Models\JobRunStatisticsModel.cs" />
@@ -172,6 +173,10 @@
<Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project>
<Name>Tango.Core</Name>
</ProjectReference>
+ <ProjectReference Include="..\..\..\Tango.CSV\Tango.CSV.csproj">
+ <Project>{58e8825f-0c96-449c-b320-1e82b0aa876b}</Project>
+ <Name>Tango.CSV</Name>
+ </ProjectReference>
<ProjectReference Include="..\..\..\Tango.Logging\Tango.Logging.csproj">
<Project>{bc932dbd-7cdb-488c-99e4-f02cf441f55e}</Project>
<Name>Tango.Logging</Name>
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs
index 800346ff9..a6a477053 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs
@@ -21,6 +21,8 @@ using LiveCharts.Wpf;
using LiveCharts;
using Tango.BL.ValueObjects;
using System.Diagnostics;
+using Microsoft.Win32;
+using Tango.CSV;
namespace Tango.MachineStudio.Statistics.ViewModels
{
@@ -200,11 +202,14 @@ namespace Tango.MachineStudio.Statistics.ViewModels
public RelayCommand LoadJobRunsCommand { get; set; }
+ public RelayCommand ExportToExcelCommand { get; set; }
+
public JobRunsViewVM(INotificationProvider notificationProvider)
{
_notification = notificationProvider;
JobRuns = new ObservableCollection<JobRunModel>();
LoadJobRunsCommand = new RelayCommand(async () => await LoadJobRuns(), () => IsFree);
+ ExportToExcelCommand = new RelayCommand(ExportToExcel, () => IsFree);
LengthUpperValue = 5000.0;
LengthLowerValue = 0.0;
DateTime now = DateTime.Now;
@@ -444,12 +449,91 @@ namespace Tango.MachineStudio.Statistics.ViewModels
}
}
- #region GenerateS_StatisticsValueCollection
+ private void ExportToExcel()
+ {
+ SaveFileDialog dlg = new SaveFileDialog();
+ dlg.Title = "Job Runs Statistic Report";
+ dlg.Filter = "CSV Files|*.csv";
+ dlg.FileName = $"Statistics_Job_runs";
+ dlg.DefaultExt = ".csv";
+ if (dlg.ShowDialog().Value)
+ {
+ try
+ {
+ CsvFile<ExcelModel> csvFile = new CsvFile<ExcelModel>(new CsvDestination(dlg.FileName), new CsvDefinition()
+ {
+ Columns = new List<String>()
+ {
+ "ID",
+ "Machine",
+ "User",
+ "Job Name",
+ "Thread",
+ "Length",
+ "Source",
+ "Upload Duration",
+ "Heating Duration",
+ "Start Time",
+ "IsGradient",
+ "Gradient Resolution",
+ "Status",
+ "End Date",
+ "End Position",
+ "Cyan",
+ "Magenta",
+ "Yellow",
+ "Black",
+ "Transparent",
+ "Lubricant",
+ "Cleaner"
+ },
+ });
+ var selection = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.JobRun.EndDate != null && z.JobRun.ActualStartDate != null);
+ foreach (var jobRunModel in selection)
+ {
+ ExcelModel excel_model = new ExcelModel();
+ excel_model.ID = jobRunModel.JobRun.ID.ToString();
+ excel_model.Machine = jobRunModel.Machine != null ? jobRunModel.Machine.SerialNumber : "";
+ excel_model.User = jobRunModel.User != null ? jobRunModel.User.Contact.FullName: "";
+ excel_model.JobName = jobRunModel.JobRun.JobName;
+ excel_model.Thread = jobRunModel.Rml != null ? jobRunModel.Rml.Name : "";
+ excel_model.Length = String.Format("{0:0.##}", jobRunModel.JobRun.JobLength);
+ excel_model.Source = jobRunModel.JobRun.Source.ToString();
+ excel_model.UploadDuration = jobRunModel.UploadDuration != null ? ((TimeSpan)(jobRunModel.UploadDuration)).ToString(@"hh\:mm\:ss") : TimeSpan.FromSeconds(0).ToString(@"hh\:mm\:ss");
+ excel_model.HeatingDuration = jobRunModel.HeatingDuration != null ? ((TimeSpan)(jobRunModel.HeatingDuration)).ToString(@"hh\:mm\:ss") : TimeSpan.FromSeconds(0).ToString(@"hh\:mm\:ss");
+ excel_model.StartTime = jobRunModel.JobRun.ActualStartDate != null ? ((DateTime)jobRunModel.JobRun.ActualStartDate).ToLocalTime().ToString("MM/dd/yy HH:mm"): "";
+ excel_model.IsGradient = jobRunModel.JobRun.IsGradient ? "Yes" : "No";
+ excel_model.GR = jobRunModel.JobRun.GradientResolutionCm.ToString();
+ excel_model.Status = jobRunModel.JobRun.JobRunStatus.ToString();
+ excel_model.EndTime = jobRunModel.JobRun.EndDate != null ? ((DateTime)jobRunModel.JobRun.EndDate).ToLocalTime().ToString("MM/dd/yy HH:mm"): "";
+ excel_model.EndPosition = String.Format("{0:0.##}", jobRunModel.JobRun.EndPosition);
+ excel_model.Cyan = jobRunModel.JobRun.CyanQuantity < 0 ? "" :jobRunModel.JobRun.CyanQuantity.ToString();
+ excel_model.Magenta = jobRunModel.JobRun.MagentaQuantity < 0 ? "" : jobRunModel.JobRun.MagentaQuantity.ToString();
+ excel_model.Yellow = jobRunModel.JobRun.YellowQuantity < 0 ? "" : jobRunModel.JobRun.YellowQuantity.ToString();
+ excel_model.Black = jobRunModel.JobRun.BlackQuantity < 0 ? "" : jobRunModel.JobRun.BlackQuantity.ToString();
+ excel_model.Transparent = jobRunModel.JobRun.TransparentQuantity < 0 ? "" : jobRunModel.JobRun.TransparentQuantity.ToString();
+ excel_model.Lubricant = jobRunModel.JobRun.LubricantQuantity < 0 ? "" : jobRunModel.JobRun.LubricantQuantity.ToString();
+ excel_model.Cleaner = jobRunModel.JobRun.CleanerQuantity < 0 ? "" : jobRunModel.JobRun.CleanerQuantity.ToString();
+ csvFile.Append(excel_model);
+
+ }
+
+ csvFile.Dispose();
+ _notification.ShowInfo("Report generated successfully.");
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error generating Statistics Job Runs report.");
+ _notification.ShowError($"Error generating Statistics Job Runs report..\n{ex.Message}");
+ }
+ }
+ }
+ #region GenerateS_StatisticsValueCollection
- /// <summary>
- /// Generates the statistics.
- /// </summary>
- protected void GenerateStatistics()
+ /// <summary>
+ /// Generates the statistics.
+ /// </summary>
+ protected void GenerateStatistics()
{
StatisticsValueCollection.Clean();
if (JobRuns.Count() == 0)
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml
index 6431d72fb..7e6ebe405 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml
@@ -695,5 +695,14 @@
</Border>
</Grid>
</Border>
+ <Grid Grid.Row="0" Grid.Column="1" Margin="20 0 20 0">
+ <Border Padding="14 14 12 14" BorderBrush="DimGray" BorderThickness="0" Background="{StaticResource Logging.Background}" HorizontalAlignment="Stretch" CornerRadius="2" >
+ <Border.Effect>
+ <DropShadowEffect ShadowDepth="4" BlurRadius="10" Opacity="0.5"/>
+ </Border.Effect>
+
+ <Button Grid.Column="1" HorizontalAlignment="Right" Command="{Binding ExportToExcelCommand}" Margin="0 0 10 0" Padding="10 15" Height="Auto" VerticalAlignment="Center" Width="Auto">EXPORT TO EXCEL</Button>
+ </Border>
+ </Grid>
</Grid>
</UserControl>