Exemplo n.º 1
0
        private bool GoToNextChange(ref DateTime t0, ScheduledComponentList scl1, Guid RoomId)
        {
            //find next time ... returns in t0
            DateTime t3    = new DateTime(3000, 1, 1);//before this...
            bool     found = false;

            //now go through our list and find next change time....

            foreach (ScheduledComponent sc in scl1.m_List)
            {
                //if ((RoomId == sc.m_RoomId)||((RoomId==Guid.Empty)&&sc.m_RoomId==null))
                {
                    if ((sc.m_Date > t0) || (sc.m_Date.AddMinutes(sc.m_TimeAllowed) > t0))
                    {
                        if (sc.m_Date.AddMinutes(sc.m_TimeAllowed) < t3)
                        {
                            t3 = sc.m_Date.AddMinutes(sc.m_TimeAllowed); found = true;
                        }
                        if ((sc.m_Date < t3) && (sc.m_Date > t0))
                        {
                            t3 = sc.m_Date; found = true;
                        }
                    }
                }
            }
            if (found)
            {
                t0 = t3.AddMinutes(1);
                return(true);
            }
            return(false);
        }
        protected void ButtonNewStartTime_Click(object sender, EventArgs e)
        {
            DateTime t0 = new DateTime(); DateTime t1 = new DateTime();

            t0 = System.Convert.ToDateTime(Label_EditTime.Text);//recover the current start time
            try
            {
                t1 = System.Convert.ToDateTime(TextBox_NewStartTime.Text);//recover the new time
                ScheduledComponentList scl1 = new ScheduledComponentList();
                scl1.LoadList(t0.AddMinutes(-1), t0.AddMinutes(1), Label_EditComponentID.Text);
                foreach (ScheduledComponent sc in scl1.m_List)
                {
                    sc.m_Date = t1; sc.Save();
                }
                TextBox_NewStartTime.BackColor = System.Drawing.Color.White;
                VisibiltiyNewStartTime(false);
                t1 = (DateTime)ViewState["EditDate"];
                Encode en = new Encode();
                SqlDataSource1.SelectCommand    = GetQueryStringDay(Year, t0.Month, t0.Day, " ORDER BY DateTime");
                SqlDataSource1.ConnectionString = en.GetDbConnection();
                SqlDataSource1.DataBind();
            }
            catch
            {
                TextBox_NewStartTime.BackColor = System.Drawing.Color.Red;
            }
        }
Exemplo n.º 3
0
 protected void GridView1_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
 {
     if (e.CommandName == "EditDay")
     {
         int                    index = Convert.ToInt32(e.CommandArgument);
         GridViewRow            row   = GridView1.Rows[index];
         string                 s     = row.Cells[1].Text;
         DateTime               t1    = new DateTime(); t1 = Convert.ToDateTime(s);
         DateTime               t2    = new DateTime(t1.Year, t1.Month, t1.Day);
         DateTime               t3    = t2.AddHours(20);
         ScheduledComponentList scl1  = new ScheduledComponentList();
         scl1.LoadList_orderbyStudentDate(t2, t3);
         s = row.Cells[1].Text;
     }
 }
Exemplo n.º 4
0
        protected void SetUp(DateTime t1, DateTime t2, bool Is_AM)
        {
            DateTime t3 = new DateTime();
            ScheduledComponentList scl1 = new ScheduledComponentList();

            scl1.LoadList_Date(t1, t2);//order by  DateTime
            t3 = new DateTime(2000, 1, 1); int nmax = 0; int n = 0;
            Guid st1 = new Guid(); st1 = Guid.Empty;

            foreach (ScheduledComponent sc in scl1.m_List)
            {
                if (t3 != sc.m_Date)
                {
                    t3   = sc.m_Date;
                    nmax = (n > nmax) ? n : nmax;
                    n    = 0;
                }
                n++;
            }
            nmax = (n > nmax) ? n : nmax;
            //so max kids nmax //offer rooms

            Label_RoomsAllcation.Text     = "Allocated: 0    Needed: " + nmax.ToString();
            ViewState["MaxDesksRequired"] = nmax;
            //setup list box
            ListBox_Rooms.Items.Clear();
            string s = "SELECT DISTINCT  dbo.tbl_Core_Rooms.RoomId AS Id, dbo.tbl_Core_Rooms.RoomCode AS Name ";

            s += " FROM  dbo.tbl_Core_Rooms INNER JOIN dbo.tbl_Exams_RoomLayouts ON dbo.tbl_Core_Rooms.RoomId = dbo.tbl_Exams_RoomLayouts.RoomId ";
            s += " ORDER BY dbo.tbl_Core_Rooms.RoomCode ";
            Encode en = new Encode();

            SqlDataSource2.SelectCommand    = s;
            SqlDataSource2.ConnectionString = en.GetDbConnection();
            SqlDataSource2.DataBind();

            foreach (ListItem l in ListBox_Rooms.Items)
            {
                if (l.Text == "HAL")
                {
                    s = s;
                }
            }

            SetupRulesBoxesSources(t1, t2, Is_AM);
        }
