private void btnTranslate_Click(object sender, EventArgs e)
        {
            ediDocument oEdiDoc;
            ediSchema oSchema;
            ediSchemas oSchemas;
            ediDataSegment oSegment;
            ediDataElement oElement = null;
            string sSegmentID = "";
            string sValue = "";
            string sLoopSection = "";
            string sEdiFileName = "";
            string sSefFileName = "";
            int nArea = 0;
            string sQlfr = "";
            string sPartyQlfr = "";
            string sPartyDesc = "";
            string sDocQlfr = "";
            string sDocDesc = "";
            

            string sPath = AppDomain.CurrentDomain.BaseDirectory;

            // Create the top-level application object "ediDocument". 
            oEdiDoc = new ediDocument();

            // For UN/EDIFACT documents, specify the terminators, indicators,  and separators 
            // because it does not automatically detect from the document.  If there is 
            // a UNA Service Segment, which specifies the delimiters then these steps 
            // are not necessary. 
            oEdiDoc.SegmentTerminator = "'{13:10}";
            oEdiDoc.ElementTerminator = "+";
            oEdiDoc.CompositeTerminator = ":";
            oEdiDoc.ReleaseIndicator = "?";

            // 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 translate 
            // the EDI document 
            oSchemas = (ediSchemas) oEdiDoc.GetSchemas();
            oSchemas.EnableStandardReference = false;

            // The FORWARD-ONLY cursor increases the performance of processing the EDI 
            // document (see Technical Note 3 below). 
            oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardOnly;
            sEdiFileName = sPath + "PAXLST.EDI";
            sSefFileName = sPath + "PAXLST_D05B_MODIFIED.SEF";

            // Specify SEF file to load. 
            oSchema = (ediSchema) oEdiDoc.LoadSchema(sSefFileName, SchemaTypeIDConstants.Schema_Standard_Exchange_Format);

            // Specify EDI document to read. 
            oEdiDoc.LoadEdi(sEdiFileName);

            // Gets the first data segment in the EDI document. 
            oSegment = (ediDataSegment) oEdiDoc.FirstDataSegment;

            // Loop that will traverse through the EDI document from top to bottom. This 
            // is required for FORWARD-ONLY cursor. 
            while (oSegment != null)
            {

                // Data segments are uniquely identified by their segment Identifier (ID). 
                // The loop section and the area (or table) properties of the data segment 
                // are read for each iteration of the loop.  
                sSegmentID = oSegment.ID;
                sLoopSection = oSegment.LoopSection;
                nArea = oSegment.Area;

                if (nArea == 0)
                {

                    // Data segments that are not designated an area (i.e. area = 0)  
                    // are control segments that are part of the Interchange or  
                    // Functional Group envelopes, and are not part of the Message. 

                    if (sSegmentID == "UNB")
                    {
                        listBox1.Items.Add("Interchange control reference: " + oSegment.get_DataElementValue(5, 0));         // Interchange control reference (0020) 
                        sValue = oSegment.get_DataElementValue(7, 0);         // Application reference (0026) 
                        sValue = oSegment.get_DataElementValue(8, 0);         // Processing priority code (0029) 
                        sValue = oSegment.get_DataElementValue(9, 0);         // Acknowledgement request (0031) 
                        sValue = oSegment.get_DataElementValue(10, 0);         // Interchange Agreement Identifier (0032) 
                        sValue = oSegment.get_DataElementValue(11, 0);         // Test indicator (0035) 
                        // Syntax identifier (S001) 
                        sValue = oSegment.get_DataElementValue(1, 1);         // Syntax identifier (0001) 
                        sValue = oSegment.get_DataElementValue(1, 2);         // Syntax version number (0002) 
                        sValue = oSegment.get_DataElementValue(1, 3);         // Service code list directory version number (0080) 
                        sValue = oSegment.get_DataElementValue(1, 4);         // Character encoding, coded (0133) 
                        // Interchange sender (S002) 
                        listBox1.Items.Add("" + oSegment.get_DataElementValue(2, 1));         // Interchange sender identification (0004) 
                        sValue = oSegment.get_DataElementValue(2, 2);         // Partner identification code qualifier (0007) 
                        sValue = oSegment.get_DataElementValue(2, 3);         // Interchange sender internal identification (0008) 
                        sValue = oSegment.get_DataElementValue(2, 4);         // Interchange sender internal sub-identification (0042) 
                        // Interchange recipient (S003) 
                        listBox1.Items.Add("" + oSegment.get_DataElementValue(3, 1));         // Recipient identification (0010) 
                        sValue = oSegment.get_DataElementValue(3, 2);         // Partner identification code qualifier (0007) 
                        sValue = oSegment.get_DataElementValue(3, 3);         // Routing address (0014) 
                        sValue = oSegment.get_DataElementValue(3, 4);         // Interchange Recipient Internal Sub-Identification (0046) 
                        // Date and time of preparation (S004) 
                        sValue = oSegment.get_DataElementValue(4, 1);         // Date (0017) 
                        sValue = oSegment.get_DataElementValue(4, 2);         // Time (0019) 
                        // Recipient reference/password details (S005) 
                        sValue = oSegment.get_DataElementValue(6, 1);         // Recipient reference/password (0022) 
                        sValue = oSegment.get_DataElementValue(6, 2);         // Recipient's reference/password qualifier (0025) 

                    }
                    else if (sSegmentID == "UNZ")
                    {
                        sValue = oSegment.get_DataElementValue(1, 0);         // Interchange control count (0036) 
                        sValue = oSegment.get_DataElementValue(2, 0);         // Interchange control reference (0020) 

                    }
                    else if (sSegmentID == "UNG")
                    {
                        listBox1.Items.Add("" + oSegment.get_DataElementValue(1, 0));         // Message group identification (0038) 
                        sValue = oSegment.get_DataElementValue(5, 0);         // Group reference number (0048) 
                        sValue = oSegment.get_DataElementValue(6, 0);         // Controlling agency (0051) 
                        sValue = oSegment.get_DataElementValue(8, 0);         // Application password (0058) 
                        // Application sender identification (S006) 
                        sValue = oSegment.get_DataElementValue(2, 1);         // Application sender identification (0040) 
                        sValue = oSegment.get_DataElementValue(2, 2);         // Partner identification code qualifier (0007) 
                        // Application recipient identification (S007) 
                        sValue = oSegment.get_DataElementValue(3, 1);         // Application recipient identification (0044) 
                        sValue = oSegment.get_DataElementValue(3, 2);         // Partner identification code qualifier (0007) 
                        // Date and time of preparation (S004) 
                        sValue = oSegment.get_DataElementValue(4, 1);         // Date (0017) 
                        sValue = oSegment.get_DataElementValue(4, 2);         // Time (0019) 
                        // Message version (S008) 
                        sValue = oSegment.get_DataElementValue(7, 1);         // Message version number (0052) 
                        sValue = oSegment.get_DataElementValue(7, 2);         // Message release number (0054) 
                        sValue = oSegment.get_DataElementValue(7, 3);         // Association assigned code (0057) 

                    }
                    else if (sSegmentID == "UNE")
                    {
                        sValue = oSegment.get_DataElementValue(1, 0);         // Group control count (0060) 
                        sValue = oSegment.get_DataElementValue(2, 0);         // Group reference number (0048) 

                    }         // sSegmentID == "UNE" 

                }
                else if (nArea == 1)
                {

                    // Data segments in area 1 are processed here. 

                    if (sLoopSection == "")
                    {

                        if (sSegmentID == "UNH")         // Message header 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Message reference number (0062) 
                            sValue = oSegment.get_DataElementValue(2, 1);         // Message type identifier (0065) 
                            sValue = oSegment.get_DataElementValue(2, 2);         // Message version number (0052) 
                            sValue = oSegment.get_DataElementValue(2, 3);         // Message release number (0054) 
                            sValue = oSegment.get_DataElementValue(2, 4);         // Controlling agency (0051) 
                            sValue = oSegment.get_DataElementValue(2, 5);         // Association assigned code (0057) 
                            listBox1.Items.Add("" + oSegment.get_DataElementValue(3, 0));         // Common access reference (0068) 
                            sValue = oSegment.get_DataElementValue(4, 1);         // Sequence of transfers (0070) 
                            
                        }
                        else if (sSegmentID == "BGM")         // Beginning of message 
                        {
                            listBox1.Items.Add("" + oSegment.get_DataElementValue(1, 1));         // Document/message name, coded (1001) 
                            sValue = oSegment.get_DataElementValue(1, 2);         // Code list qualifier (1131) 
                            
                        }
                        else if (sSegmentID == "RFF")         // Reference 
                        {
                            sValue = oSegment.get_DataElementValue(1, 1);         // Reference qualifier (1153) 
                            listBox1.Items.Add("" + oSegment.get_DataElementValue(1, 2));         // Reference number (1154) 
                            sValue = oSegment.get_DataElementValue(1, 5);         // Revision number (1060) 

                        }
                        
                    }
                    else if (sLoopSection == "NAD")
                    {

                        if (sSegmentID == "NAD")         // Name and address 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Party qualifier (3035) 
                            listBox1.Items.Add("Reporting party name: " + oSegment.get_DataElementValue(4, 1));         // Party name (3036) 
                            
                        }
                        
                        else if (sSegmentID == "COM")         // Communication contact 
                        {
                            ediDataElement.Set(ref oElement, oSegment.get_DataElement(1));    //repeating element

                            //// This is the algorithm for reading a repeating element.  However, the CPB guideline
                            //// has this element not repeating, but instead adding a similar composite element in the 
                            //// same COM segment.  So the SEF file was modified to reflect that change.
                            //int nRepeat = oElement.RepeatCount;        // get repeating element count

                            //for (int i = 1; i <= nRepeat; i++)
                            //{
                            //    if (oSegment.get_DataElementValue(1, 2, i) == "TE")
                            //    {
                            //        listBox1.Items.Add("Telephone: " + Convert.ToString(i) + " = " + oSegment.get_DataElementValue(1,1, i));     //Communication number (3148) 
                            //    }
                            //    else if (oSegment.get_DataElementValue(1, 2, i) == "FX")
                            //    {
                            //        listBox1.Items.Add("Fax: " + Convert.ToString(i) + " = " + oSegment.get_DataElementValue(1, 1, i));     //Communication number (3148) 
                            //    }
                                
                            //}
                            //oElement.Dispose(); 

                            listBox1.Items.Add("Telephone: " + " = " + oSegment.get_DataElementValue(1, 1));     //Communication number (3148) 
                            listBox1.Items.Add("Fax: " + " = " + oSegment.get_DataElementValue(2, 1));     //Communication number (3148) 

                        }         // sSegmentID == "COM" 

                    }
                    else if (sLoopSection == "TDT")
                    {

                        if (sSegmentID == "TDT")         // Transport information 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Transport stage qualifier (8051) 
                            listBox1.Items.Add("" + oSegment.get_DataElementValue(2, 0));         // Conveyance reference number (8028) 
                            sValue = oSegment.get_DataElementValue(5, 1);         // Carrier identification (3127) 
                            
                        }
                        
                    }
                    else if (sLoopSection == "TDT;LOC")
                    {

                        if (sSegmentID == "LOC")         // Place/location identification 
                        {
                            listBox1.Items.Add("" + oSegment.get_DataElementValue(1, 0));         // Place/location qualifier (3227) 
                            listBox1.Items.Add("" + oSegment.get_DataElementValue(2, 1));         // Place/location identification (3225) 
                            
                        }
                        else if (sSegmentID == "DTM")         // Date/time/period 
                        {
                            sQlfr = oSegment.get_DataElementValue(1, 1);         // Date/time/period qualifier (2005) 
                            if (sQlfr == "189")
                            {
                                listBox1.Items.Add("Departure Date/Time: " + oSegment.get_DataElementValue(1, 2));         // Date/time/period (2380) 
                                sValue = oSegment.get_DataElementValue(1, 3);         // Date/time/period format qualifier (2379) 
                            }
                            else if (sQlfr == "232")
                            {
                                listBox1.Items.Add("Arrival Date/Time: " + oSegment.get_DataElementValue(1, 2));         // Date/time/period (2380) 
                                sValue = oSegment.get_DataElementValue(1, 3);         // Date/time/period format qualifier (2379) 
                            }
                            
                        }         // sSegmentID == "DTM" 

                    }         // sLoopSection == "TDT;LOC" 

                }
                else if (nArea == 2)  //The SEF file was sectioned into two areas.
                {
                    
                    // Data segments in area 2 are processed here. 

                    if (sLoopSection == "")
                    {

                        // Nothing to do. 

                    }
                    else if (sLoopSection == "NAD")
                    {
                        
                        if (sSegmentID == "NAD")         // Name and address 
                        {
                            sPartyQlfr = oSegment.get_DataElementValue(1, 0);         // Party qualifier (3035) 

                            if (sPartyQlfr == "FL")
                                sPartyDesc = "Passenger";

                            else if (sPartyQlfr == "FM")
                                sPartyDesc = "Crew member";

                            else if (sPartyQlfr == "DDU")
                                sPartyDesc = "Intransit Passenger";

                            else if (sPartyQlfr == "DDT")
                                sPartyDesc = "Intransit Crew Member";

                            else if (sPartyQlfr == "COT")
                                sPartyDesc = "Involved Party - Gate Pass request";

                            else if (sPartyQlfr == "ZZZ")
                                sPartyDesc = "For Cancel Reservation and Flight Close-out messages";

                            listBox1.Items.Add(sPartyDesc + " Last name: " + oSegment.get_DataElementValue(4, 1));         // Party name (3036) 
                            listBox1.Items.Add(sPartyDesc + " First name: " + oSegment.get_DataElementValue(4, 2));         // Party name (3036) 
                            listBox1.Items.Add(sPartyDesc + " Second name: " + oSegment.get_DataElementValue(4, 3));         // Party name (3036) 
                            listBox1.Items.Add(sPartyDesc + " Final Destination: " + oSegment.get_DataElementValue(5, 1));         // Street and number/p.o. box (3042) 
                            listBox1.Items.Add("Final Destination City: " + oSegment.get_DataElementValue(6, 0));         // City name (3164) 
                            sValue = oSegment.get_DataElementValue(7, 1);         // Country sub-entity identification (3229) 
                            sValue = oSegment.get_DataElementValue(8, 0);         // Postcode identification (3251) 
                            listBox1.Items.Add("Final Destination Country: " + oSegment.get_DataElementValue(9, 0));         // Country, coded (3207) 

                        }
                        else if (sSegmentID == "ATT")         // Attribute 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Attribute function qualifier (9017) 
                            listBox1.Items.Add(sPartyDesc + " Gender: " + oSegment.get_DataElementValue(3, 1));         // Attribute identification (9019) 
                            
                        }
                        else if (sSegmentID == "DTM")         // Date/time/period 
                        {
                            sValue = oSegment.get_DataElementValue(1, 1);         // Date/time/period qualifier (2005) 
                            listBox1.Items.Add(sPartyDesc + " Date of Birth: " + oSegment.get_DataElementValue(1, 2));         // Date/time/period (2380) 
                            
                        }
                        
                        else if (sSegmentID == "GEI")         // Processing information 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Processing information code qualifier (9649) 
                            sValue = oSegment.get_DataElementValue(2, 1);         // Processing indicator, coded (7365) 
                            sValue = oSegment.get_DataElementValue(2, 2);         // Code list qualifier (1131) 
                            sValue = oSegment.get_DataElementValue(2, 3);         // Code list responsible agency, coded (3055) 
                            sValue = oSegment.get_DataElementValue(2, 4);         //  (7364) 
                            sValue = oSegment.get_DataElementValue(3, 0);         // Process type identification (7187) 

                        }
                        else if (sSegmentID == "FTX")         // Free text 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Text subject qualifier (4451) 
                            listBox1.Items.Add(sPartyDesc + " Bag Tag Information: " + oSegment.get_DataElementValue(4, 1));         // Free text (4440) 
                            sValue = oSegment.get_DataElementValue(4, 2);         // Free text (4440) 
                            
                        }
                        else if (sSegmentID == "LOC")         // Place/location identification 
                        {

                            string sLocQlfr = oSegment.get_DataElementValue(1, 0);         // Place/location qualifier (3227)

                            string sLocDesc = "";

                            if (sLocQlfr == "22")
                                sLocDesc = "Airport of first US arrival (Inbound international flights)";

                            else if (sLocQlfr == "174")
                                sLocDesc = "Country of residence (Inbound international flights)";

                            else if (sLocQlfr == "178")
                                sLocDesc = "Port of embarkation";

                            else if (sLocQlfr == "179")
                                sLocDesc = "Port of debarkation";

                            else if (sLocQlfr == "180")
                                sLocDesc = "Place of birth (Crew member reporting only)";


                            listBox1.Items.Add(sPartyDesc + " " + sLocDesc + ": " + oSegment.get_DataElementValue(2, 1));         // Place/location identification (3225) 
                            sValue = oSegment.get_DataElementValue(3, 1);         // Related place/location one identification (3223) 
                            sValue = oSegment.get_DataElementValue(4, 1);         // Related place/location two identification (3233) 
                            
                        }
                        else if (sSegmentID == "COM")         // Communication contact 
                        {
                            listBox1.Items.Add(sPartyDesc + " Phone: " + oSegment.get_DataElementValue(1, 1));         // Communication number (3148) 
                            sValue = oSegment.get_DataElementValue(1, 2);         // Communication channel qualifier (3155) 

                        }
                        else if (sSegmentID == "EMP")         // Employment details 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Employment qualifier (9003) 
                            listBox1.Items.Add(sPartyDesc + " Employment: " + oSegment.get_DataElementValue(2, 1));         // Employment category, coded (9005) 
                            sValue = oSegment.get_DataElementValue(2, 2);         // Code list qualifier (1131) 
                            sValue = oSegment.get_DataElementValue(2, 3);         // Code list responsible agency, coded (3055) 
                            
                        }
                        else if (sSegmentID == "NAT")         // Nationality 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Nationality qualifier (3493) 
                            listBox1.Items.Add(sPartyDesc + " Nationality: " + oSegment.get_DataElementValue(2, 1));         // Nationality, coded (3293) 
                            
                        }
                        else if (sSegmentID == "RFF")         // Reference 
                        {
                            listBox1.Items.Add(sPartyDesc + oSegment.get_DataElementValue(1, 1));         // Reference qualifier (1153) 
                            listBox1.Items.Add(sPartyDesc + oSegment.get_DataElementValue(1, 2));         // Reference number (1154) 
                            
                        }         // sSegmentID == "RFF" 

                    }
                    else if (sLoopSection == "NAD;DOC")
                    {

                        if (sSegmentID == "DOC")         // Document/message details 
                        {
                            sDocQlfr = oSegment.get_DataElementValue(1, 1);         // Document/message name, coded (1001) 

                            if (sDocQlfr == "P")
                                sDocDesc = "Passport";

                            else if (sDocQlfr == "C")
                                sDocDesc = "Permanent resident card";

                            sValue = oSegment.get_DataElementValue(1, 2);         // Code list qualifier (1131) 
                            sValue = oSegment.get_DataElementValue(1, 3);         // Code list responsible agency, coded (3055) 
                            sValue = oSegment.get_DataElementValue(2, 1);         // Document/message number (1004) 
                            
                        }
                        else if (sSegmentID == "DTM")         // Date/time/period 
                        {
                            sValue = oSegment.get_DataElementValue(1, 1);         // Date/time/period qualifier (2005) 
                            listBox1.Items.Add(sPartyDesc + " " + sDocDesc + " Expiry Date: " + oSegment.get_DataElementValue(1, 2));         // Date/time/period (2380) 
                            
                        }
                        
                        else if (sSegmentID == "LOC")         // Place/location identification 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Place/location qualifier (3227) 
                            listBox1.Items.Add(sPartyDesc + " " + sDocDesc + " Place of Issue: " + oSegment.get_DataElementValue(2, 1));         // Place/location identification (3225) 
                            
                        }
                    }
                }
                else if (nArea == 3)
                {

                    // Data segments in area 3 are processed here. 

                    if (sLoopSection == "")
                    {

                        if (sSegmentID == "CNT")         // Control total 
                        {
                            sValue = oSegment.get_DataElementValue(1, 1);         // Control qualifier (6069) 
                            sValue = oSegment.get_DataElementValue(1, 2);         // Control value (6066) 
                            sValue = oSegment.get_DataElementValue(1, 3);         // Measure unit qualifier (6411) 

                        }
                        
                        else if (sSegmentID == "UNT")         // Message trailer 
                        {
                            sValue = oSegment.get_DataElementValue(1, 0);         // Number of segments in a message (0074) 
                            sValue = oSegment.get_DataElementValue(2, 0);         // Message reference number (0062) 

                        }         // sSegmentID == "UNT" 

                    }         // sLoopSection == "" 

                }         // nArea == 3 

                // Get the next data segment in the document. 
                ediDataSegment.Set(ref oSegment, oSegment.Next());

            }         // oSegment != null 
        

    Click here to download a trial version of the Framework EDI