Ejemplo n.º 1
0
        public void LoadingAnXml()
        {
            XDocument xml = XDocument.Parse(new StringBuilder()
                                            .AppendLine("<mapping>")
                                            .AppendLine("    <st>")
                                            .AppendLine("        <st01 type=\"n1\" definition=\"acknowledgment\">99.7</st01>")
                                            .AppendLine("        <st01>")
                                            .AppendLine("            <st0101>850</st0101>")
                                            .AppendLine("            <st0102>810</st0102>")
                                            .AppendLine("        </st01>")
                                            .AppendLine("        <st02>")
                                            .AppendLine("            <st0201 type=\"n3\" definition=\"def\">1.234</st0201>")
                                            .AppendLine("            <st0203>5678</st0203>")
                                            .AppendLine("        </st02>")
                                            .AppendLine("        <st04>123</st04>")
                                            .AppendLine("    </st>")
                                            .AppendLine("</mapping>")
                                            .ToString());
            EdiDocument document = EdiDocument.LoadXml(xml);

            document.Options.SegmentTerminator   = '~';
            document.Options.ElementSeparator    = '*';
            document.Options.ComponentSeparator  = '>';
            document.Options.RepetitionSeparator = '^';
            string edi = document.ToString();

            Assert.AreEqual("ST*997^850>810*1234>>5678**123~", edi);
        }
Ejemplo n.º 2
0
        public void MappingOneSegmentWithBlankMapping()
        {
            EdiDocument edi = EdiDocument.Parse("ST*997^850>810*1234>>5678**123~", new EdiOptions {
                RepetitionSeparator = '^', ComponentSeparator = '>'
            });
            EdiMapping mapping = EdiMapping.Parse("<mapping/>");
            XDocument  actual  = mapping.Map(edi.Segments);

            XDocument expected = XDocument.Parse(new StringBuilder()
                                                 .AppendLine("<mapping>")
                                                 .AppendLine("    <ST>")
                                                 .AppendLine("        <ST01>997</ST01>")
                                                 .AppendLine("        <ST01>")
                                                 .AppendLine("            <ST0101>850</ST0101>")
                                                 .AppendLine("            <ST0102>810</ST0102>")
                                                 .AppendLine("        </ST01>")
                                                 .AppendLine("        <ST02>")
                                                 .AppendLine("            <ST0201>1234</ST0201>")
                                                 .AppendLine("            <ST0203>5678</ST0203>")
                                                 .AppendLine("        </ST02>")
                                                 .AppendLine("        <ST04>123</ST04>")
                                                 .AppendLine("    </ST>")
                                                 .AppendLine("</mapping>")
                                                 .ToString());

            Assert.IsTrue(XNode.DeepEquals(expected, actual));
        }
Ejemplo n.º 3
0
        public void IgnoringAlphaNumericRepetitionSeparator()
        {
            EdiDocument document = EdiDocument.Parse("ISA*00*          *00*          *ZZ*SENDER         *ZZ*RECEIVER       *120101*0000*U*00402*000000001*0*P*>~SEG*VALUE1>VALUE2~");

            Assert.AreEqual(1, document.Segments[1].Elements.Count);
            Assert.AreEqual(2, document.Segments[1].Elements[0].Components.Count);
            Assert.AreEqual("VALUE1", document.Segments[1].Elements[0].Components[0].Value);
            Assert.AreEqual("VALUE2", document.Segments[1].Elements[0].Components[1].Value);
        }
Ejemplo n.º 4
0
        public void IgnoringRepetitionSeparatorWhenLessThanVersion4020()
        {
            EdiDocument document = EdiDocument.Parse("ISA*00*          *00*          *ZZ*SENDER         *ZZ*RECEIVER       *120101*0000*^*00401*000000001*0*P*>~SEG*REPETITION1^COMPONENT1>COMPONENT2~");

            Assert.AreEqual(1, document.Segments[1].Elements.Count);
            Assert.AreEqual(2, document.Segments[1].Elements[0].Components.Count);
            Assert.AreEqual("REPETITION1^COMPONENT1", document.Segments[1].Elements[0].Components[0].Value);
            Assert.AreEqual("COMPONENT2", document.Segments[1].Elements[0].Components[1].Value);
        }
Ejemplo n.º 5
0
        public void ReadingSegmentsWithReleaseCharacters()
        {
            EdiDocument document = EdiDocument.Parse("UNA:+.? 'UNB+??IATB?:1?+6XPPC+LHPPC+940101:0950+1?'UNH+1+PAORES:93:1:IA'");

            Assert.AreEqual(2, document.Segments.Count);
            Assert.AreEqual("UNB", document.Segments[1].Id);
            Assert.AreEqual(6, document.Segments[1].Elements.Count);
            Assert.AreEqual("?IATB:1+6XPPC", document.Segments[1].Elements[0].Value);
        }
Ejemplo n.º 6
0
        public void Saving()
        {
            const string edi      = "ISA*00*          *00*          *ZZ*SENDER         *ZZ*RECEIVER       *120101*0000*^*00402*000000001*0*P*>~SEG*REPETITION1^COMPONENT1>COMPONENT2~";
            EdiDocument  document = EdiDocument.Parse(edi);
            var          buffer   = new StringWriter();

            document.Save(buffer);

            Assert.AreEqual(edi, buffer.ToString());
        }
Ejemplo n.º 7
0
        public void IgnoringAlphaNumericRepetitionSeparatorWhenSaving()
        {
            const string edi      = "ISA*00*          *00*          *ZZ*SENDER         *ZZ*RECEIVER_WITH_U*120101*0000*U*00402*000000001*0*P*>~";
            EdiDocument  document = EdiDocument.Parse(edi);
            var          buffer   = new StringWriter();

            document.Save(buffer);

            Assert.AreEqual(edi, buffer.ToString());
        }
Ejemplo n.º 8
0
        public void ReadingRepetitions()
        {
            EdiDocument document = EdiDocument.Parse("ISA*00*          *00*          *ZZ*SENDER         *ZZ*RECEIVER       *120101*0000*^*00402*000000001*0*P*>~SEG*REPETITION1^COMPONENT1>COMPONENT2~");

            Assert.AreEqual(1, document.Segments[1].Elements.Count);
            Assert.AreEqual(2, document.Segments[1].Elements[0].Repetitions.Count);
            Assert.AreEqual("REPETITION1", document.Segments[1].Elements[0].Repetitions[0].Value);
            Assert.AreEqual(2, document.Segments[1].Elements[0].Repetitions[1].Components.Count);
            Assert.AreEqual("COMPONENT1", document.Segments[1].Elements[0].Repetitions[1].Components[0].Value);
            Assert.AreEqual("COMPONENT2", document.Segments[1].Elements[0].Repetitions[1].Components[1].Value);
        }
