纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

249 lines
10 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. using NFine.Application.WMS;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Web;
  8. using System.Web.Mvc;
  9. using NFine.Code;
  10. using System.Data.SqlClient;
  11. using NFine.Data.Extensions;
  12. using System.Data.OleDb;
  13. using System.Configuration;
  14. using ICS.Application.Entity;
  15. using NFine.Domain._03_Entity.WMS;
  16. using System.Data.Common;
  17. namespace NFine.Web.Areas.WMS.Controllers
  18. {
  19. public class PrintController : ControllerBase
  20. {
  21. PrintApp App = new PrintApp();
  22. // GET: WMS/Print
  23. public ActionResult PrintView()
  24. {
  25. return View();
  26. }
  27. /// <summary>
  28. /// 打印数据参数:服务器的URL+打印的文件名,转化为Base64编码
  29. /// </summary>
  30. protected string strPrintData;
  31. /// <summary>
  32. /// 标识是否安装了控件
  33. /// </summary>
  34. protected bool bIsInstallPrintControl = true;
  35. /// <summary>
  36. /// 打印控件的Cookie值
  37. /// </summary>
  38. protected string strPrintControlCookie = "";
  39. /// <summary>
  40. /// 获取Url中去掉文件名的路径
  41. /// </summary>
  42. /// <returns></returns>
  43. private string GetUrlPath()
  44. {
  45. string strUrl = Request.Url.ToString();
  46. int iEnd = strUrl.LastIndexOf("/");
  47. strUrl = strUrl.Substring(0, iEnd + 1);
  48. return strUrl;
  49. }
  50. [HttpGet]
  51. [HandlerAjaxOnly]
  52. public ActionResult GetLableType()
  53. {
  54. DataTable dt = App.GetLableType();
  55. return Content(dt.ToJson());
  56. }
  57. [HttpGet]
  58. [HandlerAjaxOnly]
  59. public ActionResult GetLableSourceID()
  60. {
  61. DataTable dt = App.GetLableSourceID();
  62. return Content(dt.ToJson());
  63. }
  64. [HttpGet]
  65. [HandlerAjaxOnly]
  66. public ActionResult GetSys_LablesID(string LableType)
  67. {
  68. DataTable dt = App.GetSys_LablesID(LableType);
  69. return Content(dt.ToJson());
  70. }
  71. //打印
  72. [HttpPost]
  73. [HandlerAjaxOnly]
  74. public ActionResult PrintItemLot(string keyValue, string Parameter)
  75. {
  76. string WorkPoint = "'"+NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',')+"'";
  77. string sqltxt = "";
  78. Parameter = Parameter.Substring(1, Parameter.Length - 3);
  79. var queryParam = keyValue.ToJObject();
  80. List<DbParameter> parameter = new List<DbParameter>();
  81. var Sys_LablesID = queryParam["Sys_LablesID"].ToString();
  82. List<PrintPara> parasList = new List<PrintPara>();
  83. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  84. string sqlValue = @"select LableSourceID,FileAddress from Sys_Lables where ID='{0}'";
  85. sqlValue = string.Format(sqlValue, Sys_LablesID);
  86. DataRow drV = SqlHelper.GetDataRowBySql(sqlValue);
  87. string LableSourceID = drV["LableSourceID"].ToString();
  88. string FileAddress= drV["FileAddress"].ToString();
  89. string sqlLableDataSource = @"SELECT ID,WorkPointCode,OtherDataBaseID,WorkPointDataFlag,
  90. SysDataFlag,SqlTxt,SourceName,FormatSqlTxt,Paras,DbParas,LinkCols,CreateUserID,
  91. CreateDate,ModifyUserID,ModifyDate,Link2Cols FROM dbo.Sys_LableDataSource
  92. where ID='{0}'";
  93. sqlLableDataSource= string.Format(sqlLableDataSource, LableSourceID);
  94. DataRow dr = SqlHelper.GetDataRowBySql(sqlLableDataSource);
  95. string[] PrintParas = Parameter.Split('|');
  96. foreach (var p in PrintParas)
  97. {
  98. sqltxt = dr["SqlTxt"].ToString();
  99. if (dr["Paras"].ToString() != "")
  100. {
  101. string[] ps = dr["Paras"].ToString().Split(',');
  102. for (int i = 0; i < ps.Length; i++)
  103. {
  104. if (!string.IsNullOrEmpty(ps[i]))
  105. {
  106. sqltxt = sqltxt.Replace(ps[i], p.ToString());
  107. }
  108. }
  109. }
  110. if (sqltxt.Contains("[WorkPoint]"))
  111. {
  112. sqltxt = sqltxt.Replace("[WorkPoint]", WorkPoint);
  113. }
  114. }
  115. string strPrintFileName = Server.MapPath("/File/LablesFile/") + ""+ FileAddress + "";
  116. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  117. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  118. //pJson.CheckRegister("注册姓名", "8ECCCD6A1302DFEE1A6456A5D"); //注册信息
  119. //pJson.AddPrintParam("ShopName", "测试酒楼");
  120. //pJson.AddPrintParam("PrintDepositAdd", "说明:本单据为贵客押金收取凭证,盖章有效。退房时请出示,遗失者自负,请妥善保存。退房时间为12:00时,延时退房18:00时以前按半天房费收取,18:00时以后算全天房价。押金单有效期为一个月,过期作废。 贵重物品请交前台寄存,未寄存丢失自负。 谢谢!");
  121. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  122. string strSql = sqltxt;
  123. //DataTable dtCashLog = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  124. DataSet dtCashLog = DbHelper.GetDataSet( CommandType.Text, strSql);
  125. DataTable dt1 = null;
  126. DataTable dt2 = null;
  127. DataTable dt3 = null;
  128. string strPrintTempFile = "";
  129. if (dtCashLog.Tables.Count>0)
  130. {
  131. dt1 = dtCashLog.Tables[0];
  132. strPrintTempFile = pJson.ShowReport(dt1);
  133. }
  134. if (dtCashLog.Tables.Count > 1)
  135. {
  136. dt2 = dtCashLog.Tables[1];
  137. strPrintTempFile = pJson.ShowReport(dt1,dt2);
  138. }
  139. if (dtCashLog.Tables.Count > 2)
  140. {
  141. dt3 = dtCashLog.Tables[2];
  142. strPrintTempFile = pJson.ShowReport(dt1, dt2,dt3);
  143. }
  144. //string strPrintTempFile = pJson.ShowReport(dt1, dt2); //产生JSON文件内容
  145. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  146. string strServerURL = GetUrlPath() + "PrintTemp/";
  147. string strData = strServerURL + strPrintTempFile;
  148. strPrintData = PrintFunction.EnBase64(strData);
  149. var JsonData = new
  150. {
  151. strPrintData_1 = strPrintData,
  152. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  153. strPrintControlCookie_1 = strPrintControlCookie
  154. };
  155. //多站点
  156. //string sql = @"UPDATE dbo.ICSInventoryLot
  157. // SET PrintTimes=ISNULL(PrintTimes,0)+1,
  158. // LastPrintUser='',
  159. // LastPrintTime=GETDATE()
  160. // WHERE ID IN (" + keyValue.TrimEnd(',') + ") and WorkPoint in ('" + WorkPoint.TrimEnd(',') + "')";
  161. //SqlHelper.ExecuteNonQuery(sql);
  162. return Content(JsonData.ToJson());
  163. }
  164. /// <summary>
  165. /// 设置控件调用的Cookie值,判断是否安装了打印控件
  166. /// </summary>
  167. /// <param name="pJson"></param>
  168. private void SetCookieAndURL(PrintJson pJson)
  169. {
  170. bIsInstallPrintControl = false;
  171. strPrintControlCookie = "";
  172. HttpCookie pCookieInstall = Request.Cookies["InstallPrintControl"];
  173. if (pCookieInstall != null)
  174. { //Cookie存在
  175. strPrintControlCookie = pCookieInstall.Value.ToString();
  176. //以Cookie值查找在数据表中是否存在
  177. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  178. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strPrintControlCookie) };
  179. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  180. {
  181. if (drCookie.Read())
  182. { //标识为已经安装
  183. bIsInstallPrintControl = true;
  184. }
  185. drCookie.Close();
  186. }
  187. //更新Cookie的保存时间
  188. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  189. Response.SetCookie(pCookieInstall);
  190. }
  191. else
  192. {//Cookie不存在,则新建Cookie
  193. strPrintControlCookie = System.Guid.NewGuid().ToString();
  194. pCookieInstall = new HttpCookie("InstallPrintControl", strPrintControlCookie);
  195. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  196. Response.Cookies.Add(pCookieInstall);
  197. }
  198. string strUrl = Server.MapPath("/PrintTemp/") + "IsCheckInstall";
  199. pJson.SetCookieAndURL(strPrintControlCookie, strUrl);
  200. }
  201. [HttpGet]
  202. public ActionResult SelectColumnName(string BeginTime, string EndTime)
  203. {
  204. var data = App.SelectColumnName(BeginTime, EndTime);
  205. return Content(data.ToJson());
  206. }
  207. [HttpGet]
  208. public ActionResult GetCnValue(string Code)
  209. {
  210. string sql = string.Empty;
  211. try
  212. {
  213. string str = App.GetCnValue(Code);
  214. var JsonData = new
  215. {
  216. content = str
  217. };
  218. return Content(JsonData.ToJson());
  219. }
  220. catch (Exception ex)
  221. {
  222. return Error(ex.Message);
  223. }
  224. }
  225. }
  226. }