//glennj 6/21/2013 /// <summary> /// Opens a text file. /// </summary> /// <param name="awg">specific awg object</param> /// <param name="fileName">Path of the text file</param> /// <param name="bitDepth">OPTIONAL: The bit depth of the text file required for digital</param> public void OpenTXTFileFromAsset(IAWG awg, string fileName, TextFileType bitDepth) { string textType = ""; switch (bitDepth) { case TextFileType.FloatingPoint: textType = "ANAL"; break; case TextFileType.DAC_8Bit: textType = "DIG8"; break; case TextFileType.DAC_9Bit: textType = "DIG9"; break; case TextFileType.DAC_10Bit: textType = "DIG10"; break; case TextFileType.DAC_14Bit: textType = "DIG14"; break; } awg.MemoryOpenTxt(fileName, textType); }
//glennj 6/21/2013 /// <summary> /// Saves the given asset as a TXT file /// </summary> /// <param name="awg">specific awg object</param> /// <param name="assetName">Name of the asset to saved</param> /// <param name="filepath">New name and place to save the TXT file</param> /// <param name="fileType">Type of the text file to be saved</param> public void SaveTheAssetAsATXT(IAWG awg, string assetName, string filepath, TextFileType fileType) { string requiredFileType = ""; switch (fileType) { case TextFileType.FloatingPoint: requiredFileType = "ANAL"; break; case TextFileType.DAC_8Bit: requiredFileType = "DIG8"; break; case TextFileType.DAC_9Bit: requiredFileType = "DIG9"; break; case TextFileType.DAC_10Bit: requiredFileType = "DIG10"; break; default: return; } awg.MemorySaveTXT(assetName, filepath, requiredFileType); }
public void LoadStreams(IStream leftStream, FileType leftFileType, byte[] leftData, IStream rightStream, FileType rightFileType, byte[] rightData) { _unifiedViewer.SelectDetails(leftStream, leftFileType, rightStream, rightFileType); _sideBySideViewer.SelectDetails(leftStream, leftFileType, rightStream, rightFileType); _leftData = leftData; _leftFileType = (TextFileType)leftFileType; _rightData = rightData; _rightFileType = (TextFileType)rightFileType; int leftBomSize = _leftFileType != null?_leftFileType.Encoding.GetPreamble().Length : 0; int rightBomSize = _rightFileType != null?_rightFileType.Encoding.GetPreamble().Length : 0; _leftText = new Text( _leftData == null ? String.Empty : _leftFileType.Encoding.GetString(_leftData, leftBomSize, _leftData.Length - leftBomSize) ); _rightText = new Text( _rightData == null ? String.Empty : _rightFileType.Encoding.GetString(_rightData, rightBomSize, _rightData.Length - rightBomSize) ); LoadDiff(); }
public void LoadNametable(string filename, string filepath, byte[] data, RpfFileEntry e) { fileType = TextFileType.Nametable; FileName = filename; FilePath = filepath; TextValue = Encoding.UTF8.GetString(data).Replace('\0', '\n'); rpfFileEntry = e; modified = false; }
public void LoadGxt2(string filename, string filepath, Gxt2File gxt) { fileType = TextFileType.GXT2; FileName = filename; FilePath = filepath; TextValue = gxt?.ToText() ?? ""; rpfFileEntry = gxt?.FileEntry; modified = false; }
public void LoadText(string filename, string filepath, string text, RpfFileEntry e) { fileType = TextFileType.Text; FileName = filename; FilePath = filepath; TextValue = text; rpfFileEntry = e; modified = false; }
private void NewDocument() { if (!CloseDocument()) { return; //same thing really.. } fileType = TextFileType.Text; FileName = "New.txt"; }
private Stream BuildStream(Text text, TextFileType fileType) { var preamble = fileType.Encoding.GetPreamble(); var stream = new MemoryStream(text.Content.Length + preamble.Length); var data = fileType.Encoding.GetBytes(text.Content); stream.Write(preamble, 0, preamble.Length); stream.Write(data, 0, data.Length); stream.Position = 0; return(stream); }
private void OpenDocument() { if (OpenFileDialog.ShowDialog() != DialogResult.OK) { return; } if (!CloseDocument()) { return; } var fn = OpenFileDialog.FileName; if (!File.Exists(fn)) { return; //couldn't find file? } var fnl = fn.ToLowerInvariant(); if (fnl.EndsWith(".gxt2")) { var gxt = new Gxt2File(); gxt.Load(File.ReadAllBytes(fn), null); fileType = TextFileType.GXT2; TextValue = gxt.ToText(); } else if (fnl.EndsWith(".nametable")) { fileType = TextFileType.Nametable; TextValue = File.ReadAllText(fn).Replace('\0', '\n'); } else { fileType = TextFileType.Text; TextValue = File.ReadAllText(fn); } modified = false; FilePath = fn; FileName = new FileInfo(fn).Name; }
private bool CloseDocument() { if (modified) { var res = MessageBox.Show("Do you want to save the current document before closing it?", "Save before closing", MessageBoxButtons.YesNoCancel); switch (res) { case DialogResult.Yes: SaveDocument(); break; case DialogResult.Cancel: return(false); } } fileType = TextFileType.Text; FilePath = ""; FileName = ""; TextValue = ""; modified = false; return(true); }
protected void Button_Display_Click(object sender, EventArgs e) { if (!FileUpload1.HasFile) { return; } TextFileType ftype1 = TextFileType.Unknown; Cerval_Library.TextReader TxtRd1 = new Cerval_Library.TextReader(); TextRecord t = new TextRecord(); int l = 0; int n = 0; string s1 = ""; char ct = (char)0x09; int n_Year = 0; int n_Season = 0; int n_OptionCode = 0; int n_TQM = 0; int n_ComponentCode = 0; int n_ScaledMark = 0; int n_ComponentUMS = 0; int n_Status = 0; bool f_Year = false; bool f_Season = false; bool f_OptionCode = false; bool f_TQM = false; bool f_ComponentCode = false; bool f_ScaledMark = false; bool f_ComponentUMS = false; bool f_Status = false; int n_CandNo = 0; bool f_CandNo = false; while (TxtRd1.ReadTextLine(FileUpload1.FileContent, ref t) == Cerval_Library.TextReader.READ_LINE_STATUS.VALID) { l = s1.Length; for (int i = 0; i <= t.number_fields; i++) { s1 += t.field[i] + ct; } if (s1.Length > l) { s1 += Environment.NewLine; } if (n == 0) { //going to look for our columns: for (int i = 0; i <= t.number_fields; i++) { switch (t.field[i]) { case "Series Year": n_Year = i; f_Year = true; break; case "Series Code": n_Season = i; f_Season = true; break; case "Entry Code": n_OptionCode = i; f_OptionCode = true; break; case "Result Mark": n_TQM = i; f_TQM = true; break; case "Component Code": n_ComponentCode = i; f_ComponentCode = true; break; case "Component UMS": n_ComponentUMS = i; f_ComponentUMS = true; break; case "Component Scaled Mark": n_ScaledMark = i; f_ScaledMark = true; break; case "Component Status Notes": n_Status = i; f_Status = true; break; case "Candidate Number": n_CandNo = i; f_CandNo = true; break; default: break; } } // so do we have all the required columns?? if (!(f_Year && f_Season && f_OptionCode && f_TQM && f_ComponentCode && f_ScaledMark && f_ComponentUMS && f_Status && f_CandNo)) { Label_Text.Text = "Can't recognise the format of this file. "; if (!f_Year) { Label_Text.Text += "No YearColumn"; } if (!f_Season) { Label_Text.Text += "No SeasonColumn"; } if (!f_OptionCode) { Label_Text.Text += "No OptionCodeColumn"; } if (!f_TQM) { Label_Text.Text += "No TQMColumn"; } if (!f_ComponentCode) { Label_Text.Text += "No ComponnetCodeColumn"; } if (!f_ComponentUMS) { Label_Text.Text += "No ComponentUMSColumn"; } if (!f_ScaledMark) { Label_Text.Text += "No ScaledMarkColumn"; } if (!f_Status) { Label_Text.Text += "No StatusColumn"; } } else { foreach (TextFileType eb in Enum.GetValues(typeof(TextFileType))) { if (DropDownList1.SelectedValue == eb.ToString()) { ftype1 = eb; break; } } Label_Text.Text = "File Format Fine: Board: " + ftype1.ToString(); } } ViewState["TextFileType"] = ftype1; ViewState["n_Year"] = n_Year; ViewState["n_Season"] = n_Season; ViewState["n_OptionCode"] = n_OptionCode; ViewState["n_TQM"] = n_TQM; ViewState["n_ComponentCode"] = n_ComponentCode; ViewState["n_ComponentUMS"] = n_ComponentUMS; ViewState["n_ScaledMark"] = n_ScaledMark; ViewState["n_Status"] = n_Status; ViewState["n_CandNo"] = n_CandNo; TextBox1.Text = s1; Button_Display.Visible = false; Button_Process.Visible = true; } }
protected void Button_Process_Click(object sender, EventArgs e) { string s = TextBox1.Text; TextFileType ftype1 = TextFileType.Unknown; try { ftype1 = (TextFileType)ViewState["TextFileType"]; } catch { Label_Text.Text = "File Type not recognised"; return; } if (ftype1 == TextFileType.Unknown) { Label_Text.Text = "Board Not Set!!!"; 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; Exam_Board eb1 = new Exam_Board(); SimplePupil p1 = new SimplePupil(); ExamComponent ec1 = new ExamComponent(); ExamOption exo1 = new ExamOption(); ExamComponentResultList ecrl1 = new ExamComponentResultList(); string component_code = ""; int adno1 = 0; string Option_Code = ""; string ScaledMark = ""; string ComponentUMS = ""; string ComponentStatus = ""; string TQM_value = ""; int n_Year = (int)ViewState["n_Year"]; int n_Season = (int)ViewState["n_Season"]; int n_OptionCode = (int)ViewState["n_OptionCode"]; int n_TQM = (int)ViewState["n_TQM"]; int n_ComponentCode = (int)ViewState["n_ComponentCode"]; int n_ComponentUMS = (int)ViewState["n_ComponentUMS"]; int n_ScaledMark = (int)ViewState["n_ScaledMark"]; int n_Status = (int)ViewState["n_Status"]; int n_CandNo = (int)ViewState["n_CandNo"]; int number_entered = 0; //get exam board.... switch (ftype1) { case TextFileType.Unknown: return; case TextFileType.AQA_GCE: eb1 = new Exam_Board("70"); break; case TextFileType.OCR_GCE: eb1 = new Exam_Board("01"); break; case TextFileType.EDEXCEL_GCE: eb1 = new Exam_Board("11"); break; case TextFileType.AQA_GCSE: eb1 = new Exam_Board("70"); break; case TextFileType.OCR_GCSE: break; case TextFileType.EDEXCEL_GCSE: eb1 = new Exam_Board("10"); break; case TextFileType.CIE: eb1 = new Exam_Board("02"); break; case TextFileType.WJEC_GCSE: eb1 = new Exam_Board("40"); break; case TextFileType.WJEC_GCE: eb1 = new Exam_Board("41"); break; default: break; } using (StringReader sr = new StringReader(s)) { string firstline = sr.ReadLine(); string line; while ((line = sr.ReadLine()) != null) { fields = line.Split(ct1); adno1 = 0; component_code = ""; Option_Code = ""; ScaledMark = ""; ComponentUMS = ""; ComponentStatus = ""; adno1 = Convert.ToInt32(fields[n_CandNo]); if (Year.ToString() != fields[n_Year]) { Label_Text.Text = "Year code mismatch in file, line" + number_entered.ToString(); return; } if (SeasonCode.ToString() != fields[n_Season].Substring(0, 1)) { Label_Text.Text = "Series code mismatch in file, line" + number_entered.ToString(); return; } component_code = fields[n_ComponentCode]; Option_Code = fields[n_OptionCode]; ScaledMark = fields[n_ScaledMark]; ComponentUMS = fields[n_ComponentUMS]; ComponentStatus = fields[n_Status]; TQM_value = fields[n_TQM]; ExamComponentResult r = new ExamComponentResult(); try { p1.Load_StudentIdOnly(adno1); ec1.Load(component_code, SeasonCode.ToString(), YearCode.ToString()); exo1.Load(Option_Code, SeasonCode.ToString(), YearCode.ToString(), eb1.m_ExamBoardId); r.OptionId = exo1.m_OptionID; r.ComponentId = ec1.m_ComponentID; r.StudentId = p1.m_StudentId; try { r.ComponentScaledMark = System.Convert.ToInt32(ScaledMark); } catch { //assume it is non integer.... double d = Convert.ToDouble(ScaledMark); r.ComponentScaledMark = Convert.ToInt32(d); } try { r.ComponentUMS = System.Convert.ToInt32(ComponentUMS); } catch { } r.ComponentStatus = ComponentStatus; switch (ecrl1.Load_OptionStudent(r.OptionId, r.StudentId, r.ComponentId)) { case 0: //so can write in r.Save(); break; case 1: //so update r.ComponentResultId = ecrl1.m_list[0].ComponentResultId; r.Save(); break; case 2: //so problem break; default: break; } //now find the result.... ResultsList rl1 = new ResultsList(); rl1.m_parameters = 0; rl1.m_where = "WHERE (dbo.tbl_Core_Students.StudentId='" + r.StudentId.ToString() + "')AND(dbo.tbl_Core_Results.ExamsOptionId='" + r.OptionId.ToString() + "') "; rl1.LoadList("", ""); Result r1 = new Result(); r1 = (Result)rl1._results[0]; r1.Text = "TQM=" + TQM_value; r1.UpdateResultTextOnly(); number_entered++; } catch (Exception ex) { Label_Text.Text = ex.ToString(); } } } Label_Text.Text = "Correctly processed... " + number_entered.ToString() + " entries"; }
protected void Button_Upload_Click(object sender, EventArgs e) { if (!FileUpload1.HasFile) { return; } TextFileType ftype1 = TextFileType.Unknown; string s = Server.MapPath("BaseData") + "\\" + FileUpload1.FileName; Cerval_Library.TextReader TxtRd1 = new Cerval_Library.TextReader(); TextRecord t = new TextRecord(); int l = 0; int n = 0; string s1 = ""; char ct = (char)0x09; while (TxtRd1.ReadTextLine(FileUpload1.FileContent, ref t) == Cerval_Library.TextReader.READ_LINE_STATUS.VALID) { l = s1.Length; for (int i = 0; i < t.number_fields; i++) { if (t.field[i].Length == 0) { break; } else { s1 += t.field[i] + ct; } } if (s1.Length > l) { s1 += Environment.NewLine; } if (n == 0) { //this is first line so has headers.... if (t.field[0].ToUpper().Trim() == "SET") { ftype1 = TextFileType.Sets; } if (t.field[0].ToUpper().Trim() == "ADNO") { ftype1 = TextFileType.Students; } if (t.field[0].ToUpper().Trim() == "ADMISSION NUMBER") { ftype1 = TextFileType.Students; } switch (ftype1) { case TextFileType.Unknown: Label_Text.Text = "First column must be either 'Set' or 'adno' or 'Admission Number'"; break; case TextFileType.Students: Label_Text.Text = "Assuming columns are: Admission Number,Surname, GivenName,Board,Syllabus,Option..."; break; case TextFileType.Sets: Label_Text.Text = "Assuming columns are: Set, Board, Syllabus, Option......."; break; default: break; } } } ViewState["TextFileType"] = ftype1; TextBox1.Text = s1; Button_CheckTime.Visible = false; Button_Upload.Visible = false; Button_Process.Visible = true; }
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; } }
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"; }