Exemple #1
0
    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();
    }
Exemple #2
0
    //点击某一个按钮,激发可选择的替换项目
    protected void Button_ShowOrChange(object sender, EventArgs e)
    {
        MyButton b = (MyButton)sender;

        //获得该班所有课的按钮映射
        //全部使用双击操作,双击选中待交换课时,再双击选中某一个可以交换的课时
        //因为我仅仅对点击黑色(未选中)按钮和蓝色按钮有反应,所以当一个按钮不论是在什么时候变红,都不会对下面操作有影响

        //  if ((string)Session[b.IDForThisButton] == "courseButton")//如果这个按钮是黑色
        if ((string)Session[b.IDForThisButton] == "aspTableCell")
        {//执行查询可交换选项
            ArrayList ChoseButtonIDList = null;
            if (Session["ChoseButtonIDList"] != null)
            {
                ChoseButtonIDList = (ArrayList)Session["ChoseButtonIDList"];
                for (int i = 0; i < ChoseButtonIDList.Count; i++)
                {
                    string buttonID = (string)ChoseButtonIDList[i];
                    //   Session[buttonID] = "courseButton";//把原先红色的恢复成黑色
                    Session[buttonID] = "aspTableCell";//把原先红色的恢复成黑色
                }
                ChoseButtonIDList.Clear();
            }
            else
            {
                ChoseButtonIDList = new ArrayList();//如果没有,说明是第一次点击按钮,则新建一个
            }

            /* //对于ans课表i班j节课 所能无冲突调换的 点
             * public List<int> givepoint(int i, int j)*/
            //ArrayList ChoseButtonIDList = new ArrayList();
            //思路,点击一个按钮,如果这个按钮是黑色的,那么将先前的变红色的按钮恢复成黑色
            //调用函数,找出可替换位置,将这个按钮连同新的可替换位置放入一个记录中(存放这些按钮的ID)

            Session["WaittingChangeButton"] = b;//记录是谁要换位置
            //Session[b.IDForThisButton] = "nameRedButton";//切换状态
            ChoseButtonIDList.Add(b.IDForThisButton);

            string classNo   = b.Class_id;
            string className = classNo.Substring(2);
            int    classnameInt;
            if (className.StartsWith("0"))
            {
                classnameInt = int.Parse(className.Substring(1));
            }
            else
            {
                classnameInt = int.Parse(className);
            }
            //得到第一个参数
            AutoSchedule auto          = (AutoSchedule)Cache["auto"];
            int          lessonNo      = (b.Day - 1) * 8 + b.Lesson;
            List <int>   choseableItem = auto.givepoint(classnameInt, lessonNo);
            //给出一个序列,里面存放了某一个班的可以用来与选定课程交换的节次序号,1~8为周一的第1~8节课,9为周二第一节

            foreach (int index in choseableItem)
            {
                int day    = (index - 1) / 8;
                int lesson = (index - 1) % 8;

                string IDForAButton = "Button_" + DropDownList_Grade.SelectedValue + DropDownList_class.SelectedValue + (day + 1) + "" + (lesson + 1);
                ChoseButtonIDList.Add(IDForAButton);
            }
            foreach (string name in ChoseButtonIDList)
            {
                //   Session[name] = "courseButton blue";
                Session[name] = "aspTableCellBrown";
            }
            //Session[b.IDForThisButton] = "courseButton red";
            Session[b.IDForThisButton]   = "aspTableCellGreen";
            Session["ChoseButtonIDList"] = ChoseButtonIDList;//用Session保存颜色变化的按钮
            ShowClassTable();
            return;
        }
        else
        {
            //if ((string)Session[b.IDForThisButton] == "courseButton blue")
            if ((string)Session[b.IDForThisButton] == "aspTableCellBrown")
            {
                MyButton a = (MyButton)Session["WaittingChangeButton"];//获得上一次点击的对象

                string classNo   = b.Class_id;
                string className = classNo.Substring(2);
                int    classnameInt;
                if (className.StartsWith("0"))
                {
                    classnameInt = int.Parse(className.Substring(1));
                }
                else
                {
                    classnameInt = int.Parse(className);
                }
                //得到第一个参数
                AutoSchedule auto       = (AutoSchedule)Cache["auto"];
                int          lessonNo_a = (b.Day - 1) * 8 + b.Lesson;
                int          lessonNo_b = (a.Day - 1) * 8 + a.Lesson;
                auto.changeclass(classnameInt, lessonNo_a, lessonNo_b);
                Tea[,] Lessontable = auto.func();
                string lessonTableName = "LessonTable" + DropDownList_Grade.SelectedValue;
                Cache[lessonTableName] = Lessontable;                   //更新表
                ArrayList al = (ArrayList)Session["ChoseButtonIDList"]; //获得所有变红色的格子
                for (int i = 0; i < al.Count; i++)
                {
                    string buttonID = (string)al[i];
                    //Session[buttonID] = "courseButton";//把原先红色的恢复成黑色
                    Session[buttonID] = "aspTableCell";//把原先红色的恢复成黑色
                }
                ShowClassTable();
            }
        }
    }