2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
2017-03-19 09:37:06 +00:00
|
|
|
|
/// Copyright (c) 2013-2017 Sensus Metering Systems
|
2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using TBF.Resources;
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-12-21 07:06:42 +00:00
|
|
|
|
namespace TBF.Forms
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Provides login dialog that includes test bench selection.
|
|
|
|
|
|
/// It is used only once on program startup. Does not do authorisation
|
|
|
|
|
|
/// as User.users have not been loadded from the DB yet.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class LoginDlgWithBenchSelection : Form
|
|
|
|
|
|
{
|
2017-09-26 05:52:48 +00:00
|
|
|
|
/// Private fields
|
2016-12-21 08:22:30 +00:00
|
|
|
|
string alias;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
string password;
|
|
|
|
|
|
string benchName = null;
|
2017-09-26 05:52:48 +00:00
|
|
|
|
string legalizator;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-09-26 05:52:48 +00:00
|
|
|
|
/// Readonly public properties to do the authorization.
|
2016-12-21 08:22:30 +00:00
|
|
|
|
public string Alias { get { return alias; } }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
public string Password { get { return password; } }
|
|
|
|
|
|
public string BenchName { get { return benchName; } }
|
2017-03-16 20:53:12 +00:00
|
|
|
|
public Users.Entities.LoginMethod Method;
|
2017-09-26 05:52:48 +00:00
|
|
|
|
public string Legalizator { get { return legalizator; } }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Constructor.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public LoginDlgWithBenchSelection()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Constructor with a predefined bench.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public LoginDlgWithBenchSelection(string predefinedBench)
|
|
|
|
|
|
: this()
|
|
|
|
|
|
{
|
|
|
|
|
|
benchName = predefinedBench;
|
2017-09-26 05:52:48 +00:00
|
|
|
|
|
2017-12-06 06:58:57 +00:00
|
|
|
|
#if LANG_PL || BAHRAIN_50
|
2017-09-26 05:52:48 +00:00
|
|
|
|
Height = 156;
|
|
|
|
|
|
EnableAndPrepareLegalizatorCombo(legalizatorComboBox);
|
|
|
|
|
|
#else
|
|
|
|
|
|
legalizator = string.Empty;
|
|
|
|
|
|
#endif
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-26 05:52:48 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Load Legalizator order combo box items from the LocalSettings LastLegalizators array
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="orderComboBox">Legalizator ComboBox</param>
|
|
|
|
|
|
void EnableAndPrepareLegalizatorCombo(ComboBox comboBox)
|
|
|
|
|
|
{
|
|
|
|
|
|
legalizatorLabel.Visible = true;
|
|
|
|
|
|
legalizatorComboBox.Visible = true;
|
|
|
|
|
|
legalizatorComboBox.Enabled = true;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Program.LocalSettings.LastLegalizatorsCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
comboBox.Items.Add(Program.LocalSettings.LastLegalizators[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
legalizator = (comboBox.Items.Count > 0) ? Program.LocalSettings.LastLegalizators[0] : string.Empty;
|
|
|
|
|
|
comboBox.Text = legalizator;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void LoginDlgWithBenchSelection_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2015-10-07 19:33:37 +00:00
|
|
|
|
Localize();
|
2014-07-28 07:54:35 +00:00
|
|
|
|
#if DEBUG
|
2016-04-06 06:49:59 +00:00
|
|
|
|
userNameTextBox.Text = "milan";
|
2018-02-06 09:57:57 +00:00
|
|
|
|
passwordTextBox.Text = "kremik";
|
2014-07-28 07:54:35 +00:00
|
|
|
|
#endif
|
2015-02-28 20:36:33 +00:00
|
|
|
|
for (int i = 0; i < Program.LocalSettings.BenchesCount; i++)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2015-02-28 20:36:33 +00:00
|
|
|
|
testBenchComboBox.Items.Add(Program.LocalSettings.TestBenches[i].BenchName);
|
|
|
|
|
|
if (benchName != null && benchName == Program.LocalSettings.TestBenches[i].BenchName)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
testBenchComboBox.Text = benchName;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-10-07 19:33:37 +00:00
|
|
|
|
void Localize()
|
|
|
|
|
|
{
|
2015-12-20 12:26:33 +00:00
|
|
|
|
Text = Strings.User_Login + " TBF v." + Program.Version;
|
2016-12-21 08:22:30 +00:00
|
|
|
|
aliasLabel.Text = GetAliasLabel();
|
|
|
|
|
|
passwordLabel.Text = Strings.Password;
|
|
|
|
|
|
testBenchLabel.Text = Strings.Test_bench;
|
2015-10-07 19:33:37 +00:00
|
|
|
|
okButton.Text = Strings.OkBtnText;
|
|
|
|
|
|
cancelButton.Text = Strings.CancelBtnText;
|
2017-09-26 05:52:48 +00:00
|
|
|
|
legalizatorLabel.Text = Strings.Legalizator;
|
2015-10-07 19:33:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-21 08:22:30 +00:00
|
|
|
|
string GetAliasLabel()
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (Method)
|
|
|
|
|
|
{
|
|
|
|
|
|
default:
|
2017-03-16 20:53:12 +00:00
|
|
|
|
case Users.Entities.LoginMethod.UserName: return Strings.User_name;
|
|
|
|
|
|
case Users.Entities.LoginMethod.FullName: return Strings.Full_name;
|
|
|
|
|
|
case Users.Entities.LoginMethod.Number: return Strings.User_code;
|
2016-12-21 08:22:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// OK clicked (authorization is done outside this dialog).
|
|
|
|
|
|
/// </summary>
|
2017-09-26 05:52:48 +00:00
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (testBenchComboBox.SelectedItem != null)
|
|
|
|
|
|
{
|
2016-12-21 08:22:30 +00:00
|
|
|
|
alias = userNameTextBox.Text;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
password = passwordTextBox.Text;
|
|
|
|
|
|
benchName = testBenchComboBox.SelectedItem.ToString();
|
2017-09-26 05:52:48 +00:00
|
|
|
|
if (legalizatorComboBox.Enabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
legalizator = legalizatorComboBox.Text;
|
|
|
|
|
|
Program.LocalSettings.UpdateHistory(legalizator, ref Program.LocalSettings.LastLegalizators);
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
|
Close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show(Strings.PLs_select_testbench, Strings.Warning, MessageBoxButtons.OK);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Cancel clicked.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void cancelButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
|
Close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void passwordTextBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (passwordTextBox.Text != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
this.AcceptButton = okButton;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void userNameTextBox_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Convert.ToInt32(e.KeyChar) == 13)
|
|
|
|
|
|
{
|
|
|
|
|
|
passwordTextBox.Focus();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-12-21 08:22:30 +00:00
|
|
|
|
|
2018-03-15 03:50:52 +00:00
|
|
|
|
private void passwordTextBox_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Convert.ToInt32(e.KeyChar) == 13)
|
|
|
|
|
|
{
|
|
|
|
|
|
okButton_Click(sender, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-21 08:22:30 +00:00
|
|
|
|
private void aliasLabel_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Method++;
|
2017-03-16 20:53:12 +00:00
|
|
|
|
if (Method == Users.Entities.LoginMethod.Count)
|
2016-12-21 08:22:30 +00:00
|
|
|
|
Method = 0;
|
|
|
|
|
|
aliasLabel.Text = GetAliasLabel();
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|