protected void AddSupervision(DateTime t_start, DateTime t_end, ScheduledComponent sc)
        {
            ScheduledComponent sched1 = new ScheduledComponent();
            TimeSpan           tgap   = new TimeSpan();

            tgap = t_end - t_start;
            if ((tgap.TotalMinutes >= 10) && (tgap.TotalDays < 2))
            {
                ExamConversions u   = new ExamConversions();
                ExamComponent   ec1 = new ExamComponent();
                ec1.m_ComponentCode    = "Super";
                ec1.m_ComponentTitle   = "Supervision";
                ec1.m_ComponentTitle  += "-" + sc.GetHashCode().ToString();
                ec1.m_ExamBoardID      = new Guid("436ff234-0457-430a-b1e2-b08758ff30ef");
                ec1.m_year             = Year.ToString().Substring(2, 2);
                ec1.m_season           = u.GetSeasonCode(SeasonCode);
                ec1.m_Teachermarks     = "0"; ec1.m_MaximumMark = "0";
                ec1.m_Timetabled       = "T"; ec1.m_TimetableDate = t_start;
                ec1.m_TimetableSession = "A";
                ec1.m_Time             = tgap.TotalMinutes.ToString();
                //now if the brat has extra time we need to reduce...>!!!!
                StudentSENList ssen1      = new StudentSENList(sc.m_StudentId.ToString());
                double         extra_time = 0;
                double         time1      = tgap.TotalMinutes;
                //now if the brat has extra time we need to reduce.. becasue it will be increased by code when read...
                foreach (StudentSEN sen1 in ssen1.m_List)
                {
                    if (sen1.m_ExamsExtraTime > 0)
                    {
                        extra_time = (double)sen1.m_ExamsExtraTime;
                    }
                }
                time1 = time1 / ((100 + extra_time) / 100);
                int i = (int)time1;
                ec1.m_Time = i.ToString();
                ec1.Create();

                ec1.m_ComponentID = ec1.Find_ComponentID(ec1.m_ComponentCode, ec1.m_ComponentTitle, ec1.m_ExamBoardID.ToString(), ec1.m_season, ec1.m_year);

                if (ec1.m_ComponentID != Guid.Empty)
                {
                    sched1.Load(ec1.m_ComponentID, sc.m_StudentId);

                    if (!sched1.m_valid)
                    {
                        sched1.m_StudentId   = sc.m_StudentId;
                        sched1.m_ComponentId = ec1.m_ComponentID;
                        sched1.m_RoomId      = Guid.Empty;
                        sched1.m_Year        = Year.ToString();
                        sched1.m_Season      = u.GetSeasonCode(SeasonCode);
                        sched1.m_valid       = true;
                        sched1.m_Date        = t_start;
                        sched1.m_Desk        = "";
                        sched1.m_Will_Type   = false;// do these later...
                        sched1.Save();
                    }
                }
            }
        }
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "Select")
     {
         int         index = Convert.ToInt32(e.CommandArgument);
         GridViewRow row   = GridView1.Rows[index];
         //col 9 has id.... scheduled component ID I thinks
         TableCell   c        = row.Cells[1];
         string      s        = row.Cells[9].Text;
         Guid        g        = new Guid(s);
         List <Guid> selected = new List <Guid>();
         selected = (List <Guid>)ViewState["Selected"];
         if (selected.Contains(g))
         {
             selected.Remove(g);
             c.BackColor = System.Drawing.Color.White;
         }
         else
         {
             selected.Add(g);
             c.BackColor = System.Drawing.Color.Aqua;
         }
         ViewState["Selected"] = selected;
     }
     if (e.CommandName == "xx2")
     {
         int         index = Convert.ToInt32(e.CommandArgument);
         GridViewRow row   = GridView1.Rows[index];
         //col 9 has id.... scheduled component ID I thinks
         string             s  = row.Cells[9].Text;
         Guid               g  = new Guid(s);
         ScheduledComponent sc = new ScheduledComponent();
         sc.Load(g);
         Panel1.Visible                   = false;
         Panel2.Visible                   = true;
         Label_EditName.Text              = sc.m_Givenname + " " + sc.m_Surname + " (" + sc.m_ExamNumber + ")";
         TextBox_Desk.Text                = sc.m_Desk;
         ViewState["CurrentEdit"]         = g;
         DropDownList_Rooms.SelectedValue = sc.m_RoomId.ToString();
         TextBox_StartTime.Text           = sc.m_Date.ToShortTimeString();
     }
 }
        protected void Button_EditSave_Click(object sender, EventArgs e)
        {
            Guid g = (Guid)ViewState["CurrentEdit"];
            ScheduledComponent sc = new ScheduledComponent();

            sc.Load(g);
            sc.m_Desk   = TextBox_Desk.Text;
            sc.m_RoomId = new Guid(DropDownList_Rooms.SelectedValue);

            //starttime box is hh:mm
            int      hour = System.Convert.ToInt16(TextBox_StartTime.Text.Substring(0, 2));
            int      min  = Convert.ToInt16(TextBox_StartTime.Text.Substring(3, 2));
            DateTime t1   = new DateTime(sc.m_Date.Year, sc.m_Date.Month, sc.m_Date.Day, hour, min, 0);

            sc.m_Date = t1;
            sc.Save();

            Panel1.Visible = true;
            Panel2.Visible = false;
            SetupGrid();
            GridView1.DataBind();
        }
        protected void FindNextSlot(ScheduledComponent sc, DateTime start_time)//start time is time of last exam..
        {
            //so we are going to look forward for next slot big enough to accomodate this boy and scehdule it??
            ScheduledComponentList scl2 = new ScheduledComponentList();
            //goto next day
            DateTime t0    = new DateTime(start_time.Year, start_time.Month, start_time.Day);
            bool     found = false;

            while (!found)
            {
                t0 = t0.AddDays(1);
                if (t0.DayOfWeek == DayOfWeek.Saturday)
                {
                    t0 = t0.AddDays(2);                                    //nightmare!
                }
                scl2.LoadList_Student(t0.AddHours(8), t0.AddHours(12), sc.m_StudentId.ToString());
                if (scl2.m_List.Count == 0)
                {
                    sc.m_Date = t0.AddHours(12).AddMinutes(30).AddMinutes(-sc.m_TimeAllowed - 10);
                    sc.Save();
                    //need to add supervision....
                    AddSupervision(start_time, sc.m_Date, sc);
                    found = true;
                }
                else
                {
                    //going to count hours am...
                    int total = 0; DateTime t3 = new DateTime();
                    foreach (ScheduledComponent sc1 in scl2.m_List)
                    {
                        total += sc1.m_TimeAllowed + 10; t3 = sc1.m_Date.AddMinutes(sc1.m_TimeAllowed + 10);
                    }
                    total += sc.m_TimeAllowed;
                    if (total <= 180)
                    {
                        sc.m_Date = t3; sc.Save();
                        AddSupervision(start_time, sc.m_Date, sc); found = true;
                    }
                    else
                    {
                        scl2.LoadList_Student(t0.AddHours(13), t0.AddHours(18), sc.m_StudentId.ToString());
                        if (scl2.m_List.Count == 0)
                        {
                            sc.m_Date = t0.AddHours(13).AddMinutes(40);
                            sc.Save();
                            //need to add supervision....
                            AddSupervision(start_time, sc.m_Date, sc); found = true;
                        }
                        else
                        {
                            total = 0;
                            foreach (ScheduledComponent sc1 in scl2.m_List)
                            {
                                total += sc1.m_TimeAllowed + 10; t3 = sc1.m_Date.AddMinutes(sc1.m_TimeAllowed + 10);
                            }
                            total += sc.m_TimeAllowed;
                            if (total <= 180)
                            {
                                sc.m_Date = t3; sc.Save();
                                AddSupervision(start_time, sc.m_Date, sc); found = true;
                            }
                            else
                            {
                                found = false;
                            }
                        }
                    }
                }
            }
        }
