(1) PreviousResultsDlg with filters, (2) Procedure history can be inspected.

This commit is contained in:
Milan Hanajik
2021-01-19 09:28:05 +01:00
parent 34f8bb226f
commit 1fb76a2167
8 changed files with 293 additions and 44 deletions
+83 -19
View File
@@ -1,5 +1,5 @@
///
/// Copyright (c) 2016-2017 Sensus Slovensko a.s.
/// Copyright (c) 2016-2021 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@@ -9,8 +9,8 @@ using log4net;
using Oracle.DataAccess.Client;
using Results;
using Results.Entities;
using TBF.Resources;
using TBF.BenchControl.Output.DB.SensusOracle;
using TBF.Resources;
namespace TBF.UI.ResultsMI
{
@@ -27,9 +27,11 @@ namespace TBF.UI.ResultsMI
ISession session;
int currentBatchNr;
int lastDisplayedBatchNr;
const int LinesCount = 25;
IList<Batch> batches;
IList<Batch> batches; /// A list of batches selected from all batches using criteria from/to date and procedure name
int lastDisplayedIx; /// Index of the last displayed batch from the list 'batches'
const int LinesCount = 25; /// Number of batches displayed on one screen
PreviousResultsMode mode;
@@ -62,11 +64,31 @@ namespace TBF.UI.ResultsMI
{
Localize();
session = DB.CreateSession();
fromDateTimePicker.MinDate = Constants.MinDate;
fromDateTimePicker.MaxDate = DateTime.Today;
fromDateTimePicker.Value = Constants.MinDate;
fromDateTimePicker.CustomFormat = Constants.DateFormat;
fromDateTimePicker.ShowUpDown = true;
lastDisplayedBatchNr = currentBatchNr - 1;
DrawBatches(lastDisplayedBatchNr - LinesCount + 1, lastDisplayedBatchNr);
toDateTimePicker.MinDate = Constants.MinDate;
toDateTimePicker.MaxDate = DateTime.Today;
toDateTimePicker.Value = DateTime.Today;
toDateTimePicker.CustomFormat = Constants.DateFormat;
toDateTimePicker.ShowUpDown = true;
try
{
session = DB.CreateSession();
}
catch (Exception exc)
{
session = null;
log.ErrorFormat("Opening Results DB failed: {0}", exc.Message);
}
var batches = GetFilteredBatches();
UpdateButtons();
Redraw();
}
void Localize()
@@ -75,10 +97,44 @@ namespace TBF.UI.ResultsMI
closeButton.Text = TBF.Resources.Strings.CloseBtnText;
previousButton.Text = TBF.Resources.Strings.Previous;
nextButton.Text = TBF.Resources.Strings.Next;
fromLabel.Text = Strings.from;
toLabel.Text = Strings.to;
procedureLabel.Text = Strings.Procedure;
}
IList<Batch> GetFilteredBatches()
{
try
{
if (string.IsNullOrEmpty(procedureTextBox.Text))
{
batches = session.QueryOver<Batch>()
.Where(x => (x.StartTime >= fromDateTimePicker.Value))
.And(x => (x.StartTime <= toDateTimePicker.Value.AddDays(1)))
.OrderBy(x => x.BatchNr).Asc
.List();
}
else
{
batches = session.QueryOver<Batch>()
.Where(x => (x.ProcedureName == procedureTextBox.Text))
.And(x => (x.StartTime >= fromDateTimePicker.Value))
.And(x => (x.StartTime <= toDateTimePicker.Value.AddDays(1)))
.OrderBy(x => x.BatchNr).Asc
.List();
}
}
catch (Exception exc)
{
batches = new List<Batch>();
log.ErrorFormat("Reading batches from Results DB failed: {0}", exc.Message);
}
lastDisplayedIx = batches.Count - 1;
return batches;
}
public void OnReload(object sender, PreviousResultIdEventArgs data)
{
foreach (var batch in batches)
@@ -318,10 +374,11 @@ namespace TBF.UI.ResultsMI
if (batches == null || batches.Count == 0) return;
foreach (var b in batches)
{
for (int i = Math.Max(0, lastDisplayedIx - LinesCount + 1); i <= lastDisplayedIx; i++)
{
var b = batches[i];
int passedCount = 0;
int failedCount = 0;
int failedCount = 0;
foreach (var wm in b.WaterMeters)
{
if ((wm != null) && wm.Passed) { passedCount++; } else { failedCount++; }
@@ -340,7 +397,7 @@ namespace TBF.UI.ResultsMI
failedCount,
b.RsltsSent,
mode));
}
}
ResumeLayout();
}
@@ -354,22 +411,29 @@ namespace TBF.UI.ResultsMI
private void previousButton_Click(object sender, EventArgs e)
{
lastDisplayedBatchNr = Math.Max(lastDisplayedBatchNr - LinesCount, LinesCount);
DrawBatches(lastDisplayedBatchNr - LinesCount + 1, lastDisplayedBatchNr);
lastDisplayedIx = Math.Max(lastDisplayedIx - LinesCount, LinesCount - 1);
Redraw();
UpdateButtons();
}
private void nextButton_Click(object sender, EventArgs e)
{
lastDisplayedBatchNr = Math.Min(lastDisplayedBatchNr + LinesCount, currentBatchNr - 1);
DrawBatches(lastDisplayedBatchNr - LinesCount + 1, lastDisplayedBatchNr);
lastDisplayedIx = Math.Min(lastDisplayedIx + LinesCount, batches.Count - 1);
Redraw();
UpdateButtons();
}
private void UpdateButtons()
{
nextButton.Enabled = (lastDisplayedBatchNr < currentBatchNr - 1);
previousButton.Enabled = (lastDisplayedBatchNr > LinesCount);
nextButton.Enabled = (lastDisplayedIx < batches.Count - 1);
previousButton.Enabled = (lastDisplayedIx > LinesCount - 1);
}
private void reloadButton_Click(object sender, EventArgs e)
{
batches = GetFilteredBatches();
UpdateButtons();
Redraw();
}
}
}