Beispiel #1
0
        /// <summary>
        /// Generate and write EDI document to a file
        /// </summary>
        public static void WriteSingleInvoiceToFile()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            //  1.  Construct the invoice
            var invoice = X12TransactionBuilders.BuildInvoice("1");

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

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

                //  3.  Write directly to a file
                using (var writer = new X12Writer(@"C:\Test\Output.txt", false))
                {
                    writer.Write(SegmentBuilders.BuildIsa("1"));
                    writer.Write(SegmentBuilders.BuildGs("1"));
                    writer.Write(invoice);
                }

                Debug.WriteLine("Written to file.");
            }
            else
            {
                //  The invoice is invalid
            }
        }
Beispiel #2
0
        /// <summary>
        /// Write with custom separators, by default it uses the standard separators.
        /// </summary>
        public static void WriteWithCustomSeparators()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            var invoice = X12TransactionBuilders.BuildInvoice("1");

            using (var stream = new MemoryStream())
            {
                using (var writer = new X12Writer(stream))
                {
                    //  Set a custom segment separator.
                    var separators = new Separators('|', Separators.X12.ComponentDataElement,
                                                    Separators.X12.DataElement, Separators.X12.RepetitionDataElement, Separators.X12.Escape);

                    //  Write the ISA with the custom separator set
                    writer.Write(SegmentBuilders.BuildIsa("1"), separators);
                    writer.Write(SegmentBuilders.BuildGs("1"));
                    writer.Write(invoice);
                }

                Debug.Write(stream.LoadToString());
            }
        }
        /// <summary>
        /// Generate and write EDI document to a stream async
        /// </summary>
        public static async void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            //  1.  Construct the invoice
            var invoice = EF_X12_004010_810_Builder.BuildInvoice("1");

            using (var stream = new MemoryStream())
            {
                using (var writer = new X12Writer(stream))
                {
                    //  2.  Begin with ISA segment
                    await writer.WriteAsync(SegmentBuilders.BuildIsa("1"));

                    //  3.  Follow up with GS segment
                    await writer.WriteAsync(SegmentBuilders.BuildGs("1"));

                    //  4.  Then write the invoice(s)
                    await writer.WriteAsync(invoice);
                }

                Debug.Write(stream.LoadToString());
            }
        }
Beispiel #4
0
        /// <summary>
        /// Write transactions with whitespace.
        /// </summary>
        public static void WriteSegmentWithWhitespace()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            var invoice = X12TransactionBuilders.BuildInvoice("1");

            //  Initialize some properties with blanks
            invoice.BIG.ReleaseNumber_05             = "";
            invoice.BIG.ChangeOrderSequenceNumber_06 = "";

            using (var stream = new MemoryStream())
            {
                //  Set the PreserveWhitespace flag to true
                using (var writer = new X12Writer(stream, new X12WriterSettings()
                {
                    PreserveWhitespace = true
                }))
                {
                    writer.Write(SegmentBuilders.BuildIsa("1"));
                    writer.Write(SegmentBuilders.BuildGs("1"));
                    writer.Write(invoice);
                }

                Debug.Write(stream.LoadToString());
            }
        }
