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.

405 lines
17 KiB

  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. using Newtonsoft.Json;
  18. namespace NFine.Web.Areas.WMS.Controllers
  19. {
  20. public class PrintController : ControllerBase
  21. {
  22. PrintApp App = new PrintApp();
  23. // GET: WMS/Print
  24. public ActionResult PrintView()
  25. {
  26. return View();
  27. }
  28. /// <summary>
  29. /// 打印数据参数:服务器的URL+打印的文件名,转化为Base64编码
  30. /// </summary>
  31. protected string strPrintData;
  32. /// <summary>
  33. /// 标识是否安装了控件
  34. /// </summary>
  35. protected bool bIsInstallPrintControl = true;
  36. /// <summary>
  37. /// 打印控件的Cookie值
  38. /// </summary>
  39. protected string strPrintControlCookie = "";
  40. /// <summary>
  41. /// 获取Url中去掉文件名的路径
  42. /// </summary>
  43. /// <returns></returns>
  44. private string GetUrlPath()
  45. {
  46. string strUrl = Request.Url.ToString();
  47. int iEnd = strUrl.LastIndexOf("/");
  48. strUrl = strUrl.Substring(0, iEnd + 1);
  49. return strUrl;
  50. }
  51. [HttpGet]
  52. [HandlerAjaxOnly]
  53. public ActionResult GetLableType()
  54. {
  55. DataTable dt = App.GetLableType();
  56. return Content(dt.ToJson());
  57. }
  58. [HttpGet]
  59. [HandlerAjaxOnly]
  60. public ActionResult GetLableSourceID()
  61. {
  62. DataTable dt = App.GetLableSourceID();
  63. return Content(dt.ToJson());
  64. }
  65. [HttpGet]
  66. [HandlerAjaxOnly]
  67. public ActionResult GetSys_LablesID(string LableType)
  68. {
  69. DataTable dt = App.GetSys_LablesID(LableType);
  70. return Content(dt.ToJson());
  71. }
  72. //打印
  73. [HttpPost]
  74. [HandlerAjaxOnly]
  75. public ActionResult PrintItemLot(string keyValue, string Parameter)
  76. {
  77. string WorkPoint = "'"+NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',')+"'";
  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. #region 打印
  97. //string[] PrintParas = Parameter.Split('|');
  98. //string LinkCols = string.Empty;
  99. //foreach (var p in PrintParas)
  100. //{
  101. // sqltxt = dr["SqlTxt"].ToString();
  102. // LinkCols= dr["LinkCols"].ToString();
  103. // if (dr["Paras"].ToString() != "")
  104. // {
  105. // string[] ps = dr["Paras"].ToString().Split(',');
  106. // for (int i = 0; i < ps.Length; i++)
  107. // {
  108. // if (!string.IsNullOrEmpty(ps[i]))
  109. // {
  110. // sqltxt = sqltxt.Replace(ps[i], p.ToString());
  111. // }
  112. // }
  113. // }
  114. // if (sqltxt.Contains("[WorkPoint]"))
  115. // {
  116. // sqltxt = sqltxt.Replace("[WorkPoint]", WorkPoint);
  117. // }
  118. //}
  119. #endregion
  120. string[] PrintParas = Parameter.Split('|');
  121. string LinkCols = string.Empty;
  122. sqltxt = dr["SqlTxt"].ToString();
  123. LinkCols = dr["LinkCols"].ToString();
  124. if (dr["Paras"].ToString() != "")
  125. {
  126. string[] ps = dr["Paras"].ToString().Split(',');
  127. for (int i = 0; i < ps.Length; i++)
  128. {
  129. if (!string.IsNullOrEmpty(ps[i]))
  130. {
  131. sqltxt = sqltxt.Replace(ps[i], PrintParas[i]);
  132. }
  133. }
  134. }
  135. if (sqltxt.Contains("[WorkPoint]"))
  136. {
  137. sqltxt = sqltxt.Replace("[WorkPoint]", WorkPoint);
  138. }
  139. string strPrintFileName = Server.MapPath("/File/LablesFile/") + ""+ FileAddress + "";
  140. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  141. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  142. if (LinkCols!="")
  143. {
  144. pJson.MasterOptions(1, ""+ LinkCols + "", false); //主从关系
  145. }
  146. //pJson.CheckRegister("注册姓名", "8ECCCD6A1302DFEE1A6456A5D"); //注册信息
  147. //pJson.AddPrintParam("ShopName", "测试酒楼");
  148. //pJson.AddPrintParam("PrintDepositAdd", "说明:本单据为贵客押金收取凭证,盖章有效。退房时请出示,遗失者自负,请妥善保存。退房时间为12:00时,延时退房18:00时以前按半天房费收取,18:00时以后算全天房价。押金单有效期为一个月,过期作废。 贵重物品请交前台寄存,未寄存丢失自负。 谢谢!");
  149. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  150. string strSql = sqltxt;
  151. //DataTable dtCashLog = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  152. DataSet dtCashLog = DbHelper.GetDataSet( CommandType.Text, strSql);
  153. DataTable dt1 = null;
  154. DataTable dt2 = null;
  155. DataTable dt3 = null;
  156. string strPrintTempFile = "";
  157. if (dtCashLog.Tables.Count > 0 && dtCashLog.Tables.Count <= 1)
  158. {
  159. dt1 = dtCashLog.Tables[0];
  160. strPrintTempFile = pJson.ShowReport(dt1);
  161. }
  162. if (dtCashLog.Tables.Count > 1 && dtCashLog.Tables.Count<=2)
  163. {
  164. dt1 = dtCashLog.Tables[0];
  165. dt2 = dtCashLog.Tables[1];
  166. strPrintTempFile = pJson.ShowReport(dt1,dt2);
  167. }
  168. if (dtCashLog.Tables.Count > 2)
  169. {
  170. dt1 = dtCashLog.Tables[0];
  171. dt2 = dtCashLog.Tables[1];
  172. dt3 = dtCashLog.Tables[2];
  173. strPrintTempFile = pJson.ShowReport(dt1, dt2,dt3);
  174. }
  175. //string strPrintTempFile = pJson.ShowReport(dt1, dt2); //产生JSON文件内容
  176. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  177. string strServerURL = GetUrlPath() + "PrintTemp/";
  178. string strData = strServerURL + strPrintTempFile;
  179. strPrintData = PrintFunction.EnBase64(strData);
  180. var JsonData = new
  181. {
  182. strPrintData_1 = strPrintData,
  183. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  184. strPrintControlCookie_1 = strPrintControlCookie
  185. };
  186. //多站点
  187. //string sql = @"UPDATE dbo.ICSInventoryLot
  188. // SET PrintTimes=ISNULL(PrintTimes,0)+1,
  189. // LastPrintUser='',
  190. // LastPrintTime=GETDATE()
  191. // WHERE ID IN (" + keyValue.TrimEnd(',') + ") and WorkPoint in ('" + WorkPoint.TrimEnd(',') + "')";
  192. //SqlHelper.ExecuteNonQuery(sql);
  193. return Content(JsonData.ToJson());
  194. }
  195. [HttpPost]
  196. [HandlerAjaxOnly]
  197. public ActionResult YLPrintItemLot(string keyValue, string Parameter)
  198. {
  199. string WorkPoint = "'" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',') + "'";
  200. string sqltxt = "";
  201. //Parameter = Parameter.Substring(1, Parameter.Length - 3);
  202. var queryParam = keyValue.ToJObject();
  203. List<DbParameter> parameter = new List<DbParameter>();
  204. var Sys_LablesID = queryParam["Sys_LablesID"].ToString();
  205. List<PrintPara> parasList = new List<PrintPara>();
  206. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  207. string sqlValue = @"select LableSourceID,FileAddress from Sys_Lables where ID='{0}'";
  208. sqlValue = string.Format(sqlValue, Sys_LablesID);
  209. DataRow drV = SqlHelper.GetDataRowBySql(sqlValue);
  210. string LableSourceID = drV["LableSourceID"].ToString();
  211. string FileAddress = drV["FileAddress"].ToString();
  212. string sqlLableDataSource = @"SELECT ID,WorkPointCode,OtherDataBaseID,WorkPointDataFlag,
  213. SysDataFlag,SqlTxt,SourceName,FormatSqlTxt,Paras,DbParas,LinkCols,CreateUserID,
  214. CreateDate,ModifyUserID,ModifyDate,Link2Cols FROM dbo.Sys_LableDataSource
  215. where ID='{0}'";
  216. sqlLableDataSource = string.Format(sqlLableDataSource, LableSourceID);
  217. DataRow dr = SqlHelper.GetDataRowBySql(sqlLableDataSource);
  218. string LinkCols = string.Empty;
  219. LinkCols = dr["LinkCols"].ToString();
  220. string strPrintFileName = Server.MapPath("/File/LablesFile/") + "" + FileAddress + "";
  221. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  222. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  223. if (LinkCols != "")
  224. {
  225. pJson.MasterOptions(1, "" + LinkCols + "", false); //主从关系
  226. }
  227. //pJson.CheckRegister("注册姓名", "8ECCCD6A1302DFEE1A6456A5D"); //注册信息
  228. //pJson.AddPrintParam("ShopName", "测试酒楼");
  229. //pJson.AddPrintParam("PrintDepositAdd", "说明:本单据为贵客押金收取凭证,盖章有效。退房时请出示,遗失者自负,请妥善保存。退房时间为12:00时,延时退房18:00时以前按半天房费收取,18:00时以后算全天房价。押金单有效期为一个月,过期作废。 贵重物品请交前台寄存,未寄存丢失自负。 谢谢!");
  230. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  231. string strSql = sqltxt;
  232. //DataTable dtCashLog = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  233. //DataSet dtCashLog = DbHelper.GetDataSet(CommandType.Text, strSql);
  234. //var jsonData = $"[{Parameter}]";
  235. //DataTable dt1 = JsonConvert.DeserializeObject<DataTable>(jsonData);
  236. DataTable dt1 = JsonConvert.DeserializeObject<DataTable>(Parameter);
  237. string strPrintTempFile = "";
  238. //if (dtCashLog.Tables.Count > 0 && dtCashLog.Tables.Count <= 1)
  239. //{
  240. // dt1 = dtCashLog.Tables[0];
  241. strPrintTempFile = pJson.ShowReport(dt1);
  242. //}
  243. //if (dtCashLog.Tables.Count > 1 && dtCashLog.Tables.Count <= 2)
  244. //{
  245. // dt1 = dtCashLog.Tables[0];
  246. // dt2 = dtCashLog.Tables[1];
  247. // strPrintTempFile = pJson.ShowReport(dt1, dt2);
  248. //}
  249. //if (dtCashLog.Tables.Count > 2)
  250. //{
  251. // dt1 = dtCashLog.Tables[0];
  252. // dt2 = dtCashLog.Tables[1];
  253. // dt3 = dtCashLog.Tables[2];
  254. // strPrintTempFile = pJson.ShowReport(dt1, dt2, dt3);
  255. //}
  256. //string strPrintTempFile = pJson.ShowReport(dt1, dt2); //产生JSON文件内容
  257. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  258. string strServerURL = GetUrlPath() + "PrintTemp/";
  259. string strData = strServerURL + strPrintTempFile;
  260. strPrintData = PrintFunction.EnBase64(strData);
  261. var JsonData = new
  262. {
  263. strPrintData_1 = strPrintData,
  264. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  265. strPrintControlCookie_1 = strPrintControlCookie
  266. };
  267. //多站点
  268. //string sql = @"UPDATE dbo.ICSInventoryLot
  269. // SET PrintTimes=ISNULL(PrintTimes,0)+1,
  270. // LastPrintUser='',
  271. // LastPrintTime=GETDATE()
  272. // WHERE ID IN (" + keyValue.TrimEnd(',') + ") and WorkPoint in ('" + WorkPoint.TrimEnd(',') + "')";
  273. //SqlHelper.ExecuteNonQuery(sql);
  274. return Content(JsonData.ToJson());
  275. }
  276. /// <summary>
  277. /// 设置控件调用的Cookie值,判断是否安装了打印控件....
  278. /// </summary>
  279. /// <param name="pJson"></param>
  280. private void SetCookieAndURL(PrintJson pJson)
  281. {
  282. bIsInstallPrintControl = false;
  283. strPrintControlCookie = "";
  284. HttpCookie pCookieInstall = Request.Cookies["InstallPrintControl"];
  285. if (pCookieInstall != null)
  286. { //Cookie存在
  287. strPrintControlCookie = pCookieInstall.Value.ToString();
  288. //以Cookie值查找在数据表中是否存在
  289. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  290. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strPrintControlCookie) };
  291. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  292. {
  293. if (drCookie.Read())
  294. { //标识为已经安装
  295. bIsInstallPrintControl = true;
  296. }
  297. drCookie.Close();
  298. }
  299. //更新Cookie的保存时间
  300. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  301. Response.SetCookie(pCookieInstall);
  302. }
  303. else
  304. {//Cookie不存在,则新建Cookie
  305. strPrintControlCookie = System.Guid.NewGuid().ToString();
  306. pCookieInstall = new HttpCookie("InstallPrintControl", strPrintControlCookie);
  307. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  308. Response.Cookies.Add(pCookieInstall);
  309. }
  310. string strUrl = Server.MapPath("/PrintTemp/") + "IsCheckInstall";
  311. pJson.SetCookieAndURL(strPrintControlCookie, strUrl);
  312. }
  313. [HttpGet]
  314. public ActionResult SelectColumnName(string BeginTime, string EndTime)
  315. {
  316. var data = App.SelectColumnName(BeginTime, EndTime);
  317. return Content(data.ToJson());
  318. }
  319. [HttpGet]
  320. public ActionResult SelectTableColumnName(string BeginTime, string EndTime)
  321. {
  322. var data = App.SelectTableColumnName(BeginTime, EndTime);
  323. return Content(data.ToJson());
  324. }
  325. [HttpGet]
  326. public ActionResult GetCnValue(string Code)
  327. {
  328. string sql = string.Empty;
  329. try
  330. {
  331. string str = App.GetCnValue(Code);
  332. var JsonData = new
  333. {
  334. content = str
  335. };
  336. return Content(JsonData.ToJson());
  337. }
  338. catch (Exception ex)
  339. {
  340. return Error(ex.Message);
  341. }
  342. }
  343. [HttpGet]
  344. [HandlerAjaxOnly]
  345. public ActionResult updatePrintStatus(string LotNo)
  346. {
  347. string msg = App.updatePrintStatus(LotNo);
  348. if (!string.IsNullOrEmpty(msg))
  349. {
  350. return Error(msg);
  351. }
  352. else
  353. {
  354. return Success("打印人、打印次数、打印时间更新成功!");
  355. }
  356. }
  357. }
  358. }