示例#5
0
        protected void UpdateTimetable(DateTime start, DateTime end)
        {
            // add scheduled components for any components not scheduled...
            //TODO also delete any withdrawn....
            ExamConversions      u    = new ExamConversions();
            ExamCompononent_List ecl1 = new ExamCompononent_List();

            //ecl1.LoadAllComponents(Year.ToString(), SeasonCode.ToString());
            ecl1.LoadAllComponentsSeasonDate(YearCode.ToString(), SeasonCode.ToString(), start, end);
            Encode en = new Encode();
            string s  = "";

            ScheduledComponent sched1 = new ScheduledComponent();

            s = ""; int n = 0;
            DateTime    d1 = new DateTime();

            foreach (ExamComponent ec in ecl1.m_list)
            {
                ExamLinkComponent_List elcl1 = new ExamLinkComponent_List();
                elcl1.LoadList_Component(ec.m_ComponentID);
                foreach (ExamLinkComponent elc in elcl1.m_list)
                {
                    ExamEntries_List exl1 = new ExamEntries_List();
                    //now need all entries for this option.....
                    exl1.Load_Option(elc.m_OptionId);
                    n += exl1.m_list.Count;
                }
            }

            int n1 = 0; int n2 = 0;

            foreach (ExamComponent ec in ecl1.m_list)
            {
                if (ec.m_Timetabled == "T")
                {
                    d1 = ec.m_TimetableDate;
                    if (ec.m_TimetableSession == "A")
                    {
                        d1 = d1.AddHours(8); d1 = d1.AddMinutes(50);
                    }
                    else
                    {
                        d1 = d1.AddHours(13); d1 = d1.AddMinutes(40);
                    }
                    //need to find all entries that use this component.....
                    ExamLinkComponent_List elcl1 = new ExamLinkComponent_List();
                    elcl1.LoadList_Component(ec.m_ComponentID);
                    foreach (ExamLinkComponent elc in elcl1.m_list)
                    {
                        ExamEntries_List exl1 = new ExamEntries_List();
                        //now need all entries for this option.....
                        exl1.Load_Option(elc.m_OptionId);
                        foreach (Exam_Entry ex in exl1.m_list)
                        {
                            if (!ex.m_withdrawn)
                            {
                                sched1.Load(ec.m_ComponentID, ex.m_StudentID);
                                if (!sched1.m_valid)
                                {
                                    sched1.m_StudentId   = ex.m_StudentID;
                                    sched1.m_ComponentId = ec.m_ComponentID;
                                    sched1.m_RoomId      = Guid.Empty;
                                    sched1.m_Year        = Year.ToString();
                                    sched1.m_Season      = u.GetSeasonCode(SeasonCode);
                                    sched1.m_valid       = true;
                                    sched1.m_Date        = d1;
                                    sched1.m_Desk        = "";
                                    sched1.m_Will_Type   = false;// do these later...
                                    sched1.Save();
                                    n2++;
                                }
                            }
                            else
                            {
                                sched1.Load(ec.m_ComponentID, ex.m_StudentID);
                                if (sched1.m_valid)
                                {
                                    //need to delete
                                    sched1.Delete();
                                    n1++;
                                }
                            }
                        }
                    }
                }
            }


            //now ought to update the willtype fields to agree with the cantype entry..
            //oohhh this is going to be messy.....
            //read from a querry..... then update Exams_Scheduled_components...

            CanTypeList typists = new CanTypeList();

            foreach (Guid g in typists.m_List)
            {
                s = "UPDATE dbo.tbl_Exams_ScheduledComponents SET WillType =1 WHERE (StudentId = '" + g.ToString() + "'  )AND (Year='" + YearCode.ToString() + "' ) AND (Season ='" + u.GetSeasonCode(SeasonCode) + "' )";
                en.ExecuteSQL(s);
            }
        }
        protected bool AllocateDesksRoom(Guid roomid, DateTime t1, DateTime t2, ref string ErrorS)
        {
            ScheduledComponentList scl2 = new ScheduledComponentList();

            scl2.LoadList_Room(t1, t2, roomid, " ORDER BY DateTime ASC, TimeAllowed DESC, ComponentId DESC, StudentExamNumber ASC");
            if (scl2.m_List.Count == 0)
            {
                return(true);
            }
            ExamRoom               exr1 = new ExamRoom(); exr1.Load(roomid);
            SimpleRoom             room1 = new SimpleRoom(); room1.Load(roomid.ToString());
            ScheduledComponentList scl3 = new ScheduledComponentList();//used to check room empty below
            string             s = ""; bool found = false;
            int                column = 1; int desk = 1; int desk_inc = 1;
            DateTime           time_last     = new DateTime(2000, 1, 1);
            DateTime           time_first    = new DateTime(2000, 1, 1);
            bool               room_full     = false;
            int                no_components = 1;
            ScheduledComponent scX           = new ScheduledComponent();

            scX = (ScheduledComponent)scl2.m_List[0];
            foreach (ScheduledComponent sc in scl2.m_List)
            {
                if (scX.m_ComponentId != sc.m_ComponentId)
                {
                    scX = sc; no_components++;
                }
            }

            int Free_space_min = (exr1.m_capacity - scl2.m_List.Count) / no_components;

            //when we enter no deska allocated to this room so exr1.m_capacity is capacity
            //if we have n students and m components and (capacity -n)> m then we can try to insert gaps...
            // n< scl2.count ( might have later components...


            scX = (ScheduledComponent)scl2.m_List[0];
            foreach (ScheduledComponent sc in scl2.m_List)
            {
                if (scX.m_ComponentId != sc.m_ComponentId)
                {
                    //new component...
                    scX = sc;
                    //if space insert blamk row
                    if ((exr1.columns[column].count < Free_space_min) && (CheckBox1.Checked))
                    {
                        desk = 1; column++; column++;
                    }
                }
                if ((sc.m_Date > time_last) && ((column != 1) || (desk != 1)))
                {
                    scl3.LoadList_Room(sc.m_Date.AddMinutes(-10), sc.m_Date, roomid, "");
                    if (scl3.m_List.Count == 0)
                    {
                        //DialogResult d = MessageBox.Show("It looks as if we can reset the desk alocations at " + sc.m_Date.ToShortTimeString() + ". Are you sure you wna to do this... ie do we have two separate internal exmas in the same session?", "Warning while rooming " + room1.m_roomcode, MessageBoxButtons.YesNo);
                        //if (d == DialogResult.Yes)
                        {
                            column     = 1; desk = 1; desk_inc = 1;
                            time_last  = sc.m_Date.AddMinutes(sc.m_TimeAllowed);
                            time_first = sc.m_Date.AddMinutes(-1);
                        }
                    }
                }

                if (sc.m_Date.AddMinutes(sc.m_TimeAllowed) > time_last)
                {
                    time_last = sc.m_Date.AddMinutes(sc.m_TimeAllowed);
                }

                //assign the lad a desk.....
                //unless he already has one!!!!

                found = false;
                s     = exr1.columns[column].name + desk.ToString();
                foreach (ScheduledComponent sc1 in scl2.m_List)
                {
                    if ((sc1.m_StudentId == sc.m_StudentId) && (sc1.m_Date > time_first))
                    {
                        if (sc1.m_Desk != "")
                        {
                            s = sc1.m_Desk; found = true; break;//he already had  one
                        }
                    }
                }

                sc.m_Desk = s;
                if (!found)
                {//we have added one....
                    if (room_full)
                    {
                        ErrorS = "Room capacity exceeded....." + sc.m_ExamNumber.ToString() + ":" + sc.m_Surname + " " + sc.m_Givenname + "..." + sc.m_ComponentTitle;
                        return(false);
                    }
                    desk = desk + desk_inc;
                    if (desk > exr1.columns[column].count)
                    {
                        column++;
                        desk     = exr1.columns[column].count;
                        desk_inc = desk_inc * (-1);
                    }
                    if (desk < 1)
                    {
                        desk_inc = desk_inc * (-1);
                        desk     = 1;
                        column++;
                    }
                }
                sc.Save();
                //check if we have exceeded capacity!
                if (column > exr1.no_columns + 1)
                {
                    room_full = true;
                }
            }
            return(true);
        }