private void btnGenerate_Click(object sender, EventArgs e) { ediDocument oEdiDoc; ediSchema oSchema; ediSchemas oSchemas; ediInterchange oInterchange; ediTransactionSet oMessage; ediDataSegment oSegment; string sEdiFileName = ""; string sSefFileName = ""; string sPath = AppDomain.CurrentDomain.BaseDirectory; // Create the top-level application object "ediDocument". oEdiDoc = new ediDocument(); // This makes certain that Framework EDI only uses the SEF file provided, // and that it does not use its built-in Standard Reference table to generate // the EDI document oSchemas = (ediSchemas)oEdiDoc.GetSchemas(); oSchemas.EnableStandardReference = false; // The FORWARD-WRITE cursor increases the performance of processing the EDI // document (see Technical Note 3 below). oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardWrite; // Terminators have to be specified. oEdiDoc.SegmentTerminator = "'{13:10}"; oEdiDoc.ElementTerminator = "+"; oEdiDoc.CompositeTerminator = ":"; oEdiDoc.ReleaseIndicator = "?"; sEdiFileName = "BAPLIE_D95B_Output.EDI"; sSefFileName = "BAPLIE_D95B.EVAL0.SEF"; // Specify SEF file to load. oSchema = (ediSchema)oEdiDoc.LoadSchema(sPath + sSefFileName, SchemaTypeIDConstants.Schema_Standard_Exchange_Format); // Creates the Interchange Control Header segment (UNB). oInterchange = (ediInterchange)oEdiDoc.CreateInterchange("UN", "D95B"); oSegment = (ediDataSegment)oInterchange.GetDataSegmentHeader(); oSegment.set_DataElementValue(1, 1, "UNOA"); // Syntax identifier (0001) oSegment.set_DataElementValue(1, 2, "2"); // Syntax version number (0002) oSegment.set_DataElementValue(2, 1, "SENDER ID"); // Interchange sender identification (0004) oSegment.set_DataElementValue(2, 2, "ZZZ"); // Partner identification code qualifier (0007) oSegment.set_DataElementValue(3, 1, "RECEIVER ID"); // Recipient identification (0010) oSegment.set_DataElementValue(3, 2, "ZZZ"); // Partner identification code qualifier (0007) oSegment.set_DataElementValue(4, 1, "010101"); // Date (0017) oSegment.set_DataElementValue(4, 2, "0101"); // Time (0019) oSegment.set_DataElementValue(5, 0, "1"); // Interchange control reference (0020) // Creates the Message header segment (UNH). oMessage = (ediTransactionSet)oInterchange.CreateTransactionSet("BAPLIE"); ediDataSegment.Set(ref oSegment, (ediDataSegment)oMessage.GetDataSegmentHeader()); oSegment.set_DataElementValue(1, 0, "1"); // Message reference number (0062) oSegment.set_DataElementValue(2, 1, "BAPLIE"); // Message type identifier (0065) oSegment.set_DataElementValue(2, 2, "D"); // Message version number (0052) oSegment.set_DataElementValue(2, 3, "95B"); // Message release number (0054) oSegment.set_DataElementValue(2, 4, "UN"); // Controlling agency (0051) oSegment.set_DataElementValue(2, 5, ""); // Association assigned code (0057) // Beginning of message (BGM) oSegment = oMessage.CreateDataSegment("BGM"); oSegment.set_DataElementValue(2, 0, "0001"); // Document/message number (1004) oSegment.set_DataElementValue(3, 0, "22"); // Message function, coded (1225) // Date/time/period (DTM) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment("DTM")); oSegment.set_DataElementValue(1, 1, "137"); // Date/time/period qualifier (2005) oSegment.set_DataElementValue(1, 2, "201503011045"); // Date/time/period (2380) oSegment.set_DataElementValue(1, 3, "203"); // Date/time/period format qualifier (2379) // TDT group bool bTdt01 = true; if (bTdt01 == true) { // Transport information (TDT) oSegment = oMessage.CreateDataSegment(@"TDT\TDT"); oSegment.set_DataElementValue(1, 0, "20"); // Transport stage qualifier (8051) oSegment.set_DataElementValue(2, 0, "151W"); // Conveyance reference number (8028) oSegment.set_DataElementValue(5, 1, "ABCU"); // Carrier identification (3127) oSegment.set_DataElementValue(5, 2, "172"); // Code list qualifier (1131) oSegment.set_DataElementValue(5, 3, "20"); // Code list responsible agency, coded (3055) oSegment.set_DataElementValue(5, 4, "XYZ LINE"); // Carrier name (3128) oSegment.set_DataElementValue(8, 1, "28942"); // Id. of means of transport identification (8213) oSegment.set_DataElementValue(8, 2, "103"); // Code list qualifier (1131) oSegment.set_DataElementValue(8, 3, "11"); // Code list responsible agency, coded (3055) oSegment.set_DataElementValue(8, 4, "SEA DEALER"); // Id. of the means of transport (8212) oSegment.set_DataElementValue(8, 5, "US"); // Nationality of means of transport, coded (8453) // Place/location identification (LOC) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"TDT\LOC")); //this is the first instance of the LOC segment in the TDT group oSegment.set_DataElementValue(1, 0, "5"); // Place/location qualifier (3227) oSegment.set_DataElementValue(2, 1, "SEADGR"); // Place/location identification (3225) oSegment.set_DataElementValue(2, 2, "139"); // Code list qualifier (1131) oSegment.set_DataElementValue(2, 3, "6"); // Code list responsible agency, coded (3055) oSegment.set_DataElementValue(3, 1, "US"); // Related place/location one identification (3223) oSegment.set_DataElementValue(3, 2, "162"); // Code list qualifier (1131) oSegment.set_DataElementValue(3, 3, "5"); // Code list responsible agency, coded (3055) oSegment.set_DataElementValue(4, 1, "CA"); // Related place/location two identification (3233) oSegment.set_DataElementValue(4, 2, "163"); // Code list qualifier (1131) // Place/location identification (LOC) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"TDT\LOC(2)")); //this is the second instance of the LOC segment in the TDT group oSegment.set_DataElementValue(1, 0, "61"); // Place/location qualifier (3227) oSegment.set_DataElementValue(2, 1, "PEHWD"); // Place/location identification (3225) oSegment.set_DataElementValue(2, 2, "139"); // Code list qualifier (1131) oSegment.set_DataElementValue(2, 3, "6"); // Code list responsible agency, coded (3055) oSegment.set_DataElementValue(3, 1, "PH"); // Related place/location one identification (3223) oSegment.set_DataElementValue(3, 2, "162"); // Code list qualifier (1131) oSegment.set_DataElementValue(3, 3, "5"); // Code list responsible agency, coded (3055) } // TDT group // LOC group bool bLoc01 = true; int nLocCount = 0; while (bLoc01 == true && nLocCount < 2) //loop twice just to demo loop repeat { oSegment = oMessage.CreateDataSegment(@"LOC\LOC"); //this is the first instance of the LOC segment in the group in the LOC group oSegment.set_DataElementValue(1, 0, "147"); // Place/location qualifier (3227) oSegment.set_DataElementValue(2, 1, "24C9917"); // Place/location identification (3225) oSegment.set_DataElementValue(2, 2, ""); // Code list qualifier (1131) oSegment.set_DataElementValue(2, 3, "5"); // Code list responsible agency, coded (3055) // Goods item details (GID) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"LOC\GID")); oSegment.set_DataElementValue(1, 0, ""); // Goods item number (1496) oSegment.set_DataElementValue(2, 1, "1"); // Number of packages (7224) // Free text (FTX) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"LOC\FTX")); oSegment.set_DataElementValue(1, 0, "HAN"); // Text subject qualifier (4451) oSegment.set_DataElementValue(4, 1, "OD"); // Free text (4440) // Measurements (MEA) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"LOC\MEA")); oSegment.set_DataElementValue(1, 0, "WT"); // Measurement purpose qualifier (6311) oSegment.set_DataElementValue(3, 1, "LBR"); // Measure unit qualifier (6411) oSegment.set_DataElementValue(3, 2, "16723"); // Measurement value (6314) // Place/location identification (LOC) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"LOC\LOC(2)")); //this is the second instance of the LOC segment in the LOC group oSegment.set_DataElementValue(1, 0, "9"); // Place/location qualifier (3227) oSegment.set_DataElementValue(2, 1, "USOAK"); // Place/location identification (3225) oSegment.set_DataElementValue(2, 2, "139"); // Code list qualifier (1131) oSegment.set_DataElementValue(2, 3, "6"); // Code list responsible agency, coded (3055) oSegment.set_DataElementValue(3, 1, "US"); // Related place/location one identification (3223) oSegment.set_DataElementValue(3, 2, "162"); // Code list qualifier (1131) oSegment.set_DataElementValue(3, 3, "5"); // Code list responsible agency, coded (3055) oSegment.set_DataElementValue(4, 1, "CA"); // Related place/location two identification (3233) oSegment.set_DataElementValue(4, 2, "163"); // Code list qualifier (1131) // Place/location identification (LOC) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"LOC\LOC(3)")); //this is the third instance of the LOC segment in the LOC group oSegment.set_DataElementValue(1, 0, "11"); // Place/location qualifier (3227) oSegment.set_DataElementValue(2, 1, "SGSIN"); // Place/location identification (3225) oSegment.set_DataElementValue(2, 2, "139"); // Code list qualifier (1131) oSegment.set_DataElementValue(2, 3, "6"); // Code list responsible agency, coded (3055) oSegment.set_DataElementValue(3, 1, "SG"); // Related place/location one identification (3223) oSegment.set_DataElementValue(3, 2, "162"); // Code list qualifier (1131) oSegment.set_DataElementValue(3, 3, "5"); // Code list responsible agency, coded (3055) // Place/location identification (LOC) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"LOC\LOC(4)")); //this is the fourth instance of the LOC segment in the LOC group oSegment.set_DataElementValue(1, 0, "83"); // Place/location qualifier (3227) oSegment.set_DataElementValue(2, 1, "FRLEH"); // Place/location identification (3225) // Reference (RFF) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"LOC\RFF")); oSegment.set_DataElementValue(1, 1, "BM"); // Reference qualifier (1153) oSegment.set_DataElementValue(1, 2, "1"); // Reference number (1154) // EQD GROUP bool bLocEqd01 = true; if (bLocEqd01 == true) { oSegment = oMessage.CreateDataSegment(@"LOC\EQD\EQD"); oSegment.set_DataElementValue(1, 0, "CN"); // Equipment qualifier (8053) oSegment.set_DataElementValue(2, 1, "MDSFL234"); // Equipment identification number (8260) oSegment.set_DataElementValue(3, 1, "4310"); // Equipment size and type identification (8155) oSegment.set_DataElementValue(6, 0, "5"); // Full/empty indicator, coded (8169) // Name and address (NAD) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"LOC\EQD\NAD")); oSegment.set_DataElementValue(1, 0, "CA"); // Party qualifier (3035) oSegment.set_DataElementValue(2, 1, "ABCU"); // Party identification (3039) oSegment.set_DataElementValue(2, 2, "172"); // Code list qualifier (1131) oSegment.set_DataElementValue(2, 3, "20"); // Code list responsible agency, coded (3055) } // LOC\EQD GROUP // DGS GROUP bool bLocDgs = true; if (bLocDgs == true) { oSegment = oMessage.CreateDataSegment(@"LOC\DGS\DGS"); oSegment.set_DataElementValue(1, 0, "IMD"); // Dangerous goods regulations, coded (8273) oSegment.set_DataElementValue(2, 1, "9"); // Hazard code identification (8351) oSegment.set_DataElementValue(3, 1, "3077"); // UNDG number (7124) oSegment.set_DataElementValue(4, 1, "3"); // Shipment flashpoint (7106) } // LOC\DGS GROUP nLocCount = nLocCount + 1; } // LOC GROUP // Trailing segments are automatically created when Framework EDI commits // (saves) the instance of "oEdiDoc" object into an EDI file. oEdiDoc.Save(sPath + sEdiFileName, 0); // Show EDI string on screen MessageBox.Show(oEdiDoc.GetEdiString()); }