243 lines
7.4 KiB
C#
243 lines
7.4 KiB
C#
///
|
|
/// Copyright (c) 2026 Sensus Slovensko a.s.
|
|
///
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.Output.DB.ResultsWriter
|
|
{
|
|
public partial class ResultsWriterCfgCtrl : Configs.ConfigCtrlUtils, IComponentCfgCtrl
|
|
{
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
ResultsWriterCfg config;
|
|
IList<Component> cmpntEntities;
|
|
|
|
bool resultsConfigChanged;
|
|
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as ResultsWriterCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public ResultsWriterCfgCtrl(IList<Component> cmpntEntities)
|
|
{
|
|
InitializeComponent();
|
|
this.cmpntEntities = cmpntEntities;
|
|
}
|
|
|
|
private void ResultsWriterCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
if (config == null) return;
|
|
Redraw();
|
|
}
|
|
|
|
public void Closing()
|
|
{
|
|
}
|
|
|
|
void Redraw()
|
|
{
|
|
if (config == null) return;
|
|
|
|
config.UpdateRuntimeModel();
|
|
|
|
classNameLabel.Text = config.Factory.ClassName;
|
|
nameTextBox.Text = config.Name;
|
|
enabledCheckBox.Checked = config.Enabled;
|
|
storageNameTextBox.Text = config.StorageName;
|
|
|
|
parentComboBox.Items.Clear();
|
|
parentComboBox.Items.Add(string.Empty);
|
|
|
|
if (cmpntEntities != null)
|
|
{
|
|
foreach (Component cmpnt in cmpntEntities)
|
|
{
|
|
if (cmpnt == null) continue;
|
|
|
|
// for now, a simple filter by name/classname
|
|
if (cmpnt.ClassName != null &&
|
|
cmpnt.ClassName.IndexOf("UniDataStorageWriter") >= 0)
|
|
{
|
|
parentComboBox.Items.Add(cmpnt.Name);
|
|
}
|
|
}
|
|
}
|
|
|
|
parentComboBox.Text = config.ParentName;
|
|
|
|
selectedItemsLabel.Text = string.Format(
|
|
"{0} selected item(s)",
|
|
config.SelectedItems != null ? config.SelectedItems.Count : 0);
|
|
|
|
resultsConfigChanged = false;
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
enabledCheckBox.Enabled = true;
|
|
parentComboBox.Enabled = true;
|
|
storageNameTextBox.Enabled = true;
|
|
configureResultsButton.Enabled = true;
|
|
previewRequestButton.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
if (string.IsNullOrEmpty(nameTextBox.Text))
|
|
{
|
|
message = "Component name is empty.";
|
|
return CfgUpdateFlags.Error;
|
|
}
|
|
|
|
if (enabledCheckBox.Checked && string.IsNullOrEmpty(parentComboBox.Text))
|
|
{
|
|
message = "Parent UniDataStorageWriter is not selected.";
|
|
return CfgUpdateFlags.Error;
|
|
}
|
|
|
|
if (enabledCheckBox.Checked && string.IsNullOrEmpty(storageNameTextBox.Text))
|
|
{
|
|
message = "Storage name is empty.";
|
|
return CfgUpdateFlags.Error;
|
|
}
|
|
|
|
return CfgUpdateFlags.None;
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateCfg()
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
if (config == null) return CfgUpdateFlags.Error;
|
|
|
|
if (config.Name != nameTextBox.Text)
|
|
{
|
|
config.Name = nameTextBox.Text;
|
|
flags |= CfgUpdateFlags.AnyChange | CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
if (config.ParentName != parentComboBox.Text)
|
|
{
|
|
config.ParentName = parentComboBox.Text;
|
|
flags |= CfgUpdateFlags.AnyChange | CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
flags |= UpdateDifferent(
|
|
ref config.Enabled,
|
|
enabledCheckBox.Checked,
|
|
CfgUpdateFlags.AnyChange | CfgUpdateFlags.RestartRqrd);
|
|
|
|
flags |= UpdateDifferent(
|
|
ref config.StorageName,
|
|
storageNameTextBox.Text,
|
|
CfgUpdateFlags.AnyChange | CfgUpdateFlags.RestartRqrd);
|
|
|
|
if (resultsConfigChanged)
|
|
{
|
|
flags |= CfgUpdateFlags.AnyChange | CfgUpdateFlags.RestartRqrd;
|
|
resultsConfigChanged = false;
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
private void configureResultsButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (config == null) return;
|
|
|
|
using (ResultsWriterResultsDlg dlg = new ResultsWriterResultsDlg())
|
|
{
|
|
dlg.SelectedItems = config.SelectedItems;
|
|
|
|
if (dlg.ShowDialog(this) == DialogResult.OK)
|
|
{
|
|
config.SelectedItems = new List<Results.WMeterRsltItemSpec>(dlg.SelectedItems);
|
|
config.UpdateSerializableModel();
|
|
resultsConfigChanged = true;
|
|
|
|
selectedItemsLabel.Text = string.Format(
|
|
"{0} selected item(s)",
|
|
config.SelectedItems != null ? config.SelectedItems.Count : 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void previewRequestButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (config == null) return;
|
|
|
|
Results.Entities.Batch batch = CreateSimulationBatch();
|
|
|
|
if (batch == null || batch.WaterMeters == null || batch.WaterMeters.Count == 0)
|
|
{
|
|
MessageBox.Show(
|
|
"No current batch results are available.",
|
|
"ResultsWriter",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Information);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
config.UpdateRuntimeModel();
|
|
|
|
ResultsWriter writer = new ResultsWriter(config);
|
|
writer.InitializeParent();
|
|
writer.WriteBatchResults(batch);
|
|
|
|
MessageBox.Show(
|
|
"Current batch was written by ResultsWriter.",
|
|
"ResultsWriter",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(
|
|
ex.Message,
|
|
"ResultsWriter write failed",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private Results.Entities.Batch CreateSimulationBatch()
|
|
{
|
|
Results.Entities.Batch batch = new Results.Entities.Batch();
|
|
|
|
batch.BatchNr = 999999;
|
|
batch.ProcedureName = "ResultsWriter simulation";
|
|
batch.StartTime = DateTime.Now;
|
|
batch.EndTime = DateTime.Now;
|
|
batch.TestBenchName = "Mexico";
|
|
|
|
Results.Entities.WaterMeter wm1 = new Results.Entities.WaterMeter();
|
|
wm1.Batch = batch;
|
|
wm1.WMPosition = 1;
|
|
wm1.SerialNr = "SN000001";
|
|
batch.WaterMeters.Add(wm1);
|
|
|
|
Results.Entities.WaterMeter wm2 = new Results.Entities.WaterMeter();
|
|
wm2.Batch = batch;
|
|
wm2.WMPosition = 2;
|
|
wm2.SerialNr = "SN000002";
|
|
batch.WaterMeters.Add(wm2);
|
|
|
|
return batch;
|
|
}
|
|
}
|
|
} |