private void button3_Click(object sender, EventArgs e) { try { if (_main.lsStatueServers == null) _main.lsStatueServers = new List<RemoteServers>(); if (txtUserID.Text.Trim() == String.Empty || txtServerIp.Text.Trim() == String.Empty || txtPort.Text.Trim() == String.Empty) { MessageBox.Show("Information deformity!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (!JudgeExistServerName(txtServerName.Text.Trim())) { remoteServer = new RemoteServers(); remoteServer.ServerName = txtServerName.Text.Trim(); remoteServer.ServerIP = txtServerIp.Text.Trim(); remoteServer.UserID = txtUserID.Text.Trim(); if (cbxRemberPwd.Checked) { remoteServer.UserPwd = txtUserPwd.Text.Trim(); } remoteServer.ServerPort = Convert.ToInt32(txtPort.Text.Trim()); remoteServer.LocalUrl = txtLocalUrl.Text.Trim(); remoteServer.ServerUrl = txtServerUrl.Text.Trim(); remoteServer.Trag = txtTrag.Text.Trim(); if (cbxAnonymous.Checked) { remoteServer.IsAnonymous = 1; } else { remoteServer.IsAnonymous = 0; } _main.lsStatueServers.Add(remoteServer); InitialTreeView(); _main.InitialMyServers(); ClearText(); MessageBox.Show("AddServer Sucessfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { remoteServer = GetServerByName(txtServerName.Text.Trim()); if (remoteServer != null) { remoteServer.ServerName = txtServerName.Text.Trim(); remoteServer.ServerIP = txtServerIp.Text.Trim(); remoteServer.UserID = txtUserID.Text.Trim(); if (cbxRemberPwd.Checked) { remoteServer.UserPwd = txtUserPwd.Text.Trim(); } remoteServer.ServerPort = Convert.ToInt32(txtPort.Text.Trim()); remoteServer.LocalUrl = txtLocalUrl.Text.Trim(); remoteServer.ServerUrl = txtServerUrl.Text.Trim(); remoteServer.Trag = txtTrag.Text.Trim(); if (cbxAnonymous.Checked) { remoteServer.IsAnonymous = 1; } else { remoteServer.IsAnonymous = 0; } UpdateServer(remoteServer); MessageBox.Show("Update Sucessfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } catch (FormatException) { MessageBox.Show("The IpAdress or the port is not the correct formate!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "UnkonwError", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void UpdateServer(RemoteServers server) { try { for (int i = 0; i < _main.lsStatueServers.Count; i++) { if (_main.lsStatueServers[i].ServerName == server.ServerName) { _main.lsStatueServers[i].ServerName = server.ServerName; _main.lsStatueServers[i].ServerIP = server.ServerIP; _main.lsStatueServers[i].UserID = server.UserID; _main.lsStatueServers[i].UserPwd =server.UserPwd; _main.lsStatueServers[i].ServerPort = Convert.ToInt32(server.ServerPort); _main.lsStatueServers[i].LocalUrl = server.LocalUrl; _main.lsStatueServers[i].ServerUrl = server.ServerUrl; _main.lsStatueServers[i].Trag = server.Trag; _main.lsStatueServers[i].IsAnonymous = server.IsAnonymous; } } } catch (FormatException) { MessageBox.Show("The IpAdress or the port is not the correct formate!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "UnkonwError", MessageBoxButtons.OK, MessageBoxIcon.Error); } }