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.

642 lines
27 KiB

4 days ago
  1. using NFine.Application.KBSSRM;
  2. using NFine.Code;
  3. using NFine.Data.Extensions;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Web;
  11. using System.Web.Mvc;
  12. namespace NFine.Web.Areas.KBSSRM.Controllers
  13. {
  14. public class PalletplateController : ControllerBase
  15. {
  16. private PalletplateApp App = new PalletplateApp();
  17. // GET: KBSSRM/Palletplate
  18. public ActionResult Index()
  19. {
  20. return View();
  21. }
  22. public ActionResult PalletplateAdd()
  23. {
  24. return View();
  25. }
  26. public ActionResult SeachContainer()
  27. {
  28. return View();
  29. }
  30. public ActionResult PalletplateUpdate()
  31. {
  32. return View();
  33. }
  34. public ActionResult PalletplateAddByAsn()
  35. {
  36. return View();
  37. }
  38. [HttpGet]
  39. [HandlerAjaxOnly]
  40. public ActionResult GetGridJson(Pagination pagination, string queryJson)
  41. {
  42. DataTable ListData = App.GetGridJson(queryJson, ref pagination);
  43. var JsonData = new
  44. {
  45. total = pagination.total,
  46. page = pagination.page,
  47. records = pagination.records,
  48. rows = ListData,
  49. };
  50. return Content(JsonData.ToJson());
  51. }
  52. [HttpGet]
  53. [HandlerAjaxOnly]
  54. public ActionResult GetSubGridJson(string ContainerID, Pagination pagination)
  55. {
  56. DataTable ListData = App.GetSubGridJson(ContainerID, 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. [HttpGet]
  67. [HandlerAjaxOnly]
  68. public ActionResult GetSubGridJson_Add(string queryJson, Pagination pagination)
  69. {
  70. DataTable ListData = App.GetSubGridJson_Add(queryJson, ref pagination);
  71. var JsonData = new
  72. {
  73. total = pagination.total,
  74. page = pagination.page,
  75. records = pagination.records,
  76. rows = ListData,
  77. };
  78. return Content(JsonData.ToJson());
  79. }
  80. [HttpGet]
  81. [HandlerAjaxOnly]
  82. public ActionResult GetSubGridJson_AddByASN(string queryJson, Pagination pagination)
  83. {
  84. DataTable ListData = App.GetSubGridJson_AddByASN(queryJson, ref pagination);
  85. var JsonData = new
  86. {
  87. total = pagination.total,
  88. page = pagination.page,
  89. records = pagination.records,
  90. rows = ListData,
  91. };
  92. return Content(JsonData.ToJson());
  93. }
  94. [HttpGet]
  95. [HandlerAjaxOnly]
  96. public ActionResult GetContainerCode(string RoleEnCode,string WorkPoint)
  97. {
  98. string ListData = App.GetContainerCode(RoleEnCode, WorkPoint);
  99. var data = new
  100. {
  101. rows = ListData,
  102. };
  103. return Content(data.ToJson());
  104. }
  105. [HttpGet]
  106. public ActionResult GetContainerForBox(string invcode, string Code, string LotNo, string VenCode, string WorkPoint,string Type, Pagination pagination)
  107. {
  108. DataTable ListData = App.GetContainerForBox(invcode, Code, LotNo, VenCode, WorkPoint, Type, ref pagination);
  109. var JsonData = new
  110. {
  111. total = pagination.total,
  112. page = pagination.page,
  113. records = pagination.records,
  114. rows = ListData,
  115. };
  116. return Content(JsonData.ToJson());
  117. }
  118. [HttpPost]
  119. [HandlerAjaxOnly]
  120. public ActionResult SaveICSContainerForPalletplate(string ICSASN)
  121. {
  122. string msg = App.SaveICSContainerForPalletplate(ICSASN);
  123. if (!string.IsNullOrEmpty(msg))
  124. {
  125. return Error(msg);
  126. }
  127. else
  128. {
  129. return Success("添加成功!");
  130. }
  131. }
  132. [HttpPost]
  133. [HandlerAjaxOnly]
  134. public ActionResult SaveICSContainerForPalletplateByASN(string ICSASN)
  135. {
  136. string msg = App.SaveICSContainerForPalletplateByASN(ICSASN);
  137. if (!string.IsNullOrEmpty(msg))
  138. {
  139. return Error(msg);
  140. }
  141. else
  142. {
  143. return Success("添加成功!");
  144. }
  145. }
  146. [HttpPost]
  147. [HandlerAjaxOnly]
  148. public ActionResult UpdateICSContainerForPalletplate(string ICSASN)
  149. {
  150. string msg = App.UpdateICSContainerForPalletplate(ICSASN);
  151. if (!string.IsNullOrEmpty(msg))
  152. {
  153. return Error(msg);
  154. }
  155. else
  156. {
  157. return Success("修改成功!");
  158. }
  159. }
  160. [HttpPost]
  161. [HandlerAjaxOnly]
  162. [ValidateAntiForgeryToken]
  163. public ActionResult DeleteInfo(string keyValue, string WorkPoint)
  164. {
  165. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  166. string msg = App.DeleteInfo(keyValue, WorkPoint);
  167. if (string.IsNullOrEmpty(msg))
  168. {
  169. return Success("删除成功!");
  170. }
  171. else
  172. {
  173. return Error(msg);
  174. }
  175. }
  176. [HttpPost]
  177. [HandlerAjaxOnly]
  178. [ValidateAntiForgeryToken]
  179. public ActionResult DeleteContainer(string keyValue, string Work)
  180. {
  181. string msg = App.DeleteContainer(keyValue, Work);
  182. if (string.IsNullOrEmpty(msg))
  183. {
  184. return Success("删除成功!");
  185. }
  186. else
  187. {
  188. return Error(msg);
  189. }
  190. }
  191. #region 打印
  192. /// <summary>
  193. /// 打印数据参数:服务器的URL+打印的文件名,转化为Base64编码
  194. /// </summary>
  195. protected string strPrintData;
  196. /// <summary>
  197. /// 标识是否安装了控件
  198. /// </summary>
  199. protected bool bIsInstallPrintControl = true;
  200. /// <summary>
  201. /// 打印控件的Cookie值
  202. /// </summary>
  203. protected string strPrintControlCookie = "";
  204. /// <summary>
  205. /// 获取Url中去掉文件名的路径
  206. /// </summary>
  207. /// <returns></returns>
  208. private string GetUrlPath()
  209. {
  210. string strUrl = Request.Url.ToString();
  211. int iEnd = strUrl.LastIndexOf("/");
  212. strUrl = strUrl.Substring(0, iEnd + 1);
  213. return strUrl;
  214. }
  215. /// <summary>
  216. /// 设置控件调用的Cookie值,判断是否安装了打印控件
  217. /// </summary>
  218. /// <param name="pJson"></param>
  219. private void SetCookieAndURL(PrintJson pJson)
  220. {
  221. bIsInstallPrintControl = false;
  222. strPrintControlCookie = "";
  223. HttpCookie pCookieInstall = Request.Cookies["InstallPrintControl"];
  224. if (pCookieInstall != null)
  225. { //Cookie存在
  226. strPrintControlCookie = pCookieInstall.Value.ToString();
  227. //以Cookie值查找在数据表中是否存在
  228. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  229. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strPrintControlCookie) };
  230. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  231. {
  232. if (drCookie.Read())
  233. { //标识为已经安装
  234. bIsInstallPrintControl = true;
  235. }
  236. drCookie.Close();
  237. }
  238. //更新Cookie的保存时间
  239. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  240. Response.SetCookie(pCookieInstall);
  241. }
  242. else
  243. {//Cookie不存在,则新建Cookie
  244. strPrintControlCookie = System.Guid.NewGuid().ToString();
  245. pCookieInstall = new HttpCookie("InstallPrintControl", strPrintControlCookie);
  246. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  247. Response.Cookies.Add(pCookieInstall);
  248. }
  249. string strUrl = Server.MapPath("/PrintTemp/") + "IsCheckInstall";
  250. pJson.SetCookieAndURL(strPrintControlCookie, strUrl);
  251. }
  252. [HttpPost]
  253. [HandlerAjaxOnly]
  254. public ActionResult PrintItemLot(string keyValue)
  255. {
  256. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  257. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  258. string strPrintFileName = Server.MapPath("/ReportFile/") + "Pallet.fr3";
  259. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  260. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  261. pJson.MasterOptions(1, "ContainerCode", false); //主从关系
  262. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  263. string strSql = @" select DISTINCT a.ContainerCode,f.VenName
  264. from ICSContainer a
  265. left join ICSContainer b on a.ID=b.ContainerID and b.ContainerType='ContainerType01' and a.WorkPoint=b.WorkPoint
  266. left join ICSContainerLot c on b.ID=c.ContainerID and b.WorkPoint=c.WorkPoint
  267. left join dbo.ICSInventoryLot d on c.LotNo=d.LotNo and c.WorkPoint=d.WorkPoint
  268. left join dbo.ICSInventory e on d.InvCode=e.InvCode and d.WorkPoint=e.WorkPoint
  269. left join dbo.ICSVendor f on a.EATTRIBUTE8=f.VenCode and a.WorkPoint=f.WorkPoint
  270. where a.ContainerType='ContainerType04' and a.ContainerCode in (" + keyValue.TrimEnd(',') + ") and a.WorkPoint in(" + WorkPoint.TrimEnd(',') + ")";
  271. DataTable dtInInfo = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  272. strSql = @" select d.InvCode,e.InvName,sum(d.Quantity) AS Quantity,a.ContainerCode,f.VenName
  273. from ICSContainer a
  274. left join ICSContainer b on a.ID=b.ContainerID and b.ContainerType='ContainerType01' and a.WorkPoint=b.WorkPoint
  275. left join ICSContainerLot c on b.ID=c.ContainerID and b.WorkPoint=c.WorkPoint
  276. left join dbo.ICSInventoryLot d on c.LotNo=d.LotNo and c.WorkPoint=d.WorkPoint
  277. left join dbo.ICSInventory e on d.InvCode=e.InvCode and d.WorkPoint=e.WorkPoint
  278. left join dbo.ICSVendor f on a.EATTRIBUTE8=f.VenCode and a.WorkPoint=f.WorkPoint
  279. where a.ContainerType='ContainerType04' and a.ContainerCode in (" + keyValue.TrimEnd(',') + ") and a.WorkPoint in(" + WorkPoint.TrimEnd(',') + ")group by d.InvCode,e.InvName,a.ContainerCode,f.VenName ";
  280. DataTable dtInMaterial = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  281. string strPrintTempFile = pJson.ShowReport(dtInInfo,dtInMaterial); //产生JSON文件内容
  282. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  283. string strServerURL = GetUrlPath() + "PrintTemp/";
  284. string strData = strServerURL + strPrintTempFile;
  285. strPrintData = PrintFunction.EnBase64(strData);
  286. var JsonData = new
  287. {
  288. strPrintData_1 = strPrintData,
  289. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  290. strPrintControlCookie_1 = strPrintControlCookie
  291. };
  292. //string sql = @"UPDATE dbo.ICSCarton
  293. // SET PrintTimes=ISNULL(PrintTimes,0)+1,
  294. // lastPrintTime=GETDATE()
  295. // WHERE CartonNO IN (" + keyValue.TrimEnd(',') + ") and WorkPoint='" + WorkPoint + "'";
  296. //SqlHelper.ExecuteNonQuery(sql);
  297. return Content(JsonData.ToJson());
  298. }
  299. [HttpPost]
  300. [HandlerAjaxOnly]
  301. public ActionResult PrintItemLotByContainerType04(string keyValue)
  302. {
  303. string strSql = "";
  304. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  305. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  306. string strPrintFileName = Server.MapPath("/ReportFile/") + "Pallet.fr3";
  307. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  308. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  309. pJson.MasterOptions(1, "ContainerCode", false); //主从关系
  310. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  311. strSql = @" select DISTINCT a.ContainerCode,f.VenName
  312. from ICSContainer a
  313. left join ICSContainer b on a.ID=b.ContainerID and b.ContainerType='ContainerType01' and a.WorkPoint=b.WorkPoint
  314. left join ICSContainerLot c on b.ID=c.ContainerID and b.WorkPoint=c.WorkPoint
  315. left join dbo.ICSInventoryLot d on c.LotNo=d.LotNo and c.WorkPoint=d.WorkPoint
  316. left join dbo.ICSInventory e on d.InvCode=e.InvCode and d.WorkPoint=e.WorkPoint
  317. left join dbo.ICSVendor f on a.EATTRIBUTE8=f.VenCode and a.WorkPoint=f.WorkPoint
  318. LEFT JOIN dbo.ICSASNDetail h ON c.LotNo=h.LotNo AND c.WorkPoint=h.WorkPoint
  319. where a.ContainerType='ContainerType04' and h.ASNCode in (" + keyValue.TrimEnd(',') + ") and a.WorkPoint=" + WorkPoint.TrimEnd(',') + "";
  320. DataTable dtInInfo = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  321. strSql = @"
  322. select d.InvCode,e.InvName,sum(d.Quantity) AS Quantity,a.ContainerCode,f.VenName
  323. from ICSContainer a
  324. left join ICSContainer b on a.ID=b.ContainerID and b.ContainerType='ContainerType01' and a.WorkPoint=b.WorkPoint
  325. left join ICSContainerLot c on b.ID=c.ContainerID and b.WorkPoint=c.WorkPoint
  326. left join dbo.ICSInventoryLot d on c.LotNo=d.LotNo and c.WorkPoint=d.WorkPoint
  327. left join dbo.ICSInventory e on d.InvCode=e.InvCode and d.WorkPoint=e.WorkPoint
  328. left join dbo.ICSVendor f on a.EATTRIBUTE8=f.VenCode and a.WorkPoint=f.WorkPoint
  329. LEFT JOIN dbo.ICSASNDetail h ON c.LotNo=h.LotNo AND c.WorkPoint=h.WorkPoint
  330. where a.ContainerType='ContainerType04' and h.ASNCode in (" + keyValue.TrimEnd(',') + ") and a.WorkPoint=" + WorkPoint.TrimEnd(',') + "group by d.InvCode,e.InvName,a.ContainerCode,f.VenName ";
  331. DataTable dtInMaterial = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  332. string strPrintTempFile = pJson.ShowReport(dtInInfo,dtInMaterial); //产生JSON文件内容
  333. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  334. string strServerURL = GetUrlPath() + "PrintTemp/";
  335. string strData = strServerURL + strPrintTempFile;
  336. strPrintData = PrintFunction.EnBase64(strData);
  337. var JsonData = new
  338. {
  339. strPrintData_1 = strPrintData,
  340. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  341. strPrintControlCookie_1 = strPrintControlCookie
  342. };
  343. //string sql = @"UPDATE dbo.ICSCarton
  344. // SET PrintTimes=ISNULL(PrintTimes,0)+1,
  345. // lastPrintTime=GETDATE()
  346. // WHERE CartonNO IN (" + keyValue.TrimEnd(',') + ") and WorkPoint='" + WorkPoint + "'";
  347. //SqlHelper.ExecuteNonQuery(sql);
  348. return Content(JsonData.ToJson());
  349. }
  350. [HttpPost]
  351. [HandlerAjaxOnly]
  352. public ActionResult PrintItemLotByOOContainerType04(string keyValue)
  353. {
  354. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  355. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  356. string strPrintFileName = Server.MapPath("/ReportFile/") + "Pallet.fr3";
  357. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  358. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  359. //pJson.MasterOptions(1, "ContainerCode", false); //主从关系
  360. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  361. string strSql = @" select DISTINCT a.ContainerCode,f.VenName
  362. from ICSContainer a
  363. left join ICSContainer b on a.ID=b.ContainerID and b.ContainerType='ContainerType01' and a.WorkPoint=b.WorkPoint
  364. left join ICSContainerLot c on b.ID=c.ContainerID and b.WorkPoint=c.WorkPoint
  365. left join dbo.ICSInventoryLot d on c.LotNo=d.LotNo and c.WorkPoint=d.WorkPoint
  366. left join dbo.ICSInventory e on d.InvCode=e.InvCode and d.WorkPoint=e.WorkPoint
  367. left join dbo.ICSVendor f on a.EATTRIBUTE8=f.VenCode and a.WorkPoint=f.WorkPoint
  368. LEFT JOIN dbo.ICSOASNDetail h ON c.LotNo=h.LotNo AND c.WorkPoint=h.WorkPoint
  369. where a.ContainerType='ContainerType04' and h.OASNCode in (" + keyValue.TrimEnd(',') + ") and a.WorkPoint=" + WorkPoint.TrimEnd(',') + "";
  370. DataTable dtInInfo = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  371. strSql = @"
  372. select d.InvCode,e.InvName,sum(d.Quantity) AS Quantity,a.ContainerCode,f.VenName
  373. from ICSContainer a
  374. left join ICSContainer b on a.ID=b.ContainerID and b.ContainerType='ContainerType01' and a.WorkPoint=b.WorkPoint
  375. left join ICSContainerLot c on b.ID=c.ContainerID and b.WorkPoint=c.WorkPoint
  376. left join dbo.ICSInventoryLot d on c.LotNo=d.LotNo and c.WorkPoint=d.WorkPoint
  377. left join dbo.ICSInventory e on d.InvCode=e.InvCode and d.WorkPoint=e.WorkPoint
  378. left join dbo.ICSVendor f on a.EATTRIBUTE8=f.VenCode and a.WorkPoint=f.WorkPoint
  379. LEFT JOIN dbo.ICSOASNDetail h ON c.LotNo=h.LotNo AND c.WorkPoint=h.WorkPoint
  380. where a.ContainerType='ContainerType04' and h.OASNCode in (" + keyValue.TrimEnd(',') + ") and a.WorkPoint=" + WorkPoint.TrimEnd(',') + "group by d.InvCode,e.InvName,a.ContainerCode,f.VenName ";
  381. DataTable dtInMaterial = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  382. string strPrintTempFile = pJson.ShowReport(dtInInfo, dtInMaterial); //产生JSON文件内容
  383. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  384. string strServerURL = GetUrlPath() + "PrintTemp/";
  385. string strData = strServerURL + strPrintTempFile;
  386. strPrintData = PrintFunction.EnBase64(strData);
  387. var JsonData = new
  388. {
  389. strPrintData_1 = strPrintData,
  390. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  391. strPrintControlCookie_1 = strPrintControlCookie
  392. };
  393. //string sql = @"UPDATE dbo.ICSCarton
  394. // SET PrintTimes=ISNULL(PrintTimes,0)+1,
  395. // lastPrintTime=GETDATE()
  396. // WHERE CartonNO IN (" + keyValue.TrimEnd(',') + ") and WorkPoint='" + WorkPoint + "'";
  397. //SqlHelper.ExecuteNonQuery(sql);
  398. return Content(JsonData.ToJson());
  399. }
  400. /// <summary>
  401. /// 写日志(用于跟踪)
  402. /// </summary>
  403. private void WriteLog(string strMessage)
  404. {
  405. string strLogFile = Server.MapPath("./Cookie_Log.txt");
  406. StreamWriter swLogFile = null;
  407. try
  408. {
  409. if (!System.IO.File.Exists(strLogFile))
  410. {
  411. swLogFile = System.IO.File.CreateText(strLogFile);
  412. }
  413. else
  414. {
  415. swLogFile = System.IO.File.AppendText(strLogFile);
  416. }
  417. swLogFile.WriteLine(strMessage);
  418. }
  419. catch
  420. {
  421. }
  422. finally
  423. {
  424. if (swLogFile != null)
  425. swLogFile.Close();
  426. }
  427. }
  428. /// <summary>
  429. ///判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  430. /// </summary>
  431. /// <param name="strCookie"></param>
  432. private void UpdateCheckInstall(string strCookie)
  433. {
  434. bool bIsExist = false;
  435. //判断记录是否存在
  436. GetLastAccessTime(strCookie, ref bIsExist);
  437. string strSql = "";
  438. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) };
  439. if (bIsExist)
  440. { //存在则更新最后访问的时间
  441. strSql = @"Update sys_SRM_CheckInstall
  442. Set LastAccessTime = getDate()
  443. Where Cookie = @Cookie";
  444. }
  445. else
  446. { //不存在则新建一条记录
  447. strSql = @"Insert into sys_SRM_CheckInstall(Cookie, LastAccessTime)
  448. Values( @Cookie, getDate() )";
  449. }
  450. DbHelper.ExecuteNonQuery(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie);
  451. }
  452. public DateTime ToDateTime(object SrcValue)
  453. {
  454. if (Convert.IsDBNull(SrcValue) == true)
  455. return DateTime.MinValue;
  456. else
  457. {
  458. try
  459. {
  460. return Convert.ToDateTime(SrcValue);
  461. }
  462. catch
  463. {
  464. return DateTime.MinValue;
  465. }
  466. }
  467. }
  468. /// <summary>
  469. /// 获取此Cookie的最后访问时间
  470. /// </summary>
  471. /// <param name="strCookie"></param>
  472. /// <returns></returns>
  473. private DateTime GetLastAccessTime(string strCookie, ref bool bIsExist)
  474. {
  475. DateTime dtLastAccessTime = DateTime.MinValue;
  476. bIsExist = false;
  477. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  478. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) };
  479. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  480. {
  481. if (drCookie.Read())
  482. {
  483. dtLastAccessTime = ToDateTime(drCookie["LastAccessTime"]);
  484. bIsExist = true;
  485. }
  486. drCookie.Close();
  487. }
  488. return dtLastAccessTime;
  489. }
  490. [HttpGet]
  491. [HandlerAjaxOnly]
  492. public ActionResult IsCheckInstall(string checkInstall)
  493. {
  494. string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,");
  495. if (Request.QueryString["cookie"] != null)
  496. { //有控件上传的Cookie值
  497. string strCookie = Request.QueryString["cookie"].ToString();
  498. //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  499. UpdateCheckInstall(strCookie);
  500. strValue = strValue + "上传的cookie:" + strCookie;
  501. }
  502. else if (checkInstall != null)
  503. {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况
  504. string strCookie = checkInstall;
  505. //读取最后访问的时间
  506. string strResult = "PrintControlInstall";
  507. bool bIsExist = false;
  508. DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist);
  509. if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now)
  510. {
  511. strResult = "NOT";
  512. }
  513. Response.Clear();
  514. Response.Write(strResult);
  515. strValue = strValue + "检测安装的值:" + strCookie;
  516. }
  517. WriteLog(strValue);
  518. return null;
  519. }
  520. [HttpGet]
  521. [HandlerAjaxOnly]
  522. public ActionResult IsCheckInstall()
  523. {
  524. string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,");
  525. if (Request.QueryString["cookie"] != null)
  526. { //有控件上传的Cookie值
  527. string strCookie = Request.QueryString["cookie"].ToString();
  528. //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  529. UpdateCheckInstall(strCookie);
  530. strValue = strValue + "上传的cookie:" + strCookie;
  531. }
  532. else if (Request.QueryString["checkInstall"] != null)
  533. {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况
  534. string strCookie = Request.QueryString["checkInstall"];
  535. //读取最后访问的时间
  536. string strResult = "PrintControlInstall";
  537. bool bIsExist = false;
  538. DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist);
  539. if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now)
  540. {
  541. strResult = "NOT";
  542. }
  543. Response.Clear();
  544. Response.Write(strResult);
  545. strValue = strValue + "检测安装的值:" + strCookie;
  546. }
  547. WriteLog(strValue);
  548. return null;
  549. }
  550. #endregion
  551. }
  552. }