Column withs on the results screen can be saved and reused for all LIstView-s/watermeters

This commit is contained in:
Milan Hanajik 2015-01-16 03:06:50 +01:00
parent 2b6b569dee
commit ade156be5c
4 changed files with 93 additions and 11 deletions

View File

@ -1,5 +1,5 @@
- s/n sa nedostalo do vysledkov
- oprava process obrazovky
- dokoncenie process obrazovky
- brat desatinnu bodku aj ciarku
BUGS HI High importance

View File

@ -135,6 +135,17 @@ namespace TBF
public string[] RsltItems_Printer_SingleWM;
public string[] RsltItems_Printer_CombinedWM;
[XmlArrayAttribute("RsltsSingleClmnWdths")]
public int[] RsltsSingleClmnWdths;
[XmlIgnore]
public int RsltsSingleClmnCount { get { return (RsltsSingleClmnWdths != null) ? RsltsSingleClmnWdths.Length : 0; } }
[XmlArrayAttribute("RsltsCombinedClmnWdths")]
public int[] RsltsCombinedClmnWdths;
[XmlIgnore]
public int RsltsCombinedClmnCount { get { return (RsltsCombinedClmnWdths != null) ? RsltsCombinedClmnWdths.Length : 0; } }
/// <summary>
/// Copy public fields from a LocalSettings object to this object.
/// </summary>
@ -224,6 +235,13 @@ namespace TBF
count = (ls.RsltItems_Printer_CombinedWM != null) ? ls.RsltItems_Printer_CombinedWM.Length : 0;
RsltItems_Printer_CombinedWM = new string[count];
for (int i = 0; i < count; i++) RsltItems_Printer_CombinedWM[i] = ls.RsltItems_Printer_CombinedWM[i];
RsltsSingleClmnWdths = new int[ls.RsltsSingleClmnCount];
for (int i = 0; i < RsltsSingleClmnCount; i++)
RsltsSingleClmnWdths[i] = ls.RsltsSingleClmnWdths[i];
RsltsCombinedClmnWdths = new int[ls.RsltsCombinedClmnCount];
for (int i = 0; i < RsltsCombinedClmnCount; i++)
RsltsCombinedClmnWdths[i] = ls.RsltsCombinedClmnWdths[i];
}
}

View File

@ -32,6 +32,7 @@
this.clearResultsButton = new System.Windows.Forms.Button();
this.configureButton = new System.Windows.Forms.Button();
this.flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
this.columnWidthsButton = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
this.splitContainer.Panel1.SuspendLayout();
this.splitContainer.Panel2.SuspendLayout();
@ -50,6 +51,7 @@
// splitContainer.Panel1
//
this.splitContainer.Panel1.BackColor = System.Drawing.SystemColors.Control;
this.splitContainer.Panel1.Controls.Add(this.columnWidthsButton);
this.splitContainer.Panel1.Controls.Add(this.clearResultsButton);
this.splitContainer.Panel1.Controls.Add(this.configureButton);
//
@ -90,6 +92,16 @@
this.flowLayoutPanel.Size = new System.Drawing.Size(1057, 660);
this.flowLayoutPanel.TabIndex = 0;
//
// columnWidthsButton
//
this.columnWidthsButton.Location = new System.Drawing.Point(232, 10);
this.columnWidthsButton.Name = "columnWidthsButton";
this.columnWidthsButton.Size = new System.Drawing.Size(120, 30);
this.columnWidthsButton.TabIndex = 2;
this.columnWidthsButton.Text = "Save column widths";
this.columnWidthsButton.UseVisualStyleBackColor = true;
this.columnWidthsButton.Click += new System.EventHandler(this.columnWidthsButton_Click);
//
// ResultsTabPageCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -114,5 +126,6 @@
private System.Windows.Forms.Button clearResultsButton;
private System.Windows.Forms.Button configureButton;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel;
private System.Windows.Forms.Button columnWidthsButton;
}
}

View File

