private void button1_Click(object sender, System.EventArgs e) { //This is just an example program to show how to generate an EDI X12 130 Student Educational Record (Transcript) //in C# with the Framework EDI component ediDocument oEdiDoc = null; ediSchema oSchema = null; ediSchemas oSchemas = null; ediInterchange oInterchange = null; ediGroup oGroup = null; ediTransactionSet oTransactionset = null; ediDataSegment oSegment = null; string sEdiFile = "130Outbound.x12"; string sSefFile = "130_4010.SEF"; string sPath = AppDomain.CurrentDomain.BaseDirectory; Cursor = Cursors.WaitCursor; //CREATES EDI DOCUMENT 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 GENERATE THE EDI FILE. ediSchemas.Set(ref oSchemas,(ediSchemas) oEdiDoc.GetSchemas()); oSchemas.EnableStandardReference = false; //ENABLES FORWARD WRITE, AND INCREASES BUFFER I/O TO IMPROVE PERFORMANCE oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardWrite; oEdiDoc.set_Property(DocumentPropertyIDConstants.Property_DocumentBufferIO, 2000); //SET TERMINATORS oEdiDoc.SegmentTerminator = "~{13:10}"; oEdiDoc.ElementTerminator = "*"; oEdiDoc.CompositeTerminator = "!"; //LOADS THE SEF FILE ediSchema.Set(ref oSchema, (ediSchema) oEdiDoc.LoadSchema(sPath + sSefFile, 0)); //CREATES THE ISA SEGMENT ediInterchange.Set(ref oInterchange, (ediInterchange) oEdiDoc.CreateInterchange("X","004010")); ediDataSegment.Set(ref oSegment, (ediDataSegment) oInterchange.GetDataSegmentHeader()); oSegment.set_DataElementValue(1,0,"00"); //Authorization Information Qualifier oSegment.set_DataElementValue(2,0," "); //Authorization Information oSegment.set_DataElementValue(3,0,"00"); //Security Information Qualifier oSegment.set_DataElementValue(4,0," "); //Security Information oSegment.set_DataElementValue(5,0,"ZZ"); //Interchange ID Qualifier oSegment.set_DataElementValue(6,0,"SENDER ID "); //Interchange Sender ID oSegment.set_DataElementValue(7,0,"ZZ"); //Interchange ID Qualifier oSegment.set_DataElementValue(8,0,"RECEIVER ID "); //Interchange Receiver ID oSegment.set_DataElementValue(9,0,"061206"); //Interchange Date oSegment.set_DataElementValue(10,0,"0101"); //Interchange Time oSegment.set_DataElementValue(11,0,"U"); //Interchange Control Standards Identifier oSegment.set_DataElementValue(12,0,"00401"); //Interchange Control Version Number oSegment.set_DataElementValue(13,0,"000000001"); //Interchange Control Number oSegment.set_DataElementValue(14,0,"0"); //Acknowledgment Requested oSegment.set_DataElementValue(15,0,"T"); //Usage Indicator oSegment.set_DataElementValue(16,0,"!"); //Component Element Separator //CREATES THE GS SEGMENT ediGroup.Set(ref oGroup, (ediGroup) oInterchange.CreateGroup("004010")); ediDataSegment.Set( ref oSegment, (ediDataSegment) oGroup.GetDataSegmentHeader()); oSegment.set_DataElementValue(1,0,"ED"); //Functional Identifier Code oSegment.set_DataElementValue(2,0,"APP SENDER"); //Application Sender's Code oSegment.set_DataElementValue(3,0,"APP RECEIVER"); //Application Receiver's Code oSegment.set_DataElementValue(4,0,"01010101"); //Date oSegment.set_DataElementValue(5,0,"01010101"); //Time oSegment.set_DataElementValue(6,0,"1"); //Group Control Number oSegment.set_DataElementValue(7,0,"X"); //Responsible Agency Code oSegment.set_DataElementValue(8,0,"004010"); //Version / Release / Industry Identifier Code //CREATES THE ST SEGMENT ediTransactionSet.Set(ref oTransactionset, (ediTransactionSet) oGroup.CreateTransactionSet("130")); ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.GetDataSegmentHeader()); oSegment.set_DataElementValue(1,0,"130"); //Transaction Set Identifier Code oSegment.set_DataElementValue(2,0,"0001"); //Transaction Set Control Number //BGN - BEGINNING SEGMENT ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("BGN")); oSegment.set_DataElementValue(1,0,"00"); //Transaction Set Purpose Code oSegment.set_DataElementValue(2,0,"1234567"); //Reference Identification oSegment.set_DataElementValue(3,0,"20050503"); //Date oSegment.set_DataElementValue(4,0,"103020"); //Time oSegment.set_DataElementValue(5,0,"ET"); //Time Code //ERP - EDUCATIONAL RECORD PURPOSE ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("ERP")); oSegment.set_DataElementValue(1,0,"PS"); //Transaction Type Code oSegment.set_DataElementValue(2,0,"INF"); //Status Reason Code //REF - REFERENCE IDENTIFICATION ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("REF")); oSegment.set_DataElementValue(1,0,"SY"); //Reference Identification Qualifier oSegment.set_DataElementValue(2,0,"12345679"); //Reference Identification //N1 - NAME //create N1 segment in N1 loop ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1\\N1")); oSegment.set_DataElementValue(1,0,"AS"); //Postsecondary Education Sender Entity Identifier Code oSegment.set_DataElementValue(2,0,"UNIVERSITY SENDER"); //Name //N3 - ADDRESS INFORMATION //create N3 segment in N1 loop ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1\\N3")); oSegment.set_DataElementValue(1,0,"123 SENDER AVENUE"); //Address Information //N4 - GEOGRAPHIC LOCATION //create N4 segment in N1 loop ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1\\N4")); oSegment.set_DataElementValue(1,0,"LOS ANGELES"); //City Name //N1 - NAME //create N1 segment in the second instance of the N1 loop ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(2)\\N1")); oSegment.set_DataElementValue(1,0,"AT"); //Postsecondary Education Receiver Entity Identifier Code oSegment.set_DataElementValue(2,0,"COLLEGE RECEIVER"); //Name //N3 - ADDRESS INFORMATION //create N3 segment in the second instance of the N1 loop ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(2)\\N3")); oSegment.set_DataElementValue(1,0,"456 RECEIVER ST"); //Address Information //N4 - GEOGRAPHIC LOCATION //create N4 segment in the second instance of the N1 loop ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(2)\\N4")); oSegment.set_DataElementValue(1,0,"NEW YORK"); //City Name //IN1 - INDIVIDUAL IDENTIFICATION ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IN1\\IN1")); oSegment.set_DataElementValue(1,0,"1"); //Entity Type Qualifier oSegment.set_DataElementValue(2,0,"04"); //Name Type Code //IN2 - INDIVIDUAL NAME STRUCTURE COMPONENTS ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IN1\\IN2")); oSegment.set_DataElementValue(1,0,"05"); //Name Component Qualifier oSegment.set_DataElementValue(2,0,"SMITH"); //Name //IN2 - INDIVIDUAL NAME STRUCTURE COMPONENTS ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IN1\\IN2(2)")); oSegment.set_DataElementValue(1,0,"02"); //Name Component Qualifier oSegment.set_DataElementValue(2,0,"MARY"); //Name //IN2 - INDIVIDUAL NAME STRUCTURE COMPONENTS ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("IN1\\IN2(3)")); oSegment.set_DataElementValue(1,0,"15"); //Name Component Qualifier oSegment.set_DataElementValue(2,0,"J"); //Name //SST - STUDENT ACADEMIC STATUS ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("SST\\SST")); oSegment.set_DataElementValue(1,0,"B18"); //Status Reason Code oSegment.set_DataElementValue(2,0,"D8"); //Date Time Period Format Qualifier oSegment.set_DataElementValue(3,0,"19871215"); //Date Time Period //N1 - NAME ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("SST\\N1")); oSegment.set_DataElementValue(1,0,"HS"); //Entity Identifier Code oSegment.set_DataElementValue(2,0,"ST MARY'S HIGH SCHOOL"); //Name //N4 - GEOGRAPHIC LOCATION ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("SST\\N4")); oSegment.set_DataElementValue(1,0,"CARSON"); //City Name oSegment.set_DataElementValue(2,0,"CA"); //State or Province Code for (int nAtvLoop = 1; nAtvLoop <= 2; nAtvLoop++) //number of activities { //ATV - STUDENT ACTIVITIES AND AWARDS ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("ATV\\ATV")); oSegment.set_DataElementValue(3,0,"ATHLETE OF THE YEAR 1985"); //Entity Title //DTP - DATE OR TIME OR PERIOD ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("ATV\\DTP")); oSegment.set_DataElementValue(1,0,"103"); //Date/Time Qualifier oSegment.set_DataElementValue(2,0,"D8"); //Date Time Period Format Qualifier oSegment.set_DataElementValue(3,0,"19871130"); //Date Time Period } for (int nTstLoop = 1; nTstLoop <=3; nTstLoop++) //number of tests { //TST - TEST SCORE RECORD ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("TST\\TST")); oSegment.set_DataElementValue(1,0,"CPE"); //Educational Test or Requirement Code oSegment.set_DataElementValue(2,0,"CERTIFIED PRIMARY EDU"); //Name oSegment.set_DataElementValue(3,0,"D8"); //Date Time Period Format Qualifier oSegment.set_DataElementValue(4,0,"19791128"); //Date Time Period oSegment.set_DataElementValue(7,0,"07"); //Level of Individual, Test, or Course Code //SBT - SUBTEST ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("TST\\SBT\\SBT")); oSegment.set_DataElementValue(1,0,"TOTAL"); //Subtest Code //SRE - TEST SCORES ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("TST\\SBT\\SRE")); oSegment.set_DataElementValue(1,0,"3"); //Test Score Qualifier Code oSegment.set_DataElementValue(2,0,"ABA"); //Description } //LX - ASSIGNED NUMBER ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX\\LX")); oSegment.set_DataElementValue(1,0,"123456"); //Assigned Number //HS - HEALTH SCREENING ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX\\HS")); oSegment.set_DataElementValue(1,0,"IDIDID"); //Health Screening Type Code oSegment.set_DataElementValue(2,0,"CC"); //Date Time Period Format Qualifier oSegment.set_DataElementValue(3,0,"A1B2C3D4E5"); //Date Time Period oSegment.set_DataElementValue(4,0,"001"); //Status Reason Code //IMM - IMMUNIZATION STATUS CODE //create first instance of IMM segment in LX loop ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX\\IMM")); oSegment.set_DataElementValue(1,0,"FLU"); //Immunization Type Code oSegment.set_DataElementValue(2,0,"D8"); //Date Time Period Format Qualifier oSegment.set_DataElementValue(3,0,"19871128"); //Date Time Period oSegment.set_DataElementValue(4,0,"1"); //Immunization Status Code //IMM - IMMUNIZATION STATUS CODE //create second instance of IMM segment in LX loop ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX\\IMM(2)")); oSegment.set_DataElementValue(1,0,"TETANU"); //Immunization Type Code oSegment.set_DataElementValue(2,0,"D8"); //Date Time Period Format Qualifier oSegment.set_DataElementValue(3,0,"19700219"); //Date Time Period oSegment.set_DataElementValue(4,0,"1"); //Immunization Status Code //IMM - IMMUNIZATION STATUS CODE //create third instance of IMM segment in LX loop ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX\\IMM(3)")); oSegment.set_DataElementValue(1,0,"MUMPS"); //Immunization Type Code oSegment.set_DataElementValue(2,0,"D8"); //Date Time Period Format Qualifier oSegment.set_DataElementValue(3,0,"19750504"); //Date Time Period oSegment.set_DataElementValue(4,0,"1"); //Immunization Status Code for (int nSesLoop = 1; nSesLoop >= 2; nSesLoop++) //number of sessions { //SES - ACADEMIC SESSION HEADER //create SES segment in SES loop nested in LX loop ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX\\SES\\SES")); oSegment.set_DataElementValue(1,0,"20010407"); //Date Time Period oSegment.set_DataElementValue(4,0,"4"); //Session Code oSegment.set_DataElementValue(5,0,"SPRING QUARTER 2001"); //Name oSegment.set_DataElementValue(6,0,"D8"); //Date Time Period Format Qualifier oSegment.set_DataElementValue(7,0,"20010407"); //Date Time Period oSegment.set_DataElementValue(8,0,"D8"); //Date Time Period Format Qualifier oSegment.set_DataElementValue(9,0,"20010630"); //Date Time Period oSegment.set_DataElementValue(10,0,"21"); //Level of Individual, Test, or Course Code oSegment.set_DataElementValue(14,0,"B35"); //Status Reason Code //SSE - ENTRY AND EXIT INFORMATION //create SSE segment in SES loop nested in LX loop ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX\\SES\\SSE")); oSegment.set_DataElementValue(14,0,"20051231"); //Date for (int nCrsLoop = 1; nCrsLoop >= 2; nCrsLoop++) //number of courses in a session { //CRS - COURSE RECORD //create CRS segment in CRS loop nested in SES loop nested in LX loop ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX\\SES\\CRS\\CRS")); oSegment.set_DataElementValue(1,0,"R"); //Basis for Academic Credit Code oSegment.set_DataElementValue(2,0,"U"); //Academic Credit Type Code oSegment.set_DataElementValue(5,0,"GRD"); //Academic Grade Qualifier oSegment.set_DataElementValue(6,0,"AB"); //Academic Grade oSegment.set_DataElementValue(8,0,"U"); //Academic Grade or Course Level Code oSegment.set_DataElementValue(12,0,"12"); //Quantity oSegment.set_DataElementValue(14,0,"BEGIN MATH"); //Name oSegment.set_DataElementValue(15,0,"MAT101"); //Reference Identification oSegment.set_DataElementValue(16,0,"MATH"); //Name //create NTE segment in CRS loop nested in SES loop nested in LX loop ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX\\SES\\CRS\\NTE")); oSegment.set_DataElementValue(2,0,"INSTRUCTOR JOE"); //Basis for Academic Credit Code } } //TRAILING SEGMENTS ARE AUTOMATICALLY CREATED WHEN FREDI COMMITS (SAVES) //THE EDI DOCUMENT OBJECT INTO AN EDI FILE. oEdiDoc.Save(sPath + sEdiFile); Cursor = Cursors.Default; //DESTROYS OBJECTS oSegment.Dispose(); oTransactionset.Dispose(); oGroup.Dispose(); oInterchange.Dispose(); oSchema.Dispose(); oSchemas.Dispose(); oEdiDoc.Dispose(); MessageBox.Show("Done. Output = " + sPath + sEdiFile); }