SetTotalWidth() public method

public SetTotalWidth ( float columnWidth ) : void
columnWidth float
return void
Esempio n. 1
2
 public static void CreateHardwareReport(string fileName, IEnumerable<HardwareCountReport> hardwares)
 {
     try
     {
         Document document = new Document(PageSize.A4, 72, 72, 72, 72);
         PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None));
         document.Open();
         document.Add(new Paragraph(Element.ALIGN_CENTER, "Hardware Report", new Font(iTextSharp.text.Font.FontFamily.HELVETICA, 16, Font.BOLD)));
         document.Add(new Chunk(Chunk.NEWLINE));
         var table = new PdfPTable(3);
         table.SetTotalWidth(new float[] { 25f, 50f, 25f });
         table.WidthPercentage = 100;
         table.AddCell(new Phrase("Category"));
         table.AddCell(new Phrase("Hardware Model/Type"));
         table.AddCell(new Phrase("Total"));
         foreach (var hw in hardwares)
         {
             table.AddCell(new Phrase(hw.Category));
             table.AddCell(new Phrase(hw.Model));
             table.AddCell(new Phrase(hw.Count));
         }
         document.Add(table);
         document.Close();
     }
     catch (Exception x)
     {
         Log.Error("Error when creating report.", x);
     }
 }
Esempio n. 2
0
        public override iTextSharp.text.IElement GeneratePdfElement()
        {
            TableStyle style = (Manifest != null) ? Manifest.Styles.GetMergedFromConfiguration(Style) : Style;

            int columnCount = (Rows.Any()) ? Rows.First().Cells.Count : 0;
            iTextPdf.PdfPTable table = new iTextPdf.PdfPTable(columnCount)
            {
                HorizontalAlignment = (int) (style.HorizontalAlignment ?? TableStyle.Default.HorizontalAlignment.Value),
                SpacingBefore = style.SpacingBefore ?? TableStyle.Default.SpacingBefore.Value,
                SpacingAfter = style.SpacingAfter ?? TableStyle.Default.SpacingAfter.Value,
                LockedWidth = style.LockedWidth ?? TableStyle.Default.LockedWidth.Value,
            };

            Rows.SelectMany(r => r.Cells).ForEach(c => table.AddCell((iTextPdf.PdfPCell) c.GeneratePdfElement()));

            if (style.Widths != null && style.Widths.Any())
            {
                table.SetTotalWidth(style.Widths);
            }
            if (style.WidthPercentage.HasValue)
            {
                table.WidthPercentage = style.WidthPercentage.Value;
            }

            return table;
        }
Esempio n. 3
0
        public override void Builder()
        {
            if (table.Heads == null) throw new Exception();

            var columns = table.Heads.Length;
            headwidth = new float[columns];
            PdfPTable pdfPTable = new PdfPTable(columns);
            pdfPTable.LockedWidth = true;
            BuildHeader(columns, pdfPTable);
            pdfPTable.SkipFirstHeader = true;
            BuilBodyData(pdfPTable);
            pdfPTable.Complete = true;
            pdfPTable.SetTotalWidth(headwidth);
            var writer = _pdfBuilder.writer;

            var Height = _pdfBuilder.Height;
            if (pdfPTable.TotalHeight > Height)
            {
                Pager(pdfPTable);
            }
            else
            {
                pdfPTable.WriteSelectedRows(0, -1, 0, -1, table.Position.X, Math.Abs(table.Position.Y - Height), writer.DirectContent, true);
            }
            writer.DirectContent.Stroke();
        }
Esempio n. 4
0
            public MyEventHandler() {
                _header = new PdfPTable(1);
                PdfPCell hCell = new PdfPCell(new Phrase("HEADER"));
                hCell.Border = Rectangle.NO_BORDER;
                _header.AddCell(hCell);
                _header.SetTotalWidth(new float[]{300f});

                _footer = new PdfPTable(1);
                PdfPCell fCell = new PdfPCell(new Phrase("FOOTER"));
                fCell.Border = Rectangle.NO_BORDER;
                _footer.AddCell(fCell);
                _footer.SetTotalWidth(new float[]{300f});
            }
        public void GeneratePDFAggregatedSalesReports(List<StoreReport> allReports, string outputPath)
        {
            string path = outputPath;
            FileStream fileStream = File.Create(path);

            Rectangle pageSize = new Rectangle(900, 700);
            Document pdf = new Document(pageSize);
            pdf.SetMargins(.1f, .1f, .1f, .1f);
            //pdf.SetMargins(0f, 0f, 0f, 0f);

            PdfWriter.GetInstance(pdf, fileStream);

            pdf.Open();
            var pdfTable = new PdfPTable(TABLE_COLUMNS);
            pdfTable.SetTotalWidth(new float[] { 0.5f, 0.3f, 0.2f, 1f, .3f });
            FillTable(pdfTable, allReports);
            pdf.Add(pdfTable);
            pdf.Close();
        }
Esempio n. 6
0
        public override void ExecuteResult(ControllerContext context)
        {
            var Response = context.HttpContext.Response;
            var q = DbUtil.Db.PeopleQuery(id);
            var q2 = from p in q
                     orderby p.Name2
                     select new
                     {
                         First = p.PreferredName,
                         Last = p.LastName,
                         p.PeopleId,
                         dob = p.DOB,
                         Phone = p.CellPhone.Length > 0 ? p.CellPhone : p.HomePhone,
                         p.DoNotPublishPhones
                     };
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "filename=foo.pdf");

            var document = new Document(PageSize.LETTER);
            document.SetMargins(40f, 36f, 32f, 36f);
            var w = PdfWriter.GetInstance(document, Response.OutputStream);
            document.Open();
            dc = w.DirectContent;

            var cols = new float[] { W, W, W - 10f };
            var t = new PdfPTable(cols);
            t.SetTotalWidth(cols);

            t.HorizontalAlignment = Element.ALIGN_CENTER;
            t.LockedWidth = true;
            t.DefaultCell.Border = PdfPCell.NO_BORDER;

            if (!q2.Any())
                document.Add(new Phrase("no data"));
            else
                foreach (var m in q2)
                    AddCell(t, m.First, m.Last, m.Phone, m.PeopleId, m.DoNotPublishPhones);
            t.CompleteRow();
            document.Add(t);

            document.Close();
        }