Exemplo n.º 5
0
        protected void Button_AssignDesks_Click(object sender, EventArgs e)
        {
            string ErrorS = "Success!";

            bool     Is_AM = true;
            DateTime t0    = new DateTime();

            Is_AM = (bool)ViewState["Session_is_AM"];
            t0    = (DateTime)ViewState["EditDate"];
            DateTime t1 = new DateTime();
            DateTime t2 = new DateTime();

            t1 = (Is_AM) ? t0.AddHours(8) : t0.AddHours(13);
            t2 = (Is_AM) ? t0.AddHours(13) : t0.AddHours(18);
            //going to assign desks for this session
            //first clear all desks.....
            ExamsUtility u = new ExamsUtility();

            u.ClearDeskAssignments(t1, t2);

            ScheduledComponentList scl1 = new ScheduledComponentList();

            scl1.LoadList_orderbyRoom(t1, t2);

            Guid room1 = new Guid(); room1 = Guid.Empty;

            foreach (ScheduledComponent sc in scl1.m_List)
            {
                if (sc.m_RoomId != room1)
                {
                    if (!AllocateDesksRoom(sc.m_RoomId, t1, t2, ref ErrorS))
                    {
                        Label_message.Text    = ErrorS;
                        Label_message.Visible = true;
                        return;
                    }
                    room1 = sc.m_RoomId;
                }
            }
            scl1.LoadList(t1, t2);
            UpdateDeskGrid();
        }
Exemplo n.º 6
0
        public bool AreClashes(DateTime t1, DateTime t2)
        {
            DateTime t0 = new DateTime(); t0 = t1;//remember start time
            ScheduledComponentList scl1 = new ScheduledComponentList();

            scl1.LoadList_orderbyStudentDateASC(t1, t2);//order by StudentId , DateTime, TimeAllowed DESC, ComponentCode ";

            Guid st1 = new Guid(); st1 = Guid.Empty;

            foreach (ScheduledComponent sc in scl1.m_List)
            {
                if (sc.m_StudentId != st1)
                {
                    st1 = sc.m_StudentId; t1 = t0;
                }
                if (sc.m_Date < t1)
                {
                    return(true);
                }
                t1 = sc.m_Date.AddMinutes(sc.m_TimeAllowed);//new end time
            }
            return(false);
        }
Exemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //going to try to get from iSAMS data
                iSAMSLoad(); return;

                Utility  u1 = new Utility();
                DateTime t1 = new DateTime();
                DateTime t0 = new DateTime();
                t0 = DateTime.Now;
                t1 = t0.AddMonths(6);
                t0 = t0.AddMonths(-1);
                //SO   in future and up to 1 month in the past
                //string season = u1.ThisSeason(t0);

                //season = "3";

                ArrayList m_list   = new ArrayList();
                Guid      PersonID = new Guid();
                PersonID = u1.GetPersonIdfromRequest(Request);


#if DEBUG
                PersonID = u1.GetPersonIDX(@"CHALLONERS\charles.manning");//development
#endif

                //check they have read the exams notice...

                //string y = t0.Year.ToString();
                //bool v = false;
                //WarningNoticeRead w = new WarningNoticeRead(u1.GetStudentId(PersonID), u1.ThisSeason(t0), y, ref v);
                //if (!v)
                //{
                //Server.Transfer("ExamWarnings.aspx");//go and make them read the notice...
                //}

                PupilDetails p1 = new PupilDetails(u1.GetStudentId(PersonID).ToString());
                {
                    string s0 = "";
                    string s  = "PersonImagePage.aspx?id=" + p1.m_PersonId.ToString();
                    s  = "\"" + s;
                    s += "\" width = \"110\" height=\"140\"";
                    s  = "<FONT FACE = \"Arial\"><p align=\"center\"> <img src=" + s + "></p>";
                    s += "<p align=\"center\">This page should be printed and brought to all exams</p>";
                    {
                        s += "<center><h2>Exam Timetable for " + p1.m_GivenName + "  " + p1.m_Surname + "</h2></center>";
                        StudentSENList sen1 = new StudentSENList(p1.m_StudentId.ToString()); s0 = "";
                        foreach (StudentSEN s1 in sen1.m_List)
                        {
                            if (s1.m_ExamsExtraTime > 0)
                            {
                                s0 += "Extra Time (" + s1.m_ExamsExtraTime.ToString() + "%)  ";
                            }
                            if (s1.m_ExamsCanType)
                            {
                                s0 += " Can Type(Please report to IT4 for any exam where you wish to type)";
                            }
                        }
                        if (s0 != "")
                        {
                            s += "<center><h3>" + s0 + "</h3></center>";
                        }
                        ScheduledComponentList scl1 = new ScheduledComponentList();
                        t0 = t0.AddMonths(-3);
                        scl1.LoadList_Student(t0, t1, p1.m_StudentId.ToString());
                        SimpleRoom room1 = new SimpleRoom();
                        s += "<BR><center><TABLE BORDER><TR>";
                        s += "<Th>Date</Th>";
                        s += "<Th>Day</Th>";
                        s += "<Th>Start Time</Th>";
                        s += "<Th>End Time</Th>";
                        s += "<Th>Paper Code</Th>";
                        s += "<Th>Paper Name</Th>";
                        s += "<Th>Room</Th>";
                        s += "<Th>Desk</Th></TR>";
                        foreach (ScheduledComponent sc in scl1.m_List)
                        {
                            s += "<TR><TD>" + sc.m_Date.ToShortDateString() + "</TD>";
                            s += "<TD>" + sc.m_Date.DayOfWeek.ToString() + "</TD>";
                            t1 = sc.m_Date;
                            s += "<TD>" + sc.m_Date.ToShortTimeString() + "</TD>";
                            t1 = t1.AddMinutes(sc.m_TimeAllowed);
                            s += "<TD>" + t1.ToShortTimeString() + "</TD>";
                            s += "<TD>" + sc.m_ComponentCode + "</TD>";
                            s += "<TD>" + sc.m_ComponentTitle.ToLower() + "</TD>";
                            if (sc.m_RoomId != Guid.Empty)
                            {
                                room1.Load(sc.m_RoomId.ToString());
                                s += "<TD>" + room1.m_roomcode + "</TD>";
                            }
                            else
                            {
                                s += "<TD>not yet assigned</TD>";
                            }

                            s += "<TD>" + sc.m_Desk + "</TD></TR>";
                        }
                        s += "</TABLE></center>";
                    }
                    s += "<br><center><h3>Candidate Number = " + p1.m_examNo.ToString() + " , UCI=" + p1.m_UCI + "</h3></center></Font>";
                    servercontent.InnerHtml = s;
                }
            }
        }
