-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeacherGrade.xaml.cs
More file actions
221 lines (203 loc) · 8.53 KB
/
TeacherGrade.xaml.cs
File metadata and controls
221 lines (203 loc) · 8.53 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
using Microsoft.Data.Sqlite;
using SchoolManagement;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板
namespace StudentManagmentSystem
{
/// <summary>
/// 可用于自身或导航至 Frame 内部的空白页。
/// </summary>
public sealed partial class TeacherGrade : Page
{
string username = DatabaseHelper.userName;
public ObservableCollection<AddCourse> Course { get; set; }
public ObservableCollection<AddSC> SC { get; set; }
public TeacherGrade()
{
this.InitializeComponent();
Course = new ObservableCollection<AddCourse>();
CourseListView.ItemsSource = Course;
SC = new ObservableCollection<AddSC>();
SCListView.ItemsSource = SC;
LoadCourse();
}
private void LoadCourse()
{
Course.Clear();
string dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "SchoolManagement.db");
using (var db = new SqliteConnection($"Filename={dbPath}"))
{
db.Open();
var selectCommand = new SqliteCommand("SELECT CourseID,CourseName, TeacherName,Schedule,Classroom FROM Courses WHERE TeacherName=@teachername", db);
selectCommand.Parameters.AddWithValue("@teachername", username);
using (var reader = selectCommand.ExecuteReader())
{
while (reader.Read())
{
Course.Add(new AddCourse
{
CourseID = reader.GetInt32(0),
CourseName = reader.GetString(1),
Schedule = reader.GetString(3),
Classroom = reader.GetString(4),
});
}
}
}
}
private void LoadSC(int courseid)
{
SC.Clear();
string dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "SchoolManagement.db");
using (var db = new SqliteConnection($"Filename={dbPath}"))
{
db.Open();
var selectCommand = new SqliteCommand("SELECT ID ,StudentID,StudentName,CourseID,CourseName,TeacherName,Schedule,Classroom,Grade FROM SC WHERE CourseID=@Courseid", db);
selectCommand.Parameters.AddWithValue("@Courseid", courseid);
using (var reader = selectCommand.ExecuteReader())
{
while (reader.Read())
{
SC.Add(new AddSC
{
ID = reader.GetInt32(0),
StudentID = reader.GetInt32(1),
StudentName = reader.GetString(2),
CourseID = reader.GetInt32(3),
CourseName = reader.GetString(4),
TeacherName = reader.GetString(5),
Schedule = reader.GetString(6),
Classroom = reader.GetString(7),
Grade = reader.IsDBNull(8) ? "无成绩" : reader.GetString(8)
});
}
}
}
}
private AddSC selectedSC;
private void SCListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (SCListView.SelectedItems.Count == 1)
{
selectedSC = (AddSC)SCListView.SelectedItem;
Debug.WriteLine(selectedSC.ID);
GradeBtn.IsEnabled = true;
Grade_CheatBtn.IsEnabled = true;
Grade_AbsentBtn.IsEnabled = true;
}
else
{
selectedSC = null;
}
}
private void Grade_CheatBtn_Click(object sender, RoutedEventArgs e)
{
int ID = selectedSC.ID;
string str = "作弊";
string dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "SchoolManagement.db");
using (var db = new SqliteConnection($"Filename={dbPath}"))
{
db.Open();
string updateCommand = "UPDATE SC SET Grade=@NewGrade WHERE ID = @ID;";
using (var updateCmd = new SqliteCommand(updateCommand, db))
{
updateCmd.Parameters.AddWithValue("@NewGrade", str);
updateCmd.Parameters.AddWithValue("@ID", ID);
updateCmd.ExecuteNonQuery();
}
}
LoadSC(selectedCourse.CourseID);
GradeBtn.IsEnabled = false;
Grade_AbsentBtn.IsEnabled = false;
Grade_CheatBtn.IsEnabled = false;
}
private void GradeBtn_Click(object sender, RoutedEventArgs e)
{
int ID = selectedSC.ID;
string str = GradeTxbox.Text; ;
string dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "SchoolManagement.db");
using (var db = new SqliteConnection($"Filename={dbPath}"))
{
db.Open();
string updateCommand = "UPDATE SC SET Grade=@NewGrade WHERE ID = @ID;";
using (var updateCmd = new SqliteCommand(updateCommand, db))
{
updateCmd.Parameters.AddWithValue("@NewGrade", str);
updateCmd.Parameters.AddWithValue("@ID", ID);
updateCmd.ExecuteNonQuery();
}
}
LoadSC(selectedCourse.CourseID);
GradeBtn.IsEnabled = false;
Grade_AbsentBtn.IsEnabled = false;
Grade_CheatBtn.IsEnabled = false;
}
private void Grade_AbsentBtn_Click(object sender, RoutedEventArgs e)
{
int ID = selectedSC.ID;
string str = "缺考";
string dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "SchoolManagement.db");
using (var db = new SqliteConnection($"Filename={dbPath}"))
{
db.Open();
string updateCommand = "UPDATE SC SET Grade=@NewGrade WHERE ID = @ID;";
using (var updateCmd = new SqliteCommand(updateCommand, db))
{
updateCmd.Parameters.AddWithValue("@NewGrade", str);
updateCmd.Parameters.AddWithValue("@ID", ID);
updateCmd.ExecuteNonQuery();
}
}
LoadSC(selectedCourse.CourseID);
GradeBtn.IsEnabled = false;
Grade_AbsentBtn.IsEnabled = false;
Grade_CheatBtn.IsEnabled = false;
}
private AddCourse selectedCourse;
private void CourseListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (CourseListView.SelectedItems.Count == 1)
{
selectedCourse = (AddCourse)CourseListView.SelectedItem;
LoadSC(selectedCourse.CourseID);
}
else
selectedCourse = null;
}
}
public class AddCourse
{
public int CourseID { get; set; } // 课程ID
public string CourseName { get; set; } // 课程名称
public string Schedule { get; set; } // 时间安排
public string TeacherName { get; set; } // 教师姓名
public string Classroom { get; set; } // 教室位置
}
public class AddSC
{
public int ID { get; set; } // 课程ID
public int StudentID { get; set; } // 课程ID
public int CourseID { get; set; } // 课程ID
public string StudentName { get; set; } // 课程名称
public string CourseName { get; set; } // 课程名称
public string Schedule { get; set; } // 时间安排
public string TeacherName { get; set; } // 教师姓名
public string Classroom { get; set; } // 教室位置
public string Grade { get; set; }
}
}