169 lines
5.4 KiB
C#
169 lines
5.4 KiB
C#
///
|
|
/// Copyright (c) 2013-2019 Senus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.UI.Bench.Metrology
|
|
{
|
|
public partial class MetrologyDlgDensityTab : UserControl, IMetrologyDlgTab
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(MetrologyDlgDensityTab));
|
|
|
|
/// <summary>
|
|
/// Component entity that has a list of 'measurement-correction' pairs
|
|
/// to be updated in the database on OK.
|
|
/// </summary>
|
|
public Component MeterEntity { get; set; }
|
|
|
|
/// <summary>
|
|
/// Density configuration
|
|
/// </summary>
|
|
public Rig.DataContainer.Density.ComponentCfg DensityCfg;
|
|
|
|
/// <summary>
|
|
/// A list of 'measurement-correction' pairs to be deleted from the database on OK.
|
|
/// </summary>
|
|
public IList<MeasurementCorrection> ToBeRemoved { get; set; }
|
|
|
|
MetrologyDlg parent;
|
|
bool valuesModified;
|
|
|
|
public MetrologyDlgDensityTab()
|
|
{
|
|
InitializeComponent();
|
|
calibDateTimePicker.CustomFormat = Constants.DateFormat;
|
|
calibDateTimePicker.MinDate = Constants.MinDate;
|
|
calibExpirationDateTimePicker.CustomFormat = Constants.DateFormat;
|
|
calibExpirationDateTimePicker.MinDate = Constants.MinDate;
|
|
ToBeRemoved = new List<MeasurementCorrection>();
|
|
valuesModified = false;
|
|
}
|
|
|
|
private void MetrologyDlgDensityTab_Load(object sender, System.EventArgs e)
|
|
{
|
|
if (MeterEntity == null) return;
|
|
|
|
parent = ParentForm as MetrologyDlg;
|
|
|
|
Localize();
|
|
|
|
/// Panel1
|
|
densityLabel.Text = string.Format("{0} [{1}]", Strings.Density, Unit.kgpm3.ToDescription());
|
|
temperatureLabel.Text = string.Format("{0} [{1}]", Strings.At_temperature, Unit.C.ToDescription());
|
|
densityCorrLabel.Text = string.Format("{0} [{1}]", Strings.Density_correction, Unit.kgpm3.ToDescription());
|
|
|
|
/// Panel2
|
|
|
|
RefreshAll();
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
calibrationGroupBox.Text = Strings.Calibration;
|
|
calibCertificateNrLabel.Text = Strings.Certificate;
|
|
calibDateLabel.Text = Strings.Date;
|
|
calibValidDateLabel.Text = Strings.Valid_until;
|
|
}
|
|
|
|
void RefreshAll()
|
|
{
|
|
if (DensityCfg != null)
|
|
{
|
|
densityTextBox.Text = DensityCfg.SampleDensity.ToString();
|
|
temperatureTextBox.Text = DensityCfg.SampleTemp.ToString();
|
|
densityCorrTextBox.Text = Formulas.DensityCorrection(DensityCfg.SampleDensity, DensityCfg.SampleTemp).ToString("F5");
|
|
calibCertificateNrTextBox.Text = DensityCfg.CalibCertificateNr;
|
|
calibDateTimePicker.Value = (DensityCfg.CalibDate < Constants.MinDate) ? Constants.MinDate : DensityCfg.CalibDate;
|
|
calibExpirationDateTimePicker.Value = (DensityCfg.CalibValidDate < Constants.MinDate) ? Constants.MinDate : DensityCfg.CalibValidDate;
|
|
}
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
densityTextBox.Enabled = true;
|
|
temperatureTextBox.Enabled = true;
|
|
calibCertificateNrTextBox.Enabled = true;
|
|
calibDateTimePicker.Enabled = true;
|
|
calibExpirationDateTimePicker.Enabled = true;
|
|
}
|
|
|
|
public void OkBtnClicked()
|
|
{
|
|
if (DensityCfg != null)
|
|
{
|
|
try
|
|
{
|
|
if (valuesModified)
|
|
{
|
|
GlobalData.SampleDensity = DensityCfg.SampleDensity = Utils.ParseUDouble(densityTextBox.Text);
|
|
GlobalData.SampleTemp = DensityCfg.SampleTemp = Utils.ParseUDouble(temperatureTextBox.Text);
|
|
}
|
|
|
|
DensityCfg.CalibCertificateNr = calibCertificateNrTextBox.Text;
|
|
DensityCfg.CalibDate = calibDateTimePicker.Value.Date;
|
|
DensityCfg.CalibValidDate = calibExpirationDateTimePicker.Value.Date;
|
|
|
|
Component modified = DensityCfg.CreateDbEntity();
|
|
MeterEntity.Parameters = modified.Parameters;
|
|
}
|
|
catch
|
|
{
|
|
MessageBox.Show(Strings.Invalid_density_parameter_Correct_pls,
|
|
Strings.Error,
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Exclamation);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CancelBtnClicked() { }
|
|
public void AddOne() { }
|
|
public void RemoveSelected() { }
|
|
public void MoveUpSelected() { }
|
|
public void MoveDownSelected() { }
|
|
|
|
public string GetWarningsBeforeSaving(ref Dictionary<string, string> renmInfo)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
|
{
|
|
}
|
|
|
|
private void densityTextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
UpdateDensityCorrectionDisplay();
|
|
valuesModified = true;
|
|
}
|
|
|
|
private void temperatureTextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
UpdateDensityCorrectionDisplay();
|
|
valuesModified = true;
|
|
}
|
|
|
|
void UpdateDensityCorrectionDisplay()
|
|
{
|
|
double density;
|
|
double temp;
|
|
if (Utils.TryParseUDouble(densityTextBox.Text, out density) &&
|
|
Utils.TryParseUDouble(temperatureTextBox.Text, out temp))
|
|
{
|
|
densityCorrTextBox.Text = Formulas.DensityCorrection(density, temp).ToString();
|
|
}
|
|
}
|
|
|
|
public void SaveEntityToDB(NHibernate.ISession session)
|
|
{
|
|
session.SaveOrUpdate(MeterEntity);
|
|
}
|
|
}
|
|
}
|