static void Main(string[] args) { CaffeineBeverageInfo coffee = new CoffeeInfo(); CaffeineBeverageInfo tea = new TeaInfo(); Console.WriteLine("--== Making coffee ==--"); coffee.PrepareRecipe(); Console.WriteLine(); Console.WriteLine("--== Making tea ==--"); tea.PrepareRecipe(); Console.ReadLine(); }
private void CreateTable() { /*create table gcgFeedBack( * class_id char(4) not null, * CourseNo char(3) not null, * TeacherNo char(8) not null, * primary key(class_id,CourseNo) * )*/ //首先这也是一个二维表,行显示各个学科,列属性为班级 //先显示学科 Table1.Rows.Clear(); string sql_hasgcgFeedBackTable = "select * from sysobjects where name = 'gcgFeedBack'and xtype = 'U'"; DBManipulation dbm = new DBManipulation(); object gcgFeedBack = dbm.ExecuteScalar(sql_hasgcgFeedBackTable, null); if (gcgFeedBack == null) //如果表都不存在,说明教导主任没有反对意见 { this.Button_submit.Visible = false; return; } string sql1 = "select distinct subjectname from gcgFeedBack, gcgCourse, gcgSubject, temp_class, gcgSubjectGroup where gcgFeedBack.CourseNo = gcgCourse.CourseNo and gcgCourse.SubjectNo = gcgSubject.subjectno and gcgSubject.subjectGroupNo = gcgSubjectGroup.subjectGroupNo and temp_class.class_id = gcgFeedBack.class_id and Grade = @Grade and subjectGroupName = @subjectGroupName"; ParameterStruct p_grade = new ParameterStruct("@Grade", DropDownList_Grade.SelectedValue); ParameterStruct p_subjectGroupName = new ParameterStruct("@subjectGroupName", Label_SubjectGroup.Text); ArrayList plist1 = new ArrayList(); plist1.Add(p_grade); plist1.Add(p_subjectGroupName); SqlDataReader dataReader1 = dbm.ExecuteQueryOnLine(sql1, plist1); TableRow tableRow = new TableRow(); if (!dataReader1.HasRows)//如果没有反馈,那么什么都不显示 { this.Button_submit.Visible = false; return; } else { this.Button_submit.Visible = true; } tableRow.CssClass = "aspTableRow1"; //先加入一个空格子,这个格子是二维表的左上角的那个方格 TableCell cell_blank = new TableCell(); cell_blank.Text = " "; //没有文本显示 // cell_blank.Attributes.Add("onclick", "getdate(this)"); cell_blank.CssClass = "aspTableCell3"; tableRow.Controls.Add(cell_blank); List <string> courseset = new List <string>(); courseset.Clear();//习惯性清空 while (dataReader1.Read()) { TableCell cell_CourseName = new TableCell(); cell_CourseName.Text = dataReader1.GetString(0); //文本为科目名 // cell_CourseName.Attributes.Add("onclick", "getdate(this)"); cell_CourseName.CssClass = "aspTableCell3"; tableRow.Controls.Add(cell_CourseName); courseset.Add(cell_CourseName.Text);//将这个科目名添加到 } Table1.Controls.Add(tableRow); dataReader1.Close(); dbm.Close(); //---------------------------------------------分割线,自此表头学科一栏生成完毕-------------------------------------------- //查询某一个年级在该学科组范围内出问题的所有班级 string sql2 = "select distinct temp_class.class_id,class_name from temp_class,gcgFeedBack,gcgCourse,gcgSubject,gcgSubjectGroup where temp_class.class_id = gcgFeedBack.class_id and gcgFeedBack.CourseNo = gcgCourse.CourseNo and gcgCourse.SubjectNo = gcgSubject.subjectno and gcgSubject.subjectGroupNo = gcgSubjectGroup.subjectGroupNo and class_grade = @Grade and subjectGroupName = @subjectGroupName order by class_id asc"; SqlDataReader dataReader2 = dbm.ExecuteQueryOnLine(sql2, plist1); List <ClassInfo> classset = new List <ClassInfo>(); classset.Clear(); //班级编号写入链表 while (dataReader2.Read()) { ClassInfo cdata = new ClassInfo(dataReader2.GetString(0), dataReader2.GetString(1));//存放class_id,class_name classset.Add(cdata); } dataReader2.Close(); SqlDataReader dataReader3;//准备接受DataReader对象 string sql3; for (int i = 0; i < classset.Count; i++) { ClassInfo cinfo = classset[i]; //依据班级号和学期号查询这些班级在特定时间段的授课记录,一个班一个班的显示数据 sql3 = "select gcgFeedBack.CourseNo,gcgFeedBack.TeacherNo,TeacherName,subjectName from gcgFeedBack,gcgCourse,gcgSubject,temp_teacher where gcgFeedBack.CourseNo = gcgCourse.CourseNo and gcgFeedBack.TeacherNo = temp_teacher.TeacherNo and gcgCourse.SubjectNo = gcgSubject.subjectno and class_id = @class_id"; ParameterStruct p_class_id = new ParameterStruct("@class_id", cinfo.No); // ParameterStruct p_semester = new ParameterStruct("@SemesterNo", semeterNo); ArrayList parameterList3 = new ArrayList(); parameterList3.Add(p_class_id); // parameterList3.Add(p_semester); dataReader3 = dbm.ExecuteQueryOnLine(sql3, parameterList3); //保存这个班出问题的科目号,科目名与老师号 List <TeaInfo> tset = new List <TeaInfo>(); tset.Clear(); while (dataReader3.Read()) { TeaInfo tdata = new TeaInfo(dataReader3.GetString(1), dataReader3.GetString(2), dataReader3.GetString(3), dataReader3.GetString(0));//no,name,sbj,courseno tset.Add(tdata); } tableRow = new TableRow(); //tableRow.CssClass = "aspTableRow1"; //先加入一个班级格子,显示这个班级的名字 TableCell cell_class = new TableCell(); cell_class.Text = cinfo.Name; cell_class.CssClass = "aspTableCell"; tableRow.Controls.Add(cell_class); //循环学科链表,为每一行(每一个班)的每一门学科填入对应老师 for (int j = 0; j < courseset.Count; j++) { string s1 = courseset[j]; TableCell cell = new TableCell(); //通过遍历这个班的老师链表实现 foreach (TeaInfo s2 in tset) { if (s1.Equals(s2.Sbj)) { cell.Text = s2.Name; break; } } cell.CssClass = "aspTableCell"; tableRow.Controls.Add(cell); } Table1.Controls.Add(tableRow); dataReader3.Close();//注意每一次循环都会执行一次数据库查询,返回一个DataReader,所以这次循环体执行完之后必须将其关闭,避免占用connection } dbm.Close(); }
protected void CreateTheWholeSchedule() { string sql_courseNum = "select COUNT(*) from gcgCourse where Grade = '" + DropDownList_Grade.SelectedValue + "'"; DBManipulation dbm = new DBManipulation(); Object obj_countCourse = dbm.ExecuteScalar(sql_courseNum, null); if (obj_countCourse == null) {//这个年级还没有安排课程计划,无需接着往下了 System.Web.UI.ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "Button6_Click", "alert('没有安排学科!')", true); return; } int count_courseNum = int.Parse(obj_countCourse.ToString()); if (DropDownList_class.Items.Count == 0) { //没有班级参与排课,无需接着往下了 System.Web.UI.ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "Button6_Click", "alert('没有班级参与排课!')", true); return; } string sql_checkTime = "select count(*) from gcgSchedule where Grade = " + DropDownList_Grade.SelectedValue; Object obj_time = dbm.ExecuteScalar(sql_checkTime, null); if (obj_time.ToString().Equals("0")) { System.Web.UI.ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "Button6_Click", "alert('尚未设置每节课的时间段!')", true); return; } // debug.Text = count_courseNum + ""; Struct_CourseName[] courseList = new Struct_CourseName[count_courseNum]; if (courseList == null) { Response.Redirect("1.aspx"); } //准备科目名与学科号的映射,名字与年级有关,因为不同年级对于同一个科目的学科号是不一样的。,所以必须对应年级。 string sql_MappingCourseNoAndCourseName = "select CourseNo,subjectname from gcgCourse,gcgSubject where gcgCourse.SubjectNo = gcgSubject.subjectno and Grade = '" + DropDownList_Grade.SelectedValue + "'"; SqlDataReader dr00 = dbm.ExecuteQueryOnLine(sql_MappingCourseNoAndCourseName, null); Dictionary <string, string> dict_SubjectName_CourseNo = new Dictionary <string, string>(); while (dr00.Read()) { dict_SubjectName_CourseNo.Add(dr00.GetString(1), dr00.GetString(0)); //因为年级一旦确定,科目名就与学科号 一 一 对应了 } dr00.Close(); string dict_SubjectName_CourseNo_Name = "dict_SubjectName_CourseNo" + DropDownList_Grade.SelectedValue; Cache[dict_SubjectName_CourseNo_Name] = dict_SubjectName_CourseNo; //准备学科号与学科名的映射 Dictionary <string, string> dict_CourseNo_SubjectName = new Dictionary <string, string>(); SqlDataReader dr01 = dbm.ExecuteQueryOnLine(sql_MappingCourseNoAndCourseName, null); while (dr01.Read()) { dict_CourseNo_SubjectName.Add(dr01.GetString(0), dr01.GetString(1)); } dr01.Close(); string dict_CourseNo_SubjectName_Name = "dict_CourseNo_SubjectName" + DropDownList_Grade.SelectedValue; Cache[dict_CourseNo_SubjectName_Name] = dict_CourseNo_SubjectName; //准备班级号与班级名的映射,查询授课安排表中的最新一个学期的某一个年级的班级号与其对应的班级名,肯定是 一 一 对应的。 string sql_MappingClassNameAndClassNo = "select class_name,class_id from temp_class,(select distinct ClassNo from gcgLectureForm where SemesterNo = (select MAX(SemesterNo) from gcgLectureForm)) AS temp where class_id = ClassNo and class_grade = '" + DropDownList_Grade.SelectedValue + "'"; SqlDataReader dr_MappingClassNameAndClassNo = dbm.ExecuteQueryOnLine(sql_MappingClassNameAndClassNo, null); Dictionary <string, string> dict_ClassName_ClassNo = new Dictionary <string, string>(); while (dr_MappingClassNameAndClassNo.Read()) { dict_ClassName_ClassNo.Add(dr_MappingClassNameAndClassNo.GetString(0), dr_MappingClassNameAndClassNo.GetString(1)); } dr_MappingClassNameAndClassNo.Close(); string dict_ClassName_ClassNo_Name = "dict_ClassName_ClassNo" + DropDownList_Grade.SelectedValue; Cache[dict_ClassName_ClassNo_Name] = dict_ClassName_ClassNo; string sql_fillCourseList = "select CourseNo,subjectname,CourseTime from gcgCourse,gcgSubject where gcgCourse.SubjectNo = gcgSubject.subjectno and Grade = '" + DropDownList_Grade.SelectedValue + "'"; SqlDataReader dr1 = dbm.ExecuteQueryOnLine(sql_fillCourseList, null); if (dr1 == null) { Response.Redirect("1.aspx"); } for (int i = 0; i < courseList.Length && dr1.Read(); i++) { courseList[i] = new Struct_CourseName(); courseList[i].CourseNo1 = dr1.GetString(0); courseList[i].SubjectName1 = dr1.GetString(1); Byte b = dr1.GetByte(2); courseList[i].Hour1 = (int)b; } dr1.Close(); dbm.Close(); string sql_countClassNum = "select COUNT(*) from( select distinct ClassNo from gcgLectureForm, temp_class where gcgLectureForm.ClassNo = temp_class.class_id and class_grade = @Grade) AS temp "; //为什么上面这一句这么复杂,是为了防止有些班级还没有参与排课计划 ParameterStruct p_grade = new ParameterStruct("@Grade", DropDownList_Grade.SelectedValue); ArrayList plist1 = new ArrayList(); plist1.Add(p_grade); Object obj_countClassNum = dbm.ExecuteScalar(sql_countClassNum, plist1); if (obj_countClassNum == null) { return; } int countClassNum = int.Parse(obj_countClassNum.ToString()); string sql_LectureForm_orderByClassNoAndCourseNo = "select ClassNo,gcgLectureForm.CourseNo,gcgLectureForm.TeacherNo,temp_teacher.TeacherName from gcgLectureForm, gcgCourse, gcgSubject, temp_teacher where gcgCourse.CourseNo = gcgLectureForm.CourseNo and gcgCourse.SubjectNo = gcgSubject.subjectno and temp_teacher.TeacherNo = gcgLectureForm.TeacherNo and Grade = @Grade order by gcgLectureForm.ClassNo,gcgLectureForm.CourseNo"; SqlDataReader dr2 = dbm.ExecuteQueryOnLine(sql_LectureForm_orderByClassNoAndCourseNo, plist1); ArrayList plist2 = new ArrayList(); TeaInfo[,] teacherArrange = new TeaInfo[countClassNum, count_courseNum]; for (int i = 0; i < countClassNum; i++) { for (int j = 0; j < count_courseNum; j++) { teacherArrange[i, j] = new TeaInfo(); if (!dr2.HasRows) { break; } else { dr2.Read(); } try { teacherArrange[i, j].No = dr2.GetString(2); //教师工号 teacherArrange[i, j].Name = dr2.GetString(3); //教师名 teacherArrange[i, j].Courseno = dr2.GetString(1); //学科号,可能是擅长的,可能是非擅长的 } catch (Exception) { System.Web.UI.ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "Button6_Click", "alert('数据不够,请检查是否已经安排所有班级的老师!')", true); return; } } if (!dr2.HasRows) { break; } } dr2.Close(); dbm.Close(); AutoSchedule auto = new AutoSchedule(); Cache["auto"] = auto; auto.CourseList = courseList; auto.TeacherArrange = teacherArrange; auto.MakingSchedule(); Tea[,] Lessontable = auto.func();//注意:这个课表的行是一个个班级,列是这个班级一周的额全部课程分布,都是从1开始的 string lessonTableName = "LessonTable" + DropDownList_Grade.SelectedValue; Cache[lessonTableName] = Lessontable;//使用ViewState保存,生命周期为该页面,只要这个页面没有关闭就存在 if (Lessontable == null) { Response.Redirect("1.aspx"); } ShowClassTable(); }
protected void createtable(string semeterNo) { Table1.Rows.Clear(); ArrayList buttonlist = new ArrayList();//存放所有按钮的信息 //形参是学期号,蕴含年份和上下学期 string grade = DropDownList_Grade.SelectedValue.ToString(); //查出这个年级的所有学科,以便形成列表头 //一个年级的学科是没有历史记录的,设定即覆盖 string sql1 = "select CourseNo,subjectname from gcgCourse, gcgSubject where gcgCourse.SubjectNo = gcgSubject.subjectno and Grade = @Grade"; ParameterStruct p_grade = new ParameterStruct("@Grade", grade); ArrayList parameterList1 = new ArrayList(); parameterList1.Add(p_grade); DBManipulation dbm = new DBManipulation(); SqlDataReader dataReader1 = dbm.ExecuteQueryOnLine(sql1, parameterList1); List <string> courseset = new List <string>(); courseset.Clear();//习惯性清空 if (!dataReader1.HasRows) { return; } TableRow tableRow = new TableRow(); tableRow.CssClass = "aspTableRow1"; //先加入一个空格子,这个格子是二维表的左上角的那个方格 TableCell cell_blank = new TableCell(); cell_blank.Text = " ";//没有文本显示 // cell_blank.Attributes.Add("onclick", "getdate(this)"); cell_blank.CssClass = "aspTableCell3"; tableRow.Controls.Add(cell_blank); // int id = 0; while (dataReader1.Read()) { TableCell cell_CourseName = new TableCell(); cell_CourseName.Text = dataReader1.GetString(1);//文本为科目名 // cell_CourseName.Attributes.Add("onclick", "getdate(this)"); cell_CourseName.CssClass = "aspTableCell3"; tableRow.Controls.Add(cell_CourseName); courseset.Add(cell_CourseName.Text);//将这个科目名添加到 } Table1.Controls.Add(tableRow); dataReader1.Close(); dbm.Close(); //---------------------------------------------分割线,自此表头学科一栏生成完毕-------------------------------------------- //-------------------------------------------------以下开始按行生成数据---------------------------------------------------- // ParameterStruct p_year = new ParameterStruct("@year", year+"%"); ParameterStruct p_semesterNo = new ParameterStruct("@SemesterNo", semeterNo); ArrayList parameterList2 = new ArrayList(); parameterList2.Add(p_grade); parameterList2.Add(p_semesterNo); dbm = new DBManipulation(); //查询出某一个学期某一个年级的所有班级 string sql2 = "select distinct class_id,class_name from temp_class,gcgLectureForm where temp_class.class_id = gcgLectureForm.ClassNo and class_grade = @Grade and SemesterNo = @SemesterNo order by class_id asc"; SqlDataReader dataReader2 = dbm.ExecuteQueryOnLine(sql2, parameterList2); List <ClassInfo> classset = new List <ClassInfo>(); classset.Clear(); //班级编号写入链表 while (dataReader2.Read()) { ClassInfo cdata = new ClassInfo(dataReader2.GetString(0), dataReader2.GetString(1));//存放class_id,class_name classset.Add(cdata); } dataReader2.Close(); SqlDataReader dataReader3;//准备接受DataReader对象 string sql3; //string SemesterNo = GetSemesterNo(); for (int i = 0; i < classset.Count; i++) { ClassInfo cinfo = classset[i]; //依据班级号和学期号查询这些班级在特定时间段的授课记录,一个班一个班的显示数据 sql3 = "select gcgLectureForm.TeacherNo,TeacherName,subjectname,gcgCourse.CourseNo from gcgLectureForm,gcgCourse,gcgSubject,temp_teacher where gcgCourse.CourseNo = gcgLectureForm.CourseNo and gcgCourse.SubjectNo = gcgSubject.subjectno and temp_teacher.TeacherNo = gcgLectureForm.TeacherNo and ClassNo = @ClassNo and SemesterNo = @SemesterNo"; ParameterStruct p_classNo = new ParameterStruct("@ClassNo", cinfo.No); ParameterStruct p_semester = new ParameterStruct("@SemesterNo", semeterNo); ArrayList parameterList3 = new ArrayList(); parameterList3.Add(p_classNo); parameterList3.Add(p_semester); dataReader3 = dbm.ExecuteQueryOnLine(sql3, parameterList3); //保存这个班在某一个学期的所有老师 List <TeaInfo> tset = new List <TeaInfo>(); tset.Clear(); while (dataReader3.Read()) { TeaInfo tdata = new TeaInfo(dataReader3.GetString(0), dataReader3.GetString(1), dataReader3.GetString(2), dataReader3.GetString(3));//no,name,sbj,courseno tset.Add(tdata); } tableRow = new TableRow(); //tableRow.CssClass = "aspTableRow1"; //先加入一个班级格子,显示这个班级的名字 TableCell cell_class = new TableCell(); // cell_class.Attributes.Add("onclick", "getdate(this)"); cell_class.Text = cinfo.Name; // cell_class.ID = "cell_class_" + i + times; cell_class.CssClass = "aspTableCell4"; tableRow.Controls.Add(cell_class); //循环学科链表,为每一行(每一个班)的每一门学科填入对应老师 for (int j = 0; j < courseset.Count; j++) { string s1 = courseset[j]; // foreach (string s1 in courseset) { TableCell cell = new TableCell(); cell.CssClass = "aspTableCell";//先设置格子的样式为默认样式 // cell.Attributes.Add("onclick", "getdata()"); //通过遍历这个班的老师链表实现 foreach (TeaInfo s2 in tset) { if (s1.Equals(s2.Sbj)) { // public MyButton(string class_id,string CourseNo,string TeacherNo) { MyButton b = new MyButton(cinfo.No, s2.Courseno, s2.No); b.Text = s2.Name; //bt.Click += new EventHandler(bt_Click); string buttonName = b.Class_id + b.CourseNo1; if (Session[buttonName] == null) { // Session[buttonName] = "namebutton"; Session[buttonName] = "aspTableCell"; } b.Click += new EventHandler(ButtonForFeedBack_onClick); // b.CssClass = Session[buttonName].ToString();//如果刷新之前已经有记录,那么直接用之前的样式 b.CssClass = "namebutton"; buttonlist.Add(b); //cell.Text = s2.Name;// dataReader.GetString(1); cell.Controls.Add(b); cell.CssClass = Session[buttonName].ToString();//看要不要改样式 break; } } tableRow.Controls.Add(cell); } Table1.Controls.Add(tableRow); dataReader3.Close();//注意每一次循环都会执行一次数据库查询,返回一个DataReader,所以这次循环体执行完之后必须将其关闭,避免占用connection } dbm.Close(); Session["buttonlist"] = buttonlist; // times++; }