Files
17168ERP/web/App_Code/api/designerController.cs
2026-03-13 17:59:14 +08:00

245 lines
10 KiB
C#

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;
/// <summary>
/// designerController 的摘要描述
/// </summary>
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<JObject>()
log.writeLogPath((string)json.styleName);
TabletStyle ts = new TabletStyle();
List<TabletStyleDetail> list = new List<TabletStyleDetail>();
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;
ts.RosterLimit=(json == null || json.rosterLimit == null) ? "" : (string)json.rosterLimit;
foreach (var item in json.detail.Children<JObject>())
{
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.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;
tsd.IsActive = item.isActive == null ? "" : (string)item.isActive;
list.Add(tsd);
}
if (mode == "add")
{
object[] obj = new StyleDataAccess().AddStyle(ts, list);
}
return Ok();
}
[HttpPost]
[Route("api/tablet/UpdateDegignerData")]
public IHttpActionResult UpdateDegignerData([FromBody] dynamic data)
{
LogUtility log = new LogUtility();
var json = data;
//json.detail.Children<JObject>()
log.writeLogPath((string)json.styleName);
TabletStyle ts = new TabletStyle();
List<TabletStyleDetail> list = new List<TabletStyleDetail>();
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;
ts.RosterLimit = (json == null || json.rosterLimit == null) ? "" : (string)json.rosterLimit;
foreach (var item in json.detail.Children<JObject>())
{
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;
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;
list.Add(tsd);
}
object[] obj = new StyleDataAccess().UpdateStyle(ts, list);
return Ok();
}
[HttpPost]
[Route("api/tablet/GetPaperSize")]
public IHttpActionResult GetPaperSize([FromBody] dynamic data)
{
LogUtility log = new LogUtility();
object[] obj = new StyleDataAccess().GetTabletPaper("", "");
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/SavePaperSize")]
public IHttpActionResult SavePaperSize([FromBody] dynamic data)
{
LogUtility log = new LogUtility();
var json = data;
//json.detail.Children<JObject>()
log.writeLogPath((string)json.styleName);
TabletPaperSize tps = new TabletPaperSize();
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.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);
return Ok();
}
}