Esempio n. 1
0
        public string PrintPickList(List <TicketShelfTemp> TSList, string InvoiceNo, string TicketName)
        {
            string       PrintLogFileName = "";
            string       Date             = DateTime.Now.ToString("yyyyMMdd");
            Rectangle    pageSize         = new Rectangle(240, (145 + TSList.Count * 13)); //227, (145 + TSList.Count*13)
            Document     doc      = new Document(pageSize, -20, -10, 0, 0);                //橫式 Rotate()
            MemoryStream ms       = new MemoryStream();
            string       Filepath = HttpContext.Current.Server.MapPath(".") + "\\PDF_Pick" + _areaId;
            //多筆加結尾分頁數 調出用(2015-0205新增)
            var 結尾 = (string.IsNullOrEmpty(InvoiceNo) &&
                      !string.IsNullOrEmpty(TicketName) && TicketName.Length >= 2) ? "_" + TicketName.Substring(TicketName.Length - 2, 2) : "";

            //FILENAME 是真正的檔案位置,web用來讀檔案用
            string FileName = String.Format(@"{0}\PickList_{1}_{2}.pdf", Filepath, Date, TSList[0].Barcode + 結尾);
            string WebUrl   = String.Format(@"{0}\PickList_{1}_{2}.pdf", "\\PDF_Pick" + _areaId, Date, TSList[0].Barcode + 結尾);

            PrintLogFileName = String.Format("PickList_{0}_{1}.pdf", Date, TSList[0].Barcode + 結尾);

            //測試模式修改路徑
            if (testmode)
            {
                Filepath = HttpContext.Current.Server.MapPath(".") + "\\PDF_Pick" + _areaId + "_Test";
                FileName = String.Format(@"{0}\PickList_{1}_{2}.pdf", Filepath, Date, TSList[0].Barcode + 結尾);
                WebUrl   = String.Format(@"{0}\PickList_{1}_{2}.pdf", "\\PDF_Pick" + _areaId + "_Test", Date, TSList[0].Barcode + 結尾);
            }
            //不存在則建立資料夾
            if (!Directory.Exists(Filepath))
            {
                Directory.CreateDirectory(Filepath);
            }

            Exception ExceptionToThrow = null;

            try
            {
                PdfWriter.GetInstance(doc, new FileStream(FileName, FileMode.Create));
                PdfPTable table = new PdfPTable(new float[] { 1.5f, 0.1f, 3, 0.1f, 0.3f, 1 }); //new float[] { 3.5f, 0.005f, 4, 0.1f, 0.005f, 1 }
                //table.TotalWidth = 220f;
                //table.LockedWidth = true;

                BarcodeLib.BarcodeModel bar = new BarcodeLib.BarcodeModel();
                var    barImage             = bar.GetBarcode("Code 39", TSList[0].Barcode, 600, 150, true, false);
                byte[] img = Utility.ImageToBuffer(barImage, System.Drawing.Imaging.ImageFormat.Png);

                Image jpg = Image.GetInstance(img);
                jpg.ScaleToFit(220f, 50f);

                PdfPCell cell = new PdfPCell(jpg);
                cell.Colspan             = 6;
                cell.BorderColor         = new BaseColor(255, 255, 255);
                cell.VerticalAlignment   = Convert.ToInt32(PdfAlignType.Center);
                cell.HorizontalAlignment = Convert.ToInt32(PdfAlignType.Left);

                table.AddCell(cell);

                if (!string.IsNullOrEmpty(InvoiceNo))
                {
                    PdfPCell Invoice = new PdfPCell(new Phrase(InvoiceNo.Substring(InvoiceNo.Length - 4, 4), new Font(bfMs, 25f)));
                    Invoice.Colspan             = 6;
                    Invoice.BorderColor         = new BaseColor(255, 255, 255);
                    Invoice.HorizontalAlignment = Convert.ToInt32(PdfAlignType.Center);
                    table.AddCell(Invoice);
                }

                table = PickContent(table, TSList, TicketName);

                PdfPCell Num = new PdfPCell(new Phrase("交易序號:" + TSList[0].ShipId, new Font(bfMs, 10f)));
                Num.Colspan             = 6;
                Num.BorderColor         = new BaseColor(255, 255, 255);
                Num.HorizontalAlignment = Convert.ToInt32(PdfAlignType.Left);
                table.AddCell(Num);

                doc.Open();
                doc.Add(table);
            }
            catch (Exception e)
            {
                ExceptionToThrow = e;
            }
            finally
            {
                ClosePdf(doc);
                doc.Close();
            }

            if (ExceptionToThrow != null)
            {
                throw ExceptionToThrow;
            }

            if (TicketName.IndexOf("補印") == -1)
            {
                InsertPrintListLog(TSList[0].ShipId, PrintLogFileName, (int)PdfPrintType.結帳自動列印);
            }
            else
            {
                InsertPrintListLog(TSList[0].ShipId, PrintLogFileName, (int)PdfPrintType.手動補印);
            }

            return("Success");
        }
