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.

927 lines
36 KiB

1 month ago
  1. 
  2. using NFine.Application.PNSRM;
  3. using NFine.Application.ProductManage;
  4. using NFine.Code;
  5. using NFine.Data.Extensions;
  6. using NFine.Domain.Entity.ProductManage;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Data.SqlClient;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Threading;
  14. using System.Web;
  15. using System.Web.Mvc;
  16. namespace NFine.Web.Areas.PNSRM.Controllers
  17. {
  18. public class ASNManageController : ControllerBase
  19. {
  20. private ASNManageApp App = new ASNManageApp();
  21. public ActionResult Index()
  22. {
  23. return View();
  24. }
  25. public ActionResult ASNAdd()
  26. {
  27. return View();
  28. }
  29. public ActionResult ASNCartonSelect()
  30. {
  31. return View();
  32. }
  33. public ActionResult ASNSelect()
  34. {
  35. return View();
  36. }
  37. public ActionResult ASNUpdate()
  38. {
  39. return View();
  40. }
  41. public ActionResult ASNUpload()
  42. {
  43. return View();
  44. }
  45. [HttpGet]
  46. [HandlerAjaxOnly]
  47. public ActionResult GetGridJson(Pagination pagination, string queryJson)
  48. {
  49. DataTable ListData = App.GetGridJson(queryJson, ref pagination);
  50. var JsonData = new
  51. {
  52. total = pagination.total,
  53. page = pagination.page,
  54. records = pagination.records,
  55. rows = ListData,
  56. };
  57. return Content(JsonData.ToJson());
  58. }
  59. [HttpGet]
  60. [HandlerAjaxOnly]
  61. public ActionResult GetSubGridJson(string STNO, Pagination pagination,string WorkPoint)
  62. {
  63. DataTable ListData = App.GetSubGridJson(STNO, ref pagination, WorkPoint);
  64. var JsonData = new
  65. {
  66. total = pagination.total,
  67. page = pagination.page,
  68. records = pagination.records,
  69. rows = ListData,
  70. };
  71. return Content(JsonData.ToJson());
  72. }
  73. [HttpGet]
  74. [HandlerAjaxOnly]
  75. public ActionResult GetSubGridJson_Add(string queryJson, Pagination pagination)
  76. {
  77. DataTable ListData = App.GetSubGridJson_Add(queryJson, ref pagination);
  78. var JsonData = new
  79. {
  80. total = pagination.total,
  81. page = pagination.page,
  82. records = pagination.records,
  83. rows = ListData,
  84. };
  85. return Content(JsonData.ToJson());
  86. }
  87. //[HttpGet]
  88. //[HandlerAjaxOnly]
  89. //public ActionResult GetFormJson(string keyValue)
  90. //{
  91. // //var data = maintainAppApp.GetForm(keyValue);
  92. // //return Content(data.ToJson());
  93. //}
  94. [HttpPost]
  95. [HandlerAjaxOnly]
  96. [ValidateAntiForgeryToken]
  97. public ActionResult SubmitForm(string POCode, string PORow, string keyValue)
  98. {
  99. int i = App.CreateItemLotNo(POCode, PORow, keyValue);
  100. if (i > 0)
  101. {
  102. return Success("发布成功!");
  103. }
  104. else
  105. {
  106. return Error("发布失败!");
  107. }
  108. }
  109. [HttpGet]
  110. [HandlerAjaxOnly]
  111. public ActionResult GetSubGridJsonByCreate(string POCode, string PORow)
  112. {
  113. DataTable ListData = App.GetSubGridJsonByCreate(POCode, PORow);
  114. var JsonData = new
  115. {
  116. rows = ListData,
  117. };
  118. return Content(JsonData.ToJson());
  119. }
  120. [HttpGet]
  121. [HandlerAjaxOnly]
  122. public ActionResult GetVendorLotNo(string VenCode, string WorkPoint)
  123. {
  124. DataTable ListData = App.GetVendorLotNo(VenCode, WorkPoint);
  125. var JsonData = new
  126. {
  127. VendorLotNo = ListData.Rows[0][0].ToString(),
  128. };
  129. return Content(JsonData.ToJson());
  130. }
  131. public ActionResult DeleteSTNO(string keyValue, string WorkPoint, string EATTRIBUTE1)
  132. {
  133. string msg = App.DeleteSTNO(keyValue, WorkPoint, EATTRIBUTE1);
  134. if (string.IsNullOrEmpty(msg))
  135. {
  136. return Success("删除成功!");
  137. }
  138. else
  139. {
  140. return Error(msg);
  141. }
  142. }
  143. [HttpPost]
  144. [HandlerAjaxOnly]
  145. [ValidateAntiForgeryToken]
  146. public ActionResult UpDateBySTNO(string keyValue, string Status, string WorkPoint)
  147. {
  148. int result = App.UpDateBySTNO(keyValue, Status, WorkPoint);
  149. if (result > 0)
  150. {
  151. return Success("操作成功!");
  152. }
  153. else
  154. {
  155. return Error("操作失败!");
  156. }
  157. }
  158. [HttpPost]
  159. [HandlerAjaxOnly]
  160. [ValidateAntiForgeryToken]
  161. public ActionResult UpDateBySTNODH(string keyValue)
  162. {
  163. string result = App.UpDateBySTNODH(keyValue);
  164. if (string.IsNullOrWhiteSpace( result))
  165. {
  166. return Success("操作成功!");
  167. }
  168. else
  169. {
  170. return Error("操作失败!失败原因:"+ result);
  171. }
  172. }
  173. [HttpGet]
  174. [HandlerAjaxOnly]
  175. public ActionResult CheckIsAll(string STNO,string WorkPoint)
  176. {
  177. string _result = App.CheckIsAll(STNO, WorkPoint);
  178. var JsonData = new
  179. {
  180. result = _result
  181. };
  182. return Content(JsonData.ToJson());
  183. }
  184. #region 打印
  185. /// <summary>
  186. /// 打印数据参数:服务器的URL+打印的文件名,转化为Base64编码
  187. /// </summary>
  188. protected string strPrintData;
  189. /// <summary>
  190. /// 标识是否安装了控件
  191. /// </summary>
  192. protected bool bIsInstallPrintControl = true;
  193. /// <summary>
  194. /// 打印控件的Cookie值
  195. /// </summary>
  196. protected string strPrintControlCookie = "";
  197. /// <summary>
  198. /// 获取Url中去掉文件名的路径
  199. /// </summary>
  200. /// <returns></returns>
  201. private string GetUrlPath()
  202. {
  203. string strUrl = Request.Url.ToString();
  204. int iEnd = strUrl.LastIndexOf("/");
  205. strUrl = strUrl.Substring(0, iEnd + 1);
  206. return strUrl;
  207. }
  208. /// <summary>
  209. /// 设置控件调用的Cookie值,判断是否安装了打印控件
  210. /// </summary>
  211. /// <param name="pJson"></param>
  212. private void SetCookieAndURL(PrintJson pJson)
  213. {
  214. bIsInstallPrintControl = false;
  215. strPrintControlCookie = "";
  216. HttpCookie pCookieInstall = Request.Cookies["InstallPrintControl"];
  217. if (pCookieInstall != null)
  218. { //Cookie存在
  219. strPrintControlCookie = pCookieInstall.Value.ToString();
  220. //以Cookie值查找在数据表中是否存在
  221. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  222. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strPrintControlCookie) };
  223. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  224. {
  225. if (drCookie.Read())
  226. { //标识为已经安装
  227. bIsInstallPrintControl = true;
  228. }
  229. drCookie.Close();
  230. }
  231. //更新Cookie的保存时间
  232. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  233. Response.SetCookie(pCookieInstall);
  234. }
  235. else
  236. {//Cookie不存在,则新建Cookie
  237. strPrintControlCookie = System.Guid.NewGuid().ToString();
  238. pCookieInstall = new HttpCookie("InstallPrintControl", strPrintControlCookie);
  239. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  240. Response.Cookies.Add(pCookieInstall);
  241. }
  242. string strUrl = Server.MapPath("/PrintTemp/") + "IsCheckInstall";
  243. pJson.SetCookieAndURL(strPrintControlCookie, strUrl);
  244. }
  245. [HttpPost]
  246. [HandlerAjaxOnly]
  247. public ActionResult PrintItemLot(string keyValue, string WorkPoint)
  248. {
  249. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  250. WorkPoint = WorkPoint.Substring(1,WorkPoint.Length-2);
  251. string strPrintFileName = Server.MapPath("/ReportFile/") + "ASN.fr3";
  252. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  253. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  254. pJson.MasterOptions(1, "ASNCode", false); //主从关系
  255. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  256. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  257. string strSql = @"SELECT z.AsnCode,z.VenCode,x.VenName,CONVERT(varchar(100),z.Mtime, 23) CREATEDATE,GETDATE() AS printdate,z.EATTRIBUTE1
  258. ,VenPerson,VenHand,CONVERT(varchar(20), GETDATE(), 23) as DateNo
  259. ,CONVERT(varchar(20), z.mtime , 23) mtime
  260. FROM dbo.ICSASN z
  261. left join ICSVendor x on z.VenCode=x.VenCode and z.WorkPoint=x.WorkPoint
  262. WHERE z.AsnCode IN (" + keyValue.TrimEnd(',') + ") and z.WorkPoint=" + WorkPoint.TrimEnd(',') + "";
  263. DataTable dtInInfo = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  264. strSql = @"SELECT Row_Number() OVER (partition by a.ASNCode ORDER BY a.MTIME desc) AS rowno,
  265. aa.ASNCode, bb.InvCode,SUM(bb.Quantity)AS Quantity,cc.TransCode,b.InvName,b.InvStd,b.InvUnit,ee.BatchCode,ee.ProjectCode
  266. ,ff.CreatePerson,ff.EATTRIBUTE3 as DXEATTRIBUTE3,ff.EATTRIBUTE4 as DXEATTRIBUTE4,a.MTIME
  267. ,ff.EATTRIBUTE12,ff.CreatePerson,ISNULL(ff.Quantity,0)AS POQuantity,ISNULL(ff.Quantity,0)-ISNULL(gg.Quantity,0)AS infoQuantity,ff.EATTRIBUTE2
  268. FROM ICSASNDETAIL aa
  269. left join dbo.ICSInventoryLot bb on aa.LOTNO=bb.lotno AND aa.WorkPoint=bb.WorkPoint
  270. LEFT JOIN dbo.ICSInventoryLotDetail cc ON bb.LotNo=cc.LotNo AND bb.WorkPoint=cc.WorkPoint
  271. left join ICSASN a on aa.ASNCode=a.ASNCode and a.WorkPoint=a.WorkPoint
  272. LEFT JOIN dbo.ICSINVENTORY b ON bb.InvCode=b.INVCODE AND b.WorkPoint=a.WorkPoint
  273. LEFT JOIN dbo.ICSExtension ee ON bb.ExtensionID=ee.ID AND bb.WorkPoint=ee.WorkPoint
  274. LEFT JOIN ICSPurchaseOrder ff on cc.TransCode=ff.POCode and cc.TransSequence=ff.Sequence and cc.WorkPoint=ff.WorkPoint
  275. LEFT JOIN (SELECT TransCode,TransSequence,sum(Quantity) Quantity,WorkPoint FROM dbo.ICSWareHouseLotInfoLog WHERE BusinessCode='1' GROUP BY TransCode,TransSequence,WorkPoint) gg ON ff.POCode=gg.TransCode AND ff.Sequence=gg.TransSequence AND ff.WorkPoint=gg.WorkPoint
  276. WHERE aa.ASNCode IN (" + keyValue.TrimEnd(',') + ") and aa.WorkPoint=" + WorkPoint.TrimEnd(',') + @"
  277. GROUP BY aa.ASNCode,bb.InvCode,cc.TransCode,b.InvName,b.InvStd,b.InvUnit,ee.BatchCode,ee.ProjectCode,a.MTIME,a.ASNCode,ff.CreatePerson,ff.EATTRIBUTE3,ff.EATTRIBUTE4 ,ff.EATTRIBUTE12,ff.Quantity,gg.Quantity,ff.EATTRIBUTE2";
  278. DataTable dtInMaterial = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  279. string strPrintTempFile = pJson.ShowReport(dtInInfo, dtInMaterial); //产生JSON文件内容
  280. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  281. string strServerURL = GetUrlPath() + "PrintTemp/";
  282. string strData = strServerURL + strPrintTempFile;
  283. strPrintData = PrintFunction.EnBase64(strData);
  284. var JsonData = new
  285. {
  286. strPrintData_1 = strPrintData,
  287. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  288. strPrintControlCookie_1 = strPrintControlCookie
  289. };
  290. // string sql = @"UPDATE dbo.ICSASN
  291. // SET ADDITION1=ISNULL(ADDITION1,0)+1,
  292. // ADDITION2=CONVERT(varchar(100), GETDATE(), 21)
  293. // WHERE STNO in (" + keyValue.TrimEnd(',') + ") and WorkPoint=" + WorkPoint.TrimEnd(',') + "";
  294. // SqlHelper.ExecuteNonQuery(sql);
  295. return Content(JsonData.ToJson());
  296. }
  297. #region 根据单号打印条码信息
  298. [HttpPost]
  299. [HandlerAjaxOnly]
  300. public ActionResult PrintItemASNLot(string keyValue, string WorkPoint)
  301. {
  302. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  303. WorkPoint = WorkPoint.Substring(1, WorkPoint.Length - 2);
  304. string strPrintFileName = Server.MapPath("/ReportFile/") + "lot.fr3";
  305. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  306. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  307. pJson.MasterOptions(1, "ASNCode", false); //主从关系
  308. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  309. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  310. string strSql = @"SELECT distinct b.ExtensionID,a.InvCode,a.LotNo AS QRLotNo,b.POCode,CONVERT(varchar(100),b.CreateDateTime, 23) PODate,g.BatchCode,a.Quantity,c.InvName,
  311. c.InvStd,
  312. c.ClassName,c.InvDesc,
  313. b.VenCode,h.VenName,c.InvUnit,f.WarehouseName,
  314. a.LotNO AS QRLotNo,CONVERT(varchar(100), a.ProductDate, 23) as PRODUCTDATE,CONVERT(varchar(100), b.PlanArriveDate, 23) as PreArriveDate
  315. ,CAST(b.VenCode+'_'+a.InvCode+'_'+CAST(a.Quantity AS NVARCHAR(20))+'_'+c.InvUnit+g.BatchCode+'_'+CONVERT(varchar(100), a.ProductDate, 23)+'_' +a.LotNo AS NVARCHAR(100)) AS erweima
  316. ,a.EATTRIBUTE3,CONVERT(varchar(100),dateadd(day,c.EffectiveDays,a.ProductDate), 23) AS exprdate,i.asnCode,b.EATTRIBUTE3 as DXEATTRIBUTE3
  317. ,a.EATTRIBUTE4 as DXEATTRIBUTE4,b.EATTRIBUTE4 as PODXEATTRIBUTE4,c1.LocationCode
  318. FROM dbo.ICSInventoryLot a
  319. left join ICSExtension g on a.ExtensionID=g.ID and a.WorkPoint=g.WorkPoint
  320. left join ICSInventoryLotDetail e on a.lotNo=e.LotNo and a.WorkPoint=e.WorkPoint
  321. LEFT JOIN dbo.ICSPurchaseOrder b ON b.POCode=e.TransCode AND b.Sequence=e.TransSequence AND a.WorkPoint=e.WorkPoint
  322. LEFT JOIN dbo.ICSInventory c ON a.InvCode=c.InvCode AND a.WorkPoint=c.WorkPoint
  323. left join dbo.ICSInventoryBatchEnable d on c.InvCode=d.InvCode and c.WorkPoint=d.WorkPoint AND d.BatchEnable=1
  324. left join ICSWarehouse f on d.WHCode=f.WarehouseCode and d.WorkPoint=f.WorkPoint
  325. left join ICSVendor h on b.VenCode=h.VenCode and b.WorkPoint=h.WorkPoint
  326. LEFT JOIN icsasndetail i ON a.lotNO=i.LotNO AND a.workPoint=i.workPoint
  327. LEFT JOIN (
  328. SELECT
  329. InvCode,
  330. WarehouseCode,
  331. LocationCode,
  332. MTIME,
  333. WorkPoint,
  334. new_index
  335. FROM
  336. (
  337. SELECT
  338. b.InvCode,
  339. b.WarehouseCode,
  340. b.LocationCode,
  341. b.MTIME,
  342. b.WorkPoint,
  343. ROW_NUMBER() OVER (
  344. PARTITION BY b.InvCode
  345. ORDER BY b.MTIME ASC
  346. ) AS new_index
  347. FROM
  348. ICSWareHouseLotInfo b WITH (NOLOCK)
  349. WHERE
  350. b.quantity > 0
  351. ) AS subquery
  352. WHERE
  353. new_index = 1
  354. ) c1 ON c1.invcode = a.invcode
  355. AND c1.WorkPoint = a.WorkPoint
  356. WHERE i.ID IN (" + keyValue.TrimEnd(',') + ") and a.WorkPoint in (" + WorkPoint.Trim(',') + ")";
  357. DataTable dtInInfo = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  358. string strPrintTempFile = pJson.ShowReport(dtInInfo); //产生JSON文件内容
  359. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  360. string strServerURL = GetUrlPath() + "PrintTemp/";
  361. string strData = strServerURL + strPrintTempFile;
  362. strPrintData = PrintFunction.EnBase64(strData);
  363. var JsonData = new
  364. {
  365. strPrintData_1 = strPrintData,
  366. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  367. strPrintControlCookie_1 = strPrintControlCookie
  368. };
  369. // string sql = @"UPDATE dbo.ICSASN
  370. // SET ADDITION1=ISNULL(ADDITION1,0)+1,
  371. // ADDITION2=CONVERT(varchar(100), GETDATE(), 21)
  372. // WHERE STNO in (" + keyValue.TrimEnd(',') + ") and WorkPoint=" + WorkPoint.TrimEnd(',') + "";
  373. // SqlHelper.ExecuteNonQuery(sql);
  374. return Content(JsonData.ToJson());
  375. }
  376. #endregion
  377. #region 根据单号打印条码信息
  378. [HttpPost]
  379. [HandlerAjaxOnly]
  380. public ActionResult PrintItemASNLotByYL(string keyValue)
  381. {
  382. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  383. string strPrintFileName = Server.MapPath("/ReportFile/") + "lot.fr3";
  384. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  385. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  386. pJson.MasterOptions(1, "ASNCode", false); //主从关系
  387. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  388. //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  389. string strSql = @"SELECT distinct b.ExtensionID,a.InvCode,a.LotNo AS QRLotNo,b.POCode,CONVERT(varchar(100),b.CreateDateTime, 23) PODate,g.BatchCode,a.Quantity,c.InvName,
  390. c.InvStd,
  391. c.ClassName,c.InvDesc,
  392. b.VenCode,h.VenName,c.InvUnit,f.WarehouseName,
  393. a.LotNO AS QRLotNo,CONVERT(varchar(100), a.ProductDate, 23) as PRODUCTDATE,CONVERT(varchar(100), b.PlanArriveDate, 23) as PreArriveDate
  394. ,CAST(b.VenCode+'_'+a.InvCode+'_'+CAST(a.Quantity AS NVARCHAR(20))+'_'+c.InvUnit+g.BatchCode+'_'+CONVERT(varchar(100), a.ProductDate, 23)+'_' +a.LotNo AS NVARCHAR(100)) AS erweima
  395. ,a.EATTRIBUTE3,CONVERT(varchar(100),dateadd(day,c.EffectiveDays,a.ProductDate), 23) AS exprdate,i.asnCode,b.EATTRIBUTE3 as DXEATTRIBUTE3
  396. ,a.EATTRIBUTE4 as DXEATTRIBUTE4,b.EATTRIBUTE4 as PODXEATTRIBUTE4,c1.LocationCode,c.EATTRIBUTE11,c.EATTRIBUTE12,c.EATTRIBUTE13,c.EATTRIBUTE14,c.EATTRIBUTE15
  397. ,c.EATTRIBUTE16,c.EATTRIBUTE17,c.EATTRIBUTE18,
  398. CASE WHEN c.EATTRIBUTE19='1'THEN''WHEN c.EATTRIBUTE19='0'THEN'' END EATTRIBUTE19,ISNULL(a.EATTRIBUTE6,'') as isSJBGInvCode,a.EATTRIBUTE8, CASE WHEN c.InvIQC='0' THEN '免'ELSE '' END AS InvIQC
  399. FROM dbo.ICSInventoryLot a
  400. left join ICSExtension g on a.ExtensionID=g.ID and a.WorkPoint=g.WorkPoint
  401. left join ICSInventoryLotDetail e on a.lotNo=e.LotNo and a.WorkPoint=e.WorkPoint
  402. LEFT JOIN dbo.ICSPurchaseOrder b ON b.POCode=e.TransCode AND b.Sequence=e.TransSequence AND a.WorkPoint=e.WorkPoint
  403. LEFT JOIN dbo.ICSInventory c ON a.InvCode=c.InvCode AND a.WorkPoint=c.WorkPoint
  404. left join dbo.ICSInventoryBatchEnable d on c.InvCode=d.InvCode and c.WorkPoint=d.WorkPoint AND d.BatchEnable=1
  405. left join ICSWarehouse f on d.WHCode=f.WarehouseCode and d.WorkPoint=f.WorkPoint
  406. left join ICSVendor h on b.VenCode=h.VenCode and b.WorkPoint=h.WorkPoint
  407. LEFT JOIN icsasndetail i ON a.lotNO=i.LotNO AND a.workPoint=i.workPoint
  408. LEFT JOIN (
  409. SELECT
  410. InvCode,
  411. WarehouseCode,
  412. LocationCode,
  413. MTIME,
  414. WorkPoint,
  415. new_index
  416. FROM
  417. (
  418. SELECT
  419. b.InvCode,
  420. b.WarehouseCode,
  421. b.LocationCode,
  422. b.MTIME,
  423. b.WorkPoint,
  424. ROW_NUMBER() OVER (
  425. PARTITION BY b.InvCode
  426. ORDER BY b.MTIME ASC
  427. ) AS new_index
  428. FROM
  429. ICSWareHouseLotInfo b WITH (NOLOCK)
  430. WHERE
  431. b.quantity > 0
  432. ) AS subquery
  433. WHERE
  434. new_index = 1
  435. ) c1 ON c1.invcode = a.invcode
  436. AND c1.WorkPoint = a.WorkPoint
  437. WHERE i.ASNCode IN (" + keyValue.TrimEnd(',') + ")";
  438. DataTable dtInInfo = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  439. string strPrintTempFile = pJson.ShowReport(dtInInfo); //产生JSON文件内容
  440. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  441. string strServerURL = GetUrlPath() + "PrintTemp/";
  442. string strData = strServerURL + strPrintTempFile;
  443. strPrintData = PrintFunction.EnBase64(strData);
  444. var JsonData = new
  445. {
  446. strPrintData_1 = strPrintData,
  447. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  448. strPrintControlCookie_1 = strPrintControlCookie
  449. };
  450. // string sql = @"UPDATE dbo.ICSASN
  451. // SET ADDITION1=ISNULL(ADDITION1,0)+1,
  452. // ADDITION2=CONVERT(varchar(100), GETDATE(), 21)
  453. // WHERE STNO in (" + keyValue.TrimEnd(',') + ") and WorkPoint=" + WorkPoint.TrimEnd(',') + "";
  454. // SqlHelper.ExecuteNonQuery(sql);
  455. return Content(JsonData.ToJson());
  456. }
  457. #endregion
  458. /// <summary>
  459. /// 写日志(用于跟踪)
  460. /// </summary>
  461. private void WriteLog(string strMessage)
  462. {
  463. string strLogFile = Server.MapPath("./Cookie_Log.txt");
  464. StreamWriter swLogFile = null;
  465. try
  466. {
  467. if (!System.IO.File.Exists(strLogFile))
  468. {
  469. swLogFile = System.IO.File.CreateText(strLogFile);
  470. }
  471. else
  472. {
  473. swLogFile = System.IO.File.AppendText(strLogFile);
  474. }
  475. swLogFile.WriteLine(strMessage);
  476. }
  477. catch
  478. {
  479. }
  480. finally
  481. {
  482. if (swLogFile != null)
  483. swLogFile.Close();
  484. }
  485. }
  486. /// <summary>
  487. ///判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  488. /// </summary>
  489. /// <param name="strCookie"></param>
  490. private void UpdateCheckInstall(string strCookie)
  491. {
  492. bool bIsExist = false;
  493. //判断记录是否存在
  494. GetLastAccessTime(strCookie, ref bIsExist);
  495. string strSql = "";
  496. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) };
  497. if (bIsExist)
  498. { //存在则更新最后访问的时间
  499. strSql = @"Update sys_SRM_CheckInstall
  500. Set LastAccessTime = getDate()
  501. Where Cookie = @Cookie";
  502. }
  503. else
  504. { //不存在则新建一条记录
  505. strSql = @"Insert into sys_SRM_CheckInstall(Cookie, LastAccessTime)
  506. Values( @Cookie, getDate() )";
  507. }
  508. DbHelper.ExecuteNonQuery(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie);
  509. }
  510. public DateTime ToDateTime(object SrcValue)
  511. {
  512. if (Convert.IsDBNull(SrcValue) == true)
  513. return DateTime.MinValue;
  514. else
  515. {
  516. try
  517. {
  518. return Convert.ToDateTime(SrcValue);
  519. }
  520. catch
  521. {
  522. return DateTime.MinValue;
  523. }
  524. }
  525. }
  526. /// <summary>
  527. /// 获取此Cookie的最后访问时间
  528. /// </summary>
  529. /// <param name="strCookie"></param>
  530. /// <returns></returns>
  531. private DateTime GetLastAccessTime(string strCookie, ref bool bIsExist)
  532. {
  533. DateTime dtLastAccessTime = DateTime.MinValue;
  534. bIsExist = false;
  535. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  536. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) };
  537. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  538. {
  539. if (drCookie.Read())
  540. {
  541. dtLastAccessTime = ToDateTime(drCookie["LastAccessTime"]);
  542. bIsExist = true;
  543. }
  544. drCookie.Close();
  545. }
  546. return dtLastAccessTime;
  547. }
  548. [HttpGet]
  549. [HandlerAjaxOnly]
  550. public ActionResult IsCheckInstall(string checkInstall)
  551. {
  552. string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,");
  553. if (Request.QueryString["cookie"] != null)
  554. { //有控件上传的Cookie值
  555. string strCookie = Request.QueryString["cookie"].ToString();
  556. //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  557. UpdateCheckInstall(strCookie);
  558. strValue = strValue + "上传的cookie:" + strCookie;
  559. }
  560. else if (checkInstall != null)
  561. {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况
  562. string strCookie = checkInstall;
  563. //读取最后访问的时间
  564. string strResult = "PrintControlInstall";
  565. bool bIsExist = false;
  566. DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist);
  567. if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now)
  568. {
  569. strResult = "NOT";
  570. }
  571. Response.Clear();
  572. Response.Write(strResult);
  573. strValue = strValue + "检测安装的值:" + strCookie;
  574. }
  575. WriteLog(strValue);
  576. return null;
  577. }
  578. [HttpGet]
  579. [HandlerAjaxOnly]
  580. public ActionResult IsCheckInstall()
  581. {
  582. string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,");
  583. if (Request.QueryString["cookie"] != null)
  584. { //有控件上传的Cookie值
  585. string strCookie = Request.QueryString["cookie"].ToString();
  586. //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  587. UpdateCheckInstall(strCookie);
  588. strValue = strValue + "上传的cookie:" + strCookie;
  589. }
  590. else if (Request.QueryString["checkInstall"] != null)
  591. {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况
  592. string strCookie = Request.QueryString["checkInstall"];
  593. //读取最后访问的时间
  594. string strResult = "PrintControlInstall";
  595. bool bIsExist = false;
  596. DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist);
  597. if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now)
  598. {
  599. strResult = "NOT";
  600. }
  601. Response.Clear();
  602. Response.Write(strResult);
  603. strValue = strValue + "检测安装的值:" + strCookie;
  604. }
  605. WriteLog(strValue);
  606. return null;
  607. }
  608. #endregion
  609. [HttpGet]
  610. [HandlerAjaxOnly]
  611. public ActionResult GetICSASNCode(string RoleEnCode, string WorkPoint)
  612. {
  613. string ListData = App.GetICSASNCode(RoleEnCode, WorkPoint);
  614. var data = new
  615. {
  616. rows = ListData,
  617. };
  618. return Content(data.ToJson());
  619. }
  620. [HttpGet]
  621. [HandlerAjaxOnly]
  622. public ActionResult GetVendor()
  623. {
  624. DataTable dt = App.GetVendor();
  625. return Content(dt.ToJson());
  626. }
  627. [HttpGet]
  628. [HandlerAjaxOnly]
  629. public ActionResult GetWorkPoint()
  630. {
  631. DataTable dt = App.GetWorkPoint();
  632. return Content(dt.ToJson());
  633. }
  634. [HttpGet]
  635. [HandlerAjaxOnly]
  636. public ActionResult GetInfoBySelectItemCode(Pagination pagination, string queryJson)
  637. {
  638. DataTable ListData = App.GetInfoBySelectItemCode(queryJson, ref pagination);
  639. var JsonData = new
  640. {
  641. total = pagination.total,
  642. page = pagination.page,
  643. records = pagination.records,
  644. rows = ListData,
  645. };
  646. return Content(JsonData.ToJson());
  647. }
  648. [HttpGet]
  649. [HandlerAjaxOnly]
  650. public ActionResult GetCartonGridJson(Pagination pagination, string queryJson, string WorkPoint)
  651. {
  652. DataTable ListData = App.GetCartonGridJson(queryJson, ref pagination, WorkPoint);
  653. var JsonData = new
  654. {
  655. total = pagination.total,
  656. page = pagination.page,
  657. records = pagination.records,
  658. rows = ListData,
  659. };
  660. return Content(JsonData.ToJson());
  661. }
  662. [HttpGet]
  663. [HandlerAjaxOnly]
  664. public ActionResult GetLotByContainer(string Value ,string WorkPoint)
  665. {
  666. DataTable ListData = App.GetLotByContainer(Value, WorkPoint);
  667. var JsonData = new
  668. {
  669. rows = ListData,
  670. };
  671. return Content(JsonData.ToJson());
  672. }
  673. [HttpPost]
  674. [HandlerAjaxOnly]
  675. public ActionResult SaveICSASNAndDetail(string ICSASN,string WorkPoint)
  676. {
  677. string msg = App.SaveICSASNAndDetail(ICSASN, WorkPoint);
  678. if (!string.IsNullOrEmpty(msg))
  679. {
  680. return Error(msg);
  681. }
  682. else
  683. {
  684. return Success("添加成功!");
  685. }
  686. }
  687. [HttpPost]
  688. [HandlerAjaxOnly]
  689. public ActionResult UpdateICSASNAndDetail(string ICSASN)
  690. {
  691. string msg = App.UpdateICSASNAndDetail(ICSASN);
  692. if (!string.IsNullOrEmpty(msg))
  693. {
  694. return Error(msg);
  695. }
  696. else
  697. {
  698. return Success("修改成功!");
  699. }
  700. }
  701. public ActionResult GetContainerListType()
  702. {
  703. string sql = @"select F_ItemCode as Code,F_ItemName as Name from Sys_SRM_ItemsDetail where F_ItemId='6230217e-4413-4427-9bec-c67ba789eca9' and F_EnabledMark='1' order by F_ItemCode";
  704. DataTable ListData = SqlHelper.GetDataTableBySql(sql);
  705. return Content(ListData.ToJson());
  706. }
  707. [HttpGet]
  708. [HandlerAjaxOnly]
  709. public ActionResult GetGridJsonUpload(Pagination pagination, string STNO, string queryJson, string WorkPoint)
  710. {
  711. DataTable ListData = App.GetGridJsonUpload(queryJson, STNO,ref pagination, WorkPoint);
  712. var JsonData = new
  713. {
  714. total = pagination.total,
  715. page = pagination.page,
  716. records = pagination.records,
  717. rows = ListData,
  718. };
  719. return Content(JsonData.ToJson());
  720. }
  721. [HttpGet]
  722. [HandlerAjaxOnly]
  723. public ActionResult GetGridJsonUpload2(Pagination pagination, string STNO, string queryJson, string WorkPoint)
  724. {
  725. DataTable ListData = App.GetGridJsonUpload2(queryJson, STNO, ref pagination, WorkPoint);
  726. var JsonData = new
  727. {
  728. total = pagination.total,
  729. page = pagination.page,
  730. records = pagination.records,
  731. rows = ListData,
  732. };
  733. return Content(JsonData.ToJson());
  734. }
  735. [HttpPost]
  736. public ActionResult UpLoadFile(string STNO,string InvCode,string BatchCodeNum,string BatchCode,string VenCode,string Type)
  737. {
  738. try
  739. {
  740. string msg = "";
  741. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  742. string FileName = "";
  743. string PathName = "";
  744. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  745. string Name = "";
  746. //获取上传的文件集合
  747. var QuotationNo = STNO + InvCode + BatchCode;
  748. HttpFileCollection httpFile = System.Web.HttpContext.Current.Request.Files;
  749. for (int i = 0; i < httpFile.Count; i++)
  750. {
  751. FileName = Path.GetFileNameWithoutExtension(httpFile[i].FileName) + Path.GetExtension(httpFile[i].FileName);
  752. string Paths = System.Web.HttpContext.Current.Server.MapPath("~\\File\\VendorFile\\" + VenCode + "\\" + QuotationNo + "");
  753. if (!Directory.Exists(Paths))
  754. {
  755. Directory.CreateDirectory(Paths);
  756. }
  757. PathName = System.Web.HttpContext.Current.Server.MapPath("~\\File\\VendorFile\\" + VenCode + "\\" + QuotationNo + "\\" + FileName);
  758. int iLen = httpFile[0].ContentLength;
  759. byte[] bData = new byte[iLen];
  760. httpFile[0].InputStream.Read(bData, 0, iLen);
  761. FileStream fs = new FileStream(PathName, FileMode.OpenOrCreate);
  762. fs.Write(bData, 0, bData.Length);
  763. fs.Flush();
  764. fs.Close();
  765. fs.Dispose();
  766. Name += "" + FileName + ";";
  767. }
  768. if (Type=="1")
  769. {
  770. msg = App.UpLoadFile(STNO, InvCode, BatchCode, VenCode, BatchCodeNum, FileName, PathName);
  771. }
  772. else
  773. {
  774. msg = App.UpLoadFile2(STNO, InvCode, BatchCode, VenCode, BatchCodeNum, FileName, PathName);
  775. }
  776. // string msg = App.UpLoadFile(STNO, InvCode, BatchCode, VenCode, BatchCodeNum, FileName, PathName);
  777. if (!string.IsNullOrEmpty(msg))
  778. {
  779. return Error(msg);
  780. }
  781. else
  782. {
  783. return Success("上传成功!");
  784. }
  785. }
  786. catch (Exception ex)
  787. {
  788. return Error(ex.Message);
  789. }
  790. }
  791. [HttpGet]
  792. [HandlerAjaxOnly]
  793. public ActionResult CheckIsASNAudit()
  794. {
  795. string _result = App.CheckIsASNAudit();
  796. var JsonData = new
  797. {
  798. result = _result
  799. };
  800. return Content(JsonData.ToJson());
  801. }
  802. public ActionResult ISEableReport(string Code ,string VenCode,string Type)
  803. {
  804. bool result = App.ISEableReport(Code, VenCode, Type);
  805. var JsonData = new
  806. {
  807. result = result
  808. };
  809. return Content(JsonData.ToJson());
  810. }
  811. [HttpGet]
  812. [HandlerAjaxOnly]
  813. public ActionResult IsASNByCarton()
  814. {
  815. string _result = App.IsASNByCarton();
  816. var JsonData = new
  817. {
  818. result = _result
  819. };
  820. return Content(JsonData.ToJson());
  821. }
  822. }
  823. }