/// <summary> /// 顯示修改區塊 /// </summary> protected void setEditView() { try { P_list.Visible = false; P_add.Visible = false; P_edit.Visible = true; var logistics = new POS_Library.ShopPos.LogisticsAccount(); LDList = logistics.GetLogisticsDetail(id); //只有一筆 if (LDList.Count == 1) { lbl_ID.Text = LDList.First().Id.ToString(); lbl_barcode.Text = LDList.First().Barcode; txt_EditAccount.Text = LDList.First().Account; } else { Response.Redirect("~/logistics_account.aspx"); } } catch (Exception ex) { Response.Write("系統發生錯誤 " + ex.Message); } }
/// <summary> /// 產生barcode PDF /// </summary> protected void BarcodePDF() { try { var logistics = new POS_Library.ShopPos.LogisticsAccount(); LDList = logistics.GetLogisticsDetail(id); var LBList = logistics.GetBarcode(id); //if有找到資料 if (LDList.Count > 0) { //宣告文件doc1 Document doc1 = new Document(PageSize.A4, 20, 20, 40, 20); MemoryStream Memory = new MemoryStream(); PdfWriter PdfWriter = PdfWriter.GetInstance(doc1, Memory); //建立中文字型 BaseFont bfChinese = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\mingliu.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); //開始編輯doc1 doc1.Open(); //取得內容物件DirectContent PdfContentByte PCB = PdfWriter.DirectContent; //啟用PCB PCB.SaveState(); PCB.BeginText(); PCB.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL); PCB.SetFontAndSize(bfChinese, 14); float offset_xi = 50, offset_yi = 800; for (int i = 0; i < 10; i++) { switch (i) { case 0: offset_xi = 60; offset_yi = 770; break; case 1: offset_xi = 285; offset_yi = 770; break; case 2: offset_xi = 60; offset_yi = 630; break; case 3: offset_xi = 285; offset_yi = 630; break; case 4: offset_xi = 60; offset_yi = 490; break; case 5: offset_xi = 285; offset_yi = 490; break; case 6: offset_xi = 60; offset_yi = 350; break; case 7: offset_xi = 285; offset_yi = 350; break; case 8: offset_xi = 60; offset_yi = 210; break; case 9: offset_xi = 285; offset_yi = 210; break; } //設定帳號及圖片位置 PCB.ShowTextAligned(0, LDList[0].Account, offset_xi, offset_yi, 0); iTextSharp.text.Image img; img = iTextSharp.text.Image.GetInstance(LBList[0].ImageSource); img.ScalePercent(80, 40); img.SetAbsolutePosition(offset_xi - 35, offset_yi - 70); PCB.AddImage(img); } PCB.EndText(); //畫格線 PCB.SetRGBColorFill(0x00, 0x00, 0x00); //上下兩條橫線 PCB.Rectangle(30, 810, 450, 1); PCB.Fill(); PCB.Rectangle(30, 109, 450, 1); PCB.Fill(); //三條垂直線 PCB.Rectangle(30, 110, 1, 700); PCB.Fill(); PCB.Rectangle(480, 109, 1, 702); PCB.Fill(); PCB.Rectangle(255, 110, 1, 701); PCB.Fill(); //中間四條橫線 PCB.Rectangle(30, 249, 450, 1); PCB.Fill(); PCB.Rectangle(30, 389, 450, 1); PCB.Fill(); PCB.Rectangle(30, 529, 450, 1); PCB.Fill(); PCB.Rectangle(30, 669, 450, 1); PCB.Fill(); //關閉PCB //PCB.EndText(); PCB.RestoreState(); doc1.Close(); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment;filename=logistics_account_barcode_" + id + ".pdf"); Response.ContentType = "application/octet-stream"; Response.OutputStream.Write(Memory.GetBuffer(), 0, Memory.GetBuffer().Length); Response.OutputStream.Flush(); Response.OutputStream.Close(); Response.Flush(); Response.End(); } } catch (Exception ex) { Response.Write("系統發生錯誤 " + ex.Message); } }