Ejemplo n.º 9
0
        public void GettingTransactionSets()
        {
            string edi = new StringBuilder()
                         .AppendLine("ISA*00*          *00*          *ZZ*SENDER         *ZZ*RECEIVER       *120101*0000*U*00401*000000001*0*P*>~")
                         .AppendLine("GS********1~")
                         .AppendLine("ST**0001~")
                         .AppendLine("AK1~")
                         .AppendLine("SE~")
                         .AppendLine("SE~")
                         .AppendLine("GE~")
                         .AppendLine("IEA~")
                         .AppendLine("ST**0002~")
                         .AppendLine("SE~")
                         .AppendLine("ISA*00*          *00*          *ZZ*SENDER         *ZZ*RECEIVER       *120101*0000*U*00401*000000002*0*P*>~")
                         .AppendLine("GS********2~")
                         .AppendLine("AK2~")
                         .AppendLine("ST**0003~")
                         .AppendLine("AK3~")
                         .AppendLine("ST**0004~")
                         .AppendLine("GE~")
                         .AppendLine("IEA~")
                         .ToString();
            EdiDocument document = EdiDocument.Parse(edi);
            IList <EdiTransactionSet> transactionSets = document.TransactionSets;

            Assert.AreEqual(4, transactionSets.Count);

            Assert.AreEqual("000000001", transactionSets[0].InterchangeHeader[13]);
            Assert.AreEqual("1", transactionSets[0].FunctionalGroupHeader[8]);
            Assert.AreEqual(3, transactionSets[0].Segments.Count);
            Assert.AreEqual("0001", transactionSets[0].Segments[0][02]);
            Assert.AreEqual("AK1", transactionSets[0].Segments[1].Id);
            Assert.AreEqual("SE", transactionSets[0].Segments[2].Id);

            Assert.IsNull(transactionSets[1].InterchangeHeader);
            Assert.IsNull(transactionSets[1].FunctionalGroupHeader);
            Assert.AreEqual(2, transactionSets[1].Segments.Count);
            Assert.AreEqual("0002", transactionSets[1].Segments[0][02]);
            Assert.AreEqual("SE", transactionSets[1].Segments[1].Id);

            Assert.AreEqual("000000002", transactionSets[2].InterchangeHeader[13]);
            Assert.AreEqual("2", transactionSets[2].FunctionalGroupHeader[8]);
            Assert.AreEqual(2, transactionSets[2].Segments.Count);
            Assert.AreEqual("0003", transactionSets[2].Segments[0][02]);
            Assert.AreEqual("AK3", transactionSets[2].Segments[1].Id);

            Assert.AreEqual("000000002", transactionSets[3].InterchangeHeader[13]);
            Assert.AreEqual("2", transactionSets[3].FunctionalGroupHeader[8]);
            Assert.AreEqual(3, transactionSets[3].Segments.Count);
            Assert.AreEqual("0004", transactionSets[3].Segments[0][02]);
            Assert.AreEqual("GE", transactionSets[3].Segments[1].Id);
            Assert.AreEqual("IEA", transactionSets[3].Segments[2].Id);
        }
Ejemplo n.º 10
0
        public void ReadingComponents()
        {
            EdiDocument document = EdiDocument.Parse("ISA*00*          *00*          *ZZ*SENDER         *ZZ*RECEIVER       *120101*0000*U*00401*000000001*0*P*>~SEG*COMPONENT1>COMPONENT2*COMPONENT3>COMPONENT4>COMPONENT5~");

            Assert.AreEqual(2, document.Segments[1].Elements.Count);
            Assert.AreEqual(2, document.Segments[1].Elements[0].Components.Count);
            Assert.AreEqual("COMPONENT1", document.Segments[1].Elements[0].Components[0].Value);
            Assert.AreEqual("COMPONENT2", document.Segments[1].Elements[0].Components[1].Value);
            Assert.AreEqual(3, document.Segments[1].Elements[1].Components.Count);
            Assert.AreEqual("COMPONENT3", document.Segments[1].Elements[1].Components[0].Value);
            Assert.AreEqual("COMPONENT4", document.Segments[1].Elements[1].Components[1].Value);
            Assert.AreEqual("COMPONENT5", document.Segments[1].Elements[1].Components[2].Value);
        }
Ejemplo n.º 11
0
        public void SavingAValueContainingASeparator()
        {
            var options = new EdiOptions {
                SegmentTerminator = '~', ElementSeparator = '*'
            };
            var document = new EdiDocument(options);
            var segment  = new EdiSegment("SEG");

            segment[01] = document.Options.ElementSeparator.ToString();
            document.Segments.Add(segment);
            var buffer = new StringWriter();

            document.Save(buffer);
        }
Ejemplo n.º 12
0
        public void GuessingSeparators()
        {
            EdiDocument document = EdiDocument.Parse("ISA*00*          *00*          *ZZ*SENDER         *ZZ*RECEIVER       *120101*0000*U*00401*000000001*0*P*>~IEA*0*000000001~");

            Assert.AreEqual(2, document.Segments.Count);
            Assert.AreEqual("ISA", document.Segments[0].Id);
            Assert.AreEqual(16, document.Segments[0].Elements.Count);
            Assert.AreEqual("SENDER         ", document.Segments[0].Elements[5].Value);
            Assert.AreEqual(">", document.Segments[0].Elements[15].Value);
            Assert.AreEqual("IEA", document.Segments[1].Id);
            Assert.AreEqual(2, document.Segments[1].Elements.Count);
            Assert.AreEqual("0", document.Segments[1].Elements[0].Value);
            Assert.AreEqual("000000001", document.Segments[1].Elements[1].Value);
        }
Ejemplo n.º 13
0
        public void ReadingASegment()
        {
            var options = new EdiOptions
            {
                ElementSeparator  = '*',
                SegmentTerminator = '~'
            };
            EdiDocument document = EdiDocument.Parse("ST*997*0001~", options);

            Assert.AreEqual(1, document.Segments.Count);
            Assert.AreEqual("ST", document.Segments[0].Id);
            Assert.AreEqual(2, document.Segments[0].Elements.Count);
            Assert.AreEqual("997", document.Segments[0].Elements[0].Value);
            Assert.AreEqual("0001", document.Segments[0].Elements[1].Value);
        }
