173 lines
4.3 KiB
C#
173 lines
4.3 KiB
C#
///
|
|
/// Copyright (c) 2019 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using Config.Entities;
|
|
using TBF.BenchControl.Generic;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.BenchControl.TestMethods.ManualEntry
|
|
{
|
|
public partial class ManualEntryCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(ManualEntryCfgCtrl));
|
|
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
public bool Compound;
|
|
|
|
ManualEntryCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as ManualEntryCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
string header;
|
|
string[] commonItems;
|
|
string[] testItems;
|
|
|
|
public ManualEntryCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
Localize();
|
|
}
|
|
|
|
private void ManualEntryCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
for (TBF.BenchControl.Output.Culture s = 0; s < TBF.BenchControl.Output.Culture.Count; s++)
|
|
{
|
|
cultureComboBox.Items.Add(s.ToString());
|
|
}
|
|
testItems = config.Items;
|
|
Redraw();
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
nameLabel.Text = Strings.Name;
|
|
cultureLabel.Text = "Culture";
|
|
promptLabel.Text = "Prompt";
|
|
itemsButton.Text = "Items";
|
|
}
|
|
|
|
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;
|
|
cultureComboBox.Text = config.Culture.ToString();
|
|
promptTextBox.Text = config.Prompt;
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
cultureComboBox.Enabled = true;
|
|
promptTextBox.Enabled = true;
|
|
itemsButton.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
if (!cultureComboBox.Items.Contains(cultureComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid culture";
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(promptTextBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Prompt field is empty";
|
|
}
|
|
|
|
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 | CfgUpdateFlags.AnyChange);
|
|
}
|
|
|
|
for (TBF.BenchControl.Output.Culture i = 0; i < TBF.BenchControl.Output.Culture.Count; i++)
|
|
{
|
|
if (i.ToString().Equals(cultureComboBox.Text) && (config.Culture != i))
|
|
{
|
|
config.Culture = i;
|
|
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (config.Prompt != promptTextBox.Text)
|
|
{
|
|
config.Prompt = promptTextBox.Text;
|
|
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
}
|
|
|
|
if (config.Items != testItems)
|
|
{
|
|
config.Items = testItems;
|
|
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
|
}
|
|
|
|
|
|
if ((flags & CfgUpdateFlags.InvokeCfgChange) != 0)
|
|
{
|
|
Component.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.CfgChange, config));
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
private void itemsButton_Click(object sender, EventArgs e)
|
|
{
|
|
Results.Forms.ManualEntryConfigDlg dlg = new Results.Forms.ManualEntryConfigDlg()
|
|
{
|
|
SelectedItems = Results.ManualEntryItemSpec.FromStrArray(testItems),
|
|
};
|
|
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
testItems = Results.ManualEntryItemSpec.ToStrArray(dlg.SelectedItems);
|
|
}
|
|
}
|
|
|
|
#region Configuration Change Handling
|
|
|
|
public static void OnCmdResponse(object sender, CmdResponseArgs args)
|
|
{
|
|
if (CmdResponseHandler == null) return;
|
|
try { CmdResponseHandler(sender, args); }
|
|
catch (Exception e) { log.Error("CmdResponseHandler(...) failed", e); }
|
|
}
|
|
|
|
public static event EventHandler<CmdResponseArgs> CmdResponseHandler;
|
|
|
|
public void StartResponseHandler() { }
|
|
public void StopResponseHandler() { }
|
|
|
|
#endregion Configuration Change Handling
|
|
}
|
|
}
|