diff --git a/web/App_Code/DataAccess/StyleDataAccess.cs b/web/App_Code/DataAccess/StyleDataAccess.cs index b5764cc..10a0647 100644 --- a/web/App_Code/DataAccess/StyleDataAccess.cs +++ b/web/App_Code/DataAccess/StyleDataAccess.cs @@ -32,7 +32,7 @@ public class StyleDataAccess { StringBuilder sb = new StringBuilder(); var sp = new List(); - sb.Append("insert into TabletPaperSize (PaperID,PaperName,Width,Height,CUser,CDate,CTime,UUser,UDate,UTime )"); + sb.Append("insert into TabletPaperSize (PaperID,PaperName,Width,Height,CUser,CDate,CTime,UUser,UDate,UTime ) "); sb.Append("values (@PaperID,@PaperName,@Width,@Height,@CUser,@CDate,@CTime,@UUser,@UDate,@UTime )"); sp.Add(new SqlParameter("@PaperID",tps.PaperID)); sp.Add(new SqlParameter("@PaperName", tps.PaperName)); @@ -44,7 +44,7 @@ public class StyleDataAccess sp.Add(new SqlParameter("@UUser", tps.UUser)); sp.Add(new SqlParameter("@UDate", tps.UDate)); sp.Add(new SqlParameter("@UTime", tps.UTime)); - context.Database.ExecuteSqlCommand(sb.ToString(),sp); + context.Database.ExecuteSqlCommand(sb.ToString(),sp.ToArray()); } } catch (Exception ex) @@ -253,7 +253,7 @@ public class StyleDataAccess new SqlParameter("@UDate",""), new SqlParameter("@UTime",""), }; - context.Database.ExecuteSqlCommand(sb.ToString(), sp1); + context.Database.ExecuteSqlCommand(sb.ToString(), sp1.ToArray()); } } } diff --git a/web/App_Code/api/designerController.cs b/web/App_Code/api/designerController.cs index ea78082..7124df8 100644 --- a/web/App_Code/api/designerController.cs +++ b/web/App_Code/api/designerController.cs @@ -118,6 +118,9 @@ public class designerController : ApiController tsd.FontFamily = item.fontFamily == null ? "" : (string)item.fontFamily; tsd.BreakLen = item.breakLen == null ? "" : (string)item.breakLen; tsd.Width = item.width == null ? "" : (string)item.width; + tsd.Height = item.height == null ? "" : (string)item.height; + tsd.TextWidth = item.textWidth == null ? "" : (string)item.textWidth; + tsd.TextHeight = item.textHeight == null ? "" : (string)item.textHeight; tsd.TwoOffset = item.twoOffset == null ? "" : (string)item.twoOffset; tsd.ThreeOffset = item.threeOffset == null ? "" : (string)item.threeOffset; tsd.FourOffset = item.fourOffset == null ? "" : (string)item.fourOffset; @@ -217,16 +220,20 @@ public class designerController : ApiController //json.detail.Children() log.writeLogPath((string)json.styleName); TabletPaperSize tps = new TabletPaperSize(); - tps.PaperID = (json == null || json.PaperID == null) ? "" : (string)json.PaperID; + tps.PaperID = (json == null || json.paperID == null) ? "" : (string)json.paperID; if (string.IsNullOrEmpty(tps.PaperID)) { tps.PaperID = DateTime.Now.ToString("yyyyMMddHHmmss"); } - tps.PaperName = (json == null || json.PaperName == null) ? "" : (string)json.PaperName; - tps.Width = (json == null || json.Width == null) ? "" : (string)json.Width; - tps.Height = (json == null || json.Height == null) ? "" : (string)json.Height; - - + tps.PaperName = (json == null || json.paperName == null) ? "" : (string)json.paperName; + tps.Width = (json == null || json.width == null) ? "" : (string)json.width; + tps.Height = (json == null || json.height == null) ? "" : (string)json.height; + tps.CUser = ""; + tps.CDate = DateTime.Now.ToString("yyyyMMdd"); + tps.CTime = DateTime.Now.ToString("HHmmss"); + tps.UUser = ""; + tps.UDate = DateTime.Now.ToString("yyyyMMdd"); + tps.UTime = DateTime.Now.ToString("HHmmss"); object[] obj = new StyleDataAccess().AddTabletPaper(tps); diff --git a/web/admin/item/TabletDesigner.aspx b/web/admin/item/TabletDesigner.aspx index 4289a8a..65819b5 100644 --- a/web/admin/item/TabletDesigner.aspx +++ b/web/admin/item/TabletDesigner.aspx @@ -3,11 +3,8 @@ <%@ Register Src="~/admin/_uc/alert.ascx" TagPrefix="uc1" TagName="alert" %> - <%-- --%> + + @@ -98,16 +95,17 @@ 存檔
- <%-- 存檔--%> + 預覽列印
- +
<%--
嘿嘿
--%>
+
@@ -267,6 +265,137 @@ }); $("#paperOrientation").html("直向") }, + exportPDF() { + + // 1. 抓取您要轉成 PDF 的目標區塊 (這裡我們抓取整張牌位) + // 注意:如果有分頁,您可能需要抓取包住所有 .tablet-paper 的外層容器 + const element = document.querySelector('.tablet-paper'); + + // 如果畫面上有隱藏的滾動條或超出邊界的元素,可以先把它們推到最左上角 + // 確保截圖時不會被切到 + window.scrollTo(0, 0); + + // 2. 設定 PDF 參數 + const opt = { + margin: 0, + filename: '牌位設計.pdf', + // 設定截圖的品質 + image: { type: 'jpeg', quality: 1 }, + // scale: 2 可以讓截圖解析度變高,印出來的文字不會糊糊的 + // useCORS: true 確保您的 SVG 底圖可以被正確讀取,不會因為跨域問題破圖 + html2canvas: { scale: 2, useCORS: true, logging: false }, + // 將 PDF 尺寸設定為您系統中的動態寬高 + jsPDF: { + unit: 'mm', + format: [this.paper.width, this.paper.height], + orientation: 'portrait' + } + }; + + // 3. 呼叫 html2pdf 執行轉換並下載 + html2pdf().set(opt).from(element).save().then(() => { + console.log("PDF 匯出成功!"); + }).catch(err => { + console.error("PDF 匯出失敗:", err); + }); + + }, + print() { + let w = window.open('', '_blank'); + if (!w) { + alert("請允許瀏覽器開啟彈出式視窗!"); + return; + } + + // 1. 抓取您原本網頁定義的 HTTP_HOST (您的全域變數),如果沒有則抓取當前網址 + let hostUrl = typeof HTTP_HOST !== 'undefined' ? HTTP_HOST : (window.location.protocol + "//" + window.location.host); + if (!hostUrl.endsWith('/')) hostUrl += '/'; + + // 2. 抓出畫布完整的 HTML + let canvasHtml = $("#printArea").html(); + + // 3. 【關鍵修復】把所有的 "../../" 替換成完整的網址,解決底圖破圖問題! + canvasHtml = canvasHtml.replace(/\.\.\/\.\.\//g, hostUrl); + + // 4. 組合列印視窗的 HTML + let htmlContent = ` + + + + 預覽列印 - 牌位設計 + + + + + + + ${canvasHtml} + + + `; + + w.document.write(htmlContent); + w.document.close(); + + // 5. 將等待時間稍微拉長至 1.2 秒,確保大張的 SVG 底圖與外部字體(如標楷體)下載完畢 + setTimeout(() => { + w.focus(); + w.print(); + }, 1200); + }, changeOrientation() { this.orientation = (this.orientation === "portrait" ? "land" : "portrait"); $("#paperOrientation").empty(); @@ -281,6 +410,7 @@ "background-color": "white", width: this.paper.width + "mm", height: this.paper.height + "mm", + "background-repeat": "no-repeat!important", }); }, async getPaperSize() { @@ -300,8 +430,8 @@ }); $("#paperSize").append("") this.allSize.forEach(x => { - $("#paperSize").append("") - $("#printSize").append(""); + $("#paperSize").append("") + $("#printSize").append(""); }) }, async getElements() { @@ -348,9 +478,19 @@ self.styleID = e.target.getAttribute("data-value") self.changeStyle(e.target.getAttribute("data-value")); let style = self.allStyle.find(x => x.styleID == e.target.getAttribute("data-value")); - let size = self.allSize.find(x => x.name == style.paperSize); - self.paper.width = size.width; - self.paper.height = size.height; + if (style) { + let size = self.allSize.find(x => x.name == style.paperSize); + if (size) { + self.paper.width = size.width; + self.paper.height = size.height; + } else { + self.paper.width = 100; + self.paper.height = 272; + } + } else { + self.paper.width = 100; + self.paper.height = 272; + } }); }, @@ -413,6 +553,9 @@ changeBg() { let path = this.bg.find(el => el.name == $("#backendInp").val()) $(".tablet-paper").css({ 'background-image': 'url(' + path.path + ')', 'background-size': '100% 100%' }) + }, + changePrintSize() { + }, changePaper() { let paperSize = $("#paperSize").val() @@ -751,7 +894,7 @@ let detail = [ ]; - + this.elements.forEach((el) => { detail.push({ elementID: el.id, startX: el.x.toString(), startY: el.y.toString(), fontSize: el.style.fontSize, fontFamily: el.style.fontFamily, @@ -759,7 +902,10 @@ isActive: el.style.visibility, width: el.width, height: el.height, textWidth: el.textWidth, textHeight: el.textHeight }); }); - + let sID = this.styleID + if (sID == "20260310100234") { + this.styleID="" + } let master = { styleID: this.styleID, styleName: $("#styleName").val(), paperSize: $("#paperSize").val(), backendImg: $("#backendInp").val(), printSize: $("#printSize").val(), printMode: $("#printMode").val(),