Exemplo n.º 8
0
        protected void Button_ShowTimetable_Click(object sender, EventArgs e)
        {
            GridView1.Visible = false;
            visibility(3);
            string       studentID = Label_StudentID.Text;
            PupilDetails p1        = new PupilDetails(studentID);
            {
                Utility  u1 = new Utility();
                DateTime t1 = new DateTime();
                DateTime t0 = new DateTime();
                t0 = DateTime.Now;
                t1 = t0.AddMonths(6);
                t0 = t0.AddMonths(-2);
                //string season = u1.ThisSeason(t0);
                ArrayList m_list = new ArrayList();

                string s = "PersonImagePage.aspx?id=" + p1.m_PersonId.ToString();
                s  = "\"" + s;
                s += "\" width = \"110\" height=\"140\"";
                Response.Write("<FONT FACE = \"Arial\"><p align=\"center\"> <img src=" + s + "></p>");
                {
                    Response.Write("<br><center><h2>Exam Timetable for " + p1.m_GivenName + "  " + p1.m_Surname + "</h2></center>");
                    StudentSENList sen1 = new StudentSENList(p1.m_StudentId.ToString()); s = "";
                    foreach (StudentSEN s1 in sen1.m_List)
                    {
                        if (s1.m_ExamsExtraTime > 0)
                        {
                            s += "Extra Time (" + s1.m_ExamsExtraTime.ToString() + "%)  ";
                        }
                        if (s1.m_ExamsCanType)
                        {
                            s += "  Can Type ";
                        }
                    }
                    if (s != "")
                    {
                        s = "<center><h3>" + s + "</h3></center>";
                        Response.Write(s);
                    }
                    ScheduledComponentList scl1 = new ScheduledComponentList();
                    scl1.LoadList_Student(t0, t1, studentID);
                    SimpleRoom room1 = new SimpleRoom();
                    Response.Write("<BR><p  align=\"center\" ><TABLE BORDER><TR>");
                    s = "Date"; Response.Write("<TD>" + s + "</TD>");
                    s = "Day"; Response.Write("<TD>" + s + "</TD>");
                    s = "Start Time"; Response.Write("<TD>" + s + "</TD>");
                    s = "End Time"; Response.Write("<TD>" + s + "</TD>");
                    s = "Paper Code"; Response.Write("<TD>" + s + "</TD>");
                    s = "Paper Name"; Response.Write("<TD>" + s + "</TD>");
                    s = "Room"; Response.Write("<TD>" + s + "</TD>");
                    s = "Desk"; Response.Write("<TD>" + s + "</TD>");
                    Response.Write("</TR>");
                    foreach (ScheduledComponent sc in scl1.m_List)
                    {
                        Response.Write("<TR>");
                        s  = sc.m_Date.ToShortDateString(); Response.Write("<TD>" + s + "</TD>");
                        s  = sc.m_Date.DayOfWeek.ToString(); Response.Write("<TD>" + s + "</TD>");
                        t1 = sc.m_Date;
                        s  = sc.m_Date.ToShortTimeString(); Response.Write("<TD>" + s + "</TD>");
                        t1 = t1.AddMinutes(sc.m_TimeAllowed);
                        s  = t1.ToShortTimeString(); Response.Write("<TD>" + s + "</TD>");
                        s  = sc.m_ComponentCode; Response.Write("<TD>" + s + "</TD>");
                        s  = sc.m_ComponentTitle.ToLower(); Response.Write("<TD>" + s + "</TD>");
                        if (sc.m_RoomId != Guid.Empty)
                        {
                            room1.Load(sc.m_RoomId.ToString());
                            s = room1.m_roomcode; Response.Write("<TD>" + s + "</TD>");
                        }
                        else
                        {
                            Response.Write("<TD>not yet assigned</TD>");
                        }

                        s = sc.m_Desk; Response.Write("<TD>" + s + "</TD>");
                        Response.Write("</TR>");
                    }
                    Response.Write("</TABLE>");
                }
                Response.Write("<br><center><h3>Candidate Number = " + p1.m_examNo.ToString() + " , UCI=" + p1.m_UCI + "</h3></center></Font>");
            }
        }
        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;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
        protected void CheckClashes_Click(object sender, EventArgs e)
        {
            string[] data = (string[])ViewState["data"];
            int      nmax = (int)ViewState["nmax"]; int nmin = (int)ViewState["nmin"];
            int      i  = (int)ViewState["EditIndex"];
            DateTime t0 = new DateTime();

            t0 = (DateTime)ViewState["EditDate"];
            string s = data[i]; char[] c1 = new char[1]; c1[0] = (char)0x09;

            DateTime t1           = new DateTime(); t1 = t0.AddHours(8).AddMinutes(49);  //start at 8:40
            DateTime t2           = new DateTime(); t2 = t0.AddHours(18).AddMinutes(39); //end at 18:39
            DateTime AMSessionEnd = new DateTime(); AMSessionEnd = t0.AddMinutes(30).AddHours(12);
            DateTime PMSessionEnd = new DateTime(); PMSessionEnd = t0.AddMinutes(51).AddHours(16);

            ScheduledComponentList scl1 = new ScheduledComponentList();

            scl1.LoadList_orderbyStudentDateASC(t1, t2);//order by StudentId , DateTime, TimeAllowed DESC, ComponentCode ";

            Guid st1 = new Guid(); st1 = Guid.Empty; bool AM = true;

            foreach (ScheduledComponent sc in scl1.m_List)
            {
                AM = (sc.m_TimetabledSession == "A");
                if (sc.m_StudentId != st1)//new student so reset to start of day...
                {
                    st1 = sc.m_StudentId; t1 = t0;
                }
                //if this component starts before previous has " we have a clash
                if (sc.m_Date < t1)
                {
                    //clash....  need to move this component
                    //is there time in the session? it will now end at t1 +10 +time allowed

                    if (((t1.AddMinutes(sc.m_TimeAllowed).AddMinutes(10) < AMSessionEnd) && AM) || ((t1.AddMinutes(sc.m_TimeAllowed).AddMinutes(10) < PMSessionEnd) && !AM))
                    {//simple add...
                        sc.m_Date = t1.AddMinutes(10);
                        sc.Save();
                        //move time on
                        t1 = sc.m_Date.AddMinutes(sc.m_TimeAllowed);//new end time
                    }
                    else
                    {
                        //so can't move within session.....need to find next free session......
                        //going to reload list
                        ScheduledComponentList scl2 = new ScheduledComponentList();

                        //list is ordered by date asc
                        //if ours is PM... is there space AM... if ours is AM is there space PM???
                        if (AM)
                        {
                            scl2.LoadList_Student(t0.AddHours(13), t0.AddHours(23), sc.m_StudentId.ToString());
                            if (scl2.m_List.Count == 0)
                            {
                                //we can move it to PM
                                sc.m_Date = t0.AddHours(13).AddMinutes(40); sc.Save();
                                //need to add supervision....
                                AddSupervision(t1, sc.m_Date, sc);
                            }
                            else
                            {
                                //going to count hours pm...
                                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(t1, t0.AddHours(13).AddMinutes(40), sc);
                                    //so can fit it in.....but ought to put at end???
                                }
                                else
                                {
                                    FindNextSlot(sc, t3);
                                }
                            }
                        }
                        else
                        {
                            //pm exam try to fit in am
                            scl2.LoadList_Student(t0, t0.AddHours(13), sc.m_StudentId.ToString());///am list
                            if (scl2.m_List.Count == 0)
                            {
                                //we can move it to AM
                                sc.m_Date = t0.AddHours(8).AddMinutes(50);
                                sc.Save();
                                //need to add supervision....
                                AddSupervision(sc.m_Date.AddMinutes(sc.m_TimeAllowed + 1), t0.AddHours(13).AddMinutes(40), sc);
                            }
                            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(sc.m_Date, t0.AddHours(13).AddMinutes(40), sc);
                                    //so can fit it in.....but ought to put at end???
                                }
                                else
                                {
                                    //so no slots in am... need to go to next day...find time of last exam...
                                    scl2.LoadList_Student(t0.AddHours(13), t0.AddHours(23), sc.m_StudentId.ToString());
                                    foreach (ScheduledComponent sc1 in scl2.m_List)
                                    {
                                        t3 = sc1.m_Date.AddMinutes(sc1.m_TimeAllowed + 10);
                                    }
                                    FindNextSlot(sc, t3);
                                }
                            }
                        }
                    }
                }
                else
                {
                    //no clash.. all is good
                    t1 = sc.m_Date.AddMinutes(sc.m_TimeAllowed);//new end time
                }
            }
            UpdateButtons(t0);
        }
