private void btn_Ok_Click(object sender, EventArgs e) { // 保存 if (config == null) { config = new SessionConfig(); config.Index = AppConfig.Instance.SessionConfigDict.Count + 1; config.SessionId = "S" + YSTools.YSDateTime.ConvertDateTimeToLong(); config.Name = string.IsNullOrWhiteSpace(tb_name.Text) ? "New Session" + config.Index : tb_name.Text; config.Host = tb_host.Text; config.Port = (int)nud_port.Value; config.Protocol = cb_protocol.SelectedItem.ToString(); config.Method = cb_method.SelectedItem.ToString(); config.RemenberPwd = cb_remenber_pwd.Checked; config.UserName = tb_userName.Text; config.Password = YSEncrypt.EncryptA(tb_password.Text, KeysUtil.PassKey); ColorTheme theme = new ColorTheme(); theme.ColorScheme = cb_scheme.SelectedItem.ToString(); theme.FontName = cb_fontName.SelectedItem.ToString(); theme.FontSize = Convert.ToInt32(cb_fontSize.SelectedItem.ToString()); config.Theme = theme; AppConfig.Instance.SessionConfigDict.Add(config.Index + config.Name, config); } else { config.Name = string.IsNullOrWhiteSpace(tb_name.Text) ? "New Session" + config.Index : tb_name.Text; config.Host = tb_host.Text; config.Port = (int)nud_port.Value; config.Protocol = cb_protocol.SelectedItem.ToString(); config.Method = cb_method.SelectedItem.ToString(); config.RemenberPwd = cb_remenber_pwd.Checked; config.UserName = tb_userName.Text; config.Password = YSEncrypt.EncryptA(tb_password.Text, KeysUtil.PassKey); config.Theme.ColorScheme = cb_scheme.SelectedItem.ToString(); config.Theme.FontName = cb_fontName.SelectedItem.ToString(); config.Theme.FontSize = Convert.ToInt32(cb_fontSize.SelectedItem.ToString()); if (AppConfig.Instance.SessionConfigDict.ContainsKey(config.SessionId)) { AppConfig.Instance.SessionConfigDict.Remove(config.SessionId); } AppConfig.Instance.SessionConfigDict.Add(config.SessionId, config); } // 保存 AppConfig.Instance.SaveConfig(); this.Close(); }
private void toolStripButton7_Click(object sender, EventArgs e) { string host = text_host.Text; string username = text_username.Text; string pass = text_pass.Text; string port = text_port.Text; IPAddress ip; if (IPAddress.TryParse(host, out ip)) { if (string.IsNullOrWhiteSpace(username)) { MessageBox.Show(this, "请输入用户名"); } else if (string.IsNullOrWhiteSpace(pass)) { MessageBox.Show(this, "请输入密码"); } else if (string.IsNullOrWhiteSpace(port)) { MessageBox.Show(this, "请输入端口号"); } else { user.Host = host; user.UserName = username; user.Password = YSEncrypt.EncryptA(pass, KeysUtil.PassKey); user.Port = Convert.ToInt32(port); LoadRightForm(user); } } else { MessageBox.Show(this, "Host地址不正确"); } }