This commit is contained in:
2026-03-06 19:08:25 +08:00
parent 63ca92e470
commit 27f936d4a9
5 changed files with 551 additions and 16 deletions

View File

@@ -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;
/// <summary>
/// StyleDataAccess 的摘要描述
/// </summary>
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<TabletElement>(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<TabletStyleDetail>(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<TabletStyle>(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<TabletStyleDetail> 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;
}
}

View File

@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Style 的摘要描述
/// </summary>
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; }
}

View File

@@ -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;
/// <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;
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;
list.Add(tsd);
}
if (mode == "add")
{
object[] obj= new StyleDataAccess().AddStyle(ts,list);
}
return Ok();
}
}