///<summary> ///初始化一些数据 ///</summary> static void initData() { //专业 MajorInfo majorInfo1 = new MajorInfo(); majorInfo1.iMajorID = 1; majorInfo1.cMajorName = "HP 软件开发专业".ToCharArray(); Utility_Struct.g_MajorList.Add(majorInfo1); MajorInfo majorInfo2 = new MajorInfo(); majorInfo2.iMajorID = 2; majorInfo2.cMajorName = "HP 软件开发专业".ToCharArray(); Utility_Struct.g_MajorList.Add(majorInfo2); //科目 SubjectInfo subjectInfo1 = new SubjectInfo(); subjectInfo1.iSubjectID = 1; subjectInfo1.cSubjectName = "c# WinForm编程实践".ToCharArray(); subjectInfo1.iMajorID = 1; Utility_Struct.g_SubjectList.Add(subjectInfo1); SubjectInfo subjectInfo2 = new SubjectInfo(); subjectInfo2.iSubjectID = 2; subjectInfo2.cSubjectName = "android开发".ToCharArray(); subjectInfo2.iMajorID = 1; Utility_Struct.g_SubjectList.Add(subjectInfo2); SubjectInfo subjectInfo3 = new SubjectInfo(); subjectInfo3.iSubjectID = 3; subjectInfo3.cSubjectName = "功能测试".ToCharArray(); subjectInfo3.iMajorID = 2; Utility_Struct.g_SubjectList.Add(subjectInfo3); SubjectInfo subjectInfo4 = new SubjectInfo(); subjectInfo4.iSubjectID = 4; subjectInfo4.cSubjectName = "性能测试".ToCharArray(); subjectInfo4.iMajorID = 2; Utility_Struct.g_SubjectList.Add(subjectInfo4); }
private void bt_AddStu_Click(object sender, EventArgs e) { int iMajorID = ((ListItem)this.cb_Major.SelectedItem).id; //获取输入的科目名称 string strSubjectName = this.txt_SubjectName.Text.ToString().Trim(); SubjectInfo subjectInfo = new SubjectInfo() ; subjectInfo.iMajorID = iMajorID; subjectInfo.cSubjectName = strSubjectName.ToCharArray(); //获取列表中的最后一个ID if (Utility_Struct.g_SubjectList.Count > 0) { SubjectInfo lastSubject = (SubjectInfo)Utility_Struct.g_SubjectList[Utility_Struct.g_SubjectList.Count - 1]; subjectInfo.iSubjectID = lastSubject.iSubjectID + 1; } else { subjectInfo.iSubjectID = 1; } Utility_Struct.g_SubjectList.Add(subjectInfo); this.Close(); }