纽威
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.

278 lines
11 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
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 MUSER = "'" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  78. string sqltxt = "";
  79. Parameter = Parameter.Substring(1, Parameter.Length - 3);
  80. var queryParam = keyValue.ToJObject();
  81. List<DbParameter> parameter = new List<DbParameter>();
  82. var Sys_LablesID = queryParam["Sys_LablesID"].ToString();
  83. List<PrintPara> parasList = new List<PrintPara>();
  84. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  85. string sqlValue = @"select LableSourceID,FileAddress from Sys_Lables where ID='{0}'";
  86. sqlValue = string.Format(sqlValue, Sys_LablesID);
  87. DataRow drV = SqlHelper.GetDataRowBySql(sqlValue);
  88. string LableSourceID = drV["LableSourceID"].ToString();
  89. string FileAddress = drV["FileAddress"].ToString();
  90. string sqlLableDataSource = @"SELECT ID,WorkPointCode,OtherDataBaseID,WorkPointDataFlag,
  91. SysDataFlag,SqlTxt,SourceName,FormatSqlTxt,Paras,DbParas,LinkCols,CreateUserID,
  92. CreateDate,ModifyUserID,ModifyDate,Link2Cols FROM dbo.Sys_LableDataSource
  93. where ID='{0}'";
  94. sqlLableDataSource = string.Format(sqlLableDataSource, LableSourceID);
  95. DataRow dr = SqlHelper.GetDataRowBySql(sqlLableDataSource);
  96. //var PrintParas = Parameter.Replace(",","").Split('|').Distinct().ToArray();
  97. //foreach (var p in PrintParas)
  98. //{
  99. // sqltxt = dr["SqlTxt"].ToString();
  100. // if (dr["Paras"].ToString() != "")
  101. // {
  102. // string[] ps = dr["Paras"].ToString().Split(',');
  103. // for (int i = 0; i < ps.Length; i++)
  104. // {
  105. // if (!string.IsNullOrEmpty(ps[i]))
  106. // {
  107. // sqltxt = sqltxt.Replace(ps[i], p.ToString());
  108. // }
  109. // }
  110. // }
  111. // if (sqltxt.Contains("[WorkPoint]"))
  112. // {
  113. // sqltxt = sqltxt.Replace("[WorkPoint]", WorkPoint);
  114. // }
  115. //}
  116. var PrintParas = Parameter.Replace("|", "");
  117. sqltxt = dr["SqlTxt"].ToString();
  118. if (PrintParas != null)
  119. {
  120. string[] ps = dr["Paras"].ToString().Split(',');
  121. for (int i = 0; i < ps.Length; i++)
  122. {
  123. if (!string.IsNullOrEmpty(ps[i]))
  124. {
  125. sqltxt = sqltxt.Replace(ps[i], PrintParas);
  126. }
  127. }
  128. }
  129. if (sqltxt.Contains("[WorkPoint]"))
  130. {
  131. sqltxt = sqltxt.Replace("[WorkPoint]", WorkPoint);
  132. }
  133. if (sqltxt.Contains("[MUSER]"))
  134. {
  135. sqltxt = sqltxt.Replace("[MUSER]", MUSER);
  136. }
  137. string strPrintFileName = Server.MapPath("/File/LablesFile/") + "" + FileAddress + "";
  138. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  139. pJson.MasterOptions(1, "Code", true); //主从关系
  140. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  141. //pJson.CheckRegister("注册姓名", "8ECCCD6A1302DFEE1A6456A5D"); //注册信息
  142. //pJson.AddPrintParam("ShopName", "测试酒楼");
  143. //pJson.AddPrintParam("PrintDepositAdd", "说明:本单据为贵客押金收取凭证,盖章有效。退房时请出示,遗失者自负,请妥善保存。退房时间为12:00时,延时退房18:00时以前按半天房费收取,18:00时以后算全天房价。押金单有效期为一个月,过期作废。 贵重物品请交前台寄存,未寄存丢失自负。 谢谢!");
  144. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  145. string strSql = sqltxt;
  146. //DataTable dtCashLog = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  147. DataSet dtCashLog = DbHelper.GetDataSet(CommandType.Text, strSql);
  148. DataTable dt1 = null;
  149. DataTable dt2 = null;
  150. DataTable dt3 = null;
  151. string strPrintTempFile = "";
  152. if (dtCashLog.Tables.Count > 0 && dtCashLog.Tables.Count<=1)
  153. {
  154. dt1 = dtCashLog.Tables[0];
  155. strPrintTempFile = pJson.ShowReport(dt1);
  156. }
  157. if (dtCashLog.Tables.Count > 1 && dtCashLog.Tables.Count <= 2)
  158. {
  159. dt1 = dtCashLog.Tables[0];
  160. dt2 = dtCashLog.Tables[1];
  161. strPrintTempFile = pJson.ShowReport(dt1, dt2);
  162. }
  163. if (dtCashLog.Tables.Count > 2)
  164. {
  165. dt1 = dtCashLog.Tables[0];
  166. dt2 = dtCashLog.Tables[1];
  167. dt3 = dtCashLog.Tables[2];
  168. strPrintTempFile = pJson.ShowReport(dt1, dt2, dt3);
  169. }
  170. //string strPrintTempFile = pJson.ShowReport(dt1, dt2); //产生JSON文件内容
  171. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  172. string strServerURL = GetUrlPath() + "PrintTemp/";
  173. string strData = strServerURL + strPrintTempFile;
  174. strPrintData = PrintFunction.EnBase64(strData);
  175. var JsonData = new
  176. {
  177. strPrintData_1 = strPrintData,
  178. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  179. strPrintControlCookie_1 = strPrintControlCookie
  180. };
  181. //多站点
  182. //string sql = @"UPDATE dbo.ICSInventoryLot
  183. // SET PrintTimes=ISNULL(PrintTimes,0)+1,
  184. // LastPrintUser='',
  185. // LastPrintTime=GETDATE()
  186. // WHERE ID IN (" + keyValue.TrimEnd(',') + ") and WorkPoint in ('" + WorkPoint.TrimEnd(',') + "')";
  187. //SqlHelper.ExecuteNonQuery(sql);
  188. return Content(JsonData.ToJson());
  189. }
  190. /// <summary>
  191. /// 设置控件调用的Cookie值,判断是否安装了打印控件
  192. /// </summary>
  193. /// <param name="pJson"></param>
  194. private void SetCookieAndURL(PrintJson pJson)
  195. {
  196. bIsInstallPrintControl = false;
  197. strPrintControlCookie = "";
  198. HttpCookie pCookieInstall = Request.Cookies["InstallPrintControl"];
  199. if (pCookieInstall != null)
  200. { //Cookie存在
  201. strPrintControlCookie = pCookieInstall.Value.ToString();
  202. //以Cookie值查找在数据表中是否存在
  203. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  204. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strPrintControlCookie) };
  205. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  206. {
  207. if (drCookie.Read())
  208. { //标识为已经安装
  209. bIsInstallPrintControl = true;
  210. }
  211. drCookie.Close();
  212. }
  213. //更新Cookie的保存时间
  214. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  215. Response.SetCookie(pCookieInstall);
  216. }
  217. else
  218. {//Cookie不存在,则新建Cookie
  219. strPrintControlCookie = System.Guid.NewGuid().ToString();
  220. pCookieInstall = new HttpCookie("InstallPrintControl", strPrintControlCookie);
  221. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  222. Response.Cookies.Add(pCookieInstall);
  223. }
  224. string strUrl = Server.MapPath("/PrintTemp/") + "IsCheckInstall";
  225. pJson.SetCookieAndURL(strPrintControlCookie, strUrl);
  226. }
  227. [HttpGet]
  228. public ActionResult SelectColumnName(string BeginTime, string EndTime)
  229. {
  230. var data = App.SelectColumnName(BeginTime, EndTime);
  231. return Content(data.ToJson());
  232. }
  233. [HttpGet]
  234. public ActionResult GetCnValue(string Code)
  235. {
  236. string sql = string.Empty;
  237. try
  238. {
  239. string str = App.GetCnValue(Code);
  240. var JsonData = new
  241. {
  242. content = str
  243. };
  244. return Content(JsonData.ToJson());
  245. }
  246. catch (Exception ex)
  247. {
  248. return Error(ex.Message);
  249. }
  250. }
  251. }
  252. }