Working on configuration of results form/printout, locking OK, ResultsItemSpec class added

This commit is contained in:
Milan Hanajik
2015-01-12 04:16:48 +01:00
parent 747eb87de9
commit 222887f97d
4 changed files with 119 additions and 26 deletions
@@ -0,0 +1,30 @@
using System;
using System.Text;
namespace TBF.Forms
{
public class ResultItemSpec
{
static int idCounter; /// Values of this static counter are assigned to ID-s in instance constructor
static ResultItemSpec() { idCounter = 0; } /// Static constructor
/// Public fields
public readonly int ID;
public readonly string Name;
public readonly string ClmnHeaderText;
public readonly string Format;
public delegate float PickDlgt(Entities.MeterTestResult meterTestResult);
public readonly PickDlgt Pick;
/// Public constructor which assignes unique ID-s
public ResultItemSpec(string name, string clmnHeaderText, string format, PickDlgt pick)
{
ID = idCounter++;
Name = name;
ClmnHeaderText = clmnHeaderText;
Format = format;
Pick = pick;
}
}
}
+26 -3
View File
@@ -43,6 +43,7 @@
this.removeAllButton = new System.Windows.Forms.Button(); this.removeAllButton = new System.Windows.Forms.Button();
this.removeButton = new System.Windows.Forms.Button(); this.removeButton = new System.Windows.Forms.Button();
this.addButton = new System.Windows.Forms.Button(); this.addButton = new System.Windows.Forms.Button();
this.unlockButton = new System.Windows.Forms.Button();
this.testsArangementGroupBox.SuspendLayout(); this.testsArangementGroupBox.SuspendLayout();
this.metersArangementGroupBox.SuspendLayout(); this.metersArangementGroupBox.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@@ -50,6 +51,7 @@
// testsRowsRadioButton // testsRowsRadioButton
// //
this.testsRowsRadioButton.AutoSize = true; this.testsRowsRadioButton.AutoSize = true;
this.testsRowsRadioButton.Enabled = false;
this.testsRowsRadioButton.Location = new System.Drawing.Point(21, 24); this.testsRowsRadioButton.Location = new System.Drawing.Point(21, 24);
this.testsRowsRadioButton.Name = "testsRowsRadioButton"; this.testsRowsRadioButton.Name = "testsRowsRadioButton";
this.testsRowsRadioButton.Size = new System.Drawing.Size(120, 17); this.testsRowsRadioButton.Size = new System.Drawing.Size(120, 17);
@@ -61,6 +63,7 @@
// testsColumnsRadioButton // testsColumnsRadioButton
// //
this.testsColumnsRadioButton.AutoSize = true; this.testsColumnsRadioButton.AutoSize = true;
this.testsColumnsRadioButton.Enabled = false;
this.testsColumnsRadioButton.Location = new System.Drawing.Point(21, 46); this.testsColumnsRadioButton.Location = new System.Drawing.Point(21, 46);
this.testsColumnsRadioButton.Name = "testsColumnsRadioButton"; this.testsColumnsRadioButton.Name = "testsColumnsRadioButton";
this.testsColumnsRadioButton.Size = new System.Drawing.Size(137, 17); this.testsColumnsRadioButton.Size = new System.Drawing.Size(137, 17);
@@ -94,6 +97,7 @@
// verticallyRadioButton // verticallyRadioButton
// //
this.verticallyRadioButton.AutoSize = true; this.verticallyRadioButton.AutoSize = true;
this.verticallyRadioButton.Enabled = false;
this.verticallyRadioButton.Location = new System.Drawing.Point(21, 24); this.verticallyRadioButton.Location = new System.Drawing.Point(21, 24);
this.verticallyRadioButton.Name = "verticallyRadioButton"; this.verticallyRadioButton.Name = "verticallyRadioButton";
this.verticallyRadioButton.Size = new System.Drawing.Size(67, 17); this.verticallyRadioButton.Size = new System.Drawing.Size(67, 17);
@@ -105,6 +109,7 @@
// horizontallyRadioButton // horizontallyRadioButton
// //
this.horizontallyRadioButton.AutoSize = true; this.horizontallyRadioButton.AutoSize = true;
this.horizontallyRadioButton.Enabled = false;
this.horizontallyRadioButton.Location = new System.Drawing.Point(21, 46); this.horizontallyRadioButton.Location = new System.Drawing.Point(21, 46);
this.horizontallyRadioButton.Name = "horizontallyRadioButton"; this.horizontallyRadioButton.Name = "horizontallyRadioButton";
this.horizontallyRadioButton.Size = new System.Drawing.Size(79, 17); this.horizontallyRadioButton.Size = new System.Drawing.Size(79, 17);
@@ -115,26 +120,28 @@
// //
// okButton // okButton
// //
this.okButton.Location = new System.Drawing.Point(283, 18); this.okButton.Location = new System.Drawing.Point(283, 57);
this.okButton.Name = "okButton"; this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(104, 30); this.okButton.Size = new System.Drawing.Size(104, 30);
this.okButton.TabIndex = 4; this.okButton.TabIndex = 4;
this.okButton.Text = "OK"; this.okButton.Text = "Close";
this.okButton.UseVisualStyleBackColor = true; this.okButton.UseVisualStyleBackColor = true;
this.okButton.Click += new System.EventHandler(this.okButton_Click); this.okButton.Click += new System.EventHandler(this.okButton_Click);
// //
// cancelButton // cancelButton
// //
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(283, 55); this.cancelButton.Location = new System.Drawing.Point(283, 94);
this.cancelButton.Name = "cancelButton"; this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(104, 30); this.cancelButton.Size = new System.Drawing.Size(104, 30);
this.cancelButton.TabIndex = 5; this.cancelButton.TabIndex = 5;
this.cancelButton.Text = "Cancel"; this.cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true; this.cancelButton.UseVisualStyleBackColor = true;
this.cancelButton.Visible = false;
// //
// availableResultsListBox // availableResultsListBox
// //
this.availableResultsListBox.Enabled = false;
this.availableResultsListBox.FormattingEnabled = true; this.availableResultsListBox.FormattingEnabled = true;
this.availableResultsListBox.Location = new System.Drawing.Point(12, 205); this.availableResultsListBox.Location = new System.Drawing.Point(12, 205);
this.availableResultsListBox.Name = "availableResultsListBox"; this.availableResultsListBox.Name = "availableResultsListBox";
@@ -144,6 +151,7 @@
// //
// selectedResultsListBox // selectedResultsListBox
// //
this.selectedResultsListBox.Enabled = false;
this.selectedResultsListBox.FormattingEnabled = true; this.selectedResultsListBox.FormattingEnabled = true;
this.selectedResultsListBox.Location = new System.Drawing.Point(252, 205); this.selectedResultsListBox.Location = new System.Drawing.Point(252, 205);
this.selectedResultsListBox.Name = "selectedResultsListBox"; this.selectedResultsListBox.Name = "selectedResultsListBox";
@@ -172,6 +180,7 @@
// removeAllButton // removeAllButton
// //
this.removeAllButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.removeAllButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.removeAllButton.Enabled = false;
this.removeAllButton.Location = new System.Drawing.Point(153, 306); this.removeAllButton.Location = new System.Drawing.Point(153, 306);
this.removeAllButton.Name = "removeAllButton"; this.removeAllButton.Name = "removeAllButton";
this.removeAllButton.Size = new System.Drawing.Size(94, 30); this.removeAllButton.Size = new System.Drawing.Size(94, 30);
@@ -183,6 +192,7 @@
// removeButton // removeButton
// //
this.removeButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.removeButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.removeButton.Enabled = false;
this.removeButton.Location = new System.Drawing.Point(153, 271); this.removeButton.Location = new System.Drawing.Point(153, 271);
this.removeButton.Name = "removeButton"; this.removeButton.Name = "removeButton";
this.removeButton.Size = new System.Drawing.Size(93, 30); this.removeButton.Size = new System.Drawing.Size(93, 30);
@@ -194,6 +204,7 @@
// addButton // addButton
// //
this.addButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.addButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.addButton.Enabled = false;
this.addButton.Location = new System.Drawing.Point(153, 236); this.addButton.Location = new System.Drawing.Point(153, 236);
this.addButton.Name = "addButton"; this.addButton.Name = "addButton";
this.addButton.Size = new System.Drawing.Size(93, 30); this.addButton.Size = new System.Drawing.Size(93, 30);
@@ -202,6 +213,16 @@
this.addButton.UseVisualStyleBackColor = true; this.addButton.UseVisualStyleBackColor = true;
this.addButton.Click += new System.EventHandler(this.addButton_Click); this.addButton.Click += new System.EventHandler(this.addButton_Click);
// //
// unlockButton
//
this.unlockButton.Location = new System.Drawing.Point(283, 21);
this.unlockButton.Name = "unlockButton";
this.unlockButton.Size = new System.Drawing.Size(104, 30);
this.unlockButton.TabIndex = 47;
this.unlockButton.Text = "Unlock";
this.unlockButton.UseVisualStyleBackColor = true;
this.unlockButton.Click += new System.EventHandler(this.unlockButton_Click);
//
// ResultsConfig // ResultsConfig
// //
this.AcceptButton = this.okButton; this.AcceptButton = this.okButton;
@@ -209,6 +230,7 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelButton; this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(399, 379); this.ClientSize = new System.Drawing.Size(399, 379);
this.Controls.Add(this.unlockButton);
this.Controls.Add(this.removeAllButton); this.Controls.Add(this.removeAllButton);
this.Controls.Add(this.removeButton); this.Controls.Add(this.removeButton);
this.Controls.Add(this.addButton); this.Controls.Add(this.addButton);
@@ -250,5 +272,6 @@
private System.Windows.Forms.Button removeAllButton; private System.Windows.Forms.Button removeAllButton;
private System.Windows.Forms.Button removeButton; private System.Windows.Forms.Button removeButton;
private System.Windows.Forms.Button addButton; private System.Windows.Forms.Button addButton;
private System.Windows.Forms.Button unlockButton;
} }
} }
+62 -23
View File
@@ -12,6 +12,11 @@ namespace TBF.Forms
{ {
public partial class ResultsConfig : Form public partial class ResultsConfig : Form
{ {
/// <summary>
/// Required access rights to make changes with this form
/// </summary>
const Grp.GID RequiredGroupMembership = Grp.GID.Metrologists;
/// Arrangement of tests /// Arrangement of tests
public enum TestsAre public enum TestsAre
{ {
@@ -28,23 +33,21 @@ namespace TBF.Forms
} }
public Meters MetersArrangement; public Meters MetersArrangement;
/// Results items to be selected in the configuration public IList<ResultItemSpec> allAvailableItems;
public enum ResultsItem public IList<ResultItemSpec> AvailableItems;
{ public IList<ResultItemSpec> SelectedItems;
Abc,
Def,
Count
}
//
public IList<ResultsItem> AvailableItems;
public IList<ResultsItem> SelectedItems;
bool unlocked;
public ResultsConfig() public ResultsConfig()
{ {
InitializeComponent(); InitializeComponent();
SelectedItems = new List<ResultsItem>(); unlocked = false;
cancelButton.Visible = false;
SelectedItems = new List<ResultItemSpec>();
CreateListOfAvailableItems();
AvailableItems = GetListOfAvailableItems(); AvailableItems = GetListOfAvailableItems();
} }
@@ -62,7 +65,8 @@ namespace TBF.Forms
addButton.Text = Strings.Add; addButton.Text = Strings.Add;
removeButton.Text = Strings.Remove; removeButton.Text = Strings.Remove;
removeAllButton.Text = Strings.Remove_all; removeAllButton.Text = Strings.Remove_all;
okButton.Text = Strings.OkBtnText; unlockButton.Text = Strings.UnlockBtnText;
okButton.Text = Strings.CloseBtnText;
cancelButton.Text = Strings.CancelBtnText; cancelButton.Text = Strings.CancelBtnText;
} }
@@ -80,20 +84,22 @@ namespace TBF.Forms
RedrawSelected(); RedrawSelected();
} }
void CreateListOfAvailableItems()
{
allAvailableItems = new List<ResultItemSpec>();
allAvailableItems.Add(new ResultItemSpec("PulsesMeter", "PulsesMeter", "F0", x => (float)x.PulsesMeter));
allAvailableItems.Add(new ResultItemSpec("PulsesMaster", "PulsesMaster", "F0", x => (float)x.PulsesMaster));
}
/// <summary> /// <summary>
/// Create a list of available items from the complete list from 'auxBrdUpgInfo' /// Create a list of available items from the complete list from 'auxBrdUpgInfo'
/// and the list of selected items. In this way the order of items in the created list /// and the list of selected items. In this way the order of items in the created list
/// is always the same as in the original list in 'auxBrdUpgInfo'. /// is always the same as in the original list in 'auxBrdUpgInfo'.
/// </summary> /// </summary>
/// <returns>A list of available items which does not contain the selected items</returns> /// <returns>A list of available items which does not contain the selected items</returns>
IList<ResultsItem> GetListOfAvailableItems() IList<ResultItemSpec> GetListOfAvailableItems()
{ {
IList<ResultsItem> availableItems = new List<ResultsItem>(); return allAvailableItems;
for (ResultsItem item = 0; item < ResultsItem.Count; item++)
{
if (!SelectedItems.Contains(item)) availableItems.Add(item);
}
return availableItems;
} }
/// <summary> /// <summary>
@@ -102,7 +108,7 @@ namespace TBF.Forms
void RedrawAvailable() void RedrawAvailable()
{ {
availableResultsListBox.Items.Clear(); availableResultsListBox.Items.Clear();
foreach (var item in AvailableItems) availableResultsListBox.Items.Add(item.ToString()); foreach (var item in AvailableItems) availableResultsListBox.Items.Add(item.Name);
} }
/// <summary> /// <summary>
@@ -111,7 +117,40 @@ namespace TBF.Forms
void RedrawSelected() void RedrawSelected()
{ {
selectedResultsListBox.Items.Clear(); selectedResultsListBox.Items.Clear();
foreach (var item in SelectedItems) selectedResultsListBox.Items.Add(item.ToString()); foreach (var item in SelectedItems) selectedResultsListBox.Items.Add(item.Name);
}
private void unlockButton_Click(object sender, EventArgs e)
{
if (!unlocked)
{
if (!Entities.User.CurrentUser.IsMemberOf(RequiredGroupMembership))
{
if ((new LoginDlg(RequiredGroupMembership)).ShowDialog() != DialogResult.OK) return;
}
else if (Program.LocalSettings.AlwaysAskPasswdWhenUnlocking)
{
if ((new LoginDlg(Entities.User.CurrentUser.Name, RequiredGroupMembership)).ShowDialog() != DialogResult.OK) return;
}
unlocked = true;
///
/// Unlock user interface controls
///
unlockButton.Enabled = false;
okButton.Text = Strings.OkBtnText;
cancelButton.Visible = true;
testsRowsRadioButton.Enabled = true;
testsColumnsRadioButton.Enabled = true;
verticallyRadioButton.Enabled = true;
horizontallyRadioButton.Enabled = true;
availableResultsListBox.Enabled = true;
selectedResultsListBox.Enabled = true;
addButton.Enabled = true;
removeButton.Enabled = true;
removeAllButton.Enabled = true;
}
} }
void okButton_Click(object sender, EventArgs e) void okButton_Click(object sender, EventArgs e)
@@ -129,7 +168,7 @@ namespace TBF.Forms
private void availableResultsListBox_DoubleClick(object sender, EventArgs e) private void availableResultsListBox_DoubleClick(object sender, EventArgs e)
{ {
/// Double click works when just one item is selected /// Double click works when just one item is selected
IList<ResultsItem> itemsToRemove = new List<ResultsItem>(); IList<ResultItemSpec> itemsToRemove = new List<ResultItemSpec>();
if (availableResultsListBox.SelectedIndices.Count == 1) if (availableResultsListBox.SelectedIndices.Count == 1)
{ {
var item = AvailableItems[availableResultsListBox.SelectedIndices[0]]; var item = AvailableItems[availableResultsListBox.SelectedIndices[0]];
@@ -174,7 +213,7 @@ namespace TBF.Forms
for (int i = selectedResultsListBox.SelectedIndices.Count - 1; i >= 0; i--) for (int i = selectedResultsListBox.SelectedIndices.Count - 1; i >= 0; i--)
{ {
ResultsItem item = SelectedItems[selectedResultsListBox.SelectedIndices[i]]; ResultItemSpec item = SelectedItems[selectedResultsListBox.SelectedIndices[i]];
SelectedItems.Remove(item); SelectedItems.Remove(item);
} }
AvailableItems = GetListOfAvailableItems(); AvailableItems = GetListOfAvailableItems();
+1
View File
@@ -530,6 +530,7 @@
<Compile Include="Forms\EmergencyStopForm.designer.cs"> <Compile Include="Forms\EmergencyStopForm.designer.cs">
<DependentUpon>EmergencyStopForm.cs</DependentUpon> <DependentUpon>EmergencyStopForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Forms\ResultItemSpec.cs" />
<Compile Include="Forms\ResultsConfig.cs"> <Compile Include="Forms\ResultsConfig.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>