private void btnStart_Click(object sender, EventArgs e) { ediDocument oEdiDoc; ediSchema oSchema; ediSchemas oSchemas; ediDataSegment oSegment; string sSegmentID = ""; string sValue = ""; string sLoopDesc = ""; string sEdiFileName = ""; string sSefFileName = ""; int nArea = 0; string sQlfr = ""; string sNadQlfr = ""; 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 = "DESTIM_D96B.EDI"; sSefFileName = "DESTIM_D96B.SEF"; //evaluation SEF file // Specify SEF file to load. oSchema = (ediSchema)oEdiDoc.LoadSchema(sPath + sSefFileName, SchemaTypeIDConstants.Schema_Standard_Exchange_Format); // Specify EDI document to read. oEdiDoc.LoadEdi(sPath + 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; sLoopDesc = 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") { sValue = 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) // Interchange sender (S002) sValue = 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) // Interchange recipient (S003) sValue = 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) // 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 (nArea == 1) { // Data segments in area 1 are processed here. if (sLoopDesc == "") { if (sSegmentID == "UNH") // Message header { sValue = oSegment.get_DataElementValue(1, 0); // Message reference number (0062) listBox1.Items.Add("Message reference number: " + sValue); 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) } else if (sSegmentID == "BGM") // Beginning of message { sValue = oSegment.get_DataElementValue(1, 1); // Document/message name, coded (1001) sValue = oSegment.get_DataElementValue(2, 1); // Document/message number (1004) listBox1.Items.Add("Document/message number: " + sValue); sValue = oSegment.get_DataElementValue(3, 0); // Message function, coded (1225) sValue = oSegment.get_DataElementValue(4, 0); // Response type, coded (4343) } else if (sSegmentID == "DTM") // Date/time/period { sValue = oSegment.get_DataElementValue(1, 1); // Date/time/period qualifier (2005) sValue = oSegment.get_DataElementValue(1, 2); // Date/time/period (2380) listBox1.Items.Add("Document Date/time/period: " + sValue); sValue = oSegment.get_DataElementValue(1, 3); // Date/time/period format qualifier (2379) listBox1.Items.Add("Date/time/period format: " + sValue); } else if (sSegmentID == "CUX") // Currencies { sValue = oSegment.get_DataElementValue(1, 1); // Currency details qualifier (6347) sValue = oSegment.get_DataElementValue(1, 2); // Currency, coded (6345) listBox1.Items.Add("Currency: " + sValue); } else if (sSegmentID == "RFF") // Reference { sQlfr = oSegment.get_DataElementValue(1, 1); // Reference qualifier (1153) if (sQlfr == "CN") { sValue = oSegment.get_DataElementValue(1, 2); // Reference number (1154) listBox1.Items.Add("Carrier's Reference No: " + sValue); } else if (sQlfr == "CT") { sValue = oSegment.get_DataElementValue(1, 2); // Reference number (1154) listBox1.Items.Add("Contract No: " + sValue); } } else if (sSegmentID == "FTX") // Free text { sValue = oSegment.get_DataElementValue(1, 0); // Text subject qualifier (4451) sValue = oSegment.get_DataElementValue(4, 1); // Free text (4440) listBox1.Items.Add("Notes: " + sValue); } // sSegmentID == "FTX" } else if (sLoopDesc == "EQD") { if (sSegmentID == "EQD") // Equipment details { sValue = oSegment.get_DataElementValue(1, 0); // Equipment qualifier (8053) sValue = oSegment.get_DataElementValue(2, 1); // Equipment identification number (8260) listBox1.Items.Add("Equipment Unit No: " + sValue); sValue = oSegment.get_DataElementValue(3, 1); // Equipment size and type identification (8155) sValue = oSegment.get_DataElementValue(3, 2); // Code list qualifier (1131) sValue = oSegment.get_DataElementValue(3, 3); // Code list responsible agency, coded (3055) sValue = oSegment.get_DataElementValue(3, 4); // Equipment size and type (8154) sValue = oSegment.get_DataElementValue(6, 0); // Full/empty indicator, coded (8169) } } else if (sLoopDesc.StartsWith("NAD")) { if (sSegmentID == "NAD") { sNadQlfr = oSegment.get_DataElementValue(1, 0); //Party qualifier } if (sNadQlfr == "CA") //Carrier { if (sSegmentID == "NAD") // Name and address { sValue = oSegment.get_DataElementValue(1, 0); // Party qualifier (3035) sValue = oSegment.get_DataElementValue(2, 1); // Party identification (3039) listBox1.Items.Add("Carrier ID: " + sValue); 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 == "MOA") // Monetary amount { sValue = oSegment.get_DataElementValue(1, 1); // Monetary amount type qualifier (5025) sValue = oSegment.get_DataElementValue(1, 2); // Monetary amount (5004) sValue = oSegment.get_DataElementValue(1, 3); // Currency, coded (6345) } // sSegmentID == "MOA" else if (sSegmentID == "CTA") // Contact information { sValue = oSegment.get_DataElementValue(1, 0); // Contact function, coded (3139) sValue = oSegment.get_DataElementValue(2, 1); // Department or employee identification (3413) sValue = oSegment.get_DataElementValue(2, 2); // Department or employee (3412) } } else if (sNadQlfr == "MS") //Document/message issuer/sender { if (sSegmentID == "NAD") // Name and address { sValue = oSegment.get_DataElementValue(1, 0); // Party qualifier (3035) sValue = oSegment.get_DataElementValue(2, 1); // Party identification (3039) listBox1.Items.Add("Message sender ID: " + sValue); 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 == "MOA") // Monetary amount { sQlfr = oSegment.get_DataElementValue(1, 1); // Monetary amount type qualifier (5025) if (sQlfr == "259") { sValue = oSegment.get_DataElementValue(1, 2); // Monetary amount (5004) listBox1.Items.Add("Total charges: " + sValue); sValue = oSegment.get_DataElementValue(1, 3); // Currency, coded (6345) } } // sSegmentID == "MOA" else if (sSegmentID == "CTA") // Contact information { sValue = oSegment.get_DataElementValue(1, 0); // Contact function, coded (3139) sValue = oSegment.get_DataElementValue(2, 1); // Department or employee identification (3413) sValue = oSegment.get_DataElementValue(2, 2); // Department or employee (3412) listBox1.Items.Add("Contact Person: " + sValue); } // sSegmentID } // sNadQlfr } // sLoopDesc } else if (nArea == 2) { // Data segments in area 2 are processed here. if (sLoopDesc == "") { if (sSegmentID == "UNS") // Section control { sValue = oSegment.get_DataElementValue(1, 0); // Section identification (0081) } // sSegmentID == "UNS" } else if (sLoopDesc == "RFF") { if (sSegmentID == "RFF") // Reference { sValue = oSegment.get_DataElementValue(1, 1); // Reference qualifier (1153) sValue = oSegment.get_DataElementValue(1, 2); // Reference number (1154) listBox1.Items.Add("Approval Reference No: " + sValue); } else if (sSegmentID == "DTM") // Date/time/period { sValue = oSegment.get_DataElementValue(1, 1); // Date/time/period qualifier (2005) sValue = oSegment.get_DataElementValue(1, 2); // Date/time/period (2380) listBox1.Items.Add("Approval Date: " + sValue); sValue = oSegment.get_DataElementValue(1, 3); // Date/time/period format qualifier (2379) } else if (sSegmentID == "NAD") // Name and address { sValue = oSegment.get_DataElementValue(1, 0); // Party qualifier (3035) sValue = oSegment.get_DataElementValue(2, 1); // Party identification (3039) 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 == "MOA") // Monetary amount { sValue = oSegment.get_DataElementValue(1, 1); // Monetary amount type qualifier (5025) sValue = oSegment.get_DataElementValue(1, 2); // Monetary amount (5004) sValue = oSegment.get_DataElementValue(1, 3); // Currency, coded (6345) sValue = oSegment.get_DataElementValue(1, 4); // Currency qualifier (6343) sValue = oSegment.get_DataElementValue(1, 5); // Status, coded (4405) } // sSegmentID == "MOA" } else if (sLoopDesc == "LIN") { if (sSegmentID == "LIN") // Line item { sValue = oSegment.get_DataElementValue(1, 0); // Line item number (1082) listBox1.Items.Add("Line No: " + sValue); sValue = oSegment.get_DataElementValue(2, 0); // Action request/notification, coded (1229) } else if (sSegmentID == "DIM") // Dimensions { sValue = oSegment.get_DataElementValue(1, 0); // Dimension qualifier (6145) sValue = oSegment.get_DataElementValue(2, 1); // Measure unit qualifier (6411) sValue = oSegment.get_DataElementValue(2, 2); // Length dimension (6168) listBox1.Items.Add("Length dimension: " + sValue); sValue = oSegment.get_DataElementValue(2, 3); // Width dimension (6140) listBox1.Items.Add("Width dimension: " + sValue); sValue = oSegment.get_DataElementValue(2, 4); // Height dimension (6008) listBox1.Items.Add("Height dimension: " + sValue); } else if (sSegmentID == "QTY") // Quantity { sQlfr = oSegment.get_DataElementValue(1, 1); // Quantity qualifier (6063) if (sQlfr == "207") { sValue = oSegment.get_DataElementValue(1, 2); // Quantity (6060) listBox1.Items.Add("Labor hours: " + sValue); sValue = oSegment.get_DataElementValue(1, 3); // Measure unit qualifier (6411) } } else if (sSegmentID == "FTX") // Free text { sValue = oSegment.get_DataElementValue(1, 0); // Text subject qualifier (4451) sValue = oSegment.get_DataElementValue(3, 1); // Free text identification (4441) sValue = oSegment.get_DataElementValue(3, 3); // Code list responsible agency, coded (3055) sValue = oSegment.get_DataElementValue(4, 1); // Free text (4440) sValue = oSegment.get_DataElementValue(4, 2); // Free text (4440) sValue = oSegment.get_DataElementValue(4, 3); // Free text (4440) sValue = oSegment.get_DataElementValue(4, 4); // Free text (4440) sValue = oSegment.get_DataElementValue(4, 5); // Free text (4440) } // sSegmentID == "FTX" } else if (sLoopDesc == "LIN;DAM") { if (sSegmentID == "DAM") // Damage { sValue = oSegment.get_DataElementValue(1, 0); // Damage details qualifier (7493) sValue = oSegment.get_DataElementValue(2, 1); // Type of damage, coded (7501) listBox1.Items.Add("Type of damage code: " + sValue); 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); // Type of damage (7500) sValue = oSegment.get_DataElementValue(3, 1); // Damage area identification (7503) sValue = oSegment.get_DataElementValue(3, 2); // Code list qualifier (1131) sValue = oSegment.get_DataElementValue(3, 3); // Code list responsible agency, coded (3055) sValue = oSegment.get_DataElementValue(3, 4); // Damage area (7502) sValue = oSegment.get_DataElementValue(4, 1); // Damage severity, coded (7509) sValue = oSegment.get_DataElementValue(4, 2); // Code list qualifier (1131) sValue = oSegment.get_DataElementValue(4, 3); // Code list responsible agency, coded (3055) sValue = oSegment.get_DataElementValue(4, 4); // Damage severity (7508) sValue = oSegment.get_DataElementValue(5, 1); // Action request/notification, coded (1229) sValue = oSegment.get_DataElementValue(5, 2); // Code list qualifier (1131) sValue = oSegment.get_DataElementValue(5, 3); // Code list responsible agency, coded (3055) sValue = oSegment.get_DataElementValue(5, 4); // Action request/notification (1228) } else if (sSegmentID == "COD") // Component details { sValue = oSegment.get_DataElementValue(1, 1); // Type of unit/component, coded (7505) listBox1.Items.Add("Type of damaged component: " + sValue); 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(1, 4); // Type of unit/component (7504) sValue = oSegment.get_DataElementValue(2, 1); // Component material, coded (7507) 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); // Component material (7506) } // sSegmentID == "COD" } else if (sLoopDesc == "LIN;RTE") { if (sSegmentID == "RTE") // Rate details { sQlfr = oSegment.get_DataElementValue(1, 1); // Rate type qualifier (5419) if (sQlfr == "2") { sValue = oSegment.get_DataElementValue(1, 2); // Rate per unit (5420) listBox1.Items.Add("Charge Rate: " + sValue); } } else if (sSegmentID == "QTY") // Quantity { sValue = oSegment.get_DataElementValue(1, 1); // Quantity qualifier (6063) sValue = oSegment.get_DataElementValue(1, 2); // Quantity (6060) sValue = oSegment.get_DataElementValue(1, 3); // Measure unit qualifier (6411) } // sSegmentID == "QTY" } else if (sLoopDesc.StartsWith("LIN;NAD")) { if (sSegmentID == "NAD") // Name and address { sNadQlfr = oSegment.get_DataElementValue(1, 0); // Party qualifier (3035) } if (sNadQlfr == "CF") { if (sSegmentID == "NAD") // Name and address { sValue = oSegment.get_DataElementValue(1, 0); // Party qualifier (3035) sValue = oSegment.get_DataElementValue(2, 1); // Party identification (3039) listBox1.Items.Add("Container operator id: " + sValue); sValue = oSegment.get_DataElementValue(2, 2); // Code list qualifier (1131) sValue = oSegment.get_DataElementValue(2, 3); // Code list responsible agency, coded (3055) } // sSeg else if (sSegmentID == "MOA") // Monetary amount { sQlfr = oSegment.get_DataElementValue(1, 1); // Monetary amount type qualifier (5025) if (sQlfr == "185") { sValue = oSegment.get_DataElementValue(1, 2); // Monetary amount (5004) listBox1.Items.Add("Labor cost: " + sValue); sValue = oSegment.get_DataElementValue(1, 3); // Currency, coded (6345) } } else if (sSegmentID == "TAX") // Duty/tax/fee details { sValue = oSegment.get_DataElementValue(1, 0); // Duty/tax/fee function qualifier (5283) sQlfr = oSegment.get_DataElementValue(2, 1); // Duty/tax/fee type, coded (5153) if (sQlfr == "LOC") { sValue = oSegment.get_DataElementValue(4, 0); // Duty/tax/fee assessment basis (5286) sValue = oSegment.get_DataElementValue(5, 1); // Duty/tax/fee rate identification (5279) sValue = oSegment.get_DataElementValue(5, 2); // Code list qualifier (1131) sValue = oSegment.get_DataElementValue(5, 3); // Code list responsible agency, coded (3055) sValue = oSegment.get_DataElementValue(5, 4); // Duty/tax/fee rate (5278) listBox1.Items.Add("Local sales tax: " + sValue); } } // sSegmentID } else if (sNadQlfr == "") { } // sNadQlfr } } else if (nArea == 3) { // Data segments in area 3 are processed here. if (sLoopDesc == "") { if (sSegmentID == "CNT") // Control total { sValue = oSegment.get_DataElementValue(1, 1); // Control qualifier (6069) sValue = oSegment.get_DataElementValue(1, 2); // Control value (6066) listBox1.Items.Add("Invoice Total Amount: " + sValue); sValue = oSegment.get_DataElementValue(1, 3); // Measure unit qualifier (6411) } } // sLoopDesc == "" } // nArea == 3 // Get the next data segment in the document. ediDataSegment.Set(ref oSegment, oSegment.Next()); } // oSegment != null MessageBox.Show("Done"); }