/// <summary> /// 初始化一个学生,抛出异常表示会出现了传入值错误 /// </summary> /// <param name="num">学号,长度为9位数字</param> /// <param name="name">姓名</param> /// <param name="chinese">语文成绩</param> /// <param name="math">数学成绩</param> /// <param name="english">英语成绩</param> /// <param name="myClass">这个学生归属的班级</param> public Student(String num,String name,Double chinese,Double math,Double english,Classroom myClass) { if (num.Length != numLength) throw (new System.Exception()); Convert.ToUInt32(num); this.num=num; if(name.Length>nameLengthMax||name.Length<nameLengthMin) throw (new System.Exception()); this.name=name; if(chinese>scoreMax||chinese<scoreMin) throw (new System.Exception()); this.chinese=chinese; if(math>scoreMax||math<scoreMin) throw (new System.Exception()); this.math=math; if(english>scoreMax||english<scoreMin) throw (new System.Exception()); this.english=english; if(myClass==null) throw (new System.Exception()); this.myClass=myClass; if (!myClass.addStudent(this)) //将这个学生添加进班级 throw (new System.InvalidOperationException()); }
public FormMain() { classList[0] = new Classroom("网络一班"); classInUse=classList[0]; //studentInUse = new Student("090810108", "高翔", 60, 61, 59, classList[0]); InitializeComponent(); refreshClassList(classList); refreshStudentList(classList[0]); showStudentInfo(studentInUse); showSortMode(); }
/// <summary> /// 刷新学生列表 /// </summary> /// <param name="targetClass">目标班级对象</param> void refreshStudentList(Classroom targetClass) { listBoxStuList.Items.Clear(); if (targetClass.StudentNum <= 0) ; else { int index; for (index = 1; targetClass.getStudent(index) != null; index++) { listBoxStuList.Items.Add(targetClass.getStudent(index).NAME); } } if(targetClass.StudentNum<Classroom.maxNum) listBoxStuList.Items.Add("添加新学生"); }
/// <summary> /// 初始化一个学生,抛出异常表示会出现了传入值错误 /// </summary> /// <param name="num">学号,长度为9位数字</param> /// <param name="name">姓名</param> /// <param name="chinese">语文成绩</param> /// <param name="math">数学成绩</param> /// <param name="english">英语成绩</param> /// <param name="myClass">这个学生归属的班级</param> public Student(String num, String name, Double chinese, Double math, Double english, Classroom myClass) { if (num.Length != numLength) { throw (new System.Exception()); } Convert.ToUInt32(num); this.num = num; if (name.Length > nameLengthMax || name.Length < nameLengthMin) { throw (new System.Exception()); } this.name = name; if (chinese > scoreMax || chinese < scoreMin) { throw (new System.Exception()); } this.chinese = chinese; if (math > scoreMax || math < scoreMin) { throw (new System.Exception()); } this.math = math; if (english > scoreMax || english < scoreMin) { throw (new System.Exception()); } this.english = english; if (myClass == null) { throw (new System.Exception()); } this.myClass = myClass; if (!myClass.addStudent(this)) //将这个学生添加进班级 { throw (new System.InvalidOperationException()); } }
/// <summary> /// 刷新学生列表 /// </summary> /// <param name="targetClass">目标班级对象</param> void refreshStudentList(Classroom targetClass) { listBoxStuList.Items.Clear(); if (targetClass.StudentNum <= 0) { ; } else { int index; for (index = 1; targetClass.getStudent(index) != null; index++) { listBoxStuList.Items.Add(targetClass.getStudent(index).NAME); } } if (targetClass.StudentNum < Classroom.maxNum) { listBoxStuList.Items.Add("添加新学生"); } }
private void listBoxClassList_SelectedValueChanged(object sender, EventArgs e) { if (listBoxClassList.SelectedItem.ToString() == "添加新班级") { } else { classInUse = classList[listBoxClassList.SelectedIndex]; refreshStudentList(classInUse); } }