コード例 #1
0
        protected void Button_CheckTime_Click(object sender, EventArgs e)
        {
            string       s        = TextBox1.Text;
            string       ErrorMsg = "";
            TextFileType ftype1   = TextFileType.Unknown;

            try
            {
                ftype1 = (TextFileType)ViewState["TextFileType"];
            }
            catch
            {
                Label_Text.Text = "File Type not recognised"; return;
            }
            char[]          ct1    = new char[1]; ct1[0] = (char)0x09;
            string[]        fields = new string[20];
            ExamsUtility    u      = new ExamsUtility();
            PupilGroupList  pgl    = new PupilGroupList();
            ExamConversions Ec     = new ExamConversions();
            SimplePupil     pupil1 = new SimplePupil();
            Guid            g1     = new Guid(); g1 = Guid.Empty;
            DateTime        t1     = new DateTime(); t1 = DateTime.Now;

            using (StringReader sr = new StringReader(s))
            {
                string firstline = sr.ReadLine();
                string line      = sr.ReadLine();
                fields = line.Split(ct1);
                Exam_Board exbde1 = Ec.GetExamBoard(fields[1]);
                switch (ftype1)
                {
                case TextFileType.Unknown:
                    Label_Text.Text = "File Type not recognised";
                    break;

                case TextFileType.Students:       //Admission Number,Surname, GivenName,Board,Syllabus,Option...";
                    try
                    {
                        pupil1.Load_StudentIdOnly(System.Convert.ToInt32(fields[0]));    ///loads lft students aswell
                        if (!u.AddEntry(pupil1.m_StudentId, exbde1, Year, YearCode, SeasonCode, fields[3], 3, true, ref ErrorMsg, ref g1))
                        {
                            Label_Text.Text = ErrorMsg; return;
                        }
                        else
                        {
                            Exam_Entry en1 = new Exam_Entry(); en1.m_ExamEntryID = g1; en1.Delete();
                        }
                    }
                    catch (Exception ex)
                    {
                        Label_Text.Text = ex.ToString(); return;
                    }
                    break;

                case TextFileType.Sets:
                    pgl.m_pupilllist.Clear();
                    pgl.AddToList(fields[0], DateTime.Now);
                    foreach (SimplePupil p in pgl.m_pupilllist)
                    {
                        try
                        {
                            if (!u.AddEntry(p.m_StudentId, exbde1, Year, YearCode, SeasonCode, fields[3], 3, true, ref ErrorMsg, ref g1))
                            {
                                Label_Text.Text = ErrorMsg; return;
                            }
                            else
                            {
                                Exam_Entry en1 = new Exam_Entry(); en1.m_ExamEntryID = g1; en1.Delete();
                            }
                        }
                        catch (Exception ex)
                        {
                            Label_Text.Text = ex.ToString(); return;
                        }
                    }
                    break;

                default:
                    break;
                }

                //done one set or one student...scale up....
                TimeSpan ts1 = DateTime.Now - t1; TimeSpan ts2 = new TimeSpan(); ts2 = ts1;
                while ((line = sr.ReadLine()) != null)
                {
                    ts2 += ts1;
                }
                TextBox_Warning.Text     = "WARNING:  This operation is likely to take about " + ts2.ToString() + Environment.NewLine + "Press Process Button to continue...";
                TextBox_Warning.Visible  = true;
                Button_CheckTime.Visible = false;
                Button_Process.Visible   = true;
            }
        }
コード例 #2
0
        protected void Button_Process_Click(object sender, EventArgs e)
        {
            string       s        = TextBox1.Text;
            string       ErrorMsg = "";
            TextFileType ftype1   = TextFileType.Unknown;

            try
            {
                ftype1 = (TextFileType)ViewState["TextFileType"];
            }
            catch
            {
                Label_Text.Text = "File Type not recognised"; return;
            }
            char[]   ct1    = new char[1]; ct1[0] = (char)0x09;
            string[] fields = new string[20];

            ExamsUtility    u              = new ExamsUtility();
            PupilGroupList  pgl            = new PupilGroupList();
            ExamConversions Ec             = new ExamConversions();
            SimplePupil     pupil1         = new SimplePupil();
            Guid            g1             = new Guid(); g1 = Guid.Empty;
            int             number_entered = 0;

            using (StringReader sr = new StringReader(s))
            {
                string firstline = sr.ReadLine();
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    fields = line.Split(ct1);

                    switch (ftype1)
                    {
                    case TextFileType.Unknown:
                        Label_Text.Text = "File Type not recognised";
                        break;

                    case TextFileType.Students:       //Admission Number,Surname, GivenName,Board,Syllabus,Option...";
                        try
                        {
                            Exam_Board exbde1 = Ec.GetExamBoard(fields[3]);
                            pupil1.Load_StudentIdOnly(System.Convert.ToInt32(fields[0]));    ///loads lft students aswell
                            if (!u.AddEntry(pupil1.m_StudentId, exbde1, Year, YearCode, SeasonCode, fields[5], 3, true, ref ErrorMsg, ref g1))
                            {
                                Label_Text.Text = ErrorMsg; return;
                            }
                            else
                            {
                                number_entered++;
                            }
                        }
                        catch (Exception ex)
                        {
                            Label_Text.Text = ex.ToString(); return;
                        }
                        break;

                    case TextFileType.Sets:          //Set, Board, Syllabus, Option.
                        pgl.m_pupilllist.Clear();
                        pgl.AddToList(fields[0], DateTime.Now);

                        foreach (SimplePupil p in pgl.m_pupilllist)
                        {
                            try
                            {
                                Exam_Board exbde1 = Ec.GetExamBoard(fields[1]);
                                if (!u.AddEntry(p.m_StudentId, exbde1, Year, YearCode, SeasonCode, fields[3], 3, true, ref ErrorMsg, ref g1))
                                {
                                    Label_Text.Text = ErrorMsg; return;
                                }
                                else
                                {
                                    number_entered++;
                                }
                            }
                            catch (Exception ex)
                            {
                                Label_Text.Text = ex.ToString(); return;
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            Label_Text.Text = "Correctly processed... " + number_entered.ToString() + " entries";
        }