//DHL
        #region CreateIntraship
        public static Byte[] CreateIntraship()
        {
            MemoryStream stream = null;
            StreamWriter writer = null;
            Int32        index  = 1;

            try
            {
                //var originalEntity = MyDataContext.Default.Mailings
                //	.Where(runner => runner.DateOfShipping == null)
                //	.Where(runner => runner.ShippingMethod == ShippingMethods.DHL)
                //	.ToList()
                //	.Where(runner => runner.Sales.AreAllBilled())
                //	.Where(runner => runner.Sales.Count() > 0)
                //	.Where(runner => runner.Sales.First().Invoice != null)
                //	.Where(runner => MyDataContext.Default.MailingCostCountries.Any(x => x.IsoCode2 == runner.RecepientCountry))
                //	.ToList();

                var originalEntity = MyDataContext.Default.Mailings
                                     .Where(runner => runner.DateOfShipping == null)
                                     .Where(runner => runner.ShippingMethod == ShippingMethods.DHL)
                                     .ToList()
                                     .Where(runner => runner.Sales.AreAllBilled())
                                     .Where(runner => MailingCostCountry.LoadByName(runner.RecepientCountry) != null);

                stream = new MemoryStream();
                writer = new StreamWriter(stream, System.Text.Encoding.GetEncoding(1252));

                foreach (Mailing mailing in originalEntity)
                {
                    var country = MailingCostCountry.LoadByName(mailing.RecepientCountry);
                    var sale    = mailing.Sales.First();
                    CsvExporter.IntrashipSetShipment(writer, index, country, mailing);
                    CsvExporter.IntrashipSetSender(writer, index);
                    CsvExporter.IntrashipSetItemSetReceiver(writer, index, mailing);
                    CsvExporter.IntrashipSetItem(writer, index, mailing);
                    CsvExporter.IntrashipDhlSetNotification(writer, index, mailing);
                    index++;
                }
            }
            finally
            {
                writer.Flush();
                stream.Position = 0;
            }

            Byte[] result = new Byte[stream.Length];
            stream.Position = 0;
            stream.Read(result, 0, result.Length);
            stream.Close();
            return(result);
        }
        public static string IntrashipGetStreetNameOnly(string fullStreet)
        {
            String result = fullStreet;
            var    number = CsvExporter.IntrashipGetStreetNumber(fullStreet);

            if (number != String.Empty)
            {
                Int32 index = fullStreet.IndexOf(number);
                result = fullStreet.Remove(index, number.Length);
            }

            return(result.Trim(' ', ','));
        }
        private static void IntrashipSetItemSetReceiver(StreamWriter writer, Int32 index, Mailing mailing)
        {
            Int32  recepientLength = mailing.RecepientName.Length > 30 ? 30 : mailing.RecepientName.Length;
            String recepientName   = mailing.RecepientName.Substring(0, recepientLength);
            String streetNumber    = CsvExporter.IntrashipGetStreetNumber(mailing.RecepientStreet1);

            streetNumber = String.IsNullOrWhiteSpace(streetNumber) ? "_" : streetNumber;

            writer.Write(index + "|");                                                                                                       //1
            writer.Write("DPEE-RECEIVER" + "|");                                                                                             //2
            writer.Write(recepientName + "|");                                                                                               //3
            writer.Write("|");                                                                                                               //4
            writer.Write("|");                                                                                                               //5
            writer.Write("|");                                                                                                               //6
            writer.Write(recepientName + "|");                                                                                               //7
            writer.Write((mailing.IsDeliveredToPackstation ? "" : CsvExporter.IntrashipGetStreetNameOnly(mailing.RecepientStreet1)) + "|");  //8
            writer.Write((mailing.IsDeliveredToPackstation ? "" : streetNumber + "|"));                                                      //9
            writer.Write((mailing.IsDeliveredToPackstation ? "" : mailing.RecepientStreet2) + "|");                                          //10
            writer.Write(mailing.RecepientPostcode + "|");                                                                                   //11
            writer.Write(mailing.RecepientCity + "|");                                                                                       //12
            writer.Write(mailing.RecepientCountry + "|");                                                                                    //13
            writer.Write(mailing.Sales.First().Invoice.InvoiceNumber + "|");                                                                 //14
            writer.Write(mailing.RecepientEmail + "|");                                                                                      //15
            writer.Write(mailing.RecepientPhone + "|");                                                                                      //16
            writer.Write(mailing.Sales.First().Invoice.UstIdNr + "|");                                                                       //17
            writer.Write("|");                                                                                                               //18
            writer.Write("|");                                                                                                               //19
            writer.Write("|");                                                                                                               //20
            writer.Write("|");                                                                                                               //21
            writer.Write("|");                                                                                                               //22
            writer.Write("|");                                                                                                               //23
            writer.Write("|");                                                                                                               //24
            writer.Write("|");                                                                                                               //25
            writer.Write("|");                                                                                                               //26
            writer.Write("|");                                                                                                               //27
            writer.Write("|");                                                                                                               //28
            writer.Write("|");                                                                                                               //29
            writer.Write("|");                                                                                                               //30
            writer.Write((mailing.IsDeliveredToPackstation ? "1" : "0") + "|");                                                              //31
            writer.Write((mailing.IsDeliveredToPackstation ? mailing.GetPackstationUser() : "") + "|");                                      //32
            writer.Write((mailing.IsDeliveredToPackstation ? mailing.GetPackstationNo() : "") + "|");                                        //33
            writer.Write(Environment.NewLine);
        }
        //DHL new
        #region CreateDHL
        public static Byte[] CreateDHL()
        {
            MemoryStream stream = null;
            StreamWriter writer = null;

            try
            {
                //var originalEntity = MyDataContext.Default.Mailings
                //	.Where(runner => runner.DateOfShipping == null)
                //	.Where(runner => runner.ShippingMethod == ShippingMethods.DHL)
                //	.ToList()
                //	.Where(runner => runner.Sales.AreAllBilled())
                //	.Where(runner => runner.Sales.Count() > 0)
                //	.Where(runner => runner.Sales.First().Invoice != null)
                //	.Where(runner => MyDataContext.Default.MailingCostCountries.Any(x => x.IsoCode2 == runner.RecepientCountry))
                //	.ToList();

                var originalEntity = MyDataContext.Default.Mailings
                                     .Where(runner => runner.DateOfShipping == null)
                                     .Where(runner => runner.ShippingMethod == ShippingMethods.DHL)
                                     .ToList()
                                     .Where(runner => runner.Sales.AreAllBilled())
                                     .Where(runner => MailingCostCountry.LoadByName(runner.RecepientCountry) != null);

                stream = new MemoryStream();
                writer = new StreamWriter(stream, System.Text.Encoding.GetEncoding(1252));

                writer.Write("Sender Name 1" + ";");
                writer.Write("Sender Street" + ";");
                writer.Write("Sender Nr" + ";");
                writer.Write("Sender Postcode" + ";");
                writer.Write("Sender City" + ";");
                writer.Write("Sender Country" + ";");
                writer.Write("Sender E-Mail-Addresse" + ";");
                writer.Write("Sender Phone" + ";");

                writer.Write("Recepient Name 1" + ";");
                writer.Write("Recepient Name 2 / Postnr" + ";");
                writer.Write("Recepient Street" + ";");
                writer.Write("Recepient Nr" + ";");
                writer.Write("Recepient Address 1" + ";");
                writer.Write("Recepient Postcode" + ";");
                writer.Write("Recepient City" + ";");
                writer.Write("Recepient Country" + ";");
                writer.Write("Recepient E-Mail-Addresse" + ";");
                writer.Write("Recepient Phone" + ";");

                writer.Write("Transactionnr." + ";");
                writer.Write("Product- und Servicedetails" + ";");
                writer.Write("Weight" + ";");
                writer.Write(Environment.NewLine);

                foreach (Mailing mailing in originalEntity)
                {
                    var country = MailingCostCountry.LoadByName(mailing.RecepientCountry);
                    var dhlZone = DhlZone.LoadSingle(country.DhlProductCode);
                    var sale    = mailing.Sales.First();

                    //Absenderadresse
                    writer.Write(ShopperConfiguration.Default.Mandantor.Company + ";");
                    writer.Write(ShopperConfiguration.Default.Mandantor.Street + ";");
                    writer.Write(ShopperConfiguration.Default.Mandantor.StreetNr + ";");
                    writer.Write(ShopperConfiguration.Default.Mandantor.Zip + ";");
                    writer.Write(ShopperConfiguration.Default.Mandantor.City + ";");
                    writer.Write(ShopperConfiguration.Default.Mandantor.CountryIso3 + ";");
                    writer.Write(ShopperConfiguration.Default.Mandantor.Email + ";");
                    writer.Write(ShopperConfiguration.Default.Mandantor.Phone + ";");

                    //Empfängeradresse
                    Int32  recepientLength = mailing.RecepientName.Length > 30 ? 30 : mailing.RecepientName.Length;
                    String recepientName   = mailing.RecepientName.Substring(0, recepientLength);
                    String streetNumber    = CsvExporter.IntrashipGetStreetNumber(mailing.RecepientStreet1);
                    streetNumber = String.IsNullOrWhiteSpace(streetNumber) ? "_" : streetNumber;

                    writer.Write(recepientName + ";");                                                                                            //Name 1 (Empfänger)
                    writer.Write(mailing.IsDeliveredToPackstation ? mailing.GetPackstationUser() : "" + ";");                                     //Name 2/Postnummer (Empfänger)
                    writer.Write(mailing.IsDeliveredToPackstation ? "" : CsvExporter.IntrashipGetStreetNameOnly(mailing.RecepientStreet1) + ";"); //Straße (Empfänger)
                    writer.Write(mailing.IsDeliveredToPackstation ? "" : streetNumber + ";");                                                     //Hausnummer (Empfänger)
                    writer.Write(mailing.IsDeliveredToPackstation ? "" : mailing.RecepientStreet2 + ";");                                         //Adresszusatz 1 (Empfänger)
                    writer.Write(mailing.RecepientPostcode + ";");                                                                                //PLZ (Empfänger)
                    writer.Write(mailing.RecepientCity + ";");                                                                                    //Ort (Empfänger)
                    writer.Write(MailingCostCountry.LoadByName(mailing.RecepientCountry)?.IsoCode3 + ";");                                        //Land (Empfänger)
                    writer.Write(mailing.RecepientEmail + ";");                                                                                   //Email-Adresse (Empfänger)
                    writer.Write(mailing.RecepientPhone + ";");                                                                                   //Telefonnummer (Empfänger)

                    writer.Write(dhlZone.DhlProduct + ";");                                                                                       //Abrechnugnsnummer
                    writer.Write(dhlZone.Dhl + ";");                                                                                              //Produkt- und Servicedetails
                    writer.Write(mailing.TotalWeight / 1000 + ";");                                                                               //Gewicht

                    writer.Write(Environment.NewLine);
                }
            }
            finally
            {
                writer.Flush();
                stream.Position = 0;
            }

            Byte[] result = new Byte[stream.Length];
            stream.Position = 0;
            stream.Read(result, 0, result.Length);
            stream.Close();
            return(result);
        }