332 lines
11 KiB
C#
332 lines
11 KiB
C#
///
|
|
/// Copyright (c) 2016 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.BenchControl.Generic;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.BenchControl.Output.FileWriters.Enhanced
|
|
{
|
|
public partial class WriterCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(WriterCfgCtrl));
|
|
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
public bool Compound;
|
|
|
|
WriterCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as WriterCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
string header;
|
|
string[] commonItems;
|
|
string[] testItems;
|
|
string footer;
|
|
|
|
public WriterCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
Localize();
|
|
}
|
|
|
|
private void WriterCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
for (Separator s = 0; s < Separator.Count; s++) separatorComboBox.Items.Add(s.ToString());
|
|
for (YearFolders s = 0; s < YearFolders.Count; s++) yearFoldersComboBox.Items.Add(s.ToString());
|
|
for (MonthFolders s = 0; s < MonthFolders.Count; s++) monthFoldersComboBox.Items.Add(s.ToString());
|
|
for (DayFolders s = 0; s < DayFolders.Count; s++) dayFoldersComboBox.Items.Add(s.ToString());
|
|
|
|
for (int i = 0; i < (int)Separator.Count; i++)
|
|
{
|
|
separatorComboBox.Items.Add(((Separator)i).ToString());
|
|
}
|
|
|
|
header = config.Header;
|
|
commonItems = config.CommonItems;
|
|
testItems = config.SelectedItems;
|
|
footer = config.Footer;
|
|
|
|
Redraw();
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
nameLabel.Text = Strings.Name;
|
|
destinationLabel.Text = "Destination";
|
|
destination2Label.Text = "Destination" + " 2";
|
|
yearFoldersLabel.Text = "Year folders";
|
|
monthFoldersLabel.Text = "Month folders";
|
|
dayFoldersLabel.Text = "Day folders";
|
|
fileNameFmtLabel.Text = "File name format";
|
|
separatorLabel.Text = "Separator";
|
|
eliminateSpacesCheckBox.Text = "No spaces";
|
|
headerButton.Text = Strings.Header;
|
|
commonItemsButton.Text = "Common items";
|
|
testItemsButton.Text = "Test items";
|
|
footerButton.Text = Strings.Footer;
|
|
upgradeWizardButton.Text = "Upgrade wizard";
|
|
}
|
|
|
|
public void Closing()
|
|
{
|
|
}
|
|
|
|
void Redraw()
|
|
{
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
classNameLabel.Text = config.Factory.ClassName;
|
|
nameTextBox.Text = config.Name;
|
|
destinationTextBox.Text = config.DestinationPath;
|
|
destination2TextBox.Text = config.DestinationPath2;
|
|
yearFoldersComboBox.Text = config.YearFolders.ToString();
|
|
monthFoldersComboBox.Text = config.MonthFolders.ToString();
|
|
dayFoldersComboBox.Text = config.DayFolders.ToString();
|
|
fileNameFmtTextBox.Text = config.FileNameFormat;
|
|
separatorComboBox.Text = config.Separator.ToString();
|
|
eliminateSpacesCheckBox.Checked = config.EliminateSpaces;
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
destinationTextBox.Enabled = true;
|
|
destinationButton.Enabled = true;
|
|
destination2TextBox.Enabled = true;
|
|
destination2Button.Enabled = true;
|
|
yearFoldersComboBox.Enabled = true;
|
|
monthFoldersComboBox.Enabled = true;
|
|
dayFoldersComboBox.Enabled = true;
|
|
fileNameFmtTextBox.Enabled = true;
|
|
separatorComboBox.Enabled = true;
|
|
eliminateSpacesCheckBox.Enabled = true;
|
|
headerButton.Enabled = true;
|
|
commonItemsButton.Enabled = true;
|
|
testItemsButton.Enabled = true;
|
|
footerButton.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
if (!yearFoldersComboBox.Items.Contains(yearFoldersComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid year folders selection";
|
|
}
|
|
|
|
if (!monthFoldersComboBox.Items.Contains(monthFoldersComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid month folders selection";
|
|
}
|
|
|
|
if (!dayFoldersComboBox.Items.Contains(dayFoldersComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid day folder selection";
|
|
}
|
|
|
|
if (!separatorComboBox.Items.Contains(separatorComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid separator";
|
|
}
|
|
return flags;
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateCfg()
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
|
|
|
if (config.Name != nameTextBox.Text) { config.Name = nameTextBox.Text; flags = CfgUpdateFlags.RestartRqrd; }
|
|
|
|
if (config.DestinationPath != destinationTextBox.Text)
|
|
{
|
|
config.DestinationPath = destinationTextBox.Text;
|
|
if (!config.DestinationPath.EndsWith("\\")) config.DestinationPath += "\\";
|
|
flags = CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
if (config.DestinationPath2 != destination2TextBox.Text)
|
|
{
|
|
config.DestinationPath2 = destination2TextBox.Text;
|
|
if (!config.DestinationPath2.EndsWith("\\")) config.DestinationPath2 += "\\";
|
|
flags = CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
for (YearFolders i = 0; i < YearFolders.Count; i++)
|
|
{
|
|
if (i.ToString().Equals(yearFoldersComboBox.Text) && (config.YearFolders != i))
|
|
{
|
|
config.YearFolders = i;
|
|
flags = CfgUpdateFlags.RestartRqrd;
|
|
break;
|
|
}
|
|
}
|
|
|
|
for (MonthFolders i = 0; i < MonthFolders.Count; i++)
|
|
{
|
|
if (i.ToString().Equals(monthFoldersComboBox.Text) && (config.MonthFolders != i))
|
|
{
|
|
config.MonthFolders = i;
|
|
flags = CfgUpdateFlags.RestartRqrd;
|
|
break;
|
|
}
|
|
}
|
|
|
|
for (DayFolders i = 0; i < DayFolders.Count; i++)
|
|
{
|
|
if (i.ToString().Equals(dayFoldersComboBox.Text) && (config.DayFolders != i))
|
|
{
|
|
config.DayFolders = i;
|
|
flags = CfgUpdateFlags.RestartRqrd;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (config.FileNameFormat != fileNameFmtTextBox.Text)
|
|
{
|
|
config.FileNameFormat = fileNameFmtTextBox.Text;
|
|
flags = CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
for (Separator i = 0; i < Separator.Count; i++)
|
|
{
|
|
if (i.ToString().Equals(separatorComboBox.Text) && (config.Separator != i))
|
|
{
|
|
config.Separator = i;
|
|
flags = CfgUpdateFlags.RestartRqrd;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (config.EliminateSpaces != eliminateSpacesCheckBox.Checked)
|
|
{
|
|
config.EliminateSpaces = eliminateSpacesCheckBox.Checked;
|
|
flags = CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
if (config.CommonItems != commonItems)
|
|
{
|
|
config.CommonItems = commonItems;
|
|
flags = CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
if (config.SelectedItems != testItems)
|
|
{
|
|
config.SelectedItems = testItems;
|
|
flags = CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
if (config.Header != header)
|
|
{
|
|
config.Header = header;
|
|
flags = CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
if (config.Footer != footer)
|
|
{
|
|
config.Footer = footer;
|
|
flags = CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
private void destinationButton_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void headerButton_Click(object sender, EventArgs e)
|
|
{
|
|
HeaderFooterDlg dlg = new HeaderFooterDlg(true, header.Replace("~", "\r\n"));
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
header = dlg.EditedText.Replace("\r\n", "~");
|
|
}
|
|
}
|
|
|
|
private void commonItemsButton_Click(object sender, EventArgs e)
|
|
{
|
|
Results.Forms.ResultsConfigDlg dlg = new Results.Forms.ResultsConfigDlg();
|
|
dlg.Compound = config.Factory.ClassName.Contains("Compound");
|
|
dlg.SelectedItems = Results.WMeterRsltItemSpec.FromStrArray(commonItems);
|
|
dlg.AvailableItems = new List<Results.WMeterRsltItemSpec>();
|
|
foreach (var v in Results.WMeterRsltItemSpec.AllItems) dlg.AvailableItems.Add(v);
|
|
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
commonItems = Results.WMeterRsltItemSpec.ToStrArray(dlg.SelectedItems);
|
|
}
|
|
}
|
|
|
|
private void testItemsButton_Click(object sender, EventArgs e)
|
|
{
|
|
ResultsConfigDlg dlg = new ResultsConfigDlg() { MetersKind = config.MetersKind,
|
|
SelectedItems = Results.ItemSpec.FromStrArray(testItems),
|
|
AvailableItems = new List<Results.ItemSpec>() };
|
|
|
|
foreach (var v in Results.ItemSpec.AllItems) dlg.AvailableItems.Add(v);
|
|
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
testItems = Results.ItemSpec.ToStrArray(dlg.SelectedItems);
|
|
}
|
|
}
|
|
|
|
private void footerButton_Click(object sender, EventArgs e)
|
|
{
|
|
HeaderFooterDlg dlg = new HeaderFooterDlg(false, footer.Replace("~", "\r\n"));
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
footer = dlg.EditedText.Replace("\r\n", "~");
|
|
}
|
|
}
|
|
|
|
private void upgradeWizardButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (MessageBox.Show("This wizzard will overwrite curent settings." + Environment.NewLine +
|
|
"Do you want to continue?",
|
|
"Confirmation",
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
///
|
|
/// Use legacy common items (English)
|
|
///
|
|
commonItems = new string[] {
|
|
"3~Batch number:~~None~~~0~",
|
|
"72~Date and time:~~None~{0:yyyy.MM.dd HH:mm}~~0~",
|
|
"2~Procedure:~~None~~~0~",
|
|
"66~User:~~None~~~0~",
|
|
"26~Ambient temperature:~~C~{0} °C~F1~0~",
|
|
"27~Ambient pressure:~~mbar~{0} mbar~F0~0~",
|
|
"28~Ambient humidity:~~Pct~{0} %~F0~0~",
|
|
};
|
|
commonItemsButton_Click(this, null);
|
|
|
|
///
|
|
/// Use legacy test inems from local settings
|
|
///
|
|
testItems = config.Factory.ClassName.Contains("Compound") ? Program.LocalSettings.RsltItems_Disk_CombinedWM
|
|
: Program.LocalSettings.RsltItems_Disk_SingleWM;
|
|
testItemsButton_Click(this, null);
|
|
}
|
|
}
|
|
}
|
|
}
|