using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;
namespace RDPManager
{
public partial class frmPassword : Form
{
private List<String> machineList = null;
private string selectedMachine = "";
private string userName = "";
private string password = "";
private string domain = "";
private bool passwordChanged = false;
#region properties
public string SelectedMachine
{
get { return selectedMachine; }
set { selectedMachine = value; }
}
public string UserName
{
get { return userName; }
set { userName = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public string Domain
{
get { return domain; }
set { domain = value; }
}
public bool PasswordChanged
{
get { return passwordChanged; }
set { passwordChanged = value; }
}
#endregion
public frmPassword()
{
InitializeComponent();
if (!RdpManager.ShowPasswords)
{
txtPass.UseSystemPasswordChar = true;
}
else
{
cbDisplayPassword.Checked = true;
}
#if DEBUG
this.Text = this.Text + " *";
#endif
}
public frmPassword(List<String> List)
{
InitializeComponent();
machineList = List;
if (!RdpManager.ShowPasswords)
{
txtPass.UseSystemPasswordChar = true;
}
else
{
cbDisplayPassword.Checked = true;
}
}
private void btnOK_Click(object sender, EventArgs e)
{
userName = txtUsername.Text;
password = txtPass.Text;
domain = txtDomain.Text;
selectedMachine = ddlMachines.SelectedItem.ToString();
if (userName == "")
{
MessageBox.Show("Username can not be empty", "Username Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
/*
if (password == "")
{
MessageBox.Show("Password can not be empty", "Password Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (password != "Default123") passwordChanged = true;
*/
DialogResult = DialogResult.OK;
Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
userName = "";
password = "";
domain = "";
DialogResult = DialogResult.Cancel;
Close();
}
private void PasswordForm_Load(object sender, EventArgs e)
{
txtUsername.Text = userName;
txtPass.Text = password;
txtDomain.Text = domain;
if (machineList == null) throw new ArgumentException("machineList is null");
foreach (string machName in machineList)
{
ddlMachines.Items.Add(machName);
ddlMachines.SelectedIndex = 0;
}
}
private void txtPass_MouseClick(object sender, MouseEventArgs e)
{
if (txtPass.Text.Length > 0)
{
txtPass.SelectAll();
}
}
private void txtPass_Enter(object sender, EventArgs e)
{
if (txtPass.Text.Length > 0)
{
txtPass.SelectAll();
}
}
private void txtUsername_MouseClick(object sender, MouseEventArgs e)
{
if (txtUsername.Text.Length > 0)
{
txtUsername.SelectAll();
}
}
private void txtUsername_Enter(object sender, EventArgs e)
{
if (txtUsername.Text.Length > 0)
{
txtUsername.SelectAll();
}
}
private void txtDomain_MouseClick(object sender, MouseEventArgs e)
{
if (txtDomain.Text.Length > 0)
{
txtDomain.SelectAll();
}
}
private void txtDomain_Enter(object sender, EventArgs e)
{
if (txtDomain.Text.Length > 0)
{
txtDomain.SelectAll();
}
}
private void txtPass_TextChanged(object sender, EventArgs e)
{
passwordChanged = true;
}
private void cbDisplayPassword_CheckedChanged(object sender, EventArgs e)
{
if (!cbDisplayPassword.Checked)
{
txtPass.UseSystemPasswordChar = true;
}
else
{
txtPass.UseSystemPasswordChar = false;
}
}
}
}