@ -24,6 +24,8 @@ namespace TBF.Screens
IList<Entities.Test> tests;
IList<Entities.TestResult> testResults;
bool combined;
ListView firstListView;
int lvWidth;
int lvHeight;
@ -136,20 +138,23 @@ namespace TBF.Screens
///
/// Determine whether combined meter results are displayed
///
bool combined = ((testResults != null) &&
(testResults.Count > 0) &&
(testResults[0].MetersKind == Entities.MetersKind.Combined));
combined = ((testResults != null) &&
(testResults.Count > 0) &&
(testResults[0].MetersKind == Entities.MetersKind.Combined));
bool first = true;
for (int mtr = 0; mtr < (combined ? Program.WMsCount / 2 : Program.WMsCount); mtr++)
{
if (TestsArrangement == Forms.ResultsConfig.TestsAre.Rows)
{
ListView lview = GetResultsTestsAreRows(mtr, combined);
ListView lview = GetResultsTestsAreRows(mtr);
if (first) { firstListView = lview; first = false; }
if (lview != null) flowLayoutPanel.Controls.Add(lview);
}
else
{
ListView lview = GetResultsTestsAreColumns(mtr, combined);
ListView lview = GetResultsTestsAreColumns(mtr);
if (first) { firstListView = lview; first = false; }
if (lview != null) flowLayoutPanel.Controls.Add(lview);
}
}
@ -229,7 +234,7 @@ namespace TBF.Screens
/// </summary>
/// <param name="mtr">Water meter number: 0..Program.WMsCount</param>
/// <returns>ListView object</returns>
ListView GetResultsTestsAreRows(int mtr, bool combined)
ListView GetResultsTestsAreRows(int mtr)
{
IList<Forms.ResultItemSpec> items = (combined ? RsltItems_Screen_CombinedWM : RsltItems_Screen_SingleWM);
if (tests == null || items == null) return null;
@ -237,8 +242,27 @@ namespace TBF.Screens
ListView lview = GetListView();
// Header
lview.Columns.Add((mtr + 1).ToString());
foreach (var item in items) lview.Columns.Add(item.ClmnHeaderText);
TBF.LocalSettings ls = Program.LocalSettings;
if (combined)
{
lview.Columns.Add((mtr + 1).ToString(), (ls.RsltsCombinedClmnCount > 0) ? ls.RsltsCombinedClmnWdths[0] : 50);
int i = 1;
foreach (var item in items)
{
lview.Columns.Add(item.ClmnHeaderText, (ls.RsltsCombinedClmnCount > i) ? ls.RsltsCombinedClmnWdths[i] : 70);
i++;
}
}
else
{
lview.Columns.Add((mtr + 1).ToString(), (ls.RsltsSingleClmnCount > 0) ? ls.RsltsSingleClmnWdths[0] : 50);
int i = 1;
foreach (var item in items)
{
lview.Columns.Add(item.ClmnHeaderText, (ls.RsltsSingleClmnCount > i) ? ls.RsltsSingleClmnWdths[i] : 70);
i++;
}
}
IList<string> testNames = GetAllDecoratedTestNames();
int ix = 0;
@ -290,7 +314,7 @@ namespace TBF.Screens
/// </summary>
/// <param name="mtr">Water meter number: 0..Program.WMsCount</param>
/// <returns>ListView object</returns>
ListView GetResultsTestsAreColumns(int mtr, bool combined)
ListView GetResultsTestsAreColumns(int mtr)
{
IList<Forms.ResultItemSpec> items = (combined ? RsltItems_Screen_CombinedWM : RsltItems_Screen_SingleWM);
if (tests == null || items == null) return null;
@ -389,5 +413,32 @@ namespace TBF.Screens
RedrawAll();
}
}
private void columnWidthsButton_Click(object sender, EventArgs e)
{
if (firstListView == null) return;
/// Update the column widths
if (combined)
{
Program.LocalSettings.RsltsCombinedClmnWdths = new int[firstListView.Columns.Count];
for (int i = 0; i < firstListView.Columns.Count; i++)
{
Program.LocalSettings.RsltsCombinedClmnWdths[i] = firstListView.Columns[i].Width;
}
Program.LocalSettings.Save();
}
else
{
Program.LocalSettings.RsltsSingleClmnWdths = new int[firstListView.Columns.Count];
for (int i = 0; i < firstListView.Columns.Count; i++)
{
Program.LocalSettings.RsltsSingleClmnWdths[i] = firstListView.Columns[i].Width;
}
Program.LocalSettings.Save();
}
RedrawAll();
}
}
}