- KBuoyancy calculation - Readability column Excel export: - shape CC, for WT,T,Pr
965 lines
35 KiB
C#
965 lines
35 KiB
C#
///
|
|
/// Copyright (c) 2016-2021 Sensus Slovensko a.s.
|
|
///
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
using ClosedXML.Excel;
|
|
using log4net;
|
|
using NHibernate;
|
|
#if MANAGED
|
|
using Oracle.ManagedDataAccess.Client;
|
|
#else
|
|
using Oracle.DataAccess.Client;
|
|
#endif
|
|
using Common;
|
|
using Config.Entities;
|
|
using Results;
|
|
using Results.Entities;
|
|
using Results.Uncertainty;
|
|
using Results.Uncertainty.CommonTable;
|
|
using TBF.Rig;
|
|
using TBF.Rig.Generic;
|
|
using TBF.Rig.GenericDevices;
|
|
using TBF.Rig.Keithley.TempMeter;
|
|
using TBF.Rig.Output.DB.SensusOracle;
|
|
using TBF.Rig.Sequences;
|
|
using Strings = TBF.Resources.Strings;
|
|
|
|
namespace TBF.UI.ResultsMI
|
|
{
|
|
public partial class PreviousResultsDlgUncertainty : Form, IPreviousResultDlg
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(PreviousResultsDlgUncertainty));
|
|
|
|
ISession session;
|
|
ISession sessionDBConfig;
|
|
private static IList<Component> cmpntEntities;
|
|
|
|
int currentBatchNr;
|
|
|
|
IList<Batch> batches;
|
|
|
|
/// A list of batches selected from all batches using criteria entered in UI
|
|
IList<string> serialNrs;
|
|
|
|
/// Display only watermeters with these serial numbers (null = display all)
|
|
int lastDisplayedIx;
|
|
|
|
/// Index of the last displayed batch from the list 'batches'
|
|
const int LinesCount = 25;
|
|
|
|
/// Number of batches displayed on one screen
|
|
PreviousResultsMode mode;
|
|
|
|
|
|
public PreviousResultsDlgUncertainty(PreviousResultsMode mode)
|
|
{
|
|
InitializeComponent();
|
|
this.mode = mode;
|
|
currentBatchNr = Program.LocalSettings.BatchNr;
|
|
|
|
PrintHandler += delegate(object sndr, PreviousResultIdEventArgs args)
|
|
{
|
|
if (InvokeRequired)
|
|
{
|
|
Invoke(new EventHandler<PreviousResultIdEventArgs>(DoAddListUncertainty), sndr, args);
|
|
}
|
|
else DoAddListUncertainty(sndr, args);
|
|
};
|
|
|
|
SendAgainHandler += delegate(object sndr, PreviousResultIdEventArgs args)
|
|
{
|
|
if (InvokeRequired)
|
|
{
|
|
Invoke(new EventHandler<PreviousResultIdEventArgs>(DoSendAgain), sndr, args);
|
|
}
|
|
else DoSendAgain(sndr, args);
|
|
};
|
|
|
|
ShowResultsHandler += delegate(object sndr, PreviousResultIdEventArgs args)
|
|
{
|
|
if (InvokeRequired)
|
|
{
|
|
Invoke(new EventHandler<PreviousResultIdEventArgs>(DoShowResults), sndr, args);
|
|
}
|
|
else DoShowResults(sndr, args);
|
|
};
|
|
}
|
|
|
|
public PreviousResultsDlgUncertainty()
|
|
: this(PreviousResultsMode.Show)
|
|
{
|
|
}
|
|
|
|
private void PreviousResultsDlgUncertainty_Load(object sender, EventArgs e)
|
|
{
|
|
Localize();
|
|
|
|
fromDateTimePicker.MinDate = Constants.MinDate;
|
|
fromDateTimePicker.MaxDate = DateTime.Today;
|
|
fromDateTimePicker.Value = Constants.MinDate;
|
|
fromDateTimePicker.CustomFormat = Constants.DateFormat;
|
|
fromDateTimePicker.ShowUpDown = true;
|
|
|
|
toDateTimePicker.MinDate = Constants.MinDate;
|
|
toDateTimePicker.MaxDate = DateTime.Today;
|
|
toDateTimePicker.Value = DateTime.Today;
|
|
toDateTimePicker.CustomFormat = Constants.DateFormat;
|
|
toDateTimePicker.ShowUpDown = true;
|
|
|
|
try
|
|
{
|
|
session = Results.DB.CreateSession();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
session = null;
|
|
log.ErrorFormat("Opening Results DB failed: {0}", exc.Message);
|
|
}
|
|
|
|
batches = GetFilteredBatches(out lastDisplayedIx, out serialNrs);
|
|
UpdateButtons();
|
|
Redraw();
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
Text = Strings.Previous_results;
|
|
closeButton.Text = TBF.Resources.Strings.CloseBtnText;
|
|
previousButton.Text = TBF.Resources.Strings.Previous;
|
|
nextButton.Text = TBF.Resources.Strings.Next;
|
|
fromLabel.Text = Strings.from;
|
|
toLabel.Text = Strings.to;
|
|
procedureLabel.Text = Strings.Procedure;
|
|
listView1.Columns[0].Text = Strings.Nr;
|
|
listView1.Columns[1].Text = Strings.Name;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a list of batches selected using criteria entered in UI
|
|
/// </summary>
|
|
/// <returns>List of batches</returns>
|
|
IList<Batch> GetFilteredBatches(out int lastIx, out IList<string> serialNrs)
|
|
{
|
|
IList<Batch> rslt;
|
|
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(procedureTextBox.Text) && string.IsNullOrEmpty(snTextBox.Text))
|
|
{
|
|
rslt = session.QueryOver<Batch>()
|
|
.Where(x => (x.StartTime >= fromDateTimePicker.Value))
|
|
.And(x => (x.StartTime < toDateTimePicker.Value.AddDays(1)))
|
|
.OrderBy(x => x.BatchNr).Asc
|
|
.List();
|
|
}
|
|
else if (string.IsNullOrEmpty(snTextBox.Text))
|
|
{
|
|
rslt = session.QueryOver<Batch>()
|
|
.Where(x => (x.StartTime >= fromDateTimePicker.Value))
|
|
.And(x => (x.StartTime < toDateTimePicker.Value.AddDays(1)))
|
|
.And(x => (x.ProcedureName == procedureTextBox.Text))
|
|
.OrderBy(x => x.BatchNr).Asc
|
|
.List();
|
|
}
|
|
else if (string.IsNullOrEmpty(procedureTextBox.Text))
|
|
{
|
|
rslt = session.QueryOver<Batch>()
|
|
.Where(x => (x.StartTime >= fromDateTimePicker.Value))
|
|
.And(x => (x.StartTime < toDateTimePicker.Value.AddDays(1)))
|
|
.OrderBy(x => x.BatchNr).Asc
|
|
.JoinQueryOver<WaterMeter>(b => b.WaterMeters)
|
|
.Where(wm => (wm.SerialNr == snTextBox.Text))
|
|
.List<Batch>();
|
|
}
|
|
else
|
|
{
|
|
rslt = session.QueryOver<Batch>()
|
|
.Where(x => (x.StartTime >= fromDateTimePicker.Value))
|
|
.And(x => (x.StartTime < toDateTimePicker.Value.AddDays(1)))
|
|
.And(x => (x.ProcedureName == procedureTextBox.Text))
|
|
.OrderBy(x => x.BatchNr).Asc
|
|
.JoinQueryOver<WaterMeter>(b => b.WaterMeters)
|
|
.Where(wm => (wm.SerialNr == snTextBox.Text))
|
|
.List<Batch>();
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
rslt = new List<Batch>();
|
|
log.ErrorFormat("Reading batches from Results DB failed: {0}", exc.Message);
|
|
}
|
|
|
|
serialNrs = string.IsNullOrEmpty(snTextBox.Text) ? null : new List<string> { snTextBox.Text };
|
|
lastIx = rslt.Count - 1;
|
|
|
|
return rslt;
|
|
}
|
|
|
|
public void OnReload(object sender, PreviousResultIdEventArgs data)
|
|
{
|
|
foreach (var batch in batches)
|
|
{
|
|
if (batch.BatchNr == data.BatchNr)
|
|
{
|
|
TBF.UiBridge.Bridge.BatchNr = batch.BatchNr;
|
|
|
|
Program.MainWnd.ReloadProcedureComboBoxItems(batch.ProcedureName);
|
|
TBF.UiBridge.Bridge.Ui2Bench(TBF.UiBridge.UI2BenchCmd.ReloadBatch);
|
|
break;
|
|
}
|
|
}
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
public string getSendReloadButtonText()
|
|
{
|
|
return Strings.Add;
|
|
}
|
|
|
|
|
|
public void OnReloadAndFix(object sender, PreviousResultIdEventArgs data)
|
|
{
|
|
foreach (var batch in batches)
|
|
{
|
|
if (batch.BatchNr == data.BatchNr)
|
|
{
|
|
TBF.UiBridge.Bridge.BatchNr = batch.BatchNr;
|
|
|
|
Program.MainWnd.ReloadProcedureComboBoxItems(batch.ProcedureName);
|
|
TBF.UiBridge.Bridge.Ui2Bench(TBF.UiBridge.UI2BenchCmd.ReloadAndFixBatch);
|
|
break;
|
|
}
|
|
}
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
|
|
public event EventHandler<PreviousResultIdEventArgs> PrintHandler;
|
|
|
|
/// <summary>
|
|
/// Called from PreviousResultCtrl when 'Print' button pressed.
|
|
/// </summary>
|
|
public void OnPrint(object sender, PreviousResultIdEventArgs data)
|
|
{
|
|
if (PrintHandler == null) return;
|
|
try
|
|
{
|
|
PrintHandler(sender, data);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error("PrintHandler(...) failed", e);
|
|
}
|
|
}
|
|
|
|
public void DoAddListUncertainty(object sender, PreviousResultIdEventArgs data)
|
|
{
|
|
foreach (var b in batches)
|
|
{
|
|
if (b.BatchNr == data.BatchNr)
|
|
{
|
|
ListViewItem item1 = new ListViewItem(data.BatchNr.ToString());
|
|
item1.SubItems.Add(b.ProcedureName);
|
|
listView1.Items.Add(item1);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public event EventHandler<PreviousResultIdEventArgs> SendAgainHandler;
|
|
|
|
/// <summary>
|
|
/// Called from PreviousResultCtrl when 'Send again' button pressed.
|
|
/// </summary>
|
|
public void OnSendAgain(object sender, PreviousResultIdEventArgs data)
|
|
{
|
|
if (SendAgainHandler == null) return;
|
|
try
|
|
{
|
|
SendAgainHandler(sender, data);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error("SendAgainHandler(...) failed", e);
|
|
}
|
|
}
|
|
|
|
public void DoSendAgain(object sender, PreviousResultIdEventArgs data)
|
|
{
|
|
foreach (var b in batches)
|
|
{
|
|
if (b.BatchNr == data.BatchNr)
|
|
{
|
|
#if ORACLE_DB
|
|
if (ProcessData.OracleDB == null)
|
|
{
|
|
MessageBox.Show("No database");
|
|
return;
|
|
}
|
|
|
|
var dlg = new SendAgainDBAndWMSelectionForm();
|
|
if (dlg.ShowDialog() != DialogResult.OK) return;
|
|
|
|
OracleConnection conn;
|
|
switch (dlg.SelectedDB)
|
|
{
|
|
default:
|
|
case DBUsed.Production: conn = ProcessData.OracleDB.ProductionDB; break;
|
|
case DBUsed.Quality: conn = ProcessData.OracleDB.QualityDB; break;
|
|
case DBUsed.Test: conn = ProcessData.OracleDB.TestDB; break;
|
|
}
|
|
|
|
if (ProcessData.OracleDB.WriteResultsToDB(conn, b, dlg.SelectedWM, true) == Retv.OK)
|
|
{
|
|
b.RsltsSent = true; /// Result was successfully sent
|
|
session.SaveOrUpdate(b); /// Update MySQL DB
|
|
session.Flush();
|
|
(sender as PreviousResultCtrl).Sent = true; /// Update UI
|
|
Redraw();
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public event EventHandler<PreviousResultIdEventArgs> ShowResultsHandler;
|
|
|
|
/// <summary>
|
|
/// Called from PreviousResultCtrl when 'Show' button pressed.
|
|
/// </summary>
|
|
public void OnShowResults(object sender, PreviousResultIdEventArgs data)
|
|
{
|
|
if (ShowResultsHandler == null) return;
|
|
try
|
|
{
|
|
ShowResultsHandler(sender, data);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error("ShowResultsHandler(...) failed", e);
|
|
}
|
|
}
|
|
|
|
public void DoShowResults(object sender, PreviousResultIdEventArgs data)
|
|
{
|
|
foreach (var b in batches)
|
|
{
|
|
if (b.BatchNr == data.BatchNr)
|
|
{
|
|
if (b.WaterMeters == null || b.WaterMeters.Count == 0)
|
|
{
|
|
return; /// No water meters in the selected batch
|
|
}
|
|
|
|
/// Prepare result items
|
|
IList<WMeterRsltItemSpec> items = null;
|
|
foreach (var wm in b.WaterMeters)
|
|
{
|
|
if (!wm.Disabled && wm.WaterMeterData != null)
|
|
{
|
|
if (wm.WaterMeterData.Compound)
|
|
{
|
|
items = WMeterRsltItemSpec.FromStrArray(Program.LocalSettings
|
|
.RsltItems_Screen_CombinedWM);
|
|
}
|
|
else if (wm.WaterMeterData.HeatMeter)
|
|
{
|
|
items = WMeterRsltItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Screen_HeatM);
|
|
}
|
|
else
|
|
{
|
|
items = WMeterRsltItemSpec.FromStrArray(Program.LocalSettings
|
|
.RsltItems_Screen_SingleWM);
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (items == null) items = new List<WMeterRsltItemSpec>();
|
|
|
|
/// Show dialog with results
|
|
Results.Forms.BatchResultsDlg dlg = new Results.Forms.BatchResultsDlg
|
|
{
|
|
Text = string.Format(Strings.Results_of_batch_0, b.BatchNr),
|
|
Results = BatchResults.FromBatch(b),
|
|
Items = items,
|
|
PopupResultsLeft = Program.LocalSettings.PopupResultsLeft,
|
|
PopupResultsTop = Program.LocalSettings.PopupResultsTop,
|
|
PopupResultsWidth = Program.LocalSettings.PopupResultsWidth,
|
|
PopupResultsHeight = Program.LocalSettings.PopupResultsHeight,
|
|
MetersArrangement = Program.LocalSettings.ResultsConfigMeters,
|
|
TestsArrangement = Program.LocalSettings.ResultsConfigTests,
|
|
NrMetersInOneGroup = Math.Max(1, Program.LocalSettings.ResultsConfigMetersInOneGroup),
|
|
ShowDisabledPositions = Program.LocalSettings.ShowDisabledPositions,
|
|
MinWidth = Program.LocalSettings.ResultsConfigMinWidth,
|
|
MinHeight = Program.LocalSettings.ResultsConfigMinHeight,
|
|
RsltsClmnWidths = Program.LocalSettings.RsltsClmnWidths,
|
|
SerialNrs = data.SerialNrs,
|
|
};
|
|
|
|
dlg.Show();
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Redraws list of batches.
|
|
/// Uses member variables 'batches' and 'lastDisplayedIx'
|
|
/// </summary>
|
|
void Redraw()
|
|
{
|
|
SuspendLayout();
|
|
|
|
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
|
|
flowLayoutPanel1.Controls.Clear();
|
|
|
|
if (batches == null || batches.Count == 0) return;
|
|
|
|
for (int i = Math.Max(0, lastDisplayedIx - LinesCount + 1); i <= lastDisplayedIx; i++)
|
|
{
|
|
var b = batches[i];
|
|
int passedCount = 0;
|
|
int failedCount = 0;
|
|
foreach (var wm in b.WaterMeters)
|
|
{
|
|
if ((wm != null) && wm.Passed)
|
|
{
|
|
passedCount++;
|
|
}
|
|
else
|
|
{
|
|
failedCount++;
|
|
}
|
|
}
|
|
|
|
if (passedCount + failedCount == 0) continue;
|
|
|
|
flowLayoutPanel1.Controls.Add(new PreviousResultCtrl(this,
|
|
b.BatchNr,
|
|
b.StartTime,
|
|
b.EndTime,
|
|
b.ProgramVersion,
|
|
b.ProcedureName,
|
|
b.WaterMeters[0].PurchaseOrder,
|
|
passedCount,
|
|
failedCount,
|
|
b.RsltsSent,
|
|
mode,
|
|
serialNrs));
|
|
}
|
|
|
|
ResumeLayout();
|
|
}
|
|
|
|
private void closeButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (session != null) session.Close();
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
private void previousButton_Click(object sender, EventArgs e)
|
|
{
|
|
lastDisplayedIx = Math.Max(lastDisplayedIx - LinesCount, LinesCount - 1);
|
|
Redraw();
|
|
UpdateButtons();
|
|
}
|
|
|
|
private void nextButton_Click(object sender, EventArgs e)
|
|
{
|
|
lastDisplayedIx = Math.Min(lastDisplayedIx + LinesCount, batches.Count - 1);
|
|
Redraw();
|
|
UpdateButtons();
|
|
}
|
|
|
|
private void UpdateButtons()
|
|
{
|
|
nextButton.Enabled = (lastDisplayedIx < batches.Count - 1);
|
|
previousButton.Enabled = (lastDisplayedIx > LinesCount - 1);
|
|
}
|
|
|
|
private void reloadButton_Click(object sender, EventArgs e)
|
|
{
|
|
batches = GetFilteredBatches(out lastDisplayedIx, out serialNrs);
|
|
UpdateButtons();
|
|
Redraw();
|
|
}
|
|
|
|
private void PreviousResultsDlgUncertainty_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
if (CurrentUser.Restore(this)) Program.MainWnd.UpdateUser();
|
|
}
|
|
|
|
public class Pair
|
|
{
|
|
int offsetRows;
|
|
|
|
public int OffsetRows
|
|
{
|
|
get => offsetRows;
|
|
set => offsetRows = value;
|
|
}
|
|
|
|
public int OffsetColumns
|
|
{
|
|
get => offsetColumns;
|
|
set => offsetColumns = value;
|
|
}
|
|
|
|
int offsetColumns;
|
|
public Pair(int offsetRows, int offsetColumns)
|
|
{
|
|
this.offsetRows = offsetRows;
|
|
this.offsetColumns = offsetColumns;
|
|
}
|
|
}
|
|
|
|
Pair GetTableCC_WT_Offsets(int iTable)
|
|
{
|
|
switch (iTable)
|
|
{
|
|
case 0: return new Pair(0, 0);
|
|
case 1: return new Pair(20, 0);
|
|
case 2: return new Pair(40, 0);
|
|
case 3: return new Pair(56, 0);
|
|
default: return new Pair(0, 0);
|
|
}
|
|
}
|
|
|
|
Pair GetTableCC_Tempers_Offsets(int iTable)
|
|
{
|
|
switch (iTable)
|
|
{
|
|
case 0: return new Pair(56, 0);
|
|
case 1: return new Pair(76, 0);
|
|
case 2: return new Pair(96, 0);
|
|
case 3: return new Pair(116, 0);
|
|
case 4: return new Pair(206, 0);
|
|
case 5: return new Pair(226, 0);
|
|
case 6: return new Pair(246, 0);
|
|
case 7: return new Pair(266, 0);
|
|
case 8: return new Pair(286, 0);
|
|
default: return new Pair(56, 0);
|
|
}
|
|
}
|
|
|
|
Pair GetTableCC_Press_Offsets(int iTable)
|
|
{
|
|
switch (iTable)
|
|
{
|
|
case 0: return new Pair(326, 0);
|
|
case 1: return new Pair(346, 0);
|
|
case 2: return new Pair(366, 0);
|
|
default: return new Pair(326, 0);
|
|
}
|
|
}
|
|
|
|
Pair GetTableCC_Diverter_Offsets(int iTable)
|
|
{
|
|
switch (iTable)
|
|
{
|
|
case 0: return new Pair(146, 0);
|
|
case 1: return new Pair(158, 0);
|
|
case 2: return new Pair(170, 0);
|
|
case 3: return new Pair(182, 0);
|
|
case 4: return new Pair(194, 0);
|
|
default: return new Pair(146, 0);
|
|
}
|
|
}
|
|
|
|
private void uncertainty_button_Click(object sender, EventArgs data)
|
|
{
|
|
//get list
|
|
if (listView1.Items.Count < 1)
|
|
{
|
|
MessageBox.Show("No selected results to calculate uncertainty!");
|
|
return;
|
|
}
|
|
|
|
IList<Batch> selectedBatches = new List<Batch>();
|
|
|
|
foreach (ListViewItem item in listView1.Items)
|
|
{
|
|
int iBatch = Int32.Parse(item.Text);
|
|
foreach (Batch b in batches)
|
|
{
|
|
if (b.BatchNr == iBatch)
|
|
{
|
|
selectedBatches.Add(b);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (selectedBatches.Count == 0)
|
|
{
|
|
MessageBox.Show("Selected results no fit with results to calculate uncertainty!");
|
|
return;
|
|
}
|
|
|
|
RigUncertainty rigUncertainty = null;
|
|
try
|
|
{
|
|
string pathToTemplateExcel = Path.Combine("C:\\Users\\micha\\Downloads", "Uncertainty_template.xlsx");
|
|
string pathToTestExcel = Path.Combine("C:\\Users\\micha\\Downloads", "Uncertainty_generated.xlsx");
|
|
CopyTemplate(pathToTemplateExcel, pathToTestExcel);
|
|
rigUncertainty = new RigUncertainty(pathToTestExcel);
|
|
rigUncertainty.OpenDocument();
|
|
|
|
if (!rigUncertainty.IsOpenedDocument)
|
|
{
|
|
throw new Exception("Problem with open document!");
|
|
}
|
|
|
|
|
|
//Insert Data to worksheet Excel
|
|
int iBlock = 0;
|
|
foreach (Batch b in selectedBatches)
|
|
{
|
|
int iRow = 0;
|
|
int iStart = CommonExcell.GetBolocs()[iBlock];
|
|
//calculate
|
|
foreach (TestRslt testRslt in b.TestRslts)
|
|
{
|
|
if (!testRslt.TestDone)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
ProcessDataLine processDataLine = new ProcessDataLine();
|
|
processDataLine.Init(testRslt);
|
|
CommonExcell.InsertValueLineProcessData(rigUncertainty, iStart + iRow, processDataLine);
|
|
iRow++;
|
|
if (iRow > 16) // Max count
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
iBlock++;
|
|
}
|
|
|
|
//Insert Metrology Data to worksheet Excel
|
|
//Get r.Batch => s.BatchPaths
|
|
sessionDBConfig = TBF.DB.CreateSession(DBKind.Config);
|
|
|
|
cmpntEntities = sessionDBConfig.QueryOver<Component>()
|
|
.OrderBy(x => x.ItemNr).Asc
|
|
.List();
|
|
|
|
IList<Table> tables = new List<Table>();
|
|
int iTable_WT = 0;
|
|
int tempMetersCount = 0;
|
|
int divertersCount = 0;
|
|
foreach (var cmpnt in cmpntEntities)
|
|
{
|
|
Rig.Generic.IComponentFactory factory = TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName);
|
|
/// Tab-pages for scales
|
|
if (factory is Rig.Scales.MettlerToledo.Factory ||
|
|
factory is Rig.MettlerToledo.Standard.BalanceFactory ||
|
|
factory is Rig.MettlerToledo.Standard.BalanceOldFactory ||
|
|
factory is Rig.MettlerToledo.Standard.BalanceNewFactory)
|
|
{
|
|
IScaleCfg BalanceCfg =
|
|
factory.CmpntCfgFromCmpntEntity(cmpnt) as IScaleCfg;
|
|
Pair pair = GetTableCC_WT_Offsets(iTable_WT);
|
|
tables.Add(InsertMetrologyDataWT(BalanceCfg,pair));
|
|
iTable_WT++;
|
|
}
|
|
/// Tab-pages for temperature meters
|
|
else if (factory is Rig.Modbus.TempMeter.Groch.Factory ||
|
|
factory is Rig.Modbus.TempMeter.Meret.Factory ||
|
|
factory is Rig.Keithley.TempMeter.Factory)
|
|
{
|
|
ICalibInfoCfg calibInfoCfg = factory.CmpntCfgFromCmpntEntity(cmpnt) as ICalibInfoCfg;
|
|
Pair pair = GetTableCC_Tempers_Offsets(tempMetersCount);
|
|
tables.Add(InsertMetrologyDataTemper(calibInfoCfg,pair));
|
|
tempMetersCount++;
|
|
}
|
|
/// Tab-pages for diverters
|
|
else if (factory is Rig.Uni.Diverter.Factory)
|
|
{
|
|
ICalibInfoCfg calibInfoCfg = factory.CmpntCfgFromCmpntEntity(cmpnt) as Rig.GenericDevices.ICalibInfoCfg;
|
|
Pair pair = GetTableCC_Diverter_Offsets(divertersCount);
|
|
tables.Add(InsertMetrologyDataDiverter(calibInfoCfg,pair));
|
|
divertersCount++;
|
|
}
|
|
}
|
|
|
|
IXLWorksheet worksheet = rigUncertainty.GetWorksheet(DocumentSheets.CC);
|
|
foreach (Table table in tables)
|
|
{
|
|
table.ToWorksheetWithOffset(worksheet, table.IOffsetRows, table.IOffsetColumns,false);
|
|
}
|
|
|
|
|
|
sessionDBConfig.Close();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
MessageBox.Show("Proble in process calculate uncertainty! Detail: " + e.Message);
|
|
return;
|
|
}
|
|
finally
|
|
{
|
|
if (rigUncertainty != null)
|
|
{
|
|
rigUncertainty.SaveChangesToDocument();
|
|
rigUncertainty.CloaseDocument();
|
|
MessageBox.Show("Uncertainty document generated!");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void CopyTemplate(string pathToTemplateExcel, string pathToTestExcel)
|
|
{
|
|
try
|
|
{
|
|
File.Copy(pathToTemplateExcel, pathToTestExcel, true);
|
|
log.Info("Template File copied.");
|
|
}
|
|
catch (IOException ex)
|
|
{
|
|
log.Error("IO error: " + ex.Message);
|
|
}
|
|
catch (UnauthorizedAccessException ex)
|
|
{
|
|
log.Error("Access denied: " + ex.Message);
|
|
}
|
|
}
|
|
|
|
private void uncertainty_clear_button_Click(object sender, EventArgs e)
|
|
{
|
|
listView1.Items.Clear();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserts metrology data into a specified row of the Excel document.
|
|
/// </summary>
|
|
/// <param name="_rigUncertainty">An instance of the <see cref="RigUncertainty"/> class representing the rig uncertainty and the associated document.</param>
|
|
/// <param name="balanceCfg"></param>
|
|
/// <param name="iRowI">The row index in the Excel worksheet where the data will be inserted.</param>
|
|
/// <param name="processDataLine">An instance of the <see cref="ProcessDataLine"/> class containing the metrology data to be inserted.</param>
|
|
public static Results.Uncertainty.CommonTable.Table InsertMetrologyDataWT(IScaleCfg balanceCfg, Pair offsetPair)
|
|
{
|
|
//Define Scale meters 3x
|
|
var table = new Results.Uncertainty.CommonTable.Table();
|
|
table.IOffsetRows = offsetPair.OffsetRows;
|
|
table.IOffsetColumns = offsetPair.OffsetColumns;
|
|
|
|
string Column = "A";
|
|
table.AddColumn(Column);
|
|
for (int i = 0; i < 12; i++) //generate B - M Columns
|
|
{
|
|
Column = CommonExcell.NextColumn(Column);
|
|
table.AddColumn(Column);
|
|
}
|
|
|
|
for (int i = 0; i < 14; i++) //generate 14 rows
|
|
{
|
|
table.AddRow((i + 1).ToString());
|
|
}
|
|
|
|
//Set cell values
|
|
table.AddCell(1, "B", "C"); // Uncertainty type
|
|
table.AddCell(1, "D", balanceCfg.MeterType); //"ISNJ"); //Type
|
|
table.AddCell(1, "F", balanceCfg.MeterSerialNo); //Serial Nr
|
|
table.AddCell(1, "J", 3000); //balanceCfg.); //J - range [kg]
|
|
|
|
//Set cell values
|
|
table.AddCell(2, "B", balanceCfg.Name); // Scale Name
|
|
table.AddCell(2, "D", balanceCfg.CalibCertificateNr); //Cal. Cert
|
|
table.AddCell(2, "F", balanceCfg.CalibCertificateNr); //Nr
|
|
table.AddCell(2, "I", balanceCfg.BuoyancyTemp); //I - Amb.T
|
|
table.AddCell(2, "K", balanceCfg.BuoyancyHumi); //I - Amb.H
|
|
table.AddCell(2, "M", balanceCfg.BuoyancyPress); //I - Amb.P
|
|
|
|
//Set cell values
|
|
table.AddCell(3, "C", balanceCfg.CalibDate); // Date - datetime - format
|
|
|
|
|
|
//Load, Error, Readability, Uncertainty
|
|
//Set cell values
|
|
string columnName = "B";
|
|
foreach (var correction in balanceCfg.Corrections)
|
|
{
|
|
if (correction != null)
|
|
{
|
|
table.AddCell(4, columnName, correction.Measurement); // Load
|
|
double error = Formulas.ErrorFromVolumes(correction.Measurement,
|
|
correction.Measurement + correction.Correction);
|
|
table.AddCell(5, columnName, error); // ERROR
|
|
table.AddCell(7, columnName, correction.Readability); // Readability
|
|
table.AddCell(8, columnName, correction.Uncertainty); // Uncertainty
|
|
columnName = CommonExcell.NextColumn(columnName);
|
|
}
|
|
|
|
if (columnName == "L") // maximum column
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
return table;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserts metrology data into a specified row of the Excel document.
|
|
/// </summary>
|
|
/// <param name="_rigUncertainty">An instance of the <see cref="RigUncertainty"/> class representing the rig uncertainty and the associated document.</param>
|
|
/// <param name="balanceCfg"></param>
|
|
/// <param name="iRowI">The row index in the Excel worksheet where the data will be inserted.</param>
|
|
/// <param name="processDataLine">An instance of the <see cref="ProcessDataLine"/> class containing the metrology data to be inserted.</param>
|
|
public static Results.Uncertainty.CommonTable.Table InsertMetrologyDataTemper(ICalibInfoCfg calibInfoCfg, Pair offsetPair)
|
|
{
|
|
|
|
//Define Temper meter table
|
|
var table = new Results.Uncertainty.CommonTable.Table();
|
|
table.IOffsetRows = offsetPair.OffsetRows;
|
|
table.IOffsetColumns = offsetPair.OffsetColumns;
|
|
|
|
string Column = "A";
|
|
table.AddColumn(Column);
|
|
for (int i = 0; i < 12; i++) //generate B - M Columns
|
|
{
|
|
Column = CommonExcell.NextColumn(Column);
|
|
table.AddColumn(Column);
|
|
}
|
|
|
|
for (int i = 0; i < 14; i++) //generate 14 rows
|
|
{
|
|
table.AddRow((i + 1).ToString());
|
|
}
|
|
|
|
//Set cell values
|
|
table.AddCell(1, "B", "N"); // Uncertainty type
|
|
table.AddCell(1, "D", calibInfoCfg.MeterType); //"ISNJ"); //Type
|
|
table.AddCell(1, "F", calibInfoCfg.MeterSerialNo); //Serial Nr
|
|
|
|
try
|
|
{
|
|
if (calibInfoCfg is TBF.Rig.Keithley.TempMeter.TempMeterCfg)
|
|
{
|
|
table.AddCell(1, "G", string.Format("Ch{0}",
|
|
(calibInfoCfg as TBF.Rig.Keithley.TempMeter.TempMeterCfg)
|
|
.Channel)); //J -chanel
|
|
}
|
|
else if (calibInfoCfg is TBF.Rig.Modbus.TempMeter.Groch.TempMeterCfg)
|
|
{
|
|
table.AddCell(1, "G", string.Format("Ch{0}",
|
|
(calibInfoCfg as TBF.Rig.Modbus.TempMeter.Groch.TempMeterCfg)
|
|
.Channel)); //J -chanel
|
|
}
|
|
else if (calibInfoCfg is TBF.Rig.Modbus.TempMeter.Meret.TempMeterCfg)
|
|
{
|
|
table.AddCell(1, "G", string.Format("Addr{0}",
|
|
(calibInfoCfg as TBF.Rig.Modbus.TempMeter.Meret.TempMeterCfg)
|
|
.ModbusAddress)); //balanceCfg.); //J -chanel
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error("Chanel info failed! Detail: " + e.Message);
|
|
return null;
|
|
}
|
|
|
|
|
|
//Set cell values
|
|
table.AddCell(2, "A", calibInfoCfg.Name); // Scale Name
|
|
table.AddCell(2, "C", calibInfoCfg.CalibDate); // Date - datetime - format
|
|
table.AddCell(2, "F", calibInfoCfg.CalibCertificateNr); //Cal. Cert
|
|
|
|
|
|
|
|
//Load, Error, Readability, Uncertainty
|
|
//Set cell values
|
|
string columnName = "B";
|
|
foreach (var correction in calibInfoCfg.Corrections)
|
|
{
|
|
if (correction != null)
|
|
{
|
|
table.AddCell(4, columnName, correction.Measurement); // Load
|
|
double error = Formulas.ErrorFromVolumes(correction.Measurement,
|
|
correction.Measurement + correction.Correction);
|
|
table.AddCell(5, columnName, error); // ERROR
|
|
table.AddCell(7, columnName, correction.Readability); // Readability
|
|
table.AddCell(8, columnName, correction.Uncertainty); // Uncertainty
|
|
columnName = CommonExcell.NextColumn(columnName);
|
|
}
|
|
|
|
if (columnName == "L") // maximum column
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
return table;
|
|
}
|
|
|
|
public static Results.Uncertainty.CommonTable.Table InsertMetrologyDataDiverter(ICalibInfoCfg calibInfoCfg, Pair offsetPair)
|
|
{
|
|
|
|
//Define Temper meter table
|
|
var table = new Results.Uncertainty.CommonTable.Table();
|
|
table.IOffsetRows = offsetPair.OffsetRows;
|
|
table.IOffsetColumns = offsetPair.OffsetColumns;
|
|
|
|
string Column = "A";
|
|
table.AddColumn(Column);
|
|
for (int i = 0; i < 6; i++) //generate B - F Columns
|
|
{
|
|
Column = CommonExcell.NextColumn(Column);
|
|
table.AddColumn(Column);
|
|
}
|
|
|
|
for (int i = 0; i < 2; i++) //generate 2 rows
|
|
{
|
|
table.AddRow((i + 1).ToString());
|
|
}
|
|
|
|
|
|
|
|
//Load, Error, Readability, Uncertainty
|
|
//Set cell values
|
|
string columnName = "B";
|
|
foreach (var correction in calibInfoCfg.Corrections)
|
|
{
|
|
if (correction != null)
|
|
{
|
|
table.AddCell(1, columnName, correction.Measurement); // Load
|
|
double error = Formulas.ErrorFromVolumes(correction.Measurement,
|
|
correction.Measurement + correction.Correction);
|
|
table.AddCell(2, columnName, error); // ERROR
|
|
//table.AddCell(7, columnName, correction.Readability); // Readability
|
|
//table.AddCell(8, columnName, correction.Uncertainty); // Uncertainty
|
|
columnName = CommonExcell.NextColumn(columnName);
|
|
}
|
|
|
|
if (columnName == "L") // maximum column
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
return table;
|
|
}
|
|
}
|
|
} |