Exemplo n.º 1
0
        public async Task <TempCourse> AddTempCourseAsync(string courseId, string authorId)
        {
            var tempCourse = new TempCourse
            {
                CourseId       = courseId,
                AuthorId       = authorId,
                LoadingTime    = DateTime.Now,
                LastUpdateTime = DateTime.UnixEpoch                 // Используется вместо default, потому что default нельзя сохранить в базу
            };

            db.TempCourses.Add(tempCourse);
            await db.SaveChangesAsync();

            return(tempCourse);
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            //Teacher has at most 4 teaching hours everday
            //There're 8 periods from 8 -> 15 (from Monday -> Friday)
            //There're only 2 kinds of credit hours: 2 hrs(1 session) & 4 hrs(2 sessions)
            //There're 10 classrooms in Hogwarts School (Room #1 -> Room #10)
            int CreditHours = Classes.HogwartsDataAccess.GetCreditHours(DropDownList2.SelectedValue, DropDownList3.SelectedValue);

            bool[][] AllottedTable = new bool[7][];//8, 9, 10, 11, 12, 13, 14, 15
            for (int i = 0; i <= 6; i++)
            {
                AllottedTable[i] = new bool[9];
            }
            bool[][][] AllottedClass = new bool[11][][];

            for (int i = 0; i <= 10; i++)
            {
                AllottedClass[i] = new bool[7][];
            }

            for (int i = 0; i <= 10; i++)
            {
                for (int j = 0; j <= 6; j++)
                {
                    AllottedClass[i][j] = new bool[9];
                }
            }

            Classes.HogwartsDataAccess.FillAllottedTable(DropDownList1.SelectedValue, DropDownList2.SelectedValue, DropDownList4.SelectedValue, AllottedTable);
            Classes.HogwartsDataAccess.FillAllottedClass(DropDownList1.SelectedValue, AllottedClass);
            Session["CourseLst"] = new List <Course>();
            List <TempCourse> TCourseLst = new List <TempCourse>();

            Session["SessionLst"] = new List <Session>();
            List <TempSession> TSessionLst;
            string             error = "";

            for (int i = 1; i <= RadioButtonList1.SelectedIndex + 1; i++)
            {
                Course c = new Course();
                c.CourseID     = i;
                c.SemesterID   = Classes.HogwartsDataAccess.GetSemesterID(DropDownList1.SelectedValue);
                c.StaffID      = Classes.HogwartsDataAccess.GetStaffID(DropDownList2.SelectedValue, DropDownList4.SelectedValue);
                c.DisciplineID = Classes.HogwartsDataAccess.GetDisciplineID(DropDownList2.SelectedValue, DropDownList3.SelectedValue);
                c.MaxCapacity  = 50;
                List <Course> LC = (List <Course>)Session["CourseLst"];
                LC.Add(c);
                Session["CourseLst"] = LC;
                TempCourse tc = new TempCourse(i, DropDownList1.SelectedValue, DropDownList2.SelectedValue, DropDownList3.SelectedValue, DropDownList4.SelectedValue, c.MaxCapacity);
                TCourseLst.Add(tc);
                List <Session> LS = (List <Session>)Session["SessionLst"];
                error = AddOneCourse(i, CreditHours, AllottedClass, AllottedTable, LS);
                Session["SessionLst"] = LS;
                if (error != "")
                {
                    break;
                }
            }

            if (error != "")
            {
                HideInfo();
                Label1.Text = error;
                return;
            }

            //show all new courses and sessions
            Label1.Text          = "";
            TSessionLst          = Utility.CreateNewTempSessionList((List <Session>)Session["SessionLst"]);
            CourseGeH.Visible    = true;
            GridView1.DataSource = TCourseLst;
            GridView1.DataBind();
            GridView1.Visible    = true;
            SessionGeH.Visible   = true;
            GridView2.DataSource = TSessionLst;
            GridView2.DataBind();
            GridView2.Visible = true;
            Button2.Visible   = true;
        }