Beispiel #5
0
        /// <summary>
        /// Write Claim
        /// </summary>
        static void Write()
        {
            using (var stream = new MemoryStream())
            {
                var transaction = HipaaTransactionBuilders.BuildClaim("1");

                MessageErrorContext mec;
                if (transaction.IsValid(out mec, true))
                {
                    var separators = new Separators(Separators.X12.Segment, ':', Separators.X12.DataElement, Separators.X12.RepetitionDataElement, Separators.X12.Escape);

                    //  valid
                    using (var writer = new X12Writer(stream, Encoding.UTF8, Environment.NewLine))
                    {
                        writer.Write(SegmentBuilders.BuildIsa("1"), separators);
                        writer.Write(SegmentBuilders.BuildGs("1"));
                        writer.Write(transaction);
                    }

                    var ediString = stream.LoadToString();
                }
                else
                {
                    //  invalid
                    var errors = mec.Flatten();
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Write Purchase Order
        /// </summary>
        static void Write()
        {
            using (var stream = new MemoryStream())
            {
                var transaction = X12TransactionBuilders.BuildPurchaseOrder("1");

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

                    var ediString = stream.LoadToString();
                }
                else
                {
                    //  invalid
                    var errors = mec.Flatten();
                }
            }
        }
        /// <summary>
        /// Batch multiple interchanges in the same EDI stream
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            using (var stream = new MemoryStream())
            {
                using (var writer = new X12Writer(stream))
                {
                    //  1.  Write the first interchange
                    writer.Write(SegmentBuilders.BuildIsa("1"));
                    writer.Write(SegmentBuilders.BuildGs("1"));
                    writer.Write(SegmentBuilders.BuildInvoice("1"));

                    //  2.  Write the second interchange
                    //  No need to close the previous interchange with a IEA
                    writer.Write(SegmentBuilders.BuildIsa("2"));
                    writer.Write(SegmentBuilders.BuildGs("1"));
                    writer.Write(SegmentBuilders.BuildInvoice("1"));
                }

                Debug.Write(stream.LoadToString());
            }
        }
        /// <summary>
        /// Batch multiple transactions in the same functional group\EDI stream.
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            using (var stream = new MemoryStream())
            {
                using (var writer = new X12Writer(stream, new X12WriterSettings()
                {
                    Postfix = Environment.NewLine
                }))
                {
                    writer.Write(SegmentBuilders.BuildIsa("1"));
                    writer.Write(SegmentBuilders.BuildGs("1"));

                    //  1.  Write the first invoice
                    writer.Write(EF_X12_004010_810_Builder.BuildInvoice("1"));

                    //  2.  Write the second invoice
                    writer.Write(EF_X12_004010_810_Builder.BuildInvoice("2"));

                    //  3.  Write any subsequent invoices...
                }

                Debug.Write(stream.LoadToString());
            }
        }
Beispiel #9
0
        /// <summary>
        /// Batch multiple transactions in the same functional group\EDI stream.
        /// </summary>
        public static void WriteMultipleInvoices()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            using (var stream = new MemoryStream())
            {
                using (var writer = new X12Writer(stream, Encoding.Default, Environment.NewLine))
                {
                    writer.Write(SegmentBuilders.BuildIsa("1"));
                    writer.Write(SegmentBuilders.BuildGs("1"));

                    //  1.  Write the first invoice
                    writer.Write(X12TransactionBuilders.BuildInvoice("1"));

                    //  2.  Write the second invoice
                    writer.Write(X12TransactionBuilders.BuildInvoice("2"));

                    //  3.  Write any subsequent invoices...
                }

                Debug.Write(stream.LoadToString());
            }
        }
Beispiel #10
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 X12Writer(stream))
                {
                    writer.Write(SegmentBuilders.BuildIsa("1"));

                    //  1.  Write the first group
                    writer.Write(SegmentBuilders.BuildGs("1"));
                    //  Write the transactions...
                    writer.Write(X12TransactionBuilders.BuildInvoice("1"));

                    //  2.  Write the second group
                    //  No need to close the previous group with a GE
                    writer.Write(SegmentBuilders.BuildGs("2"));
                    //  Write the transactions...
                    writer.Write(X12TransactionBuilders.BuildInvoice("2"));
                }

                Debug.Write(stream.LoadToString());
            }
        }
        /// <summary>
        /// Write with custom separators, by default it uses the standard separators.
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            var invoice = SegmentBuilders.BuildInvoice("1");

            using (var stream = new MemoryStream())
            {
                using (var writer = new X12Writer(stream))
                {
                    //  Set a custom segment separator.
                    var separators = Separators.X12;
                    separators.Segment = '|';

                    //  Write the ISA with the custom separator set
                    writer.Write(SegmentBuilders.BuildIsa("1"), separators);
                    writer.Write(SegmentBuilders.BuildGs("1"));
                    writer.Write(invoice);
                }

                Debug.Write(stream.LoadToString());
            }
        }
