PanelOrder.cs
22.3 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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
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 partial class PanelOrder : UserControl, IPanel, IPanelChange
{
TagSet mTagSet = null;
public TagSet TagSet
{
get { return mTagSet; }
set
{
mTagSet = value;
ucResponsePara.TagSet = value;
ucKeypadPara.TagSet = value;
}
}
public PanelOrder()
{
InitializeComponent();
FrmSystemSet.LanguageSetEvent += new FrmSystemSet.LanguageSetEventHander(FrmSystemSet_LanguageSetEvent);
FrmVoteBar.PanelEnabledEvent += new FrmVoteBar.PanelEnabledEventHander(FrmVoteBar_PanelEnabledEvent);
gbxChoise.Resize += gbxChoise_Resize;
pnlScoreAnswer.Resize += pnlScoreAnswer_Resize;
//设置控件大小
//杨斌 2015-04-10
//ucResponsePara.HideVoteRate();
ucResponsePara.ShowSet(true, false);
ucKeypadPara.Top = ucResponsePara.Bottom + 6;
this.Height = ucKeypadPara.Bottom;
////GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
UpdateLan();//杨斌 2016-06-01
//杨斌 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;
}
//杨斌 2012-06-25
ucKeypadPara.cboOptionMode.SelectedIndex = 0;
ucKeypadPara.cboOptionMode.Enabled = false;
}
void gbxChoise_Resize(object sender, EventArgs e)
{
int pos = gbxChoise.ClientSize.Width / 2;
int w = pos - 3;
nudOptionCount.Left = pos;
//nudOptionCount.Width = w;
nudOptionLimit.Left = pos;
//nudOptionLimit.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 FrmVoteBar_PanelEnabledEvent(bool enabled)
{
this.Enabled = enabled;
}
/// <summary>
/// 刷新语言。杨斌 2016-06-01
/// </summary>
private void UpdateLan()
{
GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
lblCorrectAnswerMatch.Text = lblCorrectAnswer.Text;
}
void FrmSystemSet_LanguageSetEvent()
{
UpdateLan();//杨斌 2016-06-01
////GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
}
private void PanelOrder_Load(object sender, EventArgs e)
{
InitItemScore();
////GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
UpdateLan();//杨斌 2016-06-01
//杨斌 2015-05-22
decimal max = nudOptionCount.Value;
//if (GlobalInfo.GetSdkType() == 1)
// if (max > 8)
// max = 8;
nudOptionLimit.Maximum = max;
}
private void btnChartSet_Click(object sender, EventArgs e)
{
new FrmChartSet().ShowDialog();
}
private void rbtScoreAnswer_CheckedChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Order_ScoreMode, rbtScoreItem.Checked ? 1 : 0);
ShowScorePanel();
LoadCorrectAnwser();//杨斌 2016-06-02
//杨斌 2014-04-22
Globals.SunVoteARSAddIn.PPTEdit.Panel.ucChartPara.Visible = rbtScoreItem.Checked;
if (rbtScoreItem.Checked)//杨斌 2016-01-21
Globals.SunVoteARSAddIn.PPTEdit.Panel.ucChartPara.InitPanelPar(true, true, true, true, true, true);
Globals.SunVoteARSAddIn.PPTEdit.InitChart(true, Globals.SunVoteARSAddIn.PPTEdit.SlideEdit);
}
private void rbtScoreItem_CheckedChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Order_ScoreMode, rbtScoreItem.Checked ? 1 : 0);
ShowScorePanel();
//杨斌 2014-04-22
Globals.SunVoteARSAddIn.PPTEdit.Panel.ucChartPara.Visible = rbtScoreItem.Checked;
Globals.SunVoteARSAddIn.PPTEdit.InitChart(true, Globals.SunVoteARSAddIn.PPTEdit.SlideEdit);
}
private void rbtScoreMatch_CheckedChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Order_ScoreMode, 2);//计分模式3,按配对匹配项计分
LoadCorrectAnwser();//杨斌 2016-06-02
ShowScorePanel();
}
private void ShowScorePanel()
{
pnlScoreAnswer.Visible = rbtScoreAnswer.Checked;
//杨斌 2016-06-01
dgvScore.Visible = rbtScoreItem.Checked || rbtScoreMatch.Checked;
lblCorrectAnswerMatch.Visible = txtCorrectAnswerMatch.Visible = rbtScoreMatch.Checked;
if (rbtScoreMatch.Checked)
{
chkAABB.Enabled = nudOptionLimit.Enabled = false;
chkIisN.Enabled = false;
nudOptionLimit.Value = nudOptionCount.Value;
chkIisN.Checked = true;
chkAABB.Checked = false;
TagSet.SetValue(TagKey.Order_IisN, chkIisN.Checked ? 1 : 0);
TagSet.SetValue(TagKey.Order_AABB, chkAABB.Checked ? 1 : 0);
}
else
{
chkAABB.Enabled = nudOptionLimit.Enabled = true;
chkIisN.Enabled = !chkAABB.Checked;
}
}
private void InitItemScore()
{
//dgvScore.RowCount = 5;
//for (int i = 0; i < dgvScore.Rows.Count; i++)
//{
// dgvScore.Rows[0].Cells[0].Value = "1/A";
// dgvScore.Rows[0].Cells[1].Value = "0";
// dgvScore.Rows[0].Cells[2].Value = "2/B";
// dgvScore.Rows[0].Cells[3].Value = "0";
//}
int optionCount = (int)nudOptionCount.Value;
bool colFirst = 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", "分数");
if (colFirst)//逐列,与正确答案的控件一致
{
if (optionCount <= 5)
{
dgvScore.ColumnCount = 2;
dgvScore.RowCount = optionCount;
}
else
{
dgvScore.ColumnCount = 4;
dgvScore.RowCount = 5;
dgvScore.Columns[2].HeaderText = dgvScore.Columns[0].HeaderText;
dgvScore.Columns[3].HeaderText = dgvScore.Columns[1].HeaderText;
}
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++;
if (num <= optionCount)
{
dgvScore.Rows[row].Cells[col].Value = num;//PPTOper.FormatNumABC(num, true);//数字/字母
//加载分数
dgvScore.Rows[row].Cells[col + 1].Value = "0";
}
else
{
dgvScore.Rows[row].Cells[col].Value = "";
dgvScore.Rows[row].Cells[col + 1].Value = "";
}
}
}
}
else//逐行
{
if (optionCount <= 1)
{
dgvScore.ColumnCount = 2;
dgvScore.RowCount = 1;
}
else
{
dgvScore.ColumnCount = 4;
dgvScore.RowCount = optionCount / 2 + ((optionCount % 2) > 0 ? 1 : 0);
dgvScore.Columns[2].HeaderText = dgvScore.Columns[0].HeaderText;
dgvScore.Columns[3].HeaderText = dgvScore.Columns[1].HeaderText;
}
ControlOper.SetGridRowH(dgvScore);//杨斌 2016-03-04
int num = 0;
for (int row = 0; row < dgvScore.Rows.Count; row++)
{
for (int col = 0; col < dgvScore.Columns.Count; col++)
{
num++;
int m = col * 2;
if (num <= optionCount)
{
dgvScore.Rows[row].Cells[m].Value = PPTOper.FormatNumABC(num, true);//数字/字母
//加载分数
//double score = TagSet.LoadValue(TagSet.GetName(TagKey.Order_ScoreItem_) + num.ToString(), 0);
dgvScore.Rows[row].Cells[m + 1].Value = "0";
}
else
{
dgvScore.Rows[row].Cells[m].Value = "";
dgvScore.Rows[row].Cells[m + 1].Value = "";
}
}
}
}
}
private void nudChoiseLimit_ValueChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Order_OptionLimit, nudOptionLimit.Value);
txtCorrectAnswer.MaxLength = Convert.ToInt32(nudOptionLimit.Value);
try
{
string sAnswer = "";
for (int i = 0; i < Convert.ToInt32(nudOptionLimit.Value); i++)
{
if (i == 9)
sAnswer += "0";
else
sAnswer += (i + 1).ToString();
}
txtCorrectAnswer.Text = sAnswer;
txtCorrectAnswerMatch.Text = sAnswer;//杨斌 2016-06-02
SaveCorrectAnwser(txtCorrectAnswer);
}
catch { }
}
private void btnOptionText_Click(object sender, EventArgs e)
{
new FrmOptionTextSelect().ShowDialog();//杨斌 2013-01-24;
}
/// <summary>
/// 加载参数面板数据
/// </summary>
public void LoadData()
{
try
{
ucResponsePara.LoadData();
ucKeypadPara.LoadData();
ControlOper.TrySetNumericUpDownValue(nudOptionCount, TagSet.LoadValue(TagKey.Order_OptionCount, nudOptionCount.Value).ToInt);
ControlOper.TrySetNumericUpDownValue(nudOptionLimit, TagSet.LoadValue(TagKey.Order_OptionLimit, nudOptionLimit.Value).ToInt);
//if (chkAABB.Enabled)
chkAABB.Checked = TagSet.LoadValue(TagKey.Order_AABB, chkAABB.Checked ? 1 : 0).ToBoolean;
//if (chkIisN.Enabled)
chkIisN.Checked = TagSet.LoadValue(TagKey.Order_IisN, chkIisN.Checked ? true : false).ToBoolean;
chkCDBA.Checked = true;
//杨斌 2016-05-30
int scoreMode = TagSet.LoadValue(TagKey.Order_ScoreMode, 0).ToInt;
if (scoreMode == 1)
rbtScoreItem.Checked = true;
else if (scoreMode == 2)
rbtScoreMatch.Checked = true;
else
rbtScoreAnswer.Checked = true;
//if (TagSet.LoadValue(TagKey.Order_ScoreMode, rbtScoreItem.Checked ? 1 : 0).ToInt == 1)
// rbtScoreItem.Checked = true;
//else
// rbtScoreAnswer.Checked = true;
ControlOper.TrySetNumericUpDownValue(nudScoreRight, TagSet.LoadValue(TagKey.Order_ScoreRight, nudScoreRight.Value).ToInt);
ControlOper.TrySetNumericUpDownValue(nudScoreWrong, TagSet.LoadValue(TagKey.Order_ScoreWrong, nudScoreWrong.Value).ToInt);
LoadCorrectAnwser();
LoadOptionScore();//加载选项分数
ShowScorePanel();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
public void ChangeData(TagKey tagKey, object value)
{
if (tagKey == TagKey.Order_OptionCount)
ControlOper.TrySetNumericUpDownValue(nudOptionCount, TagSet.LoadValue(tagKey, nudOptionCount.Value).ToInt);
}
private void nudOptionCount_ValueChanged(object sender, EventArgs e)
{
//杨斌 2015-05-22
decimal max = nudOptionCount.Value;
//if (GlobalInfo.GetSdkType() == 1)
// if (max > 8)
// max = 8;
nudOptionLimit.Maximum = max;
TagSet.SetValue(TagKey.Order_OptionCount, nudOptionCount.Value);
//if (nudOptionLimit.Value = nudOptionCount.Value)
// nudOptionLimit.Value = nudOptionCount.Value;
InitItemScore();
LoadOptionScore();
SaveOptionScore();//保存选项分数
if (!Globals.SunVoteARSAddIn.PPTEdit.LockOptionTextChange)//判断是否选项文本在修改,杨斌 2012-03-05
{
Globals.SunVoteARSAddIn.PPTEdit.ModifyOptionText(Convert.ToInt32(nudOptionCount.Value));
}
Globals.SunVoteARSAddIn.PPTEdit.InitChart(true, Globals.SunVoteARSAddIn.PPTEdit.SlideEdit, autoFit: true);//杨斌 2014-04-22
}
private void chkAABB_CheckedChanged(object sender, EventArgs e)
{
if (!chkAABB.Enabled) return;
TagSet.SetValue(TagKey.Order_AABB, chkAABB.Checked ? 1 : 0);
if (chkAABB.Checked)
{
chkIisN.Enabled = false;
chkIisN.Checked = false;
TagSet.SetValue(TagKey.Order_IisN, 0);
}
else
{
chkIisN.Enabled = true;
}
}
private void chkIisN_CheckedChanged(object sender, EventArgs e)
{
if (!chkIisN.Enabled) return;
TagSet.SetValue(TagKey.Order_IisN, chkIisN.Checked ? 1 : 0);
}
private void nudScoreRight_ValueChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Order_ScoreRight, nudScoreRight.Value);
}
private void nudScoreWrong_ValueChanged(object sender, EventArgs e)
{
TagSet.SetValue(TagKey.Order_ScoreWrong, nudScoreWrong.Value);
}
/// <summary>
/// 获得排序的正确答案字符串,用于保存到Tag。如120->1,2,10
/// 杨斌 2014-02-18
/// </summary>
/// <param name="numList"></param>
/// <returns></returns>
public static string GetOrderCorrectAnswer(string numList)
{
string Answer = "";
for (int i = 0; i < numList.Length; i++)
{
if (i > 0)
Answer += ",";
if (numList.Substring(i, 1) == "0")
Answer += "10";
else
Answer += numList.Substring(i, 1);
}
return Answer;
}
private void SaveCorrectAnwser(TextBox txtAnswer)
{
string Anwser = "";
for (int i = 0; i < txtAnswer.Text.Length; i++)
{
if (i > 0)
Anwser += ",";
if (txtAnswer.Text.Substring(i, 1) == "0")
Anwser += "10";
else
Anwser += txtAnswer.Text.Substring(i, 1);
}
TagSet.SetValue(TagKey.Order_CorrectAnswer, Anwser);
}
private void LoadCorrectAnwser()
{
string Anwser = TagSet.LoadValue(TagKey.Order_CorrectAnswer, "").Value;
string[] ary;
ary = Anwser.Split(',');
Anwser = "";
for (int i = 0; i < ary.Length; i++)
{
if (ary[i] != "")
{
if (ary[i] == "10")
ary[i] = "0";
Anwser += ary[i];
}
}
txtCorrectAnswer.Text = Anwser;
txtCorrectAnswerMatch.Text = Anwser;//杨斌 2016-06-02
}
private void txtCorrectAnswer_TextChanged(object sender, EventArgs e)
{
SaveCorrectAnwser(txtCorrectAnswer);
Globals.SunVoteARSAddIn.PPTEdit.RefreshLabelEdit(DataLabelType.ANSWER);//杨斌 2012-03-15
}
//杨斌 2016-06-02
private void txtCorrectAnswerMatch_TextChanged(object sender, EventArgs e)
{
SaveCorrectAnwser(txtCorrectAnswerMatch);
}
private void txtCorrectAnswer_KeyPress(object sender, KeyPressEventArgs e)
{
//阻止从键盘输入键
e.Handled = true;
//当输入为0-9的数字、小数点、回车和退格键时不阻止
//允许最小分数和最大分数只能是整数
if (e.KeyChar >= '0' && e.KeyChar <= '9' || e.KeyChar == 13 || e.KeyChar == (char)8)
{
e.Handled = false;
}
//2013-2-19 赵丽 不允许输入重复字符
//for (int i = 0; i < txtCorrectAnswer.Text.Length; i++)
//{
// string sVal=txtCorrectAnswer.Text
// if()
// {
// e.Handled =false ;
// break;
// }
//}
}
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 LoadOptionScore()
{
string optionScore = TagSet.LoadValue(TagKey.Order_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;
//限制分数。杨斌 2012-11-07
double scoreMin = -100;
double scoreMax = 100;
switch (GlobalInfo.OEMLogo)
{
case OEMLogos.oem3eAnalyzer:
if (score < scoreMin)
{
score = scoreMin;
dgvScore.Rows[row].Cells[col + 1].Value = score.ToString();
}
if (score > scoreMax)
{
score = scoreMax;
dgvScore.Rows[row].Cells[col + 1].Value = score.ToString();
}
break;
default:
break;
}
}
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.Order_ScoreOption, optionScore);
}
}
}