358 lines
12 KiB
C#
358 lines
12 KiB
C#
///
|
|
/// Copyright (c) 2019 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Rig.GenericDevices;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.UI.Procedures.TestWizard
|
|
{
|
|
public partial class TestProfileSelection : Form
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(TestProfileSelection));
|
|
|
|
IList<Profile> profiles;
|
|
|
|
public Profile SelectedProfile;
|
|
public double Qn;
|
|
public string MetroClass;
|
|
public double QpQiRatio;
|
|
|
|
public TestProfileSelection(IList<Profile> profiles)
|
|
{
|
|
this.profiles = profiles;
|
|
|
|
InitializeComponent();
|
|
|
|
listView.Columns.Add(Strings.Name, 70);
|
|
listView.Columns.Add(Strings.Part, 40);
|
|
listView.Columns.Add(string.Format("{0} [m3/h]", Strings.Q_tg), 80);
|
|
listView.Columns.Add(string.Format("{0} [m3/h]", Strings.Q_from), 80);
|
|
listView.Columns.Add(string.Format("{0} [m3/h]", Strings.Q_to), 70);
|
|
listView.Columns.Add(Strings.Err_limit_neg_pct_chdr, 80);
|
|
listView.Columns.Add(Strings.Err_limit_pos_pct_chdr, 80);
|
|
|
|
if (profiles != null)
|
|
{
|
|
foreach (var p in profiles) profileComboBox.Items.Add(p.Name);
|
|
}
|
|
|
|
foreach (var s in new string[] { "10", "25", "50", "100", "250" }) qpQiRatioComboBox.Items.Add(s);
|
|
|
|
nextButton.Enabled = false;
|
|
}
|
|
|
|
private void TestProfileSelection_Load(object sender, EventArgs e)
|
|
{
|
|
Localize();
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
Text = Strings.Test_profiles_selection;
|
|
nextButton.Text = Strings.NextBtnText;
|
|
cancelButton.Text = Strings.CancelBtnText;
|
|
}
|
|
|
|
void RedrawQn(Profile profile)
|
|
{
|
|
switch (profile.ProfileType)
|
|
{
|
|
case ProfileType.Q3R:
|
|
qnLabel.Text = "Q3";
|
|
break;
|
|
case ProfileType.QpQi:
|
|
qnLabel.Text = "qp";
|
|
break;
|
|
case ProfileType.QnClassColdWater:
|
|
case ProfileType.QnClassHotWater:
|
|
case ProfileType.Manual:
|
|
default:
|
|
qnLabel.Text = "Qn";
|
|
break;
|
|
}
|
|
}
|
|
|
|
void RedrawMClassCombo(Profile profile)
|
|
{
|
|
string oriText = metroClassComboBox.Text;
|
|
metroClassComboBox.Items.Clear();
|
|
bool clearTextFlag = true;
|
|
|
|
if (profile != null)
|
|
{
|
|
string[] mClasses;
|
|
switch (profile.ProfileType)
|
|
{
|
|
default:
|
|
case ProfileType.Q3R:
|
|
mClasses = new string[] { "R40", "R50", "R63", "R80", "R100", "R125", "R160", "R200", "R250", "R315",
|
|
"R400", "R500", "R630", "R800", "R1000", "R1250", "R1600", "R2000", "R2500" };
|
|
break;
|
|
case ProfileType.QnClassColdWater:
|
|
mClasses = new string[] { "A", "B", "C" };
|
|
break;
|
|
case ProfileType.QnClassHotWater:
|
|
mClasses = new string[] { "A", "B", "C", "D" };
|
|
break;
|
|
case ProfileType.QpQi:
|
|
mClasses = new string[] { "1", "2", "3" };
|
|
break;
|
|
}
|
|
|
|
foreach (var mc in mClasses)
|
|
{
|
|
metroClassComboBox.Items.Add(mc);
|
|
if (oriText == mc) clearTextFlag = false;
|
|
}
|
|
}
|
|
|
|
if (clearTextFlag) metroClassComboBox.Text = string.Empty;
|
|
}
|
|
|
|
|
|
void RedrawPTests(Profile profile)
|
|
{
|
|
listView.Items.Clear();
|
|
|
|
if (profile == null) return;
|
|
|
|
try
|
|
{
|
|
foreach (var ptest in profile.Tests)
|
|
{
|
|
Medium medium = (profile.ProfileType == ProfileType.QnClassHotWater) ? Medium.HotWater : Medium.ColdWater;
|
|
|
|
double Qtg;
|
|
if (ptest.Name.ToLower().Contains("q4") || ptest.Name.ToLower().Contains("qmax"))
|
|
{
|
|
Qtg = Config.Utils.GetQ4Qmax(Qn, MetroClass, medium, ptest.CoefQto);
|
|
}
|
|
else if (ptest.Name.ToLower().Contains("q3") || ptest.Name.ToLower().Contains("qn") || ptest.Name.ToLower().Equals("qp"))
|
|
{
|
|
Qtg = Qn;
|
|
}
|
|
else if (ptest.Name.ToLower().Contains("q2") || ptest.Name.ToLower().Contains("qt"))
|
|
{
|
|
Qtg = Config.Utils.GetQ2Qt(Qn, MetroClass, medium, ptest.CoefQto);
|
|
}
|
|
else if (ptest.Name.ToLower().Contains("q1") || ptest.Name.ToLower().Contains("qmin"))
|
|
{
|
|
Qtg = Config.Utils.GetQ1Qmin(Qn, MetroClass, medium, ptest.CoefQto);
|
|
}
|
|
else if (ptest.Name.ToLower().Contains("0,1qp") || ptest.Name.ToLower().Contains("0.1qp"))
|
|
{
|
|
Qtg = 0.1 * Qn;
|
|
}
|
|
else if (ptest.Name.ToLower().Contains("qi"))
|
|
{
|
|
Qtg = Qn / QpQiRatio;
|
|
}
|
|
else
|
|
{
|
|
Qtg = Qn; /// Manual flow selection: CoefQfrom and CoefQto are used to calculate Qfrom and Qto from Qn
|
|
}
|
|
|
|
double Qfrom = Qtg * ptest.CoefQfrom;
|
|
double Qto = Qtg * ptest.CoefQto;
|
|
|
|
ListViewItem lvi;
|
|
if (profile.ProfileType != ProfileType.QpQi)
|
|
{
|
|
lvi = new ListViewItem(new string[] { ptest.Name,
|
|
(ptest.Part > 0) ? ptest.Part.ToString() : "-",
|
|
Qtg.ToString(),
|
|
Qfrom.ToString(),
|
|
Qto.ToString(),
|
|
ptest.ErrLimLo.ToString(),
|
|
ptest.ErrLimHi.ToString() });
|
|
}
|
|
else
|
|
{
|
|
lvi = new ListViewItem(new string[] { ptest.Name,
|
|
(ptest.Part > 0) ? ptest.Part.ToString() : "-",
|
|
Qtg.ToString(),
|
|
Qfrom.ToString(),
|
|
Qto.ToString(),
|
|
Strings.calculated,
|
|
Strings.calculated });
|
|
}
|
|
|
|
lvi.Tag = ptest;
|
|
listView.Items.Add(lvi);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageBox.Show("Something went wrong");
|
|
}
|
|
}
|
|
|
|
|
|
private void profileComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
Profile newProfile = null;
|
|
foreach (var p in profiles)
|
|
{
|
|
if (profileComboBox.Text == p.Name)
|
|
{
|
|
newProfile = p;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (SelectedProfile != newProfile)
|
|
{
|
|
SelectedProfile = newProfile;
|
|
|
|
qpQiRatioGroupBox.Visible = (SelectedProfile.ProfileType == ProfileType.QpQi);
|
|
metroClassGroupBox.Visible = (SelectedProfile.ProfileType != ProfileType.Manual);
|
|
|
|
profileTypeLabel.Text = (newProfile != null) ? newProfile.ProfileType.ToString() : string.Empty;
|
|
profileDescriptionLabel.Text = (newProfile != null) ? newProfile.Description : string.Empty;
|
|
RedrawQn(newProfile);
|
|
RedrawMClassCombo(newProfile);
|
|
|
|
if (IsFormValid())
|
|
{
|
|
RedrawPTests(newProfile);
|
|
nextButton.Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
RedrawPTests(null);
|
|
nextButton.Enabled = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void qnComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (IsFormValid())
|
|
{
|
|
RedrawPTests(SelectedProfile);
|
|
nextButton.Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
RedrawPTests(null);
|
|
nextButton.Enabled = false;
|
|
}
|
|
}
|
|
|
|
private void metroClassComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (IsFormValid())
|
|
{
|
|
RedrawPTests(SelectedProfile);
|
|
nextButton.Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
RedrawPTests(null);
|
|
nextButton.Enabled = false;
|
|
}
|
|
}
|
|
|
|
private void qpQiRatioComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (IsFormValid())
|
|
{
|
|
RedrawPTests(SelectedProfile);
|
|
nextButton.Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
RedrawPTests(null);
|
|
nextButton.Enabled = false;
|
|
}
|
|
}
|
|
|
|
|
|
bool IsProfileValid()
|
|
{
|
|
return profileComboBox.Items.Contains(profileComboBox.Text); /// CB text must be one of the items
|
|
}
|
|
|
|
bool IsQnValid()
|
|
{
|
|
if (!string.IsNullOrEmpty(qnTextBox.Text) && Utils.TryParseUDouble(qnTextBox.Text, out Qn) && (Qn > 0))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
Qn = 0;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool IsMetroClassValid()
|
|
{
|
|
if (SelectedProfile.ProfileType == ProfileType.Manual)
|
|
{
|
|
MetroClass = string.Empty;
|
|
return true;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(metroClassComboBox.Text) &&
|
|
(metroClassComboBox.Items.Count == 0 || metroClassComboBox.Items.Contains(metroClassComboBox.Text)))
|
|
{
|
|
MetroClass = metroClassComboBox.Text;
|
|
return true;
|
|
}
|
|
|
|
MetroClass = string.Empty;
|
|
return false;
|
|
}
|
|
|
|
bool IsQpQiRatioValid()
|
|
{
|
|
if (SelectedProfile.ProfileType != ProfileType.QpQi)
|
|
{
|
|
QpQiRatio = 1.0;
|
|
return true;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(qpQiRatioComboBox.Text) && qpQiRatioComboBox.Items.Contains(qpQiRatioComboBox.Text))
|
|
{
|
|
QpQiRatio = double.Parse(qpQiRatioComboBox.Text);
|
|
return true;
|
|
}
|
|
|
|
QpQiRatio = 1.0;
|
|
return false;
|
|
}
|
|
|
|
bool IsFormValid()
|
|
{
|
|
return IsProfileValid() && IsQnValid() && IsMetroClassValid() && IsQpQiRatioValid();
|
|
}
|
|
|
|
private void nextButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (IsFormValid())
|
|
{
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Something's wrong");
|
|
}
|
|
}
|
|
|
|
private void cancelButton_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
}
|
|
}
|