FrmKeypadCountSet.cs
6 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
using GeneralLib;
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;
namespace SunVoteARSPPT
{
public partial class FrmKeypadCountSet : Form
{
public FrmKeypadCountSet()
{
InitializeComponent();
}
private void btnOK_Click(object sender, EventArgs e)
{
//参与者人数要小于可用键盘数
if (GlobalInfo.response.EnableList)
{
if (MessageBox.Show(GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "SaveKeypadCountSet", "当前已启用名单,该操作将禁用名单,是否继续?"), GlobalInfo.GetAppName(), MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.No)
return;
}
GlobalInfo.response.EnableList = false;
int personNum = Convert.ToInt32(nudMemberNumber.Value);
//int avilableNum=GetAvilableKeyNum(txtKeypadZone.Text);
if (txtKeypadZone.Text.Trim() != "")
{
int avilableNum = GlobalInfo.hardwareManage.GetKeyNum(txtKeypadZone.Text);
if (avilableNum == -1)
{
MessageBox.Show(GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "Message1", "输入的范围格式有误,请重新输入"), GlobalInfo.GetAppName());
return;
}
if (avilableNum == -2)
{
MessageBox.Show(GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "Message2", "输入的键盘范围超出键盘ID的范围"), GlobalInfo.GetAppName());
return;
}
if ((avilableNum < personNum) && (avilableNum != 0))
{
MessageBox.Show(GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "Message3", "您设置的键盘数小于参与人数,请重新设置"), GlobalInfo.GetAppName());
return;
}
}
GlobalInfo.hardwareManage.PersonNum = personNum;
GlobalInfo.hardwareManage.RangeOfKey = txtKeypadZone.Text;
//存到幻灯片Tag值中
TagSet presTagSet = new TagSet();
presTagSet.Tags = Globals.SunVoteARSAddIn.PPTEdit.PPT.ActivePresentation.Tags;
presTagSet.SetValue(TagKey.Response_PersonNum, personNum);
presTagSet.SetValue(TagKey.Response_KeyRange, txtKeypadZone.Text);
//写配置文件 杨斌 2015-09-18
GlobalInfo.sysConfig.WriteSysConfig("Device", "PersonNum", nudMemberNumber.Value);
GlobalInfo.sysConfig.WriteSysConfig("Device", "RangeOfKey", txtKeypadZone.Text);
this.Close();
}
/// <summary>
/// 键盘数量
/// 杨斌 2015-09-18
/// </summary>
public static int PersonNum
{
get
{
return INIControl.GetInstances(GlobalInfo.SYSTEM_CONFIG_PATH).ReadInt("Device", "PersonNum", 100);
}
}
/// <summary>
/// 键盘范围
/// 杨斌 2015-09-18
/// </summary>
public static string RangeOfKey
{
get
{
return GlobalInfo.hardwareManage.RangeOfKey = INIControl.GetInstances(GlobalInfo.SYSTEM_CONFIG_PATH).ReadString("Device", "RangeOfKey", "1-100");
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void nudMemberNumber_ValueChanged(object sender, EventArgs e)
{
}
private void FrmKeypadCountSet_Load(object sender, EventArgs e)
{
GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
nudMemberNumber.Value = GlobalInfo.hardwareManage.PersonNum;
txtKeypadZone.Text = GlobalInfo.hardwareManage.RangeOfKey;
}
/// <summary>
/// 获得可用键盘数量
/// </summary>
/// <returns></returns>
private int GetAvilableKeyNum(string rangeOfKey)
{
int sectionNum = 0;
//没有设置键盘有效范围
if (rangeOfKey == "") { return 0; }
string[] aryAvilableKey = null;
//检验格式是否正确
//if (!PublicFunction.IsMatchWith(rangeOfKey, @"^((\d)[,](\d))|((\d)[-](\d))"))
//{
// return -1;
//}
aryAvilableKey = rangeOfKey.Split(',');
for (int i = 0; i < aryAvilableKey.Length; i++)
{
if (aryAvilableKey[i].IndexOf('-') != -1)
{
int minKey = Convert.ToInt32(aryAvilableKey[i].Substring(0, 1));
int pos = aryAvilableKey[i].LastIndexOf('-') + 1;
int maxKey = Convert.ToInt32(aryAvilableKey[i].Substring(pos, aryAvilableKey[i].Length - pos));
if (minKey > maxKey)
{
sectionNum = -1;
break;
}
for (int j = minKey; j <= maxKey; j++)
{
sectionNum += 1;
}
}
else
{
sectionNum += 1;
}
}
return sectionNum;
}
private void txtKeypadZone_KeyPress(object sender, KeyPressEventArgs e)
{
//限制只能输入数字,,,-
//阻止从键盘输入键
e.Handled = true;
//当输入为0-9的数字、小数点、回车和退格键时不阻止
if (e.KeyChar >= '0' && e.KeyChar <= '9' || e.KeyChar == ',' || e.KeyChar == ',' || e.KeyChar == '-' || e.KeyChar == 13 || e.KeyChar == (char)8)
{
if (e.KeyChar == ',')
e.KeyChar = ',';
e.Handled = false;
}
}
}
}