Exemplo n.º 11
0
        private void SetupDeskGrid(DateTime t1, DateTime t2)
        {
            System.Drawing.Color[] cell_colours = GetColors();

            Label_DeskDate.Text = t1.ToLongDateString();
            //setup dropdown list of rooms...
            List <Guid> Rooms = new List <Guid>();


            //need to load all rooms used...


            string s = "SELECT DISTINCT RoomId FROM  dbo.tbl_Exams_ScheduledComponents ";

            s += " WHERE (DateTime > CONVERT(DATETIME,'" + t1.ToString("yyyy-MM-dd HH:mm:ss") + "',102) ) ";
            s += " AND (DateTime < CONVERT(DATETIME,'" + t2.ToString("yyyy-MM-dd HH:mm:ss") + "',102) ) ";
            Encode en = new Encode();

            using (SqlConnection cn = new SqlConnection(en.GetDbConnection()))
            {
                cn.Open();
                using (SqlCommand cm = new SqlCommand(s, cn))
                {
                    using (SqlDataReader dr = cm.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (dr.IsDBNull(0))
                            {
                                Rooms.Add(Guid.Empty);
                            }
                            else
                            {
                                Rooms.Add(dr.GetGuid(0));
                            }
                        }
                        dr.Close();
                    }
                }
                cn.Close();
            }

            if ((Rooms.Count == 1) && (Rooms[0] == Guid.Empty))
            {
                Label_message.Text    = " No Rooms Allocated...";
                Label_message.Visible = true;
            }

            DropDownListDeskRooms.Items.Clear();
            SimpleRoom r1 = new SimpleRoom();

            foreach (Guid d in Rooms)
            {
                r1.Load(d.ToString());
                ListItem l = new ListItem(r1.m_roomcode, d.ToString());
                DropDownListDeskRooms.Items.Add(l);
            }


            //need to find all the changes...
            DateTime t0 = new DateTime(); t0 = t1;
            ScheduledComponentList scl1 = new ScheduledComponentList(); scl1.LoadList_Date(t1, t2);

            while (GoToNextChange(ref t0, scl1, Rooms[0]))
            {
                ListItem l = new ListItem(t0.AddMinutes(-1).ToShortTimeString(), t0.ToString());
                DropDownListDeskTimes.Items.Add(l);
            }

            UpdateDeskGrid();
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        private void UpdateDeskGrid()
        {
            DateTime t1 = System.Convert.ToDateTime(DropDownListDeskTimes.SelectedValue);
            string   s1 = "";

            string   dateS = Request.QueryString["Date"];
            DateTime t0    = new DateTime();
            string   sess  = Request.QueryString["Session"];
            bool     Is_AM = true;

            try
            {
                t0 = Convert.ToDateTime(Request.QueryString["Date"]);
                if (sess.Contains("PM"))
                {
                    Is_AM = false;
                }
                ViewState["Session_is_AM"] = Is_AM;
                ViewState["EditDate"]      = t0;
            }
            catch
            {
                //try to get from session state?
                Is_AM = (bool)ViewState["Session_is_AM"];
                t0    = (DateTime)ViewState["EditDate"];
            }
            DateTime t2 = new DateTime();

            t2 = (Is_AM) ? t0.AddHours(13) : t0.AddHours(18);

            System.Drawing.Color[] cell_colours = GetColors();

            Guid[] papers = new Guid[10]; string[] paper_title = new string[10];
            string s         = "";
            int    no_papers = 0;
            bool   found     = false;

            Label_DeskDate.Text = t1.ToLongDateString();



            ScheduledComponentList scl2 = new ScheduledComponentList(); scl2.LoadList(t0, t2);

            scl2.LoadList_orderbyComponent(t0, t2);
            //need to restrict to those current
            ScheduledComponentList scl1 = new ScheduledComponentList();

            foreach (ScheduledComponent sc in scl2.m_List)
            {
                if (sc.m_Date.AddMinutes(sc.m_TimeAllowed) > t1)
                {
                    scl1.m_List.Add(sc);
                }
            }


            t0 = System.Convert.ToDateTime(DropDownListDeskTimes.SelectedValue);

            TableDeskView.Rows.Clear();

            Guid Current_Room = new Guid();

            Current_Room = new Guid(DropDownListDeskRooms.SelectedValue);
            if (Current_Room == Guid.Empty)
            {
                return;
            }
            ExamRoom exr1 = new ExamRoom(); exr1.Load(Current_Room);
            int      nrows = 0; int ncols = 0;

            foreach (ExamColumn ec in exr1.columns)
            {
                if (ec.count > nrows)
                {
                    nrows = ec.count;
                }
            }
            TableDeskView.CssClass = "EventsTable";
            TableRow r0 = new TableRow();

            TableDeskView.Rows.Add(r0);
            TableCell c3 = new TableCell(); r0.Cells.Add(c3); ncols++;

            foreach (ExamColumn ec in exr1.columns)
            {
                if (ec.count > 0)
                {
                    TableCell c = new TableCell();
                    c.Width = 40; c.Text = ec.name;//header row
                    r0.Cells.Add(c); ncols++;
                }
            }
            TableCell c4 = new TableCell(); r0.Cells.Add(c4);
            TableCell c2 = new TableCell();

            r0.Cells.Add(c2);
            c2.Text  = "Colour Code for Papers";
            c2.Width = 200;

            //for (int i = 0; i < nrows; i++)
            for (int i = nrows - 1; i > -1; i--)
            {
                TableRow r = new TableRow();
                TableDeskView.Rows.Add(r);

                TableCell c1 = new TableCell(); c1.Text = (i + 1).ToString(); r.Cells.Add(c1);
                c1.Width = 40; c1.BackColor = System.Drawing.Color.LightGray;
                foreach (ExamColumn ec in exr1.columns)
                {
                    if (ec.count > 0)
                    {
                        TableCell c = new TableCell();
                        c.Width = 40; c.Text = "";
                        r.Cells.Add(c);
                    }
                }
                TableCell c5 = new TableCell(); r.Cells.Add(c5); c5.Width = 40;
                TableCell c6 = new TableCell(); r.Cells.Add(c6); c6.Width = 40;
            }
            t0 = t0.AddMinutes(2);

            try
            {
                s1 = TableDeskView.Rows[1].Cells[1].Text;
            }
            catch { }

            foreach (ScheduledComponent sc in scl1.m_List)
            {
                if ((Current_Room == sc.m_RoomId))
                {
                    if ((sc.m_Date < t0) && (sc.m_Date.AddMinutes(sc.m_TimeAllowed) > t0))
                    {
                        s = sc.m_Desk;

                        if ((s != "") && (s != null))
                        {
                            int col = 0;
                            foreach (TableCell tc in TableDeskView.Rows[0].Cells)
                            {
                                if (tc.Text == s.Substring(0, 1))
                                {
                                    col = TableDeskView.Rows[0].Cells.GetCellIndex(tc);
                                    break;
                                }
                            }
                            int row = System.Convert.ToInt32(s.Substring(1));
                            row = nrows + 1 - row;

                            TableDeskView.Rows[row].Cells[col].Text = sc.m_ExamNumber.ToString();


                            found = false;
                            for (int i = 0; i < no_papers; i++)
                            {
                                if (papers[i] == sc.m_ComponentId)
                                {
                                    found = true;
                                    TableDeskView.Rows[row].Cells[col].BackColor = cell_colours[i];
                                }
                            }
                            if (!found)
                            {
                                no_papers++;
                                papers[no_papers - 1] = sc.m_ComponentId;
                                TableDeskView.Rows[row].Cells[col].BackColor = cell_colours[no_papers - 1];
                                paper_title[no_papers - 1] = sc.m_ComponentCode + ":" + sc.m_ComponentTitle;
                            }
                        }
                    }
                }
            }



            for (int i = 0; i < no_papers; i++)
            {
                TableDeskView.Rows[i + 1].Cells[ncols + 1].Text      = paper_title[i];
                TableDeskView.Rows[i + 1].Cells[ncols + 1].BackColor = cell_colours[i];
            }
        }
