private void button1_Click(object sender, System.EventArgs e) { //This is just an example program to show how to translate an EDI X12 130 Student Educational Record (Transcript) //in C# with Framework EDI component ediDocument oEdiDoc = null; ediSchemas oSchemas = null; ediDataSegment oSegment = null; string sSegmentID; string sLoopSection; int nArea; string sValue; string sN1LoopQlfr = ""; string sSefFile = "130_4010.SEF"; string sEdiFile = "130.x12"; string sPath = AppDomain.CurrentDomain.BaseDirectory; Cursor = Cursors.WaitCursor; //CREATES EDIDOC OBJECT ediDocument.Set(ref oEdiDoc, new ediDocument()); //THIS MAKES CERTAIN THAT FREDI ONLY USES THE SEF FILE PROVIDED, AND THAT IT DOES //NOT USE ITS BUILT-IN STANDARD REFERENCE TABLE TO TRANSLATE THE EDI FILE. ediSchemas.Set(ref oSchemas,(ediSchemas) oEdiDoc.GetSchemas()); //oSchemas = (ediSchemas) oEdiDoc.GetSchemas(); oSchemas.EnableStandardReference = false; //THIS OPTIONS STOPS FREDI FROM KEEPING ALL THE SEGMENTS IN MEMORY oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardOnly; //LOADS THE SEF FILE oEdiDoc.ImportSchema(sPath + sSefFile, 0); //LOADS THE EDI FILE oEdiDoc.LoadEdi(sPath + sEdiFile); //GETS THE FIRST DATA SEGMENT ediDataSegment.Set(ref oSegment, (ediDataSegment) oEdiDoc.FirstDataSegment); //oSegment = (ediDataSegment) oEdiDoc.FirstDataSegment //LOOP THAT WILL TRAVERSE THRU EDI FILE FROM TOP TO BOTTOM while ( oSegment != null ) { //DATA SEGMENTS WILL BE IDENTIFIED BY THEIR ID, THE LOOP SECTION AND AREA //(OR TABLE) NUMBER THAT THEY ARE IN. sSegmentID = oSegment.ID; sLoopSection = oSegment.LoopSection; nArea = oSegment.Area; if (nArea == 0) { if (sLoopSection == "") { if (sSegmentID == "ISA") { sValue = oSegment.get_DataElementValue(1,0); //Authorization Information Qualifier sValue = oSegment.get_DataElementValue(2,0); //Authorization Information sValue = oSegment.get_DataElementValue(3,0); //Security Information Qualifier sValue = oSegment.get_DataElementValue(4,0); //Security Information sValue = oSegment.get_DataElementValue(5,0); //Interchange ID Qualifier sValue = oSegment.get_DataElementValue(6,0); //Interchange Sender ID sValue = oSegment.get_DataElementValue(7,0); //Interchange ID Qualifier sValue = oSegment.get_DataElementValue(8,0); //Interchange Receiver ID sValue = oSegment.get_DataElementValue(9,0); //Interchange Date sValue = oSegment.get_DataElementValue(10,0); //Interchange Time sValue = oSegment.get_DataElementValue(11,0); //Interchange Control Standards Identifier sValue = oSegment.get_DataElementValue(12,0); //Interchange Control Version Number listBox1.Items.Add(oSegment.get_DataElement(13).Description + " = " + oSegment.get_DataElementValue(13,0)); //Interchange Control Number sValue = oSegment.get_DataElementValue(14,0); //Acknowledgment Requested sValue = oSegment.get_DataElementValue(15,0); //Usage Indicator sValue = oSegment.get_DataElementValue(16,0); //Component Element Separator } else if (sSegmentID == "GS") { sValue = oSegment.get_DataElementValue(1,0); //Functional Identifier Code sValue = oSegment.get_DataElementValue(2,0); //Application Sender's Code sValue = oSegment.get_DataElementValue(3,0); //Application Receiver's Code sValue = oSegment.get_DataElementValue(4,0); //Date sValue = oSegment.get_DataElementValue(5,0); //Time listBox1.Items.Add(oSegment.get_DataElement(6).Description + " = " + oSegment.get_DataElementValue(6,0)); //Group Control Number sValue = oSegment.get_DataElementValue(7,0); //Responsible Agency Code sValue = oSegment.get_DataElementValue(8,0); //Version / Release / Industry Identifier Code } //sSegmentID } //sLoopSection } else if (nArea == 1) { if (sLoopSection == "") { if (sSegmentID == "ST") { sValue = oSegment.get_DataElementValue(1,0); //Transaction Set Identifier Code listBox1.Items.Add(oSegment.get_DataElement(2).Description + " = " + oSegment.get_DataElementValue(2,0)); //Transaction Set Control Number } else if (sSegmentID == "BGN") { sValue = oSegment.get_DataElementValue(1,0); //Transaction Set Purpose Code listBox1.Items.Add(oSegment.get_DataElement(2).Description + " = " + oSegment.get_DataElementValue(2,0)); //Reference Identification sValue = oSegment.get_DataElementValue(3,0); //Date sValue = oSegment.get_DataElementValue(4,0); //Time sValue = oSegment.get_DataElementValue(5,0); //Time Code } else if (sSegmentID == "ERP") { sValue = oSegment.get_DataElementValue(1,0); //Transaction Type Code sValue = oSegment.get_DataElementValue(2,0); //Status Reason Code } else if (sSegmentID == "REF") { sValue = oSegment.get_DataElementValue(1,0); //Reference Identification Qualifier listBox1.Items.Add(oSegment.get_DataElement(2).Description + " = " + oSegment.get_DataElementValue(2,0)); //Reference Identification } //Segment ID } else if (sLoopSection == "N1") { //if loop has more that one instance, then you should check for the qualifier that differentiates the loop instances here e.g. if (sSegmentID == "N1") { sN1LoopQlfr = oSegment.get_DataElementValue(1,0); //In most cases the loop qualifier is the first element of the first segment in the loop, but not necessarily } if (sN1LoopQlfr == "AS") //Post Secondary Education Sender { if (sSegmentID == "N1") { sValue = oSegment.get_DataElementValue(1,0); //Entity Identifier Code listBox1.Items.Add(oSegment.get_DataElement(2).Description + " Sender = " + oSegment.get_DataElementValue(2,0)); //Name } else if (sSegmentID == "N3") { sValue = oSegment.get_DataElementValue(1,0); //Address Information } else if (sSegmentID == "N4") { listBox1.Items.Add(oSegment.get_DataElement(2).Description + " Sender = " + oSegment.get_DataElementValue(2,0)); //City Name } //Segment ID } else if (sN1LoopQlfr == "AT") //'Post Secondary Education Receiver { if (sSegmentID == "N1") { sValue = oSegment.get_DataElementValue(1,0); //Entity Identifier Code listBox1.Items.Add(oSegment.get_DataElement(2).Description + " Receiver = " + oSegment.get_DataElementValue(2,0)); //Name } else if (sSegmentID == "N3") { sValue = oSegment.get_DataElementValue(1,0); //Address Information } else if (sSegmentID == "N4") { listBox1.Items.Add(oSegment.get_DataElement(2).Description + " Receiver = " + oSegment.get_DataElementValue(2,0)); //City Name } //Segment ID } } else if (sLoopSection == "IN1") { if (sSegmentID == "IN1") { sValue = oSegment.get_DataElementValue(1,0); //Entity Type Qualifier sValue = oSegment.get_DataElementValue(2,0); //Name Type Code } else if (sSegmentID == "IN2") { sValue = oSegment.get_DataElementValue(1,0); //Name Component Qualifier listBox1.Items.Add(oSegment.get_DataElement(2).Description + " = " + oSegment.get_DataElementValue(2,0)); //Name } //Segment ID } else if (sLoopSection == "SST") { if (sSegmentID == "SST") { sValue = oSegment.get_DataElementValue(1,0); //Status Reason Code sValue = oSegment.get_DataElementValue(2,0); //Date Time Period Format Qualifier listBox1.Items.Add(oSegment.get_DataElement(3).Description + " = " + oSegment.get_DataElementValue(3,0)); //Date Time Period } else if (sSegmentID == "N1") { sValue = oSegment.get_DataElementValue(1,0); //Entity Identifier Code listBox1.Items.Add(oSegment.get_DataElement(2).Description + " = " + oSegment.get_DataElementValue(2,0)); //Name } else if (sSegmentID == "N4") { listBox1.Items.Add(oSegment.get_DataElement(1).Description + " = " + oSegment.get_DataElementValue(1,0)); //City Name sValue = oSegment.get_DataElementValue(2,0); //State or Province Code } //Segment ID } else if (sLoopSection == "ATV") { if (sSegmentID == "ATV") { sValue = oSegment.get_DataElementValue(1,0); //Code List Qualifier Code sValue = oSegment.get_DataElementValue(2,0); //Industry Code listBox1.Items.Add(oSegment.get_DataElement(3).Description + " = " + oSegment.get_DataElementValue(3,0)); //Entity Title } else if (sSegmentID == "DTP") { sValue = oSegment.get_DataElementValue(1,0); //Date/Time Qualifier sValue = oSegment.get_DataElementValue(2,0); //Date Time Period Format Qualifier listBox1.Items.Add(oSegment.get_DataElement(3).Description + " = " + oSegment.get_DataElementValue(3,0)); //Date Time Period } //Segment ID } else if (sLoopSection == "TST") { if (sSegmentID == "TST") { sValue = oSegment.get_DataElementValue(1,0); //Educational Test or Requirement Code listBox1.Items.Add(oSegment.get_DataElement(2).Description + " = " + oSegment.get_DataElementValue(2,0)); //Name sValue = oSegment.get_DataElementValue(3,0); //Date Time Period Format Qualifier sValue = oSegment.get_DataElementValue(4,0); //Date Time Period sValue = oSegment.get_DataElementValue(5,0); //Reference Identification sValue = oSegment.get_DataElementValue(6,0); //Reference Identification sValue = oSegment.get_DataElementValue(7,0); //Level of Individual, Test, or Course Code } //Segment ID } else if (sLoopSection == "TST;SBT") { if (sSegmentID == "SBT") { listBox1.Items.Add(oSegment.get_DataElement(1).Description + " = " + oSegment.get_DataElementValue(1,0)); //Subtest Code } else if (sSegmentID == "SRE") { sValue = oSegment.get_DataElementValue(1,0); //Test Score Qualifier Code listBox1.Items.Add(oSegment.get_DataElement(2).Description + " = " + oSegment.get_DataElementValue(2,0)); //Description } //sSegmentID } //sLoopSection } else if (nArea == 2) { if (sLoopSection == "LX") { if (sSegmentID == "LX") { sValue = oSegment.get_DataElementValue(1,0); //Assigned Number } else if (sSegmentID == "HS") { sValue = oSegment.get_DataElementValue(1,0); //Health Screening Type Code sValue = oSegment.get_DataElementValue(2,0); //Date Time Period Format Qualifier sValue = oSegment.get_DataElementValue(3,0); //Date Time Period sValue = oSegment.get_DataElementValue(4,0); //Status Reason Code } else if (sSegmentID == "IMM") { sValue = oSegment.get_DataElementValue(1,0); //Immunization Type Code sValue = oSegment.get_DataElementValue(2,0); //Date Time Period Format Qualifier sValue = oSegment.get_DataElementValue(3,0); //Date Time Period sValue = oSegment.get_DataElementValue(4,0); //Immunization Status Code } //Segment ID } else if (sLoopSection == "LX;SES") { if (sSegmentID == "SES") { sValue = oSegment.get_DataElementValue(1,0); //Date Time Period sValue = oSegment.get_DataElementValue(2,0); //Count sValue = oSegment.get_DataElementValue(3,0); //Date Time Period listBox1.Items.Add(oSegment.get_DataElement(4).Description + " = " + oSegment.get_DataElementValue(4,0)); //Session Code sValue = oSegment.get_DataElementValue(5,0); //Name sValue = oSegment.get_DataElementValue(6,0); //Date Time Period Format Qualifier sValue = oSegment.get_DataElementValue(7,0); //Date Time Period sValue = oSegment.get_DataElementValue(8,0); //Date Time Period Format Qualifier sValue = oSegment.get_DataElementValue(9,0); //Date Time Period sValue = oSegment.get_DataElementValue(10,0); //Level of Individual, Test, or Course Code sValue = oSegment.get_DataElementValue(11,0); //Identification Code Qualifier sValue = oSegment.get_DataElementValue(12,0); //Identification Code listBox1.Items.Add(oSegment.get_DataElement(13).Description + " = " + oSegment.get_DataElementValue(13,0)); //Name sValue = oSegment.get_DataElementValue(14,0); //Status Reason Code } //Segment ID } else if (sLoopSection == "LX;SES;CRS") { if (sSegmentID == "CRS") { sValue = oSegment.get_DataElementValue(1,0); //Basis for Academic Credit Code sValue = oSegment.get_DataElementValue(2,0); //Academic Credit Type Code sValue = oSegment.get_DataElementValue(3,0); //Quantity sValue = oSegment.get_DataElementValue(4,0); //Quantity sValue = oSegment.get_DataElementValue(5,0); //Academic Grade Qualifier sValue = oSegment.get_DataElementValue(6,0); //Academic Grade sValue = oSegment.get_DataElementValue(7,0); //Yes/No Condition or Response Code sValue = oSegment.get_DataElementValue(8,0); //Academic Grade or Course Level Code sValue = oSegment.get_DataElementValue(9,0); //Course Repeat or No Count Indicator Code sValue = oSegment.get_DataElementValue(10,0); //Identification Code Qualifier sValue = oSegment.get_DataElementValue(11,0); //Identification Code sValue = oSegment.get_DataElementValue(12,0); //Quantity sValue = oSegment.get_DataElementValue(13,0); //Level of Individual, Test, or Course Code listBox1.Items.Add(oSegment.get_DataElement(14).Description + " = " + oSegment.get_DataElementValue(14,0)); //Name sValue = oSegment.get_DataElementValue(15,0); //Reference Identification sValue = oSegment.get_DataElementValue(16,0); //Name } //sSegmentID } //sLoopSection } //nArea //GETS THE NEXT DATA SEGMENT ediDataSegment.Set(ref oSegment, (ediDataSegment) oSegment.Next()); //oSegment = (ediDataSegment) oSegment.Next(); } //while Cursor = Cursors.Default; MessageBox.Show("Done."); }