PanelJudge.cs
13.4 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/*-------------------------------------------------------------------------------------------
* 判断反馈参数面板
* 修改:杨斌 2012-03-13
* ----------------------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.PowerPoint;
using GeneralLib;
namespace SunVoteARSPPT
{
public delegate void SetPanelChartEventHander(UserControl panelShow);
public partial class PanelJudge : UserControl, IPanel
{
public static event SetPanelChartEventHander SetPanelChartEvent;
TagSet mTagSet = null;
public TagSet TagSet
{
get { return mTagSet; }
set
{
mTagSet = value;
ucResponsePara.TagSet = value;
ucKeypadPara.TagSet = value;
}
}
public PanelJudge()
{
InitializeComponent();
FrmSystemSet.LanguageSetEvent += new FrmSystemSet.LanguageSetEventHander(FrmSystemSet_LanguageSetEvent);
FrmVoteBar.PanelEnabledEvent += new FrmVoteBar.PanelEnabledEventHander(FrmVoteBar_PanelEnabledEvent);
gbxScoreType.Resize += gbxScoreType_Resize;
pnlScoreAnswer.Resize += pnlScoreAnswer_Resize;
pnlScoreItem.Resize += pnlScoreItem_Resize;
//设置控件大小
//杨斌 2015-04-10
ucResponsePara.ShowSet(true, true);
ucKeypadPara.Top = ucResponsePara.Bottom + 6;
this.Height = ucKeypadPara.Bottom;
//GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
//杨斌 2012-06-11
switch (GlobalInfo.OEMLogo)
{
case OEMLogos.oem3eAnalyzer:
//ucKeypadPara.Visible = false;
//if (ucKeypadPara.cboSubmitMode.SelectedIndex != 0)
// ucKeypadPara.cboSubmitMode.SelectedIndex = 0;
//this.Height = ucResponsePara.Bottom;
break;
case OEMLogos.SunVote:
default:
break;
}
}
void gbxScoreType_Resize(object sender, EventArgs e)
{
int pos = gbxScoreType.ClientSize.Width / 2;
int w = pos - 3;
nudOptionCount.Left = pos;
nudOptionCount.Width = w;
}
void pnlScoreAnswer_Resize(object sender, EventArgs e)
{
int pos = pnlScoreAnswer.ClientSize.Width / 2;
int w = pos - 3;
lblScoreWrong.Left = pos;
lblScoreWrong.Width = w;
nudScoreWrong.Left = pos;
//nudScoreWrong.Width = w;
}
void pnlScoreItem_Resize(object sender, EventArgs e)
{
int pos = pnlScoreItem.ClientSize.Width / 2;
int w = pos - 3;
txtCorrectAnwser.Left = pos;
txtCorrectAnwser.Width = w;
}
void FrmVoteBar_PanelEnabledEvent(bool enabled)
{
this.Enabled = enabled;
}
void FrmSystemSet_LanguageSetEvent()
{
GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
}
private void PanelJudge_Load(object sender, EventArgs e)
{
GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
InitItemScore();
}
private void ScoreMode_CheckedChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Judge_ScoreMode, rbtScoreItem.Checked ? 1 : 0);
ShowScorePanel();
}
private void ShowScorePanel()
{
pnlScoreAnswer.Visible = rbtScoreAnswer.Checked;
pnlScoreItem.Visible = rbtScoreItem.Checked;
if (rbtScoreAnswer.Checked)
{
gbxScoreType.Height = pnlScoreAnswer.Bottom + 5;
}
if (rbtScoreItem.Checked)
{
gbxScoreType.Height = pnlScoreItem.Bottom + 5;
}
ucResponsePara.Top = gbxScoreType.Bottom + 5;
ucKeypadPara.Top = ucResponsePara.Bottom + 5;
this.Height = ucKeypadPara.Bottom;
if (SetPanelChartEvent != null)
SetPanelChartEvent(this);
}
private void InitItemScore()
{
int optionCount = 2;
clstAnswer.Items.Clear();
clstAnswer.MultiColumn = false;
clstAnswer.ColumnWidth = clstAnswer.Width - 2;
//clstAnswer.Items.Add(GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "clstAnswer_0", "1是"));
//clstAnswer.Items.Add(GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "clstAnswer_1", "2否"));
for (int i = 1; i <= optionCount; i++)//杨斌 2012-03-14
clstAnswer.Items.Add(PPTOper.FormatNumABC(i, true));
dgvScore.Columns[0].HeaderText = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "dgvScore_0", "选项");
dgvScore.Columns[1].HeaderText = GlobalInfo.SysLanguage.LPT.ReadString(this.Name, "dgvScore_1", "分数");
dgvScore.ColumnCount = 2;
dgvScore.RowCount = optionCount;
ControlOper.SetGridRowH(dgvScore);//杨斌 2016-03-04
for (int col = 0; col < dgvScore.Columns.Count; col++)
dgvScore.Columns[col].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
int num = 0;
for (int col = 0; col < dgvScore.Columns.Count; col += 2)
{
for (int row = 0; row < dgvScore.Rows.Count; row++)
{
num++;
dgvScore.Rows[row].Cells[0].Value = PPTOper.FormatNumABC(num, true);//数字/字母
//加载分数
dgvScore.Rows[row].Cells[1].Value = "0";
}
}
}
private void LoadOptionScore()
{
string optionScore = TagSet.LoadValue(TagKey.Judge_ScoreOption, "").Value;
int optionCount = (int)nudOptionCount.Value;
Dictionary<int, double> dicScore = PublicFunction.GetItemScore(optionScore);
int num = 0;
for (int col = 0; col < dgvScore.Columns.Count; col += 2)
{
for (int row = 0; row < dgvScore.Rows.Count; row++)
{
num++;
if (num <= optionCount)
{
//分数
if (dicScore.ContainsKey(num))
dgvScore.Rows[row].Cells[col + 1].Value = dicScore[num].ToString();
else
dgvScore.Rows[row].Cells[col + 1].Value = "0";
}
}
}
}
private void SaveOptionScore()
{
int optionCount = (int)nudOptionCount.Value;
string optionScore = "";
Dictionary<int, double> dicScore = new Dictionary<int, double>();
int num = 0;
for (int col = 0; col < dgvScore.Columns.Count; col += 2)
{
for (int row = 0; row < dgvScore.Rows.Count; row++)
{
num++;
if (num <= optionCount)
{
double score = 0;
try
{
score = new ConvertOper(dgvScore.Rows[row].Cells[col + 1].Value.ToString()).ToDouble;
}
catch { score = 0; }
dicScore.Add(num, score);
}
}
}
int[] aryNum = new int[dicScore.Count];
double[] aryScore = new double[dicScore.Count];
dicScore.Keys.CopyTo(aryNum, 0);
dicScore.Values.CopyTo(aryScore, 0);
for (int i = 0; i < dicScore.Count; i++)
{
if (aryScore[i] != 0)
{
if ((optionScore.Length > 0))
optionScore += PublicFunction.SplitItemScore;//杨斌 2019-07-19
optionScore += aryNum[i].ToString() + "=" + aryScore[i].ToString();
}
}
TagSet.SetValue(TagKey.Judge_ScoreOption, optionScore);
}
private void btnChartSet_Click(object sender, EventArgs e)
{
new FrmChartSet().ShowDialog();
}
private void btnOptionText_Click(object sender, EventArgs e)
{
new FrmOptionTextSelect().ShowDialog();//杨斌 2013-01-24
}
/// <summary>
/// 加载参数面板数据
/// </summary>
public void LoadData()
{
try
{
//GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
ucResponsePara.LoadData();
ucKeypadPara.LoadData();
if (TagSet.LoadValue(TagKey.Judge_ScoreMode, rbtScoreItem.Checked ? 1 : 0).ToInt == 1)
rbtScoreItem.Checked = true;
else
rbtScoreAnswer.Checked = true;
ControlOper.TrySetNumericUpDownValue(nudScoreRight, TagSet.LoadValue(TagKey.Judge_ScoreRight, nudScoreRight.Value).ToInt);
ControlOper.TrySetNumericUpDownValue(nudScoreWrong, TagSet.LoadValue(TagKey.Judge_ScoreWrong, nudScoreWrong.Value).ToInt);
chkZeroScore.Checked = TagSet.LoadValue(TagKey.Judge_ScoreOptionZero, chkZeroScore.Checked ? 1 : 0).ToBoolean;
txtCorrectAnwser.Text = TagSet.LoadValue(TagKey.Judge_CorrectAnswer2, "").Value;
LoadCorrectAnswer();//加载正确答案
LoadOptionScore();//加载选项分数
ShowScorePanel();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
/// <summary>
/// 加载正确答案
/// </summary>
private void LoadCorrectAnswer()
{
try
{
string correctAnswer = TagSet.LoadValue(TagKey.Judge_CorrectAnswer, "").Value;
string[] split = { "," };
string[] correctItem = correctAnswer.Split(split, 0);
int countCorrect = 0;
for (int i = 0; i < clstAnswer.Items.Count; i++)
{
bool bCorrect = correctItem.Contains<string>((i + 1).ToString());
bCorrect = bCorrect && (i < nudOptionCount.Value);
bCorrect = bCorrect && (countCorrect < 1);
clstAnswer.SetItemChecked(i, bCorrect);
if (bCorrect) countCorrect++;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void clstAnswer_ItemCheck(object sender, ItemCheckEventArgs e)
{
//if (e.NewValue == CheckState.Unchecked) return;
//正确答案限制可选个数
if (e.NewValue == CheckState.Checked)
{
foreach (int i in clstAnswer.CheckedIndices)
{
if ((i != e.Index) && (clstAnswer.GetItemCheckState(i) != CheckState.Unchecked))
clstAnswer.SetItemCheckState(i, CheckState.Unchecked);
}
}
//保存正确答案
string correctAnswer = "";
for (int i = 0; i < clstAnswer.Items.Count; i++)
{
bool isCheck = false;
if (i == e.Index)
isCheck = (CheckState.Checked == e.NewValue);
else
isCheck = (CheckState.Checked == clstAnswer.GetItemCheckState(i));
if (isCheck)
{
if (correctAnswer.Length > 0) correctAnswer += ",";
correctAnswer += (i + 1).ToString();
}
}
TagSet.SetValue(TagKey.Judge_CorrectAnswer, correctAnswer);
Globals.SunVoteARSAddIn.PPTEdit.RefreshLabelEdit(DataLabelType.ANSWER);//杨斌 2012-03-15
}
private void nudScoreRight_ValueChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Judge_ScoreRight, nudScoreRight.Value);
}
private void nudScoreWrong_ValueChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Judge_ScoreWrong, nudScoreWrong.Value);
}
private void chkZeroScore_CheckedChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Judge_ScoreOptionZero, chkZeroScore.Checked ? 1 : 0);
}
private void dgvScore_CellClick(object sender, DataGridViewCellEventArgs e)
{
if ((e.ColumnIndex % 2) == 0) return;
if ((e.RowIndex + 1 + (e.ColumnIndex - 1) / 2 * dgvScore.Rows.Count) > nudOptionCount.Value) return;
dgvScore.BeginEdit(true);
}
private void dgvScore_MouseLeave(object sender, EventArgs e)
{
dgvScore.EndEdit();
}
private void dgvScore_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
SaveOptionScore();
}
private void txtCorrectAnwser_TextChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Judge_CorrectAnswer2, txtCorrectAnwser.Text.Trim());
}
}
}