Exemplo n.º 14
0
        protected bool Apply_Rule(string rule, Guid rule_roomId, ScheduledComponentList scl1, ref string ErrorS, List <Guid> Components, List <int> number, ref int RoomCapacity)
        {
            int      n  = 0;
            ExamRoom er = new ExamRoom();

            switch (rule)
            {
            case "None": break;

            case "ExtraTime":
                n = 0;
                ExamComponent ec1 = new ExamComponent(); int time1 = 0;
                foreach (ScheduledComponent c in scl1.m_List)
                {
                    ec1.Load(c.m_ComponentId); time1 = Convert.ToInt32(ec1.m_Time);
                    if ((c.m_TimeAllowed > time1) && (c.m_RoomId == Guid.Empty))
                    {
                        n++;
                    }
                }
                er.Load(rule_roomId);
                if (n > er.m_capacity)
                {
                    ErrorS = "Rule" + rule + " Exceeds capacity in" + DropDownList_Rule1Room.Text; return(false);
                }
                foreach (ScheduledComponent c in scl1.m_List)
                {
                    ec1.Load(c.m_ComponentId); time1 = Convert.ToInt32(ec1.m_Time);
                    if ((c.m_TimeAllowed > time1) && (c.m_RoomId == Guid.Empty))
                    {
                        c.m_RoomId  = rule_roomId;
                        c.Save(); n = 0; RoomCapacity--;
                        foreach (Guid d in Components)
                        {
                            if (d == c.m_ComponentId)
                            {
                                number[n]--;
                            }
                            n++;
                        }
                    }
                }
                break;

            case "Typists":
                n = 0;
                foreach (ScheduledComponent c in scl1.m_List)
                {
                    if ((c.m_Will_Type) && (c.m_RoomId == Guid.Empty))
                    {
                        n++;
                    }
                }
                er.Load(rule_roomId);
                if (n > er.m_capacity)
                {
                    ErrorS = "Rule" + rule + " Exceeds capacity in" + DropDownList_Rule1Room.Text; return(false);
                }
                foreach (ScheduledComponent c in scl1.m_List)
                {
                    if ((c.m_Will_Type) && (c.m_RoomId == Guid.Empty))
                    {
                        c.m_RoomId  = rule_roomId;
                        c.Save(); n = 0; RoomCapacity--;
                        foreach (Guid d in Components)
                        {
                            if (d == c.m_ComponentId)
                            {
                                number[n]--;
                            }
                            n++;
                        }
                    }
                }
                break;

            default:
                //it is a rule based on a component
                foreach (ScheduledComponent c in scl1.m_List)
                {
                    if ((c.m_ComponentCode == rule) && (c.m_RoomId == Guid.Empty))
                    {
                        n++;
                    }
                }
                er.Load(rule_roomId);
                if (n > er.m_capacity)
                {
                    ErrorS = "Rule" + rule + " Exceeds capacity in" + DropDownList_Rule1Room.Text; return(false);
                }
                foreach (ScheduledComponent c in scl1.m_List)
                {
                    if ((c.m_ComponentCode == rule) && (c.m_RoomId == Guid.Empty))
                    {
                        c.m_RoomId  = rule_roomId;
                        c.Save(); n = 0; RoomCapacity--;
                        foreach (Guid d in Components)
                        {
                            if (d == c.m_ComponentId)
                            {
                                number[n]--;
                            }
                            n++;
                        }
                    }
                }
                break;
            }
            ErrorS += "Success_Rule1";
            return(true);
        }