Esempio n. 2
0
        public void PrintPickList(List <TicketShelfTemp> TSList, string InvoiceNo)
        {
            Document     doc      = new Document(PageSize.A8, 0, -10, 0, 0); //橫式 Rotate()
            MemoryStream ms       = new MemoryStream();
            string       Filepath = HttpContext.Current.Server.MapPath(".");
            string       FileName = String.Format("{0}PickList_{1}_{2}.pdf", Filepath, DateTime.Now.ToString("yyyyMMdd"), InvoiceNo);

            PdfWriter.GetInstance(doc, new FileStream(FileName, FileMode.Create));

            //輸出Table
            PdfPTable table = new PdfPTable(new float[] { 3.5f, 0.1f, 4, 0.1f, 0.5f, 1 }); //new float[] { 2, 1, 1, 3 }

            table.TotalWidth  = 145f;
            table.LockedWidth = true;

            if (!string.IsNullOrEmpty(InvoiceNo))
            {
                PdfPCell Invoice = new PdfPCell(new Phrase(InvoiceNo.Substring(InvoiceNo.Length - 4, 4), new Font(bfMs, 20f)));
                Invoice.Colspan             = 6;
                Invoice.BorderColor         = new BaseColor(255, 255, 255);
                Invoice.HorizontalAlignment = Convert.ToInt32(PdfAlignType.Center);
                table.AddCell(Invoice);
            }

            PdfPCell logo = new PdfPCell(new Phrase("OB嚴選 LOGO", new Font(bfMs, 10f)));

            logo.Colspan             = 6;
            logo.BorderColor         = new BaseColor(255, 255, 255);
            logo.HorizontalAlignment = Convert.ToInt32(PdfAlignType.Center);
            logo.BackgroundColor     = new BaseColor(255, 255, 255);
            logo.Padding             = 7f;
            table.AddCell(logo);

            PdfPCell header = new PdfPCell(new Phrase("交易明細", new Font(bfMs, 10f, Font.BOLD)));

            header.Colspan             = 6;
            header.BorderColor         = new BaseColor(255, 255, 255);
            header.HorizontalAlignment = Convert.ToInt32(PdfAlignType.Center);
            table.AddCell(header);

            PdfPCell hr = new PdfPCell(new Phrase("- - - - - - - - - - - - - - - - - - - - - - - - - - - -", new Font(bfMs, 7f)));

            hr.Colspan     = 6;
            hr.BorderColor = new BaseColor(255, 255, 255);
            table.AddCell(hr);

            PdfPCell title = new PdfPCell(new Phrase("檢貨單", new Font(bfMs, 9.3f, Font.BOLD)));

            title.Colspan             = 6;
            title.BorderColor         = new BaseColor(255, 255, 255);
            title.HorizontalAlignment = Convert.ToInt32(PdfAlignType.Center);
            table.AddCell(title);

            foreach (TicketShelfTemp TS in TSList)
            {
                ArrayList TrList = new ArrayList();
                TrList.Add(TS.Division);
                TrList.Add("");
                TrList.Add(TS.ProductId);
                TrList.Add("");
                TrList.Add("X");
                TrList.Add(TS.Quantity);
                CreateNewCell(table, TrList, PdfAlignType.Left);
            }

            PdfPCell colspace = new PdfPCell(new Phrase(" ", new Font(bfMs, 8f)));

            colspace.Colspan     = 6;
            colspace.BorderColor = new BaseColor(255, 255, 255);
            table.AddCell(colspace);

            table.AddCell(hr);

            PdfPCell Time = new PdfPCell(new Phrase("交易時間:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), new Font(bfMs, 9.3f)));

            Time.Colspan             = 6;
            Time.BorderColor         = new BaseColor(255, 255, 255);
            Time.HorizontalAlignment = Convert.ToInt32(PdfAlignType.Left);
            table.AddCell(Time);


            PdfPCell Num = new PdfPCell(new Phrase("交易序號:" + TSList[0].ShipId, new Font(bfMs, 9.3f)));

            Num.Colspan             = 6;
            Num.BorderColor         = new BaseColor(255, 255, 255);
            Num.HorizontalAlignment = Convert.ToInt32(PdfAlignType.Left);
            table.AddCell(Num);


            BarcodeLib.BarcodeModel bar = new BarcodeLib.BarcodeModel();
            var barImage = bar.GetBarcode("Code 39", TSList[0].Barcode, 600, 150, true, false);

            byte[] img = Utility.ImageToBuffer(barImage, System.Drawing.Imaging.ImageFormat.Png);


            Image jpg = Image.GetInstance(img);

            jpg.ScaleToFit(150f, 50f);


            doc.Open();
            doc.Add(jpg);
            doc.Add(table);
            ClosePdf(doc);

            //System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(FileName);
            //psi.Verb = "PRINT";
            //Process.Start(psi);
        }