Esempio n. 7
0
        /// <summary>
        /// Automatics the fit group columns.
        /// </summary>
        /// <param name="table">The table.</param>
        /// <param name="dictionary">Group fields data.</param>
        /// <param name="writer">Current writer.</param>
        /// <returns>
        /// <see cref="T:iTextSharp.text.pdf.PdfPTable" /> which contains adjusted columns.
        /// </returns>
        public static PdfPTable AutoFitColumns(this PdfPTable table, IDictionary <BaseDataFieldModel, int> dictionary, IWriter writer)
        {
            SentinelHelper.ArgumentNull(table);
            SentinelHelper.ArgumentNull(dictionary);
            SentinelHelper.ArgumentNull(writer);

            var tbl            = writer.Provider.Input.Model.Table;
            var resources      = writer.Provider.Input.Resources;
            var widthOfColumns = DefaultColumnWidths(tbl.Fields);

            table.LockedWidth = true;
            foreach (var entry in dictionary)
            {
                var index = tbl.Fields.IndexOf(entry.Key);
                var style = resources.Styles[entry.Key.Value.Style];

                var maxColumnLenght = entry.Key.Alias.Length > entry.Value
                    ? entry.Key.Alias.Length
                    : entry.Value;
                using (var bitmap = new Bitmap(1, 1))
                {
                    using (var graphics = Graphics.FromImage(bitmap))
                    {
                        using (var font = style.Font.ToFont())
                        {
                            var singleCharWidth = graphics.MeasureString("0", font).Width;
                            var doubleCharWidth = graphics.MeasureString("00", font).Width;

                            var charWidth  = doubleCharWidth - singleCharWidth;
                            var valueWidth = charWidth * (1.5f + maxColumnLenght + 1.5f);

                            widthOfColumns[index] = valueWidth;
                        }
                    }
                }
            }

            table.SetTotalWidth(widthOfColumns);
            return(table);
        }
        /// <summary>
        /// Print orders to PDF
        /// </summary>
        /// <param name="stream">Stream</param>
        /// <param name="orders">Orders</param>
        /// <param name="languageId">Language identifier; 0 to use a language used when placing an order</param>
        public virtual void PrintOrdersToPdf(Stream stream, IList<Order> orders, int languageId = 0)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");

            if (orders == null)
                throw new ArgumentNullException("orders");

            var pageSize = PageSize.A4;

            if (_pdfSettings.LetterPageSizeEnabled)
            {
                pageSize = PageSize.LETTER;
            }

            var doc = new Document(pageSize);
            var pdfWriter = PdfWriter.GetInstance(doc, stream);
            doc.Open();

            //fonts
            var titleFont = GetFont();
            titleFont.SetStyle(Font.BOLD);
            titleFont.Color = BaseColor.BLACK;
            var font = GetFont();
            var attributesFont = GetFont();
            attributesFont.SetStyle(Font.ITALIC);

            int ordCount = orders.Count;
            int ordNum = 0;

            foreach (var order in orders)
            {
                //by default _pdfSettings contains settings for the current active store
                //and we need PdfSettings for the store which was used to place an order
                //so let's load it based on a store of the current order
                var pdfSettingsByStore = _settingContext.LoadSetting<PdfSettings>(order.StoreId);

                var lang = _languageService.GetLanguageById(languageId == 0 ? order.CustomerLanguageId : languageId);
                if (lang == null || !lang.Published)
                    lang = _workContext.WorkingLanguage;

                #region Header

                //logo
                var logoPicture = _pictureService.GetPictureById(pdfSettingsByStore.LogoPictureId);
                var logoExists = logoPicture != null;

                //header
                var headerTable = new PdfPTable(logoExists ? 2 : 1);
                headerTable.RunDirection = GetDirection(lang);
                headerTable.DefaultCell.Border = Rectangle.NO_BORDER;

                //store info
                var store = _storeService.GetStoreById(order.StoreId) ?? _storeContext.CurrentStore;
                var anchor = new Anchor(store.Url.Trim(new [] { '/' }), font);
                anchor.Reference = store.Url;

                var cellHeader = new PdfPCell(new Phrase(String.Format(_localizationService.GetResource("PDFInvoice.Order#", lang.Id), order.Id), titleFont));
                cellHeader.Phrase.Add(new Phrase(Environment.NewLine));
                cellHeader.Phrase.Add(new Phrase(anchor));
                cellHeader.Phrase.Add(new Phrase(Environment.NewLine));
                cellHeader.Phrase.Add(new Phrase(String.Format(_localizationService.GetResource("PDFInvoice.OrderDate", lang.Id), _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc).ToString("D", new CultureInfo(lang.LanguageCulture))), font));
                cellHeader.Phrase.Add(new Phrase(Environment.NewLine));
                cellHeader.Phrase.Add(new Phrase(Environment.NewLine));
                cellHeader.HorizontalAlignment = Element.ALIGN_LEFT;
                cellHeader.Border = Rectangle.NO_BORDER;

                headerTable.AddCell(cellHeader);

                if (logoExists)
                    if (lang.Rtl)
                        headerTable.SetWidths(new[] { 0.2f, 0.8f });
                    else
                        headerTable.SetWidths(new[] { 0.8f, 0.2f });
                headerTable.WidthPercentage = 100f;

                //logo
                if (logoExists)
                {
                    var logoFilePath = _pictureService.GetThumbLocalPath(logoPicture, 0, false);
                    var logo = Image.GetInstance(logoFilePath);
                    logo.Alignment = GetAlignment(lang, true);
                    logo.ScaleToFit(65f, 65f);

                    var cellLogo = new PdfPCell();
                    cellLogo.Border = Rectangle.NO_BORDER;
                    cellLogo.AddElement(logo);
                    headerTable.AddCell(cellLogo);
                }
                doc.Add(headerTable);

                #endregion

                #region Addresses

                var addressTable = new PdfPTable(2);
                addressTable.RunDirection = GetDirection(lang);
                addressTable.DefaultCell.Border = Rectangle.NO_BORDER;
                addressTable.WidthPercentage = 100f;
                addressTable.SetWidths(new[] { 50, 50 });

                //billing info
                var billingAddress = new PdfPTable(1);
                billingAddress.DefaultCell.Border = Rectangle.NO_BORDER;
                billingAddress.RunDirection = GetDirection(lang);

                billingAddress.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.BillingInformation", lang.Id), titleFont));

                if (_addressSettings.CompanyEnabled && !String.IsNullOrEmpty(order.BillingAddress.Company))
                    billingAddress.AddCell(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Company", lang.Id), order.BillingAddress.Company), font));

                billingAddress.AddCell(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Name", lang.Id), order.BillingAddress.FirstName + " " + order.BillingAddress.LastName), font));
                if (_addressSettings.PhoneEnabled)
                    billingAddress.AddCell(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Phone", lang.Id), order.BillingAddress.PhoneNumber), font));
                if (_addressSettings.FaxEnabled && !String.IsNullOrEmpty(order.BillingAddress.FaxNumber))
                    billingAddress.AddCell(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Fax", lang.Id), order.BillingAddress.FaxNumber), font));
                if (_addressSettings.StreetAddressEnabled)
                    billingAddress.AddCell(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Address", lang.Id), order.BillingAddress.Address1), font));
                if (_addressSettings.StreetAddress2Enabled && !String.IsNullOrEmpty(order.BillingAddress.Address2))
                    billingAddress.AddCell(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Address2", lang.Id), order.BillingAddress.Address2), font));
                if (_addressSettings.CityEnabled || _addressSettings.StateProvinceEnabled || _addressSettings.ZipPostalCodeEnabled)
                    billingAddress.AddCell(new Paragraph("   " + String.Format("{0}, {1} {2}", order.BillingAddress.City, order.BillingAddress.StateProvince != null ? order.BillingAddress.StateProvince.GetLocalized(x => x.Name, lang.Id) : "", order.BillingAddress.ZipPostalCode), font));
                if (_addressSettings.CountryEnabled && order.BillingAddress.Country != null)
                    billingAddress.AddCell(new Paragraph("   " + String.Format("{0}", order.BillingAddress.Country != null ? order.BillingAddress.Country.GetLocalized(x => x.Name, lang.Id) : ""), font));

                //VAT number
                if (!String.IsNullOrEmpty(order.VatNumber))
                    billingAddress.AddCell(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.VATNumber", lang.Id), order.VatNumber), font));

                //custom attributes
                var customBillingAddressAttributes = _addressAttributeFormatter.FormatAttributes( order.BillingAddress.CustomAttributes);
                if (!String.IsNullOrEmpty(customBillingAddressAttributes))
                {
                    //TODO: we should add padding to each line (in case if we have sevaral custom address attributes)
                    billingAddress.AddCell(new Paragraph("   " + HtmlHelper.ConvertHtmlToPlainText(customBillingAddressAttributes, true, true), font));
                }

                //payment method
                var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(order.PaymentMethodSystemName);
                string paymentMethodStr = paymentMethod != null ? paymentMethod.GetLocalizedFriendlyName(_localizationService, lang.Id) : order.PaymentMethodSystemName;
                if (!String.IsNullOrEmpty(paymentMethodStr))
                {
                    billingAddress.AddCell(new Paragraph(" "));
                    billingAddress.AddCell(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.PaymentMethod", lang.Id), paymentMethodStr), font));
                    billingAddress.AddCell(new Paragraph());
                }

                //custom values
                var customValues = order.DeserializeCustomValues();
                if (customValues != null)
                {
                    foreach (var item in customValues)
                    {
                        billingAddress.AddCell(new Paragraph(" "));
                        billingAddress.AddCell(new Paragraph("   " + item.Key + ": " + item.Value, font));
                        billingAddress.AddCell(new Paragraph());
                    }
                }

                addressTable.AddCell(billingAddress);

                //shipping info
                var shippingAddress = new PdfPTable(1);
                shippingAddress.DefaultCell.Border = Rectangle.NO_BORDER;
                shippingAddress.RunDirection = GetDirection(lang);

                if (order.ShippingStatus != ShippingStatus.ShippingNotRequired)
                {
                    //cell = new PdfPCell();
                    //cell.Border = Rectangle.NO_BORDER;

                    if (!order.PickUpInStore)
                    {
                        if (order.ShippingAddress == null)
                            throw new NopException(string.Format("Shipping is required, but address is not available. Order ID = {0}", order.Id));

                        shippingAddress.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.ShippingInformation", lang.Id), titleFont));
                        if (!String.IsNullOrEmpty(order.ShippingAddress.Company))
                            shippingAddress.AddCell(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Company", lang.Id), order.ShippingAddress.Company), font));
                        shippingAddress.AddCell(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Name", lang.Id), order.ShippingAddress.FirstName + " " + order.ShippingAddress.LastName), font));
                        if (_addressSettings.PhoneEnabled)
                            shippingAddress.AddCell(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Phone", lang.Id), order.ShippingAddress.PhoneNumber), font));
                        if (_addressSettings.FaxEnabled && !String.IsNullOrEmpty(order.ShippingAddress.FaxNumber))
                            shippingAddress.AddCell(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Fax", lang.Id), order.ShippingAddress.FaxNumber), font));
                        if (_addressSettings.StreetAddressEnabled)
                            shippingAddress.AddCell(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Address", lang.Id), order.ShippingAddress.Address1), font));
                        if (_addressSettings.StreetAddress2Enabled && !String.IsNullOrEmpty(order.ShippingAddress.Address2))
                            shippingAddress.AddCell(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Address2", lang.Id), order.ShippingAddress.Address2), font));
                        if (_addressSettings.CityEnabled || _addressSettings.StateProvinceEnabled || _addressSettings.ZipPostalCodeEnabled)
                            shippingAddress.AddCell(new Paragraph("   " + String.Format("{0}, {1} {2}", order.ShippingAddress.City, order.ShippingAddress.StateProvince != null ? order.ShippingAddress.StateProvince.GetLocalized(x => x.Name, lang.Id) : "", order.ShippingAddress.ZipPostalCode), font));
                        if (_addressSettings.CountryEnabled && order.ShippingAddress.Country != null)
                            shippingAddress.AddCell(new Paragraph("   " + String.Format("{0}", order.ShippingAddress.Country != null ? order.ShippingAddress.Country.GetLocalized(x => x.Name, lang.Id) : ""), font));
                        //custom attributes
                        var customShippingAddressAttributes = _addressAttributeFormatter.FormatAttributes(order.ShippingAddress.CustomAttributes);
                        if (!String.IsNullOrEmpty(customShippingAddressAttributes))
                        {
                            //TODO: we should add padding to each line (in case if we have sevaral custom address attributes)
                            shippingAddress.AddCell(new Paragraph("   " + HtmlHelper.ConvertHtmlToPlainText(customShippingAddressAttributes, true, true), font));
                        }
                        shippingAddress.AddCell(new Paragraph(" "));
                    }
                    shippingAddress.AddCell(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.ShippingMethod", lang.Id), order.ShippingMethod), font));
                    shippingAddress.AddCell(new Paragraph());

                    addressTable.AddCell(shippingAddress);
                }
                else
                {
                    shippingAddress.AddCell(new Paragraph());
                    addressTable.AddCell(shippingAddress);
                }

                doc.Add(addressTable);
                doc.Add(new Paragraph(" "));

                #endregion

                #region Products

                //products
                var productsHeader = new PdfPTable(1);
                productsHeader.RunDirection = GetDirection(lang);
                productsHeader.WidthPercentage = 100f;
                var cellProducts = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.Product(s)", lang.Id), titleFont));
                cellProducts.Border = Rectangle.NO_BORDER;
                productsHeader.AddCell(cellProducts);
                doc.Add(productsHeader);
                doc.Add(new Paragraph(" "));

                var orderItems = _orderService.GetAllOrderItems(order.Id, null, null, null, null, null, null);

                var productsTable = new PdfPTable(_catalogSettings.ShowProductSku ? 5 : 4);
                productsTable.RunDirection = GetDirection(lang);
                productsTable.WidthPercentage = 100f;
                if (lang.Rtl)
                {
                    productsTable.SetWidths(_catalogSettings.ShowProductSku
                        ? new[] {15, 10, 15, 15, 45}
                        : new[] {20, 10, 20, 50});
                }
                else
                {
                    productsTable.SetWidths(_catalogSettings.ShowProductSku
                        ? new[] {45, 15, 15, 10, 15}
                        : new[] {50, 20, 10, 20});
                }

                //product name
                var cellProductItem = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.ProductName", lang.Id), font));
                cellProductItem.BackgroundColor = BaseColor.LIGHT_GRAY;
                cellProductItem.HorizontalAlignment = Element.ALIGN_CENTER;
                productsTable.AddCell(cellProductItem);

                //SKU
                if (_catalogSettings.ShowProductSku)
                {
                    cellProductItem = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.SKU", lang.Id), font));
                    cellProductItem.BackgroundColor = BaseColor.LIGHT_GRAY;
                    cellProductItem.HorizontalAlignment = Element.ALIGN_CENTER;
                    productsTable.AddCell(cellProductItem);
                }

                //price
                cellProductItem = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.ProductPrice", lang.Id), font));
                cellProductItem.BackgroundColor = BaseColor.LIGHT_GRAY;
                cellProductItem.HorizontalAlignment = Element.ALIGN_CENTER;
                productsTable.AddCell(cellProductItem);

                //qty
                cellProductItem = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.ProductQuantity", lang.Id), font));
                cellProductItem.BackgroundColor = BaseColor.LIGHT_GRAY;
                cellProductItem.HorizontalAlignment = Element.ALIGN_CENTER;
                productsTable.AddCell(cellProductItem);

                //total
                cellProductItem = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.ProductTotal", lang.Id), font));
                cellProductItem.BackgroundColor = BaseColor.LIGHT_GRAY;
                cellProductItem.HorizontalAlignment = Element.ALIGN_CENTER;
                productsTable.AddCell(cellProductItem);

                foreach (var orderItem in orderItems)
                {
                    var pAttribTable = new PdfPTable(1);
                    pAttribTable.RunDirection = GetDirection(lang);
                    pAttribTable.DefaultCell.Border = Rectangle.NO_BORDER;

                    var p = orderItem.Product;

                    //product name
                    string name = p.GetLocalized(x => x.Name, lang.Id);
                    pAttribTable.AddCell(new Paragraph(name, font));
                    cellProductItem.AddElement(new Paragraph(name, font));
                    //attributes
                    if (!String.IsNullOrEmpty(orderItem.AttributeDescription))
                    {
                        var attributesParagraph = new Paragraph(HtmlHelper.ConvertHtmlToPlainText(orderItem.AttributeDescription, true, true), attributesFont);
                        pAttribTable.AddCell(attributesParagraph);
                    }
                    //rental info
                    if (orderItem.Product.IsRental)
                    {
                        var rentalStartDate = orderItem.RentalStartDateUtc.HasValue ? orderItem.Product.FormatRentalDate(orderItem.RentalStartDateUtc.Value) : "";
                        var rentalEndDate = orderItem.RentalEndDateUtc.HasValue ? orderItem.Product.FormatRentalDate(orderItem.RentalEndDateUtc.Value) : "";
                        var rentalInfo = string.Format(_localizationService.GetResource("Order.Rental.FormattedDate"),
                            rentalStartDate, rentalEndDate);

                        var rentalInfoParagraph = new Paragraph(rentalInfo, attributesFont);
                        pAttribTable.AddCell(rentalInfoParagraph);
                    }
                    productsTable.AddCell(pAttribTable);

                    //SKU
                    if (_catalogSettings.ShowProductSku)
                    {
                        var sku = p.FormatSku(orderItem.AttributesXml, _productAttributeParser);
                        cellProductItem = new PdfPCell(new Phrase(sku ?? String.Empty, font));
                        cellProductItem.HorizontalAlignment = Element.ALIGN_CENTER;
                        productsTable.AddCell(cellProductItem);
                    }

                    //price
                    string unitPrice;
                    if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                    {
                        //including tax
                        var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                        unitPrice = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, true);
                    }
                    else
                    {
                        //excluding tax
                        var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                        unitPrice = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, false);
                    }
                    cellProductItem = new PdfPCell(new Phrase(unitPrice, font));
                    cellProductItem.HorizontalAlignment = Element.ALIGN_LEFT;
                    productsTable.AddCell(cellProductItem);

                    //qty
                    cellProductItem = new PdfPCell(new Phrase(orderItem.Quantity.ToString(), font));
                    cellProductItem.HorizontalAlignment = Element.ALIGN_LEFT;
                    productsTable.AddCell(cellProductItem);

                    //total
                    string subTotal;
                    if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                    {
                        //including tax
                        var priceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.PriceInclTax, order.CurrencyRate);
                        subTotal = _priceFormatter.FormatPrice(priceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, true);
                    }
                    else
                    {
                        //excluding tax
                        var priceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.PriceExclTax, order.CurrencyRate);
                        subTotal = _priceFormatter.FormatPrice(priceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, false);
                    }
                    cellProductItem = new PdfPCell(new Phrase(subTotal, font));
                    cellProductItem.HorizontalAlignment = Element.ALIGN_LEFT;
                    productsTable.AddCell(cellProductItem);
                }
                doc.Add(productsTable);

                #endregion

                #region Checkout attributes

                if (!String.IsNullOrEmpty(order.CheckoutAttributeDescription))
                {
                    doc.Add(new Paragraph(" "));
                    var attribTable = new PdfPTable(1);
                    attribTable.RunDirection = GetDirection(lang);
                    attribTable.WidthPercentage = 100f;

                    string attributes = HtmlHelper.ConvertHtmlToPlainText(order.CheckoutAttributeDescription, true, true);
                    var cCheckoutAttributes = new PdfPCell(new Phrase(attributes, font));
                    cCheckoutAttributes.Border = Rectangle.NO_BORDER;
                    cCheckoutAttributes.HorizontalAlignment = Element.ALIGN_RIGHT;
                    attribTable.AddCell(cCheckoutAttributes);
                    doc.Add(attribTable);
                }

                #endregion

                #region Totals

                //subtotal
                var totalsTable = new PdfPTable(1);
                totalsTable.RunDirection = GetDirection(lang);
                totalsTable.DefaultCell.Border = Rectangle.NO_BORDER;
                totalsTable.WidthPercentage = 100f;

                //order subtotal
                if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax && !_taxSettings.ForceTaxExclusionFromOrderSubtotal)
                {
                    //including tax

                    var orderSubtotalInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalInclTax, order.CurrencyRate);
                    string orderSubtotalInclTaxStr = _priceFormatter.FormatPrice(orderSubtotalInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, true);

                    var p = new PdfPCell(new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Sub-Total", lang.Id), orderSubtotalInclTaxStr), font));
                    p.HorizontalAlignment = Element.ALIGN_RIGHT;
                    p.Border = Rectangle.NO_BORDER;
                    totalsTable.AddCell(p);
                }
                else
                {
                    //excluding tax

                    var orderSubtotalExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalExclTax, order.CurrencyRate);
                    string orderSubtotalExclTaxStr = _priceFormatter.FormatPrice(orderSubtotalExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, false);

                    var p = new PdfPCell(new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Sub-Total", lang.Id), orderSubtotalExclTaxStr), font));
                    p.HorizontalAlignment = Element.ALIGN_RIGHT;
                    p.Border = Rectangle.NO_BORDER;
                    totalsTable.AddCell(p);
                }

                //discount (applied to order subtotal)
                if (order.OrderSubTotalDiscountExclTax > decimal.Zero)
                {
                    //order subtotal
                    if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax && !_taxSettings.ForceTaxExclusionFromOrderSubtotal)
                    {
                        //including tax

                        var orderSubTotalDiscountInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountInclTax, order.CurrencyRate);
                        string orderSubTotalDiscountInCustomerCurrencyStr = _priceFormatter.FormatPrice(-orderSubTotalDiscountInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, true);

                        var p = new PdfPCell(new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Discount", lang.Id), orderSubTotalDiscountInCustomerCurrencyStr), font));
                        p.HorizontalAlignment = Element.ALIGN_RIGHT;
                        p.Border = Rectangle.NO_BORDER;
                        totalsTable.AddCell(p);
                    }
                    else
                    {
                        //excluding tax

                        var orderSubTotalDiscountExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountExclTax, order.CurrencyRate);
                        string orderSubTotalDiscountInCustomerCurrencyStr = _priceFormatter.FormatPrice(-orderSubTotalDiscountExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, false);

                        var p = new PdfPCell(new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Discount", lang.Id), orderSubTotalDiscountInCustomerCurrencyStr), font));
                        p.HorizontalAlignment = Element.ALIGN_RIGHT;
                        p.Border = Rectangle.NO_BORDER;
                        totalsTable.AddCell(p);
                    }
                }

                //shipping
                if (order.ShippingStatus != ShippingStatus.ShippingNotRequired)
                {
                    if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                    {
                        //including tax
                        var orderShippingInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingInclTax, order.CurrencyRate);
                        string orderShippingInclTaxStr = _priceFormatter.FormatShippingPrice(orderShippingInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, true);

                        var p = new PdfPCell(new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Shipping", lang.Id), orderShippingInclTaxStr), font));
                        p.HorizontalAlignment = Element.ALIGN_RIGHT;
                        p.Border = Rectangle.NO_BORDER;
                        totalsTable.AddCell(p);
                    }
                    else
                    {
                        //excluding tax
                        var orderShippingExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingExclTax, order.CurrencyRate);
                        string orderShippingExclTaxStr = _priceFormatter.FormatShippingPrice(orderShippingExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, false);

                        var p = new PdfPCell(new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Shipping", lang.Id), orderShippingExclTaxStr), font));
                        p.HorizontalAlignment = Element.ALIGN_RIGHT;
                        p.Border = Rectangle.NO_BORDER;
                        totalsTable.AddCell(p);
                    }
                }

                //payment fee
                if (order.PaymentMethodAdditionalFeeExclTax > decimal.Zero)
                {
                    if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                    {
                        //including tax
                        var paymentMethodAdditionalFeeInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeInclTax, order.CurrencyRate);
                        string paymentMethodAdditionalFeeInclTaxStr = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, true);

                        var p = new PdfPCell(new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.PaymentMethodAdditionalFee", lang.Id), paymentMethodAdditionalFeeInclTaxStr), font));
                        p.HorizontalAlignment = Element.ALIGN_RIGHT;
                        p.Border = Rectangle.NO_BORDER;
                        totalsTable.AddCell(p);
                    }
                    else
                    {
                        //excluding tax
                        var paymentMethodAdditionalFeeExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeExclTax, order.CurrencyRate);
                        string paymentMethodAdditionalFeeExclTaxStr = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, false);

                        var p = new PdfPCell(new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.PaymentMethodAdditionalFee", lang.Id), paymentMethodAdditionalFeeExclTaxStr), font));
                        p.HorizontalAlignment = Element.ALIGN_RIGHT;
                        p.Border = Rectangle.NO_BORDER;
                        totalsTable.AddCell(p);
                    }
                }

                //tax
                string taxStr = string.Empty;
                var taxRates = new SortedDictionary<decimal, decimal>();
                bool displayTax = true;
                bool displayTaxRates = true;
                if (_taxSettings.HideTaxInOrderSummary && order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                {
                    displayTax = false;
                }
                else
                {
                    if (order.OrderTax == 0 && _taxSettings.HideZeroTax)
                    {
                        displayTax = false;
                        displayTaxRates = false;
                    }
                    else
                    {
                        taxRates = order.TaxRatesDictionary;

                        displayTaxRates = _taxSettings.DisplayTaxRates && taxRates.Count > 0;
                        displayTax = !displayTaxRates;

                        var orderTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTax, order.CurrencyRate);
                        taxStr = _priceFormatter.FormatPrice(orderTaxInCustomerCurrency, true, order.CustomerCurrencyCode, false, lang);
                    }
                }
                if (displayTax)
                {
                    var p = new PdfPCell(new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Tax", lang.Id), taxStr), font));
                    p.HorizontalAlignment = Element.ALIGN_RIGHT;
                    p.Border = Rectangle.NO_BORDER;
                    totalsTable.AddCell(p);
                }
                if (displayTaxRates)
                {
                    foreach (var item in taxRates)
                    {
                        string taxRate = String.Format(_localizationService.GetResource("PDFInvoice.TaxRate", lang.Id), _priceFormatter.FormatTaxRate(item.Key));
                        string taxValue = _priceFormatter.FormatPrice(_currencyService.ConvertCurrency(item.Value, order.CurrencyRate), true, order.CustomerCurrencyCode, false, lang);

                        var p = new PdfPCell(new Paragraph(String.Format("{0} {1}", taxRate, taxValue), font));
                        p.HorizontalAlignment = Element.ALIGN_RIGHT;
                        p.Border = Rectangle.NO_BORDER;
                        totalsTable.AddCell(p);
                    }
                }

                //discount (applied to order total)
                if (order.OrderDiscount > decimal.Zero)
                {
                    var orderDiscountInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderDiscount, order.CurrencyRate);
                    string orderDiscountInCustomerCurrencyStr = _priceFormatter.FormatPrice(-orderDiscountInCustomerCurrency, true, order.CustomerCurrencyCode, false, lang);

                    var p = new PdfPCell(new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Discount", lang.Id), orderDiscountInCustomerCurrencyStr), font));
                    p.HorizontalAlignment = Element.ALIGN_RIGHT;
                    p.Border = Rectangle.NO_BORDER;
                    totalsTable.AddCell(p);
                }

                //gift cards
                foreach (var gcuh in order.GiftCardUsageHistory)
                {
                    string gcTitle = string.Format(_localizationService.GetResource("PDFInvoice.GiftCardInfo", lang.Id), gcuh.GiftCard.GiftCardCouponCode);
                    string gcAmountStr = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(gcuh.UsedValue, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, lang);

                    var p = new PdfPCell(new Paragraph(String.Format("{0} {1}", gcTitle, gcAmountStr), font));
                    p.HorizontalAlignment = Element.ALIGN_RIGHT;
                    p.Border = Rectangle.NO_BORDER;
                    totalsTable.AddCell(p);
                }

                //reward points
                if (order.RedeemedRewardPointsEntry != null)
                {
                    string rpTitle = string.Format(_localizationService.GetResource("PDFInvoice.RewardPoints", lang.Id), -order.RedeemedRewardPointsEntry.Points);
                    string rpAmount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(order.RedeemedRewardPointsEntry.UsedAmount, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, lang);

                    var p = new PdfPCell(new Paragraph(String.Format("{0} {1}", rpTitle, rpAmount), font));
                    p.HorizontalAlignment = Element.ALIGN_RIGHT;
                    p.Border = Rectangle.NO_BORDER;
                    totalsTable.AddCell(p);
                }

                //order total
                var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate);
                string orderTotalStr = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, lang);

                var pTotal = new PdfPCell(new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.OrderTotal", lang.Id), orderTotalStr), titleFont));
                pTotal.HorizontalAlignment = Element.ALIGN_RIGHT;
                pTotal.Border = Rectangle.NO_BORDER;
                totalsTable.AddCell(pTotal);

                doc.Add(totalsTable);

                #endregion

                #region Order notes

                if (pdfSettingsByStore.RenderOrderNotes)
                {
                    var orderNotes = order.OrderNotes
                        .Where(on => on.DisplayToCustomer)
                        .OrderByDescending(on => on.CreatedOnUtc)
                        .ToList();
                    if (orderNotes.Count > 0)
                    {
                        var notesHeader = new PdfPTable(1);
                        notesHeader.RunDirection = GetDirection(lang);
                        notesHeader.WidthPercentage = 100f;
                        var cellOrderNote = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.OrderNotes", lang.Id), titleFont));
                        cellOrderNote.Border = Rectangle.NO_BORDER;
                        notesHeader.AddCell(cellOrderNote);
                        doc.Add(notesHeader);
                        doc.Add(new Paragraph(" "));

                        var notesTable = new PdfPTable(2);
                        notesTable.RunDirection = GetDirection(lang);
                        if (lang.Rtl)
                        {
                            notesTable.SetWidths(new[] {70, 30});
                        }
                        else
                        {
                            notesTable.SetWidths(new[] {30, 70});
                        }
                        notesTable.WidthPercentage = 100f;

                        //created on
                        cellOrderNote = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.OrderNotes.CreatedOn", lang.Id), font));
                        cellOrderNote.BackgroundColor = BaseColor.LIGHT_GRAY;
                        cellOrderNote.HorizontalAlignment = Element.ALIGN_CENTER;
                        notesTable.AddCell(cellOrderNote);

                        //note
                        cellOrderNote = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.OrderNotes.Note", lang.Id), font));
                        cellOrderNote.BackgroundColor = BaseColor.LIGHT_GRAY;
                        cellOrderNote.HorizontalAlignment = Element.ALIGN_CENTER;
                        notesTable.AddCell(cellOrderNote);

                        foreach (var orderNote in orderNotes)
                        {
                            cellOrderNote = new PdfPCell(new Phrase(_dateTimeHelper.ConvertToUserTime(orderNote.CreatedOnUtc, DateTimeKind.Utc).ToString(), font));
                            cellOrderNote.HorizontalAlignment = Element.ALIGN_LEFT;
                            notesTable.AddCell(cellOrderNote);

                            cellOrderNote = new PdfPCell(new Phrase(HtmlHelper.ConvertHtmlToPlainText(orderNote.FormatOrderNoteText(), true, true), font));
                            cellOrderNote.HorizontalAlignment = Element.ALIGN_LEFT;
                            notesTable.AddCell(cellOrderNote);

                            //should we display a link to downloadable files here?
                            //I think, no. Onyway, PDFs are printable documents and links (files) are useful here
                        }
                        doc.Add(notesTable);
                    }
                }

                #endregion

                #region Footer

                if (!String.IsNullOrEmpty(pdfSettingsByStore.InvoiceFooterTextColumn1) || !String.IsNullOrEmpty(pdfSettingsByStore.InvoiceFooterTextColumn2))
                {
                    var column1Lines = String.IsNullOrEmpty(pdfSettingsByStore.InvoiceFooterTextColumn1) ?
                        new List<string>() :
                        pdfSettingsByStore.InvoiceFooterTextColumn1
                        .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                        .ToList();
                    var column2Lines = String.IsNullOrEmpty(pdfSettingsByStore.InvoiceFooterTextColumn2) ?
                        new List<string>() :
                        pdfSettingsByStore.InvoiceFooterTextColumn2
                        .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                        .ToList();
                    if (column1Lines.Count > 0 || column2Lines.Count > 0)
                    {
                        var totalLines = Math.Max(column1Lines.Count, column2Lines.Count);
                        const float margin = 43;

                        //if you have really a lot of lines in the footer, then replace 9 with 10 or 11
                        int footerHeight = totalLines * 9;
                        var directContent = pdfWriter.DirectContent;
                        directContent.MoveTo(pageSize.GetLeft(margin), pageSize.GetBottom(margin) + footerHeight);
                        directContent.LineTo(pageSize.GetRight(margin), pageSize.GetBottom(margin) + footerHeight);
                        directContent.Stroke();

                        var footerTable = new PdfPTable(2);
                        footerTable.WidthPercentage = 100f;
                        footerTable.SetTotalWidth(new float[] { 250, 250 });
                        footerTable.RunDirection = GetDirection(lang);

                        //column 1
                        if (column1Lines.Count > 0)
                        {
                            var column1 = new PdfPCell(new Phrase());
                            column1.Border = Rectangle.NO_BORDER;
                            column1.HorizontalAlignment = Element.ALIGN_LEFT;
                            foreach (var footerLine in column1Lines)
                            {
                                column1.Phrase.Add(new Phrase(footerLine, font));
                                column1.Phrase.Add(new Phrase(Environment.NewLine));
                            }
                            footerTable.AddCell(column1);
                        }
                        else
                        {
                            var column = new PdfPCell(new Phrase(" "));
                            column.Border = Rectangle.NO_BORDER;
                            footerTable.AddCell(column);
                        }

                        //column 2
                        if (column2Lines.Count > 0)
                        {
                            var column2 = new PdfPCell(new Phrase());
                            column2.Border = Rectangle.NO_BORDER;
                            column2.HorizontalAlignment = Element.ALIGN_LEFT;
                            foreach (var footerLine in column2Lines)
                            {
                                column2.Phrase.Add(new Phrase(footerLine, font));
                                column2.Phrase.Add(new Phrase(Environment.NewLine));
                            }
                            footerTable.AddCell(column2);
                        }
                        else
                        {
                            var column = new PdfPCell(new Phrase(" "));
                            column.Border = Rectangle.NO_BORDER;
                            footerTable.AddCell(column);
                        }

                        footerTable.WriteSelectedRows(0, totalLines, pageSize.GetLeft(margin), pageSize.GetBottom(margin) + footerHeight, directContent);
                    }
                }

                #endregion

                ordNum++;
                if (ordNum < ordCount)
                {
                    doc.NewPage();
                }
            }
            doc.Close();
        }
        public override void OnStartPage(PdfWriter writer, Document document)
        {
            base.OnStartPage(writer, document);
            Rectangle pageSize = document.PageSize;        
            
            PdfPTable headerTable = new PdfPTable(2);
			headerTable.SetTotalWidth(new float[]{1,4});
			float cellHeight = document.TopMargin;
			headerTable.TotalWidth = pageSize.Width;


			var leftTable = new PdfPTable(1);  // logo y nit 
			PdfPCell leftTableCell = new PdfPCell( leftTable);
			leftTableCell.FixedHeight = cellHeight;
			leftTableCell.Padding=0;
			leftTableCell.PaddingTop= 5;
			leftTableCell.PaddingLeft = 0;
			leftTableCell.Border= PdfPCell.NO_BORDER;
			headerTable.AddCell(leftTableCell);

			var cell = new PdfPCell(Image.GetInstance(LogoFile),false);
			cell.FixedHeight = cellHeight*80/100;
			cell.HorizontalAlignment= PdfPCell.ALIGN_CENTER;
			cell.Padding=0;
			cell.PaddingTop=0;
			cell.PaddingLeft = 0;
			cell.Border= PdfPCell.NO_BORDER;
			leftTable.AddCell(cell);

			cell = new PdfPCell(new Phrase(Empresa.Nit, F8));
			cell.HorizontalAlignment= PdfPCell.ALIGN_CENTER;
			cell.Border= PdfPCell.NO_BORDER;
			leftTable.AddCell(cell);

			//------------------------------------------------------------------------

			PdfPTable rightTable = new PdfPTable(4);  // Consecutivo, Elaborado por etc...
			rightTable.SetTotalWidth(new float[]{3,4,3,6});
			PdfPCell rightTableCell = new PdfPCell(rightTable);
			rightTableCell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
			rightTableCell.Padding = 2;
			rightTableCell.PaddingTop= 10;
            rightTableCell.PaddingBottom = 2;
			rightTableCell.FixedHeight = cellHeight;
			rightTableCell.Border= PdfPCell.NO_BORDER;

            headerTable.AddCell(rightTableCell);

			cell = new PdfPCell(new Phrase("", F10));
			cell.Border= PdfPCell.NO_BORDER;
			cell.Colspan=3;
			rightTable.AddCell(cell);

			var textoFormato=Empresa.Formato;
			cell = new PdfPCell(new Phrase(textoFormato, F10));
			cell.Border= PdfPCell.NO_BORDER;
			rightTable.AddCell(cell);

			cell = new PdfPCell(new Phrase("", F10));
			cell.Border= PdfPCell.NO_BORDER;
			cell.Colspan=3;
			rightTable.AddCell(cell);

			textoFormato=Empresa.Edicion;
			cell = new PdfPCell(new Phrase(textoFormato, F10));
			cell.Border= PdfPCell.NO_BORDER;
			cell.PaddingBottom = 8;
			rightTable.AddCell(cell);

			cell = new PdfPCell(new Phrase("Oferta No:", F10));
			cell.Border= PdfPCell.NO_BORDER;
			rightTable.AddCell(cell);

			cell = new PdfPCell(new Phrase(string.Format("{0}-{1}", Prefijo, Pedido.Consecutivo), F10));
			cell.Border= PdfPCell.NO_BORDER;
			rightTable.AddCell(cell);

			cell = new PdfPCell(new Phrase("Forma de Pago:", F10));
			cell.Border= PdfPCell.NO_BORDER;
			rightTable.AddCell(cell);

			cell = new PdfPCell(new Phrase(Pedido.DescripcionFormaPago, F10));
			cell.Border= PdfPCell.NO_BORDER;
			rightTable.AddCell(cell);


			cell = new PdfPCell(new Phrase("Fecha Envio:", F10));
			cell.Border= PdfPCell.NO_BORDER;
			rightTable.AddCell(cell);

			cell = new PdfPCell(new Phrase(Pedido.FechaEnvio.HasValue? Pedido.FechaEnvio.Value.Format():"BORRADOR !!!",
			                               F10));
			cell.Border= PdfPCell.NO_BORDER;
			rightTable.AddCell(cell);

			cell = new PdfPCell(new Phrase("Fecha Aceptación:", F10));
			cell.Border= PdfPCell.NO_BORDER;
			rightTable.AddCell(cell);

			cell = new PdfPCell(new Phrase(Pedido.FechaAceptacion.Format(), F10));
			cell.Border= PdfPCell.NO_BORDER;
			rightTable.AddCell(cell);

			cell = new PdfPCell(new Phrase("Valida Hasta:", F10));
			cell.Border= PdfPCell.NO_BORDER;
			rightTable.AddCell(cell);

			cell = new PdfPCell(new Phrase(Pedido.VigenteHasta.Format(), F10));
			cell.Border= PdfPCell.NO_BORDER;
			rightTable.AddCell(cell);

			cell = new PdfPCell(new Phrase("Enviado por :", F10));
			cell.Border= PdfPCell.NO_BORDER;
			rightTable.AddCell(cell);

			cell = new PdfPCell(new Phrase(Pedido.NombreEnviadoPor, F10));
			cell.Border= PdfPCell.NO_BORDER;
			rightTable.AddCell(cell);


            cb.SetRGBColorFill(0, 0, 0);
            //HeaderTable.WriteSelectedRows(0, -1, pageSize.GetLeft(40), pageSize.GetTop(50), cb);

			headerTable.WriteSelectedRows( 0, -1,  0,  
			                              pageSize.Height - cellHeight + headerTable.TotalHeight,
			                              writer.DirectContent );
            
        }
Esempio n. 10
0
        /// <summary>
        /// 貨運單  delivery_store=17 即 吉甲地車隊貨到付款 才須匯出貨運單
        /// </summary>
        public void GetCarWaybillsPDF()
        {
            _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
            string deliver_id = string.Empty;
            if (!string.IsNullOrEmpty(Request.Params["deliver_id"]))
            {
                deliver_id = Request.Params["deliver_id"];
            }
            string ticketid = string.Empty;
            if (!string.IsNullOrEmpty(Request.Params["ticket_id"]))
            {
                ticketid = Request.Params["ticket_id"];
                ticketid = ticketid.Remove(ticketid.LastIndexOf(','));
            }
            DataTable bills = _DeliverDetailMgr.GetWayBills(deliver_id, ticketid);
            string estimated_delivery_date = string.Empty;
            string sestimated_arrival_period = string.Empty;
            string estimated_arrival_period = string.Empty;
            string infor = string.Empty;
            string receivable = string.Empty;
            string order_id = string.Empty;
            int i = 0;
            Document document = new Document(PageSize.A4, (float)5, (float)5, (float)5, (float)0.5);
            int iTemp = 0;
            string filename = string.Empty;
            if (int.TryParse(ticketid, out iTemp))
            {
                filename = "carwaybills_T" + ticketid.PadLeft(8, '0') + ".pdf";
            }
            else
            {
                filename = "carwaybills_T" + ticketid.Substring(0, ticketid.IndexOf(',')).ToString().PadLeft(8, '0') + ".pdf";
            }

            string newPDFName = Server.MapPath(excelPath) + filename;
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPDFName, FileMode.Create));
            document.Open();
            BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bfChinese, 8, iTextSharp.text.Font.UNDERLINE, iTextSharp.text.BaseColor.RED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  

            foreach (DataRow dr in bills.Rows)
            {
                estimated_delivery_date = !string.IsNullOrEmpty(dr["estimated_delivery_date"].ToString()) ? DateTime.Parse(dr["estimated_delivery_date"].ToString()).ToString("yyyy-MM-dd") : DateTime.Now.ToString("yyyy-MM-dd");
                estimated_arrival_period = dr["estimated_arrival_period"].ToString();
                switch (dr["estimated_arrival_period"].ToString())
                {
                    case "0":
                        sestimated_arrival_period = "不限時";
                        break;
                    case "1":
                        sestimated_arrival_period = "12:00以前";
                        break;
                    case "2":
                        sestimated_arrival_period = "12:00-17:00";
                        break;
                    case "3":
                        sestimated_arrival_period = "17:00-20:00";
                        break;
                    default:
                        break;

                }
                //infor = dr["delivery_name"].ToString() + "\n\n" + CommonFunction.ZipAddress(dr["delivery_zip"].ToString()) + "\n" + dr["delivery_address"].ToString() + "\n\n\n" + dr["delivery_mobile"].ToString();
                receivable = dr["receivable"].ToString() != "0" ? dr["receivable"].ToString() : "不收款";
                order_id = dr["order_id"].ToString();
                font = new iTextSharp.text.Font(bfChinese, 16, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑 
                Chunk c1 = new Chunk(dr["delivery_name"].ToString() + "\n\n", font);
                font = new iTextSharp.text.Font(bfChinese, 8, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑 
                Chunk c2 = new Chunk(CommonFunction.ZipAddress(dr["delivery_zip"].ToString()) + "\n\n" + dr["delivery_address"].ToString() + "\n\n\n", font);
                font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑 
                Chunk c3 = new Chunk(dr["delivery_mobile"].ToString(), font);
                Phrase pinfor = new Phrase();
                pinfor.Add(c1);
                pinfor.Add(c2);
                pinfor.Add(c3);
                BarCode.Code128 _Code = new BarCode.Code128();
                _Code.ValueFont = new System.Drawing.Font("宋体", 20);
                System.Drawing.Bitmap imgTemp = _Code.GetCodeImage(order_id, BarCode.Code128.Encode.Code128A);
                imgTemp.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                iTextSharp.text.Image IMG = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG.ScaleToFit(200, 40);
                Chunk orderidck = new Chunk(IMG, 0, 0); //图片可设置 偏移


                imgTemp = _Code.GetCodeImage("D" + dr["deliver_id"].ToString().PadLeft(8, '0'), BarCode.Code128.Encode.Code128A);
                imgTemp.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                IMG = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG.ScaleToFit(200, 40);
                Chunk deliveridck = new Chunk(IMG, 0, 0); //图片可设置 偏移



                //PdfContentByte cb = writer.DirectContent;
                // cb.BeginText();
                if (i % 2 == 0 && i != 0)
                {
                    document.NewPage();
                }
                PdfPTable totaltable = new PdfPTable(3);
                totaltable.WidthPercentage = 100;
                totaltable.SetWidths(new int[] { 45, 2, 53 });
                totaltable.DefaultCell.DisableBorderSide(1);
                totaltable.DefaultCell.DisableBorderSide(2);
                totaltable.DefaultCell.DisableBorderSide(4);
                totaltable.DefaultCell.DisableBorderSide(8);
                PdfPCell cell;
                #region 左邊框
                PdfPTable table = new PdfPTable(4);
                table.SetTotalWidth(new float[] { 60, 75, 10, 100 });
                table.DefaultCell.UseAscender = true;
                table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                table.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell = new PdfPCell(new Phrase("出貨日", font));
                cell.FixedHeight = 17f;
                table.AddCell(cell);
                table.AddCell(new Phrase("預定配送日", font));

                cell = new PdfPCell(new Phrase("指定時段", font));
                cell.Colspan = 2;
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(DateTime.Now.ToString("yyyyMMdd"), font));
                cell.FixedHeight = 17f;
                table.AddCell(cell);
                //table.AddCell(new Phrase(DateTime.Now.ToString("yyyyMMdd"), font));
                table.AddCell(new Phrase(estimated_delivery_date, font));
                table.AddCell(new Phrase(estimated_arrival_period, font));
                table.AddCell(new Phrase(sestimated_arrival_period, font));
                table.AddCell(new Phrase("收\n件\n人", font));
                cell = new PdfPCell(pinfor);
                cell.Colspan = 3;
                table.AddCell(cell);
                table.AddCell(new Phrase("寄件人", font));
                font = new iTextSharp.text.Font(bfChinese, 7, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                cell = new PdfPCell(new Phrase("台北市南港區八德路四段768巷5號4F之一 \n\n 吉甲地好市集股份有限公司", font));
                cell.UseAscender = true;
                cell.HorizontalAlignment = 3;
                cell.Colspan = 3;
                table.AddCell(cell);
                font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                table.AddCell(new Phrase("訂單編號", font));
                cell = new PdfPCell(new Phrase(orderidck));
                cell.UseAscender = true;
                cell.HorizontalAlignment = 1;
                cell.Colspan = 3;
                table.AddCell(cell);
                font = new iTextSharp.text.Font(bfChinese, 14, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                cell = new PdfPCell(new Phrase("吉\n甲\n地", font));
                cell.UseDescender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(2);
                table.AddCell(cell);
                PdfPTable stable = new PdfPTable(2);
                stable.DefaultCell.UseAscender = true;
                stable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                stable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                stable.AddCell(new Phrase("代收貨款", font));
                stable.AddCell(new Phrase(receivable, font));
                stable.AddCell(new Phrase("出貨單號", font));
                cell = new PdfPCell(new Phrase(deliveridck));
                float h = cell.Height;
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                stable.AddCell(cell);
                cell = new PdfPCell(stable);
                cell.Colspan = 3;
                table.AddCell(cell);
                // table.WriteSelectedRows(0, -1, 10, 820, writer.DirectContent);
                #endregion
                #region
                totaltable.AddCell(table);
                totaltable.AddCell(" ");
                #endregion
                #region 右邊框
                font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                table = new PdfPTable(6);
                table.SetTotalWidth(new float[] { 60, 70, 40, 65, 40, 50 });
                table.DefaultCell.UseAscender = true;
                table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                table.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell = new PdfPCell();
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(4);
                table.AddCell(cell);
                stable = new PdfPTable(1);
                stable.DefaultCell.UseAscender = true;
                stable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                stable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                //stable.AddCell(new Phrase("包裹查詢號碼", font));
                cell = new PdfPCell(new Phrase("包裹查詢號碼", font));
                cell.FixedHeight = 17f;
                stable.AddCell(cell);
                //stable.AddCell(new Phrase("D" + dr["deliver_id"].ToString().PadLeft(8, '0'), font));
                cell = new PdfPCell(new Phrase("D" + dr["deliver_id"].ToString().PadLeft(8, '0'), font));
                cell.FixedHeight = 17f;
                stable.AddCell(cell);
                cell = new PdfPCell(stable);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(deliveridck));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.Colspan = 2;
                table.AddCell(cell);
                table.AddCell(new Phrase("備註", font));
                string name = string.Empty;
                for (int k = 0; k < dr["delivery_name"].ToString().Length; k++)
                {
                    name += dr["delivery_name"].ToString()[k] + "\n";
                }
                font = new iTextSharp.text.Font(bfChinese, 14, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                cell = new PdfPCell(new Phrase("吉\n甲\n地\n\n" + name, font));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.Rowspan = 6;
                table.AddCell(cell);
                font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                table.AddCell(new Phrase("收\n件\n人", font));
                cell = new PdfPCell(pinfor);
                //cell.UseAscender = true;
                //cell.HorizontalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 3;
                table.AddCell(cell);
                cell = new PdfPCell();
                cell.Rowspan = 5;
                table.AddCell(cell);
                table.AddCell(new Phrase("寄件人", font));
                font = new iTextSharp.text.Font(bfChinese, 7, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                cell = new PdfPCell(new Phrase("台北市南港區八德路四段768巷5號4F之一 \n\n 吉甲地好市集股份有限公司", font));
                //cell.UseAscender = true;
                //cell.HorizontalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 3;
                table.AddCell(cell);
                font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                table.AddCell(new Phrase("訂單編號", font));
                cell = new PdfPCell(new Phrase(orderidck));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.Colspan = 3;
                table.AddCell(cell);
                table.AddCell(new Phrase("指定時段", font));
                table.AddCell(new Phrase(sestimated_arrival_period, font));
                cell = new PdfPCell(new Phrase("\n\n收件人簽名\n\n", font));
                cell.Rowspan = 2;
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                // cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                table.AddCell(cell);
                PdfPCell ncell = new PdfPCell();
                //ncell.DisableBorderSide(1);
                //ncell.DisableBorderSide(2);
                ncell.Rowspan = 2;
                table.AddCell(ncell);
                //table.AddCell(new Phrase("收件人簽名", font));
                cell = new PdfPCell(new Phrase("代收貨款", font));
                cell.FixedHeight = h;
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                table.AddCell(cell);
                table.AddCell(new Phrase(receivable, font));
                // table.WriteSelectedRows(0, -1, 280, 820, writer.DirectContent);
                //table.AddCell(ncell);
                //table.AddCell(ncell);
                //table.AddCell(ncell);
                //table.AddCell(ncell);
                #endregion
                totaltable.AddCell(table);
                // cb.EndText();
                totaltable.SpacingAfter = 75f;
                document.Add(totaltable);
                i++;
            }
            document.Close();


            Response.Clear();
            Response.Charset = "gb2312";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            // Response.AddHeader("Content-Disposition", "attach-ment;filename=" + System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + ".pdf ");
            Response.AddHeader("Content-Disposition", "attach-ment;filename=" + filename);
            Response.WriteFile(newPDFName);

        }
Esempio n. 11
0
        /// <summary>
        /// 出貨明細
        /// </summary>
        public void GetDeliverDetailsPDF()
        {
            string deliver_id = Request.Params["deliver_id"];
            _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
            DataTable deliverdetail = _DeliverDetailMgr.GetOrderDelivers(deliver_id, 1);
            BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bfChinese, 8, iTextSharp.text.Font.UNDERLINE, iTextSharp.text.BaseColor.RED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(bfChinese, 12, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
            string filename = "deliver_details_D" + deliver_id.PadLeft(8, '0') + ".pdf";
            Document document = new Document(PageSize.A4, (float)5, (float)5, (float)20, (float)0.5);
            string newPDFName = Server.MapPath(excelPath) + filename;
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPDFName, FileMode.Create));
            document.Open();
            PdfContentByte cb = writer.DirectContent;
            cb.BeginText();
            DataRow[] singleproduct = new DataRow[] { };//單一商品
            DataRow[] fatherproduct = new DataRow[] { };//組合商品中的父商品
            DataRow[] sonproduct = new DataRow[] { };//組合商品中的子商品
            //DataRow[] normal;
            //DataRow[] low;
            //DataRow[] lowstore;
            //List<DataRow> deliverdetails = new List<DataRow>();
            ArrayList combine = new ArrayList();

            singleproduct = deliverdetail.Select(" combined_mode<=1  and ddeliver_id=" + deliver_id, "item_id asc");//單一商品
            fatherproduct = deliverdetail.Select(" combined_mode>1 and item_mode=1 and ddeliver_id=" + deliver_id, "item_id asc");//組合商品中父商品是否存在
            foreach (var item in fatherproduct)
            {
                combine.Add(item);
                sonproduct = deliverdetail.Select(" combined_mode>1  and item_mode<>1 and parent_id=" + item["parent_id"] + " and pack_id=" + item["pack_id"], "item_id asc");//對應組合商品中的子商品
                foreach (var son in sonproduct)
                {
                    son["buy_num"] = (int.Parse(son["buy_num"].ToString()) * int.Parse(son["parent_num"].ToString())).ToString();
                    combine.Add(son);
                }

            }

            List<DataRow[]> deliverdetails = new List<DataRow[]>();
            //normal = deliverdetail.Select("product_freight_set in(1,3)  and ddeliver_id=" + deliver_id, "item_id asc");//常溫
            //low = deliverdetail.Select("product_freight_set in(2,4)  and ddeliver_id=" + deliver_id, "item_id asc");//冷凍
            //lowstore = deliverdetail.Select("product_freight_set in(5,6)  and ddeliver_id=" + deliver_id, "item_id asc");//冷藏
            if (singleproduct.Count() > 0)
            {
                deliverdetails.Add(singleproduct);
            }
            if (combine.Count > 0)
            {
                deliverdetails.Add((DataRow[])combine.ToArray(typeof(DataRow)));
            }
            if (deliverdetail.Rows.Count > 0)
            {

                cb.SetFontAndSize(bfChinese, 20);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "吉甲地台灣好市集出貨明細", 30, 750, 0);
                string freight_set = string.Empty;

                switch (deliverdetail.Rows[0]["freight_set"].ToString().Trim())
                {
                    case "1":
                        freight_set = "常溫";
                        break;
                    case "2":
                        freight_set = "冷凍";
                        break;
                    case "5":
                        freight_set = "冷藏";
                        break;
                }
                cb.SetFontAndSize(bfChinese, 12);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, freight_set, 350, 780, 0);
                if (deliverdetail.Rows[0]["estimated_arrival_period"].ToString() != "0")
                {
                    string estimated_arrival_period = string.Empty;
                    switch (deliverdetail.Rows[0]["estimated_arrival_period"].ToString().Trim())
                    {
                        case "0":
                            estimated_arrival_period = "不限時";
                            break;
                        case "1":
                            estimated_arrival_period = "12:00以前";
                            break;
                        case "2":
                            estimated_arrival_period = "12:00-17:00";
                            break;
                        case "3":
                            estimated_arrival_period = "17:00-20:00";
                            break;
                    }
                    cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, estimated_arrival_period, 350, 765, 0);
                }

                Phrase ph = new Phrase();
                BarCode.Code128 _Code = new BarCode.Code128();
                _Code.ValueFont = new System.Drawing.Font("宋体", 20);
                System.Drawing.Bitmap imgTemp1 = _Code.GetCodeImage("D" + deliverdetail.Rows[0]["deliver_id"].ToString().PadLeft(8, '0'), BarCode.Code128.Encode.Code128A);
                imgTemp1.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                iTextSharp.text.Image IMG1 = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG1.ScaleToFit(200, 30);
                Chunk ck = new Chunk(IMG1, 345, -100); //图片可设置 偏移
                ph.Add(ck);
                document.Add(ph);
                cb.SetFontAndSize(bfChinese, 10);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "付款單號:", 10, 680, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "訂購時間:", 10, 660, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "转单日期:", 200, 660, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "订购人:", 10, 640, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "收货人:", 200, 640, 0);
                string address = string.Empty;


                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["order_id"].ToString(), 80, 680, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["order_createdate"].ToString() != "0" ? CommonFunction.GetNetTime(long.Parse(deliverdetail.Rows[0]["order_createdate"].ToString())).ToString("yyyy-MM-dd HH:mm:ss") : "", 80, 660, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["money_collect_date"].ToString() != "0" ? CommonFunction.GetNetTime(long.Parse(deliverdetail.Rows[0]["money_collect_date"].ToString())).ToString("yyyy-MM-dd HH:mm:ss") : "", 250, 660, 0);
                //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["holiday_deliver"].ToString() == "1" ? "可" : "不可", 250, 620, 0);
                //cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["note_order"].ToString(), 80, 600, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["order_name"].ToString(), 80, 640, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["delivery_name"].ToString(), 250, 640, 0);
                if (deliverdetail.Rows[0]["type"].ToString() != "3")
                {
                    PdfPTable ptable = new PdfPTable(4);
                    ptable.SetTotalWidth(new float[] { 100, 320, 70, 70 });
                    PdfPCell cell = new PdfPCell();
                    cell.BorderWidth = 0.1f;
                    cell.BorderColor = new BaseColor(0, 0, 0);
                    cell = new PdfPCell(new Phrase("商品編號", font));
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("商品名稱", font));
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("數量", font));
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("售价", font));
                    ptable.AddCell(cell);
                    PdfPCell td = new PdfPCell();
                    td.BorderWidth = 0.1f;
                    int j = 0;
                    foreach (var item in deliverdetails)
                    {
                        j++;
                        for (int i = 0; i < item.Count(); i++)
                        {
                            string item_id = string.Empty;
                            if (item[i]["item_mode"].ToString() == "1")
                            {
                                item_id = item[i]["parent_id"].ToString();
                            }
                            else
                            {
                                item_id = item[i]["item_id"].ToString();
                            }
                            cell = new PdfPCell(new Phrase(item_id, font));
                            ptable.AddCell(cell);
                            string datacontent = ((item[i]["item_mode"].ToString() == "2") ? " *" : "") + item[i]["product_name"].ToString() + item[i]["product_spec_name"].ToString();
                            cell = new PdfPCell(new Phrase(item[i]["brand_name"].ToString() + "-" + datacontent, font));
                            ptable.AddCell(cell);
                            cell = new PdfPCell(new Phrase(item[i]["buy_num"].ToString(), font));
                            ptable.AddCell(cell);
                            cell = new PdfPCell(new Phrase(item[i]["item_mode"].ToString() == "1" ? "" : item[i]["single_money"].ToString(), font));
                            ptable.AddCell(cell);
                        }
                        if (deliverdetails.Count > 1 && j != deliverdetails.Count)
                        {
                            td = new PdfPCell();
                            td.Colspan = 4;
                            td.BorderWidthTop = 0.2f;
                            td.DisableBorderSide(2);
                            ptable.AddCell(td);
                        }
                    }
                    ptable.WriteSelectedRows(0, -1, 10, 620, writer.DirectContent);
                }
                else
                {
                    PdfPTable ptable = new PdfPTable(4);
                    // ptable.WidthPercentage = 90;
                    // ptable.TotalWidth = ptable.WidthPercentage;
                    ptable.SetTotalWidth(new float[] { 100, 350, 70, 70 });
                    PdfPCell cell = new PdfPCell();
                    cell.BorderWidth = 0.1f;
                    cell = new PdfPCell(new Phrase("產品細項編號", font));
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("產品名稱", font));
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("規格", font));
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("數量", font));
                    ptable.AddCell(cell);
                    int j = 0;
                    foreach (var item in deliverdetails)
                    {
                        j++;
                        for (int i = 0; i < item.Count(); i++)
                        {
                            cell = new PdfPCell(new Phrase(item[i]["item_id"].ToString(), font));
                            ptable.AddCell(cell);
                            cell = new PdfPCell(new Phrase(item[i]["brand_name"].ToString() + "-" + item[i]["product_name"].ToString(), font));
                            ptable.AddCell(cell);
                            cell = new PdfPCell(new Phrase(item[i]["product_spec_name"].ToString(), font));
                            ptable.AddCell(cell);
                            cell = new PdfPCell(new Phrase(item[i]["buy_num"].ToString(), font));
                            ptable.AddCell(cell);
                        }
                        if (deliverdetails.Count > 1 && j != deliverdetails.Count)
                        {
                            cell = new PdfPCell();
                            cell.Colspan = 4;
                            cell.BorderWidthTop = 0.2f;
                            cell.DisableBorderSide(2);
                            ptable.AddCell(cell);
                        }
                    }
                    ptable.WriteSelectedRows(0, -1, 10, 620, writer.DirectContent);

                }

                cb.EndText();
                document.Close();
                writer.Resume();

                Response.Clear();
                Response.Charset = "gb2312";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                // Response.AddHeader("Content-Disposition", "attach-ment;filename=" + System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + ".pdf ");
                Response.AddHeader("Content-Disposition", "attach-ment;filename=" + filename);
                Response.WriteFile(newPDFName);
            }

        }
