2016-06-03 12:03:12 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using Results.Entities;
|
|
|
|
|
|
using ResultsBrowser.Resources;
|
2016-11-18 13:09:12 +00:00
|
|
|
|
using ResultsBrowser.Output.Printers.Statistics;
|
2016-06-03 12:03:12 +00:00
|
|
|
|
|
|
|
|
|
|
namespace ResultsBrowser.Forms
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class StatisticsDlg : Form
|
|
|
|
|
|
{
|
|
|
|
|
|
IList<WaterMeter> waterMeters;
|
|
|
|
|
|
|
|
|
|
|
|
bool twoDim;
|
|
|
|
|
|
|
|
|
|
|
|
Results.WMeterRsltItemSpec rowItem;
|
2016-11-18 13:09:12 +00:00
|
|
|
|
Results.WMeterRsltItemSpec rowItemExt;
|
|
|
|
|
|
Results.WMeterRsltItemSpec columnItem;
|
|
|
|
|
|
Results.WMeterRsltItemSpec columnItemExt;
|
2016-06-03 12:03:12 +00:00
|
|
|
|
|
2016-11-18 10:39:07 +00:00
|
|
|
|
string rowTestSpec;
|
2016-11-18 13:09:12 +00:00
|
|
|
|
string rowExtTestSpec;
|
2016-11-18 10:39:07 +00:00
|
|
|
|
string columnTestSpec;
|
2016-11-18 13:09:12 +00:00
|
|
|
|
string columnExtTestSpec;
|
2016-11-18 10:39:07 +00:00
|
|
|
|
|
2016-06-03 12:03:12 +00:00
|
|
|
|
IList<string> rowValues;
|
|
|
|
|
|
IList<string> columnValues;
|
|
|
|
|
|
|
2016-11-18 13:09:12 +00:00
|
|
|
|
int[,] occurances;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public StatisticsDlg(IList<WaterMeter> waterMeters, bool twoDim,
|
|
|
|
|
|
Results.WMeterRsltItemSpec rowItem,
|
|
|
|
|
|
Results.WMeterRsltItemSpec rowItemExt,
|
|
|
|
|
|
Results.WMeterRsltItemSpec columnItem,
|
|
|
|
|
|
Results.WMeterRsltItemSpec columnItemExt,
|
|
|
|
|
|
string rowTestSpec,
|
|
|
|
|
|
string rowExtTestSpec,
|
|
|
|
|
|
string columnTestSpec,
|
|
|
|
|
|
string columnExtTestSpec)
|
2016-06-03 12:03:12 +00:00
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
|
|
Text = Strings.Statistics;
|
2016-11-18 13:09:12 +00:00
|
|
|
|
closeButton.Text = Strings.OkBtnText;
|
2016-06-03 12:03:12 +00:00
|
|
|
|
|
|
|
|
|
|
this.waterMeters = waterMeters;
|
|
|
|
|
|
|
|
|
|
|
|
this.twoDim = twoDim;
|
2016-11-18 13:09:12 +00:00
|
|
|
|
|
2016-11-18 10:39:07 +00:00
|
|
|
|
this.rowItem = rowItem;
|
2016-11-18 13:09:12 +00:00
|
|
|
|
this.rowItemExt = rowItemExt;
|
2016-11-18 10:39:07 +00:00
|
|
|
|
this.columnItem = columnItem;
|
2016-11-18 13:09:12 +00:00
|
|
|
|
this.columnItemExt = columnItemExt;
|
2016-11-18 10:39:07 +00:00
|
|
|
|
this.rowTestSpec = rowTestSpec;
|
2016-11-18 13:09:12 +00:00
|
|
|
|
this.rowExtTestSpec = rowExtTestSpec;
|
|
|
|
|
|
this.columnTestSpec = columnTestSpec;
|
|
|
|
|
|
this.columnExtTestSpec = columnExtTestSpec;
|
2016-06-03 12:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void StatisticsDlg_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Calculate();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Calculate()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
rowValues = new List<string>();
|
|
|
|
|
|
columnValues = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Find discrete values of rows and columns
|
|
|
|
|
|
///
|
|
|
|
|
|
foreach (var wm in waterMeters)
|
|
|
|
|
|
{
|
|
|
|
|
|
string value = rowItem.Print(wm);
|
2016-11-18 13:09:12 +00:00
|
|
|
|
if (rowItemExt != null) value = value + " | " + rowItemExt.Print(wm);
|
2016-06-03 12:03:12 +00:00
|
|
|
|
if (!rowValues.Contains(value)) rowValues.Add(value);
|
|
|
|
|
|
|
|
|
|
|
|
if (twoDim)
|
|
|
|
|
|
{
|
|
|
|
|
|
value = columnItem.Print(wm);
|
2016-11-18 13:09:12 +00:00
|
|
|
|
if (columnItemExt != null) value = value + " | " + columnItemExt.Print(wm);
|
|
|
|
|
|
if (!columnValues.Contains(value)) columnValues.Add(value);
|
2016-06-03 12:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Calculate occurances
|
|
|
|
|
|
///
|
2016-11-18 13:09:12 +00:00
|
|
|
|
int columnsCount = Math.Max(1, columnValues.Count);
|
|
|
|
|
|
occurances = new int[rowValues.Count, columnsCount];
|
2016-06-03 12:03:12 +00:00
|
|
|
|
|
|
|
|
|
|
foreach (var wm in waterMeters)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int row = 0; row < rowValues.Count; row++)
|
|
|
|
|
|
{
|
2016-11-18 13:09:12 +00:00
|
|
|
|
string rowValue = rowItem.Print(wm);
|
|
|
|
|
|
if (rowItemExt != null) rowValue = rowValue + " | " + rowItemExt.Print(wm);
|
|
|
|
|
|
|
2016-06-03 12:03:12 +00:00
|
|
|
|
if (twoDim)
|
|
|
|
|
|
{
|
2016-11-18 13:09:12 +00:00
|
|
|
|
for (int column = 0; column < columnsCount; column++)
|
2016-06-03 12:03:12 +00:00
|
|
|
|
{
|
2016-11-18 13:09:12 +00:00
|
|
|
|
string columnValue = columnItem.Print(wm);
|
|
|
|
|
|
if (columnItemExt != null) columnValue = columnValue + " | " + columnItemExt.Print(wm);
|
|
|
|
|
|
|
|
|
|
|
|
if (rowValue == rowValues[row] && columnValue == columnValues[column])
|
|
|
|
|
|
{
|
|
|
|
|
|
occurances[row, column]++;
|
|
|
|
|
|
}
|
2016-06-03 12:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-11-18 13:09:12 +00:00
|
|
|
|
if (rowValue == rowValues[row]) occurances[row, 0]++;
|
2016-06-03 12:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Update ListBox
|
|
|
|
|
|
///
|
2016-06-03 13:19:03 +00:00
|
|
|
|
statisticsListView.View = View.Details;
|
|
|
|
|
|
statisticsListView.GridLines = true;
|
|
|
|
|
|
statisticsListView.FullRowSelect = true;
|
|
|
|
|
|
|
2016-11-18 10:39:07 +00:00
|
|
|
|
statisticsListView.Columns.Add(" ", 200);
|
2016-11-18 13:09:12 +00:00
|
|
|
|
for (int column = 0; column < columnsCount; column++)
|
2016-06-03 13:19:03 +00:00
|
|
|
|
{
|
2016-11-18 10:39:07 +00:00
|
|
|
|
statisticsListView.Columns.Add((twoDim ? columnValues[column] : Strings.Count), 70);
|
2016-06-03 13:19:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int row = 0; row < rowValues.Count; row++)
|
|
|
|
|
|
{
|
|
|
|
|
|
ListViewItem lvi = new ListViewItem(rowValues[row]);
|
2016-11-18 13:09:12 +00:00
|
|
|
|
for (int column = 0; column < columnsCount; column++) lvi.SubItems.Add(occurances[row, column].ToString());
|
2016-06-03 13:19:03 +00:00
|
|
|
|
statisticsListView.Items.Add(lvi);
|
|
|
|
|
|
}
|
2016-06-03 12:03:12 +00:00
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exc)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show(exc.Message, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-11-18 13:09:12 +00:00
|
|
|
|
private void closeButton_Click(object sender, EventArgs e)
|
2016-06-03 12:03:12 +00:00
|
|
|
|
{
|
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
2016-11-18 13:09:12 +00:00
|
|
|
|
|
|
|
|
|
|
private void printButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
new StatisticsPrintDocument("", rowValues, columnValues, occurances, Config.Entities.PageOrientation.Portrait).Print();
|
|
|
|
|
|
}
|
2016-06-03 12:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|