FrmServerSet.cs
5.48 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//using GeneralLib;
using NetLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SunVoteARSPPT
{
public partial class FrmServerSet : Form
{
public FrmServerSet()
{
InitializeComponent();
}
private void FrmServerSet_Load(object sender, EventArgs e)
{
//加载配置
//INIControl ini = INIControl.GetInstances(GlobalInfo.SYSTEM_CONFIG_PATH);
//ControlOper.TrySetNumericUpDownValue(numPort, ini.ReadInt("System", "ServerPort", 8866));
//txtPwd.Text = ini.ReadString("System", "ServerPwd", "");
ShowStartState(VoteServer.IsStart);
LoadSession();
}
private string StrOnLine = "Online";
private string StrClosed = "Closed";
public void LoadSession()
{
dgvClient.Rows.Clear();
foreach (var v in VoteServer.DicSessionName)
{
NetSession session = v.Value;
string name = v.Key;
int i = dgvClient.Rows.Add();
DataGridViewRow row = dgvClient.Rows[i];
row.Tag = session.ID;
row.Cells[colNo.Name].Value = VoteServer.GetMeetNo(name);
row.Cells[colName.Name].Value = name;
row.Cells[colIP.Name].Value = session.RemoteEndPoint.Address;
row.Cells[colPort.Name].Value = session.RemoteEndPoint.Port;
ShowRowMeetConnect(row, VoteServer.IsOnline(session));
ShowSessionRosterCount(name);
}
}
public void ShowSessionRosterCount(string name)
{
DataGridViewRow row = FindRowByName(name);
if (row == null)
return;
int count = 0;
if (VoteServer.DicRosterMeet.ContainsKey(name))
count = VoteServer.DicRosterMeet[name].Count - 2;
row.Cells[colRosterCount.Name].Value = count;
}
void ShowRowMeetConnect(DataGridViewRow row, bool isOnline)
{
row.Cells[colState.Name].Value = isOnline ? StrOnLine : StrClosed;
row.Cells[colState.Name].Style.ForeColor = isOnline ? Color.Blue : Color.Red;
row.Cells[colState.Name].Style.SelectionForeColor = row.Cells[colState.Name].Style.ForeColor;
}
public void SessionChange(NetSession session, bool isOnline)
{
string name = VoteServer.GetSessionPar(session, VoteServer.KeyName);
DataGridViewRow row = null;
if (name.Length > 0)
row = FindRowByName(name);
else
row = FindRowByID(session.ID);
if (row == null)
{
if (!isOnline)
return;
int i = dgvClient.Rows.Add();
row = dgvClient.Rows[i];
row.Tag = session.ID;
row.Cells[colNo.Name].Value = VoteServer.GetMeetNo(name);
row.Cells[colName.Name].Value = name;
}
if (isOnline)
{
row.Cells[colIP.Name].Value = session.RemoteEndPoint.Address;
row.Cells[colPort.Name].Value = session.RemoteEndPoint.Port;
}
ShowRowMeetConnect(row, isOnline);
}
DataGridViewRow FindRowByName(string name)
{
DataGridViewRow res = null;
foreach (DataGridViewRow v in dgvClient.Rows)
{
if ((v.Cells[colName.Name].Value + "") == name)
{
res = v;
break;
}
}
return res;
}
DataGridViewRow FindRowByID(string ID)
{
DataGridViewRow res = null;
foreach (DataGridViewRow v in dgvClient.Rows)
{
if ((v.Tag + "") == ID)
{
res = v;
break;
}
}
return res;
}
void ShowStartState(bool isStart)
{
btnStart.Enabled = !isStart;
btnStop.Enabled = isStart;
pnlSet.Enabled = !isStart;
}
private void btnStart_Click(object sender, EventArgs e)
{
//保存配置
//GlobalInfo.sysConfig.WriteSysConfig("System", "ServerPort", numPort.Value);
//GlobalInfo.sysConfig.WriteSysConfig("System", "ServerPwd", txtPwd.Text);
bool res = VoteServer.Start((int)numPort.Value, txtPwd.Text);
ShowStartState(res);
}
private void btnStop_Click(object sender, EventArgs e)
{
VoteServer.Stop();
ShowStartState(false);
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void chkShowPwd_CheckedChanged(object sender, EventArgs e)
{
txtPwd.PasswordChar = chkShowPwd.Checked ? '\0' : '*';
}
private void btnSaveRoster_Click(object sender, EventArgs e)
{
btnSaveRoster.Enabled = false;
this.Cursor = Cursors.WaitCursor;
RosterList.RosterLoad.SaveRosterMeet();
btnSaveRoster.Enabled = true;
this.Cursor = Cursors.Default;
}
}
}