2016-06-01 10:09:03 +00:00
|
|
|
|
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;
|
2016-06-02 22:19:23 +00:00
|
|
|
|
using NHibernate;
|
|
|
|
|
|
using Results.Entities;
|
2016-06-01 10:09:03 +00:00
|
|
|
|
using ResultsBrowser.Filters;
|
|
|
|
|
|
using ResultsBrowser.Resources;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ResultsBrowser
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class ResultsBrowserWnd : Form
|
|
|
|
|
|
{
|
2016-06-02 22:19:23 +00:00
|
|
|
|
IList<Filters.IFilter> filters;
|
2016-06-01 10:09:03 +00:00
|
|
|
|
|
|
|
|
|
|
public ResultsBrowserWnd()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2016-06-02 22:19:23 +00:00
|
|
|
|
filters = new List<Filters.IFilter>();
|
2016-06-01 10:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ResultsBrowserWnd_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Localize();
|
2016-06-02 18:35:04 +00:00
|
|
|
|
RedrawTestBenches();
|
2016-06-02 22:19:23 +00:00
|
|
|
|
|
|
|
|
|
|
checkBox1.Checked = true;
|
2016-06-02 18:35:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2016-06-01 10:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Localize()
|
|
|
|
|
|
{
|
2016-06-02 18:35:04 +00:00
|
|
|
|
Text = "Results Browser"; /// or Statistics
|
|
|
|
|
|
filtersGroupBox.Text = "Filters";
|
|
|
|
|
|
resultsGroupBox.Text = "Query results";
|
|
|
|
|
|
settingsBtn.Text = "Settings";
|
|
|
|
|
|
addFilterBtn.Text = "Add filter";
|
|
|
|
|
|
loadQueryBtn.Text = "Load query";
|
|
|
|
|
|
saveQueryBtn.Text = "Save query";
|
|
|
|
|
|
testBenchesGroupBox.Text = "Test benches";
|
|
|
|
|
|
executeQueryBtn.Text = "Execute query";
|
2016-06-01 10:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void settingsBtn_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2016-06-02 18:35:04 +00:00
|
|
|
|
if (new Forms.DatabaseSettingsDlg().ShowDialog() == DialogResult.OK)
|
|
|
|
|
|
{
|
|
|
|
|
|
RedrawTestBenches();
|
|
|
|
|
|
}
|
2016-06-01 10:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void addFilterBtn_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Forms.AddFilterDlg dlg = new Forms.AddFilterDlg();
|
|
|
|
|
|
if (dlg.ShowDialog() == DialogResult.OK && dlg.SelectedFilterName != null)
|
|
|
|
|
|
{
|
2016-06-02 22:19:23 +00:00
|
|
|
|
Filters.IFilter filter = Factory.GetFilter(dlg.SelectedFilterName);
|
2016-06-02 18:35:04 +00:00
|
|
|
|
filters.Add(filter);
|
|
|
|
|
|
filtersFlowLayoutPanel.Controls.Add(filter.GetFilterUI());
|
2016-06-01 10:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void loadQueryBtn_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
OpenFileDialog dlg = new OpenFileDialog();
|
|
|
|
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
|
|
|
|
{
|
2016-06-02 18:35:04 +00:00
|
|
|
|
FiltersConfig filtersConfig = FiltersConfig.Load(dlg.FileName);
|
2016-06-01 10:09:03 +00:00
|
|
|
|
|
2016-06-02 18:35:04 +00:00
|
|
|
|
filters.Clear();
|
2016-06-01 10:09:03 +00:00
|
|
|
|
filtersFlowLayoutPanel.Controls.Clear();
|
2016-06-02 18:35:04 +00:00
|
|
|
|
///
|
|
|
|
|
|
for (int i = 0; i < filtersConfig.FiltersCount; i++)
|
2016-06-01 10:09:03 +00:00
|
|
|
|
{
|
2016-06-02 22:19:23 +00:00
|
|
|
|
Filters.IFilter filter = Factory.LoadFilter(filtersConfig.FilterName[i], filtersConfig.FilterData[i]);
|
2016-06-02 18:35:04 +00:00
|
|
|
|
filters.Add(filter);
|
|
|
|
|
|
filtersFlowLayoutPanel.Controls.Add(filter.GetFilterUI());
|
2016-06-01 10:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void saveQueryBtn_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
2016-06-02 18:35:04 +00:00
|
|
|
|
FiltersConfig filtersConfig = new FiltersConfig(filters.Count);
|
2016-06-01 10:09:03 +00:00
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2016-06-02 18:35:04 +00:00
|
|
|
|
for (int i = 0; i < filters.Count; i++)
|
2016-06-01 10:09:03 +00:00
|
|
|
|
{
|
2016-06-02 18:35:04 +00:00
|
|
|
|
filtersConfig.FilterName[i] = filters[i].GetThisFilterName();
|
2016-06-01 10:09:03 +00:00
|
|
|
|
sb.Clear();
|
2016-06-02 18:35:04 +00:00
|
|
|
|
filters[i].UI2Data();
|
|
|
|
|
|
filters[i].Save(sb);
|
|
|
|
|
|
filtersConfig.FilterData[i] = sb.ToString();
|
2016-06-01 10:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exc)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SaveFileDialog dlg = new SaveFileDialog();
|
|
|
|
|
|
if (dlg.ShowDialog() == DialogResult.OK)
|
|
|
|
|
|
{
|
2016-06-02 18:35:04 +00:00
|
|
|
|
filtersConfig.Save(dlg.FileName);
|
2016-06-01 10:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-02 18:35:04 +00:00
|
|
|
|
private void checkBox1_CheckedChanged(object sender, EventArgs e)
|
2016-06-01 10:09:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-02 18:35:04 +00:00
|
|
|
|
private void checkBox2_CheckedChanged(object sender, EventArgs e)
|
2016-06-01 10:09:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-02 18:35:04 +00:00
|
|
|
|
private void checkBox3_CheckedChanged(object sender, EventArgs e)
|
2016-06-01 10:09:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-02 18:35:04 +00:00
|
|
|
|
private void executeQueryBtn_Click(object sender, EventArgs e)
|
2016-06-01 10:09:03 +00:00
|
|
|
|
{
|
2016-06-02 22:19:23 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var filter in filters) filter.UI2Data(); /// Update filter data
|
|
|
|
|
|
|
|
|
|
|
|
IList<WaterMeter> 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() };
|
2016-06-01 10:09:03 +00:00
|
|
|
|
|
2016-06-02 22:19:23 +00:00
|
|
|
|
foreach (var filter in filters)
|
|
|
|
|
|
{
|
|
|
|
|
|
waterMeters2 = filter.ExecuteQuery(sessions, waterMeters);
|
|
|
|
|
|
waterMeters = waterMeters2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resultsListBox.Items.Clear();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var wm in waterMeters) resultsListBox.Items.Add(wm.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exc)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2016-06-01 10:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|