-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreBoard.xaml.cs
More file actions
177 lines (169 loc) · 9.11 KB
/
Copy pathScoreBoard.xaml.cs
File metadata and controls
177 lines (169 loc) · 9.11 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
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
namespace MyFriendChemistry
{
/// <summary>
/// ScoreBoard.xaml에 대한 상호 작용 논리
/// </summary>
public partial class ScoreBoard : Window
{
//필요한 배열 및 변수를 선언하는 부분. 많이 쓰이는 것만 담았다.
private string[] UserAnswer = null;
private Test.QMC[] QMC = null;
private Test.QSQ[] QSQ = null;
private int count;
public ScoreBoard(Test.QMC[] qmc, Test.QSQ[] qsq, string[] useranswer)
{
InitializeComponent();
UserAnswer = useranswer;//인수로 받아온 사용자의 답안 배열을 저장한다.
QMC = qmc;//인수로 받아온 객관식 배열을 저장한다
QSQ = qsq;//인수로 받아온 주관식 배열을 저장한다
MCscore();//객관식 채점
textBlock.Text = qsq[0].answer;
textBlock2.Text = UserAnswer[20];//서술형이 21번부터니까 21번째 답을 불러온다.
count = Convert.ToInt16(Readini("WrongQSQ", "Number"));//현재 오답목록에 몇개의 주관식 문제가 저장되어있는지 확인한다. 그 이유는 오답목록에 문제를 이어서 저장하기 위해서이다. (오답목록에 10개의 문제가 저장되어았었다고 치면 새로 저장하는 문제는 11번부터 저장된다)
}
string iniLocation = AppDomain.CurrentDomain.BaseDirectory + "TextFile.ini";
[DllImport("kernel32.dll")]
private static extern long WritePrivateProfileString(string section, string key, string value, string filepath);
[DllImport("kernel32.dll")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
private string Readini(string Section, string Key)//ini파일 읽는 함수
{
StringBuilder temp = new StringBuilder(32);
int i = GetPrivateProfileString(Section, Key, "", temp, 32, iniLocation);
return temp.ToString();
}
private void MCscore()//객관식 채점 함수
{
int score = 0;
int j = Convert.ToInt16(Readini("WrongQMC", "Number"));//현재 오답목록에 몇개의 객관식 문제가 저장되어있는지 확인한다. 그 이유는 오답목록에 문제를 이어서 저장하기 위해서이다. (오답목록에 10개의 문제가 저장되어았었다고 치면 새로 저장하는 문제는 11번부터 저장된다)
for (int i=0; i<20; i++)
{
if ((UserAnswer[i] != null) && (QMC[i].answer == UserAnswer[i])) score += 4; //문제를 맞혔을 때 점수를 준다.
else if ((UserAnswer[i] == null) || (QMC[i].answer != UserAnswer[i]))//문제를 틀렸을 때 오답목록에 문제를 저장한다.
{
j++;
WritePrivateProfileString("WrongQMC", "Q" + j.ToString(), QMC[i].question, iniLocation);
WritePrivateProfileString("WrongQMC", "A" + j.ToString() + "_1", QMC[i].a1, iniLocation);
WritePrivateProfileString("WrongQMC", "A" + j.ToString() + "_2", QMC[i].a2, iniLocation);
WritePrivateProfileString("WrongQMC", "A" + j.ToString() + "_3", QMC[i].a3, iniLocation);
WritePrivateProfileString("WrongQMC", "A" + j.ToString() + "_4", QMC[i].a4, iniLocation);
WritePrivateProfileString("WrongQMC", "A" + j.ToString() + "_5", QMC[i].a5, iniLocation);
WritePrivateProfileString("WrongQMC", "Answer" + j.ToString(), QMC[i].answer, iniLocation);
}
}
mcscore.Content = score.ToString();
if(j != 0) WritePrivateProfileString("WrongQMC", "Number", j.ToString(), iniLocation);
}
private void Close_Click(object sender, RoutedEventArgs e)//종료버튼를 눌렀을 때 호출되는 함수
{
this.Close();
}
private void button_Click(object sender, RoutedEventArgs e)//오답버튼 눌렀을 때
{
//다음 문제를 세팅하며 오답목록에 문제를 저장한다.
if(number.Text=="1/5")
{
textBlock.Text = QSQ[1].answer;
textBlock2.Text = UserAnswer[21];
number.Text = "2/5";
count++;
WritePrivateProfileString("WrongQSQ", "Q" + count.ToString(), QSQ[0].question, iniLocation);
WritePrivateProfileString("WrongQSQ", "Answer" + count.ToString(), QSQ[count - 1].question, iniLocation);
}
else if (number.Text == "2/5")
{
textBlock.Text = QSQ[2].answer;
textBlock2.Text = UserAnswer[22];
number.Text = "3/5";
count++;
WritePrivateProfileString("WrongQSQ", "Q" + count.ToString(), QSQ[1].question, iniLocation);
WritePrivateProfileString("WrongQSQ", "Answer" + count.ToString(), QSQ[count - 1].question, iniLocation);
}
else if (number.Text == "3/5")
{
textBlock.Text = QSQ[3].answer;
textBlock2.Text = UserAnswer[23];
number.Text = "4/5";
count++;
WritePrivateProfileString("WrongQSQ", "Q" + count.ToString(), QSQ[2].question, iniLocation);
WritePrivateProfileString("WrongQSQ", "Answer" + count.ToString(), QSQ[count - 1].question, iniLocation);
}
else if (number.Text == "4/5")
{
textBlock.Text = QSQ[4].answer;
textBlock2.Text = UserAnswer[24];
number.Text = "5/5";
count++;
WritePrivateProfileString("WrongQSQ", "Q" + count.ToString(), QSQ[3].question, iniLocation);
WritePrivateProfileString("WrongQSQ", "Answer" + count.ToString(), QSQ[count - 1].question, iniLocation);
}
else if (number.Text == "5/5")
{
count++;
WritePrivateProfileString("WrongQSQ", "Q" + count.ToString(), QSQ[4].question, iniLocation);
WritePrivateProfileString("WrongQSQ", "Answer" + count.ToString(), QSQ[4].answer, iniLocation);
int i, j;
i = Convert.ToInt32(mcscore.Content);
j = Convert.ToInt32(sqscore.Content);
string str = "최종점수 : " + (i + j).ToString();
textBlock.Text = str;
number.Text = "채점완료!";
if (i + j == 100) textBlock2.Text = "모두 정답을 맞히셨습니다! 축하합니다! 지금까지의 자세로 정진하세요!";
else if (i + j != 100) textBlock2.Text = "안타깝네요. 다음번에는 꼭 만점을 받으시길 바랍니다. 더 노력하세요!";
}
WritePrivateProfileString("WrongQSQ", "Number", count.ToString(), iniLocation);
}
private void button2_Click(object sender, RoutedEventArgs e)//정답버튼 눌렀을 때
{
int i, j;
//다음 문제를 세팅하며 점수를 더한다.
if (number.Text == "1/5")
{
textBlock.Text = QSQ[1].answer;
textBlock2.Text = UserAnswer[21];
i = Convert.ToInt32(sqscore.Content) + 4;
sqscore.Content = i.ToString();
number.Text = "2/5";
}
else if (number.Text == "2/5")
{
textBlock.Text = QSQ[2].answer;
textBlock2.Text = UserAnswer[22];
i = Convert.ToInt32(sqscore.Content) + 4;
sqscore.Content = i.ToString();
number.Text = "3/5";
}
else if (number.Text == "3/5")
{
textBlock.Text = QSQ[3].answer;
textBlock2.Text = UserAnswer[23];
i = Convert.ToInt32(sqscore.Content) + 4;
sqscore.Content = i.ToString();
number.Text = "4/5";
}
else if (number.Text == "4/5")
{
textBlock.Text = QSQ[4].answer;
textBlock2.Text = UserAnswer[24];
i = Convert.ToInt32(sqscore.Content) + 4;
sqscore.Content = i.ToString();
number.Text = "5/5";
}
else if (number.Text == "5/5")
{
i = Convert.ToInt32(sqscore.Content) + 4;
sqscore.Content = i.ToString();
j = Convert.ToInt32(mcscore.Content);
string str = "최종점수 : " + (i + j).ToString();
textBlock.Text = str;
number.Text = "채점완료!";
if (i + j == 100) textBlock2.Text = "모두 정답을 맞히셨습니다! 축하합니다! 지금까지의 자세로 정진하세요!";
else if (i + j != 100) textBlock2.Text = "안타깝네요. 다음번에는 꼭 만점을 받으시길 바랍니다. 더 노력하세요!";
}
}
}
}