Exemplo n.º 15
0
        protected void Button_Assign_Click(object sender, EventArgs e)
        {
            //now we are actually going to do it???

            string   ErrorS = "Success!";
            bool     Is_AM  = (bool)ViewState["Session_is_AM"];
            DateTime t0     = new DateTime();

            t0 = (DateTime)ViewState["EditDate"];
            DateTime t1 = new DateTime();
            DateTime t2 = new DateTime();

            t1 = (Is_AM) ? t0.AddHours(8) : t0.AddHours(13);
            t2 = (Is_AM) ? t0.AddHours(13) : t0.AddHours(18);
            DateTime time_last = new DateTime();



            List <Guid> Rooms = new List <Guid>();
            ListBox     lb    = ListBox_Rooms;

            foreach (ListItem l in lb.Items)
            {
                if (l.Selected)
                {
                    Rooms.Add(new Guid(l.Value));
                }
            }

            //if no rooms allocated flag error
            if (Rooms.Count == 0)
            {
                ErrorS = "...you haven't allocated Any rooms";
                goto ErrorExit;
            }


            ExamsUtility eu = new ExamsUtility();

            eu.ClearDeskAssignments(t1, t2);

            //ought to clear all room allocations first...
            //ought to do this by query
            int          n = 0;
            ExamsUtility u = new ExamsUtility();

            u.ClearRoomAssignments(t1, t2);

            ExamRoom er = new ExamRoom();

            n = 0;
            List <int> Room_Capacity = new List <int>();

            foreach (Guid d in Rooms)
            {
                er.Load(d);
                Room_Capacity.Add(er.m_capacity);
                n++;
            }
            int nmax = n - 1;

            ScheduledComponentList scl1 = new ScheduledComponentList();

            scl1.LoadList_Date(t1, t2);                              //order by  DateTime
            time_last = ((ScheduledComponent)scl1.m_List[0]).m_Date;
            string s = GetQueryStringDay(t0.Year, t0.Month, t0.Day); // gets from sc ordered by datetime,NUMBER

            List <Guid>     Components    = new List <Guid>();
            List <int>      number        = new List <int>();
            List <DateTime> Start_Time    = new List <DateTime>();
            Encode          en            = new Encode();
            string          db_connection = en.GetDbConnection();

            using (SqlConnection cn = new SqlConnection(db_connection))
            {
                cn.Open();
                using (SqlCommand cm = new SqlCommand(s, cn))
                {
                    using (SqlDataReader dr = cm.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            Components.Add(dr.GetGuid(1));
                            number.Add(dr.GetInt32(4));
                            Start_Time.Add(dr.GetDateTime(3));
                        }
                        dr.Close();
                    }
                }
                cn.Close();
            }

            //first apply rules... hopefully these will fit ... if not flag error back to ui

            int CurrentRoomCapacity = 0;

            string s_rule      = DropDownList_Rule1Source.SelectedItem.Text;
            Guid   rule_roomId = new Guid(DropDownList_Rule1Room.SelectedValue);

            n = 0; foreach (Guid d in Rooms)
            {
                if (d == rule_roomId)
                {
                    CurrentRoomCapacity = Room_Capacity[n]; break;
                }
            }
            if (!Apply_Rule(s_rule, rule_roomId, scl1, ref ErrorS, Components, number, ref CurrentRoomCapacity))
            {
                goto ErrorExit;
            }
            Room_Capacity[n] = CurrentRoomCapacity;
            if ((s_rule != "None") && (CheckBox1.Checked))
            {
                Rooms.Remove(rule_roomId); nmax--;
            }


            s_rule      = DropDownList_Rule2Source.SelectedItem.Text;
            rule_roomId = new Guid(DropDownList_Rule2Room.SelectedValue);
            n           = 0; foreach (Guid d in Rooms)
            {
                if (d == rule_roomId)
                {
                    CurrentRoomCapacity = Room_Capacity[n]; break;
                }
            }
            if (!Apply_Rule(s_rule, rule_roomId, scl1, ref ErrorS, Components, number, ref CurrentRoomCapacity))
            {
                goto ErrorExit;
            }
            if ((s_rule != "None") && (CheckBox2.Checked))
            {
                Rooms.Remove(rule_roomId); nmax--;
            }
            Room_Capacity[n] = CurrentRoomCapacity;


            s_rule      = DropDownList_Rule3Source.SelectedItem.Text;
            rule_roomId = new Guid(DropDownList_Rule3Room.SelectedValue);
            n           = 0; foreach (Guid d in Rooms)
            {
                if (d == rule_roomId)
                {
                    CurrentRoomCapacity = Room_Capacity[n]; break;
                }
            }
            if (!Apply_Rule(s_rule, rule_roomId, scl1, ref ErrorS, Components, number, ref CurrentRoomCapacity))
            {
                goto ErrorExit;
            }
            if ((s_rule != "None") && (CheckBox3.Checked))
            {
                Rooms.Remove(rule_roomId); nmax--;
            }
            Room_Capacity[n] = CurrentRoomCapacity;



            s_rule      = DropDownList_Rule4Source.SelectedItem.Text;
            rule_roomId = new Guid(DropDownList_Rule4Room.SelectedValue);
            n           = 0; foreach (Guid d in Rooms)
            {
                if (d == rule_roomId)
                {
                    CurrentRoomCapacity = Room_Capacity[n]; break;
                }
            }
            if (!Apply_Rule(s_rule, rule_roomId, scl1, ref ErrorS, Components, number, ref CurrentRoomCapacity))
            {
                goto ErrorExit;
            }
            if ((s_rule != "None") && (CheckBox4.Checked))
            {
                Rooms.Remove(rule_roomId); nmax--;
            }
            Room_Capacity[n] = CurrentRoomCapacity;



            s_rule      = DropDownList_Rule5Source.SelectedItem.Text;
            rule_roomId = new Guid(DropDownList_Rule5Room.SelectedValue);
            n           = 0; foreach (Guid d in Rooms)
            {
                if (d == rule_roomId)
                {
                    CurrentRoomCapacity = Room_Capacity[n]; break;
                }
            }
            if (!Apply_Rule(s_rule, rule_roomId, scl1, ref ErrorS, Components, number, ref CurrentRoomCapacity))
            {
                goto ErrorExit;
            }
            if ((s_rule != "None") && (CheckBox5.Checked))
            {
                Rooms.Remove(rule_roomId); nmax--;
            }
            Room_Capacity[n] = CurrentRoomCapacity;


            ScheduledComponentList scl2 = new ScheduledComponentList();

            foreach (ScheduledComponent c in scl1.m_List)
            {
                if (c.m_RoomId == Guid.Empty)
                {
                    scl2.m_List.Add(c);
                }
            }

            //now we apply the rest
            //idea is we find the sc with most students.... and put into biggest room first
            //first correct room capacity?
            n = 0;
            // well i think we have all the information....
            //going to assign biggest exam to biggest room first

            int index = 0;

            foreach (Guid d in Components)
            {
                //so new component....
                //if there is a complete gap before we start this component we can clear room allocations....
                //find the first (earliest) scheduled component
                foreach (ScheduledComponent c in scl2.m_List)
                {
                    if (c.m_ComponentId == d)
                    {
                        if (c.m_RoomId == Guid.Empty)
                        {
                            if (c.m_Date > time_last.AddMinutes(10))
                            {
                                //so this one starts at least 10 minutes after all sofar have finished....
                                time_last = c.m_Date.AddMinutes(c.m_TimeAllowed);
                                //so can reset rooms..... ie back to full capacity?
                                Room_Capacity.Clear(); n = 0;
                                foreach (Guid d1 in Rooms)
                                {
                                    er.Load(d1);
                                    Room_Capacity.Add(er.m_capacity);
                                    n++;
                                }
                                nmax = n - 1;
                            }
                        }
                    }
                }

                n = 0;
                while ((Room_Capacity[n] == 0) && (n <= nmax))
                {
                    n++;
                }
                if (n > nmax)
                {
                    ErrorS = "Ran out of room capacity !!"; goto ErrorExit;
                }
                //going to check if next one will fit in any room we have available... if so use it!  search smallest first?
                for (int i = nmax; i >= 0; i--)
                {
                    if (Room_Capacity[i] >= number[index])
                    {
                        n = i; break;
                    }
                }
                foreach (ScheduledComponent c in scl2.m_List)
                {
                    if (c.m_ComponentId == d)
                    {
                        if (c.m_RoomId == Guid.Empty)
                        {
                            if (c.m_Date.AddMinutes(c.m_TimeAllowed) > time_last)
                            {
                                time_last = c.m_Date.AddMinutes(c.m_TimeAllowed);
                            }

                            //really ought to check to see if he has any other componets in this session and assign the same room/...

                            foreach (ScheduledComponent c1 in scl1.m_List)
                            {
                                if (c1.m_StudentId == c.m_StudentId)
                                {
                                    c.m_RoomId = c1.m_RoomId;
                                }
                            }
                            if (c.m_RoomId == Guid.Empty)
                            {
                                c.m_RoomId = Rooms[n];
                                Room_Capacity[n]--;
                            }

                            c.Save();



                            foreach (ScheduledComponent c1 in scl2.m_List)
                            {
                                if ((c1.m_StudentId == c.m_StudentId) && (c1.m_RoomId == Guid.Empty))
                                {
                                    c.m_RoomId = Rooms[n];
                                    c.Save();
                                    //Room_Capacity[n]--;   should already have cleared clashes
                                }
                            }
                        }
                    }
                    while ((Room_Capacity[n] == 0) && (n < nmax))
                    {
                        n++;
                    }
                    if (n > nmax)
                    {
                        ErrorS = "Ran out of room capacity !!"; goto ErrorExit;
                    }
                }
                index++;
            }
            //check??
            //success;  open the summary panel

            Panel_left1.Visible             = false; Panel_right1.Visible = false;
            Label_message.Text              = "Rooms Allocated Successfully.";
            Label_message.Visible           = true;
            SqlDataSource3.SelectCommand    = GetQueryStringRoomSummary(t1, t2, true);
            SqlDataSource3.ConnectionString = en.GetDbConnection();
            SqlDataSource3.DataBind();
            return;

            ErrorExit : Label_message.Text = ErrorS;
            Label_message.BackColor        = System.Drawing.Color.Red;
            return;
        }
