/
ConnectionFrm.cs
97 lines (88 loc) · 3.21 KB
/
ConnectionFrm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BooBox;
namespace BooBoxClient {
public partial class ConnectionFrm : Form {
private String Mode;
private ConnectionInfo OrgConnInfo;
public ConnectionFrm() {
InitializeComponent();
}
private void NewConnectionFrm_Load(object sender, EventArgs e) {
}
/// <summary>
/// Sets the operating mode for the Connection Form.
/// </summary>
/// <param name="iMode">String containing the Operating Mode</param>
public void SetMode(String iMode) {
Mode = iMode;
if (iMode == "New") {
OKCmd.Text = "Add Connection";
} else {
OKCmd.Text = "Edit Connection";
}
}
/// <summary>
/// Sets the operating mode for the Connection Form. Edit mode.
/// </summary>
/// <param name="iMode">String containing the Operating Mode</param>
/// <param name="ConnectionInfo">ConnectionInfo object containing the ConnectionInfo to be populated.</param>
public void SetMode(String iMode, ConnectionInfo ConnectionInfo) {
SetMode(iMode);
OrgConnInfo = ConnectionInfo;
IPHostnameTxt.Text = ConnectionInfo.IPAddress;
PortTxt.Text = ConnectionInfo.InfoPort.ToString();
DescriptionTxt.Text = ConnectionInfo.Description;
PasswordTxt.Text = ConnectionInfo.Password;
ServerPasswordChk.Checked = ConnectionInfo.RequiresPassword;
}
private void ServerPasswordChk_CheckedChanged(object sender, EventArgs e) {
if (ServerPasswordChk.Checked == true) {
PasswordLbl.Enabled = true;
PasswordTxt.Enabled = true;
} else {
PasswordLbl.Enabled = false;
PasswordTxt.Enabled = false;
}
}
private void OKCmd_Click(object sender, EventArgs e) {
IPHostnameTxt.Text = IPHostnameTxt.Text.Trim();
PortTxt.Text = PortTxt.Text.Trim();
PasswordTxt.Text = PasswordTxt.Text.Trim();
DescriptionTxt.Text = DescriptionTxt.Text.Trim();
ConnectionInfo tempConnInfo = new ConnectionInfo();
if (Mode == "Edit") {
tempConnInfo = OrgConnInfo;
}
UriHostNameType hostnameType = Uri.CheckHostName(IPHostnameTxt.Text);
if (hostnameType == UriHostNameType.IPv4) {
tempConnInfo.IPAddress = IPHostnameTxt.Text; tempConnInfo.Hostname = "";
} else if (hostnameType == UriHostNameType.Dns) {
tempConnInfo.IPAddress = ""; tempConnInfo.Hostname = IPHostnameTxt.Text;
} else {
MessageBox.Show("IP Address or Hostname appears to be invalid. Please choose a valid hostname to continue."); return;
}
if (Mode == "Edit") {
Config.Instance.ConnectionInfoList.Remove(OrgConnInfo);
}
tempConnInfo.IPAddress = IPHostnameTxt.Text;
tempConnInfo.InfoPort = Convert.ToInt32(PortTxt.Text);
tempConnInfo.Description = DescriptionTxt.Text;
tempConnInfo.RequiresPassword = ServerPasswordChk.Checked;
tempConnInfo.Password = PasswordTxt.Text;
if (tempConnInfo.InternalGUID == null) {
tempConnInfo.InternalGUID = Guid.NewGuid().ToString();
}
Config.Instance.ConnectionInfoList.Add(tempConnInfo);
Config.Instance.Save();
Forms.MainFrm.PushSettingsToForm();
this.Close();
}
}
}