///<summary>Takes raw text from a file and converts it into an X12Object.</summary> public X12object(string fileName) { string row = ""; using (StreamReader sr = new StreamReader(fileName)){ row = sr.ReadLine(); //Get separator date from the first row (ISA) if (row.Substring(0, 3) != "ISA") { throw new Exception("ISA not found"); } Separators = new X12Separators(); Separators.Element = row.Substring(3, 1); Separators.Subelement = row.Substring(104, 1); Separators.Segment = row.Substring(105, 1); functGroups = new ArrayList(); X12Segment segment; row = sr.ReadLine(); while (row != null) { segment = new X12Segment(row, Separators); if (segment.SegmentID == "IEA") //if end of interchange //do nothing { } if (segment.SegmentID == "GS") //if new functional group { functGroups.Add(new X12FunctionalGroup(segment)); } else if (segment.SegmentID == "GE") //if end of functional group //do nothing { } else if (segment.SegmentID == "ST") //if new transaction set { if (LastGroup().Transactions == null) { LastGroup().Transactions = new ArrayList(); } LastGroup().Transactions.Add(new X12Transaction(segment)); } else if (segment.SegmentID == "SE") //if end of transaction //do nothing { } else //it must be a detail segment within a transaction. { if (LastTransaction().Segments == null) { LastTransaction().Segments = new ArrayList(); } LastTransaction().Segments.Add(segment); } row = sr.ReadLine(); } } //using streamReader on filename }
///<summary></summary> public X12Segment(string rawText, X12Separators separators) { Separators = separators; //first, remove the segment terminator rawText = rawText.Replace(separators.Segment, ""); //then, split the row into elements, eliminating the DataElementSeparator Elements = rawText.Split(Char.Parse(separators.Element)); SegmentID = Elements[0]; }