215 lines
6.6 KiB
C#
215 lines
6.6 KiB
C#
///
|
|
/// Copyright (c) 2013-2019 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
using Config.Entities;
|
|
using TBF.BenchControl.Generic;
|
|
using TBF.UI.Bench.Components;
|
|
|
|
namespace TBF.BenchControl.Elde.TempMeter
|
|
{
|
|
public partial class TempMeterCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
static string lastImportFileName;
|
|
|
|
ComponentParametersDlg parent;
|
|
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
TempMeterCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as TempMeterCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public TempMeterCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void TempMeterCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
parent = ParentForm as ComponentParametersDlg;
|
|
if (parent == null) return;
|
|
|
|
if (parent.CmpntEntities != null)
|
|
{
|
|
foreach (var cmpnt in parent.CmpntEntities)
|
|
{
|
|
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Elde.ControlBoardFactory)
|
|
{
|
|
parentNameComboBox.Items.Add(cmpnt.Name);
|
|
}
|
|
}
|
|
}
|
|
|
|
Redraw();
|
|
}
|
|
|
|
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;
|
|
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
|
|
positionTextBox.Text = config.Idx0.ToString();
|
|
a1TextBox.Text = config.A1.ToString();
|
|
a2TextBox.Text = config.A2.ToString();
|
|
a3TextBox.Text = config.A3.ToString();
|
|
a4TextBox.Text = config.A4.ToString();
|
|
a5TextBox.Text = config.A5.ToString();
|
|
defaultTempTextBox.Text = config.DefaultTemperature.ToString();
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
parentNameComboBox.Enabled = true;
|
|
positionTextBox.Enabled = true;
|
|
importButton.Enabled = true;
|
|
a1TextBox.Enabled = true;
|
|
a2TextBox.Enabled = true;
|
|
a3TextBox.Enabled = true;
|
|
a4TextBox.Enabled = true;
|
|
a5TextBox.Enabled = true;
|
|
defaultTempTextBox.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
int dummy;
|
|
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Parent Name'";
|
|
}
|
|
if (!int.TryParse(positionTextBox.Text, out dummy) || dummy < 0 || dummy > 15)
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Position' should be between 0 and 15";
|
|
}
|
|
|
|
double fdummy;
|
|
if (!Utils.TryParseEDouble(a1TextBox.Text, out fdummy))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'A1' is not valid";
|
|
}
|
|
|
|
if (!Utils.TryParseEDouble(a2TextBox.Text, out fdummy))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'A2' is not valid";
|
|
}
|
|
|
|
if (!Utils.TryParseEDouble(a3TextBox.Text, out fdummy))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'A3' is not valid";
|
|
}
|
|
|
|
if (!Utils.TryParseEDouble(a4TextBox.Text, out fdummy))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'A4' is not valid";
|
|
}
|
|
|
|
if (!Utils.TryParseEDouble(a5TextBox.Text, out fdummy))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'A5' is not valid";
|
|
}
|
|
|
|
if (!Utils.TryParseEDouble(defaultTempTextBox.Text, out fdummy))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "'Default temperature' is not valid";
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateCfg()
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd;
|
|
|
|
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
|
|
|
config.Name = nameTextBox.Text;
|
|
config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
|
|
config.Idx0 = int.Parse(positionTextBox.Text);
|
|
bool updateOk = Utils.TryParseEDouble(a1TextBox.Text, out config.A1) &&
|
|
Utils.TryParseEDouble(a2TextBox.Text, out config.A2) &&
|
|
Utils.TryParseEDouble(a3TextBox.Text, out config.A3) &&
|
|
Utils.TryParseEDouble(a4TextBox.Text, out config.A4) &&
|
|
Utils.TryParseEDouble(a5TextBox.Text, out config.A5) &&
|
|
Utils.TryParseEDouble(defaultTempTextBox.Text, out config.DefaultTemperature);
|
|
|
|
return flags;
|
|
}
|
|
|
|
private void importButton_Click(object sender, EventArgs e)
|
|
{
|
|
OpenFileDialog dlg = new OpenFileDialog();
|
|
if (!string.IsNullOrEmpty(lastImportFileName)) dlg.FileName = lastImportFileName;
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
using (TextReader reader = new StreamReader(dlg.FileName))
|
|
{
|
|
try
|
|
{
|
|
string startOfLine = string.Format("Calch{0} =", positionTextBox.Text);
|
|
bool channelFound = false;
|
|
string line;
|
|
|
|
do
|
|
{
|
|
line = reader.ReadLine();
|
|
if (!string.IsNullOrEmpty(line) && (line.IndexOf(startOfLine) == 0))
|
|
{
|
|
string[] factors = line.Substring(startOfLine.Length).Split(new char[] { ',' });
|
|
int count = factors.Length;
|
|
double tmp;
|
|
if (count >= 1 && Utils.TryParseEDouble(factors[0].Trim(), out tmp)) a1TextBox.Text = factors[0].Trim();
|
|
if (count >= 2 && Utils.TryParseEDouble(factors[1].Trim(), out tmp)) a2TextBox.Text = factors[1].Trim();
|
|
if (count >= 3 && Utils.TryParseEDouble(factors[2].Trim(), out tmp)) a3TextBox.Text = factors[2].Trim();
|
|
if (count >= 4 && Utils.TryParseEDouble(factors[3].Trim(), out tmp)) a4TextBox.Text = factors[3].Trim();
|
|
if (count >= 5 && Utils.TryParseEDouble(factors[4].Trim(), out tmp)) a5TextBox.Text = factors[4].Trim();
|
|
channelFound = true;
|
|
lastImportFileName = dlg.FileName;
|
|
break;
|
|
}
|
|
}
|
|
while (line != null);
|
|
|
|
if (!channelFound)
|
|
{
|
|
MessageBox.Show(string.Format("Calibration factors for channel {0} not found.", positionTextBox.Text),
|
|
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
MessageBox.Show("Wrong file format, import failed.",
|
|
"Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|