Exemplo n.º 16
0
        public Guid Find_Component(string c_file, string component, string ExamBoard, string season, string year, bool forceupdate)
        {
            ExamComponent com1   = new ExamComponent();
            Guid          com1ID = new Guid(); com1ID = Guid.Empty;
            Stream        myStream;
            string        line        = "";
            int           JCQ_Version = 0;

            //try to find in db
            com1ID = com1.Find_ComponentID(component, ExamBoard, season, year);
            if ((com1ID != Guid.Empty) && !forceupdate)
            {
                return(com1ID);
            }
            //so not in db... find in c_file and make...
            try
            {
                if ((myStream = File.Open(c_file, FileMode.Open)) != null)
                {
                    using (StreamReader sr = new StreamReader(myStream))
                    {
                        ExamComponent examcom1 = new ExamComponent();
                        ExamComponent examcom2 = new ExamComponent();//used for forced update
                        while ((line = sr.ReadLine()) != null)
                        {
                            if (line.Substring(0, 2) == "C1")
                            {
                                JCQ_Version = System.Convert.ToInt32(line.Substring(24, 2));
                            }
                            if ((line.Substring(0, 2) == "C5") && (line.Substring(2, 12) == component))
                            {
                                examcom1.m_ComponentCode = component;
                                examcom1.LoadFromBaseData(line, JCQ_Version, ExamBoard);
                                examcom1.m_season = season; examcom1.m_year = year;
                                if (com1ID != Guid.Empty)
                                {
                                    // we are doing a forced update..... and already know the ID....
                                    examcom2.Load(com1ID);//has current db version.....
                                    //now if any significant changes need to delete current scheduled components...
                                    examcom1.m_ComponentID = com1ID;
                                    if (!examcom1.EqualTo(examcom2))
                                    {
                                        ScheduledComponentList scl1 = new ScheduledComponentList();
                                        scl1.LoadList(com1ID);
                                        foreach (ScheduledComponent sc1 in scl1.m_List)
                                        {
                                            sc1.Delete();
                                        }
                                    }
                                    examcom1.Save();
                                }
                                else
                                {
                                    examcom1.Create();
                                }
                                return(Find_Component("", component, ExamBoard, season, year, false));
                            }
                        }
                    }
                }
            }
            catch (Exception e1)
            {
                System.Windows.Forms.MessageBox.Show("Error writing the component file... " + e1.Message, "File Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
            }
            //not found - this could be a poblem
            System.Windows.Forms.MessageBox.Show("Warning.... Can't find a component: " + component, "Warning", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
            return(com1ID);
        }