795 lines
34 KiB
C#
795 lines
34 KiB
C#
///
|
|
/// Copyright (c) 2016-2020 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
using NHibernate;
|
|
using Results.Entities;
|
|
using TBF.BenchControl;
|
|
using TBF.BenchControl.Generic;
|
|
using TBF.BenchControl.GenericDevices;
|
|
using ResultsBrowser.Filters;
|
|
using ResultsBrowser.Resources;
|
|
using Oracle;
|
|
using Oracle.DataAccess.Client;
|
|
|
|
namespace ResultsBrowser
|
|
{
|
|
public partial class ResultsBrowserWnd : Form
|
|
{
|
|
const string OpenFileDlg_SaveFileDlg_Filter = "{0} (*.qry)|*.qry|{1} (*.*)|*.*";
|
|
|
|
string[] args; /// Comand line argument
|
|
|
|
IList<Filters.IFilter> filters; /// Filters and the UI of filters
|
|
FiltersConfig filtersConfig; /// Serializable configuration of filters and displayed results
|
|
|
|
IList<WaterMeter> waterMeters;
|
|
|
|
DateTime timePeriodStart;
|
|
DateTime timePeriodEnd;
|
|
|
|
static IList<IComponent> tbfComponents;
|
|
static IList<IDevice> tbfDevices;
|
|
|
|
OracleConnection oracleConnection; /// Oracle database connection
|
|
|
|
public ResultsBrowserWnd(string[] args)
|
|
{
|
|
InitializeComponent();
|
|
|
|
filters = new List<Filters.IFilter>();
|
|
filtersConfig = new FiltersConfig();
|
|
this.args = args;
|
|
|
|
tbfComponents = new List<TBF.BenchControl.Generic.IComponent>();
|
|
tbfDevices = new List<IDevice>();
|
|
|
|
timePeriodStart = new DateTime(0);
|
|
timePeriodEnd = new DateTime(0);
|
|
}
|
|
|
|
private void ResultsBrowserWnd_Load(object sender, EventArgs e)
|
|
{
|
|
ResultsBrowser.LocalSettings ls = Program.LocalSettings;
|
|
Width = (ls.MainWndWidth > 0) ? ls.MainWndWidth : 1000;
|
|
Height = (ls.MainWndHeight > 0) ? ls.MainWndHeight : 750;
|
|
Left = (ls.MainWndLeft != 0) ? ls.MainWndLeft : 50;
|
|
Top = (ls.MainWndTop != 0) ? ls.MainWndTop : 50;
|
|
hSplitContainer.SplitterDistance = (ls.SplitterDistance != 0) ? ls.SplitterDistance : 280;
|
|
|
|
Localize();
|
|
|
|
RedrawTestBenches();
|
|
|
|
checkBox1.Checked = Program.LocalSettings.Bench1Selected;
|
|
checkBox2.Checked = Program.LocalSettings.Bench2Selected;
|
|
checkBox3.Checked = Program.LocalSettings.Bench3Selected;
|
|
checkBox4.Checked = Program.LocalSettings.Bench4Selected;
|
|
checkBox5.Checked = Program.LocalSettings.Bench5Selected;
|
|
checkBox6.Checked = Program.LocalSettings.Bench6Selected;
|
|
|
|
if (args.Length == 1 && args[0].IndexOf(".qry") == args[0].Length - 4)
|
|
{
|
|
LoadConfigFromFile(args[0]);
|
|
}
|
|
else if (!string.IsNullOrEmpty(Program.LocalSettings.LastConfigFileName))
|
|
{
|
|
LoadConfigFromFile(Program.LocalSettings.LastConfigFileName);
|
|
}
|
|
else
|
|
{
|
|
Text = string.Format("{0} ver.{1}", Strings.Results_Browser, Program.Version);
|
|
}
|
|
}
|
|
|
|
void RedrawTestBenches()
|
|
{
|
|
checkBox1.Text = Program.LocalSettings.Bench1;
|
|
checkBox2.Text = Program.LocalSettings.Bench2;
|
|
checkBox3.Text = Program.LocalSettings.Bench3;
|
|
checkBox4.Text = Program.LocalSettings.Bench4;
|
|
checkBox5.Text = Program.LocalSettings.Bench5;
|
|
checkBox6.Text = Program.LocalSettings.Bench6;
|
|
|
|
checkBox1.Visible = !string.IsNullOrEmpty(checkBox1.Text);
|
|
checkBox2.Visible = !string.IsNullOrEmpty(checkBox2.Text);
|
|
checkBox3.Visible = !string.IsNullOrEmpty(checkBox3.Text);
|
|
checkBox4.Visible = !string.IsNullOrEmpty(checkBox4.Text);
|
|
checkBox5.Visible = !string.IsNullOrEmpty(checkBox5.Text);
|
|
checkBox6.Visible = !string.IsNullOrEmpty(checkBox6.Text);
|
|
}
|
|
|
|
string BenchName()
|
|
{
|
|
return checkBox1.Checked ? Program.LocalSettings.Bench1
|
|
: checkBox2.Checked ? Program.LocalSettings.Bench2
|
|
: checkBox3.Checked ? Program.LocalSettings.Bench3
|
|
: checkBox4.Checked ? Program.LocalSettings.Bench4
|
|
: checkBox5.Checked ? Program.LocalSettings.Bench5
|
|
: Program.LocalSettings.Bench6;
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
filtersGroupBox.Text = Strings.Filters;
|
|
resultsGroupBox.Text = Strings.Query_results;
|
|
settingsBtn.Text = Strings.Settings;
|
|
testBenchesGroupBox.Text = Strings.Test_benches;
|
|
|
|
clearFiltersBtn.Text = Strings.Clear_filters;
|
|
addFilterBtn.Text = Strings.Add_filter;
|
|
formatOfResultsBtn.Text = Strings.Format_of_results;
|
|
printerConfigBtn.Text = Strings.Configure_printer;
|
|
loadConfigBtn.Text = Strings.Load_filters;
|
|
saveConfigBtn.Text = Strings.Save_filters;
|
|
|
|
executeQueryBtn.Text = Strings.Execute_query;
|
|
exportQueryResultsBtn.Text = Strings.Export_query_results;
|
|
printQueryResultsBtn.Text = Strings.Print_query_results;
|
|
|
|
statisticsBtn.Text = Strings.Statistics;
|
|
}
|
|
|
|
private void settingsBtn_Click(object sender, EventArgs e)
|
|
{
|
|
if (new Forms.DatabaseSettingsDlg().ShowDialog() == DialogResult.OK)
|
|
{
|
|
RedrawTestBenches();
|
|
}
|
|
}
|
|
|
|
private void checkBox1_CheckedChanged(object sender, EventArgs e) { SaveCheckBoxes(); }
|
|
private void checkBox2_CheckedChanged(object sender, EventArgs e) { SaveCheckBoxes(); }
|
|
private void checkBox3_CheckedChanged(object sender, EventArgs e) { SaveCheckBoxes(); }
|
|
private void checkBox4_CheckedChanged(object sender, EventArgs e) { SaveCheckBoxes(); }
|
|
private void checkBox5_CheckedChanged(object sender, EventArgs e) { SaveCheckBoxes(); }
|
|
private void checkBox6_CheckedChanged(object sender, EventArgs e) { SaveCheckBoxes(); }
|
|
|
|
void SaveCheckBoxes()
|
|
{
|
|
Program.LocalSettings.Bench1Selected = checkBox1.Checked;
|
|
Program.LocalSettings.Bench2Selected = checkBox2.Checked;
|
|
Program.LocalSettings.Bench3Selected = checkBox3.Checked;
|
|
Program.LocalSettings.Bench4Selected = checkBox4.Checked;
|
|
Program.LocalSettings.Bench5Selected = checkBox5.Checked;
|
|
Program.LocalSettings.Bench6Selected = checkBox6.Checked;
|
|
Program.LocalSettings.Save();
|
|
}
|
|
|
|
private void clearFiltersBtn_Click(object sender, EventArgs e)
|
|
{
|
|
filters.Clear();
|
|
filtersFlowLayoutPanel.Controls.Clear();
|
|
}
|
|
|
|
private void addFilterBtn_Click(object sender, EventArgs e)
|
|
{
|
|
Forms.AddFilterDlg dlg = new Forms.AddFilterDlg();
|
|
if (dlg.ShowDialog() == DialogResult.OK && dlg.SelectedFilterID != null)
|
|
{
|
|
Filters.IFilter filter = Factory.GetFilter(dlg.SelectedFilterID);
|
|
filters.Add(filter);
|
|
filtersFlowLayoutPanel.Controls.Add(filter.GetFilterUI());
|
|
}
|
|
}
|
|
|
|
private void formatOfResultsBtn_Click(object sender, EventArgs e)
|
|
{
|
|
Results.Forms.ResultsConfigDlg dlg = new Results.Forms.ResultsConfigDlg();
|
|
dlg.MetersKind = Config.Entities.MetersKind.Single;
|
|
dlg.SelectedItems = Results.WMeterRsltItemSpec.FromStrArray(filtersConfig.ResultItems);
|
|
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
filtersConfig.ResultItems = Results.WMeterRsltItemSpec.ToStrArray(dlg.SelectedItems);
|
|
RedrawResults();
|
|
}
|
|
}
|
|
|
|
private void printerConfigBtn_Click(object sender, EventArgs e)
|
|
{
|
|
Forms.PrinterConfigDlg dlg = new Forms.PrinterConfigDlg
|
|
{
|
|
PrinterClass = filtersConfig.PrinterClass,
|
|
PrinterCfg = filtersConfig.PrinterCfg
|
|
};
|
|
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
filtersConfig.PrinterClass = dlg.PrinterClass;
|
|
filtersConfig.PrinterCfg = dlg.PrinterCfg;
|
|
}
|
|
}
|
|
|
|
private void loadConfigBtn_Click(object sender, EventArgs e)
|
|
{
|
|
OpenFileDialog dlg = new OpenFileDialog();
|
|
dlg.Filter = string.Format("{0} (*.qry)|*.qry|{1} (*.*)|*.*", Strings.Query_files, Strings.All_files);
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
LoadConfigFromFile(dlg.FileName);
|
|
}
|
|
}
|
|
|
|
void LoadConfigFromFile(string fileName)
|
|
{
|
|
FiltersConfig localFiltersConfig = FiltersConfig.Load(fileName);
|
|
if (localFiltersConfig != null)
|
|
{
|
|
filtersConfig = localFiltersConfig;
|
|
|
|
filters.Clear();
|
|
filtersFlowLayoutPanel.Controls.Clear();
|
|
///
|
|
for (int i = 0; i < filtersConfig.FiltersCount; i++)
|
|
{
|
|
Filters.IFilter filter = Factory.LoadFilter(filtersConfig.FilterID[i], filtersConfig.FilterData[i]);
|
|
filters.Add(filter);
|
|
filtersFlowLayoutPanel.Controls.Add(filter.GetFilterUI());
|
|
}
|
|
}
|
|
|
|
|
|
Program.LocalSettings.LastConfigFileName = fileName;
|
|
Program.LocalSettings.Save();
|
|
Text = string.Format("{0} ver.{1} ({2})", Strings.Results_Browser, Program.Version, Program.LocalSettings.LastConfigFileName);
|
|
}
|
|
|
|
private void saveConfigBtn_Click(object sender, EventArgs e)
|
|
{
|
|
if (filtersConfig.UpdateFromFilters(filters)) /// filtersConfig members related to filters
|
|
{
|
|
/// Save column widths of the ListView into filtersConfig members
|
|
if (resultsListView.Columns.Count > 0)
|
|
{
|
|
filtersConfig.ResultsClmnWidths = new int[resultsListView.Columns.Count];
|
|
for (int i = 0; i < resultsListView.Columns.Count; i++)
|
|
{
|
|
filtersConfig.ResultsClmnWidths[i] = resultsListView.Columns[i].Width;
|
|
}
|
|
}
|
|
|
|
/// Save the file
|
|
SaveFileDialog dlg = new SaveFileDialog();
|
|
dlg.Filter = string.Format(OpenFileDlg_SaveFileDlg_Filter, Strings.Query_files, Strings.All_files);
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
filtersConfig.Save(dlg.FileName);
|
|
|
|
|
|
Program.LocalSettings.LastConfigFileName = dlg.FileName;
|
|
Program.LocalSettings.Save();
|
|
Text = string.Format("{0} ver.{1} ({2})", Strings.Results_Browser, Program.Version, Program.LocalSettings.LastConfigFileName);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void executeQueryBtn_Click(object sender, EventArgs e)
|
|
{
|
|
timePeriodStart = new DateTime(0);
|
|
timePeriodEnd = new DateTime(0);
|
|
|
|
try
|
|
{
|
|
foreach (var filter in filters) filter.UI2Data(); /// Update filter data
|
|
|
|
waterMeters = null;
|
|
IList<WaterMeter> waterMeters2;
|
|
|
|
Results.DB.ConnectionString = checkBox1.Checked ? Program.LocalSettings.ConnectionString1 :
|
|
(checkBox2.Checked ? Program.LocalSettings.ConnectionString2 :
|
|
(checkBox3.Checked ? Program.LocalSettings.ConnectionString3 :
|
|
(checkBox4.Checked ? Program.LocalSettings.ConnectionString4 :
|
|
(checkBox5.Checked ? Program.LocalSettings.ConnectionString5 :
|
|
(checkBox6.Checked ? Program.LocalSettings.ConnectionString6 :
|
|
Program.LocalSettings.ConnectionString1)))));
|
|
|
|
ISession[] sessions = new ISession[] { Results.DB.CreateSession() };
|
|
|
|
foreach (var filter in filters)
|
|
{
|
|
if (filter is DateFilter)
|
|
{
|
|
timePeriodStart = (filter as DateFilter).From;
|
|
timePeriodEnd = (filter as DateFilter).To;
|
|
}
|
|
waterMeters2 = filter.ExecuteQuery(sessions, waterMeters);
|
|
waterMeters = waterMeters2;
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
string message = exc.Message;
|
|
if (exc.InnerException != null)
|
|
message += string.Format("{0}Inner exception:{0}{1}", Environment.NewLine, exc.InnerException.Message);
|
|
|
|
MessageBox.Show(message, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
return;
|
|
}
|
|
|
|
RedrawResults();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Displays obtained results as configured by result items in the ListView
|
|
/// </summary>
|
|
void RedrawResults()
|
|
{
|
|
IList<Results.WMeterRsltItemSpec> items = Results.WMeterRsltItemSpec.FromStrArray(filtersConfig.ResultItems);
|
|
|
|
resultsListView.Clear();
|
|
if (waterMeters == null || waterMeters.Count == 0 || items.Count == 0) return;
|
|
|
|
try
|
|
{
|
|
for (int i = 0; i < items.Count; i++)
|
|
{
|
|
resultsListView.Columns.Add(items[i].Caption, (filtersConfig.ResultsClmnCount > i) ? filtersConfig.ResultsClmnWidths[i] : 70);
|
|
}
|
|
foreach (var wm in waterMeters)
|
|
{
|
|
ListViewItem lvi = null;
|
|
foreach (var item in items)
|
|
{
|
|
/// Get text and strip color information
|
|
string itemText = item.Print(wm);
|
|
string[] texts = itemText.Split(new char[] { '|' });
|
|
if (texts.Length == 2) { itemText = texts[0]; }
|
|
|
|
if (lvi == null)
|
|
lvi = new ListViewItem(itemText);
|
|
else
|
|
lvi.SubItems.Add(itemText);
|
|
}
|
|
if (lvi != null) resultsListView.Items.Add(lvi);
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
MessageBox.Show(exc.Message, Strings.Error_displaying_results, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
}
|
|
}
|
|
|
|
private void exportQueryResultsBtn_Click(object sender, EventArgs e)
|
|
{
|
|
IList<Results.WMeterRsltItemSpec> items = Results.WMeterRsltItemSpec.FromStrArray(filtersConfig.ResultItems);
|
|
|
|
if (waterMeters == null || waterMeters.Count == 0 || items.Count == 0) return;
|
|
|
|
SaveFileDialog dlg = new SaveFileDialog();
|
|
dlg.Filter = "CSV files (*.csv)|*.csv|All files (*.*)|*.*";
|
|
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
try
|
|
{
|
|
using (TextWriter writer = new StreamWriter(dlg.FileName, false, System.Text.Encoding.UTF8))
|
|
{
|
|
for (int i = 0; i < items.Count; i++)
|
|
{
|
|
writer.Write(items[i].Caption);
|
|
|
|
if (i == items.Count - 1)
|
|
writer.WriteLine(); /// New line after the last item
|
|
else
|
|
writer.Write(";"); /// Semicolon between two items
|
|
}
|
|
|
|
foreach (var wm in waterMeters)
|
|
{
|
|
for (int i = 0; i < items.Count; i++)
|
|
{
|
|
/// Get text and strip color information
|
|
string itemText = items[i].Print(wm);
|
|
string[] texts = itemText.Split(new char[] { '|' });
|
|
if (texts.Length == 2) { itemText = texts[0]; }
|
|
|
|
writer.Write(itemText);
|
|
|
|
if (i == items.Count - 1)
|
|
writer.WriteLine(); /// New line after the last item
|
|
else
|
|
writer.Write(";"); /// Semicolon between two items
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
MessageBox.Show(exc.Message, Strings.Error_exporting_results, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void printQueryResultsBtn_Click(object sender, EventArgs e)
|
|
{
|
|
if (waterMeters == null || waterMeters.Count == 0) return;
|
|
|
|
#if MUNICH
|
|
foreach (var wm in waterMeters)
|
|
{
|
|
new Results.Output.Printers.Munich.MunichPrintDocument(string.Format("4/13 - {0}", BenchName()), wm, Config.Entities.PageOrientation.Portrait).Print();
|
|
}
|
|
#elif CEVAK_40
|
|
IList<Results.Entities.Batch> batches = new List<Results.Entities.Batch>();
|
|
foreach (var wm in waterMeters)
|
|
{
|
|
if (!batches.Contains(wm.Batch)) batches.Add(wm.Batch);
|
|
}
|
|
|
|
//foreach (var batch in batches)
|
|
//{
|
|
// new Results.Output.Printers.Cevak.PrintDocumentCevak(batch,
|
|
// Config.Entities.PageOrientation.Portrait,
|
|
// 60, 60, 60,
|
|
// "PT40 Z/E-35-A",
|
|
// "0111-OOP-C035-13").Print();
|
|
//}
|
|
#else
|
|
if (string.IsNullOrEmpty(filtersConfig.PrinterClass))
|
|
{
|
|
MessageBox.Show(Strings.No_printer_defined);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
Config.Entities.Component cmpnt = new Config.Entities.Component();
|
|
cmpnt.Name = "printer";
|
|
cmpnt.ClassName = filtersConfig.PrinterClass;
|
|
cmpnt.Parameters = filtersConfig.PrinterCfg;
|
|
|
|
IComponentFactory printerFactory = GetFactory(filtersConfig.PrinterClass);
|
|
IComponentCfg printerCfg = printerFactory.CmpntCfgFromCmpntEntity(cmpnt);
|
|
IComponent component = printerFactory.GetComponent(printerCfg, tbfComponents);
|
|
IResultsPrinter printer = component as IResultsPrinter;
|
|
|
|
if (printer== null)
|
|
{
|
|
MessageBox.Show(Strings.No_printer_defined);
|
|
return;
|
|
}
|
|
|
|
tbfComponents.Clear();
|
|
tbfDevices.Clear();
|
|
tbfComponents.Add(component);
|
|
IDevice dev = component as IDevice;
|
|
if (dev != null)
|
|
{
|
|
dev.Initialize();
|
|
tbfDevices.Add(dev);
|
|
}
|
|
|
|
/// Find batches
|
|
IList<Results.Entities.Batch> batches = new List<Results.Entities.Batch>();
|
|
foreach (var wm in waterMeters)
|
|
{
|
|
if (!batches.Contains(wm.Batch)) batches.Add(wm.Batch);
|
|
}
|
|
|
|
foreach (var batch in batches)
|
|
{
|
|
IOperation printOp = printer.PrintResultsOp(batch);
|
|
printOp.Start();
|
|
while (printOp.Run() != Event.ResultsPrinted) { }
|
|
printOp.Stop();
|
|
}
|
|
|
|
MessageBox.Show(Strings.Printing_completed);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageBox.Show(Strings.Printing_failed);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
|
|
private void statisticsBtn_Click(object sender, EventArgs e)
|
|
{
|
|
if (waterMeters == null || waterMeters.Count == 0) return;
|
|
|
|
IList<Results.WMeterRsltItemSpec> items = Results.WMeterRsltItemSpec.FromStrArray(filtersConfig.ResultItems);
|
|
|
|
///
|
|
/// Statistics options
|
|
///
|
|
Forms.StatisticsOptionsDlg optionsDlg = new Forms.StatisticsOptionsDlg(items);
|
|
if (optionsDlg.ShowDialog() != DialogResult.OK) return;
|
|
|
|
///
|
|
/// Calculate statistics
|
|
///
|
|
Forms.StatisticsDlg statisticsDlg = new Forms.StatisticsDlg(waterMeters, optionsDlg, timePeriodStart, timePeriodEnd);
|
|
statisticsDlg.ShowDialog();
|
|
}
|
|
|
|
|
|
private void histogramBtn_Click(object sender, EventArgs e)
|
|
{
|
|
if (waterMeters == null || waterMeters.Count == 0) return;
|
|
|
|
IList<Results.WMeterRsltItemSpec> items = Results.WMeterRsltItemSpec.FromStrArray(filtersConfig.ResultItems);
|
|
|
|
///
|
|
/// Histogram options
|
|
///
|
|
Forms.HistogramOptionsDlg optionsDlg = new Forms.HistogramOptionsDlg(items);
|
|
if (optionsDlg.ShowDialog() != DialogResult.OK) return;
|
|
|
|
///
|
|
/// Calculate and display histograms
|
|
///
|
|
Forms.HistogramDlg histogramDlg = new Forms.HistogramDlg(waterMeters, optionsDlg, "Histogramy");
|
|
histogramDlg.ShowDialog();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Updates component factory
|
|
/// </summary>
|
|
/// <param name="className">Component class name</param>
|
|
/// <param name="factory">Reference to a factory</param>
|
|
/// <returns>true when factory changed</returns>
|
|
IComponentFactory GetFactory(string className)
|
|
{
|
|
if (!string.IsNullOrEmpty(className))
|
|
{
|
|
foreach (var fac in TbfComponents.Factories)
|
|
{
|
|
if (fac.ClassName == className) return fac;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private void customQueryButton_Click(object sender, EventArgs e)
|
|
{
|
|
#if IPERL
|
|
try
|
|
{
|
|
string[] orders = new string[] { "3137303", "3137301", "3142304", "3137302", "3137300" };
|
|
|
|
IList<OraData> oraDatas = new List<OraData>(); /// List of water meters
|
|
IList<int> testBenches = new List<int>(); /// List of test benches used to produce water meters
|
|
|
|
///
|
|
/// Get list of water meters satisfying (custom) criteria
|
|
///
|
|
Console.WriteLine("Collecting water meters");
|
|
foreach (var order in orders)
|
|
{
|
|
oracleConnection = new OracleConnection("Data Source=STARA01.WORLD;User Id=deltachef;Password=deltachef;");
|
|
oracleConnection.Open();
|
|
|
|
OracleCommand cmd = new OracleCommand("select VT_FERNUM, MAX_PRUEFINDEX, ZAEHLERNUMMER from VT_ZAEHLER_PD where AUFTRAGSNUMMER = :1 AND ANBID = 4 order by ZAEHLERNUMMER", oracleConnection);
|
|
cmd.Parameters.Add(new OracleParameter { ParameterName = "1", OracleDbType = OracleDbType.Varchar2, Value = order });
|
|
OracleDataReader dr = cmd.ExecuteReader();
|
|
int count = 0;
|
|
while (dr.Read())
|
|
{
|
|
int i = 0;
|
|
string pcbNr = dr.GetString(i++);
|
|
int maxPruefIx = dr.GetInt32(i++);
|
|
int testBenchId = maxPruefIx / 100;
|
|
maxPruefIx = maxPruefIx % 100;
|
|
int sn = dr.GetInt32(i++);
|
|
|
|
oraDatas.Add(new OraData() { PO = order, PcbNr = pcbNr, TestBenchId = testBenchId, MaxPruefIx = maxPruefIx, SN = sn });
|
|
if (!testBenches.Contains(testBenchId)) testBenches.Add(testBenchId);
|
|
count++;
|
|
}
|
|
dr.Close();
|
|
|
|
Console.WriteLine(string.Format("Order = {0} ... {1} water meters found", order, count));
|
|
}
|
|
Console.WriteLine("Collecting water meters completed");
|
|
Console.WriteLine();
|
|
|
|
///
|
|
/// Get required information about each water meter
|
|
///
|
|
Console.WriteLine("Reading additional data from Oracle");
|
|
int counter = 0;
|
|
foreach (var oraD in oraDatas)
|
|
{
|
|
Console.Write("{0} ", ++counter);
|
|
if (counter % 40 == 0) Console.WriteLine();
|
|
|
|
///
|
|
/// Read from VT_ZAEHLER_PINDEX_PD: TestId(ID_WZPRUEFREIHE))
|
|
///
|
|
OracleCommand cmd = new OracleCommand("select ID_PRUEFSTAND, ID_WZPRUEFREIHE, WT_PLATZ_NR, HYDR_PRUEFUNG from VT_ZAEHLER_PINDEX_PD where VT_FERNUM = :1 AND ANBID = 4 AND WZGUT = 1", oracleConnection);
|
|
cmd.Parameters.Add(new OracleParameter { ParameterName = "1", OracleDbType = OracleDbType.Varchar2, Value = oraD.PcbNr });
|
|
OracleDataReader dr = cmd.ExecuteReader();
|
|
while (dr.Read())
|
|
{
|
|
int i = 0;
|
|
int testBenchId = dr.GetInt32(i++) % 100;
|
|
oraD.TestId = dr.GetInt32(i++);
|
|
oraD.WMPosition = dr.GetInt32(i++);
|
|
oraD.HydrPruefung = dr.GetInt32(i++);
|
|
}
|
|
dr.Close();
|
|
|
|
///
|
|
/// Read from VT_IP_ZAEHLER_PINDEX_PD: Q2CorrectionRl, Q2CorrectionLr
|
|
///
|
|
cmd = new OracleCommand("select PRUEFINDEX, Q2CORRECTIONLEFT, Q2CORRECTIONRIGHT from VT_IP_ZAEHLER_PINDEX_PD where VT_FERNUM = :1 AND ANBID = 4", oracleConnection);
|
|
/// pruefindex, Q2_correction_RL, Q2_correction_LR, Q2_error_before_correction
|
|
cmd.Parameters.Add(new OracleParameter { OracleDbType = OracleDbType.Varchar2, Value = oraD.PcbNr });
|
|
dr = cmd.ExecuteReader();
|
|
while (dr.Read())
|
|
{
|
|
int i = 0;
|
|
int prfix = (dr.GetInt32(i++) % 100);
|
|
if (prfix == oraD.MaxPruefIx)
|
|
{
|
|
oraD.Q2CorrectionRl = dr.GetInt32(i++);
|
|
oraD.Q2CorrectionLr = dr.GetInt32(i++);
|
|
}
|
|
}
|
|
dr.Close();
|
|
|
|
///
|
|
/// Read data from VT_PRUEFREIHE_IST_PD
|
|
///
|
|
/// testID, flow, rel.err., passed
|
|
cmd = new OracleCommand("select PRUEFUNGSNR, Q_WZ, Q_FEHLER, Q_BEST from VT_PRUEFREIHE_IST_PD where VT_FERNUM = :1 AND PRUEFINDEX = :2 AND ANBID = 4", oracleConnection);
|
|
cmd.Parameters.Add(new OracleParameter { OracleDbType = OracleDbType.Varchar2, Value = oraD.PcbNr });
|
|
cmd.Parameters.Add(new OracleParameter { OracleDbType = OracleDbType.Int32, Value = 100 * oraD.TestBenchId + oraD.MaxPruefIx });
|
|
|
|
dr = cmd.ExecuteReader();
|
|
while (dr.Read())
|
|
{
|
|
int i = 0;
|
|
int testId = dr.GetInt32(i++); /// PRUEFUNGSNR
|
|
double flow = dr.GetDouble(i++); /// Q_WZ
|
|
double error = dr.GetDouble(i++); /// Q_FEHLER
|
|
bool testPassed = (dr.GetInt32(i++) != 0);
|
|
|
|
/// SUEZ specific
|
|
switch (testId)
|
|
{
|
|
case -2:
|
|
oraD.AdjErrA4 = error;
|
|
break;
|
|
case -1:
|
|
oraD.AdjErr = error;
|
|
break;
|
|
case 5:
|
|
oraD.Q3LrErr = error;
|
|
break;
|
|
case 10:
|
|
oraD.Q3RlErr = error;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
dr.Close();
|
|
} /// end of foreach (var oraD in OraDatas)
|
|
Console.WriteLine();
|
|
Console.WriteLine("Reading additional data from Oracle completed");
|
|
Console.WriteLine();
|
|
|
|
oracleConnection.Close();
|
|
|
|
Console.WriteLine("Reading additional data from MySQL");
|
|
counter = 0;
|
|
foreach (var testBenchId in testBenches)
|
|
{
|
|
Console.WriteLine((testBenchId == 8) ? "WR13" : (testBenchId == 9) ? "WR15" : (testBenchId == 10) ? "WR14" : "other");
|
|
|
|
switch (testBenchId)
|
|
{
|
|
case 8:
|
|
Results.DB.ConnectionString = "SERVER=localhost; DATABASE=st-wr13-r; UID=root; PASSWORD=kraken; CharSet=utf8;";
|
|
break;
|
|
case 9:
|
|
Results.DB.ConnectionString = "SERVER=localhost; DATABASE=st-wr15-r; UID=root; PASSWORD=kraken; CharSet=utf8;";
|
|
break;
|
|
case 10:
|
|
Results.DB.ConnectionString = "SERVER=localhost; DATABASE=st-wr14-r; UID=root; PASSWORD=kraken; CharSet=utf8;";
|
|
break;
|
|
default:
|
|
Results.DB.ConnectionString = string.Empty;
|
|
break;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(Results.DB.ConnectionString))
|
|
{
|
|
ISession session = Results.DB.CreateSession();
|
|
|
|
foreach (var oraD in oraDatas)
|
|
{
|
|
|
|
if (oraD.TestBenchId == testBenchId)
|
|
{
|
|
Console.Write("{0} ", ++counter);
|
|
if (counter % 40 == 0) Console.WriteLine();
|
|
|
|
IList<WaterMeter> wms = session.QueryOver<WaterMeter>()
|
|
.Where(x => x.SerialNr == oraD.PcbNr)
|
|
.And(x => x.Passed)
|
|
.List();
|
|
|
|
if (wms.Count == 1)
|
|
{
|
|
oraD.CalibFactor = (int)Math.Round(wms[0].CalibFactor);
|
|
oraD.CalibFactorLNA = (int)Math.Round(wms[0].CalibFactorLNA);
|
|
}
|
|
else
|
|
{
|
|
foreach (var wm in wms)
|
|
{
|
|
if (wm.Batch.BatchNr == oraD.TestId)
|
|
{
|
|
oraD.CalibFactor = (int)Math.Round(wm.CalibFactor);
|
|
oraD.CalibFactorLNA = (int)Math.Round(wm.CalibFactorLNA);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Console.WriteLine();
|
|
|
|
session.Close();
|
|
}
|
|
}
|
|
Console.WriteLine("Reading additional data from MySQL");
|
|
Console.WriteLine();
|
|
|
|
Console.WriteLine("CSV data begin");
|
|
foreach (var oraD in oraDatas)
|
|
{
|
|
//Console.WriteLine(string.Format("S/N={0} PCB={1} bench={2} Batch={3} Pos={4} AdjA0={5} AdjA4={6} Q3RL={7} Q3LR={8} CalF={9} CAlF_LNA={10} HP={11} Q2cRL={12} Q2cLR={13}",
|
|
// oraD.SN,
|
|
// oraD.PcbNr,
|
|
// (oraD.TestBenchId == 8) ? "WR13" : (oraD.TestBenchId == 9) ? "WR15" : (oraD.TestBenchId == 10) ? "WR14" : "other",
|
|
// oraD.TestId,
|
|
// oraD.WMPosition,
|
|
// oraD.AdjErr.ToString("F1"),
|
|
// oraD.AdjErrA4.ToString("F1"),
|
|
// oraD.Q3RlErr.ToString("F1"),
|
|
// oraD.Q3LrErr.ToString("F1"),
|
|
// oraD.CalibFactor,
|
|
// oraD.CalibFactorLNA,
|
|
// oraD.HydrPruefung,
|
|
// oraD.Q2CorrectionRl,
|
|
// oraD.Q2CorrectionLr));
|
|
|
|
Console.WriteLine(string.Format("{0}; =(\"{1}\"); {2}; {3}; {4}; {5}; {6}; {7}; {8}; {9}; {10}; {12}; {13}",
|
|
oraD.SN,
|
|
oraD.PcbNr,
|
|
(oraD.TestBenchId == 8) ? "WR13" : (oraD.TestBenchId == 9) ? "WR15" : (oraD.TestBenchId == 10) ? "WR14" : "other",
|
|
oraD.TestId,
|
|
oraD.WMPosition,
|
|
oraD.AdjErr.ToString("F2"),
|
|
oraD.AdjErrA4.ToString("F2"),
|
|
oraD.Q3RlErr.ToString("F2"),
|
|
oraD.Q3LrErr.ToString("F2"),
|
|
oraD.CalibFactor,
|
|
oraD.CalibFactorLNA,
|
|
oraD.HydrPruefung,
|
|
oraD.Q2CorrectionRl,
|
|
oraD.Q2CorrectionLr));
|
|
}
|
|
Console.WriteLine("CSV data end");
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
MessageBox.Show(exc.Message);
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
}
|