HeReport - date range

This commit is contained in:
Stoyan Zlatev
2023-04-11 15:34:51 +02:00
parent e7d457da19
commit a74dccf5bf
6 changed files with 56 additions and 39 deletions
@@ -2,6 +2,7 @@
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
public class HeliumReportFilter : List<HeliumReportFilterProperty>
@@ -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))
@@ -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)}";
}
}
@@ -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