Esempio n. 12
0
        public void KTPrintPDF()
        {
            PdfHelper pdf = new PdfHelper();
            List<string> pdfList = new List<string>();
            float[] arrColWidth = new float[] { 60, 60, 100, 60, 50, 30, 60, 60, 60, 60 };
            int index = 0;
            string newFileName = string.Empty;
            string newName = string.Empty;
            string json = string.Empty;
            IialgQuery q = new IialgQuery();
            if (!string.IsNullOrEmpty(Request.Params["KT_NO"].Trim().ToUpper()))//by zhaozhi0623j add 20151006
            {
                q.doc_no = Request.Params["KT_NO"].Trim().ToUpper();
            }
            try
            {
                List<IialgQuery> store = new List<IialgQuery>();
                _iagMgr = new IialgMgr(mySqlConnectionString);
                int totalCount = 0;
                q.IsPage = false;
                store = _iagMgr.GetIialgList(q, out totalCount);
                int rid = 0;
                DataTable _dtBody = new DataTable();

                if (store.Count > 0)
                {
                    _dtBody.Columns.Add("商品細項編號", typeof(string));
                    _dtBody.Columns.Add("主料位", typeof(string));
                    _dtBody.Columns.Add("商品名稱", typeof(string));
                    _dtBody.Columns.Add("規格", typeof(string));
                    _dtBody.Columns.Add("調整原因", typeof(string));
                    _dtBody.Columns.Add("數量", typeof(string));
                    _dtBody.Columns.Add("调整料位", typeof(string));
                    _dtBody.Columns.Add("有效日期", typeof(string));
                    _dtBody.Columns.Add("前置單號", typeof(string));
                    _dtBody.Columns.Add("備註", typeof(string));
                    for (int i = 0; i < store.Count; i++)
                    {
                        store[i].id = rid++;
                        store[i].qty = store[i].qty_o + store[i].adj_qty;
                        DataRow newRow = _dtBody.NewRow();
                        newRow["商品細項編號"] = store[i].item_id;
                        newRow["主料位"] = store[i].loc_id;
                        newRow["商品名稱"] = store[i].product_name;
                        newRow["規格"] = string.IsNullOrEmpty(store[i].prod_sz) ? " " : store[i].prod_sz;
                        newRow["調整原因"] = string.IsNullOrEmpty(store[i].iarc_id) ? " " : store[i].iarc_id;
                        newRow["數量"] = store[i].adj_qty;
                        newRow["调整料位"] = store[i].loc_R;
                        newRow["有效日期"] = store[i].cde_dt.ToString("yyyy-MM-dd").Substring(0, 10) == "0001-01-01" ? " " : store[i].cde_dt.ToString("yyyy-MM-dd").Substring(0, 10);
                        newRow["前置單號"] = string.IsNullOrEmpty(store[i].po_id) ? " " : store[i].po_id;
                        newRow["備註"] = string.IsNullOrEmpty(store[i].remarks) ? " " : store[i].remarks;

                        _dtBody.Rows.Add(newRow);
                    }
                }
                string UsingName = " ";
                String UsingTime = " ";
                if (store.Count > 0)
                {
                    UsingName = store[0].name;
                    UsingTime = store[0].create_dtim.ToString("yyyy/MM/dd");
                }
                BaseFont bf = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bf, 8, iTextSharp.text.Font.UNDERLINE, iTextSharp.text.BaseColor.RED);
                iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                string filename = "庫存調整" + DateTime.Now.ToString("yyyyMMddHHmmss");
                Document document = new Document(PageSize.A4.Rotate());
                string newPDFName = Server.MapPath(excelPath) + filename;
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPDFName, FileMode.Create));
                document.Open();

                #region 庫存調整單頭

                PdfPTable ptable = new PdfPTable(10);


                ptable.WidthPercentage = 100;//表格寬度
                ptable.SetTotalWidth(arrColWidth);
                PdfPCell cell = new PdfPCell();

                cell = new PdfPCell(new Phrase("執行人員:" + UsingName, new iTextSharp.text.Font(bf, 10)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 2;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 10)));
                cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                cell.Colspan = 8;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("執行日期:" + UsingTime, new iTextSharp.text.Font(bf, 10)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 2;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 10)));
                cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                cell.Colspan = 8;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 4)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 10;
                //cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                //cell.DisableBorderSide(4);
                //cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 15)));
                cell.VerticalAlignment = Element.ALIGN_CENTER;//字體水平居左
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                //cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("  庫存調整單", new iTextSharp.text.Font(bf, 15)));
                cell.VerticalAlignment = Element.ALIGN_CENTER;//字體水平居左
                cell.Colspan = 7;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                // cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 10)));
                cell.VerticalAlignment = Element.ALIGN_CENTER;//字體水平居左
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                // cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("單號" + ":" + q.doc_no, new iTextSharp.text.Font(bf, 10)));// ipoStore[a].po_type_desc
                cell.VerticalAlignment = Element.ALIGN_CENTER;//字體水平居左
                cell.Colspan = 7;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                // cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 4)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 10;
                cell.DisableBorderSide(1);
                //cell.DisableBorderSide(2);
                // cell.DisableBorderSide(4);
                //cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("商品細項編號", new iTextSharp.text.Font(bf, 10)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左

                //cell.DisableBorderSide(1);
                // cell.DisableBorderSide(2);
                //cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("主料位", new iTextSharp.text.Font(bf, 10)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左

                //cell.DisableBorderSide(1);
                // cell.DisableBorderSide(2);
                //cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("商品名稱", new iTextSharp.text.Font(bf, 10)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左

                //cell.DisableBorderSide(1);
                // cell.DisableBorderSide(2);
                //cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("規格", new iTextSharp.text.Font(bf, 10)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左

                //cell.DisableBorderSide(1);
                // cell.DisableBorderSide(2);
                //cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("調整原因", new iTextSharp.text.Font(bf, 10)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左

                //cell.DisableBorderSide(1);
                // cell.DisableBorderSide(2);
                //cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("數量", new iTextSharp.text.Font(bf, 10)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左

                //cell.DisableBorderSide(1);
                //cell.DisableBorderSide(2);
                //cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("调整料位", new iTextSharp.text.Font(bf, 10)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左

                //cell.DisableBorderSide(1);
                // cell.DisableBorderSide(2);
                //cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("有效日期", new iTextSharp.text.Font(bf, 10)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左

                //cell.DisableBorderSide(1);
                // cell.DisableBorderSide(2);
                //cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("前置單號", new iTextSharp.text.Font(bf, 10)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左

                //cell.DisableBorderSide(1);
                // cell.DisableBorderSide(2);
                //cell.DisableBorderSide(4);
                //cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("備註", new iTextSharp.text.Font(bf, 10)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左

                //cell.DisableBorderSide(1);
                // cell.DisableBorderSide(2);
                //cell.DisableBorderSide(4);
                //cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                //cell.UseAscender = true;
                //cell.HorizontalAlignment = Element.ALIGN_CENTER;//字體垂直居中
                //cell.VerticalAlignment = Element.ALIGN_MIDDLE;//字體水平居中
                //cell.BorderWidth = 0.1f;
                //cell.BorderColor = new BaseColor(0, 0, 0);

                #endregion

                #region 庫存調整單尾

                PdfPTable ptablefoot = new PdfPTable(10);


                ptablefoot.WidthPercentage = 100;//表格寬度
                ptablefoot.SetTotalWidth(arrColWidth);
                PdfPCell footcell = new PdfPCell();
                footcell.UseAscender = true;
                footcell.HorizontalAlignment = Element.ALIGN_CENTER;//字體垂直居中
                footcell.VerticalAlignment = Element.ALIGN_MIDDLE;//字體水平居中
                footcell.BorderWidth = 0.1f;
                footcell.BorderColor = new BaseColor(0, 0, 0);
                footcell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 15)));
                footcell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                //footcell.HorizontalAlignment = Element.ALIGN_LEFT;//水平居右
                footcell.Colspan = 10;
                footcell.DisableBorderSide(1);
                footcell.DisableBorderSide(2);
                footcell.DisableBorderSide(4);
                footcell.DisableBorderSide(8);
                ptablefoot.AddCell(footcell);


                footcell = new PdfPCell(new Phrase("印表日期:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), new iTextSharp.text.Font(bf, 10)));
                footcell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居右
                // footcell.HorizontalAlignment = Element.ALIGN_LEFT;//水平居右
                footcell.Colspan = 2;
                footcell.DisableBorderSide(1);
                footcell.DisableBorderSide(2);
                footcell.DisableBorderSide(4);
                footcell.DisableBorderSide(8);
                ptablefoot.AddCell(footcell);
                footcell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 10)));
                footcell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居右
                // footcell.HorizontalAlignment = Element.ALIGN_LEFT;//水平居右
                footcell.Colspan = 1;
                footcell.DisableBorderSide(1);
                footcell.DisableBorderSide(2);
                footcell.DisableBorderSide(4);
                footcell.DisableBorderSide(8);
                ptablefoot.AddCell(footcell);

                footcell = new PdfPCell(new Phrase("印表人:" + (System.Web.HttpContext.Current.Session["caller"] as Caller).user_username, new iTextSharp.text.Font(bf, 10)));
                footcell.VerticalAlignment = Element.ALIGN_RIGHT;//水平居右
                footcell.Colspan = 2;
                footcell.DisableBorderSide(1);
                footcell.DisableBorderSide(2);
                footcell.DisableBorderSide(4);
                footcell.DisableBorderSide(8);
                ptablefoot.AddCell(footcell);
                footcell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 10)));
                footcell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居右
                // footcell.HorizontalAlignment = Element.ALIGN_LEFT;//水平居右
                footcell.Colspan = 3;
                footcell.DisableBorderSide(1);
                footcell.DisableBorderSide(2);
                footcell.DisableBorderSide(4);
                footcell.DisableBorderSide(8);
                ptablefoot.AddCell(footcell);

                footcell = new PdfPCell(new Phrase("主管簽核:__________________", new iTextSharp.text.Font(bf, 10)));
                footcell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                footcell.Colspan = 2;
                footcell.DisableBorderSide(1);
                footcell.DisableBorderSide(2);
                footcell.DisableBorderSide(4);
                footcell.DisableBorderSide(8);
                ptablefoot.AddCell(footcell);


                #endregion
                if (store.Count == 0)
                {
                    document = new Document(PageSize.A4.Rotate());
                    if (!document.IsOpen())
                    {
                        document.Open();
                    }
                    cell = new PdfPCell(new Phrase(" ", font));
                    cell.Colspan = 4;
                    cell.VerticalAlignment = Element.ALIGN_CENTER;//字體水平居左
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase("此庫調單庫調數據不存在!", font));
                    cell.Colspan = 7;
                    cell.DisableBorderSide(4);
                    cell.VerticalAlignment = Element.ALIGN_CENTER;//字體水平居左
                    ptable.AddCell(cell);


                    // document.Add(ptable);
                    //document.Add(ptablefoot); 
                    newFileName = newPDFName + "_part" + index++ + "." + "pdf";
                    pdf.ExportDataTableToPDF(_dtBody, false, newFileName, arrColWidth, ptable, ptablefoot, "", "", 10, uint.Parse(store.Count.ToString()));/*第一7是列,第二個是行*/
                    pdfList.Add(newFileName);

                }
                else
                {
                    newFileName = newPDFName + "_part" + index++ + "." + "pdf";

                    pdf.ExportDataTableToPDF(_dtBody, false, newFileName, arrColWidth, ptable, ptablefoot, "", "", 10, uint.Parse(store.Count.ToString()));/*第一7是列,第二個是行*/
                    pdfList.Add(newFileName);

                }


                //newFileName = newPDFName + "_part" + index++ + "." + "pdf";
                //pdf.ExportDataTableToPDF(newFileName, ptable, "", "");
                //pdfList.Add(newFileName);

                //document.Add(ptable);
                //document.NewPage();
                newFileName = newPDFName + "." + "pdf";
                pdf.MergePDF(pdfList, newFileName);

                Response.Clear();
                Response.Charset = "gb2312";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                Response.AddHeader("Content-Disposition", "attach-ment;filename=" + filename + ".pdf");
                Response.WriteFile(newFileName);

            }
            catch (Exception)
            {

                throw;
            }

        }
Esempio n. 13
0
        public override void ExecuteResult(ControllerContext context)
        {
            var ctl = new MailingController { UseTitles = titles ?? false, UseMailFlags = useMailFlags ?? false };
            var Response = context.HttpContext.Response;

            IEnumerable<MailingController.MailingInfo> q = null;
            switch (format)
            {
                case "Individual":
                    q = ctl.FetchIndividualList(sort, id);
                    break;
                case "GroupAddress":
                    q = ctl.GroupByAddress(id);
                    break;
                case "Family":
                case "FamilyMembers":
                    q = ctl.FetchFamilyList(sort, id);
                    break;
                case "ParentsOf":
                    q = ctl.FetchParentsOfList(sort, id);
                    break;
                case "CouplesEither":
                    q = ctl.FetchCouplesEitherList(sort, id);
                    break;
                case "CouplesBoth":
                    q = ctl.FetchCouplesBothList(sort, id);
                    break;
                default:
                    Response.Write("unknown format");
                    return;
            }
            if (!q.Any())
            {
                Response.Write("no data found");
                return;
            }
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "filename=foo.pdf");

            var document = new Document(PageSize.LETTER);
            document.SetMargins(50f, 36f, 32f, 36f);
            var w = PdfWriter.GetInstance(document, Response.OutputStream);
            document.Open();
            dc = w.DirectContent;

            var cols = new float[] { W, W, W - 25f };
            var t = new PdfPTable(cols);
            t.SetTotalWidth(cols);
            t.HorizontalAlignment = Element.ALIGN_CENTER;
            t.LockedWidth = true;
            t.DefaultCell.Border = PdfPCell.NO_BORDER;
            t.DefaultCell.FixedHeight = H;
            t.DefaultCell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;
            t.DefaultCell.PaddingLeft = 8f;
            t.DefaultCell.PaddingRight = 8f;
            t.DefaultCell.SetLeading(2.0f, 1f);

            if (skip > 0)
            {
                var blankCell = new PdfPCell(t.DefaultCell);

                for (int iX = 0; iX < skip; iX++)
                {
                    t.AddCell(blankCell);
                }
            }

            foreach (var m in q)
            {
                var c = new PdfPCell(t.DefaultCell);
                var ph = new Paragraph();
                if (format == "GroupAddress")
                    ph.AddLine(m.LabelName + " " + m.LastName, font);
                else
                    ph.AddLine(m.LabelName, font);
                ph.AddLine(m.Address, font);
                ph.AddLine(m.Address2, font);
                ph.AddLine(m.CityStateZip, font);
                c.AddElement(ph);
                if (usephone)
                {
                    var phone = Util.PickFirst(m.CellPhone.FmtFone("C "), m.HomePhone.FmtFone("H "));
                    var p = new Paragraph();
                    c.PaddingRight = 7f;
                    p.Alignment = Element.ALIGN_RIGHT;
                    p.Add(new Chunk(phone, smfont));
                    p.ExtraParagraphSpace = 0f;
                    c.AddElement(p);
                }
                t.AddCell(c);
            }
            t.CompleteRow();
            document.Add(t);

            document.Close();
        }
Esempio n. 14
0
        public void GenerateXMLReport()
        {
            try
            {
                this.doc.Open();
                RenderLogo();
                //RenderHeaderAddress();
                RenderReportJobInfo();

                #region Add Details Table
                PdfPTable myTable = new PdfPTable(ColList.Count );
                myTable.SetTotalWidth(this.Headerwidths);
                myTable.LockedWidth = true;
                myTable.HorizontalAlignment = Element.ALIGN_LEFT;
                myTable.DefaultCell.BorderWidth = 1;
                myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                myTable.DefaultCell.BackgroundColor = Color.LIGHT_GRAY;

                foreach (var x in this.ColList)
                {
                    myTable.AddCell(new Phrase(x, fntHeading));

                }
                //myTable.EndHeaders();
                Font myDetailFont = fntDetails;
                foreach (var x in this.ReportRows)
                {
                    for (int i = 0; i < ColList.Count; i++)
                    {
                        myTable.DefaultCell.BackgroundColor = Color.WHITE;
                        if (x.row[i].type == CellType.Number)
                            myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                        else
                            myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
                        myTable.AddCell(new Phrase(x.row[i].value, myDetailFont));
                    }
                }

                myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                myTable.DefaultCell.BackgroundColor = Color.LIGHT_GRAY;
                int colindex = 0;
                foreach (var x in this.FooterList)
                {
                    //decimal.Parse(FooterList[colindex]) >
                    myTable.AddCell(new Phrase(x, footerFont));
                    colindex++;
                }
                myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                myTable.DefaultCell.BackgroundColor = Color.BLUE;

                foreach (var x in this.SacoList)
                {
                    myTable.AddCell(new Phrase(x, SacoFont));
                }

                doc.Add(myTable);

                #endregion

            }
            catch (Exception ex)
            {
                //MessageBox.Show("Error: " + ex.Message);
            }
            doc.Close();

            writer.Close();
        }
Esempio n. 15
0
        private PdfPTable GetSalesAmountData(int Invoiceid = 0)
        {
            double dSalesAmount = 0;
            double dTax = 0;
            double dTotalTax = 0;
            double dTotalAmount = 0;
            double dBalanceDue = 0;
            decimal dPayment = 0;
            string szNotes = "The note";
            string szShipping = "";
            string szPayment = "";

            string szMsg = "";
            Paragraph title = null;

            //Get the invoice data
            Invoice invoice = null;
            invoice = db.Invoices.Find(Invoiceid);
            if (invoice == null)
            {
                return null;
            }
            szNotes = invoice.Note;
            szShipping = Convert.ToDecimal(invoice.ShippingHandling).ToString("C");

            if (invoice.PaymentAmount == null)
            {
                dPayment = 0;
            }
            else
            {
                dPayment = Convert.ToDecimal(invoice.PaymentAmount);
            }
            szPayment = dPayment.ToString("C");

            //Get the totals
            TimelyDepotMVC.Controllers.InvoiceController invoiceCtrl = new Controllers.InvoiceController();
            invoiceCtrl.GetInvoiceTotals(invoice.InvoiceId, ref dSalesAmount, ref dTotalTax, ref dTax, ref dTotalAmount, ref dBalanceDue);
            string szSalesAmount = dSalesAmount.ToString("C");
            string szTotalTax = dTotalTax.ToString("C");
            string szTax = dTax.ToString("F2");
            string szTotalAmount = dTotalAmount.ToString("C");
            string szBalanceDue = dBalanceDue.ToString("C");

            Font times01 = FontFactory.GetFont("helvetica-bold", 10, BaseColor.BLACK);
            Font times02 = FontFactory.GetFont("helvetica-bold", 10, Font.ITALIC, BaseColor.BLACK);
            Font times03 = FontFactory.GetFont("helvetica-bold", 10, Font.UNDERLINE, BaseColor.BLACK);
            Font times04 = FontFactory.GetFont("helvetica", 10, BaseColor.BLACK);
            Font times05 = FontFactory.GetFont("helvetica", 10, Font.UNDERLINE, BaseColor.BLACK);
            Font times06 = FontFactory.GetFont("helvetica", 8, BaseColor.BLACK);
            Font times07 = FontFactory.GetFont("helvetica", 10, Font.ITALIC, BaseColor.BLACK);

            PdfPTable infotable = new PdfPTable(numColumns: 4);
            infotable.WidthPercentage = 100;
            infotable.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            infotable.SpacingBefore = 25;

            PdfPCell nestingcell = null;
            PdfPCell hlpCel = null;

            //First Row Sales Amount
            PdfPTable nested = new PdfPTable(numColumns: 3);
            nested.SetTotalWidth(new float[] { 350.6f, 123.6f, 64.2f });
            nested.LockedWidth = true;

            szMsg = string.Format("Notes:");
            title = new Paragraph(szMsg, times06);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 4;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested.AddCell(hlpCel);

            szMsg = string.Format("Sales Amount:");
            title = new Paragraph(szMsg, times02);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 4;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested.AddCell(hlpCel);

            szMsg = string.Format("{0}", szSalesAmount);
            title = new Paragraph(szMsg, times02);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 4;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_RIGHT;
            nested.AddCell(hlpCel);

            nestingcell = new PdfPCell(nested);
            nestingcell.Colspan = 4;
            nestingcell.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            nestingcell.BorderWidthLeft = 0;
            nestingcell.BorderWidthRight = 0;
            nestingcell.BorderWidthTop = 0;
            nestingcell.BorderWidthBottom = 0;
            nestingcell.Padding = 0;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            nestingcell.HorizontalAlignment = Element.ALIGN_CENTER;
            infotable.AddCell(nestingcell);

            //Second Row Sales Amount
            PdfPTable nested01 = new PdfPTable(numColumns: 2);
            nested01.SetTotalWidth(new float[] { 350.6f, 187.8f });
            nested01.LockedWidth = true;

            szMsg = string.Format("{0}", szNotes);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested01.AddCell(hlpCel);

            PdfPTable nested02 = new PdfPTable(numColumns: 2);
            nested02.SetTotalWidth(new float[] { 123.6f, 64.2f });
            nested02.LockedWidth = true;

            szMsg = string.Format("Tax {0} %:", szTax);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested02.AddCell(hlpCel);

            szMsg = string.Format("{0}", szTotalTax);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_RIGHT;
            nested02.AddCell(hlpCel);

            szMsg = string.Format("Shipping & Handling:", " ");
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested02.AddCell(hlpCel);

            szMsg = string.Format("{0}", szShipping);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_RIGHT;
            nested02.AddCell(hlpCel);

            szMsg = string.Format("Total Amount:", " ");
            title = new Paragraph(szMsg, times01);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested02.AddCell(hlpCel);

            szMsg = string.Format("{0}", szTotalAmount);
            title = new Paragraph(szMsg, times01);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_RIGHT;
            nested02.AddCell(hlpCel);

            szMsg = string.Format("Payment:", " ");
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested02.AddCell(hlpCel);

            szMsg = string.Format("{0}", szPayment);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_RIGHT;
            nested02.AddCell(hlpCel);

            //
            hlpCel = new PdfPCell(nested02);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_CENTER;
            nested01.AddCell(hlpCel);

            nestingcell = new PdfPCell(nested01);
            nestingcell.Colspan = 4;
            nestingcell.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            nestingcell.BorderWidthLeft = 0;
            nestingcell.BorderWidthRight = 0;
            nestingcell.BorderWidthTop = 0;
            nestingcell.BorderWidthBottom = 0;
            nestingcell.Padding = 0;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            nestingcell.HorizontalAlignment = Element.ALIGN_CENTER;
            infotable.AddCell(nestingcell);

            //Last Row Sales Amount
            PdfPTable nested03 = new PdfPTable(numColumns: 3);
            nested03.SetTotalWidth(new float[] { 350.6f, 123.6f, 64.2f });
            nested03.LockedWidth = true;

            times07.SetStyle(Font.UNDERLINE);
            szMsg = string.Format("C/C#: {0}", "******8286");
            title = new Paragraph(szMsg, times07);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 4;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_CENTER;
            nested03.AddCell(hlpCel);

            times02.SetStyle(Font.UNDERLINE);
            szMsg = string.Format("Balance Due:");
            title = new Paragraph(szMsg, times02);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 4;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested03.AddCell(hlpCel);

            szMsg = string.Format("{0}", szBalanceDue);
            title = new Paragraph(szMsg, times02);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 4;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_RIGHT;
            nested03.AddCell(hlpCel);

            nestingcell = new PdfPCell(nested03);
            nestingcell.Colspan = 4;
            nestingcell.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            nestingcell.BorderWidthLeft = 0;
            nestingcell.BorderWidthRight = 0;
            nestingcell.BorderWidthTop = 0;
            nestingcell.BorderWidthBottom = 0;
            nestingcell.Padding = 0;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            nestingcell.HorizontalAlignment = Element.ALIGN_CENTER;
            infotable.AddCell(nestingcell);

            return infotable;
        }
