|
@@ -2,6 +2,7 @@ using Prism.Commands;
|
|
|
using Prism.Mvvm;
|
|
using Prism.Mvvm;
|
|
|
using System;
|
|
using System;
|
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
+using System.Globalization;
|
|
|
using System.IO;
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
using System.Text;
|
|
@@ -108,19 +109,27 @@ namespace TeamAAS_VP.ViewModels.Statistics
|
|
|
{
|
|
{
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
- var start = StartDate.HasValue ? StartDate.Value.Date : DateTime.MinValue;
|
|
|
|
|
- var end = EndDate.HasValue ? EndDate.Value.Date.AddDays(1) : DateTime.MaxValue;
|
|
|
|
|
- string productName = SelectedProduct?.Name;
|
|
|
|
|
- var resAll = await _systemDatabaseService.GetProductionStatsAsync(new ProductionStatQuery { ProductName = productName, Start = start, End = end, GroupBy = "total" });
|
|
|
|
|
- var saveFileDialog = new Microsoft.Win32.SaveFileDialog { FileName = $"Production_{DateTime.Now:yyyyMMddHHmmss}.csv", DefaultExt = ".csv", Filter = "CSV Files (*.csv)|*.csv" };
|
|
|
|
|
|
|
+ // Export current page Results (paged) to CSV including all ProductionRecord fields
|
|
|
|
|
+ var saveFileDialog = new Microsoft.Win32.SaveFileDialog { FileName = $"ProductionRecords_{DateTime.Now:yyyyMMddHHmmss}.csv", DefaultExt = ".csv", Filter = "CSV Files (*.csv)|*.csv" };
|
|
|
if (saveFileDialog.ShowDialog() != true) return;
|
|
if (saveFileDialog.ShowDialog() != true) return;
|
|
|
var path = saveFileDialog.FileName;
|
|
var path = saveFileDialog.FileName;
|
|
|
using (var sw = new StreamWriter(path, false, Encoding.UTF8))
|
|
using (var sw = new StreamWriter(path, false, Encoding.UTF8))
|
|
|
{
|
|
{
|
|
|
- sw.WriteLine("PeriodStart,PeriodEnd,Quantity,ProductName");
|
|
|
|
|
- foreach (var r in resAll)
|
|
|
|
|
|
|
+ sw.WriteLine("Id,Timestamp,ProductName,ProductCode,DeviceId,DeviceName,Category,Quantity,UserName,Remark");
|
|
|
|
|
+ foreach (var r in Results)
|
|
|
{
|
|
{
|
|
|
- sw.WriteLine($"{r.PeriodStart:yyyy-MM-dd HH:mm:ss},{r.PeriodEnd:yyyy-MM-dd HH:mm:ss},{r.Quantity},{r.ProductName}");
|
|
|
|
|
|
|
+ sw.WriteLine(string.Join(",",
|
|
|
|
|
+ EscapeCsv(r.Id.ToString()),
|
|
|
|
|
+ EscapeCsv(r.Timestamp.ToString("yyyy-MM-dd HH:mm:ss")),
|
|
|
|
|
+ EscapeCsv(r.ProductName),
|
|
|
|
|
+ EscapeCsv(r.ProductCode),
|
|
|
|
|
+ EscapeCsv(r.DeviceId.ToString()),
|
|
|
|
|
+ EscapeCsv(r.DeviceName),
|
|
|
|
|
+ EscapeCsv(r.Category),
|
|
|
|
|
+ EscapeCsv(r.Quantity.ToString()),
|
|
|
|
|
+ EscapeCsv(r.UserName),
|
|
|
|
|
+ EscapeCsv(r.Remark)
|
|
|
|
|
+ ));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -128,6 +137,7 @@ namespace TeamAAS_VP.ViewModels.Statistics
|
|
|
{
|
|
{
|
|
|
MessageBox.Show(ex.Message, "´íÎó", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
MessageBox.Show(ex.Message, "´íÎó", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
}
|
|
}
|
|
|
|
|
+ await Task.CompletedTask;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private async void LoadCategoriesForProduct(string productName)
|
|
private async void LoadCategoriesForProduct(string productName)
|
|
@@ -143,5 +153,15 @@ namespace TeamAAS_VP.ViewModels.Statistics
|
|
|
}
|
|
}
|
|
|
catch { }
|
|
catch { }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private string EscapeCsv(string s)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (s == null) return "";
|
|
|
|
|
+ if (s.Contains(",") || s.Contains("\"") || s.Contains("\r") || s.Contains("\n"))
|
|
|
|
|
+ {
|
|
|
|
|
+ return "\"" + s.Replace("\"", "\"\"") + "\"";
|
|
|
|
|
+ }
|
|
|
|
|
+ return s;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|