protected void Page_Load(object sender, EventArgs e)
        {
            string s = Request.QueryString["Year"];

            //YearDisplay(); return;
#if DEBUG
            if (s != null)
            {
                YearDisplay(); return;
            }
#else
#endif
            s = Request.QueryString["Id"];
            StudentAccademicProfile StudentProfile = new StudentAccademicProfile(new Guid(s));
            SimplePupil             p = new SimplePupil(); int KeyStage = 0;
            DateTime date1 = new DateTime(); date1 = DateTime.Now;
            //this is when we load tt etc... so if in summer gap... alter
            if (date1.Month == 8)
            {
                date1 = date1.AddMonths(2);
            }
            StudentProfile.Load_Profile(date1, ref p, ref KeyStage, true);
            StudentIncidentList stinl = new StudentIncidentList();
            stinl.LoadListDate(StudentProfile.StudentId, DateTime.Now.AddMonths(-1), DateTime.Now);

            Double d = 0; int n = 0;
            //so now to display...
            // vary this with Key Stage...???
            string class1 = "";
            s  = "<h3>Academic Profile for " + p.m_GivenName + " " + p.m_Surname + "</h3><br />";
            s += "<table class=\"EventsTable\" > ";
            s += "<tr><th>Subject</th>";
            s += "<th>Current Grade</th>";
            //s += "<th>Prof Grade</th>";
            //s += "<th>Max grade</th>";
            s += "<th>Target Grade </th>";
            s += "<th>Commitment</th>";
            s += "<th>Last Internal Exam</th>";
            s += "<th>Year Average</th>";
            s += "<th>Year Position (percentile)</th>";
            s += "</tr>";
            double margin = 1;
            double xgrade = 20;
            double pgrade = 0;
            string Profile_approx = ""; string Target_approx = "";
            foreach (StudentSubjectProfile sp in StudentProfile.profile)
            {
                s     += "<tr><td>" + sp.course.CourseName + "</td>";
                pgrade = sp.PredictedGrade;
                pgrade = sp.Convert_to_scale(ref xgrade, ref d, ref Target_approx, ref Profile_approx);
                if (sp.latestProfileGrade != null)

                {
                    //pgrade = sp.Convert_to_scale(ref xgrade, ref d,ref Target_approx, ref Profile_approx);
                    margin = xgrade / 2;//half a grade
                    class1 = " class=\"tableHighlight3\"";
                    if ((pgrade - d) > margin)
                    {
                        class1 = " class=\"tableHighlight4\"";
                    }
                    if ((pgrade - d) > 2 * margin)
                    {
                        class1 = " class=\"tableHighlight5\"";
                    }
                    if ((d - pgrade) > margin)
                    {
                        class1 = " class=\"tableHighlight2\"";
                    }
                    if ((d - pgrade) > 2 * margin)
                    {
                        class1 = " class=\"tableHighlight1\"";
                    }
                    if (sp.PredictedGrade == 0)
                    {
                        class1 = " class=\"tableHighlight3\"";
                    }
                    //s += "<td"+class1+" >" + d.ToString() + "</td>";
                    s += "<td" + class1 + " >" + Profile_approx + "</td>";
                    //s+= "<td >" + sp.latestProfileGrade.Value.ToString() + "</td>";
                    //s += "<td >" + sp.latestProfileGradeScale.MaxValue.ToString() + "</td>";
                }
                else
                {
                    s += "<td></td>";
                }
                //s+="<td></td><td></td>";

                //if (pgrade != 0) s += "<td>" + pgrade.ToString() + "</td>";else s += "<td></td>";
                if (pgrade != 0)
                {
                    s += "<td>" + Target_approx + "</td>";
                }
                else
                {
                    s += "<td></td>";
                }
                if (sp.latestCommintmentGrade != null)
                {
                    class1 = " class=\"tableHighlight3\"";
                    d      = System.Convert.ToDouble(sp.latestCommintmentGrade.Value);
                    if (d > 3)
                    {
                        class1 = " class=\"tableHighlight2\"";
                    }
                    if (d > 4)
                    {
                        class1 = " class=\"tableHighlight1\"";
                    }
                    if (d < 2)
                    {
                        class1 = " class=\"tableHighlight4\"";
                    }
                    if (d < 1)
                    {
                        class1 = " class=\"tableHighlight5\"";
                    }
                    s += "<td" + class1 + " >" + sp.latestCommintmentGrade.Value.ToString() + "</td>";
                }
                else
                {
                    s += "<td></td>";
                }

                if (sp.latestInternalExamResult != null)
                {
                    s     += "<td>" + sp.latestInternalExamResult.Value + "</td>";
                    s     += "<td>" + sp.AvgInternalResult.ToString() + "</td>";
                    n      = (int)Round1(100 * ((double)sp.PositionInternalResult / (double)sp.NumberInternalResult));
                    class1 = " class=\"tableHighlight3\"";
                    if (n < 30)
                    {
                        class1 = " class=\"tableHighlight2\"";
                    }
                    if (n < 15)
                    {
                        class1 = " class=\"tableHighlight1\"";
                    }
                    if (n > 70)
                    {
                        class1 = " class=\"tableHighlight4\"";
                    }
                    if (n > 85)
                    {
                        class1 = " class=\"tableHighlight5\"";
                    }
                    s += "<td" + class1 + " >" + n.ToString() + "</td>";
                }
                else
                {
                    s += "<td></td>";
                    s += "<td></td>";
                    s += "<td></td>";
                }
                s += "</tr>";
            }
            s += "</table>";

            content0.InnerHtml = s; s = "";
            if (stinl.m_list.Count > 0)
            {
                Utility u = new Utility();
                s  = "Incdents in past month :<br />";
                s += "<table class=\"EventsTable\" > ";
                s += "<tr><th>Date</th>";
                s += "<th>Text</th>";
                s += "<th>Incident Pairs</th>";
                s += "<th>Staff</th>";
                s += "</tr>";
                foreach (StudentIncident si in stinl.m_list)
                {
                    s += "<tr>";
                    s += "<td>" + si.Date.ToShortDateString() + "</td>";
                    s += "<td>" + si.Text + "</td>";
                    s += "<td>" + si.IncidentPairs + "</td>";
                    s += "<td>" + u.Get_StaffCodefromStaffID(si.StaffID) + "</td>";
                    s += "</tr>";
                }
                s += "</table>";
            }
            else
            {
                s += "No recorded Incidents in past month";
            }
            content1.InnerHtml = s;
        }
        protected string GenerateVA(string GroupID, string GroupName)
        {
            string         s = ""; string s1 = ""; List <VAresult> list1 = new List <VAresult>();
            PupilGroupList pgl = new PupilGroupList(); pgl.AddToList(new Guid(GroupID), DateTime.Now);
            //going to get the data
            double xgrade = 0;
            double x1     = 0;
            double x2     = 0;

            foreach (SimplePupil p in pgl.m_pupilllist)
            {
                StudentAccademicProfile StudentProfile = new StudentAccademicProfile(p.m_StudentId);
                int      KeyStage = 0;
                DateTime date1    = new DateTime(); date1 = DateTime.Now;
                //this is when we load tt etc... so if in summer gap... alter
                if (date1.Month == 8)
                {
                    date1 = date1.AddMonths(2);
                }
                SimplePupil p1 = new SimplePupil(); p1 = p;
                StudentProfile.Load_Profile(date1, ref p1, ref KeyStage, false);
                string Profile_approx = ""; string Target_approx = "";
                foreach (StudentSubjectProfile sp in StudentProfile.profile)
                {
                    try
                    {
                        if (sp.latestProfileGrade != null)
                        {
                            x2 = sp.Convert_to_scale(ref xgrade, ref x1, ref Target_approx, ref Profile_approx);
                            VAresult v1 = new VAresult();
                            v1.adno   = p1.m_adno.ToString();
                            v1.course = sp.course.CourseCode;
                            //v1.profile = x1.ToString();
                            v1.profile = Profile_approx;
                            //v1.predict = x2.ToString();
                            v1.predict = Target_approx;
                            v1.surname = p.m_Surname; v1.givename = p.m_GivenName;
                            v1.x1      = x1; v1.x2 = x2;
                            v1.xgrade  = xgrade;
                            list1.Add(v1);
                        }
                    }
                    catch {  }
                }
            }

            //find all the courses in the list...
            List <string> courselist = new List <string>();
            bool          found      = false;

            foreach (VAresult v in list1)
            {
                found = false;
                foreach (string s4 in courselist)
                {
                    if (s4 == v.course)
                    {
                        found = true; break;
                    }
                }
                //not found
                if (!found)
                {
                    courselist.Add(v.course);
                }
            }
            courselist.Sort();
            //find all the students
            List <string> adnolist = new List <string>();

            foreach (VAresult v in list1)
            {
                found = false;
                foreach (string s4 in adnolist)
                {
                    if (s4 == v.adno)
                    {
                        found = true; break;
                    }
                }
                //not found
                if (!found)
                {
                    adnolist.Add(v.adno);
                }
            }
            string [,] list2 = new string[adnolist.Count + 3, 2 * courselist.Count + 6];
            double [,] list3 = new double[adnolist.Count + 3, 2 * courselist.Count + 6];
            double [,] listx = new double[adnolist.Count + 3, 2 * courselist.Count + 6];
            int i = 3;

            foreach (string s5 in courselist)
            {
                list2[0, i] = s5; i++;
                list2[0, i] = s5; i++;
            }
            int j = 1;

            foreach (VAresult v in list1)
            {
                if (list2[j, 0] != v.adno)
                {
                    j++; list2[j, 0] = v.adno; list2[j, 1] = v.givename; list2[j, 2] = v.surname;
                }
                //now find the course
                i = 3;
                foreach (string s5 in courselist)
                {
                    if (s5 == v.course)
                    {
                        list2[j, i]     = v.predict;
                        list2[j, i + 1] = v.profile;
                        list3[j, i]     = v.xgrade;
                        list3[j, i + 1] = v.xgrade;
                        listx[j, i]     = v.x2;
                        listx[j, i + 1] = v.x1;
                        break;
                    }
                    i++; i++;
                }
            }
            s  = "<h2><p align=\"center\"> Latest Profile Score v Predicted Grade </p></h2>";
            s += "<div><p  align=\"center\"><table class=\"EventsTable\"> ";
            s += "<TR><TD >Cells have:   </TD><td>course</br>Profile Grade</br>Predicted Grade</td>";
            s += "<td>Predictions are from Alis (KS5) / ";
            s += " Yellis (KS4)</br>Points are UCAS at KS5 (A=120) and GCSE at KS4 (A=52 or new 1-9 scale)</td>";
            s += "</tr></table></p>";
            s += "Colour indicates how far they exceed / failed to reach target";
            s += "<table class=\"EventsTable\"> ";
            s += "<TR><TD class= \"tableHighlight1\">Exceed by 1 grade</TD>";
            s += "<TD class= \"tableHighlight2\">Exceed by 0.5 grade</TD>";
            s += "<TD class= \"tableHighlight4\">Below by 0.5 grade</TD>";
            s += "<TD class= \"tableHighlight5\">Below by 1 grade</TD>";
            s += "</tr></table></div>";
            s += "<p  align=\"center\"><table class=\"EventsTable\"> ";
            s += "<TR><td>Adno</td><TD>Given Name</TD><TD>Surname</TD>";
            s += "<TD>Subjects</TD><TD>...............</TD></TR>";

            for (int i1 = 1; i1 < adnolist.Count + 2; i1++)
            {
                s += "<tr>";
                for (int j1 = 0; j1 < 3; j1++)
                {
                    s += "<td>" + list2[i1, j1] + "</td>";
                }

                for (int j1 = 4; j1 < 2 * courselist.Count + 4; j1 = j1 + 2)
                {
                    s1 = "<td>" + list2[0, j1] + "</br>";
                    try
                    {
                        x1     = listx[i1, j1];
                        x2     = listx[i1, j1 - 1];
                        xgrade = list3[i1, j1];
                        double xd = x2 - x1;
                        if (x1 > 0)
                        {
                            if (x2 > 0)
                            {
                                if (xd > xgrade / 2)
                                {
                                    s1 = "<td class= \"tableHighlight4\" >" + list2[0, j1] + "</br>";
                                    if (xd > xgrade)
                                    {
                                        s1 = "<td class= \"tableHighlight5\" >" + list2[0, j1] + "</br>";
                                    }
                                }
                                else if (xd < -xgrade / 2)
                                {
                                    s1 = "<td class= \"tableHighlight2\" >" + list2[0, j1] + "</br>";
                                    if (xd < -xgrade)
                                    {
                                        s1 = "<td class= \"tableHighlight1\" >" + list2[0, j1] + "</br>";
                                    }
                                }
                                //s1 += x1.ToString() + "</br>";
                                //s1 += x2.ToString();
                                s1 += list2[i1, j1] + "</br>";
                                s1 += list2[i1, j1 + 1];
                            }
                            else
                            {
                                s1  = "<td>" + list2[0, j1] + "</br>";
                                s1 += x1.ToString() + "</br>";
                            }
                        }
                        else
                        {
                            s1 = "<td></br>";
                        }
                    }
                    catch { };

                    s += s1 + "</TD>";
                }
                s += "</tr>";
            }
            s += "</table></div></p>";


            //going to add to pure data table....


            s += "</br><h2><p align=\"center\"> Data as flat table for copying to sheets etc. </p></h2></br>";
            s += "</p><div><p  align=\"center\"><table class=\"EventsTable\"> ";
            s += "<TR><td>Adno</td><TD>Given Name</TD><TD>Surname</TD>";
            s += "<TD>Subjects</TD><TD>Always prediction then Profile...</TD></TR>";
            for (int i1 = 0; i1 < adnolist.Count + 2; i1++)
            {
                s += "<tr>";
                for (int j1 = 0; j1 < 2 * courselist.Count + 4; j1 = j1 + 2)
                {
                    s += "<td>" + list2[i1, j1] + "</td>";
                    s += "<td>" + list2[i1, j1 + 1] + "</td>";
                }
                s += "</tr>";
            }
            s += "</table></div></p>";
            return(s);
        }