Esempio n. 16
0
        /// <summary>
        /// 匯出盤點工作PDF
        /// </summary>
        public void CountBookPDF()
        {
            PdfHelper pdf = new PdfHelper();
            List<string> pdfList = new List<string>();
            float[] arrColWidth = new float[] { 25, 60, 40, 40, 55,40, 140, 50, 40, 50};
            string newFileName = string.Empty;
            string newName = string.Empty;
            string json = string.Empty;
            BaseFont bf = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bf, 8, iTextSharp.text.Font.UNDERLINE, iTextSharp.text.BaseColor.RED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
            string filename = "盤點工作" + DateTime.Now.ToString("yyyyMMddHHmmss");
            Document document = new Document(PageSize.A4.Rotate());
            string newPDFName = Server.MapPath(excelPath) + filename;
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPDFName, FileMode.Create));
            document.Open();
            int index = 0;
            CbjobMasterQuery query = new CbjobMasterQuery();
            List<CbjobMasterQuery> cbjobList = new List<CbjobMasterQuery>();
            query.IsPage = false;

            if (!string.IsNullOrEmpty(Request.Params["rowIDs"]))
            {
                query.row_id_IN = Request.Params["rowIDs"].TrimEnd(',');

            }
            _CbjobMasterMgr = new CbjobMasterMgr(mySqlConnectionString);
            int totalCount = 0;
            cbjobList = _CbjobMasterMgr.GetjobMaster(query, out  totalCount);
            DataTable _dtBody = new DataTable();
            _dtBody.Columns.Add("編號", typeof(string));
            _dtBody.Columns.Add("條碼", typeof(string));
            _dtBody.Columns.Add("料位", typeof(string));
            _dtBody.Columns.Add("現有庫存", typeof(string));
            _dtBody.Columns.Add("盤點數量", typeof(string));
            _dtBody.Columns.Add("效期控制", typeof(string));
            _dtBody.Columns.Add("品名", typeof(string));
            _dtBody.Columns.Add("規格", typeof(string));
            _dtBody.Columns.Add("細項編號", typeof(string));
            _dtBody.Columns.Add("備註", typeof(string));
            PdfPTable ptablefoot = new PdfPTable(10);

                if (cbjobList.Count > 0)
                {
                    _cbjobMgr = new CbjobDetailMgr(mySqlConnectionString);


                    for (int i = 0; i < cbjobList.Count; i++)
                    {
                        CbjobDetail cbdetail = new CbjobDetail();
                        cbdetail.cb_jobid = cbjobList[i].cbjob_id;
                        DataTable _dtdetail = _cbjobMgr.GetDetailTable(cbdetail);
                        _dtBody.Rows.Clear();


                        #region 標頭
                        #region 標頭
                        PdfPTable ptable = new PdfPTable(10);
                        ptable.WidthPercentage = 100;//表格寬度
                        ptable.SetTotalWidth(arrColWidth);
                        PdfPCell cell = new PdfPCell();
                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 10;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        // cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("      盤點薄" + "-" + cbdetail.cb_jobid, new iTextSharp.text.Font(bf, 18)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;
                        cell.Colspan = 3;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 3;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        // cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 10;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        // cell.DisableBorderSide(4);
                        //cell.DisableBorderSide(8);
                        ptable.AddCell(cell);


                        #endregion
                        #region 表頭
                        cell = new PdfPCell(new Phrase("編號", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("條碼", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);



                        cell = new PdfPCell(new Phrase("料位", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("現有庫存", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("盤點數量", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("效期控制", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("品名", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("規格", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("細項編號", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("備註", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        ptable.AddCell(cell);
                        #endregion
                        #endregion

                        if (_dtdetail.Rows.Count > 0)
                        {
                            _IiupcMgr = new IupcMgr(mySqlConnectionString);
                            int a = 0;
                            foreach (DataRow rows in _dtdetail.Rows)
                            {
                                a++;
                                string upc_id = string.Empty;
                                #region 取條碼

                                List<IupcQuery> list = new List<IupcQuery>();
                                IupcQuery iupc_query = new IupcQuery();
                                if (!string.IsNullOrEmpty(rows["item_id"].ToString()))
                                {
                                    uint item_id = uint.Parse(rows["item_id"].ToString());
                                    iupc_query.item_id = item_id;
                                    iupc_query.upc_type_flg = "1";
                                    list = _IiupcMgr.GetIupcByType(iupc_query);
                                    if (list.Count > 0)
                                    {
                                        upc_id = list[0].upc_id;
                                    }
                                    else
                                    {
                                        iupc_query.upc_type_flg = "3";
                                        list = _IiupcMgr.GetIupcByType(iupc_query);
                                        if (list.Count > 0)
                                        {
                                            upc_id = list[0].upc_id;
                                        }
                                        else
                                        {
                                            iupc_query.upc_type_flg = "2";
                                            list = _IiupcMgr.GetIupcByType(iupc_query);
                                            if (list.Count > 0)
                                            {
                                                upc_id = list[0].upc_id;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    upc_id = " ";
                                }
                                #endregion
                                DataRow row = _dtBody.NewRow();
                                row["編號"] = a;
                                row["條碼"] = upc_id;

                                row["料位"] = rows["loc_id"];
                                row["現有庫存"] = rows["prod_qty"];
                                row["盤點數量"] = "";
                                row["效期控制"] = string.IsNullOrEmpty(rows["pwy_dte_ctl"].ToString()) ? "否" : (rows["pwy_dte_ctl"].ToString() == "Y" ? "是" : "否");
                                row["品名"] = rows["product_name"];
                                row["規格"] = rows["spec_title_1"];
                                row["細項編號"] = rows["item_id"];
                                row["備註"] = " ";
                                _dtBody.Rows.Add(row);
                            }
                        }
                        newFileName = newPDFName + "_part" + index++ + "." + "pdf";
                        pdf.ExportDataTableToPDF(_dtBody, false, newFileName, arrColWidth, ptable, ptablefoot, "", "", 10, uint.Parse(_dtBody.Rows.Count.ToString()));/*第一7是列,第二個是行*/
                        pdfList.Add(newFileName);
                    }



                }
            if (_dtBody.Rows.Count == 0)
            {
                #region 標頭
                #region 標頭
                PdfPTable ptable = new PdfPTable(10);
                ptable.WidthPercentage = 100;//表格寬度
                ptable.SetTotalWidth(arrColWidth);
                PdfPCell cell = new PdfPCell();
                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 10;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 4;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                // cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("      盤點薄", new iTextSharp.text.Font(bf, 18)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                // cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 10;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                // cell.DisableBorderSide(4);
                //cell.DisableBorderSide(8);
                ptable.AddCell(cell);


                #endregion
                #region 表頭
                cell = new PdfPCell(new Phrase("編號", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("條碼", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);



                cell = new PdfPCell(new Phrase("料位", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("現有庫存", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("盤點數量", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("效期控制", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("品名", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("規格", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("細項編號", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("備註", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                ptable.AddCell(cell);
                #endregion
                #endregion
                document = new Document(PageSize.A4.Rotate());
                if (!document.IsOpen())
                {
                    document.Open();
                }
                cell = new PdfPCell(new Phrase(" ", font));
                cell.Colspan = 4;
                cell.VerticalAlignment = Element.ALIGN_CENTER;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("此工作代號無數據!", font));
                cell.Colspan = 3;
                cell.DisableBorderSide(4);
                cell.VerticalAlignment = Element.ALIGN_CENTER;//字體水平居左
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase(" ", font));
                cell.Colspan = 3;
                cell.VerticalAlignment = Element.ALIGN_CENTER;//字體水平居左
                //cell.DisableBorderSide(8);
                ptable.AddCell(cell);


                // document.Add(ptable);
                //document.Add(ptablefoot); 
                newFileName = newPDFName + "_part" + index++ + "." + "pdf";
                pdf.ExportDataTableToPDF(_dtBody, false, newFileName, arrColWidth, ptable, ptablefoot, "", "", 10, uint.Parse(_dtBody.Rows.Count.ToString()));/*第一7是列,第二個是行*/
                pdfList.Add(newFileName);

            }
            newFileName = newPDFName + "." + "pdf";
            pdf.MergePDF(pdfList, newFileName);

            Response.Clear();
            Response.Charset = "gb2312";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.AddHeader("Content-Disposition", "attach-ment;filename=" + filename + ".pdf");
            Response.WriteFile(newFileName);
        }
Esempio n. 17
0
        /// <summary>
        /// Print orders to PDF
        /// </summary>
        /// <param name="stream">Stream</param>
        /// <param name="orders">Orders</param>
        /// <param name="languageId">Language identifier; 0 to use a language used when placing an order</param>
        public virtual void PrintOrdersToPdf(Stream stream, IList<Order> orders, int languageId = 0)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");

            if (orders == null)
                throw new ArgumentNullException("orders");

            var pageSize = PageSize.A4;

            if (_pdfSettings.LetterPageSizeEnabled)
            {
                pageSize = PageSize.LETTER;
            }

            var doc = new Document(pageSize);
            var pdfWriter = PdfWriter.GetInstance(doc, stream);
            doc.Open();

            //fonts
            var titleFont = GetFont();
            titleFont.SetStyle(Font.BOLD);
            titleFont.Color = BaseColor.BLACK;
            var font = GetFont();
            var attributesFont = GetFont();
            attributesFont.SetStyle(Font.ITALIC);

            int ordCount = orders.Count;
            int ordNum = 0;

            foreach (var order in orders)
            {
                var lang = _languageService.GetLanguageById(languageId == 0 ? order.CustomerLanguageId : languageId);
                if (lang == null || !lang.Published)
                    lang = _workContext.WorkingLanguage;

                #region Header

                //logo
                var logoPicture = _pictureService.GetPictureById(_pdfSettings.LogoPictureId);
                var logoExists = logoPicture != null;

                //header
                var headerTable = new PdfPTable(logoExists ? 2 : 1);
                headerTable.WidthPercentage = 100f;
                if (logoExists)
                    headerTable.SetWidths(new[] { 50, 50 });

                //logo
                if (logoExists)
                {
                    var logoFilePath = _pictureService.GetThumbLocalPath(logoPicture, 0, false);
                    var cellLogo = new PdfPCell(Image.GetInstance(logoFilePath));
                    cellLogo.Border = Rectangle.NO_BORDER;
                    headerTable.AddCell(cellLogo);
                }
                //store info
                var cell = new PdfPCell();
                cell.Border = Rectangle.NO_BORDER;
                cell.AddElement(new Paragraph(String.Format(_localizationService.GetResource("PDFInvoice.Order#", lang.Id), order.Id), titleFont));
                var store = _storeService.GetStoreById(order.StoreId) ?? _storeContext.CurrentStore;
                var anchor = new Anchor(store.Url.Trim(new char[] { '/' }), font);
                anchor.Reference = store.Url;
                cell.AddElement(new Paragraph(anchor));
                cell.AddElement(new Paragraph(String.Format(_localizationService.GetResource("PDFInvoice.OrderDate", lang.Id), _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc).ToString("D", new CultureInfo(lang.LanguageCulture))), font));
                headerTable.AddCell(cell);
                doc.Add(headerTable);

                #endregion

                #region Addresses

                var addressTable = new PdfPTable(2);
                addressTable.WidthPercentage = 100f;
                addressTable.SetWidths(new[] { 50, 50 });

                //billing info
                cell = new PdfPCell();
                cell.Border = Rectangle.NO_BORDER;
                cell.AddElement(new Paragraph(_localizationService.GetResource("PDFInvoice.BillingInformation", lang.Id), titleFont));

                if (_addressSettings.CompanyEnabled && !String.IsNullOrEmpty(order.BillingAddress.Company))
                    cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Company", lang.Id), order.BillingAddress.Company), font));

                cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Name", lang.Id), order.BillingAddress.FirstName + " " + order.BillingAddress.LastName), font));
                if (_addressSettings.PhoneEnabled)
                    cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Phone", lang.Id), order.BillingAddress.PhoneNumber), font));
                if (_addressSettings.FaxEnabled && !String.IsNullOrEmpty(order.BillingAddress.FaxNumber))
                    cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Fax", lang.Id), order.BillingAddress.FaxNumber), font));
                if (_addressSettings.StreetAddressEnabled)
                    cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Address", lang.Id), order.BillingAddress.Address1), font));
                if (_addressSettings.StreetAddress2Enabled && !String.IsNullOrEmpty(order.BillingAddress.Address2))
                    cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Address2", lang.Id), order.BillingAddress.Address2), font));
                if (_addressSettings.CityEnabled || _addressSettings.StateProvinceEnabled || _addressSettings.ZipPostalCodeEnabled)
                    cell.AddElement(new Paragraph("   " + String.Format("{0}, {1} {2}", order.BillingAddress.City, order.BillingAddress.StateProvince != null ? order.BillingAddress.StateProvince.GetLocalized(x => x.Name, lang.Id) : "", order.BillingAddress.ZipPostalCode), font));
                if (_addressSettings.CountryEnabled && order.BillingAddress.Country != null)
                    cell.AddElement(new Paragraph("   " + String.Format("{0}", order.BillingAddress.Country != null ? order.BillingAddress.Country.GetLocalized(x => x.Name, lang.Id) : ""), font));

                //VAT number
                if (!String.IsNullOrEmpty(order.VatNumber))
                    cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.VATNumber", lang.Id), order.VatNumber), font));

                //payment method
                var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(order.PaymentMethodSystemName);
                string paymentMethodStr = paymentMethod != null ? paymentMethod.GetLocalizedFriendlyName(_localizationService, lang.Id) : order.PaymentMethodSystemName;
                if (!String.IsNullOrEmpty(paymentMethodStr))
                {
                    cell.AddElement(new Paragraph(" "));
                    cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.PaymentMethod", lang.Id), paymentMethodStr), font));
                    cell.AddElement(new Paragraph());
                }

                //purchase order number (we have to find a better to inject this information because it's related to a certain plugin)
                if (paymentMethod != null && paymentMethod.PluginDescriptor.SystemName.Equals("Payments.PurchaseOrder", StringComparison.InvariantCultureIgnoreCase))
                {
                    cell.AddElement(new Paragraph(" "));
                    cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.PurchaseOrderNumber", lang.Id), order.PurchaseOrderNumber), font));
                    cell.AddElement(new Paragraph());
                }

                addressTable.AddCell(cell);

                //shipping info
                if (order.ShippingStatus != ShippingStatus.ShippingNotRequired)
                {
                    if (order.ShippingAddress == null)
                        throw new NopException(string.Format("Shipping is required, but address is not available. Order ID = {0}", order.Id));
                    cell = new PdfPCell();
                    cell.Border = Rectangle.NO_BORDER;

                    cell.AddElement(new Paragraph(_localizationService.GetResource("PDFInvoice.ShippingInformation", lang.Id), titleFont));
                    if (!String.IsNullOrEmpty(order.ShippingAddress.Company))
                        cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Company", lang.Id), order.ShippingAddress.Company), font));
                    cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Name", lang.Id), order.ShippingAddress.FirstName + " " + order.ShippingAddress.LastName), font));
                    if (_addressSettings.PhoneEnabled)
                        cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Phone", lang.Id), order.ShippingAddress.PhoneNumber), font));
                    if (_addressSettings.FaxEnabled && !String.IsNullOrEmpty(order.ShippingAddress.FaxNumber))
                        cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Fax", lang.Id), order.ShippingAddress.FaxNumber), font));
                    if (_addressSettings.StreetAddressEnabled)
                        cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Address", lang.Id), order.ShippingAddress.Address1), font));
                    if (_addressSettings.StreetAddress2Enabled && !String.IsNullOrEmpty(order.ShippingAddress.Address2))
                        cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.Address2", lang.Id), order.ShippingAddress.Address2), font));
                    if (_addressSettings.CityEnabled || _addressSettings.StateProvinceEnabled || _addressSettings.ZipPostalCodeEnabled)
                        cell.AddElement(new Paragraph("   " + String.Format("{0}, {1} {2}", order.ShippingAddress.City, order.ShippingAddress.StateProvince != null ? order.ShippingAddress.StateProvince.GetLocalized(x => x.Name, lang.Id) : "", order.ShippingAddress.ZipPostalCode), font));
                    if (_addressSettings.CountryEnabled && order.ShippingAddress.Country != null)
                        cell.AddElement(new Paragraph("   " + String.Format("{0}", order.ShippingAddress.Country != null ? order.ShippingAddress.Country.GetLocalized(x => x.Name, lang.Id) : ""), font));
                    cell.AddElement(new Paragraph(" "));
                    cell.AddElement(new Paragraph("   " + String.Format(_localizationService.GetResource("PDFInvoice.ShippingMethod", lang.Id), order.ShippingMethod), font));
                    cell.AddElement(new Paragraph());

                    addressTable.AddCell(cell);
                }
                else
                {
                    cell = new PdfPCell(new Phrase(" "));
                    cell.Border = Rectangle.NO_BORDER;
                    addressTable.AddCell(cell);
                }

                doc.Add(addressTable);
                doc.Add(new Paragraph(" "));

                #endregion

                #region Products
                //products
                doc.Add(new Paragraph(_localizationService.GetResource("PDFInvoice.Product(s)", lang.Id), titleFont));
                doc.Add(new Paragraph(" "));

                var orderItems = _orderService.GetAllOrderItems(order.Id, null, null, null, null, null, null);

                var productsTable = new PdfPTable(_catalogSettings.ShowProductSku ? 5 : 4);
                productsTable.WidthPercentage = 100f;
                productsTable.SetWidths(_catalogSettings.ShowProductSku ? new[] { 40, 15, 15, 15, 15 } : new[] { 40, 20, 20, 20 });

                //product name
                cell = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.ProductName", lang.Id), font));
                cell.BackgroundColor = BaseColor.LIGHT_GRAY;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                productsTable.AddCell(cell);

                //SKU
                if (_catalogSettings.ShowProductSku)
                {
                    cell = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.SKU", lang.Id), font));
                    cell.BackgroundColor = BaseColor.LIGHT_GRAY;
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    productsTable.AddCell(cell);
                }

                //price
                cell = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.ProductPrice", lang.Id), font));
                cell.BackgroundColor = BaseColor.LIGHT_GRAY;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                productsTable.AddCell(cell);

                //qty
                cell = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.ProductQuantity", lang.Id), font));
                cell.BackgroundColor = BaseColor.LIGHT_GRAY;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                productsTable.AddCell(cell);

                //total
                cell = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.ProductTotal", lang.Id), font));
                cell.BackgroundColor = BaseColor.LIGHT_GRAY;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                productsTable.AddCell(cell);

                for (int i = 0; i < orderItems.Count; i++)
                {
                    var orderItem = orderItems[i];
                    var p = orderItem.Product;

                    //product name
                    string name = p.GetLocalized(x => x.Name, lang.Id);
                    cell = new PdfPCell();
                    cell.AddElement(new Paragraph(name, font));
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    var attributesParagraph = new Paragraph(HtmlHelper.ConvertHtmlToPlainText(orderItem.AttributeDescription, true, true), attributesFont);
                    cell.AddElement(attributesParagraph);
                    productsTable.AddCell(cell);

                    //SKU
                    if (_catalogSettings.ShowProductSku)
                    {
                        var sku = p.FormatSku(orderItem.AttributesXml, _productAttributeParser);
                        cell = new PdfPCell(new Phrase(sku ?? String.Empty, font));
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        productsTable.AddCell(cell);
                    }

                    //price
                    string unitPrice = string.Empty;
                    switch (order.CustomerTaxDisplayType)
                    {
                        case TaxDisplayType.ExcludingTax:
                            {
                                var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                                unitPrice = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, false);
                            }
                            break;
                        case TaxDisplayType.IncludingTax:
                            {
                                var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                                unitPrice = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, true);
                            }
                            break;
                    }
                    cell = new PdfPCell(new Phrase(unitPrice, font));
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    productsTable.AddCell(cell);

                    //qty
                    cell = new PdfPCell(new Phrase(orderItem.Quantity.ToString(), font));
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    productsTable.AddCell(cell);

                    //total
                    string subTotal = string.Empty;
                    switch (order.CustomerTaxDisplayType)
                    {
                        case TaxDisplayType.ExcludingTax:
                            {
                                var priceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.PriceExclTax, order.CurrencyRate);
                                subTotal = _priceFormatter.FormatPrice(priceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, false);
                            }
                            break;
                        case TaxDisplayType.IncludingTax:
                            {
                                var priceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.PriceInclTax, order.CurrencyRate);
                                subTotal = _priceFormatter.FormatPrice(priceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, true);
                            }
                            break;
                    }
                    cell = new PdfPCell(new Phrase(subTotal, font));
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    productsTable.AddCell(cell);
                }
                doc.Add(productsTable);

                #endregion

                #region Checkout attributes

                if (!String.IsNullOrEmpty(order.CheckoutAttributeDescription))
                {
                    doc.Add(new Paragraph(" "));
                    string attributes = HtmlHelper.ConvertHtmlToPlainText(order.CheckoutAttributeDescription, true, true);
                    var pCheckoutAttributes = new Paragraph(attributes, font);
                    pCheckoutAttributes.Alignment = Element.ALIGN_RIGHT;
                    doc.Add(pCheckoutAttributes);
                    doc.Add(new Paragraph(" "));
                }

                #endregion

                #region Totals

                //subtotal
                doc.Add(new Paragraph(" "));
                switch (order.CustomerTaxDisplayType)
                {
                    case TaxDisplayType.ExcludingTax:
                        {
                            var orderSubtotalExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalExclTax, order.CurrencyRate);
                            string orderSubtotalExclTaxStr = _priceFormatter.FormatPrice(orderSubtotalExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, false);

                            var p = new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Sub-Total", lang.Id), orderSubtotalExclTaxStr), font);
                            p.Alignment = Element.ALIGN_RIGHT;
                            doc.Add(p);
                        }
                        break;
                    case TaxDisplayType.IncludingTax:
                        {
                            var orderSubtotalInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalInclTax, order.CurrencyRate);
                            string orderSubtotalInclTaxStr = _priceFormatter.FormatPrice(orderSubtotalInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, true);

                            var p = new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Sub-Total", lang.Id), orderSubtotalInclTaxStr), font);
                            p.Alignment = Element.ALIGN_RIGHT;
                            doc.Add(p);
                        }
                        break;
                }
                //discount (applied to order subtotal)
                if (order.OrderSubTotalDiscountExclTax > decimal.Zero)
                {
                    switch (order.CustomerTaxDisplayType)
                    {
                        case TaxDisplayType.ExcludingTax:
                            {
                                var orderSubTotalDiscountExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountExclTax, order.CurrencyRate);
                                string orderSubTotalDiscountInCustomerCurrencyStr = _priceFormatter.FormatPrice(-orderSubTotalDiscountExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, false);

                                var p = new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Discount", lang.Id), orderSubTotalDiscountInCustomerCurrencyStr), font);
                                p.Alignment = Element.ALIGN_RIGHT;
                                doc.Add(p);
                            }
                            break;
                        case TaxDisplayType.IncludingTax:
                            {
                                var orderSubTotalDiscountInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountInclTax, order.CurrencyRate);
                                string orderSubTotalDiscountInCustomerCurrencyStr = _priceFormatter.FormatPrice(-orderSubTotalDiscountInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, true);

                                var p = new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Discount", lang.Id), orderSubTotalDiscountInCustomerCurrencyStr), font);
                                p.Alignment = Element.ALIGN_RIGHT;
                                doc.Add(p);
                            }
                            break;
                    }
                }

                //shipping
                if (order.ShippingStatus != ShippingStatus.ShippingNotRequired)
                {
                    switch (order.CustomerTaxDisplayType)
                    {
                        case TaxDisplayType.ExcludingTax:
                            {
                                var orderShippingExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingExclTax, order.CurrencyRate);
                                string orderShippingExclTaxStr = _priceFormatter.FormatShippingPrice(orderShippingExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, false);

                                var p = new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Shipping", lang.Id), orderShippingExclTaxStr), font);
                                p.Alignment = Element.ALIGN_RIGHT;
                                doc.Add(p);
                            }
                            break;
                        case TaxDisplayType.IncludingTax:
                            {
                                var orderShippingInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingInclTax, order.CurrencyRate);
                                string orderShippingInclTaxStr = _priceFormatter.FormatShippingPrice(orderShippingInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, true);

                                var p = new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Shipping", lang.Id), orderShippingInclTaxStr), font);
                                p.Alignment = Element.ALIGN_RIGHT;
                                doc.Add(p);
                            }
                            break;
                    }
                }

                //payment fee
                if (order.PaymentMethodAdditionalFeeExclTax > decimal.Zero)
                {
                    switch (order.CustomerTaxDisplayType)
                    {
                        case TaxDisplayType.ExcludingTax:
                            {
                                var paymentMethodAdditionalFeeExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeExclTax, order.CurrencyRate);
                                string paymentMethodAdditionalFeeExclTaxStr = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, false);

                                var p = new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.PaymentMethodAdditionalFee", lang.Id), paymentMethodAdditionalFeeExclTaxStr), font);
                                p.Alignment = Element.ALIGN_RIGHT;
                                doc.Add(p);
                            }
                            break;
                        case TaxDisplayType.IncludingTax:
                            {
                                var paymentMethodAdditionalFeeInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeInclTax, order.CurrencyRate);
                                string paymentMethodAdditionalFeeInclTaxStr = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, true);

                                var p = new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.PaymentMethodAdditionalFee", lang.Id), paymentMethodAdditionalFeeInclTaxStr), font);
                                p.Alignment = Element.ALIGN_RIGHT;
                                doc.Add(p);
                            }
                            break;
                    }
                }

                //tax
                string taxStr = string.Empty;
                var taxRates = new SortedDictionary<decimal, decimal>();
                bool displayTax = true;
                bool displayTaxRates = true;
                if (_taxSettings.HideTaxInOrderSummary && order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                {
                    displayTax = false;
                }
                else
                {
                    if (order.OrderTax == 0 && _taxSettings.HideZeroTax)
                    {
                        displayTax = false;
                        displayTaxRates = false;
                    }
                    else
                    {
                        taxRates = order.TaxRatesDictionary;

                        displayTaxRates = _taxSettings.DisplayTaxRates && taxRates.Count > 0;
                        displayTax = !displayTaxRates;

                        var orderTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTax, order.CurrencyRate);
                        taxStr = _priceFormatter.FormatPrice(orderTaxInCustomerCurrency, true, order.CustomerCurrencyCode, false, lang);
                    }
                }
                if (displayTax)
                {
                    var p = new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Tax", lang.Id), taxStr), font);
                    p.Alignment = Element.ALIGN_RIGHT;
                    doc.Add(p);
                }
                if (displayTaxRates)
                {
                    foreach (var item in taxRates)
                    {
                        string taxRate = String.Format(_localizationService.GetResource("PDFInvoice.TaxRate", lang.Id), _priceFormatter.FormatTaxRate(item.Key));
                        string taxValue = _priceFormatter.FormatPrice(_currencyService.ConvertCurrency(item.Value, order.CurrencyRate), true, order.CustomerCurrencyCode, false, lang);

                        var p = new Paragraph(String.Format("{0} {1}", taxRate, taxValue), font);
                        p.Alignment = Element.ALIGN_RIGHT;
                        doc.Add(p);
                    }
                }

                //discount (applied to order total)
                if (order.OrderDiscount > decimal.Zero)
                {
                    var orderDiscountInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderDiscount, order.CurrencyRate);
                    string orderDiscountInCustomerCurrencyStr = _priceFormatter.FormatPrice(-orderDiscountInCustomerCurrency, true, order.CustomerCurrencyCode, false, lang);

                    var p = new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.Discount", lang.Id), orderDiscountInCustomerCurrencyStr), font);
                    p.Alignment = Element.ALIGN_RIGHT;
                    doc.Add(p);
                }

                //gift cards
                foreach (var gcuh in order.GiftCardUsageHistory)
                {
                    string gcTitle = string.Format(_localizationService.GetResource("PDFInvoice.GiftCardInfo", lang.Id), gcuh.GiftCard.GiftCardCouponCode);
                    string gcAmountStr = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(gcuh.UsedValue, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, lang);

                    var p = new Paragraph(String.Format("{0} {1}", gcTitle, gcAmountStr), font);
                    p.Alignment = Element.ALIGN_RIGHT;
                    doc.Add(p);
                }

                //reward points
                if (order.RedeemedRewardPointsEntry != null)
                {
                    string rpTitle = string.Format(_localizationService.GetResource("PDFInvoice.RewardPoints", lang.Id), -order.RedeemedRewardPointsEntry.Points);
                    string rpAmount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(order.RedeemedRewardPointsEntry.UsedAmount, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, lang);

                    var p = new Paragraph(String.Format("{0} {1}", rpTitle, rpAmount), font);
                    p.Alignment = Element.ALIGN_RIGHT;
                    doc.Add(p);
                }

                //order total
                var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate);
                string orderTotalStr = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, lang);

                var pTotal = new Paragraph(String.Format("{0} {1}", _localizationService.GetResource("PDFInvoice.OrderTotal", lang.Id), orderTotalStr), titleFont);
                pTotal.Alignment = Element.ALIGN_RIGHT;
                doc.Add(pTotal);

                #endregion

                #region Order notes

                if (_pdfSettings.RenderOrderNotes)
                {
                    var orderNotes = order.OrderNotes
                        .Where(on => on.DisplayToCustomer)
                        .OrderByDescending(on => on.CreatedOnUtc)
                        .ToList();
                    if (orderNotes.Count > 0)
                    {
                        doc.Add(new Paragraph(_localizationService.GetResource("PDFInvoice.OrderNotes", lang.Id), titleFont));

                        doc.Add(new Paragraph(" "));

                        var notesTable = new PdfPTable(2);
                        notesTable.WidthPercentage = 100f;
                        notesTable.SetWidths(new[] { 30, 70 });

                        //created on
                        cell = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.OrderNotes.CreatedOn", lang.Id), font));
                        cell.BackgroundColor = BaseColor.LIGHT_GRAY;
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        notesTable.AddCell(cell);

                        //note
                        cell = new PdfPCell(new Phrase(_localizationService.GetResource("PDFInvoice.OrderNotes.Note", lang.Id), font));
                        cell.BackgroundColor = BaseColor.LIGHT_GRAY;
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        notesTable.AddCell(cell);

                        foreach (var orderNote in orderNotes)
                        {
                            cell = new PdfPCell();
                            cell.AddElement(new Paragraph(_dateTimeHelper.ConvertToUserTime(orderNote.CreatedOnUtc, DateTimeKind.Utc).ToString(), font));
                            cell.HorizontalAlignment = Element.ALIGN_LEFT;
                            notesTable.AddCell(cell);

                            cell = new PdfPCell();
                            cell.AddElement(new Paragraph(HtmlHelper.ConvertHtmlToPlainText(orderNote.FormatOrderNoteText(), true, true), font));
                            cell.HorizontalAlignment = Element.ALIGN_LEFT;
                            notesTable.AddCell(cell);
                        }
                        doc.Add(notesTable);
                    }
                }

                #endregion

                #region Footer

                if (!String.IsNullOrEmpty(_pdfSettings.InvoiceFooterTextColumn1) || !String.IsNullOrEmpty(_pdfSettings.InvoiceFooterTextColumn2))
                {
                    var column1Lines = String.IsNullOrEmpty(_pdfSettings.InvoiceFooterTextColumn1) ?
                        new List<string>() :
                        _pdfSettings.InvoiceFooterTextColumn1
                        .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                        .ToList();
                    var column2Lines = String.IsNullOrEmpty(_pdfSettings.InvoiceFooterTextColumn2) ?
                        new List<string>() :
                        _pdfSettings.InvoiceFooterTextColumn2
                        .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                        .ToList();
                    if (column1Lines.Count > 0 || column2Lines.Count > 0)
                    {
                        var totalLines = Math.Max(column1Lines.Count, column2Lines.Count);
                        const float margin = 43;

                        //if you have really a lot of lines in the footer, then replace 9 with 10 or 11
                        int footerHeight = totalLines * 9;
                        var directContent = pdfWriter.DirectContent;
                        directContent.MoveTo(pageSize.GetLeft(margin), pageSize.GetBottom(margin) + footerHeight);
                        directContent.LineTo(pageSize.GetRight(margin), pageSize.GetBottom(margin) + footerHeight);
                        directContent.Stroke();

                        var footerTable = new PdfPTable(2);
                        footerTable.WidthPercentage = 100f;
                            footerTable.SetTotalWidth(new float[] { 250, 250 });

                        //column 1
                        if (column1Lines.Count > 0)
                        {
                            var column1 = new PdfPCell();
                            column1.Border = Rectangle.NO_BORDER;
                            column1.HorizontalAlignment = Element.ALIGN_LEFT;
                            foreach (var footerLine in column1Lines)
                            {
                                column1.AddElement(new Phrase(footerLine, font));
                            }
                            footerTable.AddCell(column1);
                        }
                        else
                        {
                            var column = new PdfPCell(new Phrase(" "));
                            column.Border = Rectangle.NO_BORDER;
                            footerTable.AddCell(column);
                        }

                        //column 2
                        if (column2Lines.Count > 0)
                        {
                            var column2 = new PdfPCell();
                            column2.Border = Rectangle.NO_BORDER;
                            column2.HorizontalAlignment = Element.ALIGN_LEFT;
                            foreach (var footerLine in column2Lines)
                            {
                                column2.AddElement(new Phrase(footerLine, font));
                            }
                            footerTable.AddCell(column2);
                        }
                        else
                        {
                            var column = new PdfPCell(new Phrase(" "));
                            column.Border = Rectangle.NO_BORDER;
                            footerTable.AddCell(column);
                        }

                        footerTable.WriteSelectedRows(0, totalLines, pageSize.GetLeft(margin), pageSize.GetBottom(margin) + footerHeight, directContent);
                    }
                }

                #endregion

                ordNum++;
                if (ordNum < ordCount)
                {
                    doc.NewPage();
                }
            }
            doc.Close();
        }
Esempio n. 18
0
        /// <summary>
        /// 订单出货明细
        /// </summary>
        public void GetOrderDetailsPDF()
        {
            string deliver_id = Request.Params["deliver_id"];
            _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
            DataTable orderdeliver = _DeliverDetailMgr.GetOrderDelivers(deliver_id);
            Dictionary<string, string> dicproduct_freight_set = new Dictionary<string, string> { { "1", "1" }, { "2", "2" }, { "3", "1" }, { "4", "2" }, { "5", "5" }, { "6", "5" } };
            BaseFont bfChinese = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(bfChinese, 12, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑

            string filename = "order_details_D" + deliver_id.PadLeft(8, '0') + ".pdf";
            Document document = new Document(PageSize.A4, (float)5, (float)5, (float)20, (float)0.5);
            string newPDFName = Server.MapPath(excelPath) + filename;
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPDFName, FileMode.Create));
            document.Open();

            PdfContentByte cb = writer.DirectContent;

            if (orderdeliver.Rows.Count > 0)
            {
                #region 生成條形碼
                BarCode.Code128 _Code = new BarCode.Code128();
                _Code.ValueFont = new System.Drawing.Font("宋体", 20);
                System.Drawing.Bitmap imgTemp = _Code.GetCodeImage("D" + orderdeliver.Rows[0]["deliver_id"].ToString().PadLeft(8, '0'), BarCode.Code128.Encode.Code128A);
                imgTemp.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                iTextSharp.text.Image IMG = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG.ScaleToFit(200, 30);
                IMG.SetAbsolutePosition(345, 740);
                #endregion

                cb.BeginText();
                cb.SetFontAndSize(bfChinese, 20);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "吉甲地市集出貨明細", 30, 750, 0);
                //首購
                if (orderdeliver.Rows[0]["priority"].ToString() == "1")
                {
                    PdfPTable ot = new PdfPTable(1);
                    ot.SetTotalWidth(new float[] { 190 });
                    PdfPCell c = new PdfPCell(new Phrase("", font));
                    c.FixedHeight = 30;
                    c.BorderWidthBottom = 0.5f;
                    c.BorderWidthLeft = 0.5f;
                    c.BorderWidthRight = 0.5f;
                    c.BorderWidthTop = 0.5f;
                    ot.AddCell(c);
                    ot.WriteSelectedRows(0, -1, 29, 770, cb);
                }
                cb.AddImage(IMG);
                if (orderdeliver.Rows[0]["channel"].ToString() != "1")
                {
                    cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, orderdeliver.Rows[0]["channel_name_simple"].ToString(), 80, 700, 0);
                }
                if (orderdeliver.Rows[0]["retrieve_mode"].ToString() == "1")
                {
                    cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "7-11取貨", 200, 700, 0);
                }
                cb.SetFontAndSize(bfChinese, 10);
                string freight_set = string.Empty;
                switch (orderdeliver.Rows[0]["freight_set"].ToString().Trim())
                {
                    case "1":
                        freight_set = "常溫";
                        break;
                    case "2":
                        freight_set = "冷凍";
                        break;
                    case "5":
                        freight_set = "冷藏";
                        break;
                }
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, freight_set, 345, 785, 0);
                string estimated_arrival_period = string.Empty;
                if (orderdeliver.Rows[0]["estimated_arrival_period"].ToString() != "0")
                {
                    switch (orderdeliver.Rows[0]["estimated_arrival_period"].ToString().Trim())
                    {
                        case "0":
                            estimated_arrival_period = "不限時";
                            break;
                        case "1":
                            estimated_arrival_period = "12:00以前";
                            break;
                        case "2":
                            estimated_arrival_period = "12:00-17:00";
                            break;
                        case "3":
                            estimated_arrival_period = "17:00-20:00";
                            break;
                    }

                    cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, estimated_arrival_period, 345, 773, 0);
                }

            }
            cb.SetFontAndSize(bfChinese, 10);
            //cb.SetTextMatrix(150,20);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "訂購人:", 10, 680, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "收件人:", 200, 680, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "付款單號:", 10, 660, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "收件地址:", 200, 660, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "訂購時間:", 10, 640, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "聯絡電話:", 200, 640, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "付款時間:", 10, 620, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "假日可收貨:", 200, 620, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "出貨備註:", 10, 600, 0);
            cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "訂單明細:", 10, 580, 0);
            if (orderdeliver.Rows.Count > 0 && orderdeliver.Rows[0]["receivable"].ToString() != "0")
            {
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "應收金額:" + orderdeliver.Rows[0]["receivable"].ToString(), 200, 580, 0);
            }

            string address = string.Empty;
            string deliver_note = string.Empty;
            if (orderdeliver.Rows.Count > 0)
            {
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, orderdeliver.Rows[0]["order_name"].ToString(), 65, 680, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, orderdeliver.Rows[0]["delivery_name"].ToString(), 250, 680, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, orderdeliver.Rows[0]["order_id"].ToString(), 65, 660, 0);
                address += CommonFunction.ZipAddress(orderdeliver.Rows[0]["delivery_zip"].ToString()) + orderdeliver.Rows[0]["delivery_address"].ToString();

                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, address, 250, 660, 0);
                string order_createdate = orderdeliver.Rows[0]["order_createdate"].ToString() != "0" ? CommonFunction.GetNetTime(long.Parse(orderdeliver.Rows[0]["order_createdate"].ToString())).ToString("yyyy-MM-dd HH:mm:ss") : "";
                string money_collect_date = orderdeliver.Rows[0]["money_collect_date"].ToString() != "0" ? CommonFunction.GetNetTime(long.Parse(orderdeliver.Rows[0]["money_collect_date"].ToString())).ToString("yyyy-MM-dd HH:mm:ss") : "";
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, order_createdate, 65, 640, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, orderdeliver.Rows[0]["delivery_mobile"].ToString(), 250, 640, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, money_collect_date, 65, 620, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, orderdeliver.Rows[0]["holiday_deliver"].ToString() == "1" ? "可" : "不可", 260, 620, 0);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, orderdeliver.Rows[0]["note_order"].ToString().Trim(), 65, 600, 0);
                if (orderdeliver.Rows[0]["delivery_store"].ToString() == "12")
                {
                    deliver_note = "*自取(取貨地址:台北市南港區八德路4段768巷7號6樓之1,取貨時間週一~週五,AM9:00~PM6:00)";
                }
                else if (orderdeliver.Rows[0]["delivery_store"].ToString() == "13")
                {
                    deliver_note = "*自取(取貨地址:新北市板橋區三民路二段33號21樓,取貨時間週一~週五,AM9:00~PM6:00)";
                }
                else if (orderdeliver.Rows[0]["delivery_store"].ToString() == "14")
                {
                    deliver_note = "*自取(取貨地址:新北市永和區成功路一段80號20樓,取貨時間週一~週五,AM9:00~PM6:00)";
                }
                cb.SetFontAndSize(bfChinese, 8);
                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliver_note, 65, 580, 0);
            }
            cb.EndText();
            PdfPTable ptable = new PdfPTable(7);
            ptable.WidthPercentage = 98;
            ptable.SetTotalWidth(new float[] { 50, 280, 50, 50, 50, 50, 50 });
            PdfPCell cell;
            font = new iTextSharp.text.Font(bfChinese, 8, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
            cell = new PdfPCell(new Phrase("商品編號", font));
            cell.DisableBorderSide(2);
            cell.DisableBorderSide(8);
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase("商品名稱", font));
            cell.DisableBorderSide(2);
            cell.DisableBorderSide(8);
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase("托運單屬性", font));
            cell.DisableBorderSide(2);
            cell.DisableBorderSide(8);
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase("數量", font));
            cell.DisableBorderSide(2);
            cell.DisableBorderSide(8);
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase("本次出貨", font));
            cell.DisableBorderSide(2);
            cell.DisableBorderSide(8);
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase("預計出貨日", font));
            cell.DisableBorderSide(2);
            cell.DisableBorderSide(8);
            ptable.AddCell(cell);
            cell = new PdfPCell(new Phrase("供應商自出", font));
            cell.DisableBorderSide(2);
            ptable.AddCell(cell);
            PdfPCell td;
            string lastdeliverid = "0";
            ArrayList normal = new ArrayList();
            ArrayList low = new ArrayList();
            ArrayList lowstore = new ArrayList();
            DataRow[] sinceorder = new DataRow[] { };

            DataRow[] singleproduct = new DataRow[] { };//單一商品
            DataRow[] fatherproduct = new DataRow[] { };//組合商品中的父商品
            DataRow[] sonproduct = new DataRow[] { };//組合商品中的子商品
            ArrayList combine = new ArrayList();
            List<DataRow[]> orderdelivers = new List<DataRow[]>();

            sinceorder = orderdeliver.Select("dtype=2 and combined_mode<=1 ", "item_id asc");//自出商品
            singleproduct = orderdeliver.Select("dtype <>2 and combined_mode<=1  ", "item_id asc");//單一商品
            if (singleproduct.Count() > 0)
            {
                orderdelivers.Add(singleproduct);
            }
            fatherproduct = orderdeliver.Select(" combined_mode>1 and item_mode=1", "item_id asc");//組合商品中父商品是否存在
            foreach (var item in fatherproduct)
            {
                combine.Add(item);
                sonproduct = orderdeliver.Select(" combined_mode>1 and item_mode<>1 and parent_id=" + item["parent_id"] + " and pack_id=" + item["pack_id"], "item_id asc");//對應組合商品中的子商品
                foreach (var son in sonproduct)
                {
                    son["buy_num"] = (int.Parse(son["buy_num"].ToString()) * int.Parse(son["parent_num"].ToString())).ToString();
                    combine.Add(son);
                }
            }
            if (combine.Count > 0)
            {
                orderdelivers.Add((DataRow[])combine.ToArray(typeof(DataRow)));
            }
            //區分常溫、冷凍、冷藏
            foreach (var item in orderdelivers)
            {
                foreach (var row in item)
                {
                    string s = row["product_freight_set"].ToString();
                    switch (row["product_freight_set"].ToString())
                    {
                        case "1":
                        case "3":
                            normal.Add(row);//常溫
                            break;
                        case "2":
                        case "4":
                            low.Add(row);//冷凍
                            break;
                        case "5":
                        case "6":
                            lowstore.Add(row);//冷藏
                            break;
                        default:
                            break;
                    }
                }
            }

            orderdelivers = new List<DataRow[]>();
            if (normal.Count > 0)
            {
                orderdelivers.Add((DataRow[])normal.ToArray(typeof(DataRow)));
            }
            if (low.Count > 0)
            {
                orderdelivers.Add((DataRow[])low.ToArray(typeof(DataRow)));
            }
            if (lowstore.Count > 0)
            {
                orderdelivers.Add((DataRow[])lowstore.ToArray(typeof(DataRow)));
            }
            if (sinceorder.Count() > 0)
            {
                orderdelivers.Add(sinceorder);
            }
            int j = 0;
            foreach (var item in orderdelivers)
            {
                j++;
                for (int i = 0; i < item.Count(); i++)
                {
                    if (item[i]["ddeliver_id"].ToString() != lastdeliverid || i == 0)
                    {
                        lastdeliverid = item[i]["ddeliver_id"].ToString();//以一個出貨單號為界限
                        if (lastdeliverid != "0" || i == 0)
                        {
                            td = new PdfPCell();
                            td.Colspan = 7;
                            td.DisableBorderSide(2);
                            td.DisableBorderSide(4);
                            td.DisableBorderSide(8);
                            //td.BorderWidthTop = 0.2f;
                            ptable.AddCell(td);
                        }
                    }
                    string item_id = string.Empty;
                    if (item[i]["item_mode"].ToString() == "1")
                    {
                        item_id = item[i]["parent_id"].ToString();
                    }
                    else
                    {
                        item_id = item[i]["item_id"].ToString();
                    }
                    font = new iTextSharp.text.Font(bfChinese, 8, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
                    td = new PdfPCell(new Phrase(item_id, font));
                    td.DisableBorderSide(1);
                    td.DisableBorderSide(2);
                    td.DisableBorderSide(8);
                    //td.BorderWidthLeft = 0.2f;
                    ptable.AddCell(td);
                    string datacontent = ((item[i]["product_mode"].ToString() == "2" && item[i]["item_mode"].ToString() != "1") ? "*" : " ") + item[i]["brand_name"].ToString() + "-" + item[i]["product_name"].ToString() + item[i]["product_spec_name"].ToString();
                    if (item[i]["combined_mode"].ToString() != "0" && item[i]["item_mode"].ToString() == "2")
                    {
                        datacontent = "  " + datacontent;
                    }
                    td = new PdfPCell(new Phrase(datacontent, font));
                    td.DisableBorderSide(1);
                    td.DisableBorderSide(2);
                    td.DisableBorderSide(8);
                    ptable.AddCell(td);
                    string value = string.Empty;
                    string freight_set = string.Empty;
                    if (dicproduct_freight_set.TryGetValue(item[i]["product_freight_set"].ToString(), out value))
                    {

                    }
                    switch (value)
                    {
                        case "1":
                            freight_set = "常溫";
                            break;
                        case "2":
                            freight_set = "冷凍";
                            break;
                        case "5":
                            freight_set = "冷藏";
                            break;
                    }
                    td = new PdfPCell(new Phrase(freight_set, font));
                    td.DisableBorderSide(1);
                    td.DisableBorderSide(2);
                    td.DisableBorderSide(8);
                    //td.BorderWidthLeft = 0.2f;
                    ptable.AddCell(td);
                    font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
                    td = new PdfPCell(new Phrase(item[i]["item_mode"].ToString() != "1" ? item[i]["buy_num"].ToString() : "", font));
                    td.DisableBorderSide(1);
                    td.DisableBorderSide(2);
                    td.DisableBorderSide(8);
                    // td.BorderWidthLeft = 0.2f;
                    ptable.AddCell(td);
                    td = new PdfPCell();
                    td.DisableBorderSide(1);
                    td.DisableBorderSide(2);
                    td.DisableBorderSide(8);
                    //td.BorderWidthLeft = 0.2f;
                    ptable.AddCell(td);
                    td = new PdfPCell();
                    td.DisableBorderSide(1);
                    td.DisableBorderSide(2);
                    td.DisableBorderSide(8);
                    //td.BorderWidthLeft = 0.2f;
                    ptable.AddCell(td);

                    Image image = Image.GetInstance(Server.MapPath("../Content/img/icons/mark.png"));
                    image.ScalePercent(5, 5);
                    if (item[i]["dtype"].ToString() == "2")
                    {
                        td = new PdfPCell(image, false);
                    }
                    else
                    {
                        td = new PdfPCell();
                    }
                    td.HorizontalAlignment = Element.ALIGN_CENTER;
                    td.VerticalAlignment = Element.ALIGN_MIDDLE;
                    td.DisableBorderSide(1);
                    td.DisableBorderSide(2);
                    ptable.AddCell(td);
                }
            }
            string note_order = orderdeliver.Rows.Count.ToString() != "0" ? orderdeliver.Rows[0]["note_order"].ToString().Trim() : "";
            cell = new PdfPCell(new Phrase(new Chunk("備註:" + note_order, font)));
            cell.Colspan = 7;
            cell.HorizontalAlignment = Element.ALIGN_LEFT;
            ptable.AddCell(cell);
            PdfPTable nulltable = new PdfPTable(2);
            nulltable.SetWidths(new int[] { 20, 20 });
            nulltable.DefaultCell.DisableBorderSide(1);
            nulltable.DefaultCell.DisableBorderSide(2);
            nulltable.DefaultCell.DisableBorderSide(4);
            nulltable.DefaultCell.DisableBorderSide(8);
            nulltable.AddCell("");
            nulltable.AddCell("");
            nulltable.SpacingAfter = 250;
            document.Add(nulltable);
            ptable.SpacingAfter = 50;
            document.Add(ptable);

            font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
            document.Add(new Phrase("吉甲地市集網路平台購物發票說明:\n", font));
            font = new iTextSharp.text.Font(bfChinese, 8, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
            document.Add(new Phrase("若您訂購時未選擇開立三聯式發票,平台一律開立電子發票。\n", font));
            document.Add(new Phrase("發票將於該筆訂單商品完全出貨之後第10天開立並以E-Mail通知您。\n", font));
            document.Add(new Phrase("如需紙本發票請來信客服中心,會計部門將會依需求將電子發票印出並以平信郵寄約2~7個工作天內送達。\n", font));
            document.Add(new Phrase("託管發票將會在單月26日進行對獎作業後,系統將會發信通知中獎發票持有人,\n", font));
            document.Add(new Phrase("且為保障您的權益,我們將在七個工作天內,以掛號方式把中獎發票寄給您。\n", font));
            font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
            document.Add(new Phrase("祝您購物愉快!", font));
            document.Close();
            writer.Resume();

            Response.Clear();
            Response.Charset = "gb2312";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.AddHeader("Content-Disposition", "attach-ment;filename=" + filename);
            Response.WriteFile(newPDFName);
        }
Esempio n. 19
0
        /*
         * (non-Javadoc)
         *
         * @see
         * com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag,
         * java.util.List, com.itextpdf.text.Document)
         */
        public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) {
            try {
			    bool percentage = false;
                String widthValue = null;
                tag.CSS.TryGetValue(HTML.Attribute.WIDTH, out widthValue);
			    if (!tag.CSS.TryGetValue(HTML.Attribute.WIDTH, out widthValue)
                    && !tag.Attributes.TryGetValue(HTML.Attribute.WIDTH, out widthValue)) {
			        widthValue = null;
			    }
			    if(widthValue != null && widthValue.Trim().EndsWith("%")) {
				    percentage = true;
			    }
                int numberOfColumns = 0;
                List<TableRowElement> tableRows = new List<TableRowElement>(currentContent.Count);
                IList<IElement> invalidRowElements = new List<IElement>(1);
                String repeatHeader;
                tag.CSS.TryGetValue(CSS.Property.REPEAT_HEADER, out repeatHeader);
                String repeatFooter;
                tag.CSS.TryGetValue(CSS.Property.REPEAT_FOOTER, out repeatFooter);
                int headerRows = 0;
                int footerRows = 0;
                foreach (IElement e in currentContent) {
                    int localNumCols = 0;
                    if (e is TableRowElement) {
                        TableRowElement tableRowElement = (TableRowElement) e;
                        foreach (HtmlCell cell in tableRowElement.Content) {
                            localNumCols += cell.Colspan;
                        }
                        if (localNumCols > numberOfColumns) {
                            numberOfColumns = localNumCols;
                        }
                        tableRows.Add(tableRowElement);
                        if (repeatHeader != null && Util.EqualsIgnoreCase(repeatHeader, "yes") && tableRowElement.RowPlace.Equals(TableRowElement.Place.HEADER)) {
                            headerRows++;
                        }
                        if (repeatFooter != null && Util.EqualsIgnoreCase(repeatFooter, "yes") && tableRowElement.RowPlace.Equals(TableRowElement.Place.FOOTER)){
                            footerRows++;
                        }
                    } else {
                        invalidRowElements.Add(e);
                    }
                }
                if(repeatFooter == null || !Util.EqualsIgnoreCase(repeatFooter, "yes")) {
                    SortUtil.InsertionSort<TableRowElement>(tableRows, delegate(TableRowElement o1, TableRowElement o2) {
                        return o1.RowPlace.Normal.CompareTo(o2.RowPlace.Normal);
                    });
                } else {
                    SortUtil.InsertionSort<TableRowElement>(tableRows, delegate(TableRowElement o1, TableRowElement o2) {
                        return o1.RowPlace.Repeated.CompareTo(o2.RowPlace.Repeated);
                    });
                }
                PdfPTable table = new PdfPTable(numberOfColumns);
                table.HeaderRows = headerRows+footerRows;
                table.FooterRows = footerRows;
                table.HorizontalAlignment = Element.ALIGN_LEFT;
                table.SplitLate = false;
                TableStyleValues styleValues = SetStyleValues(tag);
                table.TableEvent = new TableBorderEvent(styleValues);
                SetVerticalMargin(table, tag, styleValues, ctx);
                WidenLastCell(tableRows, styleValues.HorBorderSpacing);
                float[] columnWidths = new float[numberOfColumns];
                float[] widestWords = new float[numberOfColumns];
                float[] fixedWidths = new float[numberOfColumns];
                float[] colspanWidestWords = new float[numberOfColumns];
                int[] rowspanValue = new int[numberOfColumns];
                float largestColumn = 0;
                float largestColspanColumn = 0;
                int indexOfLargestColumn = -1;
                int indexOfLargestColspanColumn = -1;

                // Initial fill of the widths arrays
                foreach (TableRowElement row in tableRows) {
                    int column = 0;
                    foreach (HtmlCell cell in row.Content) {
                        // check whether the current column should be skipped due to a
                        // rowspan value of higher cell in this column.
                        // Contribution made by Arnost Havelka (Asseco): added while condition
                        while ((column < numberOfColumns) && (rowspanValue[column] > 0)) {
                            rowspanValue[column] = rowspanValue[column] - 1;
                            ++column;
                        }
                        // sets a rowspan counter for current column (counter not
                        // needed for last column).
                        if (cell.Rowspan > 1 && column != numberOfColumns - 1 && column < rowspanValue.Length) {
                            rowspanValue[column] = cell.Rowspan - 1;
                        }
                        int colspan = cell.Colspan;
                        if (cell.FixedWidth != 0) {
                            float fixedWidth = cell.FixedWidth + GetCellStartWidth(cell);
                            fixedWidth /= colspan;
                            for (int i = 0; i < colspan; i++) {
                                int c = column + i;
                                // Contribution made by Arnost Havelka (Asseco)
                                if (c > numberOfColumns - 1) {
                                    break;
                                }
                                if (fixedWidth > fixedWidths[c]) {
                                    fixedWidths[c] = fixedWidth;
                                    columnWidths[c] = fixedWidth;
                                }
                            }
                        }
                        if (cell.CompositeElements != null) {
                            float[] widthValues = SetCellWidthAndWidestWord(cell);
                            float cellWidth = widthValues[0] / colspan;
                            float widestWordOfCell = widthValues[1] / colspan;
                            for (int i = 0; i < colspan; i++) {
                                int c = column + i;
                                // Contribution made by Arnost Havelka (Asseco)
                                if (c >= numberOfColumns) {
                                    continue;
                                }
                                if (fixedWidths[c] == 0 && cellWidth > columnWidths[c]) {
                                    columnWidths[c] = cellWidth;
                                    if (colspan == 1) {
                                        if (cellWidth > largestColumn) {
                                            largestColumn = cellWidth;
                                            indexOfLargestColumn = c;
                                        }
                                    } else {
                                        if (cellWidth > largestColspanColumn) {
                                            largestColspanColumn = cellWidth;
                                            indexOfLargestColspanColumn = c;
                                        }
                                    }
                                }
                                if (colspan == 1) {
                                    if (widestWordOfCell > widestWords[c]) {
                                        widestWords[c] = widestWordOfCell;
                                    }
                                } else {
                                    if (widestWordOfCell > colspanWidestWords[c]) {
                                        colspanWidestWords[c] = widestWordOfCell;
                                    }
                                }
                            }
                        }
                        if (colspan > 1) {
                            if (LOG.IsLogging(Level.TRACE)) {
                                LOG.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.COLSPAN), colspan));
                            }
                            column += colspan - 1;
                        }
                        column++;
                    }
                }

                if (indexOfLargestColumn == -1) {
                    indexOfLargestColumn = indexOfLargestColspanColumn;
                    if (indexOfLargestColumn == -1) {
                        indexOfLargestColumn = 0;
                    }

                    for (int column = 0; column < numberOfColumns; column++) {
                        widestWords[column] = colspanWidestWords[column];
                    }
                }
                float outerWidth = GetTableOuterWidth(tag, styleValues.HorBorderSpacing, ctx);
                float initialTotalWidth = GetTableWidth(columnWidths, 0);
    //          float targetWidth = calculateTargetWidth(tag, columnWidths, outerWidth, ctx);
                float targetWidth = 0;
                HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx);
                float max = htmlPipelineContext.PageSize.Width - outerWidth;
                bool tableWidthFixed = false;
                if (tag.Attributes.ContainsKey(CSS.Property.WIDTH) || tag.CSS.ContainsKey(CSS.Property.WIDTH)) {
                    targetWidth = new WidthCalculator().GetWidth(tag, htmlPipelineContext.GetRootTags(), htmlPipelineContext.PageSize.Width);
                    if (targetWidth > max) {
                        targetWidth = max;
                    }
                    tableWidthFixed = true;
                } else if (initialTotalWidth <= max) {
                    targetWidth = initialTotalWidth;
                } else if (null == tag.Parent || (null != tag.Parent && htmlPipelineContext.GetRootTags().Contains(tag.Parent.Name))) {
                    targetWidth = max;
                } else /* this table is an inner table and width adjustment is done in outer table */{
                    targetWidth = GetTableWidth(columnWidths, outerWidth);
                }
                float totalFixedColumnWidth = GetTableWidth(fixedWidths, 0);
                float targetPercentage = 0;
                if (totalFixedColumnWidth == initialTotalWidth) { // all column widths are fixed
                    targetPercentage = targetWidth / initialTotalWidth;
                    if (initialTotalWidth > targetWidth) {
                        for (int column = 0; column < columnWidths.Length; column++) {
                            columnWidths[column] *= targetPercentage;
                        }
                    } else if(tableWidthFixed && targetPercentage != 1){
                        for (int column = 0; column < columnWidths.Length; column++) {
                            columnWidths[column] *= targetPercentage;
                        }
                    }
                } else {
                    targetPercentage = (targetWidth - totalFixedColumnWidth) / (initialTotalWidth - totalFixedColumnWidth);
                    // Reduce width of columns if the columnWidth array + borders +
                    // paddings
                    // is too large for the given targetWidth.
                    if (initialTotalWidth > targetWidth) {
                        float leftToReduce = 0;
                        for (int column = 0; column < columnWidths.Length; column++) {
                            if (fixedWidths[column] == 0) {
                                // Reduce width of the column to its targetWidth, if
                                // widestWord of column still fits in the targetWidth of
                                // the
                                // column.
                                if (widestWords[column] <= columnWidths[column] * targetPercentage) {
                                    columnWidths[column] *= targetPercentage;
                                    // else take the widest word and calculate space
                                    // left to
                                    // reduce.
                                } else {
                                    columnWidths[column] = widestWords[column];
                                    leftToReduce += widestWords[column] - columnWidths[column] * targetPercentage;
                                }
                                // if widestWord of a column does not fit in the
                                // fixedWidth,
                                // set the column width to the widestWord.
                            } else if (fixedWidths[column] < widestWords[column]) {
                                columnWidths[column] = widestWords[column];
                                leftToReduce += widestWords[column] - fixedWidths[column];
                            }
                        }
                        if (leftToReduce != 0) {
                            // Reduce width of the column with the most text, if its
                            // widestWord still fits in the reduced column.
                            if (widestWords[indexOfLargestColumn] <= columnWidths[indexOfLargestColumn] - leftToReduce) {
                                columnWidths[indexOfLargestColumn] -= leftToReduce;
                            } else { // set all columns to their minimum, with the
                                        // widestWord array.
                                for (int column = 0; leftToReduce != 0 && column < columnWidths.Length; column++) {
                                    if (fixedWidths[column] == 0 && columnWidths[column] > widestWords[column]) {
                                        float difference = columnWidths[column] - widestWords[column];
                                        if (difference <= leftToReduce) {
                                            leftToReduce -= difference;
                                            columnWidths[column] = widestWords[column];
                                        } else {
                                            columnWidths[column] -= leftToReduce;
                                            leftToReduce = 0;
                                        }
                                    }
                                }
                                if (leftToReduce != 0) {
                                    // If the table has an insufficient fixed width
                                    // by
                                    // an
                                    // attribute or style, try to enlarge the table
                                    // to
                                    // its
                                    // minimum width (= widestWords array).
                                    float pageWidth = GetHtmlPipelineContext(ctx).PageSize.Width;
                                    if (GetTableWidth(widestWords, outerWidth) < pageWidth) {
                                        targetWidth = GetTableWidth(widestWords, outerWidth);
                                        leftToReduce = 0;
                                    } else {
                                        // If all columnWidths are set to the
                                        // widestWordWidths and the table is still
                                        // to
                                        // wide
                                        // content will fall off the edge of a page,
                                        // which
                                        // is similar to HTML.
                                        targetWidth = pageWidth - outerWidth;
                                        leftToReduce = 0;
                                    }
                                }
                            }
                        }
                        // Enlarge width of columns to fit the targetWidth.
                    } else if (initialTotalWidth < targetWidth) {
                        for (int column = 0; column < columnWidths.Length; column++) {
                            if (fixedWidths[column] == 0) {
                                columnWidths[column] *= targetPercentage;
                            }
                        }
                    }
                }
                try {
                    table.SetTotalWidth(columnWidths);
                    table.LockedWidth = true;
                    table.DefaultCell.Border = Rectangle.NO_BORDER;
                } catch (DocumentException e) {
                    throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e);
                }
                float? tableHeight = new HeightCalculator().GetHeight(tag, GetHtmlPipelineContext(ctx).PageSize.Height);
                float? tableRowHeight = null;
                if (tableHeight != null && tableHeight > 0)
                    tableRowHeight = tableHeight / tableRows.Count;
                int rowNumber = 0;
                foreach (TableRowElement row in tableRows) {
                    int columnNumber = -1;
                    float? computedRowHeight = null;
                    /*if ( tableHeight != null &&  tableRows.IndexOf(row) == tableRows.Count - 1) {
                        float computedTableHeigt = table.CalculateHeights();
                        computedRowHeight = tableHeight - computedTableHeigt;
                    }*/
                    IList<HtmlCell> rowContent = row.Content;
                    if(rowContent.Count < 1)
                        continue;
                    foreach (HtmlCell cell in rowContent) {
                        IList<IElement> compositeElements = cell.CompositeElements;
                        if (compositeElements != null) {
                            foreach (IElement baseLevel in compositeElements) {
                                if (baseLevel is PdfPTable) {
                                    TableStyleValues cellValues = cell.CellValues;
                                    float totalBordersWidth = cellValues.IsLastInRow ? styleValues.HorBorderSpacing * 2
                                            : styleValues.HorBorderSpacing;
                                    totalBordersWidth += cellValues.BorderWidthLeft + cellValues.BorderWidthRight;
                                    float columnWidth = 0;
                                    for (int currentColumnNumber = columnNumber + 1; currentColumnNumber <= columnNumber + cell.Colspan; currentColumnNumber++){
                                        columnWidth += columnWidths[currentColumnNumber];
                                    }
                                    IPdfPTableEvent tableEvent = ((PdfPTable) baseLevel).TableEvent;
                                    TableStyleValues innerStyleValues = ((TableBorderEvent) tableEvent).TableStyleValues;
                                    totalBordersWidth += innerStyleValues.BorderWidthLeft;
                                    totalBordersWidth += innerStyleValues.BorderWidthRight;
                                    ((PdfPTable) baseLevel).TotalWidth = columnWidth - totalBordersWidth;
                                }
                            }
                        }
                        columnNumber += cell.Colspan;

                        table.AddCell(cell);
                    }
                    table.CompleteRow();
                    if ((computedRowHeight == null || computedRowHeight <= 0) && tableRowHeight != null)
                        computedRowHeight = tableRowHeight;
                    if (computedRowHeight != null && computedRowHeight > 0) {
                        float rowHeight = table.GetRow(rowNumber).MaxHeights;
                        if (rowHeight < computedRowHeight) {
                            table.GetRow(rowNumber).MaxHeights = computedRowHeight.Value;
                        }
                        else if (tableRowHeight != null && tableRowHeight < rowHeight)
                        {
                            tableRowHeight = (tableHeight - rowHeight - rowNumber * tableRowHeight)
                                    / (tableRows.Count - rowNumber - 1);
                        }
                    }
                    rowNumber++;
                }
                if (percentage) {
				    table.WidthPercentage = utils.ParsePxInCmMmPcToPt(widthValue);
				    table.LockedWidth = false;
			    }
                List<IElement> elems = new List<IElement>();
                if (invalidRowElements.Count > 0) {
                    // all invalid row elements taken as caption
                    int i = 0;
                    Tag captionTag = tag.Children[i++];
                    while (!Util.EqualsIgnoreCase(captionTag.Name, HTML.Tag.CAPTION) && i < tag.Children.Count) {
                        captionTag = tag.Children[i];
                        i++;
                    }
                    String captionSideValue;
                    captionTag.CSS.TryGetValue(CSS.Property.CAPTION_SIDE, out captionSideValue);
                    if (captionSideValue != null && Util.EqualsIgnoreCase(captionSideValue, CSS.Value.BOTTOM)) {
                        elems.Add(table);
                        elems.AddRange(invalidRowElements);
                    } else {
                        elems.AddRange(invalidRowElements);
                        elems.Add(table);
                    }
                } else {
                    elems.Add(table);
                }
                return elems;
            } catch (NoCustomContextException e) {
                throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e);
            }
        }
