324 lines
12 KiB
C#
324 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using NHibernate;
|
|
using Results.Entities;
|
|
using ResultsBrowser.Filters;
|
|
using ResultsBrowser.Resources;
|
|
|
|
namespace ResultsBrowser
|
|
{
|
|
public partial class ResultsBrowserWnd : Form
|
|
{
|
|
const string OpenFileDlg_SaveFileDlg_Filter = "{0} (*.qry)|*.qry|{1} (*.*)|*.*";
|
|
|
|
string[] args;
|
|
|
|
IList<Filters.IFilter> filters; /// Filters and the UI of filters
|
|
FiltersConfig filtersConfig; /// Serializable configuration of filters and displayed results
|
|
|
|
IList<WaterMeter> waterMeters;
|
|
|
|
public ResultsBrowserWnd(string[] args)
|
|
{
|
|
InitializeComponent();
|
|
filters = new List<Filters.IFilter>();
|
|
filtersConfig = new FiltersConfig();
|
|
this.args = args;
|
|
}
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
checkBox1.Visible = !string.IsNullOrEmpty(checkBox1.Text);
|
|
checkBox2.Visible = !string.IsNullOrEmpty(checkBox2.Text);
|
|
checkBox3.Visible = !string.IsNullOrEmpty(checkBox3.Text);
|
|
}
|
|
|
|
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;
|
|
loadConfigBtn.Text = Strings.Load_filters;
|
|
saveConfigBtn.Text = Strings.Save_filters;
|
|
executeQueryBtn.Text = Strings.Execute_query;
|
|
formatOfResultsBtn.Text = Strings.Format_of_results;
|
|
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(); }
|
|
|
|
void SaveCheckBoxes()
|
|
{
|
|
Program.LocalSettings.Bench1Selected = checkBox1.Checked;
|
|
Program.LocalSettings.Bench2Selected = checkBox2.Checked;
|
|
Program.LocalSettings.Bench3Selected = checkBox3.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 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)
|
|
{
|
|
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 :
|
|
Program.LocalSettings.ConnectionString1));
|
|
|
|
ISession[] sessions = new ISession[] { Results.DB.CreateSession() };
|
|
|
|
foreach (var filter in filters)
|
|
{
|
|
waterMeters2 = filter.ExecuteQuery(sessions, waterMeters);
|
|
waterMeters = waterMeters2;
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
MessageBox.Show(exc.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)
|
|
{
|
|
if (lvi == null) lvi = new ListViewItem(item.Print(wm));
|
|
else lvi.SubItems.Add(item.Print(wm));
|
|
}
|
|
if (lvi != null) resultsListView.Items.Add(lvi);
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
MessageBox.Show(exc.Message, Strings.Error_displaying_results, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
}
|
|
}
|
|
|
|
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);
|
|
dlg.AvailableItems = new List<Results.WMeterRsltItemSpec>();
|
|
foreach (var v in Results.WMeterRsltItemSpec.AllItems) dlg.AvailableItems.Add(v);
|
|
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
filtersConfig.ResultItems = Results.WMeterRsltItemSpec.ToStrArray(dlg.SelectedItems);
|
|
RedrawResults();
|
|
}
|
|
}
|
|
|
|
private void exportQueryResultsBtn_Click(object sender, EventArgs e)
|
|
{
|
|
if (waterMeters == null || waterMeters.Count == 0) return;
|
|
|
|
}
|
|
|
|
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("", wm, Config.Entities.PageOrientation.Portrait).Print();
|
|
}
|
|
#elif CEVAK_PT40_272
|
|
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();
|
|
}
|
|
#endif
|
|
}
|
|
|
|
private void statisticsBtn_Click(object sender, EventArgs e)
|
|
{
|
|
if (waterMeters == null || waterMeters.Count == 0) return;
|
|
|
|
///
|
|
/// Enter options
|
|
///
|
|
Forms.StatisticsOptionsDlg dlg = new Forms.StatisticsOptionsDlg();
|
|
if (dlg.ShowDialog() != DialogResult.OK) return;
|
|
|
|
///
|
|
/// Calculate statistics
|
|
///
|
|
Forms.StatisticsDlg statisticsDlg = new Forms.StatisticsDlg(waterMeters, dlg.TwoDim, dlg.RowItemID, dlg.ColumnItemID, dlg.RowTestSpecifier, dlg.ColumnTestSpecifier);
|
|
statisticsDlg.ShowDialog();
|
|
}
|
|
}
|
|
}
|