예제 #1
0
        public iTextSharp.text.Rectangle GetDocRectangle(decimal x, decimal y)
        {
            decimal xPixel = ValueConvert.MM2Pixel(x);
            decimal yPixel = ValueConvert.MM2Pixel(y);

            return(new iTextSharp.text.Rectangle((float)xPixel, (float)yPixel));
        }
예제 #2
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);
        }