Esempio n. 20
0
        /// <summary>
        /// 貨運單  delivery_store=42 即 到店取貨 才須匯出貨運單
        /// </summary>
        public void GetShopbillsPDF()
        {
            string deliver_id = string.Empty;
            if (!string.IsNullOrEmpty(Request.Params["deliver_id"]))
            {
                deliver_id = Request.Params["deliver_id"];
            }
            string ticket_id = string.Empty;
            string fticket_id = string.Empty; ;
            if (!string.IsNullOrEmpty(Request.Params["ticket_id"]))
            {
                ticket_id = Request.Params["ticket_id"];
                ticket_id = ticket_id.Remove(ticket_id.LastIndexOf(','));
                string[] ticket_ids = ticket_id.Split(',');
                if (ticket_ids.Length > 0)
                {
                    fticket_id = ticket_ids[0];
                }
                else
                {
                    fticket_id = ticket_id;
                }

            }

            int i = 0;//用來計算表格數量,來分頁
            _DeliverDetailMgr = new DeliverDetailMgr(mySqlConnectionString);
            DataTable bills = _DeliverDetailMgr.GetWayBills(deliver_id, ticket_id);
            BaseFont bf = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bf, 8, iTextSharp.text.Font.UNDERLINE, iTextSharp.text.BaseColor.RED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
            string filename = string.Empty;
            if (string.IsNullOrEmpty(ticket_id))
            {
                filename = "shopbills_T" + deliver_id.PadLeft(8, '0') + ".pdf";
            }
            else
            {
                filename = "shopbills_T" + fticket_id.PadLeft(8, '0') + ".pdf";
            }
            Document document = new Document(PageSize.A4, (float)5, (float)5, (float)20, (float)0.5);
            string newPDFName = Server.MapPath(excelPath) + filename;
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPDFName, FileMode.Create));
            document.Open();
            #region 條形碼
            foreach (DataRow dr in bills.Rows)
            {
                #region 條形碼要顯示的內容
                string code1 = string.Empty;
                string csvuser = "******";
                string deliver_stno = dr["deliver_stno"].ToString();
                string delivercode = "0".PadLeft(11 - dr["deliver_id"].ToString().Length, '0');
                if (deliver_stno.Length >= 1)
                {
                    switch (deliver_stno.Substring(0, 1))
                    {
                        case "F":
                            code1 = "1" + csvuser + "00";
                            break;
                        case "K":
                            code1 = "3" + csvuser + "00";
                            break;
                        case "L":
                            code1 = "2" + csvuser + "00";
                            break;
                        default:
                            break;
                    }
                }
                code1 += delivercode + dr["deliver_id"].ToString();
                int checkcode = 0;
                for (int j = 0; j < code1.Length; j++)
                {
                    checkcode += int.Parse(code1.Substring(j, 1));
                }
                checkcode = checkcode % 43;
                string[] checkcodemap = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S",
			     "T","U","V","W","X","Y","Z","-",".","SP","$","/","+","%" };
                code1 += checkcodemap.GetValue(checkcode).ToString();

                string code2 = string.Empty;
                code2 = csvuser + delivercode.Substring(0, 3) + "963";
                string code3 = string.Empty;
                string nreceivable = string.Empty;
                string ndeliver_id = string.Empty;
                ndeliver_id = (delivercode + dr["deliver_id"].ToString()).Substring(3, 8);
                nreceivable = "0".PadLeft(5 - dr["receivable"].ToString().Length, '0') + dr["receivable"].ToString();
                if (dr["order_payment"].ToString() == "20")
                {
                    code3 = ndeliver_id + "1" + nreceivable;
                }
                else
                {
                    code3 = ndeliver_id + "3" + nreceivable;
                }
                int basenum = 0;//奇數
                int evennum = 0;//偶數
                for (int k = 0; k < code2.Length; k++)
                {
                    if ((k + 1) % 2 == 1)
                    {
                        basenum += int.Parse(code2.Substring(k, 1));
                    }
                    else
                    {
                        evennum += int.Parse(code2.Substring(k, 1));
                    }
                }
                for (int l = 0; l < code3.Length; l++)
                {
                    if ((l + 1) % 2 == 1)
                    {
                        basenum += int.Parse(code3.Substring(l, 1));
                    }
                    else
                    {
                        evennum += int.Parse(code3.Substring(l, 1));
                    }
                }
                basenum = basenum % 11;
                evennum = evennum % 11;
                if (basenum == 10)
                {
                    basenum = 1;
                }
                if (evennum == 10)
                {
                    evennum = 9;
                }
                else if (evennum == 0)
                {
                    evennum = 8;
                }
                code3 += basenum.ToString() + evennum.ToString();
                #endregion
                BarCode.Code128 _Code = new BarCode.Code128();
                _Code.ValueFont = new System.Drawing.Font("宋体", 20);
                System.Drawing.Bitmap imgTemp1 = _Code.GetCodeImage((!string.IsNullOrEmpty(dr["dcrono"].ToString())) ? dr["dcrono"].ToString() : "0", BarCode.Code128.Encode.Code128A);
                imgTemp1.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                iTextSharp.text.Image IMG1 = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG1.ScaleToFit(200, 30);

                Chunk ck1 = new Chunk(IMG1, 0, 0); //图片可设置 偏移


                _Code = new BarCode.Code128();
                //如果條形碼顯示的內容過長的話,一定要注意設置的字體大小,字體過大,內容不會顯示
                _Code.ValueFont = new System.Drawing.Font("宋体", 18);
                System.Drawing.Bitmap imgTemp2 = _Code.GetCodeImage(code1, BarCode.Code128.Encode.Code128A);
                imgTemp2.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                iTextSharp.text.Image IMG2 = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG2.ScaleToFit(200, 30);
                Chunk ck2 = new Chunk(IMG2, 0, 0); //图片可设置 偏移

                _Code = new BarCode.Code128();
                _Code.ValueFont = new System.Drawing.Font("宋体", 20);
                System.Drawing.Bitmap imgTemp3 = _Code.GetCodeImage(code2, BarCode.Code128.Encode.Code128A);
                imgTemp3.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                iTextSharp.text.Image IMG3 = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG3.ScaleToFit(200, 30);
                Chunk ck3 = new Chunk(IMG3, 0, 0); //图片可设置 偏移

                _Code = new BarCode.Code128();
                _Code.ValueFont = new System.Drawing.Font("宋体", 18);
                System.Drawing.Bitmap imgTemp4 = _Code.GetCodeImage(code3, BarCode.Code128.Encode.Code128A);
                imgTemp4.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
                iTextSharp.text.Image IMG4 = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
                IMG4.ScaleToFit(200, 30);
                Chunk ck4 = new Chunk(IMG4, 0, 0); //图片可设置 偏移


            #endregion
                if (i % 3 == 0 && i != 0)
                {
                    document.NewPage();
                }
                string stnm_1 = string.Empty;
                string stnm_2 = string.Empty;
                string stnm = dr["stnm"].ToString();
                if (dr["deliver_stno"].ToString().Length >= 1)
                {
                    switch (dr["deliver_stno"].ToString().Substring(0, 1))
                    {
                        case "F":
                            if (stnm.Length * 3 >= 6)
                            {
                                stnm_1 = stnm.Substring(0, 6 / 3);
                            }
                            else
                            {
                                stnm_1 = stnm.Substring(0, stnm.Length);
                            }
                            if (stnm.Length * 3 >= 40)
                            {
                                stnm_2 = stnm.Substring(6 / 3, 40 / 3);
                            }
                            else
                            {
                                if (stnm.Length * 3 >= 6)
                                {
                                    stnm_2 = stnm.Substring(6 / 3, stnm.Length - 6 / 3);
                                }
                            }
                            break;
                        case "K":
                            if (stnm.Length * 3 >= 4)
                            {
                                stnm_1 = stnm.Substring(0, 4 / 3);
                            }
                            else
                            {
                                stnm_1 = stnm.Substring(0, stnm.Length);
                            }
                            if (stnm.Length * 3 >= 40)
                            {
                                stnm_2 = stnm.Substring(2 / 3, 40 / 3);
                            }
                            else
                            {
                                if (stnm.Length * 3 > 2)
                                {
                                    stnm_2 = stnm.Substring(2 / 3, stnm.Length - 2 / 3);
                                }
                            }
                            break;
                        case "L":
                            if (stnm.Length * 3 >= 10)
                            {
                                stnm_1 = stnm.Substring(0, 10 / 3);
                            }
                            else
                            {
                                stnm_1 = stnm.Substring(0, stnm.Length);
                            }
                            if (stnm.Length * 3 >= 40)
                            {
                                stnm_2 = stnm.Substring(9 / 3, 40 / 3);
                            }
                            else
                            {
                                if (stnm.Length * 3 >= 9)
                                {
                                    stnm_2 = stnm.Substring(9 / 3, stnm.Length - 9 / 3);
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
                PdfPTable totaltable = new PdfPTable(3);
                totaltable.WidthPercentage = 100;
                totaltable.SetWidths(new int[] { 40, 2, 58 });
                PdfPTable table = new PdfPTable(3);
                #region 左邊框
                table.SetWidths(new int[] { 25, 15, 60 });
                table.DefaultCell.DisableBorderSide(1);
                table.DefaultCell.DisableBorderSide(2);
                table.DefaultCell.DisableBorderSide(4);
                table.DefaultCell.DisableBorderSide(8);
                PdfPCell cell;
                font = new iTextSharp.text.Font(bf, 14, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                cell = new PdfPCell(new PdfPCell(new Phrase(dr["dcrono"].ToString(), font)));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase("   提貨人:" + dr["delivery_name"].ToString(), font));
                cell.Colspan = 2;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(stnm_1 + "\n" + stnm_2, font));
                cell.Colspan = 2;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(ck1));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(ck2));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                //cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                cell.Colspan = 3;
                table.AddCell(cell);
                font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                cell = new PdfPCell(new Phrase("廠商出貨編號:" + dr["deliver_id"].ToString(), font));
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase("金額:" + dr["receivable"].ToString() + "元", font));
                cell.HorizontalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase("吉甲地在地好物 www.gigade100.com", font));
                cell.HorizontalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase("客服專線:(02) 2783-4997", font));
                cell.HorizontalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase("若需退貨請消費者聯繫上述電子商務網站\n\n\n\n\n\n", font));
                cell.HorizontalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                font = new iTextSharp.text.Font(bf, 14, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                cell = new PdfPCell(new PdfPCell(new Phrase("D10", font)));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                table.AddCell(cell);
                cell = new PdfPCell();
                cell.Colspan = 2;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                #endregion
                totaltable.AddCell(table);
                cell = new PdfPCell();
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(8);
                totaltable.AddCell(cell);
                #region 右邊
                table = new PdfPTable(6);
                table.SetWidths(new int[] { 20, 20, 37, 10, 1, 12 });
                table.DefaultCell.DisableBorderSide(1);
                table.DefaultCell.DisableBorderSide(2);
                table.DefaultCell.DisableBorderSide(4);
                table.DefaultCell.DisableBorderSide(8);
                table.DefaultCell.UseAscender = true;
                table.HorizontalAlignment = Element.ALIGN_CENTER;
                //table.AddCell(new Phrase(dr["order_payment"].ToString() == "20" ? "取貨付款" : "取貨不付款", font));
                cell = new PdfPCell(new PdfPCell(new Phrase(dr["order_payment"].ToString() == "20" ? " 取貨付款" : " 取貨不付款", font)));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new PdfPCell(new Phrase("D10", font)));
                //cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase());
                if (dr["order_payment"].ToString() == "20")
                {
                    cell.Rowspan = 6;
                }
                else
                {
                    cell.Rowspan = 7;
                }
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                string delivery_name = string.Empty;
                for (int k = 0; k < dr["delivery_name"].ToString().Length; k++)
                {
                    delivery_name += dr["delivery_name"].ToString()[k] + "\n";
                }
                cell = new PdfPCell(new Phrase("吉\n甲\n地\n\n" + delivery_name, font));
                if (dr["order_payment"].ToString() == "20")
                {
                    cell.Rowspan = 6;
                }
                else
                {
                    cell.Rowspan = 7;
                }
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                //cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(ck3));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                cell.Colspan = 5;
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(ck4));
                cell.UseAscender = true;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                cell.Colspan = 5;
                table.AddCell(cell);

                if (dr["order_payment"].ToString() == "20")
                {
                    font = new iTextSharp.text.Font(bf, 16, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑
                    Phrase p = new Phrase("*應付金額:" + dr["receivable"].ToString() + "元*\n\n", font);
                    font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑
                    p.Add(new Phrase("消費者簽名:____________________\n\n\n\n\n", font));
                    cell = new PdfPCell(p);
                    cell.Colspan = 5;
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    table.AddCell(cell);

                }
                else
                {
                    Phrase p = new Phrase();
                    font = new iTextSharp.text.Font(bf, 14, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑
                    p.Add(new Phrase(" *憑身分證件正本領貨*\n\n", font));
                    font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑
                    p.Add(new Phrase(" 消費者簽名:____________________\n\n", font));
                    p.Add(new Phrase(" 消費者身分證末四碼\n", font));
                    cell = new PdfPCell(p);
                    cell.Colspan = 5;
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    table.AddCell(cell);

                    PdfPTable stable = new PdfPTable(4);
                    stable.SetTotalWidth(new float[] { 20, 20, 20, 20 });
                    stable.DefaultCell.FixedHeight = 10;
                    stable.AddCell(new Phrase());
                    stable.AddCell(new Phrase());
                    stable.AddCell(new Phrase());
                    stable.AddCell(new Phrase());
                    //p.Add(new Phrase("請核對證件\n並  簽  名", font));
                    cell = new PdfPCell(stable);
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    table.AddCell(cell);
                    cell = new PdfPCell(new Phrase("請核對證件\n並  簽  名\n", font));
                    //cell.AddElement(new Phrase("請核對證件\n並  簽  名", font));
                    cell.Colspan = 4;
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    cell.UseAscender = true;
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.AddCell(cell);

                }
                font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑
                cell = new PdfPCell(new Phrase("\n門市結帳人員簽名:____________________", font));
                cell.Colspan = 5;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                table.AddCell(cell);
                string estimated_delivery_date = (!string.IsNullOrEmpty(dr["estimated_delivery_date"].ToString())) ? DateTime.Parse(dr["estimated_delivery_date"].ToString()).ToString("yyyy/MM/dd") : "";

                cell = new PdfPCell(new PdfPCell(new Phrase(dr["deliver_stno"].ToString(), font)));
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(cell);
                cell = new PdfPCell(new Phrase(" " + estimated_delivery_date, font));
                cell.Colspan = 2;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                //cell.HorizontalAlignment = Element.ALIGN_LEFT;
                table.AddCell(cell);
                cell = new PdfPCell(new PdfPCell(new Phrase(dr["dcrono"].ToString(), font)));
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(cell);
                table.AddCell("");
                //cell = new PdfPCell(new Phrase("11111111111", font));
                //cell.Colspan = 5;
                //table.AddCell(cell);

                totaltable.AddCell(table);
                totaltable.SpacingAfter = 25f;
                #endregion
                document.Add(totaltable);
            }


            document.Close();

            Response.Clear();
            Response.Charset = "gb2312";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            // Response.AddHeader("Content-Disposition", "attach-ment;filename=" + System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + ".pdf ");
            Response.AddHeader("Content-Disposition", "attach-ment;filename=" + filename);
            Response.WriteFile(newPDFName);


        }
