diff --git a/web/App_Code/DataAccess/StyleDataAccess.cs b/web/App_Code/DataAccess/StyleDataAccess.cs
new file mode 100644
index 0000000..574ff38
--- /dev/null
+++ b/web/App_Code/DataAccess/StyleDataAccess.cs
@@ -0,0 +1,199 @@
+using DocumentFormat.OpenXml.Office2010.Excel;
+using DocumentFormat.OpenXml.Wordprocessing;
+using MINOM.COM.Utility;
+using Model;
+using System;
+using System.Collections.Generic;
+using System.Data.SqlClient;
+using System.Linq;
+using System.Text;
+using System.Web;
+using System.Web.Http.ModelBinding;
+
+///
+/// StyleDataAccess 的摘要描述
+///
+public class StyleDataAccess
+{
+ LogUtility log=new LogUtility();
+ object[] obj = new object[] { "Y", "" ,null};
+ public StyleDataAccess()
+ {
+ //
+ // TODO: 在這裡新增建構函式邏輯
+ //
+ }
+
+ public object[] GetTabletElement(string elementID ,string name)
+ {
+ try
+ {
+ using (var context = new ezEntities())
+ {
+ StringBuilder sb = new StringBuilder();
+ SqlParameter[] sp = new SqlParameter[] { };
+
+ sb.Append("select * from TabletElement where 1=1 ");
+ if (!string.IsNullOrEmpty(elementID))
+ {
+ sb.Append("and ElementID=@ElementID ");
+ sp.Append(new SqlParameter("ElementID", elementID));
+ }
+ if (!string.IsNullOrEmpty(name))
+ {
+ sb.Append("and Name=@Name ");
+ sp.Append(new SqlParameter("Name", name));
+ }
+ var data = context.Database.SqlQuery(sb.ToString(), sp).ToList();
+ obj[2] = data;
+ }
+ }
+ catch (Exception ex)
+ {
+ log.writeErrorPath("GetTabletElement:" + ex.Message + ex.StackTrace);
+ obj[0] = "N";
+ obj[1] = ex.Message;
+ }
+
+ return obj;
+ }
+
+ public object[] GetStyleDetail(string styleID,string elementID)
+ {
+ try
+ {
+ using (var context = new ezEntities())
+ {
+ StringBuilder sb = new StringBuilder();
+ SqlParameter[] sp = new SqlParameter[] { };
+
+ sb.Append("select * from TabletStyleDetail where 1=1 ");
+ if (!string.IsNullOrEmpty(styleID))
+ {
+ sb.Append("and StyleID=@StyleID ");
+ sp.Append(new SqlParameter("StyleID", styleID));
+ }
+ if (!string.IsNullOrEmpty(elementID))
+ {
+ sb.Append("and ElementID=@ElementID ");
+ sp.Append(new SqlParameter("ElementID", elementID));
+ }
+ var data = context.Database.SqlQuery(sb.ToString(), sp).ToList();
+ obj[2] = data;
+ }
+ }
+ catch (Exception ex)
+ {
+ log.writeErrorPath("GetStyleDetail:" + ex.Message + ex.StackTrace);
+ obj[0] = "N";
+ obj[1] = ex.Message;
+ }
+
+ return obj;
+ }
+ public object[] GetStyle(string id,string name)
+ {
+ try
+ {
+ using (var context = new ezEntities())
+ {
+ StringBuilder sb = new StringBuilder();
+ SqlParameter[] sp = new SqlParameter[] { };
+
+ sb.Append("select * from TabletStyle where 1=1 ");
+ if (!string.IsNullOrEmpty(id))
+ {
+ sb.Append("and StyleID=@StyleID ");
+ sp.Append(new SqlParameter( "StyleID",id));
+ }
+ if (!string.IsNullOrEmpty(name))
+ {
+ sb.Append("and Name=@Name ");
+ sp.Append(new SqlParameter("Name", name));
+ }
+ var data= context.Database.SqlQuery(sb.ToString(), sp).ToList();
+ obj[2]= data;
+ }
+ }
+ catch (Exception ex)
+ {
+ log.writeErrorPath("GetStyle:" + ex.Message + ex.StackTrace);
+ obj[0] = "N";
+ obj[1] = ex.Message;
+ }
+ return obj;
+ }
+
+ public object[] AddStyle(TabletStyle ts, List list)
+ {
+ try
+ {
+ using (var context = new ezEntities())
+ {
+ StringBuilder sb = new StringBuilder();
+ SqlParameter[] sp = new SqlParameter[] {
+ new SqlParameter("@StyleID",ts.StyleID),
+ new SqlParameter("@Name",ts.Name),
+ new SqlParameter("@Descr",ts.Descr),
+ new SqlParameter("@PaperSize",ts.PaperSize),
+ new SqlParameter("@BackendImg",ts.BackendImg),
+ new SqlParameter("@PrintSize",ts.PrintSize),
+ new SqlParameter("@PrintMode",ts.PrintMode),
+ new SqlParameter("@Orientation",ts.Orientation),
+ new SqlParameter("@PrintPageCount",ts.PrintPageCount),
+ new SqlParameter("@CUser",""),
+ new SqlParameter("@CDate",""),
+ new SqlParameter("@CTime",""),
+ new SqlParameter("@UUser",""),
+ new SqlParameter("@UDate",""),
+ new SqlParameter("@UTime",""),
+ };
+
+ sb.Append("insert into TabletStyle (StyleID,Name,Descr,PaperSize,BackendImg,PrintSize,PrintMode,Orientation,PrintPageCount");
+ sb.Append(",CUser,CDate,CTime,UUser,UDate,UTime ) ");
+ sb.Append("values(@StyleID,@Name,@Descr,@PaperSize,@BackendImg,@PrintSize,@PrintMode,@Orientation,@PrintPageCount");
+ sb.Append(",@CUser,@CDate,@CTime,@UUser,@UDate,@UTime ) ");
+ context.Database.ExecuteSqlCommand(sb.ToString(), sp);
+
+ sb.Clear();
+ sb.Append("insert into TabletStyleDetail(StyleID,Name,Descr,ElementID,StartX,StartY,FontSize,BreakLen,FontFamily,TwoOffset,");
+ sb.Append("ThreeOffset,FourOffSet,IsActive,Width,CUser,CDate,CTime,UUser,UDate,UTime) ");
+ sb.Append("values (@StyleID,@Name,@Descr,@ElementID,@StartX,@StartY,@FontSize,@BreakLen,@FontFamily,@TwoOffset,");
+ sb.Append("@ThreeOffset,@FourOffSet,@IsActive,@Width,@CUser,@CDate,@CTime,@UUser,@UDate,@UTime) ");
+ foreach (var item in list)
+ {
+ SqlParameter[] sp1 = new SqlParameter[] {
+ new SqlParameter("@StyleID",item.StyleID),
+ new SqlParameter("@Name",item.Name),
+ new SqlParameter("@Descr",item.Descr),
+ new SqlParameter("@ElementID",item.ElementID),
+ new SqlParameter("@StartX",item.StartX),
+ new SqlParameter("@StartY",item.StartY),
+ new SqlParameter("@FontSize",item.FontSize),
+ new SqlParameter("@BreakLen",item.BreakLen),
+ new SqlParameter("@FontFamily",item.FontFamily),
+ new SqlParameter("@TwoOffset",item.TwoOffset),
+ new SqlParameter("@ThreeOffset",item.ThreeOffset),
+ new SqlParameter("@FourOffset",item.FourOffset),
+ new SqlParameter("@IsActive",item.IsActive),
+ new SqlParameter("@Width",item.Width),
+ new SqlParameter("@CUser",""),
+ new SqlParameter("@CDate",""),
+ new SqlParameter("@CTime",""),
+ new SqlParameter("@UUser",""),
+ new SqlParameter("@UDate",""),
+ new SqlParameter("@UTime",""),
+ };
+ context.Database.ExecuteSqlCommand(sb.ToString(), sp1);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ log.writeErrorPath("AddStyle:" + ex.Message+ex.StackTrace);
+ obj[0] = "N";
+ obj[1] = ex.Message;
+ }
+ return obj;
+ }
+}
\ No newline at end of file
diff --git a/web/App_Code/Entity/Style.cs b/web/App_Code/Entity/Style.cs
new file mode 100644
index 0000000..35c7be0
--- /dev/null
+++ b/web/App_Code/Entity/Style.cs
@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+///
+/// Style 的摘要描述
+///
+public class TabletStyle
+{
+ public TabletStyle()
+ {
+ //
+ // TODO: 在這裡新增建構函式邏輯
+ //
+ }
+
+ public string StyleID { get; set; }
+ public string Name { get; set; }
+ public string Descr { get; set; }
+ public string PaperSize { get; set; }
+ public string BackendImg { get; set; }
+ public string PrintSize { get; set; }
+ public string PrintMode { get; set; }
+ public string Orientation { get; set; }
+ public string PrintPageCount { get; set; }
+ public string CUser { get; set; }
+ public string CDate { get; set; }
+ public string CTime { get; set; }
+ public string UUser { get; set; }
+ public string UDate { get; set; }
+ public string UTime { get; set; }
+}
+
+public class TabletStyleDetail
+{
+ public TabletStyleDetail() { }
+ public string StyleID { get; set; }
+ public string Name { get; set; }
+ public string Descr { get; set; }
+ public string ElementID { get; set; }
+ public string StartX { get; set; }
+ public string StartY { get; set; }
+ public string FontSize { get; set; }
+ public string FontFamily { get; set; }
+ public string TwoOffset { get; set; }
+ public string ThreeOffset { get; set; }
+ public string FourOffset { get; set; }
+ public string IsActive { get; set; }
+ public string Width { get; set; }
+ public string BreakLen { get; set; }
+ public string CUser { get; set; }
+ public string CDate { get; set; }
+ public string CTime { get; set; }
+ public string UUser { get; set; }
+ public string UDate { get; set; }
+ public string UTime { get; set; }
+}
+
+public class TabletElement
+{
+ public TabletElement() { }
+ public string ElementID { get; set; }
+ public string Name { get; set; }
+ public string ElementType { get; set; }
+ public string SampleContent { get; set; }
+ public string CUser { get; set; }
+ public string CDate { get; set; }
+ public string CTime { get; set; }
+ public string UUser { get; set; }
+ public string UDate { get; set; }
+ public string UTime { get; set; }
+}
\ No newline at end of file
diff --git a/web/App_Code/api/designerController.cs b/web/App_Code/api/designerController.cs
new file mode 100644
index 0000000..905455f
--- /dev/null
+++ b/web/App_Code/api/designerController.cs
@@ -0,0 +1,133 @@
+using Microsoft.Ajax.Utilities;
+using MINOM.COM.Utility;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Web;
+using System.Web.Http;
+
+///
+/// designerController 的摘要描述
+///
+public class designerController:ApiController
+{
+ public designerController()
+ {
+ //
+ // TODO: 在這裡新增建構函式邏輯
+ //
+ }
+
+ [HttpPost]
+ [Route("api/tablet/GetTabletElement")]
+ public IHttpActionResult GetTabletElement([FromBody] dynamic data)
+ {
+ LogUtility log = new LogUtility();
+ var json = data;
+ string elementID = (json == null || json.elementID == null) ? "" : (string)json.elementID;
+ object[] obj = new StyleDataAccess().GetTabletElement(elementID, "");
+ if (obj[0].ToString() == "Y")
+ {
+ return Ok(new { result = "Y", data = obj[2] });
+ }
+ else
+ {
+ return Ok(new { result = "N", message = obj[1] });
+ //throw new HttpResponseException(HttpStatusCode.NotFound);
+ }
+ //return Ok(data);
+ }
+
+ [HttpPost]
+ [Route("api/tablet/GetStyleDetailData")]
+ public IHttpActionResult GetStyleDetailData([FromBody] dynamic data)
+ {
+ LogUtility log = new LogUtility();
+ var json = data;
+ string styleID = (json == null || json.styleID == null) ? "" : (string)json.styleID;
+ object[] obj = new StyleDataAccess().GetStyleDetail(styleID, "");
+ if (obj[0].ToString() == "Y")
+ {
+ return Ok(new { result = "Y", data = obj[2] });
+ }
+ else
+ {
+ return Ok(new { result = "N", message = obj[1] });
+ //throw new HttpResponseException(HttpStatusCode.NotFound);
+ }
+ //return Ok(data);
+ }
+
+ [HttpPost]
+ [Route("api/tablet/GetStyleData")]
+ public IHttpActionResult GetStyleData([FromBody] dynamic data)
+ {
+ LogUtility log = new LogUtility();
+
+ object[] obj=new StyleDataAccess().GetStyle("","");
+ if (obj[0].ToString()=="Y")
+ {
+ return Ok(new { result = "Y", data = obj[2] });
+ }
+ else
+ {
+ return Ok(new { result = "N", message = obj[1] });
+ //throw new HttpResponseException(HttpStatusCode.NotFound);
+ }
+ //return Ok(data);
+ }
+
+ [HttpPost]
+ [Route("api/tablet/SavDegignerData")]
+ public IHttpActionResult SavDegignerData([FromBody] dynamic data)
+ {
+ LogUtility log=new LogUtility();
+ var json = data;
+ //json.detail.Children()
+ log.writeLogPath((string)json.styleName);
+ TabletStyle ts=new TabletStyle();
+ List list=new List();
+ ts.StyleID = (json == null || json.styleID == null) ? "" : (string) json.styleID;
+ string mode = "edit";
+ if (string.IsNullOrEmpty(ts.StyleID))
+ {
+ ts.StyleID = DateTime.Now.ToString("yyyyMMddHHmmss");
+ mode = "add";
+ }
+ ts.Name = (json == null || json.styleName == null) ? "" : (string)json.styleName;
+ ts.Descr = (json == null || json.descr == null) ? "" : (string)json.descr;
+ ts.PaperSize = (json == null || json.paperSize == null) ? "" : (string)json.paperSize;
+ ts.BackendImg = (json == null || json.backendImg == null) ? "" : (string)json.backendImg;
+ ts.PrintSize = (json == null || json.printSize == null) ? "" : (string)json.printSize;
+ ts.Orientation = (json == null || json.orientation == null) ? "" : (string)json.orientation;
+ ts.PrintPageCount = (json == null || json.printPageCount == null) ? "" : (string)json.printPageCount;
+ ts.PrintMode = (json == null || json.printMode == null) ? "" : (string)json.printMode;
+ foreach (var item in json.detail.Children())
+ {
+ TabletStyleDetail tsd = new TabletStyleDetail();
+ tsd.StyleID=ts.StyleID;
+ tsd.Name=item.name==null?"":(string)item.name;
+ tsd.Descr = item.descr == null ? "" : (string)item.descr;
+ tsd.ElementID = item.elementID == null ? "" : (string)item.elementID;
+ tsd.StartX = item.startX == null ? "" : (string)item.startX;
+ tsd.StartY = item.startY == null ? "" : (string)item.startY;
+ tsd.FontSize = item.fontSize == null ? "" : (string)item.fontSize;
+ 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.TwoOffset = item.twoOffset == null ? "" : (string)item.twoOffset;
+ tsd.ThreeOffset = item.threeOffset == null ? "" : (string)item.threeOffset;
+ tsd.FourOffset = item.fourOffset == null ? "" : (string)item.fourOffset;
+ tsd.IsActive = item.isActive == null ? "" : (string)item.isActive;
+ list.Add(tsd);
+ }
+ if (mode == "add")
+ {
+ object[] obj= new StyleDataAccess().AddStyle(ts,list);
+ }
+ return Ok();
+ }
+ }
\ No newline at end of file
diff --git a/web/admin/item/TabletDesigner.aspx b/web/admin/item/TabletDesigner.aspx
index 8c6778d..fcd6838 100644
--- a/web/admin/item/TabletDesigner.aspx
+++ b/web/admin/item/TabletDesigner.aspx
@@ -18,7 +18,7 @@
-
-
+
@@ -185,9 +198,15 @@
{ name: "紅1", path: "../../admin/print/html/tablet-2.svg" },
{ name: "紅2", path: "../../admin/print/html/tablet-2B.svg" }
],
+ allStyle: [
+ ],
+ tabletElements: [
+ ],
orientation: "portrait",
init() {
//$(".tablet-element").draggable({});
+ this.getElements();
+ this.getStyles();
this.bindEvents();
this.loadConfig();
this.bindBackend();
@@ -209,7 +228,6 @@
$("#paperOrientation").html("" + ori + "");
let paperSize = $("#paperSize").val()
-
let size = this.allSize.find(x => x.name == paperSize)
console.log(paperSize, size);
this.paper.width = this.orientation == "portrait" ? size.width : size.height;
@@ -220,8 +238,95 @@
height: this.paper.height + "mm",
});
},
- changeStyle() {//切換版型
+ async getElements() {
+ await axios
+ .post(HTTP_HOST + 'api/tablet/GetTabletElement', {})
+ .then(response => {
+ console.log(response);
+ //if (response.result=="Y") {
+ if (response.status == "200") {
+ let data = response.data;
+ if (data.result == "Y") {
+ data.data.forEach(x => {
+ this.tabletElements.push(x);
+ }
+ }
+ }
+ });
+ },
+ async getStyles() {
+ await axios
+ .post(HTTP_HOST + 'api/tablet/GetStyleData', {})
+ .then(response => {
+ console.log(response);
+ //if (response.result=="Y") {
+ if (response.status == "200") {
+ let data = response.data;
+ if (data.result == "Y") {
+ data.data.forEach(x => {
+ this.allStyle.push(x);
+ $(".style-menu").append("" + x.name + "");
+ });
+ this.bindDropdown();
+ }
+ }
+ //}
+ });
+ },
+ bindDropdown() {
+ let self = this;
+ $(".style-menu li").on("click", function (e) {
+ $(".style-menu li").removeClass('active');
+ $(this).addClass('active');
+ console.log(e.target.textContent, $(this));
+ $("#styleName").val(e.target.textContent);
+ 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;
+
+ });
+ },
+ async changeStyle(id) {//切換版型,抓回明細
+ let self = this;
+ this.elements.length = 0;
+ let obj = this.elements
+ await axios
+ .post(HTTP_HOST + 'api/tablet/GetStyleDetailData', {})
+ .then(response => {
+ if (response.status == "200") {
+ let data = response.data;
+ if (data.result == "Y") {
+ let details = data.data;
+
+ $(".tablet-paper").empty()
+ details.forEach(el => {
+ let te=self.tabletElements.find(x=>x.elementID==el.elementID);
+ let config = {
+ id: el.elementID,
+ type: te.elementType,
+ text: te.sampleContent,
+ x: el.startX, y: el.startY,
+ style: {
+ fontSize: 24,
+ fontFamily: "Kaiti", isVertical : true,
+ letterSpacing : 5, lineHeight : 1.5,
+ visibility: el.isActive
+ },
+ width: el.width,
+ breakLen:el.breakLen
+ };
+
+ obj.push(config)
+
+ })
+
+ this.render();
+ }
+ }
+ });
},
changeBg() {
let path = this.bg.find(el => el.name == $("#backendInp").val())
@@ -243,6 +348,11 @@
// 文字變更連動渲染
$('#inp-text').on('input', (e) => this.updateActive('text', $(e.target).val()));
$('#inp-size').on('input', (e) => this.updateActive('fontSize', $(e.target).val()));
+ $('#width').on('input', (e) => this.updateActive('width', $(e.target).val()))
+ $('#2offset').on('input', (e) => this.updateActive('2offset', $(e.target).val()))
+ $('#3offset').on('input', (e) => this.updateActive('3offset', $(e.target).val()))
+ $('#4offset').on('input', (e) => this.updateActive('4offset', $(e.target).val()))
+ $('#breakLen').on('input', (e) => this.updateActive('breakLen', $(e.target).val()))
$(document).on('mousedown', '.tablet-element', (e) => {
e.stopPropagation();
this.select($(e.currentTarget).attr('id'));
@@ -359,17 +469,24 @@
$('#inp-size').val(el.style.fontSize);
$('#xPosition').val(el.x);
$("#yPosition").val(el.y);
- $('#TwoOffset').val(el.TwoOffset);
- $("#ThreeOffset").val(el.ThreeOffset);
- $("#FourOffset").val(el.FourOffset);
+ $('#2offset').val(el.twoOffset);
+ $("#3offset").val(el.threeOffset);
+ $("#4offset").val(el.fourOffset);
+ $("#breakLen").val(el.breakLen);
+ $("#width").val(el.width);
//this.render();
},
updateActive(key, val) {
const el = this.elements.find(x => x.id === this.activeId);
- console.log(this.activeId, el)
+ console.log("updateActive:",this.activeId, el,key,val)
if (key === 'fontSize') el.style.fontSize = parseFloat(val);
+ else if (key === 'width') el.width = parseFloat(val);
+ else if (key === 'breakLen') el.breakLen = parseInt(val);
+ else if (key === '2offset') el.twoOffset = parseFloat(val);
+ else if (key === '3offset') el.threeOffset = parseFloat(val);
+ else if (key === '4offset') el.fourOffset = parseFloat(val);
else el[key] = val;
if (el.type == "roster") {
const names = el.text.split('\n').filter(s => s.trim());
@@ -468,12 +585,8 @@
}
})
},
- saveStyle() {
- let master = {
- styleID: "", styleName: $("#styleName").val(), paperSize: $("#paperSize").val(),
- backendImg: $("#backendInp").val(), printSize: $("#printSize").val(), printMode: $("#printMode").val(),
- orientation: $("#paperOrientation").val(), printPageCount: $("#perpage").val()
- }
+ async saveStyle() {
+
let detail = [
];
@@ -482,11 +595,22 @@
detail.push({
elementID: el.id, startX: el.x, startY: el.y, fontSize: el.style.fontSize, fontFamily: el.style.fontFamily,
breakLen: el.breakLen, twoOffset: el.twoOffset, threeOffset: el.threeOffset, fourOffset: el.fourOffset,
- isActive: el.style.visibility
+ isActive: el.style.visibility,width:el.width
});
});
- console.log(master,detail);
+ let master = {
+ styleID: "", styleName: $("#styleName").val(), paperSize: $("#paperSize").val(),
+ backendImg: $("#backendInp").val(), printSize: $("#printSize").val(), printMode: $("#printMode").val(),
+ orientation: $("#paperOrientation").val(), printPageCount: $("#perpage").val(),
+ detail: detail
+ }
+ console.log(master);
+ await axios
+ .post(HTTP_HOST + 'api/tablet/SavDegignerData', master)
+ .then(response => {
+ console.log(response);
+ });
}
};
diff --git a/web/admin/item/TabletDesigner.aspx.cs b/web/admin/item/TabletDesigner.aspx.cs
index 85355d2..ddf0e33 100644
--- a/web/admin/item/TabletDesigner.aspx.cs
+++ b/web/admin/item/TabletDesigner.aspx.cs
@@ -23,6 +23,7 @@ public class TabletElement
public double? threeOffset { get; set; }
public double? fourOffset { get; set; }
public int? breakLen { get; set; }
+
}
public class ElementStyle
@@ -43,7 +44,12 @@ public partial class admin_item_TabletDesigner :MyWeb.config
{
}
+ [WebMethod]
+ public static string SaveDesigner()
+ {
+ return "";
+ }
[WebMethod]
public static string GetConfig()
{