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

410 lines
18 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. #region 打印(主从关系动态指定)
  72. //[HttpPost]
  73. //[HandlerAjaxOnly]
  74. //public ActionResult PrintItemLotBak(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. // string LinkCols = dr["LinkCols"].ToString();
  119. // if (PrintParas != null)
  120. // {
  121. // string[] ps = dr["Paras"].ToString().Split(',');
  122. // for (int i = 0; i < ps.Length; i++)
  123. // {
  124. // if (!string.IsNullOrEmpty(ps[i]))
  125. // {
  126. // sqltxt = sqltxt.Replace(ps[i], PrintParas);
  127. // }
  128. // }
  129. // }
  130. // if (sqltxt.Contains("[WorkPoint]"))
  131. // {
  132. // sqltxt = sqltxt.Replace("[WorkPoint]", WorkPoint);
  133. // }
  134. // if (sqltxt.Contains("[MUSER]"))
  135. // {
  136. // sqltxt = sqltxt.Replace("[MUSER]", MUSER);
  137. // }
  138. // string strPrintFileName = Server.MapPath("/File/LablesFile/") + "" + FileAddress + "";
  139. // PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  140. // if (LinkCols != "")
  141. // {
  142. // pJson.MasterOptions(1, "" + LinkCols + "", false); //主从关系
  143. // }
  144. // pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  145. // //pJson.CheckRegister("注册姓名", "8ECCCD6A1302DFEE1A6456A5D"); //注册信息
  146. // //pJson.AddPrintParam("ShopName", "测试酒楼");
  147. // //pJson.AddPrintParam("PrintDepositAdd", "说明:本单据为贵客押金收取凭证,盖章有效。退房时请出示,遗失者自负,请妥善保存。退房时间为12:00时,延时退房18:00时以前按半天房费收取,18:00时以后算全天房价。押金单有效期为一个月,过期作废。 贵重物品请交前台寄存,未寄存丢失自负。 谢谢!");
  148. // SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  149. // string strSql = sqltxt;
  150. // //DataTable dtCashLog = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  151. // DataSet dtCashLog = DbHelper.GetDataSet(CommandType.Text, strSql);
  152. // DataTable dt1 = null;
  153. // DataTable dt2 = null;
  154. // DataTable dt3 = null;
  155. // string strPrintTempFile = "";
  156. // if (dtCashLog.Tables.Count > 0 && dtCashLog.Tables.Count <= 1)
  157. // {
  158. // dt1 = dtCashLog.Tables[0];
  159. // strPrintTempFile = pJson.ShowReport(dt1);
  160. // }
  161. // if (dtCashLog.Tables.Count > 1 && dtCashLog.Tables.Count <= 2)
  162. // {
  163. // dt1 = dtCashLog.Tables[0];
  164. // dt2 = dtCashLog.Tables[1];
  165. // strPrintTempFile = pJson.ShowReport(dt1, dt2);
  166. // }
  167. // if (dtCashLog.Tables.Count > 2)
  168. // {
  169. // dt1 = dtCashLog.Tables[0];
  170. // dt2 = dtCashLog.Tables[1];
  171. // dt3 = dtCashLog.Tables[2];
  172. // strPrintTempFile = pJson.ShowReport(dt1, dt2, dt3);
  173. // }
  174. // //string strPrintTempFile = pJson.ShowReport(dt1, dt2); //产生JSON文件内容
  175. // //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  176. // string strServerURL = GetUrlPath() + "PrintTemp/";
  177. // string strData = strServerURL + strPrintTempFile;
  178. // strPrintData = PrintFunction.EnBase64(strData);
  179. // var JsonData = new
  180. // {
  181. // strPrintData_1 = strPrintData,
  182. // bIsInstallPrintControl_1 = bIsInstallPrintControl,
  183. // strPrintControlCookie_1 = strPrintControlCookie
  184. // };
  185. // //多站点
  186. // //string sql = @"UPDATE dbo.ICSInventoryLot
  187. // // SET PrintTimes=ISNULL(PrintTimes,0)+1,
  188. // // LastPrintUser='',
  189. // // LastPrintTime=GETDATE()
  190. // // WHERE ID IN (" + keyValue.TrimEnd(',') + ") and WorkPoint in ('" + WorkPoint.TrimEnd(',') + "')";
  191. // //SqlHelper.ExecuteNonQuery(sql);
  192. // return Content(JsonData.ToJson());
  193. //}
  194. #endregion
  195. //打印
  196. [HttpPost]
  197. [HandlerAjaxOnly]
  198. public ActionResult PrintItemLot(string keyValue, string Parameter)
  199. {
  200. string WorkPoint = "'" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',') + "'";
  201. string MUSER = "'" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  202. string sqltxt = "";
  203. Parameter = Parameter.Substring(1, Parameter.Length - 3);
  204. var queryParam = keyValue.ToJObject();
  205. List<DbParameter> parameter = new List<DbParameter>();
  206. var Sys_LablesID = queryParam["Sys_LablesID"].ToString();
  207. List<PrintPara> parasList = new List<PrintPara>();
  208. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  209. string sqlValue = @"select LableSourceID,FileAddress from Sys_Lables where ID='{0}'";
  210. sqlValue = string.Format(sqlValue, Sys_LablesID);
  211. DataRow drV = SqlHelper.GetDataRowBySql(sqlValue);
  212. string LableSourceID = drV["LableSourceID"].ToString();
  213. string FileAddress = drV["FileAddress"].ToString();
  214. string sqlLableDataSource = @"SELECT ID,WorkPointCode,OtherDataBaseID,WorkPointDataFlag,
  215. SysDataFlag,SqlTxt,SourceName,FormatSqlTxt,Paras,DbParas,LinkCols,CreateUserID,
  216. CreateDate,ModifyUserID,ModifyDate,Link2Cols FROM dbo.Sys_LableDataSource
  217. where ID='{0}'";
  218. sqlLableDataSource = string.Format(sqlLableDataSource, LableSourceID);
  219. DataRow dr = SqlHelper.GetDataRowBySql(sqlLableDataSource);
  220. //var PrintParas = Parameter.Replace(",","").Split('|').Distinct().ToArray();
  221. //foreach (var p in PrintParas)
  222. //{
  223. // sqltxt = dr["SqlTxt"].ToString();
  224. // if (dr["Paras"].ToString() != "")
  225. // {
  226. // string[] ps = dr["Paras"].ToString().Split(',');
  227. // for (int i = 0; i < ps.Length; i++)
  228. // {
  229. // if (!string.IsNullOrEmpty(ps[i]))
  230. // {
  231. // sqltxt = sqltxt.Replace(ps[i], p.ToString());
  232. // }
  233. // }
  234. // }
  235. // if (sqltxt.Contains("[WorkPoint]"))
  236. // {
  237. // sqltxt = sqltxt.Replace("[WorkPoint]", WorkPoint);
  238. // }
  239. //}
  240. var PrintParas = Parameter.Replace("|", "");
  241. sqltxt = dr["SqlTxt"].ToString();
  242. if (PrintParas != null)
  243. {
  244. string[] ps = dr["Paras"].ToString().Split(',');
  245. for (int i = 0; i < ps.Length; i++)
  246. {
  247. if (!string.IsNullOrEmpty(ps[i]))
  248. {
  249. sqltxt = sqltxt.Replace(ps[i], PrintParas);
  250. }
  251. }
  252. }
  253. if (sqltxt.Contains("[WorkPoint]"))
  254. {
  255. sqltxt = sqltxt.Replace("[WorkPoint]", WorkPoint);
  256. }
  257. if (sqltxt.Contains("[MUSER]"))
  258. {
  259. sqltxt = sqltxt.Replace("[MUSER]", MUSER);
  260. }
  261. string strPrintFileName = Server.MapPath("/File/LablesFile/") + "" + FileAddress + "";
  262. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  263. pJson.MasterOptions(1, "Code", true); //主从关系
  264. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  265. //pJson.CheckRegister("注册姓名", "8ECCCD6A1302DFEE1A6456A5D"); //注册信息
  266. //pJson.AddPrintParam("ShopName", "测试酒楼");
  267. //pJson.AddPrintParam("PrintDepositAdd", "说明:本单据为贵客押金收取凭证,盖章有效。退房时请出示,遗失者自负,请妥善保存。退房时间为12:00时,延时退房18:00时以前按半天房费收取,18:00时以后算全天房价。押金单有效期为一个月,过期作废。 贵重物品请交前台寄存,未寄存丢失自负。 谢谢!");
  268. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  269. string strSql = sqltxt;
  270. //DataTable dtCashLog = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  271. DataSet dtCashLog = DbHelper.GetDataSet(CommandType.Text, strSql);
  272. DataTable dt1 = null;
  273. DataTable dt2 = null;
  274. DataTable dt3 = null;
  275. string strPrintTempFile = "";
  276. if (dtCashLog.Tables.Count > 0 && dtCashLog.Tables.Count<=1)
  277. {
  278. dt1 = dtCashLog.Tables[0];
  279. strPrintTempFile = pJson.ShowReport(dt1);
  280. }
  281. if (dtCashLog.Tables.Count > 1 && dtCashLog.Tables.Count <= 2)
  282. {
  283. dt1 = dtCashLog.Tables[0];
  284. dt2 = dtCashLog.Tables[1];
  285. strPrintTempFile = pJson.ShowReport(dt1, dt2);
  286. }
  287. if (dtCashLog.Tables.Count > 2)
  288. {
  289. dt1 = dtCashLog.Tables[0];
  290. dt2 = dtCashLog.Tables[1];
  291. dt3 = dtCashLog.Tables[2];
  292. strPrintTempFile = pJson.ShowReport(dt1, dt2, dt3);
  293. }
  294. //string strPrintTempFile = pJson.ShowReport(dt1, dt2); //产生JSON文件内容
  295. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  296. string strServerURL = GetUrlPath() + "PrintTemp/";
  297. string strData = strServerURL + strPrintTempFile;
  298. strPrintData = PrintFunction.EnBase64(strData);
  299. var JsonData = new
  300. {
  301. strPrintData_1 = strPrintData,
  302. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  303. strPrintControlCookie_1 = strPrintControlCookie
  304. };
  305. //多站点
  306. //string sql = @"UPDATE dbo.ICSInventoryLot
  307. // SET PrintTimes=ISNULL(PrintTimes,0)+1,
  308. // LastPrintUser='',
  309. // LastPrintTime=GETDATE()
  310. // WHERE ID IN (" + keyValue.TrimEnd(',') + ") and WorkPoint in ('" + WorkPoint.TrimEnd(',') + "')";
  311. //SqlHelper.ExecuteNonQuery(sql);
  312. return Content(JsonData.ToJson());
  313. }
  314. /// <summary>
  315. /// 设置控件调用的Cookie值,判断是否安装了打印控件
  316. /// </summary>
  317. /// <param name="pJson"></param>
  318. private void SetCookieAndURL(PrintJson pJson)
  319. {
  320. bIsInstallPrintControl = false;
  321. strPrintControlCookie = "";
  322. HttpCookie pCookieInstall = Request.Cookies["InstallPrintControl"];
  323. if (pCookieInstall != null)
  324. { //Cookie存在
  325. strPrintControlCookie = pCookieInstall.Value.ToString();
  326. //以Cookie值查找在数据表中是否存在
  327. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  328. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strPrintControlCookie) };
  329. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  330. {
  331. if (drCookie.Read())
  332. { //标识为已经安装
  333. bIsInstallPrintControl = true;
  334. }
  335. drCookie.Close();
  336. }
  337. //更新Cookie的保存时间
  338. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  339. Response.SetCookie(pCookieInstall);
  340. }
  341. else
  342. {//Cookie不存在,则新建Cookie
  343. strPrintControlCookie = System.Guid.NewGuid().ToString();
  344. pCookieInstall = new HttpCookie("InstallPrintControl", strPrintControlCookie);
  345. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  346. Response.Cookies.Add(pCookieInstall);
  347. }
  348. string strUrl = Server.MapPath("/PrintTemp/") + "IsCheckInstall";
  349. pJson.SetCookieAndURL(strPrintControlCookie, strUrl);
  350. }
  351. [HttpGet]
  352. public ActionResult SelectColumnName(string BeginTime, string EndTime)
  353. {
  354. var data = App.SelectColumnName(BeginTime, EndTime);
  355. return Content(data.ToJson());
  356. }
  357. [HttpGet]
  358. public ActionResult GetCnValue(string Code)
  359. {
  360. string sql = string.Empty;
  361. try
  362. {
  363. string str = App.GetCnValue(Code);
  364. var JsonData = new
  365. {
  366. content = str
  367. };
  368. return Content(JsonData.ToJson());
  369. }
  370. catch (Exception ex)
  371. {
  372. return Error(ex.Message);
  373. }
  374. }
  375. }
  376. }