Esempio n. 21
0
 // ---------------------------------------------------------------------------    
 /**
  * Creates a table; widths are set with setTotalWidth().
  * @return a PdfPTable
  */
 public static PdfPTable CreateTable5()
 {
     PdfPTable table = new PdfPTable(3);
     table.SetTotalWidth(new float[] { 144, 72, 72 });
     table.LockedWidth = true;
     PdfPCell cell;
     cell = new PdfPCell(new Phrase("Table 5"));
     cell.Colspan = 3;
     table.AddCell(cell);
     cell = new PdfPCell(new Phrase("Cell with rowspan 2"));
     cell.Rowspan = 2;
     table.AddCell(cell);
     table.AddCell("row 1; cell 1");
     table.AddCell("row 1; cell 2");
     table.AddCell("row 2; cell 1");
     table.AddCell("row 2; cell 2");
     return table;
 }
Esempio n. 22
0
        private void Pager(PdfPTable pdfPTable)
        {
            var writer = _pdfBuilder.writer;
            var Height = _pdfBuilder.Height;
            var document = _pdfBuilder.document;
            bool isfisrt = table.NextPageMarginPosition;
            var rowheight = pdfPTable.Rows[0].GetCells()[0].Height;
            var pageCount = (int)((Height - document.TopMargin - document.BottomMargin - table.Position.Y) / rowheight);
            float ylocal = Math.Abs(table.Position.Y - Height);
            var fillrow = pageCount + 1;
            while (true)
            {
                if (table.FillPage && pdfPTable.Rows.Count < fillrow)
                {
                    var count = fillrow - pdfPTable.Rows.Count;
                    if (count > 0)
                    {
                        FillTabel(count, pdfPTable);
                        pdfPTable.Complete = true;
                        pdfPTable.SetTotalWidth(headwidth);
                    }
                }
                pdfPTable.WriteSelectedRows(0, -1, 0, fillrow, table.Position.X, ylocal, writer.DirectContent, true);
                if (isfisrt)
                {
                    pageCount = (int)((Height - document.TopMargin - document.BottomMargin - 30) / rowheight);
                    fillrow = pageCount + 1;
                    var tmp = Height - document.TopMargin;
                    if (tmp > ylocal) ylocal = tmp;
                    isfisrt = false;
                }
                if (pdfPTable.Rows.Count > pageCount)
                {
                    pdfPTable.Rows.RemoveRange(1, pageCount);
                }
                else
                {
                    pdfPTable.Rows.RemoveRange(1, pdfPTable.Rows.Count - 1);
                }
                if (pdfPTable.Rows.Count <= 1) break;

                _pdfBuilder.NewPage();
            }
        }
        private static PdfGrid createFooter01(PagesFooterBuilder footer, string date, FooterData data)
        {
            string szMsg = "";
            Paragraph title = null;

            Font times01 = FontFactory.GetFont("helvetica-bold", 10, BaseColor.BLACK);
            Font times02 = FontFactory.GetFont("helvetica-bold", 10, Font.ITALIC, BaseColor.BLACK);
            Font times03 = FontFactory.GetFont("helvetica-bold", 10, Font.UNDERLINE, BaseColor.BLACK);
            Font times04 = FontFactory.GetFont("helvetica", 10, BaseColor.BLACK);
            Font times05 = FontFactory.GetFont("helvetica", 10, Font.UNDERLINE, BaseColor.BLACK);
            Font times06 = FontFactory.GetFont("helvetica", 8, BaseColor.BLACK);

            var table = new PdfGrid(numColumns: 4)
            {
                WidthPercentage = 100,
                RunDirection = PdfWriter.RUN_DIRECTION_LTR
            };

            PdfPCell nestingcell = null;
            PdfPCell hlpCel = null;

            //First Row Sales Amount
            PdfPTable nested = new PdfPTable(numColumns: 3);
            nested.SetTotalWidth(new float[] { 390.6f, 83.6f, 64.2f });
            nested.LockedWidth = true;

            szMsg = string.Format("Notes:");
            title = new Paragraph(szMsg, times06);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 4;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested.AddCell(hlpCel);

            szMsg = string.Format("Sales Amount:");
            title = new Paragraph(szMsg, times02);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 4;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested.AddCell(hlpCel);

            szMsg = string.Format("{0}", "96.85");
            title = new Paragraph(szMsg, times02);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 4;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_RIGHT;
            nested.AddCell(hlpCel);

            nestingcell = new PdfPCell(nested);
            nestingcell.Colspan = 4;
            nestingcell.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            nestingcell.BorderWidthLeft = 0;
            nestingcell.BorderWidthRight = 0;
            nestingcell.BorderWidthTop = 0;
            nestingcell.BorderWidthBottom = 0;
            nestingcell.Padding = 0;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            nestingcell.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(nestingcell);

            //Second Row Sales Amount
            PdfPTable nested01 = new PdfPTable(numColumns: 2);
            nested01.SetTotalWidth(new float[] { 390.6f, 147.8f });
            nested01.LockedWidth = true;

            szMsg = string.Format("{0}", "The note goes here !! (Use 4 rows)");
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested01.AddCell(hlpCel);

            PdfPTable nested02 = new PdfPTable(numColumns: 2);
            nested02.SetTotalWidth(new float[] { 83.6f, 64.2f });
            nested02.LockedWidth = true;

            szMsg = string.Format("Tax {0} %:", " ");
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested02.AddCell(hlpCel);

            szMsg = string.Format("{0}", "0.00");
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_RIGHT;
            nested02.AddCell(hlpCel);

            szMsg = string.Format("Shipping & Handling:", " ");
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested02.AddCell(hlpCel);

            szMsg = string.Format("{0}", "21.00");
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_RIGHT;
            nested02.AddCell(hlpCel);

            hlpCel = new PdfPCell(nested02);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_CENTER;
            nested01.AddCell(hlpCel);

            nestingcell = new PdfPCell(nested01);
            nestingcell.Colspan = 4;
            nestingcell.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            nestingcell.BorderWidthLeft = 0;
            nestingcell.BorderWidthRight = 0;
            nestingcell.BorderWidthTop = 0;
            nestingcell.BorderWidthBottom = 0;
            nestingcell.Padding = 0;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            nestingcell.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(nestingcell);

            //Page counter
            var datePhrase = footer.PdfFont.FontSelector.Process(date);
            var datePhrase01 = footer.PdfFont.FontSelector.Process(" ");
            var datePdfCell = new PdfPCell(datePhrase01)
            {
                RunDirection = PdfWriter.RUN_DIRECTION_LTR,
                BorderWidthLeft = 0,
                BorderWidthRight = 0,
                BorderWidthTop = 1,
                BorderWidthBottom = 0,
                Padding = 4,
                BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
                HorizontalAlignment = Element.ALIGN_CENTER
            };

            var nullPdfCell = new PdfPCell
            {
                RunDirection = PdfWriter.RUN_DIRECTION_LTR,
                BorderWidthLeft = 0,
                BorderWidthRight = 0,
                BorderWidthTop = 1,
                BorderWidthBottom = 0,
                Padding = 4,
                BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
                HorizontalAlignment = Element.ALIGN_RIGHT
            };

            var pageNumberPhrase = footer.PdfFont.FontSelector.Process("Page " + data.CurrentPageNumber + " of ");
            var pageNumberPdfCell = new PdfPCell(pageNumberPhrase)
            {
                RunDirection = PdfWriter.RUN_DIRECTION_LTR,
                BorderWidthLeft = 0,
                BorderWidthRight = 0,
                BorderWidthTop = 1,
                BorderWidthBottom = 0,
                Padding = 4,
                BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
                HorizontalAlignment = Element.ALIGN_RIGHT
            };

            var totalPagesNumberImagePdfCell = new PdfPCell(data.TotalPagesCountImage)
            {
                RunDirection = PdfWriter.RUN_DIRECTION_LTR,
                BorderWidthLeft = 0,
                BorderWidthRight = 0,
                BorderWidthTop = 1,
                BorderWidthBottom = 0,
                Padding = 4,
                PaddingLeft = 0,
                BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
                HorizontalAlignment = Element.ALIGN_LEFT
            };

            table.AddCell(datePdfCell);
            table.AddCell(nullPdfCell);
            table.AddCell(pageNumberPdfCell);
            table.AddCell(totalPagesNumberImagePdfCell);
            return table;
        }
        private PdfGrid createPOHeader(PagesHeaderBuilder header, int purchaseorderId)
        {
            int nTradeId = 0;
            string szMsg = "";
            string szAddress = "";
            string szCity = "";
            string szState = "";
            string szZip = "";
            string szCountry = "";
            string szTel = "";
            string szFax = "";
            string szWebSiteTrade = "";
            string szEmailTrade = "";
            string szTradeName = "";
            string szAsiTrade = "";
            string szSageTrade = "";
            string szPpaiTrade = "";

            string szPODate = "";
            string szPORef = "";
            string szPONo = "";
            string szPOShipDate = "";
            string szPOBy = "";
            string szPOBlindDrop = "";

            string szVendorCompanyName = "";
            string szVendorFirstName = "";
            string szVendorLastName = "";
            string szVendorTitle = "";
            string szVendorAddress1 = "";
            string szVendorAddress2 = "";
            string szVendorAddress3 = "";
            string szVendorCity = "";
            string szVendorState = "";
            string szVendorZip = "";
            string szVendorCountry = "";
            string szVendorTel = "";
            string szVendorFax = "";
            string szVendorEmail = "";
            string szVendorWebsite = "";
            string szVendorTel1 = "";
            string szVendorTel2 = "";

            long telHlp = 0;
            long faxHlp = 0;
            string telfmt = "000-000-0000";

            DateTime dDate = DateTime.Now;

            //The report data
            PurchaseOrders purchaseorder = db.PurchaseOrders.Find(purchaseorderId);
            if (purchaseorder != null)
            {
                nTradeId = Convert.ToInt32(purchaseorder.TradeId);
                dDate = Convert.ToDateTime(purchaseorder.PODate);
                szPODate = dDate.ToString("MM/dd/yyyy");
                szPORef = purchaseorder.PurchaseOrderReference;
                szPONo = purchaseorder.PurchaseOrderNo;
                szPOBy = purchaseorder.PaidBy;
                szPOBlindDrop = purchaseorder.BlindDrop;
                if (purchaseorder.ShipDate == null)
                {
                    szPOShipDate = string.Empty;
                }
                else
                {
                    dDate = Convert.ToDateTime(purchaseorder.ShipDate);
                    szPOShipDate = dDate.ToString("MM/dd/yyyy");

                }
            }
            TimelyDepotMVC.Controllers.SalesOrderController.GetTradeData(db, ref szAddress, ref szCity, ref szState, ref szZip, ref szCountry, ref szTel, ref szFax,
                ref szWebSiteTrade, ref szEmailTrade, ref szTradeName, ref szAsiTrade, ref szSageTrade, ref szPpaiTrade, nTradeId);
            if (string.IsNullOrEmpty(szTel))
            {
                szTel = "0";
            }
            if (string.IsNullOrEmpty(szFax))
            {
                szFax = "0";
            }

            telHlp = Convert.ToInt64(szTel);
            szTel = telHlp.ToString(telfmt);
            telHlp = Convert.ToInt64(szFax);
            szFax = telHlp.ToString(telfmt);

            TimelyDepotMVC.Controllers.PurchaseOrderController.GetVendorData(db, purchaseorder.VendorId, ref szVendorCompanyName, ref szVendorFirstName, ref szVendorLastName,
                ref szVendorTitle, ref szVendorAddress1, ref szVendorAddress2, ref szVendorAddress3, ref szVendorCity, ref szVendorState, ref szVendorZip, ref szVendorCountry,
                ref szVendorTel, ref szVendorFax, ref szVendorEmail, ref szVendorWebsite, ref szVendorTel1, ref szVendorTel2);
            if (string.IsNullOrEmpty(szVendorTel1))
            {
                szVendorTel1 = "0";
            }
            if (string.IsNullOrEmpty(szVendorTel2))
            {
                szVendorTel2 = "0";
            }
            if (string.IsNullOrEmpty(szVendorTel))
            {
                szVendorTel = "0";
            }

            telHlp = Convert.ToInt64(szVendorTel1);
            szVendorTel1 = telHlp.ToString(telfmt);
            telHlp = Convert.ToInt64(szVendorTel2);
            szVendorTel2 = telHlp.ToString(telfmt);
            telHlp = Convert.ToInt64(szVendorTel);
            szVendorTel = telHlp.ToString(telfmt);

            //The report layout
            Font times01 = FontFactory.GetFont("helvetica-bold", 12, BaseColor.BLACK);
            Font times02 = FontFactory.GetFont("helvetica-bold", 12, Font.ITALIC, BaseColor.BLACK);
            Font times03 = FontFactory.GetFont("helvetica-bold", 12, Font.UNDERLINE, BaseColor.BLACK);
            Font times04 = FontFactory.GetFont("helvetica", 12, BaseColor.BLACK);
            Font times05 = FontFactory.GetFont("helvetica", 12, Font.UNDERLINE, BaseColor.BLACK);
            Font times06 = FontFactory.GetFont("helvetica", 10, BaseColor.BLACK);
            Font times07 = FontFactory.GetFont("helvetica", 12, Font.ITALIC, BaseColor.BLACK);
            Font times08 = FontFactory.GetFont("helvetica-bold", 16, BaseColor.BLACK);

            PdfPCell nestingcell = null;
            PdfPCell hlpCel = null;
            Paragraph title = null;

            //Create the table for the headr
            var table = new PdfGrid(numColumns: 1);
            table.SetTotalWidth(new float[] { 553f });
            table.LockedWidth = true;
            table.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            table.SpacingAfter = 7;

            szMsg = string.Format("{0}", szTradeName);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 4;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(hlpCel);

            szMsg = string.Format("{0}", szAddress);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(hlpCel);

            szMsg = string.Format("{0}, {1} {2}", szCity, szState, szZip);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(hlpCel);

            szMsg = string.Format("Tel: {0}", szTel);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(hlpCel);

            szMsg = string.Format("Fax: {0}", szFax);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(hlpCel);

            szMsg = string.Format("Email: {0}", szEmailTrade);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(hlpCel);

            //
            szMsg = string.Format("{0}", szPODate);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidthLeft = 0;
            hlpCel.BorderWidthRight = 0;
            hlpCel.BorderWidthTop = 0;
            hlpCel.BorderWidthBottom = 0;
            hlpCel.PaddingTop = 10;
            hlpCel.PaddingLeft = 0;
            hlpCel.PaddingRight = 0;
            hlpCel.PaddingBottom = 1;
            //BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(hlpCel);

            PdfPTable nested = new PdfPTable(2);
            nested.SetTotalWidth(new float[] { 332f, 221f });
            nested.LockedWidth = true;

            szMsg = string.Format("Attn: {0} {1}", szVendorFirstName, szVendorLastName);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidth = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 4;
            hlpCel.PaddingRight = 1;
            hlpCel.PaddingBottom = 1;
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested.AddCell(hlpCel);

            szMsg = string.Format("Ref: {0}", szPORef);
            title = new Paragraph(szMsg, times08);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidth = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 4;
            hlpCel.PaddingRight = 1;
            hlpCel.PaddingBottom = 1;
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested.AddCell(hlpCel);

            szMsg = string.Format("{0}", szVendorCompanyName.ToUpper());
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidth = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 4;
            hlpCel.PaddingRight = 1;
            hlpCel.PaddingBottom = 1;
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested.AddCell(hlpCel);

            szMsg = string.Format("Purchase Order No.: {0}", szPONo);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidth = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 4;
            hlpCel.PaddingRight = 1;
            hlpCel.PaddingBottom = 1;
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            nested.AddCell(hlpCel);

            PdfPCell nesthousing = new PdfPCell(nested);
            nesthousing.BorderWidth = 0;
            nesthousing.Padding = 0f;
            table.AddCell(nesthousing);

            szMsg = string.Format("{0} {1} {2}", szVendorAddress1, szVendorAddress2, szVendorAddress3);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidth = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 4;
            hlpCel.PaddingRight = 1;
            hlpCel.PaddingBottom = 1;
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(hlpCel);

            szMsg = string.Format("{0}, {1} {2}", szVendorCity, szVendorState, szVendorZip);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidth = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 4;
            hlpCel.PaddingRight = 1;
            hlpCel.PaddingBottom = 1;
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(hlpCel);

            szMsg = string.Format("Tel: {0} {1} {2}", szVendorTel1, szVendorTel2, szVendorTel);
            title = new Paragraph(szMsg, times04);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidth = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 4;
            hlpCel.PaddingRight = 1;
            hlpCel.PaddingBottom = 1;
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(hlpCel);

            szMsg = string.Format("Ship date: {0}", szPOShipDate);
            title = new Paragraph(szMsg, times01);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidth = 0;
            hlpCel.PaddingTop = 20;
            hlpCel.PaddingLeft = 4;
            hlpCel.PaddingRight = 1;
            hlpCel.PaddingBottom = 1;
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(hlpCel);

            szMsg = string.Format("By: {0}", szPOBy);
            title = new Paragraph(szMsg, times01);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidth = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 4;
            hlpCel.PaddingRight = 1;
            hlpCel.PaddingBottom = 1;
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(hlpCel);

            szMsg = string.Format("Blind Drop by: {0}", szPOBlindDrop);
            title = new Paragraph(szMsg, times01);
            hlpCel = new PdfPCell(title);
            hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpCel.BorderWidth = 0;
            hlpCel.PaddingTop = 1;
            hlpCel.PaddingLeft = 4;
            hlpCel.PaddingRight = 1;
            hlpCel.PaddingBottom = 6;
            hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(hlpCel);

            return table;
        }
