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; } }
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(); }
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]; } }
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); }