private void btnAdd_Click(object sender, RoutedEventArgs e) { if (lstAvailableStudents.SelectedItem != null && lstClassrooms.SelectedItem != null) { Classroom classroom = (Classroom)lstClassrooms.SelectedItem; Student student = (Student)lstAvailableStudents.SelectedItem; classroom.AddStudent(student); PopulateStudentsLisboxes(classroom); } }
public async Task <ActionResult <string> > CreateClassroom(string ownerId, string classroomName, string description = "") { string classId = Guid.NewGuid().ToString(); Classroom classroom = new Classroom(classId, ownerId, classroomName, description); classroom.AddStudent(ownerId); await classesContainer.CreateItemAsync <Classroom>(classroom, new PartitionKey(classId)); return(Ok()); }
private void ReadDataFromDatabase() { if (AllStudents.Count != 0) { updateDataBase(); } try { if (conn.State != ConnectionState.Open) { spb.add("正在连接数据库"); conn.Open(); } } catch (Exception) { MessageBox.Show("数据库连接失败!"); } try { spb.add("数据库连接成功"); var cmd = conn.CreateCommand(); cmd.CommandText = "select * from students"; var reader = cmd.ExecuteReader(); AllStudents.Clear(); while (reader.Read()) { Student tempstd = new Student(); tempstd.Id = reader.GetString(0); tempstd.Name = reader.GetString(1); string tempStrClassID = reader.GetString(2); Classroom cls = GetOrCreateClassroomById(tempStrClassID); cls.AddStudent(tempstd); tempstd.Classroom = cls; tempstd.Grade = reader.GetDouble(3); tempstd.Sha1 = reader.GetString(4); tempstd.Selected_Mutiply = reader.GetBoolean(5); tempstd.Selected_Single = reader.GetBoolean(6); tempstd.Selected_Report = reader.GetBoolean(7); AllStudents.Add(tempstd); } } catch (Exception ex) { statusPrint(ex.Message); } if (SECURITY_Enabled == true) { foreach (Student astd in AllStudents) { if (astd.getSHA1() != astd.Sha1) { DialogResult ok = MessageBox.Show(astd.Name + astd.Id + "\n的成绩遭到非法修改" + "为" + astd.Grade + "\n是否清空?", "警告!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (ok == DialogResult.Yes) { astd.Grade = -1; astd.Selected_Mutiply = false; updateDataBase(); } } } } foreach (Student astd in AllStudents) { if (astd.Grade != -1 && astd.Selected_Mutiply == false) { DialogResult ok = MessageBox.Show(astd.Name + astd.Id + "\n的成绩" + "为" + astd.Grade + "\n但未生成抽取记录,是否重新生成?", "警告!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (ok == DialogResult.Yes) { astd.Selected_Mutiply = true; updateDataBase(); } } } spb.add(AllStudents.Count + "已读取"); }