Esempio n. 25
0
		public void ConstruirTablaItems(Document document, List<PedidoItem> items){


			List<string> itemHeaders= new List<string>(new string[]{
				"Descripción","Días","Ctd","Precio Unit",
				"Dscnt %","Precio Con Dscnt","IVA","Procedimiento"
			});

			//var grupos = from p in items group p by p.NombreServicio ;

			var unifont10= FontFactory.GetFont(FontFamilyName,BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
			unifont10.Size=10;

			var unifont8= FontFactory.GetFont(FontFamilyName,BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
			unifont8.Size=8;

			var unifont7= FontFactory.GetFont(FontFamilyName,BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
			unifont7.Size=7;

			//foreach(var grupo in grupos){

				PdfPTable  itemTable = new PdfPTable(8);
				itemTable.WidthPercentage=95;
				itemTable.SetTotalWidth(new float[]{4,0.4f,0.4f,0.9f,0.5f,0.95f,0.75f,5});

				//var cell = new PdfPCell(new Phrase(grupo.Key, unifont10 ));
				//cell.Colspan = 8;
				//itemTable.AddCell(cell);
				PdfPCell cell;

				foreach(var header in itemHeaders){
					cell = new PdfPCell(new Phrase(header,unifont8));
					cell.HorizontalAlignment = Element.ALIGN_CENTER;
					itemTable.AddCell(cell);
				}

				itemTable.HeaderRows=1;

				foreach(var item in items){

					cell = new PdfPCell(new Phrase(string.Concat(item.NombreServicio,". ", item.Descripcion.Decode(),
					              item.Nota.IsNullOrEmpty()?"": "\r\nNota:"+item.Nota.Decode() ),unifont8 ));
					itemTable.AddCell(cell);

					cell = new PdfPCell(new Phrase(item.DiasEntrega.ToString(), unifont8));
					cell.HorizontalAlignment = Element.ALIGN_CENTER;
					itemTable.AddCell(cell);

					cell = new PdfPCell(new Phrase(item.Cantidad.ToString(), unifont8));
					cell.HorizontalAlignment = Element.ALIGN_CENTER;
					itemTable.AddCell(cell);

					cell = new PdfPCell(new Phrase(string.Format("{0:##,0}", item.CostoUnitario),unifont8));
					cell.HorizontalAlignment = Element.ALIGN_RIGHT;
					itemTable.AddCell(cell);

					cell = new PdfPCell(new Phrase(string.Format("{0:##,0}", item.Descuento),unifont8));
					cell.HorizontalAlignment = Element.ALIGN_CENTER;
					itemTable.AddCell(cell);

					cell = new PdfPCell(new Phrase(string.Format("{0:##,0}", item.CostoInversion),unifont8));
					cell.HorizontalAlignment = Element.ALIGN_RIGHT;
					itemTable.AddCell(cell);

					cell = new PdfPCell(new Phrase(string.Format("{0:##,0}", item.ValorIva),unifont8));
					cell.HorizontalAlignment = Element.ALIGN_RIGHT;
					itemTable.AddCell(cell);

					cell = new PdfPCell(new Phrase(item.DescripcionProcedimiento,unifont7));
					cell.HorizontalAlignment=Element.ALIGN_JUSTIFIED;
					itemTable.AddCell(cell);

				}

				document.Add(itemTable);
			//}
		}
Esempio n. 26
0
        public static PdfPTable CreateTable(float[] columnWidths, int border)
        {
            const string METHOD_NAME = "CreateTable";

            try {

                float sumWidths = 0;
                foreach (float w in columnWidths) {
                    sumWidths += w;
                }

                PdfPTable table = new PdfPTable(columnWidths.Length);
                table.DefaultCell.Border = border;

                if (Math.Round(sumWidths, 0) != 100) {
                    table.SetTotalWidth(columnWidths);
                    table.LockedWidth = true;
                } else {
                    table.SetWidths(columnWidths);
                    table.WidthPercentage = 100;
                }

                return table;

            }
            catch (Exception ex) {
                ApplicationException aex = new ApplicationException(MOD_NAME + METHOD_NAME, ex);
                throw (aex);
            }
        }
Esempio n. 27
0
        /// <summary>
        /// 匯出pdf文檔
        /// </summary>
        //public void WritePdf()
        //{
        //    string newName = string.Empty;
        //    string json = string.Empty;
        //    IpodQuery ipod = new IpodQuery();
        //    IpoQuery ipo = new IpoQuery();

        //    if (!string.IsNullOrEmpty(Request.Params["Poid"]))
        //    {
        //        ipo.po_id = Request.Params["Poid"];
        //    }
        //    if (!string.IsNullOrEmpty(Request.Params["Potype"]))
        //    {
        //        ipo.po_type = Request.Params["Potype"];
        //    }
        //    List<IpodQuery> ipodStore = new List<IpodQuery>();
        //    List<IpoQuery> ipoStore = new List<IpoQuery>();
        //    _ipoMgr = new IpoMgr(mySqlConnectionString);
        //    int totalCount = 0;
        //    ipo.IsPage = false;
        //    ipoStore = _ipoMgr.GetIpoList(ipo, out  totalCount);
        //    try
        //    {
        //        #region 採購單匯出

        //        BaseFont bf = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
        //        iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bf, 8, iTextSharp.text.Font.UNDERLINE, iTextSharp.text.BaseColor.RED);
        //        iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
        //        string filename = "採購單"+ DateTime.Now.ToString("yyyyMMddHHmmss") +".pdf";
        //        Document document = new Document(PageSize.A4, (float)5, (float)5, (float)20, (float)0.5);
        //        string newPDFName = Server.MapPath(excelPath) + filename;
        //        PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPDFName, FileMode.Create));
        //        document.Open();
        //        //運送方式

        //           _paraMgr = new ParameterMgr(mySqlConnectionString);
        //        List<Parametersrc> parameterStore = new List<Parametersrc>();


        //        parameterStore = _paraMgr.GetElementType("product_freight");

        //        for (int a = 0; a < ipoStore.Count; a++)//循環單頭
        //        {
        //            //GetIpodListExprot
        //            _ipodMgr = new IpodMgr(mySqlConnectionString);
        //            ipod = new IpodQuery();
        //            ipod.po_id = ipoStore[a].po_id;
        //            ipodStore = new List<IpodQuery>();
        //            ipodStore = _ipodMgr.GetIpodListExprot(ipod);
        //            Dictionary<int, List<IpodQuery>> product_freight_set_mapping = new Dictionary<int, List<IpodQuery>>();
        //            #region 通過運送方式把採購單分開--一張採購單,分成常溫,冷凍等採購單


        //            for (int i = 0; i < ipodStore.Count; i++)//通過運送方式保存到字典里
        //            {
        //                ipodStore[i].spec = GetProductSpec(ipodStore[i].item_id.ToString());
        //                IupcQuery upc = new IupcQuery();
        //                upc.item_id = ipodStore[i].item_id;
        //                List<IupcQuery> upcStore = new List<IupcQuery>();
        //                _IiupcMgr = new IupcMgr(mySqlConnectionString);
        //                upcStore = _IiupcMgr.GetIupcByItemID(upc);
        //                if (upcStore.Count > 0)
        //                {
        //                    ipodStore[i].upc_id = upcStore[0].upc_id;
        //                }
        //                int freiset = ipodStore[i].product_freight_set;
        //                if (!product_freight_set_mapping.Keys.Contains(freiset))
        //                {
        //                    List<IpodQuery> s = new List<IpodQuery>();
        //                    product_freight_set_mapping.Add(freiset, s);
        //                }
        //                product_freight_set_mapping[freiset].Add(ipodStore[i]);
        //            }
        //            #endregion

        //            #region 針對匯出一個而無商品的pdf


        //            if (ipodStore.Count == 0)
        //            {

        //                #region 獲取供應商信息

        //                Vendor vendor = new Vendor();
        //                _vendorMgr = new VendorMgr(mySqlConnectionString);

        //                vendor.erp_id = ipoStore[a].vend_id;
        //                vendor = _vendorMgr.GetSingle(vendor);
        //                #endregion
        //                #region 採購單標題


        //                PdfContentByte cb = writer.DirectContent;
        //                cb.BeginText();
        //                cb.SetFontAndSize(bf, 15);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "吉甲地好市集股份有限公司", 220, 790, 0);
        //                font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
        //                cb.SetFontAndSize(bf, 12);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "採購單" + "-" + ipoStore[a].po_type_desc, 280, 770, 0);
        //                cb.SetFontAndSize(bf, 8);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "公司電話:", 60, 760, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "公司傳真:", 470, 760, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "製造日期:" + DateTime.Now.ToString("yyyy/MM/dd"), 60, 750, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "頁", 510, 750, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "次", 530, 750, 0);
        //                #endregion

        //                PdfPTable ptable = new PdfPTable(6);

        //                ptable.WidthPercentage = 150;//表格寬度
        //                font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
        //                ptable.SetTotalWidth(new float[] { 82, 50, 100, 90, 110, 71 });
        //                PdfPCell cell = new PdfPCell();
        //                cell.UseAscender = true;
        //                cell.HorizontalAlignment = Element.ALIGN_CENTER;//字體垂直居中
        //                cell.VerticalAlignment = Element.ALIGN_MIDDLE;//字體水平居中
        //                cell.BorderWidth = 0.1f;
        //                cell.BorderColor = new BaseColor(0, 0, 0);

        //                #region 上部分


        //                cell = new PdfPCell(new Phrase("採購單別:" + ipoStore[a].po_type, font));
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("交易幣別:" + "世界貨幣", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("匯率:" + "浮動", font));
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("運輸方式:" , font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);


        //                cell = new PdfPCell(new Phrase("商品是新品么?:", font));//新品
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("所在層:", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("採購單(" + ipoStore[a].po_type_desc + ")", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("預約到貨日期:", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);



        //                cell = new PdfPCell(new Phrase("採購單號:" + ipoStore[a].po_id, font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("課稅別:", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("營業稅率:", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("價格條件:", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);



        //                cell = new PdfPCell(new Phrase("單據日期:" + DateTime.Now.ToString("yyyy/MM/dd"), font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("採購人員:" + ipoStore[a].buyer, font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase((System.Web.HttpContext.Current.Session["caller"] as Caller).user_username, font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("廠別代號:", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("gigade(讀取)", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);



        //                cell = new PdfPCell(new Phrase("廠商代號:" + ipoStore[a].vend_id, font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("付款條件(讀取)", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("月結N天(讀取):", font));


        //                cell.Colspan = 3;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("廠商全名(讀取):" , font));
        //                cell.Colspan = 4;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("備註:", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);


        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("廠商地址:", font));
        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);


        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(" ", font));
        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);


        //                cell = new PdfPCell(new Phrase("聯絡人(讀取):", font));
        //                cell.Colspan = 2;

        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("廠商電話:" , font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("廠商傳真:" , font));


        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("送貨地址(讀取):", font));



        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(" ", font));




        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("預計送貨日期(讀取):", font));




        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("配送聯絡人(讀取):", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("配送電話(讀取):", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("配送傳真(讀取):", font));


        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("處理備註:", font));


        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("運送備註:", font));
        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);

        //                ptable.AddCell(cell);
        //                #endregion

        //                ptable.WriteSelectedRows(0, -1, 46, 740, writer.DirectContent);//顯示的開始行,結束航(-1為所有)x坐標,y坐標
        //                PdfPTable nulltable = new PdfPTable(2);
        //                nulltable.SetWidths(new int[] { 20, 20 });
        //                nulltable.DefaultCell.DisableBorderSide(1);
        //                nulltable.DefaultCell.DisableBorderSide(2);
        //                nulltable.DefaultCell.DisableBorderSide(4);
        //                nulltable.DefaultCell.DisableBorderSide(8);
        //                nulltable.AddCell("");
        //                nulltable.AddCell("");
        //                nulltable.SpacingAfter = 292;
        //                document.Add(nulltable);
        //                ptable = new PdfPTable(6);
        //                ptable.WidthPercentage = 86;//表格寬度
        //                font = new iTextSharp.text.Font(bf, 9, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
        //                ptable.SetTotalWidth(new float[] { 90, 130, 50, 50, 60, 120 });
        //                cell = new PdfPCell(new Phrase("此採購單商品不存在!", font));


        //                cell.Colspan = 6;

        //                ptable.AddCell(cell);
        //                cb.EndText();
        //                document.Add(ptable);
        //                document.NewPage();


        //            }
        //            #endregion

        //            foreach (int key in product_freight_set_mapping.Keys)
        //            {
        //                #region 取出運送方式
        //                string procduct_freight = "";
        //                for (int i = 0; i < parameterStore.Count; i++)
        //                {
        //                    if (key.ToString() == parameterStore[i].ParameterCode)
        //                    {
        //                        procduct_freight = parameterStore[i].parameterName;
        //                    }
        //                }
        //                #endregion

        //                #region 獲取供應商信息

        //               Vendor vendor = new Vendor();
        //               _vendorMgr = new VendorMgr(mySqlConnectionString);

        //               vendor.erp_id = ipoStore[a].vend_id;
        //               vendor = _vendorMgr.GetSingle(vendor);
        //                #endregion
        //                #region 採購單標題


        //                PdfContentByte cb = writer.DirectContent;
        //                cb.BeginText();
        //                cb.SetFontAndSize(bf, 15);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "吉甲地好市集股份有限公司", 220, 790, 0);
        //                font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
        //                cb.SetFontAndSize(bf, 12);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "採購單" + "-" + ipoStore[a].po_type_desc, 280, 770, 0);
        //                cb.SetFontAndSize(bf, 8);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "公司電話:", 60, 760, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "公司傳真:", 470, 760, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "製造日期:" + DateTime.Now.ToString("yyyy/MM/dd"), 60, 750, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "頁", 510, 750, 0);
        //                cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "次", 530, 750, 0);
        //               #endregion

        //                PdfPTable ptable = new PdfPTable(6);

        //                ptable.WidthPercentage = 150;//表格寬度
        //                font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
        //                ptable.SetTotalWidth(new float[] { 82, 50, 100, 90, 110, 71 });
        //                PdfPCell cell = new PdfPCell();
        //                cell.UseAscender = true;
        //                cell.HorizontalAlignment = Element.ALIGN_CENTER;//字體垂直居中
        //                cell.VerticalAlignment = Element.ALIGN_MIDDLE;//字體水平居中
        //                cell.BorderWidth = 0.1f;
        //                cell.BorderColor = new BaseColor(0, 0, 0);


        //                #region 上部分


        //                cell = new PdfPCell(new Phrase("採購單別:" + ipoStore[a].po_type, font));
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("交易幣別:" + "世界貨幣", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("匯率:" + "浮動", font));
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("運輸方式:" + procduct_freight, font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);


        //                cell = new PdfPCell(new Phrase("商品是新品么?:", font));//新品
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("所在層:", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("採購單(" + ipoStore[a].po_type_desc + ")", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("預約到貨日期:", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);



        //                cell = new PdfPCell(new Phrase("採購單號:" + ipoStore[a].po_id, font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("課稅別:", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("營業稅率:", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("價格條件:", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);



        //                cell = new PdfPCell(new Phrase("單據日期:" + DateTime.Now.ToString("yyyy/MM/dd"), font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("採購人員:" + ipoStore[a].buyer, font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase((System.Web.HttpContext.Current.Session["caller"] as Caller).user_username, font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("廠別代號:" , font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("gigade(讀取)", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);



        //                cell = new PdfPCell(new Phrase("廠商代號:" + ipoStore[a].vend_id, font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(vendor == null ? "暫無此信息" : vendor.vendor_name_simple, font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("付款條件(讀取)", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("月結N天(讀取):", font));


        //                cell.Colspan = 3;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(vendor == null ? "廠商全名(讀取):暫無此信息" :"廠商全名:"+ vendor.vendor_name_full, font));
        //                cell.Colspan = 4;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("備註:", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);


        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(vendor == null ? "廠商地址:暫無此信息" : "廠商地址:"+vendor.company_address, font));
        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);


        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(" ", font));
        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);


        //                cell = new PdfPCell(new Phrase("聯絡人(讀取):", font));
        //                cell.Colspan = 2;

        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(vendor == null?"廠商電話:暫無此信息" :"廠商電話:"+ vendor.company_phone, font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(vendor == null? "廠商傳真:暫無此信息" :"廠商傳真:"+ vendor.company_fax, font));


        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("送貨地址(讀取):", font));



        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase(" ", font));




        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("預計送貨日期(讀取):", font));




        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("配送聯絡人(讀取):", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("配送電話(讀取):", font));
        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                cell.DisableBorderSide(8);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("配送傳真(讀取):", font));


        //                cell.Colspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("處理備註:", font));


        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("運送備註:", font));
        //                cell.Colspan = 6;
        //                cell.DisableBorderSide(1);

        //                ptable.AddCell(cell);
        //                #endregion


        //                ptable.WriteSelectedRows(0, -1, 46, 740, writer.DirectContent);//顯示的開始行,結束航(-1為所有)x坐標,y坐標
        //                PdfPTable nulltable = new PdfPTable(2);
        //                nulltable.SetWidths(new int[] { 20, 20 });
        //                nulltable.DefaultCell.DisableBorderSide(1);
        //                nulltable.DefaultCell.DisableBorderSide(2);
        //                nulltable.DefaultCell.DisableBorderSide(4);
        //                nulltable.DefaultCell.DisableBorderSide(8);
        //                nulltable.AddCell("");
        //                nulltable.AddCell("");
        //                nulltable.SpacingAfter = 292;
        //                document.Add(nulltable);
        //                ptable = new PdfPTable(6);
        //                ptable.WidthPercentage = 86;//表格寬度
        //                font = new iTextSharp.text.Font(bf, 9, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
        //                ptable.SetTotalWidth(new float[] { 90, 130, 50, 50, 60, 120 });
        //                #region 下面表格頭部

        //                cell = new PdfPCell(new Phrase("條碼", font));
        //                cell.Rowspan = 2;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("品號", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("採購數量", font));
        //                cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("允收天數", font));
        //                cell.HorizontalAlignment = Element.ALIGN_RIGHT;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("製造日期", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("備註", font));
        //                cell.Rowspan = 3;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);




        //                cell = new PdfPCell(new Phrase("品名", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("允收數量", font));
        //                cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("允出天數", font));
        //                cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(2);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("有效日期", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(4);
        //                cell.Rowspan = 2;
        //                ptable.AddCell(cell);



        //                cell = new PdfPCell(new Phrase("料位", font));
        //                cell.DisableBorderSide(1);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("規格", font));
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("不允收數量", font));
        //                cell.HorizontalAlignment = Element.ALIGN_RIGHT;
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);
        //                cell = new PdfPCell(new Phrase("有效期天數", font));
        //                cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                cell.DisableBorderSide(1);
        //                cell.DisableBorderSide(4);
        //                ptable.AddCell(cell);


        //                #endregion
        //                _ipodMgr = new IpodMgr(mySqlConnectionString);
        //                ipod = new IpodQuery();
        //                ipod.po_id = ipoStore[a].po_id;
        //                ipod.IsPage = false;
        //                ipodStore = new List<IpodQuery>();
        //                ipodStore = _ipodMgr.GetIpodList(ipod, out totalCount);


        //                List<IpodQuery> Ipodleibie = new List<IpodQuery>();
        //                Ipodleibie.AddRange(product_freight_set_mapping[key]);

        //                #region 循環讀取數據填入表格


        //                for (int i = 0; i < Ipodleibie.Count; i++)
        //                {
        //                    //string sResult = "";
        //                    //if (ipodStore[i].pod_id.ToString().Length < 4)
        //                    //{
        //                    //    for (int n = 0; n < 4 - (ipodStore[i].pod_id.ToString().Length); n++)
        //                    //    {
        //                    //        sResult += "0";
        //                    //    }

        //                    //}
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].upc_id, font));//條碼
        //                    cell.Rowspan = 2;
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].Erp_Id.ToString(), font));//品號
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].qty_ord.ToString(), font));//採購數量qty_ord
        //                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].cde_dt_var.ToString(), font));//允收天數cde_dt_var
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    cell.DisableBorderSide(4);
        //                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase("", font));//製造日期
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase("", font));//備註
        //                    cell.Rowspan = 3;
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);




        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].product_name, font));//品名
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].qty_claimed.ToString(), font));//允收數量
        //                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].cde_dt_shp.ToString(), font));//允出天數
        //                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;//.setHorizontalAlignment(Element.ALIGN_CENTER);
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(2);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase("", font));//有效日期
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(4);
        //                    cell.Rowspan = 2;
        //                    ptable.AddCell(cell);



        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].loc_id, font));//料位
        //                    cell.DisableBorderSide(1);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].spec, font));//規格
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].qty_damaged.ToString(), font));//不允收數量
        //                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                    cell = new PdfPCell(new Phrase(Ipodleibie[i].cde_dt_incr.ToString(), font));//有效期天數
        //                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
        //                    cell.DisableBorderSide(1);
        //                    cell.DisableBorderSide(4);
        //                    ptable.AddCell(cell);
        //                }
        //                #endregion

        //                //cell = new PdfPCell(new Phrase(" 數量合計:" + 5, font));
        //                //cell.Colspan = 2;

        //                //cell.DisableBorderSide(1);

        //                //cell.DisableBorderSide(8);
        //                //cell.HorizontalAlignment = Element.ALIGN_CENTER;
        //                //ptable.AddCell(cell);
        //                //cell = new PdfPCell(new Phrase(" 採購金額:", font));
        //                //cell.Colspan = 2;
        //                //cell.HorizontalAlignment = Element.ALIGN_CENTER;
        //                //cell.DisableBorderSide(1);

        //                //cell.DisableBorderSide(4);
        //                //cell.DisableBorderSide(8);
        //                //ptable.AddCell(cell);
        //                //cell = new PdfPCell(new Phrase(" 稅額:", font));
        //                //cell.Colspan = 2;
        //                //cell.HorizontalAlignment = Element.ALIGN_CENTER;
        //                //cell.DisableBorderSide(1);

        //                //cell.DisableBorderSide(4);
        //                //ptable.AddCell(cell);
        //                //cell = new PdfPCell(new Phrase(" 金額合計:", font));
        //                //cell.Colspan = 2;

        //                //cell.DisableBorderSide(1);
        //                //cell.DisableBorderSide(4);

        //                //ptable.AddCell(cell);
        //                //Sumtable.AddCell(ptable);

        //                cb.EndText();
        //                // Sumtable.SpacingAfter = 0;
        //                ptable.SpacingAfter = 250;
        //                //Sumtable.WriteSelectedRows(0, -1, 60, 740, writer.DirectContent);//顯示的開始行,結束航(-1為所有)x坐標,y坐標
        //                document.Add(ptable);
        //                document.NewPage();


        //            }






        //    }


        //        document.Close();
        //        writer.Resume();

        //        Response.Clear();
        //        Response.Charset = "gb2312";
        //        Response.ContentEncoding = System.Text.Encoding.UTF8;
        //        Response.AddHeader("Content-Disposition", "attach-ment;filename=" + filename);
        //        Response.WriteFile(newPDFName);
        //        //}
        //        #endregion


        //        //}
        //    }
        //    catch (Exception ex)
        //    {
        //        //cb.EndText();
        //        //writer.Resume();
        //        //Response.Clear();

        //    }
        //}
        public void WritePdf()
        {
            PdfHelper pdf = new PdfHelper();
            List<string> pdfList = new List<string>();
            //float[] arrColWidth_pftable = new float[] { 30,100, 80, 60, 60, 60, 60 };
            float[] arrColWidth = new float[] { 30, 100, 80, 60, 60, 60, 60 };
            int index = 0;
            string newFileName = string.Empty;
            string newName = string.Empty;
            string json = string.Empty;
            IpodQuery ipod = new IpodQuery();
            IpoQuery ipo = new IpoQuery();

            if (!string.IsNullOrEmpty(Request.Params["Poid"]))
            {
                ipo.po_id = Request.Params["Poid"];
            }
            if (!string.IsNullOrEmpty(Request.Params["Potype"]))
            {
                ipo.po_type = Request.Params["Potype"];
            }
            if (!string.IsNullOrEmpty(Request.Params["start_time"]))
            {
                ipo.start_time = Convert.ToDateTime(Request.Params["start_time"].ToString());
            }
            if (!string.IsNullOrEmpty(Request.Params["end_time"]))
            {
                ipo.end_time = Convert.ToDateTime(Request.Params["end_time"].ToString());
            }
            if (!string.IsNullOrEmpty(Request.Params["freight"]))
            {
                ipo.freight = Convert.ToInt32(Request.Params["freight"].ToString());
            }
            List<IpodQuery> ipodStore = new List<IpodQuery>();
            List<IpoQuery> ipoStore = new List<IpoQuery>();
            _ipoMgr = new IpoMgr(mySqlConnectionString);
            int totalCount = 0;
            ipo.IsPage = false;
            ipoStore = _ipoMgr.GetIpoList(ipo, out  totalCount);
            //if (!string.IsNullOrEmpty(Request.Params["freight"]))
            //{
            //    if (Request.Params["freight"].ToString() != "0")
            //    {
            //        _ipodMgr = new IpodMgr(mySqlConnectionString);
            //        List<IpoQuery> newstore = new List<IpoQuery>();
            //        foreach (IpoQuery item in ipoStore)
            //        {
            //            if (!string.IsNullOrEmpty(item.po_id))
            //            {
            //                if (_ipodMgr.GetIpodfreight(item.po_id, Convert.ToInt32(Request.Params["freight"].ToString())))
            //                {
            //                    newstore.Add(item);
            //                }
            //            }
            //        }
            //        ipoStore = newstore;
            //    }
            //}
            try
            {
                #region 採購單匯出

                BaseFont bf = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bf, 8, iTextSharp.text.Font.UNDERLINE, iTextSharp.text.BaseColor.RED);
                iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                string filename = "採購單" + DateTime.Now.ToString("yyyyMMddHHmmss");
                Document document = new Document(PageSize.A4);
                string newPDFName = Server.MapPath(excelPath) + filename;
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPDFName, FileMode.Create));
                document.Open();
                //運送方式

                _paraMgr = new ParameterMgr(mySqlConnectionString);
                List<Parametersrc> parameterStore = new List<Parametersrc>();


                parameterStore = _paraMgr.GetElementType("product_freight");
                if (ipoStore.Count == 0)
                {

                }
                for (int a = 0; a < ipoStore.Count; a++)//循環單頭
                {
                    _ipodMgr = new IpodMgr(mySqlConnectionString);
                    ipod = new IpodQuery();
                    ipod.po_id = ipoStore[a].po_id;
                    ipodStore = new List<IpodQuery>();
                    ipodStore = _ipodMgr.GetIpodListExprot(ipod);
                    Dictionary<int, List<IpodQuery>> product_freight_set_mapping = new Dictionary<int, List<IpodQuery>>();
                    #region 通過運送方式把採購單分開--一張採購單,分成常溫,冷凍等採購單


                    for (int i = 0; i < ipodStore.Count; i++)//通過運送方式保存到字典里
                    {
                        ipodStore[i].spec = GetProductSpec(ipodStore[i].prod_id.ToString());//--------取值出錯了item_id-----------
                        IupcQuery upc = new IupcQuery();
                        _IiupcMgr = new IupcMgr(mySqlConnectionString);

                        upc.item_id = uint.Parse(ipodStore[i].prod_id);//--------取值出錯了item_id-----------
                        //獲取國際條碼
                        List<IupcQuery> upcInternationalStore = new List<IupcQuery>();
                        upc.upc_type_flg = "1";
                        upcInternationalStore = _IiupcMgr.GetIupcByType(upc);
                        //獲取店內條碼
                        List<IupcQuery> upcShopStore = new List<IupcQuery>();
                        upc.upc_type_flg = "3";
                        upcShopStore = _IiupcMgr.GetIupcByType(upc);
                        if (upcInternationalStore.Count > 0)
                        {
                            ipodStore[i].upc_id_international = upcInternationalStore[0].upc_id;
                        }
                        if (upcShopStore.Count > 0)
                        {
                            ipodStore[i].upc_id_shop = upcShopStore[0].upc_id;
                        }
                        int freiset = ipodStore[i].product_freight_set;
                        if (!product_freight_set_mapping.Keys.Contains(freiset))
                        {
                            List<IpodQuery> s = new List<IpodQuery>();
                            product_freight_set_mapping.Add(freiset, s);
                        }
                        product_freight_set_mapping[freiset].Add(ipodStore[i]);
                    }
                    #endregion

                    #region 針對匯出一個而無商品的pdf
                    if (ipodStore.Count == 0)
                    {

                        #region 獲取供應商信息

                        Vendor vendor = new Vendor();
                        _vendorMgr = new VendorMgr(mySqlConnectionString);

                        vendor.erp_id = ipoStore[a].vend_id;
                        vendor = _vendorMgr.GetSingle(vendor);
                        #endregion
                        #region 採購單標題

                        PdfPTable ptable = new PdfPTable(7);


                        ptable.WidthPercentage = 100;//表格寬度
                        font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                        ptable.SetTotalWidth(arrColWidth);
                        PdfPCell cell = new PdfPCell();

                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 15)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("    吉甲地好市集股份有限公司", new iTextSharp.text.Font(bf, 15)));
                        cell.VerticalAlignment = Element.ALIGN_CENTER;//字體水平居左
                        cell.Colspan = 5;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 3;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("採購單" + "-" + ipoStore[a].po_type_desc, new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("公司電話:", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 6;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("公司傳真:", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("製造日期:" + DateTime.Now.ToString("yyyy/MM/dd"), new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 3;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell.UseAscender = true;
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;//字體垂直居中
                        cell.VerticalAlignment = Element.ALIGN_MIDDLE;//字體水平居中
                        cell.BorderWidth = 0.1f;
                        cell.BorderColor = new BaseColor(0, 0, 0);

                        #endregion
                        #region 上部分


                        cell = new PdfPCell(new Phrase("採購單別:" + ipoStore[a].po_type, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("交易幣別:" + "世界貨幣", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("匯率:" + "浮動", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("運輸方式:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);


                        cell = new PdfPCell(new Phrase("商品是新品么?:", font));//新品
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("所在層:", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("採購單(" + ipoStore[a].po_type_desc + ")", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("預約到貨日期:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);



                        cell = new PdfPCell(new Phrase("採購單號:" + ipoStore[a].po_id, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("課稅別:", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("營業稅率:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("價格條件:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);



                        cell = new PdfPCell(new Phrase("單據日期:" + DateTime.Now.ToString("yyyy/MM/dd"), font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("採購人員:" + ipoStore[a].buyer, font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase((System.Web.HttpContext.Current.Session["caller"] as Caller).user_username, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("廠別代號:", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("gigade(讀取)", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);



                        cell = new PdfPCell(new Phrase("廠商代號:" + ipoStore[a].vend_id, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("付款條件(讀取)", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("月結N天(讀取):", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("廠商全名(讀取):", font));
                        cell.Colspan = 5;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("備註:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);


                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("廠商地址:", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);


                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase(" ", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);


                        cell = new PdfPCell(new Phrase("聯絡人(讀取):", font));
                        cell.Colspan = 2;

                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("廠商電話:", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("廠商傳真:", font));
                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("送貨地址(讀取):", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase(" ", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("預計送貨日期(讀取):", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("配送聯絡人(讀取):", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("配送電話(讀取):", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("配送傳真(讀取):", font));
                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("處理備註:", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("運送備註:", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);

                        ptable.AddCell(cell);
                        #endregion

                        cell = new PdfPCell(new Phrase("此採購單商品不存在!", font));
                        cell.Colspan = 7;

                        ptable.AddCell(cell);

                        newFileName = newPDFName + "_part" + index++ + "." + "pdf";
                        pdf.ExportDataTableToPDF(newFileName, ptable, "", "");
                        pdfList.Add(newFileName);

                        document.Add(ptable);
                        document.NewPage();


                    }
                    #endregion

                    foreach (int key in product_freight_set_mapping.Keys)
                    {
                        #region 取出運送方式
                        string procduct_freight = "";
                        for (int i = 0; i < parameterStore.Count; i++)
                        {
                            if (key.ToString() == parameterStore[i].ParameterCode)
                            {
                                procduct_freight = parameterStore[i].parameterName;
                            }
                        }
                        #endregion

                        #region 獲取供應商信息

                        Vendor vendor = new Vendor();
                        _vendorMgr = new VendorMgr(mySqlConnectionString);

                        vendor.erp_id = ipoStore[a].vend_id;
                        vendor = _vendorMgr.GetSingle(vendor);
                        #endregion

                        #region 採購單標題


                        PdfPTable ptable = new PdfPTable(7);


                        ptable.WidthPercentage = 100;//表格寬度
                        font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
                        ptable.SetTotalWidth(arrColWidth);
                        PdfPCell cell = new PdfPCell();

                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 15)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("      吉甲地好市集股份有限公司", new iTextSharp.text.Font(bf, 15)));
                        cell.VerticalAlignment = Element.ALIGN_CENTER;//字體水平居左
                        cell.Colspan = 5;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 3;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("    採購單" + "-" + ipoStore[a].po_type_desc, new iTextSharp.text.Font(bf, 12)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("公司電話:", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 6;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("公司傳真:", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("製造日期:" + DateTime.Now.ToString("yyyy/MM/dd"), new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                        cell.Colspan = 3;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 8)));
                        cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);

                        cell.UseAscender = true;
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;//字體垂直居中
                        cell.VerticalAlignment = Element.ALIGN_MIDDLE;//字體水平居中
                        cell.BorderWidth = 0.1f;
                        cell.BorderColor = new BaseColor(0, 0, 0);
                        #endregion

                        #region 上部分


                        cell = new PdfPCell(new Phrase("採購單別:" + ipoStore[a].po_type, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("交易幣別:" + "世界貨幣", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("匯率:" + "浮動", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        if (procduct_freight != "常溫" && procduct_freight != "冷凍")
                        {
                            ;
                        }
                        cell = new PdfPCell(new Phrase("運輸方式:" + procduct_freight, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);


                        cell = new PdfPCell(new Phrase("商品是新品么?:", font));//新品
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("所在層:", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("採購單(" + ipoStore[a].po_type_desc + ")", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("預約到貨日期:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);



                        cell = new PdfPCell(new Phrase("採購單號:" + ipoStore[a].po_id, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("課稅別:", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("營業稅率:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("價格條件:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);



                        cell = new PdfPCell(new Phrase("單據日期:" + DateTime.Now.ToString("yyyy/MM/dd"), font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("採購人員:", font));
                        //cell = new PdfPCell(new Phrase("採購人員:" + ipoStore[a].buyer, font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase((System.Web.HttpContext.Current.Session["caller"] as Caller).user_username, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("廠別代號:", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("gigade(讀取)", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);



                        cell = new PdfPCell(new Phrase("廠商代號:" + ipoStore[a].vend_id, font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase(vendor == null ? "暫無此信息" : vendor.vendor_name_simple, font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("付款條件(讀取)", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("月結N天(讀取):", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase(vendor == null ? "廠商全名(讀取):暫無此信息" : "廠商全名:" + vendor.vendor_name_full, font));
                        cell.Colspan = 5;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("備註:", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);


                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase(vendor == null ? "廠商地址:暫無此信息" : "廠商地址:" + vendor.company_address, font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);


                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase(" ", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);


                        cell = new PdfPCell(new Phrase("聯絡人(讀取):", font));
                        cell.Colspan = 2;

                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase(vendor == null ? "廠商電話:暫無此信息" : "廠商電話:" + vendor.company_phone, font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase(vendor == null ? "廠商傳真:暫無此信息" : "廠商傳真:" + vendor.company_fax, font));


                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("送貨地址(讀取):", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase(" ", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("預計送貨日期(讀取):", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("配送聯絡人(讀取):", font));
                        cell.Colspan = 2;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("配送電話(讀取):", font));
                        cell.Colspan = 1;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        cell.DisableBorderSide(8);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("配送傳真(讀取):", font));


                        cell.Colspan = 4;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        cell.DisableBorderSide(4);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("處理備註:", font));


                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("運送備註:", font));
                        cell.Colspan = 7;
                        cell.DisableBorderSide(1);

                        ptable.AddCell(cell);
                        #endregion
                        #region 下面表格頭部
                        cell = new PdfPCell(new Phrase("序號", font));
                        cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                        //cell.DisableBorderSide(2);
                        cell.Rowspan = 3;
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("國際條碼", font));
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("品號", font));
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("採購數量", font));
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("允收天數", font));
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("製造日期", font));
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("備註", font));
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);



                        cell = new PdfPCell(new Phrase("供應商店內碼", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("品名", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("允收數量", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("允出天數", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("有效日期", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("料位", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("規格", font));
                        cell.DisableBorderSide(1);
                        cell.DisableBorderSide(2);
                        ptable.AddCell(cell);

                        cell = new PdfPCell(new Phrase("不允收數量", font));
                        cell.DisableBorderSide(1);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("有效期天數", font));
                        cell.DisableBorderSide(1);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("", font));
                        cell.DisableBorderSide(1);
                        ptable.AddCell(cell);
                        cell = new PdfPCell(new Phrase("", font));
                        cell.DisableBorderSide(1);
                        ptable.AddCell(cell);

                        #endregion

                        _ipodMgr = new IpodMgr(mySqlConnectionString);
                        ipod = new IpodQuery();
                        ipod.po_id = ipoStore[a].po_id;
                        ipod.IsPage = false;
                        ipodStore = new List<IpodQuery>();
                        ipodStore = _ipodMgr.GetIpodList(ipod, out totalCount);

                        List<IpodQuery> Ipodleibie = new List<IpodQuery>();
                        Ipodleibie.AddRange(product_freight_set_mapping[key]);

                        #region 循環讀取數據填入表格
                        DataTable Ipod_dt = new DataTable();
                        Ipod_dt.Columns.Add("序號", typeof(string));
                        Ipod_dt.Columns.Add("國際條碼", typeof(string));
                        Ipod_dt.Columns.Add("品號", typeof(string));
                        Ipod_dt.Columns.Add("採購數量", typeof(string));
                        Ipod_dt.Columns.Add("允收天數", typeof(string));
                        Ipod_dt.Columns.Add("製造日期", typeof(string));
                        Ipod_dt.Columns.Add("備註", typeof(string));
                        Ipod_dt.Columns.Add("Empty_1", typeof(string));
                        Ipod_dt.Columns.Add("供應商店內碼", typeof(string));
                        Ipod_dt.Columns.Add("品名", typeof(string));
                        Ipod_dt.Columns.Add("允收數量", typeof(string));
                        Ipod_dt.Columns.Add("允出天數", typeof(string));
                        Ipod_dt.Columns.Add("有效日期", typeof(string));
                        Ipod_dt.Columns.Add("Empty_3", typeof(string));
                        Ipod_dt.Columns.Add("Empty_4", typeof(string));
                        Ipod_dt.Columns.Add("料位", typeof(string));
                        Ipod_dt.Columns.Add("規格", typeof(string));
                        Ipod_dt.Columns.Add("不允收數量", typeof(string));
                        Ipod_dt.Columns.Add("有效期天數", typeof(string));
                        Ipod_dt.Columns.Add("Empty_5", typeof(string));
                        Ipod_dt.Columns.Add("Empty_6", typeof(string));

                        for (int i = 0; i < Ipodleibie.Count; i++)
                        {
                            DataRow newRow = Ipod_dt.NewRow();
                            newRow["國際條碼"] = Ipodleibie[i].upc_id_international;
                            newRow["品號"] = Ipodleibie[i].Erp_Id.ToString();
                            newRow["採購數量"] = Ipodleibie[i].qty_ord.ToString();
                            newRow["允收天數"] = Ipodleibie[i].cde_dt_var.ToString();
                            newRow["製造日期"] = "";
                            newRow["備註"] = "";
                            newRow["Empty_1"] = (i + 1).ToString(); //序號
                            newRow["供應商店內碼"] = Ipodleibie[i].upc_id_shop;
                            newRow["品名"] = Ipodleibie[i].product_name;
                            newRow["允收數量"] = Ipodleibie[i].qty_claimed.ToString();
                            newRow["允出天數"] = Ipodleibie[i].cde_dt_shp.ToString();
                            newRow["有效日期"] = "";
                            newRow["Empty_3"] = "";
                            newRow["Empty_4"] = "";
                            newRow["料位"] = Ipodleibie[i].loc_id;
                            newRow["規格"] = Ipodleibie[i].spec;
                            newRow["不允收數量"] = Ipodleibie[i].qty_damaged.ToString();
                            newRow["有效期天數"] = Ipodleibie[i].cde_dt_incr.ToString();
                            newRow["Empty_5"] = "";
                            newRow["Empty_6"] = "";
                            Ipod_dt.Rows.Add(newRow);
                        }

                        #endregion
                        ////////
                        newFileName = newPDFName + "_part" + index++ + "." + "pdf";

                        pdf.ExportDataTableToPDF(Ipod_dt, false, newFileName, arrColWidth, ptable, "", "", 7, 7);/*第一7是列,第二個是行*/
                        pdfList.Add(newFileName);

                    }






                }
                newFileName = newPDFName + "." + "pdf";
                pdf.MergePDF(pdfList, newFileName);

                Response.Clear();
                Response.Charset = "gb2312";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                Response.AddHeader("Content-Disposition", "attach-ment;filename=" + filename + ".pdf");
                Response.WriteFile(newFileName);
                //}
                #endregion
            }
            catch (Exception ex)
            {
                //cb.EndText();
                //writer.Resume();
                //Response.Clear();

            }
        }
Esempio n. 28
0
            public override void OnEndPage(PdfWriter writer, Document document)
            {
                base.OnEndPage(writer, document);
                Rectangle pageSize = document.PageSize;
                PdfContentByte m_Cb = writer.DirectContent;
                m_Cb.MoveTo(pageSize.GetLeft(MilimetersToPoints(15)), pageSize.GetBottom(MilimetersToPoints(15)) + 40);
                m_Cb.LineTo(pageSize.GetRight(MilimetersToPoints(15)), pageSize.GetBottom(MilimetersToPoints(15)) + 40);
                m_Cb.Stroke();

                //variables
                var font = new Font(iTextSharp.text.Font.FontFamily.HELVETICA, 8, iTextSharp.text.Font.NORMAL);

                // Header - Logo

                //logo
                //var logoPicture = _pictureService.GetPictureById(_pdfSettings.LogoPictureId);
                //var logoExists = logoPicture != null;

                ////header
                //var headerTable = new PdfPTable(logoExists ? 2 : 1);
                //headerTable.WidthPercentage = 100f;
                //if (logoExists)
                //    headerTable.SetWidths(new[] { 50, 50 });

                ////logo
                //if (logoExists)
                //{
                //    var logoFilePath = _pictureService.GetPictureLocalPath(logoPicture, 0, false);
                //    //var img = Image.GetInstance(logoFilePath);
                //    //var cellLogo = new PdfPCell(img);
                //    //cellLogo.Border = Rectangle.NO_BORDER;
                //    //headerTable.AddCell(cellLogo);
                //    //document.Add(headerTable);

                //    Image img = Image.GetInstance(logoFilePath);
                //    img.SetAbsolutePosition(pageSize.GetRight(MilimetersToPoints(20)) - img.ScaledWidth + 10, pageSize.GetTop(MilimetersToPoints(10) + img.ScaledHeight));
                //    document.Add(img);
                //}

                // Footer
                var tableCompanyInfo = new PdfPTable(3);
                tableCompanyInfo.WidthPercentage = 80;
                tableCompanyInfo.SetTotalWidth(new float[] {200, 200, 200});

                var cellInfo = new PdfPCell();
                var cellContact = new PdfPCell();
                var cellBank = new PdfPCell();

                //border
                cellInfo.Border = 0;
                cellContact.Border = 0;
                cellBank.Border = 0;
                cellInfo.HorizontalAlignment = Element.ALIGN_LEFT;
                cellContact.HorizontalAlignment = Element.ALIGN_CENTER;
                cellBank.HorizontalAlignment = Element.ALIGN_RIGHT;

                cellInfo.AddElement(new Phrase(_companyInformationSettings.CompanyName, font));
                cellInfo.AddElement(new Phrase(_companyInformationSettings.Salutation + 
                    (String.IsNullOrEmpty(_companyInformationSettings.Title) ? (_companyInformationSettings.Title + " ") : "") +
                    _companyInformationSettings.Firstname + " " + _companyInformationSettings.Lastname
                    , font));
                cellInfo.AddElement(new Phrase(_companyInformationSettings.Street + " " + _companyInformationSettings.Street2, font));
                cellInfo.AddElement(new Phrase(_companyInformationSettings.ZipCode + " " + _companyInformationSettings.City, font));
                cellInfo.AddElement(new Phrase(_companyInformationSettings.CountryName + (!String.IsNullOrEmpty(_companyInformationSettings.StateName) ? (", " + _companyInformationSettings.StateName) : ""), font));

                cellContact.AddElement(new Phrase(String.Format(_localizationService.GetResource("PDFInvoice.Footer.Url", _lang.Id), _storeContext.CurrentStore.Url), font));
                cellContact.AddElement(new Phrase(String.Format(_localizationService.GetResource("PDFInvoice.Footer.Mail", _lang.Id), _contactDataSettings.ContactEmailAddress), font));
                cellContact.AddElement(new Phrase(String.Format(_localizationService.GetResource("PDFInvoice.Footer.Fon", _lang.Id), _contactDataSettings.CompanyTelephoneNumber), font));
                cellContact.AddElement(new Phrase(String.Format(_localizationService.GetResource("PDFInvoice.Footer.Fax", _lang.Id), _contactDataSettings.CompanyFaxNumber), font));

                cellBank.AddElement(new Phrase(_bankConnectionSettings.Bankname, font));
                cellBank.AddElement(new Phrase(String.Format(_localizationService.GetResource("PDFInvoice.Footer.Bankcode", _lang.Id), _bankConnectionSettings.Bankcode), font));
                cellBank.AddElement(new Phrase(String.Format(_localizationService.GetResource("PDFInvoice.Footer.AccountNumber", _lang.Id), _bankConnectionSettings.AccountNumber), font));
                cellBank.AddElement(new Phrase(String.Format(_localizationService.GetResource("PDFInvoice.Footer.AccountHolder", _lang.Id), _bankConnectionSettings.AccountHolder), font));
                cellBank.AddElement(new Phrase(String.Format(_localizationService.GetResource("PDFInvoice.Footer.Iban", _lang.Id), _bankConnectionSettings.Iban), font));
                cellBank.AddElement(new Phrase(String.Format(_localizationService.GetResource("PDFInvoice.Footer.Bic", _lang.Id), _bankConnectionSettings.Bic), font));


                tableCompanyInfo.AddCell(cellInfo);
                tableCompanyInfo.AddCell(cellContact);
                tableCompanyInfo.AddCell(cellBank);

                tableCompanyInfo.WriteSelectedRows(0, 6, pageSize.GetLeft(MilimetersToPoints(15)), pageSize.GetBottom(MilimetersToPoints(15)) + 40, m_Cb);
            }
Esempio n. 29
0
        public void AseldPDFS()
        {
            PdfHelper pdf = new PdfHelper();
            List<string> pdfList = new List<string>();
            float[] arrColWidth = new float[] {  135,50,45, 60,  55, 55,60, 45,  35, 45, 45, 35 };
            int index = 0;
            string newFileName = string.Empty;
            string newName = string.Empty;
            string json = string.Empty;
            BaseFont bf = BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bf, 8, iTextSharp.text.Font.UNDERLINE, iTextSharp.text.BaseColor.RED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));//黑  
            string filename = "總量撿貨報表" + DateTime.Now.ToString("yyyyMMddHHmmss");
            Document document = new Document(PageSize.A4.Rotate());
            string newPDFName = Server.MapPath(excelPath) + filename;
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPDFName, FileMode.Create));
            document.Open();


            string user_username = (Session["caller"] as Caller).user_username;
            DataTable aseldTable = new DataTable();
            DataTable assg_idTable = new DataTable();
            AseldQuery ase_query = new AseldQuery();
            ase_query.IsPage = false;
            ase_query.assg_id = string.Empty;
            ase_query.start_dtim = DateTime.MinValue;
            ase_query.change_dtim = DateTime.MinValue;
            int total = 0;

            //PdfHelper pdf = new PdfHelper();
            //List<string> pdfList = new List<string>();
            //string newfilename = string.Empty;
            //string filename = "待撿貨商品報表" + DateTime.Now.ToString("yyyyMMddHHmmss");
            //string newPDFName = Server.MapPath(excelPath) + filename;
            //int index = 0;
            int serchWhr = 0;

            if (!string.IsNullOrEmpty(Request.Params["assg_id"]))
            {
                ase_query.assg_id = Request.Params["assg_id"].Trim();
                serchWhr++;
            }
            DateTime date = DateTime.MinValue;
            if (Request.Params["start_time"] != "null" && Request.Params["end_time"] != "null")
            {
                if (DateTime.TryParse(Request.Params["start_time"], out date))
                {
                    ase_query.start_dtim = Convert.ToDateTime(date.ToString("yyyy-MM-dd HH:mm:ss"));
                }
                if (DateTime.TryParse(Request.Params["end_time"], out date))
                {
                    ase_query.change_dtim = Convert.ToDateTime(date.ToString("yyyy-MM-dd HH:mm:ss"));
                }
                serchWhr++;
            }
            IAseldImplMgr aseldMgr = new AseldMgr(mySqlConnectionString);

            DataTable _dtBody = new DataTable();
           
            _dtBody.Columns.Add("商品名稱", typeof(string));
            _dtBody.Columns.Add("料位編號", typeof(string));
            _dtBody.Columns.Add("撿貨庫存", typeof(string));
            _dtBody.Columns.Add("本次撿貨量", typeof(string));
            _dtBody.Columns.Add("製造日期", typeof(string)); 
            _dtBody.Columns.Add("有效日期", typeof(string));
            _dtBody.Columns.Add("條碼", typeof(string));
            _dtBody.Columns.Add("細項編號", typeof(string));

            _dtBody.Columns.Add("訂貨量", typeof(string));
            _dtBody.Columns.Add("已撿貨量", typeof(string));
            _dtBody.Columns.Add("待撿貨量", typeof(string));
           
            
            _dtBody.Columns.Add("備註", typeof(string));
            PdfPTable ptablefoot = new PdfPTable(14);
            #region MyRegion



            #region 數據行
            if (ase_query.assg_id != string.Empty)
            {
                _dtBody.Rows.Clear();
                aseldTable = aseldMgr.GetAseldTable(ase_query, out total);
                #region 標頭
                #region 表頭
                PdfPTable ptable = new PdfPTable(12);


                ptable.WidthPercentage = 100;//表格寬度
                ptable.SetTotalWidth(arrColWidth);
                PdfPCell cell = new PdfPCell();
                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 12;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 4;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("總量撿貨報表", new iTextSharp.text.Font(bf, 18)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 5;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 12;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("印表人:" + user_username, new iTextSharp.text.Font(bf, 8)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 8)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 6;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("印表時間:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), new iTextSharp.text.Font(bf, 8)));
                cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 8)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 12;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                #endregion
                cell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 8)));
                cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                cell.Colspan = 4;
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("工作代號:" + ase_query.assg_id, new iTextSharp.text.Font(bf, 15)));
                cell.VerticalAlignment = Element.ALIGN_CENTER;
                cell.Colspan = 5;
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 8)));
                cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                cell.Colspan = 3;
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("商品名稱", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("料位編號", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("撿貨庫存", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("本次撿貨量", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("製造日期", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                //cell = new PdfPCell(new Phrase("撿貨料位編號", new iTextSharp.text.Font(bf, 8)));
                //cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                //cell.DisableBorderSide(8);
                //ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("有效日期", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("條碼", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("細項編號", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
               
               
               

                cell = new PdfPCell(new Phrase("訂貨量", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("已撿貨量", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("待撿貨量", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
               
           

                //cell = new PdfPCell(new Phrase("創建時間", new iTextSharp.text.Font(bf, 8)));
                //cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                //ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("備註", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                ptable.AddCell(cell);
                #endregion
                #region 新增功能


                if (aseldTable.Rows.Count > 0)
                {
                    _iinvd = new IinvdMgr(mySqlConnectionString);//  GetSearchIinvd
                    _IiupcMgr = new IupcMgr(mySqlConnectionString);
                    foreach (DataRow rows in aseldTable.Rows)
                    {
                        IinvdQuery IinvdQuery = new IinvdQuery();
                        IinvdQuery.item_id = uint.Parse(rows["item_id"].ToString());
                        IinvdQuery.ista_id = "A";
                        List<IinvdQuery> Store = new List<IinvdQuery>();
                        Store = _iinvd.GetPlasIinvd(IinvdQuery);
                        int P_num = string.IsNullOrEmpty(rows["out_qty"].ToString()) ? 0 : int.Parse(rows["out_qty"].ToString()); /*要撿貨的數量*/
                        string upc_id = string.Empty;
                        #region 取條碼

                        List<IupcQuery> list = new List<IupcQuery>();
                        IupcQuery iupc_query = new IupcQuery();
                        if (!string.IsNullOrEmpty(rows["item_id"].ToString()))
                        {
                            uint item_id = uint.Parse(rows["item_id"].ToString());
                            iupc_query.item_id = item_id;
                            iupc_query.upc_type_flg = "1";
                            list = _IiupcMgr.GetIupcByType(iupc_query);
                            if (list.Count > 0)
                            {
                                upc_id = list[0].upc_id;
                            }
                            else
                            {
                                iupc_query.upc_type_flg = "3";
                                list = _IiupcMgr.GetIupcByType(iupc_query);
                                if (list.Count > 0)
                                {
                                    upc_id = list[0].upc_id;
                                }
                                else
                                {
                                    iupc_query.upc_type_flg = "2";
                                    list = _IiupcMgr.GetIupcByType(iupc_query);
                                    if (list.Count > 0)
                                    {
                                        upc_id = list[0].upc_id;
                                    }
                                }
                            }
                        }
                        
                        else
                        {
                            upc_id = " ";
                        }
                        #endregion

                        if (Store.Count > 0)
                        {
                            int crorow = 0;
                            for (int i = 0; i < Store.Count; i++)
                            {
                                DataRow row = _dtBody.NewRow();
                                if (Store[i].prod_qty > P_num)
                                {
                                    if (crorow != 0)
                                    {
                                        row["商品名稱"] = "";
                                        row["條碼"] = "";
                                        row["細項編號"] ="";
                                        row["訂貨量"] = "";
                                        row["已撿貨量"] = "";
                                        row["待撿貨量"] = "";
                                        row["料位編號"] = "";
                                    }
                                    else
                                    {
                                        row["商品名稱"] = rows["product_name"] + rows["spec"].ToString();
                                        row["條碼"] = upc_id;
                                        row["細項編號"] = rows["item_id"];
                                        row["訂貨量"] = rows["ord_qty"];
                                        row["已撿貨量"] = rows["act_pick_qty"];
                                        row["待撿貨量"] = rows["out_qty"];
                                        row["料位編號"] = rows["loc_id"];
                                    }
                                    row["製造日期"] = string.IsNullOrEmpty(Store[i].made_date.ToString()) ? " " : Store[i].made_date.ToString("yyyy/MM/dd");
                                    row["有效日期"] = string.IsNullOrEmpty(Store[i].cde_dt.ToString()) ? " " : Store[i].cde_dt.ToString("yyyy/MM/dd");
                                    row["撿貨庫存"] = P_num;
                                    row["本次撿貨量"] = " ";
                                    row["備註"] = " ";
                                    // row["撿貨料位編號"] = Store[i].plas_loc_id;
                                   
                                   
                                  //  row["創建時間"] = rows["create_dtim"];
                                  
                                    _dtBody.Rows.Add(row);
                                    break;
                                }
                                else
                                {
                                    if (crorow != 0)
                                    {
                                        row["商品名稱"] = "";
                                        row["條碼"] = "";
                                        row["細項編號"] = "";
                                        row["訂貨量"] = "";
                                        row["已撿貨量"] = "";
                                        row["待撿貨量"] = "";
                                        row["料位編號"] = "";
                                    }
                                    else
                                    {
                                        row["商品名稱"] = rows["product_name"] + rows["spec"].ToString();
                                        row["條碼"] = upc_id;
                                        row["細項編號"] = rows["item_id"];
                                        row["訂貨量"] = rows["ord_qty"];
                                        row["已撿貨量"] = rows["act_pick_qty"];
                                        row["待撿貨量"] = rows["out_qty"];
                                        row["料位編號"] = rows["loc_id"];
                                    }
                                    row["製造日期"] = string.IsNullOrEmpty(Store[i].made_date.ToString()) ? " " : Store[i].made_date.ToString("yyyy/MM/dd");
                                    row["有效日期"] = string.IsNullOrEmpty(Store[i].cde_dt.ToString()) ? " " : Store[i].cde_dt.ToString("yyyy/MM/dd");
                                    row["撿貨庫存"] = Store[i].prod_qty;
                                    row["本次撿貨量"] = " ";

                                    //row["撿貨料位編號"] = Store[i].plas_loc_id;
                                  //  row["創建時間"] = rows["create_dtim"];
                                    row["備註"] = " ";
                                    _dtBody.Rows.Add(row);
                                    P_num -= Store[i].prod_qty;
                                    crorow++;
                                    if (P_num == 0)
                                        break;
                                }

                            }
                            // _dtBody.Rows.Add(row);
                        }
                        else
                        {
                            DataRow row = _dtBody.NewRow();
                            row["商品名稱"] = rows["product_name"] + rows["spec"].ToString();
                            row["條碼"] = upc_id;
                            row["細項編號"] = rows["item_id"];
                            row["訂貨量"] = rows["ord_qty"];
                            row["已撿貨量"] = rows["act_pick_qty"];
                            row["待撿貨量"] = rows["out_qty"];
                            row["本次撿貨量"] = " ";
                            row["料位編號"] = rows["loc_id"];
                            //row["撿貨料位編號"] = " ";
                            row["撿貨庫存"] = 0;
                            row["製造日期"] = " ";
                            row["有效日期"] = " ";
                         //   row["創建時間"] = rows["create_dtim"];
                            row["備註"] = " ";
                            _dtBody.Rows.Add(row);
                        }


                    }
                }
                #endregion

                //  pdfList.Add(MakePDF(aseldTable, ase_query.assg_id, user_username, newPDFName, index++));
                newFileName = newPDFName + "_part" + index++ + "." + "pdf";
                pdf.ExportDataTableToPDF(_dtBody, false, newFileName, arrColWidth, ptable, ptablefoot, "", "", 12, uint.Parse(_dtBody.Rows.Count.ToString()));/*第一7是列,第二個是行*/
                pdfList.Add(newFileName);
            }
            else if (ase_query.start_dtim != DateTime.MinValue && ase_query.change_dtim != DateTime.MinValue || serchWhr == 0)
            {
                assg_idTable = aseldMgr.GetAseldTablePDF(ase_query);
                for (int a = 0; a < assg_idTable.Rows.Count; a++)
                {
                    ase_query.assg_id = assg_idTable.Rows[a]["assg_id"].ToString();
                    aseldTable = aseldMgr.GetAseldTable(ase_query, out total);
                    _dtBody.Rows.Clear();
                    #region 標頭
                    #region 表頭
                    PdfPTable ptable = new PdfPTable(12);


                    ptable.WidthPercentage = 100;//表格寬度
                    ptable.SetTotalWidth(arrColWidth);
                    PdfPCell cell = new PdfPCell();
                    cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.Colspan = 12;
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.Colspan = 4;
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase("總量撿貨報表", new iTextSharp.text.Font(bf, 18)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;
                    cell.Colspan = 5;
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.Colspan = 4;
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.Colspan = 12;
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase("印表人:" + user_username, new iTextSharp.text.Font(bf, 8)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.Colspan = 3;
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 8)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.Colspan = 6;
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase("印表時間:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), new iTextSharp.text.Font(bf, 8)));
                    cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                    cell.Colspan = 3;
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 8)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.Colspan = 12;
                    cell.DisableBorderSide(1);
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);
                    #endregion
                    cell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 8)));
                    cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                    cell.Colspan = 4;
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("工作代號:" + ase_query.assg_id, new iTextSharp.text.Font(bf, 15)));
                    cell.VerticalAlignment = Element.ALIGN_CENTER;
                    cell.Colspan = 5;
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 8)));
                    cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                    cell.Colspan = 3;
                    cell.DisableBorderSide(2);
                    cell.DisableBorderSide(4);
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("商品名稱", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("料位編號", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);
                     cell = new PdfPCell(new Phrase("撿貨庫存", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase("本次撿貨量", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("製造日期", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);
                    //cell = new PdfPCell(new Phrase("撿貨料位編號", new iTextSharp.text.Font(bf, 8)));
                    //cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    //cell.DisableBorderSide(8);
                    //ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("有效日期", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("條碼", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);
                    cell = new PdfPCell(new Phrase("細項編號", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);
                    
                   
                   

                    cell = new PdfPCell(new Phrase("訂貨量", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase("已撿貨量", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase("待撿貨量", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    cell.DisableBorderSide(8);
                    ptable.AddCell(cell);
                   
                  

                    //cell = new PdfPCell(new Phrase("創建時間", new iTextSharp.text.Font(bf, 8)));
                    //cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    //ptable.AddCell(cell);

                    cell = new PdfPCell(new Phrase("備註", new iTextSharp.text.Font(bf, 12)));
                    cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                    ptable.AddCell(cell);
                    #endregion


                    #region 新增功能


                    if (aseldTable.Rows.Count > 0)
                    {
                        _iinvd = new IinvdMgr(mySqlConnectionString);//  GetSearchIinvd
                        _IiupcMgr = new IupcMgr(mySqlConnectionString);
                        foreach (DataRow rows in aseldTable.Rows)
                        {
                            IinvdQuery IinvdQuery = new IinvdQuery();
                            IinvdQuery.item_id = uint.Parse(rows["item_id"].ToString());
                            IinvdQuery.ista_id = "A";
                            List<IinvdQuery> Store = new List<IinvdQuery>();
                            Store = _iinvd.GetPlasIinvd(IinvdQuery);
                            int P_num = string.IsNullOrEmpty(rows["out_qty"].ToString()) ? 0 : int.Parse(rows["out_qty"].ToString()); /*要撿貨的數量*/
                            string upc_id = string.Empty;
                            #region 取條碼

                            List<IupcQuery> list = new List<IupcQuery>();
                            IupcQuery iupc_query = new IupcQuery();
                            if (!string.IsNullOrEmpty(rows["item_id"].ToString()))
                            {
                                uint item_id = uint.Parse(rows["item_id"].ToString());
                                iupc_query.item_id = item_id;
                                iupc_query.upc_type_flg = "1";
                                list = _IiupcMgr.GetIupcByType(iupc_query);
                                if (list.Count > 0)
                                {
                                    upc_id = list[0].upc_id;
                                }
                                else
                                {
                                    iupc_query.upc_type_flg = "3";
                                    list = _IiupcMgr.GetIupcByType(iupc_query);
                                    if (list.Count > 0)
                                    {
                                        upc_id = list[0].upc_id;
                                    }
                                    else
                                    {
                                        iupc_query.upc_type_flg = "2";
                                        list = _IiupcMgr.GetIupcByType(iupc_query);
                                        if (list.Count > 0)
                                        {
                                            upc_id = list[0].upc_id;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                upc_id = " ";
                            }
                            #endregion

                            if (Store.Count > 0)
                            {
                                int crorow = 0;
                                for (int i = 0; i < Store.Count; i++)
                                {
                                    DataRow row = _dtBody.NewRow();
                                    if (Store[i].prod_qty > P_num)
                                    {
                                        if (crorow != 0)
                                        {
                                            row["商品名稱"] = "";
                                            row["條碼"] = "";
                                            row["細項編號"] = "";
                                            row["訂貨量"] = "";
                                            row["已撿貨量"] = "";
                                            row["待撿貨量"] = "";
                                            row["料位編號"] = "";
                                        }
                                        else
                                        {
                                            row["商品名稱"] = rows["product_name"] + rows["spec"].ToString();
                                            row["條碼"] = upc_id;
                                            row["細項編號"] = rows["item_id"];
                                            row["訂貨量"] = rows["ord_qty"];
                                            row["已撿貨量"] = rows["act_pick_qty"];
                                            row["待撿貨量"] = rows["out_qty"];
                                            row["料位編號"] = rows["loc_id"];
                                        }
                                        row["製造日期"] = string.IsNullOrEmpty(Store[i].made_date.ToString()) ? " " : Store[i].made_date.ToString("yyyy/MM/dd");
                                        row["有效日期"] = string.IsNullOrEmpty(Store[i].cde_dt.ToString()) ? " " : Store[i].cde_dt.ToString("yyyy/MM/dd");
                                        row["撿貨庫存"] = P_num;
                                        row["本次撿貨量"] = " ";
                                        row["備註"] = " ";
                                        _dtBody.Rows.Add(row);
                                        break;
                                    }
                                    else
                                    {
                                        if (crorow != 0)
                                        {
                                            row["商品名稱"] = "";
                                            row["條碼"] = "";
                                            row["細項編號"] = "";
                                            row["訂貨量"] = "";
                                            row["已撿貨量"] = "";
                                            row["待撿貨量"] = "";
                                            row["料位編號"] = "";
                                        }
                                        else
                                        {
                                            row["商品名稱"] = rows["product_name"] + rows["spec"].ToString();
                                            row["條碼"] = upc_id;
                                            row["細項編號"] = rows["item_id"];
                                            row["訂貨量"] = rows["ord_qty"];
                                            row["已撿貨量"] = rows["act_pick_qty"];
                                            row["待撿貨量"] = rows["out_qty"];
                                            row["料位編號"] = rows["loc_id"];
                                        }
                                        row["製造日期"] = string.IsNullOrEmpty(Store[i].made_date.ToString()) ? " " : Store[i].made_date.ToString("yyyy/MM/dd");
                                        row["有效日期"] = string.IsNullOrEmpty(Store[i].cde_dt.ToString()) ? " " : Store[i].cde_dt.ToString("yyyy/MM/dd");
                                        row["撿貨庫存"] = Store[i].prod_qty;
                                        row["本次撿貨量"] = " ";

                                        //row["撿貨料位編號"] = Store[i].plas_loc_id;
                                        //  row["創建時間"] = rows["create_dtim"];
                                        row["備註"] = " ";
                                        _dtBody.Rows.Add(row);
                                        crorow++;
                                        P_num -= Store[i].prod_qty;
                                        if (P_num == 0)
                                            break;
                                    }

                                }
                                // _dtBody.Rows.Add(row);
                            }
                            else
                            {
                                DataRow row = _dtBody.NewRow();
                                row["商品名稱"] = rows["product_name"] + rows["spec"].ToString();
                                row["條碼"] = upc_id;
                                row["細項編號"] = rows["item_id"];
                                row["訂貨量"] = rows["ord_qty"];
                                row["已撿貨量"] = rows["act_pick_qty"];
                                row["待撿貨量"] = rows["out_qty"];
                                
                                row["本次撿貨量"] = " ";
                                row["料位編號"] = rows["loc_id"];
                                //row["撿貨料位編號"] = " ";
                                row["撿貨庫存"] = 0;
                                row["製造日期"] = " ";
                                row["有效日期"] = " ";
                              //  row["創建時間"] = rows["create_dtim"];
                                row["備註"] = " ";
                                _dtBody.Rows.Add(row);
                            }


                        }
                    }
                    #endregion

                    //  pdfList.Add(MakePDF(aseldTable, ase_query.assg_id, user_username, newPDFName, index++));
                    newFileName = newPDFName + "_part" + index++ + "." + "pdf";
                    pdf.ExportDataTableToPDF(_dtBody, false, newFileName, arrColWidth, ptable, ptablefoot, "", "", 12, uint.Parse(_dtBody.Rows.Count.ToString()));/*第一7是列,第二個是行*/
                    pdfList.Add(newFileName);
                }
            }
            #endregion

            #endregion
           
          
            if (_dtBody.Rows.Count == 0)
            {
                #region 標頭
                #region 表頭
                PdfPTable ptable = new PdfPTable(12);


                ptable.WidthPercentage = 100;//表格寬度
                ptable.SetTotalWidth(arrColWidth);
                PdfPCell cell = new PdfPCell();
                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 12;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 4;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("總量撿貨報表", new iTextSharp.text.Font(bf, 18)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;
                cell.Colspan = 5;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 12;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("印表人:" + user_username, new iTextSharp.text.Font(bf, 8)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 8)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 6;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("印表時間:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), new iTextSharp.text.Font(bf, 8)));
                cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                cell.Colspan = 3;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 8)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.Colspan = 12;
                cell.DisableBorderSide(1);
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                #endregion
                cell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 8)));
                cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                cell.Colspan = 4;
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("工作代號:" + ase_query.assg_id, new iTextSharp.text.Font(bf, 15)));
                cell.VerticalAlignment = Element.ALIGN_CENTER;
                cell.Colspan = 5;
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase(" ", new iTextSharp.text.Font(bf, 8)));
                cell.VerticalAlignment = Element.ALIGN_RIGHT;//字體水平居右
                cell.Colspan = 3;
                cell.DisableBorderSide(2);
                cell.DisableBorderSide(4);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("商品名稱", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("料位編碼", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("撿貨庫存", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("本次撿貨量", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("製造日期", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                //cell = new PdfPCell(new Phrase("撿貨料位編號", new iTextSharp.text.Font(bf, 8)));
                //cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                //cell.DisableBorderSide(8);
                //ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("有效日期", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                cell = new PdfPCell(new Phrase("條碼", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                
               
                cell = new PdfPCell(new Phrase("細項編號", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("訂貨量", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("已撿貨量", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("待撿貨量", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);
                


                //cell = new PdfPCell(new Phrase("創建時間", new iTextSharp.text.Font(bf, 8)));
                //cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                //ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("備註", new iTextSharp.text.Font(bf, 12)));
                cell.VerticalAlignment = Element.ALIGN_LEFT;//字體水平居左
                ptable.AddCell(cell);
                #endregion
                document = new Document(PageSize.A4.Rotate());
                if (!document.IsOpen())
                {
                    document.Open();
                }
                cell = new PdfPCell(new Phrase(" ", font));
                cell.Colspan = 5;
                cell.VerticalAlignment = Element.ALIGN_CENTER;//字體水平居左
                cell.DisableBorderSide(8);
                ptable.AddCell(cell);

                cell = new PdfPCell(new Phrase("此工作代號無數據!", font));
                cell.Colspan = 9;
                cell.DisableBorderSide(4);
                cell.VerticalAlignment = Element.ALIGN_CENTER;//字體水平居左
                ptable.AddCell(cell);


                // document.Add(ptable);
                //document.Add(ptablefoot); 
                newFileName = newPDFName + "_part" + index++ + "." + "pdf";
                pdf.ExportDataTableToPDF(_dtBody, false, newFileName, arrColWidth, ptable, ptablefoot, "", "", 12, uint.Parse(_dtBody.Rows.Count.ToString()));/*第一7是列,第二個是行*/
                pdfList.Add(newFileName);

            }
            //else
            //{
            //    newFileName = newPDFName + "_part" + index++ + "." + "pdf";

            //    pdf.ExportDataTableToPDF(_dtBody, false, newFileName, arrColWidth, ptable, ptablefoot, "", "", 11, uint.Parse(_dtBody.Rows.Count.ToString()));/*第一7是列,第二個是行*/
            //    pdfList.Add(newFileName);

            //}

            newFileName = newPDFName + "." + "pdf";
            pdf.MergePDF(pdfList, newFileName);

            Response.Clear();
            Response.Charset = "gb2312";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.AddHeader("Content-Disposition", "attach-ment;filename=" + filename + ".pdf");
            Response.WriteFile(newFileName);

        }
Esempio n. 30
0
        public override iTextSharp.text.IElement GeneratePdfElement()
        {
            PdfPanelStyle style = (Manifest != null) ? Manifest.Styles.GetMergedFromConfiguration(Style) : Style;

            iTextPdf.PdfPTable panel = new iTextPdf.PdfPTable(1)
            {
                HorizontalAlignment = (int)(style.HorizontalAlignment ?? PdfPanelStyle.Default.HorizontalAlignment.Value),
                SpacingBefore = style.TopIndent ?? PdfPanelStyle.Default.TopIndent.Value,
                SpacingAfter = style.BottomIndent ?? PdfPanelStyle.Default.BottomIndent.Value,
            };

            iTextPdf.PdfPCell cell = new iTextPdf.PdfPCell()
            {
                BackgroundColor = new BaseColor(style.BackgroundColor ?? PdfPanelStyle.Default.BackgroundColor.Value),
                BorderColor = new BaseColor(style.BorderColor ?? PdfPanelStyle.Default.BorderColor.Value),
                Border = iText.Rectangle.BOX,
                Padding = style.Padding ?? PdfPanelStyle.Default.Padding.Value,
                BorderWidth = style.BorderWidth ?? PdfPanelStyle.Default.BorderWidth.Value,
            };

            if (Content.Any())
            {
                Content.ForEach(e => cell.AddElement(e.GeneratePdfElement()));
            }

            panel.AddCell(cell);

            cell.SetLeading(style.Leading ?? PdfPanelStyle.Default.Leading.Value, 0);

            if (style.Width.HasValue && !style.Width.Value.IsBlank)
            {
                PdfUnit unit = style.Width.Value;
                if (unit.Type.IsPercentage())
                {
                    panel.WidthPercentage = unit.Value;
                }
                else
                {
                    panel.SetTotalWidth(new float[] { unit.Value });
                    panel.LockedWidth= true;
                }
            }

            return panel;
        }
Esempio n. 31
0
        private PdfPTable GetInvoiceData(Font times04, Font times05, Invoice invoice)
        {
            string szMsg = "";
            string szData01 = "09/20/2013";
            string szData02 = "UPS GROUND";
            string szData03 = " ";
            string szData04 = "PAID BY VISA";
            string szData05 = "5586";
            string szData06 = "9/10/2013";
            string szData07 = "AD";
            string szData08 = "99067";
            DateTime dDate = DateTime.Now;

            PurchaseOrders purchaseorder = db.PurchaseOrders.Where(pror => pror.PurchaseOrderNo == invoice.PurchaseOrderNo).FirstOrDefault<PurchaseOrders>();
            if (purchaseorder == null)
            {
                szData06 = string.Empty;
            }

            PdfPTable invoicedatatbl = new PdfPTable(numColumns: 4);
            invoicedatatbl.SetTotalWidth(new float[] { 138.105f, 138.105f, 138.105f, 138.105f });
            invoicedatatbl.LockedWidth = true;

            Paragraph hlpPar = null;
            PdfPCell hlpinv = null;

            //First Row
            szMsg = string.Format("{0}", "Date:");
            hlpPar = new Paragraph(szMsg, times05);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0.5f;
            hlpinv.BorderWidthBottom = 0f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            szMsg = string.Format("{0}", "Ship Via");
            hlpPar = new Paragraph(szMsg, times05);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0.5f;
            hlpinv.BorderWidthBottom = 0f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            szMsg = string.Format("{0}", "Tracking No.");
            hlpPar = new Paragraph(szMsg, times05);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0.5f;
            hlpinv.BorderWidthBottom = 0f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            szMsg = string.Format("{0}", "Terms");
            hlpPar = new Paragraph(szMsg, times05);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0f;
            hlpinv.BorderWidthBottom = 0f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            //Second Row
            dDate = Convert.ToDateTime(invoice.InvoiceDate);
            szData01 = dDate.ToString("MM/dd/yyyy");
            szMsg = string.Format("{0}", szData01);
            hlpPar = new Paragraph(szMsg, times04);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0.5f;
            hlpinv.BorderWidthBottom = 0f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            szData02 = invoice.ShipVia;
            szMsg = string.Format("{0}", szData02);
            hlpPar = new Paragraph(szMsg, times04);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0.5f;
            hlpinv.BorderWidthBottom = 0f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            szData03 = invoice.TrackingNo;
            szMsg = string.Format("{0}", szData03);
            hlpPar = new Paragraph(szMsg, times04);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0.5f;
            hlpinv.BorderWidthBottom = 0f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            szData04 = invoice.PaymentTerms;
            szMsg = string.Format("{0}", szData04);
            hlpPar = new Paragraph(szMsg, times04);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0f;
            hlpinv.BorderWidthBottom = 0f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            //Third Row
            szMsg = string.Format("{0}", "P/O No.");
            hlpPar = new Paragraph(szMsg, times05);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0.5f;
            hlpinv.BorderWidthBottom = 0f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            szMsg = string.Format("{0}", "Order Date");
            hlpPar = new Paragraph(szMsg, times05);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0.5f;
            hlpinv.BorderWidthBottom = 0f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            szMsg = string.Format("{0}", "Sales Rep.");
            hlpPar = new Paragraph(szMsg, times05);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0.5f;
            hlpinv.BorderWidthBottom = 0f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            szMsg = string.Format("{0}", "Sales Order No.");
            hlpPar = new Paragraph(szMsg, times05);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0f;
            hlpinv.BorderWidthBottom = 0f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            //Fourth Row
            if (string.IsNullOrEmpty(invoice.PurchaseOrderNo))
            {
                szData06 = string.Empty;
            }
            else
            {
                dDate = Convert.ToDateTime(purchaseorder.PODate);
                szData06 = dDate.ToString("MM/dd/yyyy");
            }
            szData05 = invoice.PurchaseOrderNo;
            szMsg = string.Format("{0}", szData05);
            hlpPar = new Paragraph(szMsg, times04);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0.5f;
            hlpinv.BorderWidthBottom = 0.5f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            szMsg = string.Format("{0}", szData06);
            hlpPar = new Paragraph(szMsg, times04);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0.5f;
            hlpinv.BorderWidthBottom = 0.5f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            szData07 = invoice.SalesRep;
            szMsg = string.Format("{0}", szData07);
            hlpPar = new Paragraph(szMsg, times04);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0.5f;
            hlpinv.BorderWidthBottom = 0.5f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            szData08 = invoice.SalesOrderNo;
            szMsg = string.Format("{0}", szData08);
            hlpPar = new Paragraph(szMsg, times04);
            hlpinv = new PdfPCell(hlpPar);
            hlpinv.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            hlpinv.BorderWidthTop = 0.5f;
            hlpinv.BorderWidthLeft = 0f;
            hlpinv.BorderWidthRight = 0f;
            hlpinv.BorderWidthBottom = 0.5f;
            hlpinv.PaddingTop = 1;
            hlpinv.PaddingLeft = 1;
            hlpinv.PaddingRight = 1;
            hlpinv.PaddingBottom = 3;
            hlpinv.HorizontalAlignment = Element.ALIGN_CENTER;
            invoicedatatbl.AddCell(hlpinv);

            return invoicedatatbl;
        }