Ejemplo n.º 14
0
        public void DetectingRepetitionAndComponentSeparatorsWhenSaving()
        {
            string edi = new StringBuilder()
                         .Append("ISA*00*          *00*          *ZZ*SENDER         *ZZ*RECEIVER       *120101*0000*^*00402*000000001*0*P*>~")
                         .Append("SEG*REPETITION1^COMPONENT1>COMPONENT2~")
                         .Append("ISA*00*          *00*          *ZZ*SENDER         *ZZ*RECEIVER       *120101*0000*|*00402*000000001*0*P*<~")
                         .Append("SEG*REPETITION1|COMPONENT1<COMPONENT2~")
                         .ToString();
            EdiDocument document = EdiDocument.Parse(edi);
            var         buffer   = new StringWriter();

            document.Save(buffer);

            Assert.AreEqual(edi, buffer.ToString());
        }
Ejemplo n.º 15
0
        public void SavingWithLineBreaks()
        {
            string edi = new StringBuilder()
                         .AppendLine("ISA*00*          *00*          *ZZ*SENDER         *ZZ*RECEIVER       *120101*0000*^*00402*000000001*0*P*>~")
                         .AppendLine("SEG*REPETITION1^COMPONENT1>COMPONENT2~")
                         .ToString();
            EdiDocument document = EdiDocument.Parse(edi);

            document.Options.AddLineBreaks = true;
            var buffer = new StringWriter();

            document.Save(buffer);

            Assert.AreEqual(edi, buffer.ToString());
        }
Ejemplo n.º 16
0
        public void ReadingEdifactSegments()
        {
            EdiDocument document = EdiDocument.Parse("UNA:+.? 'UNB+IATB:1+6XPPC+LHPPC+940101:0950+1'UNH+1+PAORES:93:1:IA'");

            Assert.AreEqual(3, document.Segments.Count);
            Assert.AreEqual("UNA", document.Segments[0].Id);
            Assert.AreEqual(1, document.Segments[0].Elements.Count);
            Assert.AreEqual(":+.? ", document.Segments[0].Elements[0].Value);
            Assert.AreEqual("UNB", document.Segments[1].Id);
            Assert.AreEqual(5, document.Segments[1].Elements.Count);
            Assert.AreEqual(2, document.Segments[1].Elements[3].Components.Count);
            Assert.AreEqual("940101", document.Segments[1].Elements[3].Components[0].Value);
            Assert.AreEqual("0950", document.Segments[1].Elements[3].Components[1].Value);
            Assert.AreEqual("UNH", document.Segments[2].Id);
            Assert.AreEqual(2, document.Segments[2].Elements.Count);
            Assert.AreEqual("1", document.Segments[2].Elements[0].Value);
        }
Ejemplo n.º 17
0
        public void IgnoringExtraWhiteSpace()
        {
            string edi = new StringBuilder()
                         .AppendLine("ISA*00*          *00*          *ZZ*SENDER         *ZZ*RECEIVER       *120101*0000*U*00401*000000001*0*P*>~")
                         .AppendLine("IEA*0*000000001~")
                         .ToString();
            EdiDocument document = EdiDocument.Parse(edi);

            Assert.AreEqual(2, document.Segments.Count);
            Assert.AreEqual("ISA", document.Segments[0].Id);
            Assert.AreEqual(16, document.Segments[0].Elements.Count);
            Assert.AreEqual("SENDER         ", document.Segments[0].Elements[5].Value);
            Assert.AreEqual(">", document.Segments[0].Elements[15].Value);
            Assert.AreEqual("IEA", document.Segments[1].Id);
            Assert.AreEqual(2, document.Segments[1].Elements.Count);
            Assert.AreEqual("0", document.Segments[1].Elements[0].Value);
            Assert.AreEqual("000000001", document.Segments[1].Elements[1].Value);
        }
Ejemplo n.º 18
0
        public void MappingAnExpectedSegment()
        {
            EdiDocument edi = EdiDocument.Parse("ST*997^850>810*1234>>5678**123~", new EdiOptions {
                RepetitionSeparator = '^', ComponentSeparator = '>'
            });
            EdiMapping mapping = EdiMapping.Parse(new StringBuilder()
                                                  .AppendLine("<mapping>")
                                                  .AppendLine("    <st>")
                                                  .AppendLine("        <st01 type=\"n1\">")
                                                  .AppendLine("            <option definition=\"purchase order\">850</option>")
                                                  .AppendLine("            <option definition=\"acknowledgment\">997</option>")
                                                  .AppendLine("        </st01>")
                                                  .AppendLine("        <st02 type=\"n2\">")
                                                  .AppendLine("            <st0201 type=\"n3\">")
                                                  .AppendLine("                <option definition=\"def\">1234</option>")
                                                  .AppendLine("            </st0201>")
                                                  .AppendLine("        </st02>")
                                                  .AppendLine("    </st>")
                                                  .AppendLine("</mapping>")
                                                  .ToString());
            XDocument actual = mapping.Map(edi.Segments);

            XDocument expected = XDocument.Parse(new StringBuilder()
                                                 .AppendLine("<mapping>")
                                                 .AppendLine("    <st>")
                                                 .AppendLine("        <st01 type=\"n1\" definition=\"acknowledgment\">99.7</st01>")
                                                 .AppendLine("        <st01>")
                                                 .AppendLine("            <st0101>850</st0101>")
                                                 .AppendLine("            <st0102>810</st0102>")
                                                 .AppendLine("        </st01>")
                                                 .AppendLine("        <st02>")
                                                 .AppendLine("            <st0201 type=\"n3\" definition=\"def\">1.234</st0201>")
                                                 .AppendLine("            <st0203>5678</st0203>")
                                                 .AppendLine("        </st02>")
                                                 .AppendLine("        <st04>123</st04>")
                                                 .AppendLine("    </st>")
                                                 .AppendLine("</mapping>")
                                                 .ToString());

            Assert.IsTrue(XNode.DeepEquals(expected, actual));
        }
Ejemplo n.º 19
0
        public void GettingEdifactTransactionSets()
        {
            string edi = new StringBuilder()
                         .AppendLine("UNA:+.? '")
                         .AppendLine("UNB+1'")
                         .AppendLine("UNH+2'")
                         .AppendLine("MSG'")
                         .AppendLine("IFT'")
                         .AppendLine("UNT'")
                         .AppendLine("UNZ'")
                         .AppendLine("UNB+3'")
                         .AppendLine("UNG+4'")
                         .AppendLine("UNH+5'")
                         .AppendLine("UNT'")
                         .AppendLine("UNE'")
                         .AppendLine("UNZ'")
                         .ToString();
            EdiDocument document = EdiDocument.Parse(edi);
            IList <EdiTransactionSet> transactionSets = document.TransactionSets;

            Assert.AreEqual(2, transactionSets.Count);

            Assert.AreEqual("1", transactionSets[0].InterchangeHeader[01]);
            Assert.IsNull(transactionSets[0].FunctionalGroupHeader);
            Assert.AreEqual(4, transactionSets[0].Segments.Count);
            Assert.AreEqual("2", transactionSets[0].Segments[0][01]);
            Assert.AreEqual("MSG", transactionSets[0].Segments[1].Id);
            Assert.AreEqual("IFT", transactionSets[0].Segments[2].Id);
            Assert.AreEqual("UNT", transactionSets[0].Segments[3].Id);

            Assert.AreEqual("3", transactionSets[1].InterchangeHeader[01]);
            Assert.AreEqual("4", transactionSets[1].FunctionalGroupHeader[01]);
            Assert.AreEqual(2, transactionSets[1].Segments.Count);
            Assert.AreEqual("5", transactionSets[1].Segments[0][01]);
            Assert.AreEqual("UNT", transactionSets[1].Segments[1].Id);
        }
