125 lines
3.5 KiB
C#
125 lines
3.5 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using TBF.Resources;
|
|
|
|
|
|
namespace TBF
|
|
{
|
|
/// <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
|
|
{
|
|
// Private fields
|
|
string user;
|
|
string password;
|
|
string benchName = null;
|
|
|
|
// Readonly public properties to do the authorization.
|
|
public string User { get { return user; } }
|
|
public string Password { get { return password; } }
|
|
public string BenchName { get { return benchName; } }
|
|
|
|
/// <summary>
|
|
/// Constructor.
|
|
/// </summary>
|
|
public LoginDlgWithBenchSelection()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructor with a predefined bench.
|
|
/// </summary>
|
|
public LoginDlgWithBenchSelection(string predefinedBench)
|
|
: this()
|
|
{
|
|
benchName = predefinedBench;
|
|
}
|
|
|
|
private void LoginDlgWithBenchSelection_Load(object sender, EventArgs e)
|
|
{
|
|
Localize();
|
|
#if DEBUG
|
|
userNameTextBox.Text = Config.Data.AdminUsername;
|
|
passwordTextBox.Text = Config.Data.AdminPassword;
|
|
#endif
|
|
for (int i = 0; i < Program.LocalSettings.BenchesCount; i++)
|
|
{
|
|
testBenchComboBox.Items.Add(Program.LocalSettings.TestBenches[i].BenchName);
|
|
if (benchName != null && benchName == Program.LocalSettings.TestBenches[i].BenchName)
|
|
{
|
|
testBenchComboBox.Text = benchName;
|
|
}
|
|
}
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
Text = Strings.User_Login;
|
|
label1.Text = Strings.Username;
|
|
label2.Text = Strings.Password;
|
|
label3.Text = Strings.Test_bench;
|
|
okButton.Text = Strings.OkBtnText;
|
|
cancelButton.Text = Strings.CancelBtnText;
|
|
}
|
|
|
|
/// <summary>
|
|
/// OK clicked (authorization is done outside this dialog).
|
|
/// </summary>
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (testBenchComboBox.SelectedItem != null)
|
|
{
|
|
user = userNameTextBox.Text;
|
|
password = passwordTextBox.Text;
|
|
benchName = testBenchComboBox.SelectedItem.ToString();
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|