-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
259 lines (229 loc) · 9.91 KB
/
MainWindow.xaml.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ServerDTT_New_.SupportClass;
using ServerDTT_New_.ExtendedWindow;
using ServerDTT_New_.User_Control;
using ServerDTT_New_.DTO;
using ServerDTT_New_.DAO;
using System.Data;
namespace ServerDTT_New_
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public List<TextBox> txtBoxStudentNameList = new List<TextBox>();
public List<TextBox> txtBoxStudentPointList = new List<TextBox>();
List<Student> studentList = new List<Student>();
EWMainWindow eWMainWindow;
EWPointSummarized eWPointSummarized;
EWStart eWStart;
EWObstacles eWObstacles;
EWAccelerate eWAccelerate;
EWDecode eWDecode;
EWFinish eWFinish;
UCStart uCStart;
UCObstacles uCObstacles;
UCAccelerate uCAccelerate;
UCDecode uCDecode;
UCFinish uCFinish;
UCReadExcel uCReadExcel;
UCSubQuestions uCSubQuestions;
Server server;
string matchID = "";
Dictionary<string, string> matches;
const int numberOfStudent = 4;
public MainWindow()
{
InitializeComponent();
GetMatch();
server = new Server(this);
uCReadExcel = new UCReadExcel(this);
tabMain.Items.Add(new TabItem { Content = uCReadExcel, Header = "Read Excel", Width = 80, Height = 20, FontSize = 10 });
}
void InitMainWindow()
{
if (txtBoxStudentNameList.Count != 4)
{
for (int i = 0; i < numberOfStudent; i++)
{
Viewbox viewbox = new Viewbox();
TextBox txtBoxName = new TextBox { FontSize = 35, Background = Brushes.Transparent, Foreground = Brushes.Black, Text = studentList[i].Name, TextAlignment = TextAlignment.Center, Margin = new Thickness(0, 15, 0, 0) };
viewbox.Child = txtBoxName;
viewbox.SetValue(Grid.RowProperty, i + 1);
viewbox.SetValue(Grid.ColumnProperty, 0);
gridStudentInformation.Children.Add(viewbox);
txtBoxStudentNameList.Add(txtBoxName);
TextBox txtBoxPoint = new TextBox { FontSize = 35, Background = Brushes.Transparent, Foreground = Brushes.Black, Text = studentList[i].Point.ToString(), TextAlignment = TextAlignment.Center, Margin = new Thickness(0, 15, 0, 0) };
txtBoxPoint.SetValue(Grid.RowProperty, i + 1);
txtBoxPoint.SetValue(Grid.ColumnProperty, 1);
gridStudentInformation.Children.Add(txtBoxPoint);
txtBoxStudentPointList.Add(txtBoxPoint);
}
}
else
{
for (int i = 0; i < numberOfStudent; i++)
{
txtBoxStudentNameList[i].Text = studentList[i].Name;
txtBoxStudentPointList[i].Text = studentList[i].Point.ToString();
}
}
eWMainWindow = new EWMainWindow();
eWMainWindow.Show();
eWPointSummarized = new EWPointSummarized();
eWStart = new EWStart();
eWObstacles = new EWObstacles();
eWAccelerate = new EWAccelerate();
eWDecode = new EWDecode();
eWFinish = new EWFinish();
uCReadExcel = new UCReadExcel(this);
uCStart = new UCStart(this, eWMainWindow, eWStart, studentList, server, matchID);
uCObstacles = new UCObstacles(this, eWMainWindow, eWObstacles, studentList, server, matchID);
uCAccelerate = new UCAccelerate(this, eWMainWindow, eWAccelerate, studentList, server, matchID);
uCDecode = new UCDecode(this, eWMainWindow, eWDecode, studentList, server, matchID);
uCFinish = new UCFinish(this, eWMainWindow, eWFinish, studentList, server, matchID);
uCSubQuestions = new UCSubQuestions(this, eWMainWindow, studentList, server, matchID);
while(tabMain.Items.Count != 0)
{
tabMain.Items.RemoveAt(0);
}
tabMain.Items.Add(new TabItem { Content = uCStart, Header = "Khởi Động", Width = 80, Height = 20, FontSize = 10 });
tabMain.Items.Add(new TabItem { Content = uCObstacles, Header = "VCNV", Width = 80, Height = 20, FontSize = 10 });
tabMain.Items.Add(new TabItem { Content = uCAccelerate, Header = "Tăng Tốc", Width = 80, Height = 20, FontSize = 10 });
tabMain.Items.Add(new TabItem { Content = uCDecode, Header = "Giải Mã", Width = 80, Height = 20, FontSize = 10 });
tabMain.Items.Add(new TabItem { Content = uCFinish, Header = "Về Đích", Width = 80, Height = 20, FontSize = 10 });
tabMain.Items.Add(new TabItem { Content = uCSubQuestions, Header = "Câu hỏi phụ", Width = 80, Height = 20, FontSize = 10 });
tabMain.Items.Add(new TabItem { Content = uCReadExcel, Header = "Read Excel", Width = 80, Height = 20, FontSize = 10 });
//Cap nhap ID cua vong hien tai
System.IO.StreamWriter streamWriter = new System.IO.StreamWriter("Round.txt");
streamWriter.Flush();
streamWriter.Write("0");
streamWriter.Close();
}
public void GetMatch()
{
cbMatch.Items.Clear();
matches = new Dictionary<string, string>();
String command = "SELECT DISTINCT A.matchID, B.name FROM tblDetailMatch A, tblMatch B WHERE A.matchID = B.matchID";
DataTable data = DataProvider.Instance.ExecuteQuery(command);
foreach(DataRow row in data.Rows)
{
string id = row["matchID"].ToString();
string name = row["name"].ToString();
if (!matches.ContainsKey(id))
{
matches.Add(id, name);
cbMatch.Items.Add(name);
}
}
}
public void SolveMessage(string message)
{
switch (message[0])
{
case '1':
break;
case '2':
uCObstacles.SolveMessage(message.Substring(2));
break;
case '3':
uCAccelerate.SolveMessage(message.Substring(2));
break;
case '4':
uCFinish.SolveMessage(message.Substring(2));
break;
case '5':
uCDecode.SolveMessage(message.Substring(2));
break;
case '6':
uCSubQuestions.SolveMessage(message.Substring(2));
break;
}
}
public void BtnSave_Click(object sender, RoutedEventArgs e)
{
for (int i = 0; i < numberOfStudent; i++)
{
int point = int.Parse(txtBoxStudentPointList[i].Text);
studentList[i].Name = txtBoxStudentNameList[i].Text;
studentList[i].Point = int.Parse(txtBoxStudentPointList[i].Text);
DAO.StudentDAO.Instance.UpdatePoint(studentList[i].StudentID, point, studentList[i].MatchID.ToString());
DAO.StudentDAO.Instance.UpdateName(studentList[i].StudentID, studentList[i].Name);
}
uCStart.UpdateInfoOnScreen();
uCObstacles.UpdateInfoOnScreen();
uCAccelerate.UpdateInfoOnScreen();
uCDecode.UpdateInfoOnScreen();
uCFinish.UpdateInfoOnScreen();
System.IO.StreamReader stream = new System.IO.StreamReader("Round.txt");
int round = int.Parse(stream.ReadLine());
stream.Close();
server.SendTSInfo(round, studentList);
}
private void BtnSummarizedPoint_Click(object sender, RoutedEventArgs e)
{
eWMainWindow.Content = eWPointSummarized;
eWPointSummarized.PlayVideoSummarizedPoint(studentList);
}
private void BtnFinal_Click(object sender, RoutedEventArgs e)
{
eWMainWindow.Content = eWPointSummarized;
eWPointSummarized.soundFinishAll.Play();
}
//
private void cbMatch_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string s = cbMatch.SelectedItem.ToString();
studentList = StudentDAO.Instance.getStartStudent(s);// get student
foreach(string id in matches.Keys)
{
if(s == matches[id])
{
this.matchID = id;
}
}
InitMainWindow();
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
private void miniBtn_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void maxiBtn_Click(object sender, RoutedEventArgs e)
{
if(this.WindowState == WindowState.Maximized)
{
this.WindowState = WindowState.Normal;
}
else
{
this.WindowState = WindowState.Maximized;
}
}
private void closeBtn_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void ColorZone_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
}
}