Ejemplo n.º 20
0
        public string WritePurchaseOrderEdi(PurchaseOrder purchaseOrder, int customerId)
        {
            string custId = customerId.ToString();

            while (custId.Length < 8)
            {
                custId = "0" + custId;
            }

            var ediDocument = new EdiDocument();
            var isa         = new EdiSegment("ISA");

            isa[01] = "00";
            isa[02] = "".PadRight(10);
            isa[03] = "00";
            isa[04] = "".PadRight(10);
            isa[05] = "ZZ";
            isa[06] = custId.PadRight(15);
            isa[07] = "ZZ";
            isa[08] = "RECEIVER".PadRight(15);
            isa[09] = EdiValue.Date(6, DateTime.Now);
            isa[10] = EdiValue.Time(4, DateTime.Now);
            isa[11] = "U";
            isa[12] = "00401";
            isa[13] = 1.ToString("d9");
            isa[14] = "0";
            isa[15] = "P";
            isa[16] = ">";
            ediDocument.Segments.Add(isa);

            var gs = new EdiSegment("GS");

            gs[01] = "PO";
            gs[02] = "SENDER".PadRight(15);
            gs[03] = "RECEIVER".PadRight(15);
            gs[04] = EdiValue.Date(8, DateTime.Now);
            gs[05] = EdiValue.Time(4, DateTime.Now);
            gs[06] = EdiValue.Numeric(0, 1);
            gs[07] = "X";
            gs[08] = "004010";
            ediDocument.Segments.Add(gs);

            var st = new EdiSegment("ST");

            st[01] = "850";
            st[02] = "166061414";
            ediDocument.Segments.Add(st);

            var beg = new EdiSegment("BEG");

            beg[01] = purchaseOrder.BEG01_TransactionSetPurposeCode;
            beg[02] = purchaseOrder.BEG02_PurchaseOrderTypeCode;
            beg[03] = purchaseOrder.BEG03_PurchaseOrderNumber;
            beg[04] = "";
            beg[05] = purchaseOrder.BEG05_Date != null
                ? purchaseOrder.BEG05_Date.Value.ToString("yyyyMMdd")
                : "";

            ediDocument.Segments.Add(beg);

            if (!(String.IsNullOrEmpty(purchaseOrder.CUR01_CurrencyEntityIdentifierCode) &&
                  String.IsNullOrEmpty(purchaseOrder.CUR02_CurrencyCode)))
            {
                var cur = new EdiSegment("CUR");
                cur[01] = purchaseOrder.CUR01_CurrencyEntityIdentifierCode;
                cur[02] = purchaseOrder.CUR02_CurrencyCode;
                ediDocument.Segments.Add(cur);
            }

            foreach (var poRef in purchaseOrder.Refs)
            {
                var refpo = new EdiSegment("REF");
                refpo[01] = poRef.REF01_ReferenceIdentificationQualifier;
                refpo[02] = poRef.REF02_ReferenceIdentification;
                refpo[03] = poRef.REF03_Description;
                ediDocument.Segments.Add(refpo);
            }
            foreach (var dtm in purchaseOrder.Dtms)
            {
                var dtmpo = new EdiSegment("DTM");
                dtmpo[01] = dtm.DTM01_DateTimeQualifier;
                dtmpo[02] = dtm.DTM02_PurchaseOrderDate != null
                ? dtm.DTM02_PurchaseOrderDate.Value.ToString("yyyyMMdd")
                : "";

                ediDocument.Segments.Add(dtmpo);
            }

            foreach (var name in purchaseOrder.Names)
            {
                var n1 = new EdiSegment("N1");
                n1[01] = name.N101_EntityIdentifierCode;
                n1[02] = name.N102_Name;
                n1[03] = name.N103_IdentificationCodeQualifier;
                n1[04] = name.N104_IdentificationCode;
                ediDocument.Segments.Add(n1);

                if (!(String.IsNullOrEmpty(name.N201_Name) &&
                      String.IsNullOrEmpty(name.N202_Name)))
                {
                    var n2 = new EdiSegment("N2");
                    n2[01] = name.N201_Name;
                    n2[02] = name.N202_Name;
                    ediDocument.Segments.Add(n2);
                }

                if (!(String.IsNullOrEmpty(name.N301_Address) &&
                      String.IsNullOrEmpty(name.N302_Address)))
                {
                    var n3 = new EdiSegment("N3");
                    n3[01] = name.N301_Address;
                    n3[02] = name.N302_Address;
                    ediDocument.Segments.Add(n3);
                }

                if (!(String.IsNullOrEmpty(name.N401_City) &&
                      String.IsNullOrEmpty(name.N402_State) &&
                      String.IsNullOrEmpty(name.N403_PostalCode) &&
                      String.IsNullOrEmpty(name.N404_Country)))
                {
                    var n4 = new EdiSegment("N4");
                    n4[01] = name.N401_City;
                    n4[02] = name.N402_State;
                    n4[03] = name.N403_PostalCode;
                    n4[04] = name.N404_Country;
                    ediDocument.Segments.Add(n4);
                }
                foreach (var nameRef in name.Refs)
                {
                    var refname = new EdiSegment("REF");
                    refname[01] = nameRef.REF01_ReferenceIdentificationQualifier;
                    refname[02] = nameRef.REF02_ReferenceIdentification;
                    refname[03] = nameRef.REF03_Description;
                    ediDocument.Segments.Add(refname);
                }
            }


            foreach (var item in purchaseOrder.Items)
            {
                var po1 = new EdiSegment("PO1");
                po1[01] = item.PO101_AssignedIdentification;
                po1[02] = item.PO102_QuantityOrdered != null
                    ? item.PO102_QuantityOrdered.ToString()
                    : "";

                po1[03] = item.PO103_UnitOfMeasurement;
                po1[04] = item.PO104_UnitPrice != null
                    ? item.PO104_UnitPrice.Value.ToString("0.00")
                    : "";

                po1[05] = item.PO105_BasisOfUnitPriceCode;
                po1[06] = item.PO106_ProductIdQualifier;
                po1[07] = item.PO107_ProductID;
                po1[08] = item.PO108_ProductIdQualifier;
                po1[09] = item.PO109_ProductID;
                ediDocument.Segments.Add(po1);

                var cur = new EdiSegment("CUR");
                cur[01] = item.CUR01_CurrencyEntityIdentifierCode;
                cur[02] = item.CUR02_CurrencyCode;
                ediDocument.Segments.Add(cur);

                var itref = new EdiSegment("REF");
                itref[01] = item.REF01_ReferenceIdentificationQualifier;
                itref[02] = item.REF02_ReferenceIdentification;
                ediDocument.Segments.Add(itref);

                foreach (var dtm in item.Dtms)
                {
                    var dtmit = new EdiSegment("DTM");
                    dtmit[01] = dtm.DTM01_DateTimeQualifier;
                    dtmit[02] = dtm.DTM02_PurchaseOrderDate != null
                    ? dtm.DTM02_PurchaseOrderDate.Value.ToString("yyyyMMdd")
                    : "";

                    ediDocument.Segments.Add(dtmit);
                }
                foreach (var name in purchaseOrder.Names)
                {
                    var n1 = new EdiSegment("N1");
                    n1[01] = name.N101_EntityIdentifierCode;
                    n1[02] = name.N102_Name;
                    n1[03] = name.N103_IdentificationCodeQualifier;
                    n1[04] = name.N104_IdentificationCode;
                    ediDocument.Segments.Add(n1);

                    if (!(String.IsNullOrEmpty(name.N201_Name) &&
                          String.IsNullOrEmpty(name.N202_Name)))
                    {
                        var n2 = new EdiSegment("N2");
                        n2[01] = name.N201_Name;
                        n2[02] = name.N202_Name;
                        ediDocument.Segments.Add(n2);
                    }

                    if (!(String.IsNullOrEmpty(name.N301_Address) &&
                          String.IsNullOrEmpty(name.N302_Address)))
                    {
                        var n3 = new EdiSegment("N3");
                        n3[01] = name.N301_Address;
                        n3[02] = name.N302_Address;
                        ediDocument.Segments.Add(n3);
                    }

                    if (!(String.IsNullOrEmpty(name.N401_City) &&
                          String.IsNullOrEmpty(name.N402_State) &&
                          String.IsNullOrEmpty(name.N403_PostalCode) &&
                          String.IsNullOrEmpty(name.N404_Country)))
                    {
                        var n4 = new EdiSegment("N4");
                        n4[01] = name.N401_City;
                        n4[02] = name.N402_State;
                        n4[03] = name.N403_PostalCode;
                        n4[04] = name.N404_Country;
                        ediDocument.Segments.Add(n4);
                    }
                    foreach (var nameRef in name.Refs)
                    {
                        var refname = new EdiSegment("REF");
                        refname[01] = nameRef.REF01_ReferenceIdentificationQualifier;
                        refname[02] = nameRef.REF02_ReferenceIdentification;
                        refname[03] = nameRef.REF03_Description;
                        ediDocument.Segments.Add(refname);
                    }
                }
            }



            var ctt = new EdiSegment("CTT");

            ctt[01] = purchaseOrder.CTT01_NumberofLineItems != null
                ? purchaseOrder.CTT01_NumberofLineItems.ToString()
                : "";

            ediDocument.Segments.Add(ctt);
            var amt = new EdiSegment("AMT");

            amt[01] = purchaseOrder.AMT01_AmountQualifierCode;
            amt[02] = purchaseOrder.AMT02_Amount != null
                ? purchaseOrder.AMT02_Amount.Value.ToString("0.00")
                : "";

            ediDocument.Segments.Add(amt);

            var se = new EdiSegment("SE");

            se[01] = (ediDocument.Segments.Count - 1).ToString();
            se[02] = st[02];
            ediDocument.Segments.Add(se);

            var ge = new EdiSegment("GE");

            ge[01] = EdiValue.Numeric(0, 1);
            ge[02] = gs[06];
            ediDocument.Segments.Add(ge);

            var iea = new EdiSegment("IEA");

            iea[01] = EdiValue.Numeric(0, 1);
            iea[02] = isa[13];
            ediDocument.Segments.Add(iea);

            ediDocument.Options.SegmentTerminator = '~';
            ediDocument.Options.ElementSeparator  = '*';

            var filename = Path.Combine(Settings.EdiTextFileDirectory, "SENDER_" + DateTime.Now.ToString("yyyy-mm-dd_hh.mm.ss") + ".txt");

            ediDocument.Save(filename);

            return(filename);
        }
