120 lines
3.8 KiB
C#
120 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using NetworkCommon.Network;
|
|
|
|
namespace NetworkCommon.View
|
|
{
|
|
public partial class ConnectionParameterForm : Form
|
|
{
|
|
public ConnectionParameterForm()
|
|
{
|
|
InitializeComponent();
|
|
int portEngineSettings = ConnectTools.Instance.EngineSettings.Port;
|
|
labelDefaultPort.Text = portEngineSettings.ToString();
|
|
|
|
string ip = ConnectTools.Instance.ConnectIP.Trim();
|
|
if (ip != ConnectTools.LOCALHOST)
|
|
{
|
|
comboBoxIP.Text = ip;
|
|
radioButtonCustomIP.Checked = true;
|
|
}
|
|
|
|
int port = ConnectTools.Instance.ConnectPort;
|
|
if (port != portEngineSettings)
|
|
{
|
|
comboBoxPort.Text = port.ToString();
|
|
radioButtonCustomPort.Checked = true;
|
|
}
|
|
}
|
|
|
|
public void RefreshSettings()
|
|
{
|
|
comboBoxIP.Items.Clear();
|
|
comboBoxIP.Text = "";
|
|
comboBoxIP.Items.AddRange(SettingsManager.Instance.GetIPs().ToArray());
|
|
if(comboBoxIP.Items.Count > 0)
|
|
{
|
|
comboBoxIP.Text = (string)comboBoxIP.Items[0];
|
|
}
|
|
|
|
comboBoxPort.Items.Clear();
|
|
comboBoxPort.Text = "";
|
|
comboBoxPort.Items.AddRange(SettingsManager.Instance.GetPorts().ToArray());
|
|
if (comboBoxPort.Items.Count > 0)
|
|
{
|
|
comboBoxPort.Text = (string)comboBoxPort.Items[0];
|
|
}
|
|
|
|
radioButtonCustomIP.Checked = SettingsManager.Instance.SelectedCustomIP;
|
|
radioButtonCustomPort.Checked = SettingsManager.Instance.SelectedCustomPort;
|
|
radioButtonLocalhost.Checked = !SettingsManager.Instance.SelectedCustomIP;
|
|
radioButtonDefaultPort.Checked = !SettingsManager.Instance.SelectedCustomPort;
|
|
}
|
|
|
|
private void buttonOK_Click(object sender, EventArgs e)
|
|
{
|
|
// IP
|
|
if (radioButtonCustomIP.Checked)
|
|
{
|
|
ConnectTools.Instance.ConnectIP = comboBoxIP.Text;
|
|
SettingsManager.Instance.AddIP(comboBoxIP.Text);
|
|
SettingsManager.Instance.SelectedCustomIP = true;
|
|
}
|
|
else
|
|
{
|
|
ConnectTools.Instance.ConnectIP = ConnectTools.LOCALHOST;
|
|
SettingsManager.Instance.SelectedCustomIP = false;
|
|
}
|
|
|
|
// Port
|
|
if (radioButtonCustomPort.Checked)
|
|
{
|
|
int result;
|
|
if (int.TryParse(comboBoxPort.Text, out result))
|
|
{
|
|
ConnectTools.Instance.ConnectPort = result;
|
|
SettingsManager.Instance.AddPort(result.ToString());
|
|
SettingsManager.Instance.SelectedCustomPort = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SettingsManager.Instance.SelectedCustomPort = false;
|
|
ConnectTools.Instance.ConnectPort = ConnectTools.Instance.EngineSettings.Port;
|
|
}
|
|
|
|
SettingsManager.Instance.Save();
|
|
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
Dispose();
|
|
}
|
|
|
|
private void buttonCancel_Click(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
Dispose();
|
|
}
|
|
|
|
private void textBoxIP_Click(object sender, EventArgs e)
|
|
{
|
|
radioButtonCustomIP.Checked = true;
|
|
}
|
|
|
|
private void textBoxPort_Click(object sender, EventArgs e)
|
|
{
|
|
radioButtonCustomPort.Checked = true;
|
|
}
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
SettingsManager.Instance.Clear();
|
|
RefreshSettings();
|
|
}
|
|
}
|
|
}
|