protected void Button_FileUpload_Click(object sender, EventArgs e) { SimplePupil pupil1 = new SimplePupil(); if (FileUpload_picker.FileName.ToUpper().Contains("WHOLEYEAR"))//should be WholeYear10 or etc { try { string s1 = FileUpload_picker.FileName.Substring(9); if (s1.StartsWith("1")) { s1 = s1.Substring(0, 2); } else { s1 = s1.Substring(0, 1); } int year = System.Convert.ToInt32(s1); int k = 4; if (year < 10) { k = 3; } if (year > 11) { k = 5; } //need to set up the date for result string s2 = ""; DateTime SetListDate = new DateTime(); Utility u = new Utility(); TextBox2.Text = u.GetResultDate(s1, ref s2, ref SetListDate).ToShortDateString(); ProcessYearFile(k); return; } catch { } } string s = "DataUpload_" + TextBox1.Text + "_" + DateTime.Now.ToLongTimeString() + ".txt"; s = s.Replace(":", "-"); string path = Server.MapPath(@"../App_Data/") + s; //String username = System.Security.Principal.WindowsIdentity.GetCurrent().Name; FileUpload_picker.SaveAs(path); Stream mystream = FileUpload_picker.FileContent; byte[] buffer = new byte[mystream.Length]; mystream.Read(buffer, 0, (int)mystream.Length); Cerval_Library.TextReader text1 = new Cerval_Library.TextReader(); Cerval_Library.TextRecord t = new TextRecord(); FileStream f = new FileStream(path, FileMode.Open); while (text1.ReadTextLine(f, ref t) == Cerval_Library.TextReader.READ_LINE_STATUS.VALID) { //if all goes well col 2 is adno.... s = t.field[2]; try { pupil1.Load(System.Convert.ToInt32(s)); TextBox tst1 = (TextBox)content0.FindControl(pupil1.m_StudentId.ToString()); if (tst1 != null) { //so we have the adno of a student in the list... s = t.field[3];//and a grade try { int r = System.Convert.ToInt32(s); if ((r > 0) && (r < 101)) { SaveResult(pupil1.m_StudentId.ToString(), s, TextBox3.Text); } } catch { } } } catch { } } f.Close(); //File.Delete(path); Table1.Controls.Clear(); AddControls(true); }
protected void ProcessYearFile(int Key_stage) { string s = "DataUpload_YearFile_" + DateTime.Now.ToLongTimeString() + ".txt"; s = s.Replace(":", "-"); string path = Server.MapPath(@"../App_Data/") + s; //String username = System.Security.Principal.WindowsIdentity.GetCurrent().Name; FileUpload_picker.SaveAs(path); Cerval_Library.TextReader text1 = new Cerval_Library.TextReader(); Cerval_Library.TextRecord t = new TextRecord(); FileStream f = new FileStream(path, FileMode.Open); string s2 = ""; string[] Course_Name = new string[20]; string[] Course_ID = new string[20]; text1.ReadTextLine(f, ref t);//header row s = t.field[2]; int n = t.number_fields; SimplePupil pupil1 = new SimplePupil(); if ((s != "Adno") || (n < 4)) { f.Close(); return; } CourseList cl1 = new CourseList(Key_stage); for (int i = 3; i < n; i++) { Course_Name[i] = t.field[i]; foreach (Course c in cl1._courses) { if (c.CourseCode == Course_Name[i]) { Course_ID[i] = c._CourseID.ToString(); } } } while (text1.ReadTextLine(f, ref t) == Cerval_Library.TextReader.READ_LINE_STATUS.VALID) { //if all goes well col 2 is adno.... s = t.field[2]; for (int i = 3; i < n; i++) { s2 = t.field[i];//result try { pupil1.Load(System.Convert.ToInt32(s)); try { int r = System.Convert.ToInt32(s2); if ((r > 0) && (r < 101)) { SaveResult(pupil1.m_StudentId.ToString(), s2, Course_ID[i]); } } catch { } } catch { } } } f.Close(); }