Ejemplo n.º 21
0
        public void WriteInvoiceEdi(Invoice invoice)
        {
            var ediDocument = new EdiDocument();
            var isa         = new EdiSegment("ISA");

            isa[01] = "00";
            isa[02] = "".PadRight(10);
            isa[03] = "00";
            isa[04] = "".PadRight(10);
            isa[05] = "ZZ";
            isa[06] = "SENDER".PadRight(15);
            isa[07] = "ZZ";
            isa[08] = "RECEIVER".PadRight(15);
            isa[09] = EdiValue.Date(6, DateTime.Now);
            isa[10] = EdiValue.Time(4, DateTime.Now);
            isa[11] = "U";
            isa[12] = "00400";
            isa[13] = 1.ToString("d9");
            isa[14] = "0";
            isa[15] = "P";
            isa[16] = ">";
            ediDocument.Segments.Add(isa);

            var gs = new EdiSegment("GS");

            gs[01] = "IN";
            gs[02] = "SENDER";
            gs[03] = "RECEIVER";
            gs[04] = EdiValue.Date(8, DateTime.Now);
            gs[05] = EdiValue.Time(4, DateTime.Now);
            gs[06] = EdiValue.Numeric(0, 1);
            gs[07] = "X";
            gs[08] = "004010";
            ediDocument.Segments.Add(gs);

            var st = new EdiSegment("ST");

            st[01] = "810";
            st[02] = "166061414";
            ediDocument.Segments.Add(st);

            var big = new EdiSegment("BIG");

            big[01] = invoice.BIG01_Date != null
                ? invoice.BIG01_Date.Value.ToString("yyyyMMdd")
                : "";

            big[02] = invoice.BIG02_InvoiceNumber;
            big[03] = invoice.BIG03_Date != null
                ? invoice.BIG01_Date.Value.ToString("yyyyMMdd")
                : "";

            big[04] = invoice.BIG04_PurchaseOrderNumber;
            big[07] = invoice.BIG04_TransactionTypeCode;
            big[08] = invoice.BIG08_TransactionSetPurposeCode;
            ediDocument.Segments.Add(big);

            foreach (var note in invoice.Notes)
            {
                var nte = new EdiSegment("NTE");
                nte[01] = note.NTE01_NoteReferenceCode;
                nte[02] = note.NTE02_NoteDescription;
                ediDocument.Segments.Add(nte);
            }

            if (!(String.IsNullOrEmpty(invoice.CUR01_CurrencyEntityIdentifierCode) &&
                  String.IsNullOrEmpty(invoice.CUR02_CurrencyCode) &&
                  String.IsNullOrEmpty(invoice.CUR03_ExchangeRate)))
            {
                var cur = new EdiSegment("CUR");
                cur[01] = invoice.CUR01_CurrencyEntityIdentifierCode;
                cur[02] = invoice.CUR02_CurrencyCode;
                ediDocument.Segments.Add(cur);
            }

            foreach (var invoiceRef in invoice.Refs)
            {
                var refinv = new EdiSegment("REF");
                refinv[01] = invoiceRef.REF01_ReferenceIdentificationQualifier;
                refinv[02] = invoiceRef.REF02_ReferenceIdentification;
                refinv[03] = invoiceRef.REF03_Description;
                ediDocument.Segments.Add(refinv);
            }

            foreach (var name in invoice.Names)
            {
                var n1 = new EdiSegment("N1");
                n1[01] = name.N101_EntityIdentifierCode;
                n1[02] = name.N102_Name;
                n1[03] = name.N103_IdentificationCodeQualifier;
                n1[04] = name.N104_IdentificationCode;
                ediDocument.Segments.Add(n1);

                if (!(String.IsNullOrEmpty(name.N201_Name) &&
                      String.IsNullOrEmpty(name.N202_Name)))
                {
                    var n2 = new EdiSegment("N2");
                    n2[01] = name.N201_Name;
                    n2[02] = name.N202_Name;
                    ediDocument.Segments.Add(n2);
                }

                if (!(String.IsNullOrEmpty(name.N301_Address) &&
                      String.IsNullOrEmpty(name.N302_Address)))
                {
                    var n3 = new EdiSegment("N3");
                    n3[01] = name.N301_Address;
                    n3[02] = name.N302_Address;
                    ediDocument.Segments.Add(n3);
                }

                if (!(String.IsNullOrEmpty(name.N401_City) &&
                      String.IsNullOrEmpty(name.N402_State) &&
                      String.IsNullOrEmpty(name.N403_PostalCode) &&
                      String.IsNullOrEmpty(name.N404_Country)))
                {
                    var n4 = new EdiSegment("N4");
                    n4[01] = name.N401_City;
                    n4[02] = name.N402_State;
                    n4[03] = name.N403_PostalCode;
                    n4[04] = name.N404_Country;
                    ediDocument.Segments.Add(n4);
                }
            }

            var itd = new EdiSegment("ITD");

            itd[01] = invoice.ITD01_TermsTypeCode;
            itd[02] = invoice.ITD02_TermsBasisDateCode;
            itd[07] = invoice.ITD07_TermsNetDays != null
                ? invoice.ITD07_TermsNetDays.Value.ToString()
                : "";

            itd[12] = invoice.ITD12_Description;
            ediDocument.Segments.Add(itd);

            var dtm = new EdiSegment("DTM");

            dtm[01] = invoice.DTM01_DateTimeQualifier;
            dtm[02] = invoice.DTM02_ShipDate != null
                ? invoice.DTM02_ShipDate.Value.ToString("yyyyMMdd")
                : "";

            ediDocument.Segments.Add(dtm);

            foreach (var item in invoice.Items)
            {
                var it1 = new EdiSegment("IT1");
                it1[01] = item.IT101_AssignedIdentification;
                it1[02] = item.IT102_QuantityInvoiced != null
                    ? item.IT102_QuantityInvoiced.ToString()
                    : "";

                it1[03] = item.IT103_UnitOfMeasurement;
                it1[04] = item.IT104_UnitPrice != null
                    ? item.IT104_UnitPrice.Value.ToString("0.00")
                    : "";

                it1[05] = item.IT105_BasisOfUnitPriceCode;
                it1[06] = item.IT106_ProductIdQualifier;
                it1[07] = item.IT107_ProductID;
                it1[08] = item.IT108_ProductIdQualifier;
                it1[09] = item.IT109_ProductID;
                it1[10] = item.IT110_ProductIdQualifier;
                it1[11] = item.IT111_ProductID;
                ediDocument.Segments.Add(it1);

                var pid = new EdiSegment("PID");
                pid[01] = item.PID01_ItemDescriptionType;
                pid[05] = item.PID05_ItemDescription;
                ediDocument.Segments.Add(pid);
            }

            var tds = new EdiSegment("TDS");

            tds[01] = invoice.TDS01_Amount != null
                ? invoice.TDS01_Amount.Value.ToString("0.00")
                : "";

            ediDocument.Segments.Add(tds);

            var ctt = new EdiSegment("CTT");

            ctt[01] = invoice.CTT01_TransactionTotals != null
                ? invoice.CTT01_TransactionTotals.ToString()
                : "";

            var se = new EdiSegment("SE");

            se[01] = (ediDocument.Segments.Count - 1).ToString();
            se[02] = st[02];
            ediDocument.Segments.Add(se);

            var ge = new EdiSegment("GE");

            ge[01] = EdiValue.Numeric(0, 1);
            ge[02] = gs[06];
            ediDocument.Segments.Add(ge);

            var iea = new EdiSegment("IEA");

            iea[01] = EdiValue.Numeric(0, 1);
            iea[02] = isa[13];
            ediDocument.Segments.Add(iea);

            ediDocument.Options.SegmentTerminator = '~';
            ediDocument.Options.ElementSeparator  = '*';
            ediDocument.Save(@"..\..\..\Invoice.txt");
        }
