using System;
using System.ComponentModel;
using System.Drawing;
using System.Security.Principal;
using System.Windows.Forms;

namespace QC.QTMSecurity;

public class LoginScreen : Form
{
	private PictureBox pictureBox1;

	private Label lblUsername;

	private Label lblPassword;

	private Button btnOk;

	private Button btnCancel;

	private ErrorProvider errorProvider;

	private StatusBar statusBar;

	private TextBox txtUsername;

	private TextBox txtPassword;

	private HelpProvider helpProvider;

	private Label lblFailed;

	private Label lblDomain;

	private ComboBox cmbDomains;

	private IContainer components;

	public LoginScreen()
	{
		InitializeComponent();
		statusBar.Text = DateTime.Now.ToLongDateString() + "   (" + DateTime.Now.ToLongTimeString() + ")";
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.components = new System.ComponentModel.Container();
		System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(QC.QTMSecurity.LoginScreen));
		this.pictureBox1 = new System.Windows.Forms.PictureBox();
		this.txtUsername = new System.Windows.Forms.TextBox();
		this.txtPassword = new System.Windows.Forms.TextBox();
		this.lblUsername = new System.Windows.Forms.Label();
		this.lblPassword = new System.Windows.Forms.Label();
		this.btnOk = new System.Windows.Forms.Button();
		this.btnCancel = new System.Windows.Forms.Button();
		this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
		this.statusBar = new System.Windows.Forms.StatusBar();
		this.helpProvider = new System.Windows.Forms.HelpProvider();
		this.cmbDomains = new System.Windows.Forms.ComboBox();
		this.lblFailed = new System.Windows.Forms.Label();
		this.lblDomain = new System.Windows.Forms.Label();
		((System.ComponentModel.ISupportInitialize)this.pictureBox1).BeginInit();
		((System.ComponentModel.ISupportInitialize)this.errorProvider).BeginInit();
		base.SuspendLayout();
		this.pictureBox1.Image = (System.Drawing.Image)resources.GetObject("pictureBox1.Image");
		this.pictureBox1.Location = new System.Drawing.Point(0, 0);
		this.pictureBox1.Name = "pictureBox1";
		this.pictureBox1.Size = new System.Drawing.Size(320, 64);
		this.pictureBox1.TabIndex = 0;
		this.pictureBox1.TabStop = false;
		this.txtUsername.CausesValidation = false;
		this.helpProvider.SetHelpString(this.txtUsername, "Provides a space for you to type the user name required by the server.");
		this.txtUsername.Location = new System.Drawing.Point(96, 88);
		this.txtUsername.Name = "txtUsername";
		this.helpProvider.SetShowHelp(this.txtUsername, true);
		this.txtUsername.Size = new System.Drawing.Size(197, 20);
		this.txtUsername.TabIndex = 1;
		this.helpProvider.SetHelpString(this.txtPassword, "Provides a space for you to type the password for the selected user.");
		this.txtPassword.ImeMode = System.Windows.Forms.ImeMode.On;
		this.txtPassword.Location = new System.Drawing.Point(96, 121);
		this.txtPassword.Name = "txtPassword";
		this.txtPassword.PasswordChar = '*';
		this.helpProvider.SetShowHelp(this.txtPassword, true);
		this.txtPassword.Size = new System.Drawing.Size(197, 20);
		this.txtPassword.TabIndex = 3;
		this.lblUsername.AutoSize = true;
		this.lblUsername.Location = new System.Drawing.Point(24, 88);
		this.lblUsername.Name = "lblUsername";
		this.lblUsername.Size = new System.Drawing.Size(61, 13);
		this.lblUsername.TabIndex = 0;
		this.lblUsername.Text = "User name:";
		this.lblPassword.AutoSize = true;
		this.lblPassword.Location = new System.Drawing.Point(24, 121);
		this.lblPassword.Name = "lblPassword";
		this.lblPassword.Size = new System.Drawing.Size(56, 13);
		this.lblPassword.TabIndex = 2;
		this.lblPassword.Text = "Password:";
		this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
		this.btnOk.Location = new System.Drawing.Point(136, 217);
		this.btnOk.Name = "btnOk";
		this.btnOk.Size = new System.Drawing.Size(75, 23);
		this.btnOk.TabIndex = 6;
		this.btnOk.Text = "Ok";
		this.btnOk.Click += new System.EventHandler(btnOk_Click);
		this.btnCancel.CausesValidation = false;
		this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
		this.btnCancel.Location = new System.Drawing.Point(224, 217);
		this.btnCancel.Name = "btnCancel";
		this.btnCancel.Size = new System.Drawing.Size(75, 23);
		this.btnCancel.TabIndex = 7;
		this.btnCancel.Text = "Cancel";
		this.errorProvider.ContainerControl = this;
		this.statusBar.Location = new System.Drawing.Point(0, 246);
		this.statusBar.Name = "statusBar";
		this.statusBar.Size = new System.Drawing.Size(312, 22);
		this.statusBar.TabIndex = 9;
		this.cmbDomains.CausesValidation = false;
		this.cmbDomains.FormattingEnabled = true;
		this.helpProvider.SetHelpString(this.cmbDomains, "Provides a space for you to type the domain.");
		this.cmbDomains.Items.AddRange(new object[7] { "AP", "CORP", "EU", "MEA", "NA", "QCDFS", "SA" });
		this.cmbDomains.Location = new System.Drawing.Point(96, 154);
		this.cmbDomains.Name = "cmbDomains";
		this.helpProvider.SetShowHelp(this.cmbDomains, true);
		this.cmbDomains.Size = new System.Drawing.Size(197, 21);
		this.cmbDomains.TabIndex = 5;
		this.lblFailed.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75f, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0);
		this.lblFailed.ForeColor = System.Drawing.Color.FromArgb(192, 0, 0);
		this.lblFailed.Location = new System.Drawing.Point(100, 187);
		this.lblFailed.Name = "lblFailed";
		this.lblFailed.Size = new System.Drawing.Size(112, 23);
		this.lblFailed.TabIndex = 8;
		this.lblFailed.Text = "LOGIN FAILED!";
		this.lblFailed.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
		this.lblFailed.Visible = false;
		this.lblDomain.AutoSize = true;
		this.lblDomain.Location = new System.Drawing.Point(24, 154);
		this.lblDomain.Name = "lblDomain";
		this.lblDomain.Size = new System.Drawing.Size(46, 13);
		this.lblDomain.TabIndex = 4;
		this.lblDomain.Text = "Domain:";
		base.AcceptButton = this.btnOk;
		this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
		base.CancelButton = this.btnCancel;
		base.CausesValidation = false;
		base.ClientSize = new System.Drawing.Size(312, 268);
		base.Controls.Add(this.cmbDomains);
		base.Controls.Add(this.lblDomain);
		base.Controls.Add(this.lblFailed);
		base.Controls.Add(this.statusBar);
		base.Controls.Add(this.btnCancel);
		base.Controls.Add(this.btnOk);
		base.Controls.Add(this.lblPassword);
		base.Controls.Add(this.lblUsername);
		base.Controls.Add(this.txtPassword);
		base.Controls.Add(this.txtUsername);
		base.Controls.Add(this.pictureBox1);
		base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
		base.HelpButton = true;
		base.Icon = (System.Drawing.Icon)resources.GetObject("$this.Icon");
		base.MaximizeBox = false;
		base.MinimizeBox = false;
		base.Name = "LoginScreen";
		base.ShowInTaskbar = false;
		base.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
		this.Text = "Login ";
		base.Load += new System.EventHandler(LoginScreen_Load);
		((System.ComponentModel.ISupportInitialize)this.pictureBox1).EndInit();
		((System.ComponentModel.ISupportInitialize)this.errorProvider).EndInit();
		base.ResumeLayout(false);
		base.PerformLayout();
	}

	private void btnOk_Click(object sender, EventArgs e)
	{
		if (txtUsername.Text.Trim().Length == 0)
		{
			errorProvider.SetError(txtUsername, "User name cannot be empty.");
			txtUsername.Focus();
			base.DialogResult = DialogResult.None;
			return;
		}
		errorProvider.SetError(txtUsername, "");
		if (txtPassword.Text.Trim().Length == 0)
		{
			errorProvider.SetError(txtPassword, "Password cannot be empty.");
			txtPassword.Focus();
			base.DialogResult = DialogResult.None;
			return;
		}
		errorProvider.SetError(txtPassword, "");
		if (cmbDomains.Text.Trim().Length == 0)
		{
			errorProvider.SetError(cmbDomains, "Domain cannot be empty.");
			cmbDomains.Focus();
			base.DialogResult = DialogResult.None;
			return;
		}
		errorProvider.SetError(cmbDomains, "");
		if (!QSecurity.Login(txtUsername.Text.Trim(), txtPassword.Text.Trim(), cmbDomains.Text.Trim()))
		{
			lblFailed.Visible = true;
			base.DialogResult = DialogResult.None;
		}
	}

	private void LoginScreen_Load(object sender, EventArgs e)
	{
		try
		{
			cmbDomains.Items.Add(SystemInformation.ComputerName.ToUpper());
			string name = WindowsIdentity.GetCurrent().Name;
			string[] array = name.Split('\\');
			if (!cmbDomains.Items.Contains(array[0].ToUpper()))
			{
				cmbDomains.Items.Add(array[0].ToUpper());
			}
			cmbDomains.SelectedItem = array[0].ToUpper();
		}
		catch
		{
		}
	}
}
