private void btnGenerate_Click(object sender, EventArgs e) { ediDocument oEdiDoc; ediSchema oSchema; ediSchemas oSchemas; ediInterchange oInterchange; ediGroup oGroup; ediTransactionSet oMessage; ediDataSegment oSegment; string sPath = AppDomain.CurrentDomain.BaseDirectory; string sEdiFileName = "PAXLST.EDI"; string sSefFileName = "PAXLST_D05B_MODIFIED.SEF"; //"PAXLST_D05B.SEF"; // 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 = "?"; oEdiDoc.RepeatSeparator = "^"; // not necessary to specify repeating element separator because this message has repeating elements removed (see COM segment) //Creates UNA segment oEdiDoc.set_Option(DocumentOptionIDConstants.OptDocument_ServiceSegment, 1); // 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", "D05B"); oSegment = (ediDataSegment)oInterchange.GetDataSegmentHeader(); oSegment.set_DataElementValue(1, 1, "UNOA"); // Syntax identifier (0001) oSegment.set_DataElementValue(1, 2, "4"); // Syntax version number (0002) oSegment.set_DataElementValue(2, 1, "APIS*ABE"); // Interchange sender identification (0004) oSegment.set_DataElementValue(3, 1, "USADHS"); // Recipient identification (0010) oSegment.set_DataElementValue(4, 1, "070429"); // Date (0017) oSegment.set_DataElementValue(4, 2, "0900"); // Time (0019) oSegment.set_DataElementValue(5, 0, "000000001"); // Interchange control reference (0020) oSegment.set_DataElementValue(6, 1, ""); // Recipient reference/password (0022) oSegment.set_DataElementValue(6, 2, ""); // Recipient's reference/password qualifier (0025) oSegment.set_DataElementValue(7, 0, "USADHS"); // Application reference (0026) // Creates the Functional Group Header segment (UNG). oGroup = (ediGroup)oInterchange.CreateGroup("D05B"); ediDataSegment.Set(ref oSegment, (ediDataSegment)oGroup.GetDataSegmentHeader()); oSegment.set_DataElementValue(1, 0, "PAXLST"); // Message group identification (0038) oSegment.set_DataElementValue(2, 1, "XYZ AIRLINES"); // Application sender identification (0040) oSegment.set_DataElementValue(3, 1, "USADHS"); // Application recipient identification (0044) oSegment.set_DataElementValue(4, 1, "070429"); // Date (0017) oSegment.set_DataElementValue(4, 2, "0900"); // Time (0019) oSegment.set_DataElementValue(5, 0, "100"); // Group reference number (0048) oSegment.set_DataElementValue(6, 0, "UN"); // Controlling agency (0051) oSegment.set_DataElementValue(8, 0, "A1B2C3D4E5"); // Application password (0058) oSegment.set_DataElementValue(7, 1, "D"); // Message version number (0052) oSegment.set_DataElementValue(7, 2, "05B"); // Message release number (0054) // MESSAGE ID PAXLST - Passenger list message // Creates the Message header segment (UNH). oMessage = (ediTransactionSet)oGroup.CreateTransactionSet("PAXLST"); ediDataSegment.Set(ref oSegment, (ediDataSegment)oMessage.GetDataSegmentHeader()); oSegment.set_DataElementValue(1, 0, "PAX001"); // Message reference number (0062) oSegment.set_DataElementValue(2, 1, "PAXLST"); // Message type identifier (0065) oSegment.set_DataElementValue(2, 2, "D"); // Message version number (0052) oSegment.set_DataElementValue(2, 3, "05B"); // Message release number (0054) oSegment.set_DataElementValue(2, 4, "UN"); // Controlling agency (0051) oSegment.set_DataElementValue(2, 5, "IATA"); // Association assigned code (0057) oSegment.set_DataElementValue(3, 0, "API01"); // Common access reference oSegment.set_DataElementValue(4, 1, "01"); // Sequence of transfers (0070) // Beginning of message (BGM) oSegment = oMessage.CreateDataSegment("BGM"); oSegment.set_DataElementValue(1, 1, "745"); // Document/message name, coded (1001) oSegment.set_DataElementValue(2, 1, ""); // Document/message number (1004) // Reference (RFF) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment("RFF")); oSegment.set_DataElementValue(1, 1, "TN"); // Reference qualifier (1153) oSegment.set_DataElementValue(1, 2, "BA123456789"); // Reference number (1154) oSegment.set_DataElementValue(1, 5, "1"); // Revision number (1060) oSegment = oMessage.CreateDataSegment(@"NAD\NAD"); oSegment.set_DataElementValue(1, 0, "MS"); // Party qualifier (3035) oSegment.set_DataElementValue(4, 1, "JACKSON"); // Party name (3036) // Communication contact (COM) //The standard for this COM segment is that it has a one composite element that can be repeated 3 times (repeating element). //However, the CPB guideline has the COM segment with two composite elements and are not repeating elements. So the SEF file //was modified to reflect this change. ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD\COM")); //oSegment.set_DataElementValue(1, 1, 1, "703-555-1234"); // Communication number (3148) //oSegment.set_DataElementValue(1, 2, 1, "TE"); // Communication channel qualifier (3155) //oSegment.set_DataElementValue(1, 1, 2, "703-555-9876"); // Communication number (3148) //oSegment.set_DataElementValue(1, 2, 2, "FX"); // Communication channel qualifier (3155) oSegment.set_DataElementValue(1, 1, "703-555-1234"); // Communication number (3148) oSegment.set_DataElementValue(1, 2, "TE"); // Communication channel qualifier (3155) oSegment.set_DataElementValue(2, 1, "703-555-9876"); // Communication number (3148) oSegment.set_DataElementValue(2, 2, "FX"); // Communication channel qualifier (3155) // Transport information (TDT) oSegment = oMessage.CreateDataSegment(@"TDT\TDT"); oSegment.set_DataElementValue(1, 0, "20"); // Transport stage qualifier (8051) oSegment.set_DataElementValue(2, 0, "UA123"); // Conveyance reference number (8028) oSegment.set_DataElementValue(5, 1, "UA"); // Carrier identification (3127) // Place/location identification (LOC) oSegment = oMessage.CreateDataSegment(@"TDT\LOC\LOC"); oSegment.set_DataElementValue(1, 0, "125"); // Place/location qualifier (3227) oSegment.set_DataElementValue(2, 1, "YVR"); // Place/location identification (3225) // Date/time/period (DTM) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"TDT\LOC\DTM")); oSegment.set_DataElementValue(1, 1, "189"); // Date/time/period qualifier (2005) oSegment.set_DataElementValue(1, 2, "0704291230"); // Date/time/period (2380) oSegment.set_DataElementValue(1, 3, "201"); // Date/time/period format qualifier (2379) // Place/location identification (LOC) oSegment = oMessage.CreateDataSegment(@"TDT\LOC\LOC"); oSegment.set_DataElementValue(1, 0, "87"); // Place/location qualifier (3227) oSegment.set_DataElementValue(2, 1, "JFK"); // Place/location identification (3225) // Date/time/period (DTM) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"TDT\LOC\DTM")); oSegment.set_DataElementValue(1, 1, "232"); // Date/time/period qualifier (2005) oSegment.set_DataElementValue(1, 2, "0704291600"); // Date/time/period (2380) oSegment.set_DataElementValue(1, 3, "201"); // Date/time/period format qualifier (2379) // Transport information (TDT) oSegment = oMessage.CreateDataSegment(@"TDT\TDT"); oSegment.set_DataElementValue(1, 0, "20"); // Transport stage qualifier (8051) oSegment.set_DataElementValue(2, 0, "UA124"); // Conveyance reference number (8028) oSegment.set_DataElementValue(5, 1, "UA"); // Carrier identification (3127) // Place/location identification (LOC) oSegment = oMessage.CreateDataSegment(@"TDT\LOC\LOC"); oSegment.set_DataElementValue(1, 0, "92"); // Place/location qualifier (3227) oSegment.set_DataElementValue(2, 1, "ATL"); // Place/location identification (3225) // Date/time/period (DTM) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"TDT\LOC\DTM")); oSegment.set_DataElementValue(1, 1, "189"); // Date/time/period qualifier (2005) oSegment.set_DataElementValue(1, 2, "0704291730"); // Date/time/period (2380) oSegment.set_DataElementValue(1, 3, "201"); // Date/time/period format qualifier (2379) // Place/location identification (LOC) oSegment = oMessage.CreateDataSegment(@"TDT\LOC\LOC"); oSegment.set_DataElementValue(1, 0, "87"); // Place/location qualifier (3227) oSegment.set_DataElementValue(2, 1, "JFK"); // Place/location identification (3225) // Date/time/period (DTM) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"TDT\LOC\DTM")); oSegment.set_DataElementValue(1, 1, "232"); // Date/time/period qualifier (2005) oSegment.set_DataElementValue(1, 2, "0704291945"); // Date/time/period (2380) oSegment.set_DataElementValue(1, 3, "201"); // Date/time/period format qualifier (2379) //***** THE SEF FILE HAD TO BE MODIFIED TO CHANGE THIS SECTION TO BE AREA 2 TO DIFFERENTIATE //***** THIS NAD GROUP FROM THE FIRST ONE // Name and address (NAD) oSegment = oMessage.CreateDataSegment(@"NAD#2\NAD"); oSegment.set_DataElementValue(1, 0, "FL"); // Party qualifier (3035) oSegment.set_DataElementValue(4, 1, "DOE"); // Party name (3036) oSegment.set_DataElementValue(4, 2, "JOE"); // Party name (3036) oSegment.set_DataElementValue(4, 3, "WAYNE"); // Party name (3036) oSegment.set_DataElementValue(5, 1, "20 MAIN ST"); // Street and number/p.o. box (3042) oSegment.set_DataElementValue(6, 0, "ANYCITY"); // City name (3164) oSegment.set_DataElementValue(7, 1, "VA"); // Country sub-entity identification (3229) oSegment.set_DataElementValue(8, 0, "10053"); // Postcode identification (3251) oSegment.set_DataElementValue(9, 0, "USA"); // Country, coded (3207) // Attribute (ATT) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\ATT")); oSegment.set_DataElementValue(1, 0, "2"); // Attribute function qualifier (9017) oSegment.set_DataElementValue(3, 1, "M"); // Attribute identification (9019) // Date/time/period (DTM) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\DTM")); oSegment.set_DataElementValue(1, 1, "329"); // Date/time/period qualifier (2005) oSegment.set_DataElementValue(1, 2, "570121"); // Date/time/period (2380) //// Processing information (GEI) //ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\GEI")); //oSegment.set_DataElementValue(1, 0, "4"); // Processing information code qualifier (9649) //oSegment.set_DataElementValue(2, 1, "ZZZ"); // Processing indicator, coded (7365) // Free text (FTX) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\FTX")); oSegment.set_DataElementValue(1, 0, "BAG"); // Text subject qualifier (4451) oSegment.set_DataElementValue(4, 1, "UA123456"); // Free text (4440) oSegment.set_DataElementValue(4, 2, "3"); // Free text (4440) // Place/location identification (LOC) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\LOC")); oSegment.set_DataElementValue(1, 0, "22"); // Place/location qualifier (3227) oSegment.set_DataElementValue(2, 1, "JFK"); // Place/location identification (3225) //oSegment.set_DataElementValue(3, 1, "A1B2C3D4E5"); // Related place/location one identification (3223) //oSegment.set_DataElementValue(4, 1, "A1B2C3D4E5"); // Related place/location two identification (3233) // Place/location identification (LOC) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\LOC(2)")); oSegment.set_DataElementValue(1, 0, "178"); // Place/location qualifier (3227) oSegment.set_DataElementValue(2, 1, "YVR"); // Place/location identification (3225) //oSegment.set_DataElementValue(3, 1, "A1B2C3D4E5"); // Related place/location one identification (3223) //oSegment.set_DataElementValue(4, 1, "A1B2C3D4E5"); // Related place/location two identification (3233) // Place/location identification (LOC) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\LOC(3)")); oSegment.set_DataElementValue(1, 0, "179"); // Place/location qualifier (3227) oSegment.set_DataElementValue(2, 1, "ATL"); // Place/location identification (3225) //oSegment.set_DataElementValue(3, 1, "A1B2C3D4E5"); // Related place/location one identification (3223) //oSegment.set_DataElementValue(4, 1, "A1B2C3D4E5"); // Related place/location two identification (3233) // Place/location identification (LOC) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\LOC(4)")); oSegment.set_DataElementValue(1, 0, "174"); // Place/location qualifier (3227) oSegment.set_DataElementValue(2, 1, "CAN"); // Place/location identification (3225) //oSegment.set_DataElementValue(3, 1, "A1B2C3D4E5"); // Related place/location one identification (3223) //oSegment.set_DataElementValue(4, 1, "A1B2C3D4E5"); // Related place/location two identification (3233) // Communication contact (COM) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\COM")); oSegment.set_DataElementValue(1, 1, "502-555-1234"); // Communication number (3148) oSegment.set_DataElementValue(1, 2, "TE"); // Communication channel qualifier (3155) //// Employment details (EMP) //ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\EMP")); //oSegment.set_DataElementValue(1, 0, "1"); // Employment qualifier (9003) //oSegment.set_DataElementValue(2, 1, "A1B"); // Employment category, coded (9005) //oSegment.set_DataElementValue(2, 2, "A1B2C3D4E5"); // Code list qualifier (1131) //oSegment.set_DataElementValue(2, 3, "1"); // Code list responsible agency, coded (3055) // Nationality (NAT) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\NAT")); oSegment.set_DataElementValue(1, 0, "2"); // Nationality qualifier (3493) oSegment.set_DataElementValue(2, 1, "CAN"); // Nationality, coded (3293) // Reference (RFF) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\RFF")); oSegment.set_DataElementValue(1, 1, "AVF"); // Reference qualifier (1153) oSegment.set_DataElementValue(1, 2, "ABC123"); // Reference number (1154) // Reference (RFF) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\RFF(2)")); oSegment.set_DataElementValue(1, 1, "ABO"); // Reference qualifier (1153) oSegment.set_DataElementValue(1, 2, "BA1321654987"); // Reference number (1154) // Reference (RFF) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\RFF(3)")); oSegment.set_DataElementValue(1, 1, "AEA"); // Reference qualifier (1153) oSegment.set_DataElementValue(1, 2, "1234567890ABC"); // Reference number (1154) // Reference (RFF) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\RFF(4)")); oSegment.set_DataElementValue(1, 1, "CR"); // Reference qualifier (1153) oSegment.set_DataElementValue(1, 2, "20060907NY123"); // Reference number (1154) // Reference (RFF) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\RFF(5)")); oSegment.set_DataElementValue(1, 1, "SEA"); // Reference qualifier (1153) oSegment.set_DataElementValue(1, 2, "23C"); // Reference number (1154) // Document/message details (DOC) oSegment = oMessage.CreateDataSegment(@"NAD#2\DOC\DOC"); oSegment.set_DataElementValue(1, 1, "P"); // Document/message name, coded (1001) oSegment.set_DataElementValue(1, 2, "110"); // Code list qualifier (1131) oSegment.set_DataElementValue(1, 3, "111"); // Code list responsible agency, coded (3055) oSegment.set_DataElementValue(2, 1, "MB1402411"); // Document/message number (1004) // Date/time/period (DTM) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\DOC\DTM")); oSegment.set_DataElementValue(1, 1, "36"); // Date/time/period qualifier (2005) oSegment.set_DataElementValue(1, 2, "081021"); // Date/time/period (2380) // Place/location identification (LOC) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment(@"NAD#2\DOC\LOC")); oSegment.set_DataElementValue(1, 0, "91"); // Place/location qualifier (3227) oSegment.set_DataElementValue(2, 1, "CAN"); // Place/location identification (3225) // Control total (CNT) ediDataSegment.Set(ref oSegment, oMessage.CreateDataSegment("CNT")); // Control (C270) oSegment.set_DataElementValue(1, 1, "42"); // Control qualifier (6069) oSegment.set_DataElementValue(1, 2, "1"); // Control value (6066) // Trailing segments are automatically created when Framework EDI commits // (saves) the instance of "oEdiDoc" object into an EDI file. oEdiDoc.Save(sPath + sEdiFileName, 0); MessageBox.Show(oEdiDoc.GetEdiString()); } }