Ejemplo n.º 22
0
        public void MappingAHierarchy()
        {
            EdiDocument edi = EdiDocument.Parse(new StringBuilder()
                                                .AppendLine("ST~")
                                                .AppendLine("HL***S~")
                                                .AppendLine("TD1~")
                                                .AppendLine("N1~")
                                                .AppendLine("N3~")
                                                .AppendLine("N4~")
                                                .AppendLine("N1~")
                                                .AppendLine("N1~")
                                                .AppendLine("HL***O~")
                                                .AppendLine("PRF~")
                                                .AppendLine("TD1~")
                                                .AppendLine("N1~")
                                                .AppendLine("HL***I~")
                                                .AppendLine("HL***I~")
                                                .AppendLine("HL***O~")
                                                .AppendLine("PRF~")
                                                .AppendLine("TD1~")
                                                .AppendLine("N1~")
                                                .AppendLine("HL***I~")
                                                .AppendLine("CTT~")
                                                .AppendLine("SE~")
                                                .ToString(),
                                                new EdiOptions
            {
                ElementSeparator    = '*',
                RepetitionSeparator = '^',
                ComponentSeparator  = '>'
            });
            EdiMapping mapping = EdiMapping.Parse(new StringBuilder()
                                                  .AppendLine("<mapping>")
                                                  .AppendLine("    <loop>")
                                                  .AppendLine("        <hl>")
                                                  .AppendLine("            <hl03 restrict=\"true\">")
                                                  .AppendLine("                <option>s</option>")
                                                  .AppendLine("            </hl03>")
                                                  .AppendLine("        </hl>")
                                                  .AppendLine("        <loop>")
                                                  .AppendLine("            <n1/>")
                                                  .AppendLine("        </loop>")
                                                  .AppendLine("    </loop>")
                                                  .AppendLine("    <loop>")
                                                  .AppendLine("        <hl>")
                                                  .AppendLine("            <hl03 restrict=\"true\">")
                                                  .AppendLine("                <option>o</option>")
                                                  .AppendLine("            </hl03>")
                                                  .AppendLine("        </hl>")
                                                  .AppendLine("        <td1/>")
                                                  .AppendLine("    </loop>")
                                                  .AppendLine("    <loop>")
                                                  .AppendLine("        <hl>")
                                                  .AppendLine("            <hl03 restrict=\"true\">")
                                                  .AppendLine("                <option>i</option>")
                                                  .AppendLine("            </hl03>")
                                                  .AppendLine("        </hl>")
                                                  .AppendLine("    </loop>")
                                                  .AppendLine("    <ctt/>")
                                                  .AppendLine("</mapping>")
                                                  .ToString());
            XDocument actual = mapping.Map(edi.Segments);

            XDocument expected = XDocument.Parse(new StringBuilder()
                                                 .AppendLine("<mapping>")
                                                 .AppendLine("    <ST/>")
                                                 .AppendLine("    <loop>")
                                                 .AppendLine("        <hl>")
                                                 .AppendLine("            <hl03>S</hl03>")
                                                 .AppendLine("        </hl>")
                                                 .AppendLine("        <TD1/>")
                                                 .AppendLine("        <loop>")
                                                 .AppendLine("            <n1/>")
                                                 .AppendLine("            <N3/>")
                                                 .AppendLine("            <N4/>")
                                                 .AppendLine("        </loop>")
                                                 .AppendLine("        <loop>")
                                                 .AppendLine("            <n1/>")
                                                 .AppendLine("        </loop>")
                                                 .AppendLine("        <loop>")
                                                 .AppendLine("            <n1/>")
                                                 .AppendLine("        </loop>")
                                                 .AppendLine("    </loop>")
                                                 .AppendLine("    <loop>")
                                                 .AppendLine("        <hl>")
                                                 .AppendLine("            <hl03>O</hl03>")
                                                 .AppendLine("        </hl>")
                                                 .AppendLine("        <PRF/>")
                                                 .AppendLine("        <td1/>")
                                                 .AppendLine("        <N1/>")
                                                 .AppendLine("    </loop>")
                                                 .AppendLine("    <loop>")
                                                 .AppendLine("        <hl>")
                                                 .AppendLine("            <hl03>I</hl03>")
                                                 .AppendLine("        </hl>")
                                                 .AppendLine("    </loop>")
                                                 .AppendLine("    <loop>")
                                                 .AppendLine("        <hl>")
                                                 .AppendLine("            <hl03>I</hl03>")
                                                 .AppendLine("        </hl>")
                                                 .AppendLine("    </loop>")
                                                 .AppendLine("    <loop>")
                                                 .AppendLine("        <hl>")
                                                 .AppendLine("            <hl03>O</hl03>")
                                                 .AppendLine("        </hl>")
                                                 .AppendLine("        <PRF/>")
                                                 .AppendLine("        <td1/>")
                                                 .AppendLine("        <N1/>")
                                                 .AppendLine("    </loop>")
                                                 .AppendLine("    <loop>")
                                                 .AppendLine("        <hl>")
                                                 .AppendLine("            <hl03>I</hl03>")
                                                 .AppendLine("        </hl>")
                                                 .AppendLine("    </loop>")
                                                 .AppendLine("    <ctt/>")
                                                 .AppendLine("    <SE/>")
                                                 .AppendLine("</mapping>")
                                                 .ToString());

            Assert.IsTrue(XNode.DeepEquals(expected, actual));
        }
