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.

693 lines
30 KiB

4 days ago
  1. using NFine.Application.SRM;
  2. using NFine.Code;
  3. using NFine.Data.Extensions;
  4. using NFine.Domain._03_Entity.SRM;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Configuration;
  8. using System.Data;
  9. using System.Data.SqlClient;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Web;
  13. using System.Web.Mvc;
  14. namespace NFine.Web.Areas.SRM.Controllers
  15. {
  16. public class POSignBacksController : ControllerBase
  17. {
  18. POSignBacksApp App = new POSignBacksApp();
  19. //
  20. // GET: /SRM/POSignBacks/
  21. public ActionResult ICSPOSignBacks()
  22. {
  23. return View();
  24. }
  25. public ActionResult POSignBackCommint()
  26. {
  27. return View();
  28. }
  29. [HttpGet]
  30. [HandlerAjaxOnly]
  31. public ActionResult GetGridJson(Pagination pagination, string queryJson)
  32. {
  33. DataTable ListData = App.GetGridJson(queryJson, ref pagination);
  34. var JsonData = new
  35. {
  36. total = pagination.total,
  37. page = pagination.page,
  38. records = pagination.records,
  39. rows = ListData,
  40. };
  41. return Content(JsonData.ToJson());
  42. }
  43. public ActionResult ChridenList(string keyValue, string WorkPoint)
  44. {
  45. string result = App.ChridenList(keyValue, WorkPoint);
  46. var JsonData = new
  47. {
  48. result = result
  49. };
  50. return Content(JsonData.ToJson());
  51. }
  52. [HttpGet]
  53. [HandlerAjaxOnly]
  54. public ActionResult GetGridJsonCommint(Pagination pagination, string queryJson)
  55. {
  56. DataTable ListData = App.GetGridJsonCommint(queryJson, ref pagination);
  57. var JsonData = new
  58. {
  59. total = pagination.total,
  60. page = pagination.page,
  61. records = pagination.records,
  62. rows = ListData,
  63. };
  64. return Content(JsonData.ToJson());
  65. }
  66. /// <summary>
  67. ///
  68. /// </summary>
  69. /// <param name="ReturnRemark"></param>
  70. /// <param name="POCode"></param>
  71. /// <returns></returns>
  72. [HttpPost]
  73. [HandlerAjaxOnly]
  74. //[ValidateAntiForgeryToken]
  75. public ActionResult UpdatePOBackRemark(string ReturnRemark, string POCode)
  76. {
  77. int result = App.UpdatePOBackRemark(ReturnRemark, POCode);
  78. if (result > 0)
  79. {
  80. return Success("操作成功!");
  81. }
  82. else
  83. {
  84. return Error("操作失败!");
  85. }
  86. }
  87. [HttpPost]
  88. //[HandlerAjaxOnly]
  89. //[ValidateAntiForgeryToken]
  90. public ActionResult POBackCommit(string keyValue)
  91. {
  92. try
  93. {
  94. App.POBackCommit(keyValue);
  95. return Success("确认成功!");
  96. }
  97. catch (Exception ex)
  98. {
  99. return Error(ex.Message);
  100. }
  101. //int result = App.POBackCommit(keyValue);
  102. //if (result > 0)
  103. //{
  104. // return Success("操作成功!");
  105. //}
  106. //else
  107. //{
  108. // return Error("操作失败!");
  109. //}
  110. }
  111. [HttpPost]
  112. public ActionResult UpLoadFile()
  113. {
  114. //获取采购订单号
  115. string PoCode = Request.Form["CurrentPoCode"].ToString();
  116. string ReturnRemark = Request.Form["uploadcomment"].ToString();
  117. string WorkPoint = Request.Form["WorkPoint"].ToString();
  118. string VenName = Request.Form["VenName"].ToString();
  119. //string VenCode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  120. int UploadFrequency = 0;
  121. if (!string.IsNullOrEmpty(Request.Form["uploadFrequency"].ToString()))
  122. {
  123. UploadFrequency = Convert.ToInt32(Request.Form["uploadFrequency"].ToString())+1;
  124. }
  125. else
  126. {
  127. UploadFrequency = UploadFrequency + 1;
  128. }
  129. //获取上传的文件集合
  130. HttpFileCollection httpFile = System.Web.HttpContext.Current.Request.Files;
  131. //string fileName = PoCode + Path.GetExtension(httpFile[0].FileName);
  132. string FileAddres = PoCode + "_" + VenName + "_" + UploadFrequency + Path.GetExtension(httpFile[0].FileName);
  133. string Paths = System.Web.HttpContext.Current.Server.MapPath("~\\File\\" + PoCode);
  134. if (!Directory.Exists(Paths))
  135. {
  136. Directory.CreateDirectory(Paths);
  137. }
  138. string filePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\" + PoCode + "\\" + FileAddres);
  139. int iLen = httpFile[0].ContentLength;
  140. byte[] bData = new byte[iLen];
  141. httpFile[0].InputStream.Read(bData, 0, iLen);
  142. FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate);
  143. fs.Write(bData, 0, bData.Length);
  144. fs.Flush();
  145. fs.Close();
  146. fs.Dispose();
  147. string msg = App.UpLoadFile(PoCode, FileAddres, filePath, ReturnRemark,WorkPoint);
  148. if (string.IsNullOrEmpty(msg))
  149. {
  150. return Success("上传成功!");
  151. }
  152. else
  153. {
  154. return Error(msg);
  155. }
  156. }
  157. [HttpPost]
  158. public ActionResult UpLoadFileCommint()
  159. {
  160. //获取采购订单号
  161. string PoCode = Request.Form["CurrentPoCode"].ToString();
  162. string ReturnRemark = Request.Form["uploadcomment"].ToString();
  163. string WorkPoint = Request.Form["WorkPoint"].ToString();
  164. int UploadFrequency = Convert.ToInt32( Request.Form["uploadFrequency"].ToString())+1;
  165. //获取上传的文件集合
  166. HttpFileCollection httpFile = System.Web.HttpContext.Current.Request.Files;
  167. string fileName = PoCode + "_" + UploadFrequency + Path.GetExtension(httpFile[0].FileName);
  168. string Paths = System.Web.HttpContext.Current.Server.MapPath("~\\File\\" + PoCode);
  169. if (!Directory.Exists(Paths))
  170. {
  171. Directory.CreateDirectory(Paths);
  172. }
  173. string filePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\" + PoCode + "\\" + fileName);
  174. int iLen = httpFile[0].ContentLength;
  175. byte[] bData = new byte[iLen];
  176. httpFile[0].InputStream.Read(bData, 0, iLen);
  177. FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate);
  178. fs.Write(bData, 0, bData.Length);
  179. fs.Flush();
  180. fs.Close();
  181. fs.Dispose();
  182. string msg = App.UpLoadFileCommint(PoCode, fileName, filePath, ReturnRemark, WorkPoint);
  183. if (string.IsNullOrEmpty(msg))
  184. {
  185. return Success("上传成功!");
  186. }
  187. else
  188. {
  189. return Error(msg);
  190. }
  191. }
  192. [HttpGet]
  193. [HandlerAjaxOnly]
  194. public ActionResult GetSubGridJson(string queryJson, Pagination pagination)
  195. {
  196. DataTable ListData = App.GetSubGridJson(queryJson, ref pagination);
  197. var JsonData = new
  198. {
  199. total = pagination.total,
  200. page = pagination.page,
  201. records = pagination.records,
  202. rows = ListData,
  203. };
  204. //获取当前登录人信息;
  205. return Content(JsonData.ToJson());
  206. }
  207. #region 打印
  208. /// <summary>
  209. /// 打印数据参数:服务器的URL+打印的文件名,转化为Base64编码
  210. /// </summary>
  211. protected string strPrintData;
  212. /// <summary>
  213. /// 标识是否安装了控件
  214. /// </summary>
  215. protected bool bIsInstallPrintControl = true;
  216. /// <summary>
  217. /// 打印控件的Cookie值
  218. /// </summary>
  219. protected string strPrintControlCookie = "";
  220. /// <summary>
  221. /// 获取Url中去掉文件名的路径
  222. /// </summary>
  223. /// <returns></returns>
  224. private string GetUrlPath()
  225. {
  226. string strUrl = Request.Url.ToString();
  227. int iEnd = strUrl.LastIndexOf("/");
  228. strUrl = strUrl.Substring(0, iEnd + 1);
  229. return strUrl;
  230. }
  231. /// <summary>
  232. /// 设置控件调用的Cookie值,判断是否安装了打印控件
  233. /// </summary>
  234. /// <param name="pJson"></param>
  235. private void SetCookieAndURL(PrintJson pJson)
  236. {
  237. bIsInstallPrintControl = false;
  238. strPrintControlCookie = "";
  239. HttpCookie pCookieInstall = Request.Cookies["InstallPrintControl"];
  240. if (pCookieInstall != null)
  241. { //Cookie存在
  242. strPrintControlCookie = pCookieInstall.Value.ToString();
  243. //以Cookie值查找在数据表中是否存在
  244. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  245. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strPrintControlCookie) };
  246. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  247. {
  248. if (drCookie.Read())
  249. { //标识为已经安装
  250. bIsInstallPrintControl = true;
  251. }
  252. drCookie.Close();
  253. }
  254. //更新Cookie的保存时间
  255. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  256. Response.SetCookie(pCookieInstall);
  257. }
  258. else
  259. {//Cookie不存在,则新建Cookie
  260. strPrintControlCookie = System.Guid.NewGuid().ToString();
  261. pCookieInstall = new HttpCookie("InstallPrintControl", strPrintControlCookie);
  262. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  263. Response.Cookies.Add(pCookieInstall);
  264. }
  265. string strUrl = Server.MapPath("/PrintTemp/") + "IsCheckInstall";
  266. pJson.SetCookieAndURL(strPrintControlCookie, strUrl);
  267. }
  268. [HttpPost]
  269. [HandlerAjaxOnly]
  270. public ActionResult PrintItemLot(string keyValue, string WorkPoint)
  271. {
  272. string strPrintFileName ="";
  273. string DBLANK = SqlHelper.GetItemsDetails("ERP001", WorkPoint);
  274. string CusterJC = ConfigurationManager.ConnectionStrings["CusterJC"].ConnectionString;
  275. //string U8ConnStr = ConfigurationManager.ConnectionStrings["ERPDB"].ConnectionString;
  276. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  277. string strSqls = string.Empty;
  278. if (WorkPoint == "02")
  279. {
  280. strPrintFileName = Server.MapPath("/ReportFile/") + "LOEssd02.fr3";
  281. }else if(WorkPoint == "03")
  282. {
  283. strPrintFileName = Server.MapPath("/ReportFile/") + "LOEssd03.fr3";
  284. }
  285. else if(WorkPoint == "01")
  286. {
  287. strPrintFileName = Server.MapPath("/ReportFile/") + "LOEssd.fr3";
  288. }
  289. else
  290. {
  291. strPrintFileName = Server.MapPath("/ReportFile/") + "LOEssd.fr3";
  292. }
  293. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  294. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  295. //pJson.CheckRegister("注册姓名", "8ECCCD6A1302DFEE1A6456A5D"); //注册信息
  296. //pJson.AddPrintParam("ShopName", "测试酒楼");
  297. //pJson.AddPrintParam("PrintDepositAdd", "说明:本单据为贵客押金收取凭证,盖章有效。退房时请出示,遗失者自负,请妥善保存。退房时间为12:00时,延时退房18:00时以前按半天房费收取,18:00时以后算全天房价。押金单有效期为一个月,过期作废。 贵重物品请交前台寄存,未寄存丢失自负。 谢谢!");
  298. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  299. string strSql = @"select distinct poCode
  300. ,VenName
  301. ,b.VenAddress cVenAddress
  302. ,b.VenPerson cVenPerson
  303. ,CreatePerson as MUSER
  304. ,b.VenPayCond as iPayCreDays
  305. -- ,e.CsSName as cVenPayCond
  306. ,VenPhone
  307. ,VenAddress
  308. ,c.F_MobilePhone
  309. ,VenBank AS VenBank
  310. ,VenAccount as VenAccount
  311. ,VenRegCode
  312. ,VenEmail
  313. ,a.EATTRIBUTE12
  314. ,a.EATTRIBUTE13
  315. from dbo.ICSPurchaseOrder a
  316. left join ICSVendor b on a.VenCode=b.VenCode and a.WorkPoint=b.WorkPoint
  317. left join Sys_SRM_User c on a.CreatePerson=c.F_RealName and a.WorkPoint=c.F_Location
  318. --left join {0}.dbo.PayCondition d on b.cVenPayCond=d.cPayCode
  319. --left join {0}.dbo.settleStyle e on b.Free2=e.cssCode
  320. where a.POCode IN (" + keyValue.TrimEnd(',') + ") and a.WorkPoint='" + WorkPoint + "'";
  321. strSql = string.Format(strSql, DBLANK);
  322. //string strSql = @"Select * From CashLog";
  323. DataTable dtCashLog = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  324. if (CusterJC.Contains("佑伦")|| CusterJC.Contains("思米思"))
  325. {
  326. strSqls = @" select * from POSignBacks where POCode IN (" + keyValue.TrimEnd(',') + ") and WorkPoint='" + WorkPoint + "' and (isnull(Status,'')<>'关闭' and isnull(Status,'')<>'弃审')";
  327. }
  328. else
  329. {
  330. strSqls = @" SELECT a.Sequence,a.InvCode,b.INVNAME,b.INVSTD,b.InvUnit,a.Quantity,a.UnitPrice,
  331. CONVERT(NVARCHAR(50), a.PlanArriveDate,23) as PreArriveDate,CONVERT(NVARCHAR(50),a.ArriveDate,23) as ArriveDate,
  332. CONVERT(NVARCHAR(50), a.DeliveryDate,23) as Free5,c.ProjectCode,b.INVDESC,a.CreatePerson as MUSER,CONVERT(NVARCHAR(50), a.MTIME,23) as MTIME,c.BatchCode,a.EATTRIBUTE11 as iSum
  333. FROM dbo.ICSPurchaseOrder a
  334. LEFT JOIN dbo.ICSINVENTORY b ON a.InvCode=b.INVCODE AND a.WorkPoint=b.WorkPoint
  335. LEFT JOIN dbo.ICSExtension c ON a.ExtensionID=c.id AND a.WorkPoint=c.WorkPoint
  336. where a.POCode IN (" + keyValue.TrimEnd(',') + ") and a.WorkPoint='" + WorkPoint + "' and (isnull(a.Status,'')<>'' and isnull(a.Status,'')<>'')";
  337. }
  338. DataTable dtInMaterial = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSqls, true, null);
  339. strSql = @" select SUM(CONVERT(INT,isnull(a.Quantity,0))) as SumQuantity,SUM(CONVERT(DECIMAL(18,2),isnull(a.EATTRIBUTE11,0))) as SumiSum,dbo.CNumeric(SUM(CONVERT(DECIMAL(18,2),isnull(a.EATTRIBUTE11,0)))) as ZWSumiSum
  340. FROM dbo.ICSPurchaseOrder a
  341. LEFT JOIN dbo.ICSINVENTORY b ON a.InvCode=b.INVCODE AND a.WorkPoint=b.WorkPoint
  342. where a.POCode IN (" + keyValue.TrimEnd(',') + ") and a.WorkPoint='" + WorkPoint + "'";
  343. DataTable dtInMaterials = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  344. string strPrintTempFile = pJson.ShowReport(dtCashLog, dtInMaterial, dtInMaterials); //产生JSON文件内容
  345. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  346. string strServerURL = GetUrlPath() + "PrintTemp/";
  347. string strData = strServerURL + strPrintTempFile;
  348. strPrintData = PrintFunction.EnBase64(strData);
  349. var JsonData = new
  350. {
  351. strPrintData_1 = strPrintData,
  352. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  353. strPrintControlCookie_1 = strPrintControlCookie
  354. };
  355. string sql = @"UPDATE dbo.ICSPurchaseOrder
  356. SET DownloadFrequency=ISNULL(DownloadFrequency,0)+1
  357. WHERE POCode IN (" + keyValue.TrimEnd(',') + ") and WorkPoint='" + WorkPoint + "'";
  358. SqlHelper.ExecuteNonQuery(sql);
  359. return Content(JsonData.ToJson());
  360. }
  361. [HttpPost]
  362. [HandlerAjaxOnly]
  363. public ActionResult MergePrintItemLot(string keyValue, string WorkPoint)
  364. {
  365. string strPrintFileName = "";
  366. string DBLANK = SqlHelper.GetItemsDetails("ERP001", WorkPoint);
  367. string CusterJC = ConfigurationManager.ConnectionStrings["CusterJC"].ConnectionString;
  368. //string U8ConnStr = ConfigurationManager.ConnectionStrings["ERPDB"].ConnectionString;
  369. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  370. string strSqls = string.Empty;
  371. if (WorkPoint == "02")
  372. {
  373. strPrintFileName = Server.MapPath("/ReportFile/") + "LOEssd02.fr3";
  374. }
  375. else if (WorkPoint == "03")
  376. {
  377. strPrintFileName = Server.MapPath("/ReportFile/") + "LOEssd03.fr3";
  378. }
  379. else if (WorkPoint == "01")
  380. {
  381. strPrintFileName = Server.MapPath("/ReportFile/") + "LOEssd.fr3";
  382. }
  383. else
  384. {
  385. strPrintFileName = Server.MapPath("/ReportFile/") + "LOEssd.fr3";
  386. }
  387. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  388. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  389. //pJson.CheckRegister("注册姓名", "8ECCCD6A1302DFEE1A6456A5D"); //注册信息
  390. //pJson.AddPrintParam("ShopName", "测试酒楼");
  391. //pJson.AddPrintParam("PrintDepositAdd", "说明:本单据为贵客押金收取凭证,盖章有效。退房时请出示,遗失者自负,请妥善保存。退房时间为12:00时,延时退房18:00时以前按半天房费收取,18:00时以后算全天房价。押金单有效期为一个月,过期作废。 贵重物品请交前台寄存,未寄存丢失自负。 谢谢!");
  392. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  393. string strSql = @"select distinct poCode
  394. ,VenName
  395. ,b.VenAddress cVenAddress
  396. ,b.VenPerson cVenPerson
  397. ,CreatePerson as MUSER
  398. ,b.VenPayCond as iPayCreDays
  399. -- ,e.CsSName as cVenPayCond
  400. ,VenPhone
  401. ,VenAddress
  402. ,c.F_MobilePhone
  403. ,VenBank AS VenBank
  404. ,VenAccount as VenAccount
  405. ,VenRegCode
  406. ,VenEmail
  407. ,a.EATTRIBUTE12
  408. ,a.EATTRIBUTE13
  409. from dbo.ICSPurchaseOrder a
  410. left join ICSVendor b on a.VenCode=b.VenCode and a.WorkPoint=b.WorkPoint
  411. left join Sys_SRM_User c on a.CreatePerson=c.F_RealName and a.WorkPoint=c.F_Location
  412. --left join {0}.dbo.PayCondition d on b.cVenPayCond=d.cPayCode
  413. --left join {0}.dbo.settleStyle e on b.Free2=e.cssCode
  414. where a.POCode IN (" + keyValue.TrimEnd(',') + ") and a.WorkPoint='" + WorkPoint + "'";
  415. strSql = string.Format(strSql, DBLANK);
  416. //string strSql = @"Select * From CashLog";
  417. DataTable dtCashLog = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  418. if (CusterJC.Contains("佑伦") || CusterJC.Contains("思米思"))
  419. {
  420. strSqls = @"select Row_Number() OVER ( ORDER BY cDefine23 desc) AS Sequence,
  421. cDefine22,cDefine23,InvUnit,sum(Quantity) as Quantity
  422. ,UnitPrice,sum(CAST(iSum as decimal(16,2)) ) as iSum,PreArriveDate,MTIME
  423. from POSignBacks
  424. where POCode IN (" + keyValue.TrimEnd(',') + ") and WorkPoint='" + WorkPoint + "' and (isnull(Status,'')<>'' and isnull(Status,'')<>'') group by cDefine22,cDefine23,InvUnit,PreArriveDate,UnitPrice,MTIME";
  425. }
  426. else
  427. {
  428. strSqls = @" SELECT a.Sequence,a.InvCode,b.INVNAME,b.INVSTD,b.InvUnit,a.Quantity,a.UnitPrice,
  429. CONVERT(NVARCHAR(50), a.PlanArriveDate,23) as PreArriveDate,CONVERT(NVARCHAR(50),a.ArriveDate,23) as ArriveDate,
  430. CONVERT(NVARCHAR(50), a.DeliveryDate,23) as Free5,c.ProjectCode,b.INVDESC,a.CreatePerson as MUSER,CONVERT(NVARCHAR(50), a.MTIME,23) as MTIME,c.BatchCode,a.EATTRIBUTE11 as iSum
  431. FROM dbo.ICSPurchaseOrder a
  432. LEFT JOIN dbo.ICSINVENTORY b ON a.InvCode=b.INVCODE AND a.WorkPoint=b.WorkPoint
  433. LEFT JOIN dbo.ICSExtension c ON a.ExtensionID=c.id AND a.WorkPoint=c.WorkPoint
  434. where a.POCode IN (" + keyValue.TrimEnd(',') + ") and a.WorkPoint='" + WorkPoint + "' and (isnull(a.Status,'')<>'' and isnull(a.Status,'')<>'')";
  435. }
  436. DataTable dtInMaterial = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSqls, true, null);
  437. strSql = @" select SUM(CONVERT(INT,isnull(a.Quantity,0))) as SumQuantity,SUM(CONVERT(DECIMAL(18,2),isnull(a.EATTRIBUTE11,0))) as SumiSum,dbo.CNumeric(SUM(CONVERT(DECIMAL(18,2),isnull(a.EATTRIBUTE11,0)))) as ZWSumiSum
  438. FROM dbo.ICSPurchaseOrder a
  439. LEFT JOIN dbo.ICSINVENTORY b ON a.InvCode=b.INVCODE AND a.WorkPoint=b.WorkPoint
  440. where a.POCode IN (" + keyValue.TrimEnd(',') + ") and a.WorkPoint='" + WorkPoint + "'";
  441. DataTable dtInMaterials = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  442. string strPrintTempFile = pJson.ShowReport(dtCashLog, dtInMaterial, dtInMaterials); //产生JSON文件内容
  443. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  444. string strServerURL = GetUrlPath() + "PrintTemp/";
  445. string strData = strServerURL + strPrintTempFile;
  446. strPrintData = PrintFunction.EnBase64(strData);
  447. var JsonData = new
  448. {
  449. strPrintData_1 = strPrintData,
  450. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  451. strPrintControlCookie_1 = strPrintControlCookie
  452. };
  453. string sql = @"UPDATE dbo.ICSPurchaseOrder
  454. SET DownloadFrequency=ISNULL(DownloadFrequency,0)+1
  455. WHERE POCode IN (" + keyValue.TrimEnd(',') + ") and WorkPoint='" + WorkPoint + "'";
  456. SqlHelper.ExecuteNonQuery(sql);
  457. return Content(JsonData.ToJson());
  458. }
  459. /// <summary>
  460. /// 写日志(用于跟踪)
  461. /// </summary>
  462. private void WriteLog(string strMessage)
  463. {
  464. string strLogFile = Server.MapPath("./Cookie_Log.txt");
  465. StreamWriter swLogFile = null;
  466. try
  467. {
  468. if (!System.IO.File.Exists(strLogFile))
  469. {
  470. swLogFile = System.IO.File.CreateText(strLogFile);
  471. }
  472. else
  473. {
  474. swLogFile = System.IO.File.AppendText(strLogFile);
  475. }
  476. swLogFile.WriteLine(strMessage);
  477. }
  478. catch
  479. {
  480. }
  481. finally
  482. {
  483. if (swLogFile != null)
  484. swLogFile.Close();
  485. }
  486. }
  487. /// <summary>
  488. ///判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  489. /// </summary>
  490. /// <param name="strCookie"></param>
  491. private void UpdateCheckInstall(string strCookie)
  492. {
  493. bool bIsExist = false;
  494. //判断记录是否存在
  495. GetLastAccessTime(strCookie, ref bIsExist);
  496. string strSql = "";
  497. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) };
  498. if (bIsExist)
  499. { //存在则更新最后访问的时间
  500. strSql = @"Update sys_SRM_CheckInstall
  501. Set LastAccessTime = getDate()
  502. Where Cookie = @Cookie";
  503. }
  504. else
  505. { //不存在则新建一条记录
  506. strSql = @"Insert into sys_SRM_CheckInstall(Cookie, LastAccessTime)
  507. Values( @Cookie, getDate() )";
  508. }
  509. DbHelper.ExecuteNonQuery(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie);
  510. }
  511. public DateTime ToDateTime(object SrcValue)
  512. {
  513. if (Convert.IsDBNull(SrcValue) == true)
  514. return DateTime.MinValue;
  515. else
  516. {
  517. try
  518. {
  519. return Convert.ToDateTime(SrcValue);
  520. }
  521. catch
  522. {
  523. return DateTime.MinValue;
  524. }
  525. }
  526. }
  527. /// <summary>
  528. /// 获取此Cookie的最后访问时间
  529. /// </summary>
  530. /// <param name="strCookie"></param>
  531. /// <returns></returns>
  532. private DateTime GetLastAccessTime(string strCookie, ref bool bIsExist)
  533. {
  534. DateTime dtLastAccessTime = DateTime.MinValue;
  535. bIsExist = false;
  536. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  537. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) };
  538. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  539. {
  540. if (drCookie.Read())
  541. {
  542. dtLastAccessTime = ToDateTime(drCookie["LastAccessTime"]);
  543. bIsExist = true;
  544. }
  545. drCookie.Close();
  546. }
  547. return dtLastAccessTime;
  548. }
  549. [HttpGet]
  550. [HandlerAjaxOnly]
  551. public ActionResult IsCheckInstall(string checkInstall)
  552. {
  553. string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,");
  554. if (Request.QueryString["cookie"] != null)
  555. { //有控件上传的Cookie值
  556. string strCookie = Request.QueryString["cookie"].ToString();
  557. //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  558. UpdateCheckInstall(strCookie);
  559. strValue = strValue + "上传的cookie:" + strCookie;
  560. }
  561. else if (checkInstall != null)
  562. {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况
  563. string strCookie = checkInstall;
  564. //读取最后访问的时间
  565. string strResult = "PrintControlInstall";
  566. bool bIsExist = false;
  567. DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist);
  568. if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now)
  569. {
  570. strResult = "NOT";
  571. }
  572. Response.Clear();
  573. Response.Write(strResult);
  574. strValue = strValue + "检测安装的值:" + strCookie;
  575. }
  576. WriteLog(strValue);
  577. return null;
  578. }
  579. [HttpGet]
  580. [HandlerAjaxOnly]
  581. public ActionResult IsCheckInstall()
  582. {
  583. string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,");
  584. if (Request.QueryString["cookie"] != null)
  585. { //有控件上传的Cookie值
  586. string strCookie = Request.QueryString["cookie"].ToString();
  587. //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  588. UpdateCheckInstall(strCookie);
  589. strValue = strValue + "上传的cookie:" + strCookie;
  590. }
  591. else if (Request.QueryString["checkInstall"] != null)
  592. {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况
  593. string strCookie = Request.QueryString["checkInstall"];
  594. //读取最后访问的时间
  595. string strResult = "PrintControlInstall";
  596. bool bIsExist = false;
  597. DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist);
  598. if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now)
  599. {
  600. strResult = "NOT";
  601. }
  602. Response.Clear();
  603. Response.Write(strResult);
  604. strValue = strValue + "检测安装的值:" + strCookie;
  605. }
  606. WriteLog(strValue);
  607. return null;
  608. }
  609. #endregion
  610. public ActionResult BackCommit(string keyValue)
  611. {
  612. try
  613. {
  614. App.BackCommit(keyValue);
  615. return Success("保存成功");
  616. }
  617. catch (Exception ex)
  618. {
  619. return Error(ex.Message);
  620. }
  621. }
  622. [HttpGet]
  623. public ActionResult Download(string filePath) {
  624. filePath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["AttachmentPath"] + filePath);
  625. string fileName = Path.GetFileName(filePath);
  626. FileStream fs = new FileStream(filePath, FileMode.Open);
  627. byte[] bytes = new byte[(int)fs.Length]; //以字符流的形式下载文件
  628. fs.Read(bytes, 0, bytes.Length);
  629. fs.Close();
  630. Response.Charset = "UTF-8";
  631. Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
  632. Response.ContentType = "application/octet-stream"; //通知浏览器下载文件而不是打开
  633. Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fileName));
  634. Response.BinaryWrite(bytes);
  635. Response.Flush();
  636. Response.End();
  637. return new EmptyResult();
  638. }
  639. }
  640. }