Refactoring : TestBenchFramework --> TBF ver. 2.18.789
This commit is contained in:
@@ -0,0 +1,282 @@
|
||||
///
|
||||
/// Copyright (c) 2016-2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using Results.Entities;
|
||||
using NHibernate;
|
||||
using log4net;
|
||||
using TBF.Resources;
|
||||
using TBF.BenchControl.DB.SensusOracle;
|
||||
using Oracle.DataAccess.Client;
|
||||
|
||||
namespace TBF.Forms
|
||||
{
|
||||
public partial class PreviousResultsDlg : Form
|
||||
{
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(PreviousResultsDlg));
|
||||
|
||||
ISession session;
|
||||
int currentBatchNr;
|
||||
IList<Batch> batches;
|
||||
bool reloadEn;
|
||||
|
||||
|
||||
public PreviousResultsDlg(bool reloadEn)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.reloadEn = reloadEn;
|
||||
currentBatchNr = Program.LocalSettings.BatchNr;
|
||||
|
||||
SendAgainHandler += delegate(object sndr, PreviousResultIdEventArgs args)
|
||||
{
|
||||
if (InvokeRequired) { Invoke(new EventHandler<PreviousResultIdEventArgs>(DoSendAgain), sndr, args); }
|
||||
else DoSendAgain(sndr, args);
|
||||
};
|
||||
|
||||
ShowResultsHandler += delegate(object sndr, PreviousResultIdEventArgs args)
|
||||
{
|
||||
if (InvokeRequired) { Invoke(new EventHandler<PreviousResultIdEventArgs>(DoShowResults), sndr, args); }
|
||||
else DoShowResults(sndr, args);
|
||||
};
|
||||
}
|
||||
|
||||
public PreviousResultsDlg()
|
||||
: this(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
private void PreviousResultsDlg_Load(object sender, EventArgs e)
|
||||
{
|
||||
Localize();
|
||||
|
||||
session = Results.DB.CreateSession();
|
||||
|
||||
batches = session.QueryOver<Batch>()
|
||||
.WhereRestrictionOn(x => x.BatchNr)
|
||||
.IsBetween(Math.Max(1, currentBatchNr - 25))
|
||||
.And(Math.Max(1, currentBatchNr - 1))
|
||||
.OrderBy(x => x.BatchNr).Asc
|
||||
.List<Batch>();
|
||||
|
||||
Redraw();
|
||||
}
|
||||
|
||||
void Localize()
|
||||
{
|
||||
Text = Strings.Previous_results;
|
||||
closeButton.Text = TBF.Resources.Strings.CloseBtnText;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void OnReload(object sender, PreviousResultIdEventArgs data)
|
||||
{
|
||||
foreach (var batch in batches)
|
||||
{
|
||||
if (batch.BatchNr == data.BatchNr)
|
||||
{
|
||||
TBF.UiBridge.Bridge.BatchNr = batch.BatchNr;
|
||||
Program.MainWnd.UpdateProcedure(batch.ProcedureName);
|
||||
TBF.UiBridge.Bridge.Ui2Bench(TBF.UiBridge.UI2BenchCmd.ReloadBatch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public event EventHandler<PreviousResultIdEventArgs> SendAgainHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Called from PreviousResultCtrl when 'Send again' button pressed.
|
||||
/// </summary>
|
||||
public void OnSendAgain(object sender, PreviousResultIdEventArgs data)
|
||||
{
|
||||
if (SendAgainHandler == null) return;
|
||||
try
|
||||
{
|
||||
SendAgainHandler(sender, data);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.Error("SendAgainHandler(...) failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void DoSendAgain(object sender, PreviousResultIdEventArgs data)
|
||||
{
|
||||
foreach (var b in batches)
|
||||
{
|
||||
if (b.BatchNr == data.BatchNr)
|
||||
{
|
||||
#if ORACLE_DB
|
||||
//System.IO.StreamWriter logger;
|
||||
//string fname = "C:\\TBF\\Logs\\test.log";
|
||||
//try { logger = new System.IO.StreamWriter(System.IO.File.Create(fname)); }
|
||||
//catch
|
||||
//{
|
||||
// logger = null;
|
||||
// log.ErrorFormat("Was not able to open LU log file {0}", fname);
|
||||
//}
|
||||
//Database.WriteLogsToDisk(logger, b);
|
||||
|
||||
using (ISession configSession = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config))
|
||||
{
|
||||
IList<Config.Entities.Component> cmpntEntities = configSession.QueryOver<Config.Entities.Component>()
|
||||
.OrderBy(x => x.ItemNr).Asc
|
||||
.Where(x => (x.ClassName == "Sensus-Oracle-Database"))
|
||||
.List<Config.Entities.Component>();
|
||||
|
||||
if (cmpntEntities.Count == 0)
|
||||
{
|
||||
MessageBox.Show("Nepodarilo sa uložiť, neviem načítať nastavenia Oracle databázy",
|
||||
Strings.Error,
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
TBF.BenchControl.DB.SensusOracle.DatabaseCfg cfg = TBF.BenchControl.ComponentCfgBase.CreateFromDbEntity(DatabaseCfg.Serializer, cmpntEntities[0], null)
|
||||
as TBF.BenchControl.DB.SensusOracle.DatabaseCfg;
|
||||
|
||||
MessageBox.Show(string.Format("Výsledky budú zapísané do '{0}' databázy", cfg.DBUsed),
|
||||
Strings.Information,
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
|
||||
OracleConnection conn = (cfg.DBUsed == DBUsed.Production)
|
||||
? new OracleConnection("Data Source=STARA01.WORLD;User Id=deltachef;Password=deltachef;")
|
||||
: new OracleConnection("Data Source=STARA_TEST.WORLD;User Id=deltachef;Password=deltachef;");
|
||||
|
||||
if (Database.WriteResultsToDatabase(conn, b, true) == Retv.OK)
|
||||
{
|
||||
b.RsltsSent = true; /// Result was successfully sent
|
||||
session.SaveOrUpdate(b); /// Update MySQL DB
|
||||
session.Flush();
|
||||
(sender as PreviousResultCtrl).Sent = true; /// Update UI
|
||||
Redraw();
|
||||
}
|
||||
}
|
||||
#elif MUNICH
|
||||
string docVersion = string.Empty;
|
||||
foreach (var cmp in TBF.BenchControl.StateMachine.Components)
|
||||
{
|
||||
if (cmp.ClassName == "ResultsPrinter4Munich")
|
||||
{
|
||||
docVersion = (cmp as TBF.BenchControl.ResultsPrinters.Munich.Printer).Version;
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach (var wm in b.WaterMeters)
|
||||
{
|
||||
new Results.Output.Printers.Munich.MunichPrintDocument(docVersion, wm, Config.Entities.PageOrientation.Portrait).Print();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public event EventHandler<PreviousResultIdEventArgs> ShowResultsHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Called from PreviousResultCtrl when 'Show' button pressed.
|
||||
/// </summary>
|
||||
public void OnShowResults(object sender, PreviousResultIdEventArgs data)
|
||||
{
|
||||
if (ShowResultsHandler == null) return;
|
||||
try { ShowResultsHandler(sender, data); }
|
||||
catch (Exception e) { log.Error("ShowResultsHandler(...) failed", e); }
|
||||
}
|
||||
|
||||
public void DoShowResults(object sender, PreviousResultIdEventArgs data)
|
||||
{
|
||||
Results.Forms.BatchResultsDlg dlg = new Results.Forms.BatchResultsDlg();
|
||||
dlg.PopupResultsLeft = Program.LocalSettings.PopupResultsLeft;
|
||||
dlg.PopupResultsTop = Program.LocalSettings.PopupResultsTop;
|
||||
dlg.PopupResultsWidth = Program.LocalSettings.PopupResultsWidth;
|
||||
dlg.PopupResultsHeight = Program.LocalSettings.PopupResultsHeight;
|
||||
|
||||
dlg.MetersArrangement = Program.LocalSettings.ResultsConfigMeters;
|
||||
dlg.TestsArrangement = Program.LocalSettings.ResultsConfigTests;
|
||||
dlg.NrMetersInOneGroup = Math.Max(1, Program.LocalSettings.ResultsConfigMetersInOneGroup);
|
||||
|
||||
dlg.RsltItems_Screen_SingleWM = Results.WMeterRsltItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Screen_SingleWM);
|
||||
dlg.RsltItems_Screen_CombinedWM = Results.WMeterRsltItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Screen_CombinedWM);
|
||||
dlg.RsltItems_Screen_HeatM = Results.WMeterRsltItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Screen_HeatM);
|
||||
dlg.RsltsClmnWidths = Program.LocalSettings.RsltsClmnWidths;
|
||||
|
||||
foreach (var b in batches)
|
||||
{
|
||||
if (b.BatchNr == data.BatchNr)
|
||||
{
|
||||
dlg.Results = Results.BatchResults.FromBatch(b);
|
||||
dlg.Text = string.Format(Strings.Results_of_batch_0, b.BatchNr);
|
||||
dlg.Show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//if (dlg.PopupResultsLeft != Program.LocalSettings.PopupResultsLeft ||
|
||||
// dlg.PopupResultsTop != Program.LocalSettings.PopupResultsTop ||
|
||||
// dlg.PopupResultsWidth != Program.LocalSettings.PopupResultsWidth ||
|
||||
// dlg.PopupResultsHeight != Program.LocalSettings.PopupResultsHeight)
|
||||
//{
|
||||
// Program.LocalSettings.PopupResultsLeft = dlg.PopupResultsLeft;
|
||||
// Program.LocalSettings.PopupResultsTop = dlg.PopupResultsTop;
|
||||
// Program.LocalSettings.PopupResultsWidth = dlg.PopupResultsWidth;
|
||||
// Program.LocalSettings.PopupResultsHeight = dlg.PopupResultsHeight;
|
||||
// Program.LocalSettings.Save();
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
void Redraw()
|
||||
{
|
||||
SuspendLayout();
|
||||
|
||||
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
|
||||
flowLayoutPanel1.Controls.Clear();
|
||||
|
||||
if (batches == null || batches.Count == 0) return;
|
||||
|
||||
foreach (var b in batches)
|
||||
{
|
||||
int passedCount = 0;
|
||||
int failedCount = 0;
|
||||
foreach (var wm in b.WaterMeters)
|
||||
{
|
||||
if (wm.Passed) { passedCount++; } else { failedCount++; }
|
||||
}
|
||||
|
||||
if (passedCount + failedCount == 0) continue;
|
||||
|
||||
|
||||
flowLayoutPanel1.Controls.Add(new PreviousResultCtrl(this,
|
||||
b.BatchNr,
|
||||
b.StartTime,
|
||||
b.EndTime,
|
||||
b.ProcedureName,
|
||||
b.WaterMeters[0].PurchaseOrder,
|
||||
passedCount,
|
||||
failedCount,
|
||||
b.RsltsSent,
|
||||
reloadEn));
|
||||
}
|
||||
|
||||
ResumeLayout();
|
||||
}
|
||||
|
||||
private void closeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user