private void btnGenerate_Click(object sender, System.EventArgs e) { // This is just an example program to demonstrate how to generate an EDI X12 210 file using Framework EDI component in C# ediDocument oEdiDoc = null; ediSchema oSchema = null; ediSchemas oSchemas = null; ediInterchange oInterchange = null; ediGroup oGroup = null; ediTransactionSet oTransactionset = null; ediDataSegment oSegment = null; btnGenerate.Enabled = false; string sPath = AppDomain.CurrentDomain.BaseDirectory; string sEdiFile = "210Output.X12"; string sSefFile = "210_003070.SEF"; //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. IMPROVES PERFORMANCE 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 = "~"; 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","003070")); 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,"AABB "); //Interchange Sender ID oSegment.set_DataElementValue(7,0,"01"); //Interchange ID Qualifier oSegment.set_DataElementValue(8,0,"112233445 "); //Interchange Receiver ID oSegment.set_DataElementValue(9,0,"080304"); //Interchange Date oSegment.set_DataElementValue(10,0,"1116"); //Interchange Time oSegment.set_DataElementValue(11,0,"U"); //Interchange Control Standards Identifier oSegment.set_DataElementValue(12,0,"00307"); //Interchange Control Version Number oSegment.set_DataElementValue(13,0,"000017859"); //Interchange Control Number oSegment.set_DataElementValue(14,0,"0"); //Acknowledgment Requested oSegment.set_DataElementValue(15,0,"P"); //Usage Indicator oSegment.set_DataElementValue(16,0,">"); //Component Element Separator //CREATES THE GS SEGMENT ediGroup.Set(ref oGroup, (ediGroup) oInterchange.CreateGroup("003070")); ediDataSegment.Set( ref oSegment, (ediDataSegment) oGroup.GetDataSegmentHeader()); oSegment.set_DataElementValue(1,0,"IM"); //Functional Identifier Code oSegment.set_DataElementValue(2,0,"AABB"); //Application Sender's Code oSegment.set_DataElementValue(3,0,"112233445"); //Application Receiver's Code oSegment.set_DataElementValue(4,0,"080304"); //Date oSegment.set_DataElementValue(5,0,"1116"); //Time oSegment.set_DataElementValue(6,0,"1"); //Group Control Number oSegment.set_DataElementValue(7,0,"X"); //Responsible Agency Code oSegment.set_DataElementValue(8,0,"003070"); //Version / Release / Industry Identifier Code //CREATES THE ST SEGMENT ediTransactionSet.Set(ref oTransactionset, (ediTransactionSet) oGroup.CreateTransactionSet("210")); ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.GetDataSegmentHeader()); oSegment.set_DataElementValue(1,0,"210"); //Transaction Set Identifier Code oSegment.set_DataElementValue(2,0,"0001"); //Transaction Set Control Number //B3 - BEGINNING SEGMENT FOR CARRIER'S INVOICE ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("B3")); oSegment.set_DataElementValue(2,0,"1538260"); //Invoice Number oSegment.set_DataElementValue(4,0,"DE"); //Shipment Method of Payment oSegment.set_DataElementValue(6,0,"080304"); //Date oSegment.set_DataElementValue(7,0,"190520"); //Net Amount Due oSegment.set_DataElementValue(11,0,"AABB"); //Standard Carrier Alpha Code oSegment.set_DataElementValue(12,0,"200803"); //Date //B2A - SET PURPOSE ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("B2A")); oSegment.set_DataElementValue(1,0,"00"); //Transaction Set Purpose Code //N9 - REFERENCE IDENTIFICATION ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N9")); oSegment.set_DataElementValue(1,0,"CN"); //Reference Identification Qualifier oSegment.set_DataElementValue(2,0,"338131"); //Reference Identification //G62 - DATE/TIME ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("G62")); oSegment.set_DataElementValue(1,0,"03"); //Date Qualifier oSegment.set_DataElementValue(2,0,"080304"); //Date oSegment.set_DataElementValue(3,0,"0"); //Time Qualifier oSegment.set_DataElementValue(4,0,"1116"); //Time oSegment.set_DataElementValue(5,0,"LT"); //Time Code // SHIPPER INFORMATION LOOP //N1 - NAME ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1\\N1")); //CREATES AN N1 SEGMENT IN THE N1 LOOPS oSegment.set_DataElementValue(1,0,"SH"); //Entity Identifier Code oSegment.set_DataElementValue(2,0,"HARDWARE BIZ"); //Name oSegment.set_DataElementValue(3,0,"1"); //Identification Code Qualifier oSegment.set_DataElementValue(4,0,"006932917"); //Identification Code //N2 - ADDITIONAL NAME INFORMATION ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1\\N2")); //CREATES AN N2 SEGMENT IN THE N1 LOOP oSegment.set_DataElementValue(1,0,"99448855"); //Name //N3 - ADDRESS INFORMATION ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1\\N3")); //CREATES AN N3 SEGMENT IN THE N1 LOOP oSegment.set_DataElementValue(1,0,"200 HIGHWAY ST"); //Address Information //N4 - GEOGRAPHIC LOCATION ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1\\N4")); //CREATES AN N4 SEGMENT IN THE N1 LOOP oSegment.set_DataElementValue(1,0,"LONGBEACH"); //City Name oSegment.set_DataElementValue(2,0,"CA"); //State or Province Code oSegment.set_DataElementValue(3,0,"37027"); //Postal Code //BILL-TO INFORMATION LOOP //N1 - NAME ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(2)\\N1")); //CREATES AN N1 SEGMENT IN THE SECOND INSTANCE OF THE N1 LOOP oSegment.set_DataElementValue(1,0,"BT"); //Entity Identifier Code oSegment.set_DataElementValue(2,0,"OFFICE HQ"); //Name oSegment.set_DataElementValue(3,0,"1"); //Identification Code Qualifier oSegment.set_DataElementValue(4,0,"PP22BBCC66"); //Identification Code //N2 - ADDITIONAL NAME INFORMATION ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(2)\\N2")); //CREATES AN N2 SEGMENT IN THE SECOND INSTANCE OF THE N1 LOOP oSegment.set_DataElementValue(1,0,"HQ99999999"); //Name //N3 - ADDRESS INFORMATION ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(2)\\N3")); oSegment.set_DataElementValue(1,0,"123 CENTER DR"); //Address Information //N4 - GEOGRAPHIC LOCATION ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N1(2)\\N4")); oSegment.set_DataElementValue(1,0,"LOS ANGELES"); //City Name oSegment.set_DataElementValue(2,0,"CA"); //State or Province Code oSegment.set_DataElementValue(3,0,"46064"); //Postal Code //N7 - EQUIPMENT DETAILS ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("N7\\N7")); oSegment.set_DataElementValue(1,0,"EIS"); //Equipment Initial oSegment.set_DataElementValue(2,0,"803126"); //Equipment Number oSegment.set_DataElementValue(18,0,"6"); //Equipment Number Check Digit //LX - ASSIGNED NUMBER ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX\\LX")); oSegment.set_DataElementValue(1,0,"1"); //Assigned Number //N9 - REFERENCE IDENTIFICATION ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX\\N9")); oSegment.set_DataElementValue(1,0,"F9"); //Reference Identification Qualifier oSegment.set_DataElementValue(2,0,"1006494351 CommodityCode"); //Reference Identification //L1 - RATE AND CHARGES ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX\\L1")); oSegment.set_DataElementValue(2,0,"1430.00"); //Freight Rate oSegment.set_DataElementValue(3,0,"FR"); //Rate/Value Qualifier oSegment.set_DataElementValue(4,0,"143000"); //Charge oSegment.set_DataElementValue(12,0,"HANDLING"); //Special Charge Description //LX - ASSIGNED NUMBER ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX(2)\\LX")); oSegment.set_DataElementValue(1,0,"2"); //Assigned Number //L1 - RATE AND CHARGES ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX(2)\\L1")); oSegment.set_DataElementValue(2,0,"72.00"); //Freight Rate oSegment.set_DataElementValue(3,0,"FR"); //Rate/Value Qualifier oSegment.set_DataElementValue(4,0,"7200"); //Charge oSegment.set_DataElementValue(12,0,"EARLY"); //Special Charge Description //LX - ASSIGNED NUMBER ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX(3)\\LX")); oSegment.set_DataElementValue(1,0,"3"); //Assigned Number //L1 - RATE AND CHARGES ediDataSegment.Set(ref oSegment, (ediDataSegment) oTransactionset.CreateDataSegment("LX(3)\\L1")); oSegment.set_DataElementValue(2,0,"403.20"); //Freight Rate oSegment.set_DataElementValue(3,0,"FR"); //Rate/Value Qualifier oSegment.set_DataElementValue(4,0,"40320"); //Charge oSegment.set_DataElementValue(12,0,"LATE"); //Special Charge Description //TRAILING SEGMENTS ARE AUTOMATICALLY CREATED //DISPLAY EDI STRING MessageBox.Show(oEdiDoc.GetEdiString(),"EDI File"); //SAVE EDI DOCUMENT OBJECT INTO AN EDI FILE. oEdiDoc.Save(sPath + sEdiFile); //DESTROYS OBJECTS oSegment.Dispose(); oTransactionset.Dispose(); oGroup.Dispose(); oInterchange.Dispose(); oSchema.Dispose(); oSchemas.Dispose(); oEdiDoc.Dispose(); MessageBox.Show("Done. Output = " + sPath + sEdiFile); }