From a74dccf5bfb3530ac51816650c9b732773dd9247 Mon Sep 17 00:00:00 2001 From: Stoyan Zlatev Date: Tue, 11 Apr 2023 15:34:51 +0200 Subject: [PATCH] HeReport - date range --- .../Models/HeliumReportFilter.cs | 40 ++++++++++++++----- .../Models/HeliumReportFilterProperty.cs | 36 ++++++----------- .../ReportService.cs | 1 + .../Controllers/ReportController.cs | 6 +++ .../Views/Report/DateFilter.cshtml | 11 ++--- .../Views/Report/Filter.cshtml | 1 + 6 files changed, 56 insertions(+), 39 deletions(-) diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/HeliumReportFilter.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/HeliumReportFilter.cs index 379fbe8d..704fcc6f 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Models/HeliumReportFilter.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/HeliumReportFilter.cs @@ -2,6 +2,7 @@ { using System; using System.Collections.Generic; + using System.Globalization; using System.Linq; public class HeliumReportFilter : List @@ -58,20 +59,39 @@ { if (property.Type == "date") { - if (property.Von != default(DateTime)) + if (!string.IsNullOrWhiteSpace(property.Like)) { - var propertyName = $"{property.Property}_{property.Index}_Von"; - var propertyValue = $"{property.Column} >= @{propertyName}"; + var dateTokens = property + .Like + .Split(new[] { ' ', '-' }, StringSplitOptions.RemoveEmptyEntries) + .Select(x => DateTimeOffset.TryParse($"{x}", new CultureInfo("de"), DateTimeStyles.None, out DateTimeOffset date) + ? (DateTimeOffset?)date.AddHours(-date.Hour) + : null) + .ToArray(); - sqlExpression.Add($"{property.Column} >= @{propertyName}", propertyName, property.Von); - } + if (dateTokens.Length >= 1) + { + var propertyValue = dateTokens[0]; - if (property.Bis != default(DateTime)) - { - var propertyName = $"{property.Property}_{property.Index}_Bis"; - var propertyValue = $"{property.Column} <= @{propertyName}"; + if (propertyValue != null) + { + var propertyName = $"{property.Property}_{property.Index}_From"; - sqlExpression.Add($"{property.Column} <= @{propertyName}", propertyName, property.Bis); + sqlExpression.Add($"{property.Column} >= @{propertyName}", propertyName, propertyValue); + } + } + + if (dateTokens.Length >= 2) + { + var propertyValue = dateTokens[1]; + + if (propertyValue != null) + { + var propertyName = $"{property.Property}_{property.Index}_To"; + + sqlExpression.Add($"{property.Column} <= @{propertyName}", propertyName, propertyValue); + } + } } } else if (string.IsNullOrWhiteSpace(property.Like)) diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/HeliumReportFilterProperty.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/HeliumReportFilterProperty.cs index 56ca62e3..0d6070e8 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Models/HeliumReportFilterProperty.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/HeliumReportFilterProperty.cs @@ -1,51 +1,39 @@ namespace LaaProductionWeb.Services.Models { - using System; - using System.ComponentModel.DataAnnotations; - public class HeliumReportFilterProperty { + public int Index { get; set; } + public string Type { get; set; } + public string Property { get; set; } + + public string Column { get; set; } + + public string Like { get; set; } + + public int OrderBy { get; set; } + + public string TypeName => $"Filter[{this.Index}].{nameof(this.Type)}"; - public int Index { get; set; } - public string IndexName => $"Filter[{this.Index}].{nameof(this.Index)}"; - public string Property { get; set; } - public string PropertyName => $"Filter[{this.Index}].{nameof(this.Property)}"; - public string Column { get; set; } - public string ColumnName => $"Filter[{this.Index}].{nameof(this.Column)}"; - public virtual string Like { get; set; } - - public string LikeName + public string LikeName => $"Filter[{this.Index}].{nameof(this.Like)}"; - public int OrderBy { get; set; } - public string OrderByName => $"Filter[{this.Index}].{nameof(this.OrderBy)}"; public string OrderById => $"Filter_{this.Index}_{nameof(this.OrderBy)}"; - - public DateTime Von { get; set; } - - public string VonName - => $"Filter[{this.Index}].{nameof(this.Von)}"; - - public DateTime Bis { get; set; } - - public string BisName - => $"Filter[{this.Index}].{nameof(this.Bis)}"; } } diff --git a/LaaProductionWeb/LaaProductionWeb.Services/ReportService.cs b/LaaProductionWeb/LaaProductionWeb.Services/ReportService.cs index ac2bf336..7c5f7a17 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/ReportService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/ReportService.cs @@ -24,6 +24,7 @@ var where = model.Filter.Where(); var orderBy = model.Filter.OrderBy(); + var debug = 1; model.Items = this.dbContext.AsEnumerable($@" SELECT [PT].[CordonelPressureTest_FertigungsAuftragsNr] AS [FertigungNr] -- 0 Filter diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/ReportController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/ReportController.cs index f26cfcb9..f7cf0074 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/ReportController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/ReportController.cs @@ -25,6 +25,12 @@ [HttpPost] public ActionResult Index(HeliumReportModel model) { + //foreach (var filter in model.Filter) + //{ + // filter.DatesToStrings(); + // filter.StringsToDates(); + //} + model = this.reportService.LoadHeliumPressureReport(model); return this.View(model); diff --git a/LaaProductionWeb/LaaProductionWeb/Views/Report/DateFilter.cshtml b/LaaProductionWeb/LaaProductionWeb/Views/Report/DateFilter.cshtml index a6144d23..acddbfc7 100644 --- a/LaaProductionWeb/LaaProductionWeb/Views/Report/DateFilter.cshtml +++ b/LaaProductionWeb/LaaProductionWeb/Views/Report/DateFilter.cshtml @@ -5,15 +5,16 @@ Func bgColor = x => !x ? "bg-light" : string.Empty; } + - -
- - -
+
diff --git a/LaaProductionWeb/LaaProductionWeb/Views/Report/Filter.cshtml b/LaaProductionWeb/LaaProductionWeb/Views/Report/Filter.cshtml index fa46fb3d..0d0a4949 100644 --- a/LaaProductionWeb/LaaProductionWeb/Views/Report/Filter.cshtml +++ b/LaaProductionWeb/LaaProductionWeb/Views/Report/Filter.cshtml @@ -10,6 +10,7 @@ +