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
@@ -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);
@@ -5,15 +5,16 @@
Func<bool, string> bgColor = x => !x ? "bg-light" : string.Empty;
}
<input type="hidden" name="@this.Model.TypeName" value="@this.Model.Type" />
<input type="hidden" name="@this.Model.IndexName" value="@this.Model.Index" />
<input type="hidden" name="@this.Model.ColumnName" value="@this.Model.Column" />
<input type="hidden" name="@this.Model.PropertyName" value="@this.Model.Property" />
<input type="hidden" name="@this.Model.TypeName" value="@this.Model.Type" />
<div class="input-group flex-nowrap justify-content-center">
<input name="@this.Model.VonName" type="date" class="form-control form-control-sm mb-1" value="@($"{this.Model.Von:MM/dd/yyyy}")" />
<input name="@this.Model.BisName" type="date" class="form-control form-control-sm mb-1" value="@($"{this.Model.Bis:MM/dd/yyyy}")" />
</div>
<input autocomplete="off"
style="min-width: 200px"
class="form-control form-control-sm mb-1"
name="@this.Model.LikeName"
value="@(!string.IsNullOrWhiteSpace(this.Model.Like) ? this.Model.Like : "dd.MM.yyyy - dd.MM.yyyy")" />
<div class="input-group flex-nowrap justify-content-center">
<input id="@(this.Model.OrderById)_1" name="@this.Model.OrderByName" type="radio" value="1" @isChecked(this.Model.OrderBy == 1) class="d-none" />
@@ -10,6 +10,7 @@
<input type="hidden" name="@this.Model.PropertyName" value="@this.Model.Property" />
<input type="hidden" name="@this.Model.TypeName" value="@this.Model.Type" />
<input name="@this.Model.LikeName" class="form-control form-control-sm mb-1" autocomplete="off" value="@this.Model.Like" />
<div class="input-group flex-nowrap justify-content-center">
<input id="@(this.Model.OrderById)_1" name="@this.Model.OrderByName" type="radio" value="1" @isChecked(this.Model.OrderBy == 1) class="d-none" />
<label for="@(this.Model.OrderById)_1" class="form-control form-control-sm text-center text-secondary border-light @bgColor(this.Model.OrderBy == 1) cursor-pointer">