Ejemplo n.º 23
0
 public void SavingAValueContainingASeparator()
 {
     var options = new EdiOptions {SegmentTerminator = '~', ElementSeparator = '*'};
     var document = new EdiDocument(options);
     var segment = new EdiSegment("SEG");
     segment[01] = document.Options.ElementSeparator.ToString();
     document.Segments.Add(segment);
     var buffer = new StringWriter();
     document.Save(buffer);
 }
Ejemplo n.º 24
0
        public EdiDocument GenerateEDIUPRD(bool IsOacy, bool IsUnsc, bool IsSwnt, bool IsTest, string pipeDuns, PipelineEDISettingDTO pipelineEdiSetting, bool sendManu)
        {
            string number = String.Format("{0:d9}", (DateTime.Now.Ticks / 10) % 1000000000);
            string path   = Path.GetRandomFileName();

            path = path.Replace(".", "");
            var ediDocument = new EdiDocument();
            var isa         = new EdiSegment("ISA");

            isa[01] = "00";
            isa[02] = "".PadRight(10);
            isa[03] = "00";
            isa[04] = "".PadRight(10);
            isa[05] = "01";
            isa[06] = pipelineEdiSetting.ISA06_Segment.Trim().PadRight(15);// service requester duns
            isa[07] = pipelineEdiSetting.ISA08_segment.Trim().All(char.IsDigit) == true ? "01" : "14";
            isa[08] = pipelineEdiSetting.ISA08_segment.Trim().PadRight(15);
            isa[09] = EdiValue.Date(6, DateTime.Now);
            isa[10] = EdiValue.Time(4, DateTime.Now);
            isa[11] = pipelineEdiSetting.ISA11_Segment.Trim(); //"U";// UPRD setting ISA11_seg
            isa[12] = pipelineEdiSetting.ISA12_Segment.Trim(); //"00304";//Release/version*******PipelineUprdSetting_ISA12_Seg
            isa[13] = number;
            isa[14] = "0";
            isa[15] = IsTest ? "T" : "P";                      //Convert.ToBoolean(ConfigurationManager.AppSettings["EDIForTest"]) ? "T" : "P";//"P";//configuration setting for Test and Prod
            isa[16] = pipelineEdiSetting.ISA16_Segment.Trim(); //">";//uprd setting ISA16
            ediDocument.Segments.Add(isa);

            var gs = new EdiSegment("GS");

            gs[01] = pipelineEdiSetting.GS01_Segment.Trim(); //"IB"; //GS01_segment in edisetting
            gs[02] = pipelineEdiSetting.GS02_Segment.Trim(); //"078711334";//service requester duns
            gs[03] = pipelineEdiSetting.GS03_Segment.Trim(); //"RECEIVER";//GS03_Segment UPRD setting
            gs[04] = (pipeDuns.Trim() == "006958581" ||
                      pipeDuns.Trim() == "046077343" ||
                      pipeDuns.Trim() == "007933021" ||
                      pipeDuns.Trim() == "116025180" ||
                      pipeDuns.Trim() == "094992187" ||
                      pipeDuns.Trim() == "784158214" ||
                      pipeDuns.Trim() == "876833500" ||
                      pipeDuns.Trim() == "808168645" ||
                      pipeDuns.Trim() == "006912885" ||
                      pipeDuns.Trim() == "021632583" ||
                      pipeDuns.Trim() == "030353283" ||
                      pipeDuns.Trim() == "961777229" ||
                      pipeDuns.Trim() == "013081810" ||
                      pipeDuns.Trim() == "017738746") ?
                     EdiValue.Date(6, DateTime.Now) : EdiValue.Date(8, DateTime.Now);
            gs[05] = EdiValue.Time(4, DateTime.Now);
            gs[06] = number.Substring(number.Length - 4, 4);
            gs[07] = pipelineEdiSetting.GS07_Segment.Trim(); //"X"; //GS07 segmnet in EDI setting
            gs[08] = pipelineEdiSetting.GS08_Segment.Trim(); //"004010"; //GS08 segment in EDI setting
            ediDocument.Segments.Add(gs);

            var st = new EdiSegment("ST");

            st[01] = pipelineEdiSetting.ST01_Segment.Trim();//"846"; //ST01 Segment in EDI setting
            st[02] = gs[06];
            ediDocument.Segments.Add(st);

            var bia = new EdiSegment("BIA");

            bia[01] = "00";
            bia[02] = "PS";
            bia[03] = path.ToString();
            bia[04] = EdiValue.Date(6, DateTime.Now);
            ediDocument.Segments.Add(bia);


            //var searchCri = DateTime.Parse("9/9/2017");
            var dtm = new EdiSegment("DTM");

            dtm[01] = "007";

            if (pipeDuns.Trim() == "116025180" || pipeDuns.Trim() == "876833500")
            {
                dtm[06] = "RD8";
                if (sendManu)
                {
                    dtm[07] = EdiValue.Date(8, pipelineEdiSetting.StartDate) + "-" + EdiValue.Date(8, pipelineEdiSetting.EndDate);
                }
                else
                {
                    dtm[07] = EdiValue.Date(8, DateTime.Now) + "-" + EdiValue.Date(8, DateTime.Now);
                }
            }
            else
            {
                dtm[06] = "DTS";
                if (sendManu)
                {
                    dtm[07] = (pipeDuns.Trim() == "094992187") ? EdiValue.Date(14, pipelineEdiSetting.StartDate.Date) : EdiValue.Date(14, pipelineEdiSetting.StartDate.AddSeconds(1));//  + "-" + EdiValue.Date(14, pipelineEdiSetting.EndDate);//EdiValue.Date(8, searchCri) + "-" + EdiValue.Date(8, searchCri.AddDays(1));
                }
                else
                {
                    dtm[07] = (pipeDuns.Trim() == "094992187") ? EdiValue.Date(14, DateTime.Now.Date) : EdiValue.Date(14, DateTime.Now.Date.AddSeconds(1));// + "-" + EdiValue.Date(14, DateTime.Now);//EdiValue.Date(8, searchCri) + "-" + EdiValue.Date(8, searchCri.AddDays(1));
                }
            }


            ediDocument.Segments.Add(dtm);

            var n1SvcPvdr = new EdiSegment("N1");

            n1SvcPvdr[01] = "SJ";
            n1SvcPvdr[03] = "1";
            n1SvcPvdr[04] = pipeDuns.Trim();//"Receiver";
            ediDocument.Segments.Add(n1SvcPvdr);

            var n1SvcRq = new EdiSegment("N1");

            n1SvcRq[01] = "41";
            n1SvcRq[03] = "1";
            n1SvcRq[04] = "078711334";//Sender
            ediDocument.Segments.Add(n1SvcRq);

            if (IsOacy)
            {
                var lin = new EdiSegment("LIN");
                lin[01] = "1";
                lin[02] = "OA";
                lin[03] = "8";//uprd_DataRequestCode.RequestCode.Trim();//"8";//oacy(8),UNSC(9),SWNT(6);
                ediDocument.Segments.Add(lin);
            }

            if (IsUnsc)
            {
                var lin = new EdiSegment("LIN");
                lin[01] = "1";
                lin[02] = "OA";
                lin[03] = "9";//uprd_DataRequestCode.RequestCode.Trim();//"8";//oacy(8),UNSC(9),SWNT(6);
                ediDocument.Segments.Add(lin);
            }

            if (IsSwnt)
            {
                var lin = new EdiSegment("LIN");
                lin[01] = "1";
                lin[02] = "OA";
                lin[03] = "6";//uprd_DataRequestCode.RequestCode.Trim();//"8";//oacy(8),UNSC(9),SWNT(6);
                ediDocument.Segments.Add(lin);
            }

            var ctt = new EdiSegment("CTT");

            ctt[01] = "1";
            ediDocument.Segments.Add(ctt);

            var se = new EdiSegment("SE");

            se[01] = "8";
            se[02] = st[02];
            ediDocument.Segments.Add(se);

            var ge = new EdiSegment("GE");

            ge[01] = "1";
            ge[02] = gs[06];
            ediDocument.Segments.Add(ge);

            var iea = new EdiSegment("IEA");

            iea[01] = "1";
            iea[02] = number;
            ediDocument.Segments.Add(iea);

            // more segments...

            // ediDocument.Options.SegmentTerminator = pipeDuns.Trim()== "094992187" ? Convert.ToChar("\n"): Convert.ToChar(pipelineEdiSetting.SegmentSeperator);//Segment Separator from edi setting
            ediDocument.Options.SegmentTerminator = !string.IsNullOrEmpty(pipelineEdiSetting.SegmentSeperator) ? Convert.ToChar(pipelineEdiSetting.SegmentSeperator) : EdiOptions.DefaultSegmentTerminator;
            ediDocument.Options.ElementSeparator  = Convert.ToChar(pipelineEdiSetting.DataSeparator);//'*';// data separator from edi setting

            return(ediDocument);
        }