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.

926 lines
36 KiB

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