void IPComboBox_SelectedIndexChanged(object sender, EventArgs e) { RemoteLoginInfo newLoginInfo = IPComboBox.SelectedItem as RemoteLoginInfo; //new thing if (newLoginInfo == null) { ClearFields(); currentLoginInfo = newLoginInfo; return; } updatingFields = true; currentLoginInfo = newLoginInfo; IPComboBox.Text = currentLoginInfo.IP; PortSelector.Value = currentLoginInfo.Port; UsernameTextBox.Text = currentLoginInfo.Username; SavePasswordCheckBox.Checked = currentLoginInfo.HasPassword; if (currentLoginInfo.HasPassword) { PasswordTextBox.Text = "************"; } else { PasswordTextBox.Text = ""; } updatingFields = false; }
void ClearFields(int start = 1) { if (updatingFields || currentLoginInfo == null) { return; } updatingFields = true; switch (start) { case 1: IPComboBox.Text = ""; goto case 2; //reason number #3 why you shouldn't use c# case 2: PortSelector.Value = 38607; goto case 3; case 3: UsernameTextBox.Text = ""; goto case 4; case 4: if (currentLoginInfo?.HasPassword ?? false) //reason number #749 why you shouldn't use c# { PasswordTextBox.Text = ""; } break; } currentLoginInfo = null; updatingFields = false; }
void SavePasswordCheckBox_CheckedChanged(object sender, EventArgs e) { if (!updatingFields && !SavePasswordCheckBox.Checked && currentLoginInfo != null) { currentLoginInfo = null; PasswordTextBox.Text = ""; } }
void ClearFields() { if (updatingFields || currentLoginInfo == null) { return; } updatingFields = true; currentLoginInfo = null; IPComboBox.Text = ""; PortSelector.Value = 38607; UsernameTextBox.Text = ""; PasswordTextBox.Text = ""; updatingFields = false; }
void RemoteLoginButton_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(PasswordTextBox.Text) || String.IsNullOrWhiteSpace(UsernameTextBox.Text) || String.IsNullOrWhiteSpace(IPComboBox.Text) || PortSelector.Value == 0) { return; } RemoteLoginInfo loginInfo; if (currentLoginInfo == null) { loginInfo = new RemoteLoginInfo(IPComboBox.Text, (ushort)PortSelector.Value, UsernameTextBox.Text.Trim(), PasswordTextBox.Text); } else { loginInfo = (RemoteLoginInfo)IPComboBox.SelectedItem; if (!loginInfo.HasPassword) { loginInfo.Password = PasswordTextBox.Text; } } var I = new Client(loginInfo); var Config = Properties.Settings.Default; //This needs to be read here because V&C Closing us will corrupt the data var savePassword = SavePasswordCheckBox.Checked; if (VerifyAndConnect(I)) { Config.RemoteDefault = true; if (!savePassword) { loginInfo.Password = null; } Config.RemoteLoginInfo = new StringCollection { loginInfo.ToJSON() }; foreach (RemoteLoginInfo info in IPComboBox.Items) { if (!info.Equals(loginInfo)) { Config.RemoteLoginInfo.Add(info.ToJSON()); } } } }