Beispiel #12
0
        /// <summary>
        /// Generate and write EDI document to a stream async
        /// </summary>
        public static async void WriteSingleInvoiceToStreamAsync()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            //  1.  Construct the invoice
            var invoice = X12TransactionBuilders.BuildInvoice("1");

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

            if (invoice.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 X12Writer(stream))
                    {
                        //  3.  Begin with ISA segment
                        await writer.WriteAsync(SegmentBuilders.BuildIsa("1"));

                        //  4.  Follow up with GS segment
                        await writer.WriteAsync(SegmentBuilders.BuildGs("1"));

                        //  5.  Then write the invoice(s)
                        await writer.WriteAsync(invoice);
                    }

                    Debug.Write(stream.LoadToString());
                }
            }
            else
            {
                //  The invoice 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);
                }
            }
        }
        /// <summary>
        /// Write Response Transmission
        /// </summary>
        static void Write()
        {
            var transaction = BuildResponseTransmission("1");

            using (var stream = new MemoryStream())
            {
                using (var writer = new X12Writer(stream))
                {
                    writer.Write(SegmentBuilders.BuildIsa("1"));
                    writer.Write(SegmentBuilders.BuildGs("1", "SENDER1", "RECEIVER1", "005010X212"));
                    writer.Write(transaction);
                }

                var ediString = stream.LoadToString();
            }
        }
Beispiel #14
0
        /// <summary>
        /// Write Payment Order
        /// </summary>
        static void Write()
        {
            var transaction = PaymentOrderRemittanceAdvice("1");

            using (var stream = new MemoryStream())
            {
                using (var writer = new X12Writer(stream))
                {
                    writer.Write(SegmentBuilders.BuildIsa("1"));
                    writer.Write(SegmentBuilders.BuildGs("1", "SENDER1", "RECEIVER1", "005010X306"));
                    writer.Write(transaction);
                }

                var ediString = stream.LoadToString();
            }
        }
Beispiel #15
0
        /// <summary>
        /// Write Payment
        /// </summary>
        static void Write()
        {
            var transaction = BuildPayment("1");

            using (var stream = new MemoryStream())
            {
                using (var writer = new X12Writer(stream))
                {
                    writer.Write(SegmentBuilders.BuildIsa("1"));
                    writer.Write(SegmentBuilders.BuildGs("1"));
                    writer.Write(transaction);
                }

                var ediString = stream.LoadToString();
            }
        }
        /// <summary>
        /// Write Generic Request
        /// </summary>
        static void Write()
        {
            var transaction = BuildGenericRequest("1234");

            using (var stream = new MemoryStream())
            {
                using (var writer = new X12Writer(stream))
                {
                    writer.Write(SegmentBuilders.BuildIsa("1"));
                    writer.Write(SegmentBuilders.BuildGs("1", "SENDER1", "RECEIVER1", "005010X279A1"));
                    writer.Write(transaction);
                }

                var ediString = stream.LoadToString();
            }
        }
        /// <summary>
        /// Write Dental Claim
        /// </summary>
        static void Write()
        {
            var transaction = BuildDentalClaim("3456");

            using (var stream = new MemoryStream())
            {
                using (var writer = new X12Writer(stream))
                {
                    writer.Write(SegmentBuilders.BuildIsa("1"));
                    writer.Write(SegmentBuilders.BuildGs("1", "SENDER1", "RECEIVER1", "005010X224A2"));
                    writer.Write(transaction);
                }

                var ediString = stream.LoadToString();
            }
        }
Beispiel #18
0
        private string Get277Edi(TS277 ts277)
        {
            var transaction = ts277;

            using (var stream = new MemoryStream())
            {
                using (var writer = new X12Writer(stream))
                {
                    writer.Write(SegmentBuilders.BuildIsa("1"));
                    writer.Write(SegmentBuilders.BuildGs("1"));
                    writer.Write(transaction);
                }

                var ediString = stream.LoadToString();
                return(ediString);
            }
        }
Beispiel #19
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 = X12TransactionBuilders.BuildPurchaseOrder("1");

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

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

                using (var stream = new MemoryStream())
                {
                    using (var writer = new X12Writer(stream))
                    {
                        //  3.  Begin with ISA segment
                        writer.Write(SegmentBuilders.BuildIsa("1"));
                        //  4.  Follow up with GS segment
                        writer.Write(SegmentBuilders.BuildGs("1"));
                        //  5.  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);
                }
            }
        }
