Exemple #1
0
        public string BuildPrintFile(V_RP_WAYBILL_H_PRINT hData, List <V_RP_WAYBILL_D_PRINT> dPrintList, string appUser)
        {
            string fileName = string.Format("{0}-{1}-{2}-{3}.pdf",
                                            hData.L_ADRNAM, hData.ORDTYP_WB, hData.CARCOD, DateTime.Now.ToString("yyyyMMddHHmm"));
            string fullPath = BasePath + fileName;

            //base waybilltype to get PageSize?, and whether Including details parts
            RP_WAYBILL_TYPE_BLL wbTypeBLL = new RP_WAYBILL_TYPE_BLL();
            RP_WAYBILL_TYPE     wbType    = wbTypeBLL.GetSpecifyItem(hData.WAYBILL_ID);

            iTextSharp.text.Rectangle pageRec = null;
            float   bottomMargin = 0f;
            decimal xPixel       = ValueConvert.MM2Pixel(wbType.PAPER_HORIZONTAL);
            decimal yPixel       = ValueConvert.MM2Pixel(wbType.PAPER_VERTICAL);

            pageRec = new iTextSharp.text.Rectangle((float)xPixel, (float)yPixel);

            //500m, a flag for A5 or larger than A5
            if (yPixel > 500m)
            {
                bottomMargin = 120f;
            }
            else
            {
                bottomMargin = 35f;
            }

            List <string>        sData    = new List <string>();
            LocalPageEventHelper leHelper = new LocalPageEventHelper();

            leHelper.hData    = hData;
            leHelper.BasePath = BasePath;
            //whether print code128 part
            if (wbType.TRACK_NUM_BY_IHUB == CHubConstValues.IndY)
            {
                leHelper.printCode = true;

                //picture
                string sourceString = hData.SHIP_ID + "C";

                QRCodeEncoder qr = new QRCodeEncoder();
                qr.QRCodeScale        = 3;
                qr.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L;
                qr.QRCodeEncodeMode   = QRCodeEncoder.ENCODE_MODE.BYTE;
                qr.QRCodeVersion      = 1;

                Bitmap img         = qr.Encode(sourceString, Encoding.ASCII);
                string imgName     = Guid.NewGuid().ToString() + ".gif";
                string fullImgPath = this.BasePath + imgName;
                img.Save(fullImgPath, System.Drawing.Imaging.ImageFormat.Gif);

                leHelper.QRPath = fullImgPath;

                leHelper.codeString = string.Format("编号:{0}", hData.SHIP_ID + "C");
            }

            //line 1
            sData.Clear();
            sData.Add(hData.HEADER1);
            sData.Add(hData.HEADER2);
            sData.Add(hData.CARCOD);
            sData.Add(hData.CARNAM);
            sData.Add(hData.HEADER3);
            //leHelper.pLine1 =  new Paragraph(GetLineString(sData, 80), new iTextSharp.text.Font(BF_Light, HeaderFontSize));
            leHelper.line1String = pdfUtility.GetLineString(sData, 80);

            Document doc = new Document(pageRec);

            doc.SetMargins(30f, 36f, 30f, bottomMargin);
            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(fullPath, FileMode.Create));

            //leHelper.QRPath = fullImgPath;
            writer.PageEvent = leHelper;
            doc.Open();
            //doc.Add(GetCode128(hData.SHIP_ID));

            //Table part
            if (wbType.PRINT_DETAIL == CHubConstValues.IndY)
            {
                PdfPTable dTable = new PdfPTable(5);
                dTable.WidthPercentage = 90f;
                dTable.AddCell(pdfUtility.BuildCell(hData.DETAIL_TITLE1, new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(hData.DETAIL_TITLE2, new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(hData.DETAIL_TITLE3, new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(hData.DETAIL_TITLE4, new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(hData.DETAIL_TITLE5, new iTextSharp.text.Font(BF_Light, ContentFontSize)));

                decimal totalWGT = 0;
                decimal totalM3  = 0;
                if (dPrintList != null && dPrintList.Count != 0)
                {
                    foreach (var item in dPrintList)
                    {
                        dTable.AddCell(pdfUtility.BuildCell(item.SHIP_ID, new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.LODNUM, new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell((item.VC_PALWGT ?? 0).ToString("f2"), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.PALVOL, new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.REMARK1, new iTextSharp.text.Font(BF_Light, ContentFontSize)));

                        totalWGT += item.VC_PALWGT ?? 0;
                        totalM3  += item.PALVOL_M3 ?? 0;
                    }
                }
                doc.Add(dTable);

                if (dPrintList != null && dPrintList.Count != 0)
                {
                    Paragraph pLast = new Paragraph(string.Format("Total Items:{0}    Total Weight:{1}    Total Volumn:{2}          ", dPrintList.Count, totalWGT, totalM3), new iTextSharp.text.Font(BF_Light, 10));
                    pLast.Alignment = Element.ALIGN_RIGHT;
                    doc.Add(pLast);
                }
            }

            //footer  part
            sData.Clear();
            sData.Add(hData.FOOTER1 ?? string.Empty);
            sData.Add(hData.FOOTER2 ?? string.Empty);
            sData.Add(hData.FOOTER3 ?? string.Empty);

            PdfContentByte cb = writer.DirectContent;
            ColumnText     ct = new ColumnText(cb);

            cb.BeginText();
            cb.SetFontAndSize(BF_Light, FooterFontSize);
            cb.SetTextMatrix(doc.LeftMargin, doc.BottomMargin);
            cb.ShowText(pdfUtility.GetLineString(sData));
            cb.EndText();

            doc.Close();

            //add track data

            string            sourceString1 = hData.SHIP_ID + "C";
            RP_SHIP_TRACK_BLL trackBLL      = new RP_SHIP_TRACK_BLL();

            foreach (var item in dPrintList)
            {
                RP_SHIP_TRACK track = new RP_SHIP_TRACK();
                track.WH_ID             = item.WH_ID;
                track.SHIP_ID           = item.SHIP_ID;
                track.TRACK_NUM_IHUB    = sourceString1;
                track.RECORD_DATE       = DateTime.Now;
                track.TRACK_NUM_BY_IHUB = hData.TRACK_NUM_BY_IHUB;
                track.UPDATED_BY        = appUser;
                trackBLL.AddOrUpdate(track);
            }
            return(fileName);
        }
Exemple #2
0
        public string BuildPrintFile(List <PackPageData> pageDatas, string appUser)
        {
            string fileName = string.Format("CustPack-{0}.pdf", DateTime.Now.ToString("yyyyMMddHHmm"));
            string fullPath = BasePath + fileName;


            List <string> sData = new List <string>();

            //each page size get from header ,
            Document doc = new Document(pdfUtility.GetDocRectangle(pageDatas[0].Header.PAPER_HORIZONTAL, pageDatas[0].Header.PAPER_VERTICAL));

            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(fullPath, FileMode.Create));

            //string imagePath = BasePath.Replace("temp", "images") + pageDatas[0].Header.LOGO; //;"custpack.png";
            PackPageEventHelper pHelper = new PackPageEventHelper();

            if (!string.IsNullOrEmpty(pageDatas[0].Header.LOGO))
            {
                pHelper.LogoPath = BasePath.Replace("temp", "images") + pageDatas[0].Header.LOGO;
            }
            writer.PageEvent = pHelper;

            doc.SetMargins(10f, 10f, 10f, 36f);

            pHelper.CurrentGroup = pageDatas[0].Header.LODNUM;
            for (int i = 0; i < pageDatas.Count; i++)
            {
                //pHelper.CurrentGroup = pageDatas[i].Header.SHIP_ID;
                if (i != 0)
                {
                    doc.SetPageSize(pdfUtility.GetDocRectangle(pageDatas[i].Header.PAPER_HORIZONTAL, pageDatas[i].Header.PAPER_VERTICAL));
                    doc.NewPage();
                }
                else
                {
                    doc.Open();
                }


                PdfPCell cellUnit;
                //Content part
                PdfPTable contentTable = new PdfPTable(3);
                contentTable.WidthPercentage = 90f;
                contentTable.SetWidths(new float[] { 200f, 190f, 185f });//575

                cellUnit             = new PdfPCell(new Paragraph(pageDatas[i].Header.HEADER1, new iTextSharp.text.Font(BF_Light, HeaderFontSize)));
                cellUnit.BorderWidth = 0;
                contentTable.AddCell(cellUnit);
                cellUnit             = new PdfPCell(new Paragraph(pageDatas[i].Header.HEADER2, new iTextSharp.text.Font(BF_Light, HeaderFontSize)));
                cellUnit.BorderWidth = 0;
                contentTable.AddCell(cellUnit);
                cellUnit             = new PdfPCell(new Paragraph(pageDatas[i].Header.HEADER3, new iTextSharp.text.Font(BF_Light, HeaderFontSize)));
                cellUnit.BorderWidth = 0;
                contentTable.AddCell(cellUnit);
                doc.Add(contentTable);
                doc.Add(new Paragraph(Environment.NewLine));

                //part 2
                PdfPTable table_2 = new PdfPTable(2);
                table_2.WidthPercentage = 90f;
                table_2.SetWidths(new float[] { 285f, 285f });//575
                Paragraph p21 = new Paragraph();
                p21.Add(new Phrase(string.Format("{0}    {1}", pageDatas[i].Header.NOTE1, pageDatas[i].Header.FLEX1), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p21.Add(System.Environment.NewLine);
                p21.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.COMPANY), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p21.Add(System.Environment.NewLine);
                p21.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.ADDRESS), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p21.Add(System.Environment.NewLine);
                p21.Add(new Phrase(string.Format("{0}    {1}", pageDatas[i].Header.CONTACT, pageDatas[i].Header.TELEPHONE), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p21.Add(System.Environment.NewLine);
                cellUnit             = new PdfPCell(p21);
                cellUnit.BorderWidth = 0;
                table_2.AddCell(cellUnit);

                Paragraph p22 = new Paragraph();
                p22.Add(new Phrase(string.Format("{0}    {1}", pageDatas[i].Header.NOTE2, pageDatas[i].Header.FLEX2), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p22.Add(System.Environment.NewLine);
                p22.Add(new Phrase(string.Format("{0}    {1}", pageDatas[i].Header.ADRNAM, pageDatas[i].Header.ADRCTY), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p22.Add(System.Environment.NewLine);
                p22.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.ADRLN1), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p22.Add(System.Environment.NewLine);
                p22.Add(new Phrase(string.Format("{0}    {1}", pageDatas[i].Header.ADRLN2, pageDatas[i].Header.ADRLN3), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p22.Add(System.Environment.NewLine);
                p22.Add(new Phrase(string.Format("{0}    {1}", pageDatas[i].Header.LAST_NAME, pageDatas[i].Header.PHNNUM), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p22.Add(System.Environment.NewLine);
                cellUnit             = new PdfPCell(p22);
                cellUnit.BorderWidth = 0;
                table_2.AddCell(cellUnit);

                doc.Add(table_2);
                doc.Add(new Paragraph(Environment.NewLine));

                //part 3
                PdfPTable table_3 = new PdfPTable(3);
                table_3.WidthPercentage = 90f;
                table_3.SetWidths(new float[] { 200f, 190f, 185f });//575
                Paragraph p31 = new Paragraph();
                p31.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.NOTE3), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p31.Add(System.Environment.NewLine);
                p31.Add(System.Environment.NewLine);
                p31.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.FLEX3), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                cellUnit             = new PdfPCell(p31);
                cellUnit.BorderWidth = 0;
                table_3.AddCell(cellUnit);

                Paragraph p32 = new Paragraph();
                p32.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.NOTE4), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p32.Add(System.Environment.NewLine);
                p32.Add(System.Environment.NewLine);
                p32.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.FLEX4), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                cellUnit             = new PdfPCell(p32);
                cellUnit.BorderWidth = 0;
                table_3.AddCell(cellUnit);

                Paragraph p33 = new Paragraph();
                p33.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.NOTE5), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p33.Add(System.Environment.NewLine);
                p33.Add(System.Environment.NewLine);
                p33.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.FLEX5), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                cellUnit             = new PdfPCell(p33);
                cellUnit.BorderWidth = 0;
                table_3.AddCell(cellUnit);

                doc.Add(table_3);
                doc.Add(new Paragraph(Environment.NewLine));

                //Table part
                PdfPTable dTable = new PdfPTable(11);
                dTable.WidthPercentage = 90f;
                dTable.SetWidths(new float[] { 30f, 52f, 98f, 25f, 30f, 47f, 47f, 47f, 47f, 47f, 47f });
                dTable.AddCell(pdfUtility.BuildCell("Index", new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL01, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL02, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL03, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL04, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL05, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL06, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL07, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL08, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL09, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL10, new iTextSharp.text.Font(BF_Light, TableFontSize)));

                if (pageDatas[i].Details != null && pageDatas[i].Details.Count > 0)
                {
                    //order
                    //pageDatas[i].Details.OrderBy(a => a.COL01);

                    int indexPoint = 1;
                    foreach (var item in pageDatas[i].Details)
                    {
                        dTable.AddCell(pdfUtility.BuildCell(indexPoint.ToString(), new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        indexPoint++;
                        dTable.AddCell(pdfUtility.BuildCell(item.COL01, new iTextSharp.text.Font(BF_Light, BigTableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL02, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL03, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL04, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL05, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL06, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL07, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL08, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL09, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL10, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                    }
                    doc.Add(dTable);

                    Paragraph pLast = new Paragraph(string.Format("Total Items:{0}          ", pageDatas[i].Details.Count.ToString()), new iTextSharp.text.Font(BF_Light, ContentFontSize));
                    pLast.Alignment = Element.ALIGN_RIGHT;
                    doc.Add(pLast);
                }

                //footer  part
                //
                sData.Clear();
                sData.Add(pageDatas[i].Header.FOOTER1 ?? string.Empty);
                sData.Add(pageDatas[i].Header.FOOTER2 ?? string.Empty);
                sData.Add(pageDatas[i].Header.FOOTER3 ?? string.Empty);

                PdfContentByte cb = writer.DirectContent;
                ColumnText     ct = new ColumnText(cb);
                cb.BeginText();
                cb.SetFontAndSize(BF_Light, FooterFontSize);
                cb.SetTextMatrix(doc.LeftMargin, doc.BottomMargin);
                cb.ShowText(pdfUtility.GetLineString(sData));
                cb.EndText();

                if ((i + 1) < pageDatas.Count)
                {
                    pHelper.CurrentGroup = pageDatas[i + 1].Header.LODNUM;
                    if (!string.IsNullOrEmpty(pageDatas[i + 1].Header.LOGO))
                    {
                        pHelper.LogoPath = BasePath.Replace("temp", "images") + pageDatas[i + 1].Header.LOGO;
                    }
                    else
                    {
                        pHelper.LogoPath = null;
                    }
                }
            }

            doc.Close();

            //add track data

            //string sourceString1 = hData.SHIP_ID + "C";
            //RP_SHIP_TRACK_BLL trackBLL = new RP_SHIP_TRACK_BLL();
            //foreach (var item in dPrintList)
            //{
            //    RP_SHIP_TRACK track = new RP_SHIP_TRACK();
            //    track.WH_ID = item.WH_ID;
            //    track.SHIP_ID = item.SHIP_ID;

            //    if (wbType.TRACK_NUM_BY_IHUB == CHubConstValues.IndY)
            //        track.TRACK_NUM_IHUB = sourceString1;
            //    else
            //        track.TRACK_NUM_IHUB = "IHUB_Printed";

            //    track.RECORD_DATE = DateTime.Now;
            //    track.UPDATED_BY = appUser;
            //    trackBLL.AddOrUpdate(track);
            //}


            return(fileName);
        }