Ejemplo n.º 1
0
        /// <summary>
        /// Batch multiple transactions under multiple functional groups in the same EDI stream.
        /// </summary>
        public static void WriteMultipleGroups()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            using (var stream = new MemoryStream())
            {
                using (var writer = new EdifactWriter(stream))
                {
                    writer.Write(SegmentBuilders.BuildUnb("1"));

                    //  1.  Write the first group
                    writer.Write(SegmentBuilders.BuildUng("1", "INVOIC"));
                    writer.Write(EdifactTransactionBuilders.BuildInvoice("1"));

                    //  2.  Write the second group
                    //  No need to close the previous group with a UNE
                    writer.Write(SegmentBuilders.BuildUng("2", "ORDERS"));
                    writer.Write(EdifactTransactionBuilders.BuildPurchaseOrder("1"));
                }

                Debug.Write(stream.LoadToString());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Write Purchase Orders
        /// </summary>
        static void Write()
        {
            using (var stream = new MemoryStream())
            {
                var transaction = EdifactTransactionBuilders.BuildPurchaseOrder("1");

                MessageErrorContext mec;
                if (transaction.IsValid(out mec, new ValidationSettings {
                    SkipTrailerValidation = true
                }))
                {
                    //  valid
                    using (var writer = new EdifactWriter(stream))
                    {
                        writer.Write(SegmentBuilders.BuildUnb("1"));
                        writer.Write(transaction);
                    }

                    var ediString = stream.LoadToString();
                }
                else
                {
                    //  invalid
                    var errors = mec.Flatten();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generate and write EDI document to a stream.
        /// </summary>
        public static void WriteSinglePurchaseOrderToStream()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            //  1.  Construct the purchase order
            var po = EdifactTransactionBuilders.BuildPurchaseOrder("1");

            //  2.  Validate it by skipping trailer validation
            MessageErrorContext errorContext;

            if (po.IsValid(out errorContext, new ValidationSettings {
                SkipTrailerValidation = true
            }))
            {
                Debug.WriteLine("Message {0} with control number {1} is valid.", errorContext.Name, errorContext.ControlNumber);

                using (var stream = new MemoryStream())
                {
                    using (var writer = new EdifactWriter(stream))
                    {
                        //  3.  Begin with UNB segment
                        writer.Write(SegmentBuilders.BuildUnb("1"));
                        //  4.  Then write the purchase order(s)
                        writer.Write(po);
                    }

                    Debug.Write(stream.LoadToString());
                }
            }
            else
            {
                //  The purchase order is invalid
                Debug.WriteLine("Message {0} with control number {1} is invalid with errors:", errorContext.Name,
                                errorContext.ControlNumber);

                //  List all error messages
                var errors = errorContext.Flatten();
                foreach (var error in errors)
                {
                    Debug.WriteLine(error);
                }
            }
        }