Beispiel #20
0
        /// <summary>
        /// Write Claim
        /// </summary>
        public static void Write()
        {
            var transaction = BuildClaim("1");

            using (var stream = new MemoryStream())
            {
                using (var writer = new X12Writer(stream, new X12WriterSettings {
                    Postfix = Environment.NewLine
                }))
                {
                    writer.Write(SegmentBuilders.BuildIsa("1"));
                    writer.Write(SegmentBuilders.BuildGs("1"));
                    writer.Write(transaction);
                }

                var ediString = stream.LoadToString();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Hello, World!");

            //  1.  Construct the purchase order
            var purchaseOrder = EF_X12_004010_850_Builder.BuildPurchaseOrder("1");

            //  2.  Write directly to a file
            //  Change the path to a file on your machine
            using (var writer = new X12Writer(@"C:\Users\alxje\dev\Test\PurchaseOrderTestFile.txt", false))
            {
                writer.Write(SegmentBuilders.BuildIsa("1"));
                writer.Write(SegmentBuilders.BuildGs("1"));
                writer.Write(purchaseOrder);
            }

            Debug.WriteLine("Written to file.");
        }
Beispiel #22
0
        /// <summary>
        /// Generate and write EDI document to a file
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            //  1.  Construct the invoice
            var invoice = EF_X12_004010_810_Builder.BuildInvoice("1");

            //  2.  Write directly to a file
            //  Change the patch to a file on your machine
            using (var writer = new X12Writer(@"C:\Test\Output.txt", false))
            {
                writer.Write(SegmentBuilders.BuildIsa("1"));
                writer.Write(SegmentBuilders.BuildGs("1"));
                writer.Write(invoice);
            }

            Debug.WriteLine("Written to file.");
        }
Beispiel #23
0
        /// <summary>
        /// Write with segment postfix.
        /// </summary>
        public static void WriteWithSegmetPostfix()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            var invoice = X12TransactionBuilders.BuildInvoice("1");

            using (var stream = new MemoryStream())
            {
                using (var writer = new X12Writer(stream, Encoding.UTF8, Environment.NewLine))
                {
                    writer.Write(SegmentBuilders.BuildIsa("1"));
                    writer.Write(SegmentBuilders.BuildGs("1"));
                    writer.Write(invoice);
                }

                Debug.Write(stream.LoadToString());
            }
        }
Beispiel #24
0
        /// <summary>
        /// Write with segment postfix.
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            var invoice = EF_X12_004010_810_Builder.BuildInvoice("1");

            using (var stream = new MemoryStream())
            {
                using (var writer = new X12Writer(stream, new X12WriterSettings()
                {
                    Postfix = Environment.NewLine
                }))
                {
                    writer.Write(SegmentBuilders.BuildIsa("1"));
                    writer.Write(SegmentBuilders.BuildGs("1"));
                    writer.Write(invoice);
                }

                Debug.Write(stream.LoadToString());
            }
        }
Beispiel #25
0
        /// <summary>
        /// Pull the last purchase order from DB
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            using (var db = new X12Context())
            {
                var po = db.TS850.OrderByDescending(o => o.Id).FirstOrDefault();

                using (var stream = new MemoryStream())
                {
                    using (var writer = new X12Writer(stream))
                    {
                        writer.Write(SegmentBuilders.BuildIsa("1"));
                        writer.Write(SegmentBuilders.BuildGs("1"));
                        writer.Write(po);
                    }

                    Debug.Write(stream.LoadToString());
                }
            }
        }
Beispiel #26
0
        /// <summary>
        /// Write without auto trailers
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            using (var stream = new MemoryStream())
            {
                //  Set AutoTrailers to false
                using (var writer = new X12Writer(stream, new X12WriterSettings {
                    AutoTrailers = false
                }))
                {
                    writer.Write(SegmentBuilders.BuildIsa("1"));
                    writer.Write(SegmentBuilders.BuildGs("1"));
                    writer.Write(EF_X12_004010_810_Builder.BuildInvoice("1"));
                    //  trailers need to be manually written
                }

                using (var writer = new StreamWriter(stream))
                {
                    var ge = new GE();
                    ge.NumberOfIncludedSets_1 = "1";
                    ge.GroupControlNumber_2   = "000000001";
                    writer.Write(ge.ToEdi(Separators.X12));

                    var iea = new IEA();
                    iea.NumberOfIncludedGroups_1   = "1";
                    iea.InterchangeControlNumber_2 = "000000001";
                    writer.Write(iea.ToEdi(Separators.X12));

                    writer.Flush();

                    Debug.Write(stream.LoadToString());
                }
            }
        }