ResultsBrowser: Results displayed in the window can be configured, items and column widths are saved together with filters., ver.2.7.303
This commit is contained in:
@@ -136,7 +136,7 @@ namespace Results
|
||||
AllItems.Add(new WMeterRsltItemSpec(29, "Volume", Strings.Volume_l + "()", (w, t, u, f, p) => (w.GetMeterTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetMeterTestRslt(t).VolumeMeter).ToString(string.IsNullOrEmpty(p) ? "F3" : p)));
|
||||
AllItems.Add(new WMeterRsltItemSpec(30, "Reference volume", Strings.VolRef_l + "()", (w, t, u, f, p) => (w.GetMeterTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetMeterTestRslt(t).VolumeRef).ToString(string.IsNullOrEmpty(p) ? "F3" : p)));
|
||||
#if IPERLST || IPERLST_SPECIAL
|
||||
AllItems.Add(new WMeterRsltItemSpec(31, "Error", "Error()", (w, t, u, f, p) => (w.GetMeterTestRslt(t) == null) ? "0" : Config.Units.ConvertTo(u, w.GetMeterTestRslt(t).Error).ToString(string.IsNullOrEmpty(p) ? "F2" : p)));
|
||||
AllItems.Add(new WMeterRsltItemSpec(31, "Error", Strings.Error_pct + "()", (w, t, u, f, p) => (w.GetMeterTestRslt(t) == null) ? "0" : Config.Units.ConvertTo(u, w.GetMeterTestRslt(t).Error).ToString(string.IsNullOrEmpty(p) ? "F2" : p)));
|
||||
#else
|
||||
AllItems.Add(new WMeterRsltItemSpec(31, "Error", Strings.Error_pct + "()", (w, t, u, f, p) => (w.GetMeterTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetMeterTestRslt(t).Error).ToString(string.IsNullOrEmpty(p) ? "F2" : p)));
|
||||
#endif
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
/// Copyright (c) 2016 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using System.Windows.Forms;
|
||||
using ResultsBrowser.Resources;
|
||||
|
||||
namespace ResultsBrowser
|
||||
{
|
||||
@@ -22,6 +25,13 @@ namespace ResultsBrowser
|
||||
public int FiltersCount { get { return Math.Min((FilterID != null) ? FilterID.Length : 0,
|
||||
(FilterData != null) ? FilterData.Length : 0); } }
|
||||
|
||||
public string[] ResultItems;
|
||||
|
||||
[XmlArrayAttribute("ResultsClmnWidths")]
|
||||
public int[] ResultsClmnWidths;
|
||||
[XmlIgnore]
|
||||
public int ResultsClmnCount { get { return (ResultsClmnWidths != null) ? ResultsClmnWidths.Length : 0; } }
|
||||
|
||||
|
||||
public FiltersConfig()
|
||||
{
|
||||
@@ -57,10 +67,42 @@ namespace ResultsBrowser
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates public arrays FilterID[] and FilterData[] of this serializable class.
|
||||
/// </summary>
|
||||
/// <param name="filters"></param>
|
||||
/// <returns></returns>
|
||||
public bool UpdateFromFilters(IList<Filters.IFilter> filters)
|
||||
{
|
||||
try
|
||||
{
|
||||
int cnt = filters.Count;
|
||||
FilterID = new string[cnt];
|
||||
FilterData = new string[cnt];
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
FilterID[i] = filters[i].GetThisFilterID();
|
||||
filters[i].UI2Data();
|
||||
sb.Clear();
|
||||
filters[i].Save(sb);
|
||||
FilterData[i] = sb.ToString();
|
||||
}
|
||||
|
||||
return true; /// All OK
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
MessageBox.Show(exc.Message, Strings.Error_serializing_filters, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save public fields of this class to the XML file.
|
||||
/// </summary>
|
||||
public void Save(string fileName)
|
||||
public bool Save(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -68,10 +110,12 @@ namespace ResultsBrowser
|
||||
{
|
||||
(new XmlSerializer(typeof(FiltersConfig))).Serialize(writer, this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception exc)
|
||||
{
|
||||
string msg = e.Message;
|
||||
MessageBox.Show(exc.Message, Strings.Error_saving_file, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -85,6 +85,7 @@
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.availFiltersListBox);
|
||||
this.Name = "AddFilterDlg";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
this.Text = "Select a filter";
|
||||
this.Load += new System.EventHandler(this.AddFilterDlg_Load);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
@@ -159,6 +159,7 @@
|
||||
this.Controls.Add(this.benchNameLabel);
|
||||
this.Controls.Add(this.connectionStringTextBox1);
|
||||
this.Name = "DatabaseSettingsDlg";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
this.Text = "Database Settings";
|
||||
this.Load += new System.EventHandler(this.DatabaseSettings_Load);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
@@ -160,6 +160,7 @@
|
||||
this.Controls.Add(this.cancelButton);
|
||||
this.Controls.Add(this.okButton);
|
||||
this.Name = "StatisticsOptionsDlg";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
this.Text = "StatisticsOptionsDlg";
|
||||
this.Load += new System.EventHandler(this.StatisticsOptionsDlg_Load);
|
||||
this.rowsGroupBox.ResumeLayout(false);
|
||||
|
||||
@@ -38,7 +38,6 @@ namespace ResultsBrowser
|
||||
public bool Bench2Selected;
|
||||
public bool Bench3Selected;
|
||||
|
||||
|
||||
public bool TwoDim;
|
||||
public int RowItemID;
|
||||
public int ColumnItemID;
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace ResultsBrowser
|
||||
{
|
||||
/// Open the main application window
|
||||
log.Info("Creating the main window");
|
||||
#if IPERLST || IPERLST_SPECIAL
|
||||
#if false //IPERLST || IPERLST_SPECIAL
|
||||
MainWnd = new MainWnd();
|
||||
log.Info("Opening the main window");
|
||||
Application.Run(MainWnd);
|
||||
|
||||
@@ -222,4 +222,13 @@
|
||||
<data name="Water_Meter" xml:space="preserve">
|
||||
<value>Wasserzähler</value>
|
||||
</data>
|
||||
<data name="Error_displaying_results" xml:space="preserve">
|
||||
<value>Fehler beim Anzeigen der Ergebnisse</value>
|
||||
</data>
|
||||
<data name="Error_saving_file" xml:space="preserve">
|
||||
<value>Fehler beim Speichern der Datei</value>
|
||||
</data>
|
||||
<data name="Error_serializing_filters" xml:space="preserve">
|
||||
<value>Fehler Serialisierung Filter</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -765,4 +765,19 @@
|
||||
<data name="Select_a_filter" xml:space="preserve">
|
||||
<value>Select a filter</value>
|
||||
</data>
|
||||
<data name="Error_displaying_results" xml:space="preserve">
|
||||
<value>Error displaying results</value>
|
||||
</data>
|
||||
<data name="All_files" xml:space="preserve">
|
||||
<value>All files</value>
|
||||
</data>
|
||||
<data name="Error_saving_file" xml:space="preserve">
|
||||
<value>Error saving file</value>
|
||||
</data>
|
||||
<data name="Error_serializing_filters" xml:space="preserve">
|
||||
<value>Error serializing filters</value>
|
||||
</data>
|
||||
<data name="Query_files" xml:space="preserve">
|
||||
<value>Query files</value>
|
||||
</data>
|
||||
</root>
|
||||
+45
@@ -150,6 +150,15 @@ namespace ResultsBrowser.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to All files.
|
||||
/// </summary>
|
||||
internal static string All_files {
|
||||
get {
|
||||
return ResourceManager.GetString("All_files", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Ambient humidity: .
|
||||
/// </summary>
|
||||
@@ -978,6 +987,15 @@ namespace ResultsBrowser.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Error displaying results.
|
||||
/// </summary>
|
||||
internal static string Error_displaying_results {
|
||||
get {
|
||||
return ResourceManager.GetString("Error_displaying_results", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Error loading users from the database:.
|
||||
/// </summary>
|
||||
@@ -996,6 +1014,24 @@ namespace ResultsBrowser.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Error saving file.
|
||||
/// </summary>
|
||||
internal static string Error_saving_file {
|
||||
get {
|
||||
return ResourceManager.GetString("Error_saving_file", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Error serializing filters.
|
||||
/// </summary>
|
||||
internal static string Error_serializing_filters {
|
||||
get {
|
||||
return ResourceManager.GetString("Error_serializing_filters", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Error while creating the database. Reason: .
|
||||
/// </summary>
|
||||
@@ -1725,6 +1761,15 @@ namespace ResultsBrowser.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Query files.
|
||||
/// </summary>
|
||||
internal static string Query_files {
|
||||
get {
|
||||
return ResourceManager.GetString("Query_files", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Query results.
|
||||
/// </summary>
|
||||
|
||||
+13
-12
@@ -33,7 +33,6 @@
|
||||
this.filtersGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.filtersFlowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.resultsGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.resultsListBox = new System.Windows.Forms.ListBox();
|
||||
this.statisticsBtn = new System.Windows.Forms.Button();
|
||||
this.printQueryResultsBtn = new System.Windows.Forms.Button();
|
||||
this.exportQueryResultsBtn = new System.Windows.Forms.Button();
|
||||
@@ -48,6 +47,7 @@
|
||||
this.checkBox3 = new System.Windows.Forms.RadioButton();
|
||||
this.checkBox2 = new System.Windows.Forms.RadioButton();
|
||||
this.checkBox1 = new System.Windows.Forms.RadioButton();
|
||||
this.resultsListView = new System.Windows.Forms.ListView();
|
||||
((System.ComponentModel.ISupportInitialize)(this.vSplitContainer)).BeginInit();
|
||||
this.vSplitContainer.Panel1.SuspendLayout();
|
||||
this.vSplitContainer.Panel2.SuspendLayout();
|
||||
@@ -130,7 +130,7 @@
|
||||
//
|
||||
// resultsGroupBox
|
||||
//
|
||||
this.resultsGroupBox.Controls.Add(this.resultsListBox);
|
||||
this.resultsGroupBox.Controls.Add(this.resultsListView);
|
||||
this.resultsGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.resultsGroupBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.resultsGroupBox.Name = "resultsGroupBox";
|
||||
@@ -139,15 +139,6 @@
|
||||
this.resultsGroupBox.TabStop = false;
|
||||
this.resultsGroupBox.Text = "Query results";
|
||||
//
|
||||
// resultsListBox
|
||||
//
|
||||
this.resultsListBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.resultsListBox.FormattingEnabled = true;
|
||||
this.resultsListBox.Location = new System.Drawing.Point(3, 16);
|
||||
this.resultsListBox.Name = "resultsListBox";
|
||||
this.resultsListBox.Size = new System.Drawing.Size(834, 409);
|
||||
this.resultsListBox.TabIndex = 0;
|
||||
//
|
||||
// statisticsBtn
|
||||
//
|
||||
this.statisticsBtn.Location = new System.Drawing.Point(8, 521);
|
||||
@@ -296,6 +287,16 @@
|
||||
this.checkBox1.UseVisualStyleBackColor = true;
|
||||
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
|
||||
//
|
||||
// resultsListView
|
||||
//
|
||||
this.resultsListView.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.resultsListView.Location = new System.Drawing.Point(3, 16);
|
||||
this.resultsListView.Name = "resultsListView";
|
||||
this.resultsListView.Size = new System.Drawing.Size(834, 409);
|
||||
this.resultsListView.TabIndex = 0;
|
||||
this.resultsListView.UseCompatibleStateImageBehavior = false;
|
||||
this.resultsListView.View = System.Windows.Forms.View.Details;
|
||||
//
|
||||
// ResultsBrowserWnd
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
@@ -326,7 +327,6 @@
|
||||
private System.Windows.Forms.SplitContainer vSplitContainer;
|
||||
private System.Windows.Forms.SplitContainer hSplitContainer;
|
||||
private System.Windows.Forms.FlowLayoutPanel filtersFlowLayoutPanel;
|
||||
private System.Windows.Forms.ListBox resultsListBox;
|
||||
private System.Windows.Forms.GroupBox testBenchesGroupBox;
|
||||
private System.Windows.Forms.Button saveFiltersBtn;
|
||||
private System.Windows.Forms.Button loadFiltersBtn;
|
||||
@@ -343,5 +343,6 @@
|
||||
private System.Windows.Forms.Button formatOfResultsBtn;
|
||||
private System.Windows.Forms.Button printQueryResultsBtn;
|
||||
private System.Windows.Forms.Button statisticsBtn;
|
||||
private System.Windows.Forms.ListView resultsListView;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,8 @@ namespace ResultsBrowser
|
||||
{
|
||||
public partial class ResultsBrowserWnd : Form
|
||||
{
|
||||
IList<Filters.IFilter> filters;
|
||||
IList<Filters.IFilter> filters; /// Filters and the UI of filters
|
||||
FiltersConfig filtersConfig; /// Serializable configuration of filters and displayed results
|
||||
|
||||
IList<WaterMeter> waterMeters;
|
||||
|
||||
@@ -23,6 +24,7 @@ namespace ResultsBrowser
|
||||
{
|
||||
InitializeComponent();
|
||||
filters = new List<Filters.IFilter>();
|
||||
filtersConfig = new FiltersConfig();
|
||||
}
|
||||
|
||||
private void ResultsBrowserWnd_Load(object sender, EventArgs e)
|
||||
@@ -104,9 +106,13 @@ namespace ResultsBrowser
|
||||
private void loadFiltersBtn_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)
|
||||
{
|
||||
FiltersConfig filtersConfig = FiltersConfig.Load(dlg.FileName);
|
||||
FiltersConfig localFiltersConfig = FiltersConfig.Load(dlg.FileName);
|
||||
if (localFiltersConfig != null)
|
||||
{
|
||||
filtersConfig = localFiltersConfig;
|
||||
|
||||
filters.Clear();
|
||||
filtersFlowLayoutPanel.Controls.Clear();
|
||||
@@ -119,36 +125,31 @@ namespace ResultsBrowser
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void saveFiltersBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
FiltersConfig filtersConfig = new FiltersConfig(filters.Count);
|
||||
|
||||
try
|
||||
if (filtersConfig.UpdateFromFilters(filters)) /// filtersConfig members related to filters
|
||||
{
|
||||
for (int i = 0; i < filters.Count; i++)
|
||||
/// Save column widths of the ListView into filtersConfig members
|
||||
if (resultsListView.Columns.Count > 0)
|
||||
{
|
||||
filtersConfig.FilterID[i] = filters[i].GetThisFilterID();
|
||||
sb.Clear();
|
||||
filters[i].UI2Data();
|
||||
filters[i].Save(sb);
|
||||
filtersConfig.FilterData[i] = sb.ToString();
|
||||
filtersConfig.ResultsClmnWidths = new int[resultsListView.Columns.Count];
|
||||
for (int i = 0; i < resultsListView.Columns.Count; i++)
|
||||
{
|
||||
filtersConfig.ResultsClmnWidths[i] = resultsListView.Columns[i].Width;
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
MessageBox.Show(exc.Message, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
return;
|
||||
}
|
||||
|
||||
/// Save the file
|
||||
SaveFileDialog dlg = new SaveFileDialog();
|
||||
dlg.Filter = string.Format("{0} (*.qry)|*.qry|{1} (*.*)|*.*", Strings.Query_files, Strings.All_files);
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
filtersConfig.Save(dlg.FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void executeQueryBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
@@ -171,21 +172,62 @@ namespace ResultsBrowser
|
||||
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, 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.Compound = false; /// config.Factory.ClassName.Contains("Compound");
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user