-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnswerBoard.cs
167 lines (144 loc) · 6.59 KB
/
AnswerBoard.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CW
{
public partial class AnswerBoard : Form
{
string? answer = "";
DataGridView dgv = null;
public AnswerBoard(string answer, DataGridView dgv)
{
InitializeComponent();
this.answer = answer;
this.dgv = dgv;
}
private void AnswerBoard_Load(object sender, EventArgs e)
{
//对答案掐头去尾
answer = answer.Replace("=== ", "");
answer = answer.Replace(" iii ", "");
//分解答案
var answerList = answer.Split(' ').Select(p => p.Trim()).ToList();
int answerFlag = 0;
answerBox.Font = new Font("Segoe UI", 15, FontStyle.Bold);
//插入20个空行
for (int i = 0; i < 30; i++)
{
for (int j = 0; j < 49; j++)
{
answerBox.AppendText(" ");
}
answerBox.AppendText(Environment.NewLine);
}
//错误
int error = 0;
//漏掉
int miss = 0;
foreach (DataGridViewRow row in dgv.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.ReadOnly)
{
break;
}
var content =System.Convert.ToString(cell.Value) ;
//空的就直接算作错误
if (content == "" || content == null)
{
error += 4;
//插入正确答案
answerBox.SelectionStart = 3 * (answerFlag / 10) * 50 + (answerFlag % 10)*5 ;
answerBox.SelectionLength = 4;
answerBox.SelectedText = answerList[answerFlag];
//插入回答
answerBox.SelectionStart = (3 * (answerFlag / 10) + 1) * 50 + (answerFlag % 10) * 5;
answerBox.SelectionLength = 4;
answerBox.SelectedText = "____";
answerBox.SelectionStart = (3 * (answerFlag / 10) + 1) * 50 + (answerFlag % 10) * 5;
answerBox.SelectionLength = 4;
answerBox.SelectionColor = Color.Red;
answerFlag++;
continue;
}
//划线的就直接算作漏掉
if (content == "----" || content == "____")
{
miss += 4;
//插入正确答案
answerBox.SelectionStart = 3 * (answerFlag / 10) * 50 + (answerFlag % 10) * 5;
answerBox.SelectionLength = 4;
answerBox.SelectedText = answerList[answerFlag];
//插入回答
answerBox.SelectionStart = (3 * (answerFlag / 10) + 1) * 50 + (answerFlag % 10) * 5;
answerBox.SelectionLength = 4;
answerBox.SelectedText = "____";
answerBox.SelectionStart = (3 * (answerFlag / 10) + 1) * 50 + (answerFlag % 10) * 5;
answerBox.SelectionLength = 4;
answerBox.SelectionColor = Color.Red;
answerFlag++;
continue;
}
var key = answerList[answerFlag];
//插入正确答案
answerBox.SelectionStart = 3 * (answerFlag / 10) * 50 + (answerFlag % 10) * 5;
answerBox.SelectionLength = 4;
answerBox.SelectedText = answerList[answerFlag];
for (int i = 0; i < key.Length; i++)
{
//如果内容还没有答案长,后面的都是按照掉了的处理
if (content.Length - 1 < i)
{
miss += 1;
answerBox.SelectionStart = (3 * (answerFlag / 10) + 1) * 50 + (answerFlag % 10) * 5+i;
answerBox.SelectionLength = 1;
answerBox.SelectedText = "_";
answerBox.SelectionStart = (3 * (answerFlag / 10) + 1) * 50 + (answerFlag % 10) * 5+i;
answerBox.SelectionLength = 1;
answerBox.SelectionColor = Color.Red;
continue;
}
//统计漏掉的
if (content[i] == '-' || content[i] == '_')
{
answerBox.SelectionStart = (3 * (answerFlag / 10) + 1) * 50 + (answerFlag % 10) * 5 + i;
answerBox.SelectionLength = 1;
answerBox.SelectedText = "_";
answerBox.SelectionStart = (3 * (answerFlag / 10) + 1) * 50 + (answerFlag % 10) * 5 + i;
answerBox.SelectionLength = 1;
answerBox.SelectionColor = Color.Red;
miss += 1;
continue;
}
answerBox.SelectionStart = (3 * (answerFlag / 10) + 1) * 50 + (answerFlag % 10) * 5 + i;
answerBox.SelectionLength = 1;
answerBox.SelectedText = System.Convert.ToString(content[i]);
//统计错误的
if (content[i] != key[i])
{
answerBox.SelectionStart = (3 * (answerFlag / 10) + 1) * 50 + (answerFlag % 10) * 5 + i;
answerBox.SelectionLength = 1;
answerBox.SelectionColor = Color.Red;
error += 1;
continue;
}
}
//下一个答案
answerFlag++;
}
}
//展示漏掉的和错误的
answerBox.AppendText(Environment.NewLine+"错:" + error + " 漏:" + miss);
//answerBox.Select(0, 1);
//answerBox.SelectionColor = Color.Red;
}
}
}