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.

498 lines
18 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 InvoiceManageController : ControllerBase
  18. {
  19. private InvoiceManageApp App = new InvoiceManageApp();
  20. [HttpGet]
  21. [HandlerAjaxOnly]
  22. public ActionResult GetGridJson(Pagination pagination, string queryJson)
  23. {
  24. DataTable ListData = App.GetGridJson(queryJson, ref pagination);
  25. var JsonData = new
  26. {
  27. total = pagination.total,
  28. page = pagination.page,
  29. records = pagination.records,
  30. rows = ListData,
  31. };
  32. return Content(JsonData.ToJson());
  33. }
  34. [HttpGet]
  35. [HandlerAjaxOnly]
  36. public ActionResult GetSubGridJson(string ID, Pagination pagination, string WorkPoint)
  37. {
  38. DataTable ListData = App.GetSubGridJson(ID, ref pagination, WorkPoint);
  39. var JsonData = new
  40. {
  41. total = pagination.total,
  42. page = pagination.page,
  43. records = pagination.records,
  44. rows = ListData,
  45. };
  46. return Content(JsonData.ToJson());
  47. }
  48. [HttpGet]
  49. [HandlerAjaxOnly]
  50. public ActionResult GetSubGridJson_Add(string queryJson, Pagination pagination)
  51. {
  52. DataTable ListData = App.GetSubGridJson_Add(queryJson, ref pagination);
  53. var JsonData = new
  54. {
  55. total = pagination.total,
  56. page = pagination.page,
  57. records = pagination.records,
  58. rows = ListData,
  59. };
  60. return Content(JsonData.ToJson());
  61. }
  62. public ActionResult Index()
  63. {
  64. return View();
  65. }
  66. //[HttpGet]
  67. //[HandlerAjaxOnly]
  68. //public ActionResult GetFormJson(string keyValue)
  69. //{
  70. // //var data = maintainAppApp.GetForm(keyValue);
  71. // //return Content(data.ToJson());
  72. //}
  73. [HttpPost]
  74. [HandlerAjaxOnly]
  75. [ValidateAntiForgeryToken]
  76. public ActionResult SubmitForm(string POCode, string PORow, string keyValue)
  77. {
  78. int i = App.CreateItemLotNo(POCode, PORow, keyValue);
  79. if (i > 0)
  80. {
  81. return Success("发布成功!");
  82. }
  83. else
  84. {
  85. return Error("发布失败!");
  86. }
  87. }
  88. public ActionResult ChridenList(string keyValue, string WorkPoint)
  89. {
  90. string result = App.ChridenList(keyValue, WorkPoint);
  91. var JsonData = new
  92. {
  93. result = result
  94. };
  95. return Content(JsonData.ToJson());
  96. }
  97. [HttpGet]
  98. [HandlerAjaxOnly]
  99. public ActionResult GetSubGridJsonByCreate(string POCode, string PORow)
  100. {
  101. DataTable ListData = App.GetSubGridJsonByCreate(POCode, PORow);
  102. var JsonData = new
  103. {
  104. rows = ListData,
  105. };
  106. return Content(JsonData.ToJson());
  107. }
  108. [HttpGet]
  109. [HandlerAjaxOnly]
  110. public ActionResult GetVendorLotNo(string VenCode, string WorkPoint)
  111. {
  112. DataTable ListData = App.GetVendorLotNo(VenCode, WorkPoint);
  113. var JsonData = new
  114. {
  115. VendorLotNo = ListData.Rows[0][0].ToString(),
  116. };
  117. return Content(JsonData.ToJson());
  118. }
  119. [HttpPost]
  120. [HandlerAjaxOnly]
  121. [ValidateAntiForgeryToken]
  122. public ActionResult DeleteDocNo(string keyValue, string WorkPoint)
  123. {
  124. string msg = App.DeleteDocNo(keyValue, WorkPoint);
  125. if (string.IsNullOrEmpty(msg))
  126. {
  127. return Success("删除成功!");
  128. }
  129. else
  130. {
  131. return Error(msg);
  132. }
  133. }
  134. [HttpPost]
  135. [HandlerAjaxOnly]
  136. [ValidateAntiForgeryToken]
  137. public ActionResult UpDateByDocNo(string keyValue, string Status, string WorkPoint)
  138. {
  139. try
  140. {
  141. App.UpDateByDocNoBYPush(keyValue, Status, WorkPoint);
  142. return Success("操作成功!");
  143. }
  144. catch (Exception ex)
  145. {
  146. return Error(ex.Message);
  147. }
  148. }
  149. [HttpGet]
  150. [HandlerAjaxOnly]
  151. public ActionResult CheckIsAll(string STNO)
  152. {
  153. string _result = App.CheckIsAll(STNO);
  154. var JsonData = new
  155. {
  156. result = _result
  157. };
  158. return Content(JsonData.ToJson());
  159. }
  160. [HttpPost]
  161. public ActionResult UpLoadFile()
  162. {
  163. //获取采购订单号
  164. string DocNo = Request.Form["DocNo"].ToString();
  165. string WorkPoint = Request.Form["WorkPoint"].ToString();
  166. //string VenCode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  167. //获取上传的文件集合
  168. HttpFileCollection httpFile = System.Web.HttpContext.Current.Request.Files;
  169. //string fileName = PoCode + Path.GetExtension(httpFile[0].FileName);
  170. string FileAddres = DocNo + Path.GetExtension(httpFile[0].FileName);
  171. string Paths = System.Web.HttpContext.Current.Server.MapPath("~\\File\\Invoice\\" + DocNo);
  172. if (!Directory.Exists(Paths))
  173. {
  174. Directory.CreateDirectory(Paths);
  175. }
  176. string filePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\Invoice\\" + DocNo + "\\" + FileAddres);
  177. int iLen = httpFile[0].ContentLength;
  178. byte[] bData = new byte[iLen];
  179. httpFile[0].InputStream.Read(bData, 0, iLen);
  180. FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate);
  181. fs.Write(bData, 0, bData.Length);
  182. fs.Flush();
  183. fs.Close();
  184. fs.Dispose();
  185. string msg = App.UpLoadFile(DocNo, FileAddres, filePath, WorkPoint);
  186. if (string.IsNullOrEmpty(msg))
  187. {
  188. return Success("上传成功!");
  189. }
  190. else
  191. {
  192. return Error(msg);
  193. }
  194. }
  195. #region 打印
  196. /// <summary>
  197. /// 打印数据参数:服务器的URL+打印的文件名,转化为Base64编码
  198. /// </summary>
  199. protected string strPrintData;
  200. /// <summary>
  201. /// 标识是否安装了控件
  202. /// </summary>
  203. protected bool bIsInstallPrintControl = true;
  204. /// <summary>
  205. /// 打印控件的Cookie值
  206. /// </summary>
  207. protected string strPrintControlCookie = "";
  208. /// <summary>
  209. /// 获取Url中去掉文件名的路径
  210. /// </summary>
  211. /// <returns></returns>
  212. private string GetUrlPath()
  213. {
  214. string strUrl = Request.Url.ToString();
  215. int iEnd = strUrl.LastIndexOf("/");
  216. strUrl = strUrl.Substring(0, iEnd + 1);
  217. return strUrl;
  218. }
  219. /// <summary>
  220. /// 设置控件调用的Cookie值,判断是否安装了打印控件
  221. /// </summary>
  222. /// <param name="pJson"></param>
  223. private void SetCookieAndURL(PrintJson pJson)
  224. {
  225. bIsInstallPrintControl = false;
  226. strPrintControlCookie = "";
  227. HttpCookie pCookieInstall = Request.Cookies["InstallPrintControl"];
  228. if (pCookieInstall != null)
  229. { //Cookie存在
  230. strPrintControlCookie = pCookieInstall.Value.ToString();
  231. //以Cookie值查找在数据表中是否存在
  232. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  233. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strPrintControlCookie) };
  234. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  235. {
  236. if (drCookie.Read())
  237. { //标识为已经安装
  238. bIsInstallPrintControl = true;
  239. }
  240. drCookie.Close();
  241. }
  242. //更新Cookie的保存时间
  243. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  244. Response.SetCookie(pCookieInstall);
  245. }
  246. else
  247. {//Cookie不存在,则新建Cookie
  248. strPrintControlCookie = System.Guid.NewGuid().ToString();
  249. pCookieInstall = new HttpCookie("InstallPrintControl", strPrintControlCookie);
  250. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  251. Response.Cookies.Add(pCookieInstall);
  252. }
  253. string strUrl = Server.MapPath("/PrintTemp/") + "IsCheckInstall";
  254. pJson.SetCookieAndURL(strPrintControlCookie, strUrl);
  255. }
  256. [HttpPost]
  257. [HandlerAjaxOnly]
  258. public ActionResult PrintItemLot(string keyValue, string WorkPoint)
  259. {
  260. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  261. string strPrintFileName = Server.MapPath("/ReportFile/") + "ASN.fr3";
  262. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  263. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  264. pJson.MasterOptions(1, "STNO", false); //主从关系
  265. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  266. string strSql = @"SELECT z.STNO,z.VENDORCODE,x.cVCName,CONVERT(varchar(100),z.CREATEDATE, 23) CREATEDATE,GETDATE() AS printdate FROM dbo.ICSASN z
  267. left join ICSVendor x on z.VENDORCODE=x.cVenCode and z.WorkPoint=x.WorkPoint
  268. WHERE z.STNO IN (" + keyValue.TrimEnd(',') + ") and z.WorkPoint='" + WorkPoint + "'";
  269. DataTable dtInInfo = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  270. strSql = @"SELECT Row_Number() OVER (partition by a.STNO ORDER BY a.CREATETIME desc) AS rowno,
  271. c.STNO,c.ITEMCODE,c.PLANQTY,c.LotnoQTY,c.CartonNOQTY,b.INVNAME,b.INVSTD,b.INVPARSETYPE,b.INVTYPE,b.INVDESC,b.INVUOM,b.INVMACHINETYPE,d.StorageName
  272. FROM
  273. (select aa.stno,aa.itemcode,aa.WorkPoint,sum(aa.PLANQTY) PLANQTY,count(aa.lotno) LotnoQTY,count(bb.CartonNO) CartonNOQTY
  274. from ICSASNDETAIL aa
  275. left join ICSITEMLot2Carton bb on aa.LOTNO=bb.lotno
  276. group by aa.stno,aa.itemcode,aa.WorkPoint ) c
  277. left join ICSASN a on c.stno=a.stno and c.WorkPoint=a.WorkPoint
  278. LEFT JOIN dbo.ICSINVENTORY b ON c.ITEMCODE=b.INVCODE AND b.WorkPoint=c.WorkPoint
  279. left join dbo.icsstorage d on b.INVMACHINETYPE=d.StorageCode
  280. WHERE c.STNO IN (" + keyValue.TrimEnd(',') + ") and c.WorkPoint='" + WorkPoint + "'";
  281. DataTable dtInMaterial = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  282. string strPrintTempFile = pJson.ShowReport(dtInInfo, dtInMaterial); //产生JSON文件内容
  283. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  284. string strServerURL = GetUrlPath() + "PrintTemp/";
  285. string strData = strServerURL + strPrintTempFile;
  286. strPrintData = PrintFunction.EnBase64(strData);
  287. var JsonData = new
  288. {
  289. strPrintData_1 = strPrintData,
  290. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  291. strPrintControlCookie_1 = strPrintControlCookie
  292. };
  293. string sql = @"UPDATE dbo.ICSASN
  294. SET ADDITION1=ISNULL(ADDITION1,0)+1,
  295. ADDITION2=CONVERT(varchar(100), GETDATE(), 21)
  296. WHERE STNO in (" + keyValue.TrimEnd(',') + ") and WorkPoint='" + WorkPoint + "'";
  297. SqlHelper.ExecuteNonQuery(sql);
  298. return Content(JsonData.ToJson());
  299. }
  300. /// <summary>
  301. /// 写日志(用于跟踪)
  302. /// </summary>
  303. private void WriteLog(string strMessage)
  304. {
  305. string strLogFile = Server.MapPath("./Cookie_Log.txt");
  306. StreamWriter swLogFile = null;
  307. try
  308. {
  309. if (!System.IO.File.Exists(strLogFile))
  310. {
  311. swLogFile = System.IO.File.CreateText(strLogFile);
  312. }
  313. else
  314. {
  315. swLogFile = System.IO.File.AppendText(strLogFile);
  316. }
  317. swLogFile.WriteLine(strMessage);
  318. }
  319. catch
  320. {
  321. }
  322. finally
  323. {
  324. if (swLogFile != null)
  325. swLogFile.Close();
  326. }
  327. }
  328. /// <summary>
  329. ///判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  330. /// </summary>
  331. /// <param name="strCookie"></param>
  332. private void UpdateCheckInstall(string strCookie)
  333. {
  334. bool bIsExist = false;
  335. //判断记录是否存在
  336. GetLastAccessTime(strCookie, ref bIsExist);
  337. string strSql = "";
  338. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) };
  339. if (bIsExist)
  340. { //存在则更新最后访问的时间
  341. strSql = @"Update sys_SRM_CheckInstall
  342. Set LastAccessTime = getDate()
  343. Where Cookie = @Cookie";
  344. }
  345. else
  346. { //不存在则新建一条记录
  347. strSql = @"Insert into sys_SRM_CheckInstall(Cookie, LastAccessTime)
  348. Values( @Cookie, getDate() )";
  349. }
  350. DbHelper.ExecuteNonQuery(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie);
  351. }
  352. public DateTime ToDateTime(object SrcValue)
  353. {
  354. if (Convert.IsDBNull(SrcValue) == true)
  355. return DateTime.MinValue;
  356. else
  357. {
  358. try
  359. {
  360. return Convert.ToDateTime(SrcValue);
  361. }
  362. catch
  363. {
  364. return DateTime.MinValue;
  365. }
  366. }
  367. }
  368. /// <summary>
  369. /// 获取此Cookie的最后访问时间
  370. /// </summary>
  371. /// <param name="strCookie"></param>
  372. /// <returns></returns>
  373. private DateTime GetLastAccessTime(string strCookie, ref bool bIsExist)
  374. {
  375. DateTime dtLastAccessTime = DateTime.MinValue;
  376. bIsExist = false;
  377. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  378. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) };
  379. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  380. {
  381. if (drCookie.Read())
  382. {
  383. dtLastAccessTime = ToDateTime(drCookie["LastAccessTime"]);
  384. bIsExist = true;
  385. }
  386. drCookie.Close();
  387. }
  388. return dtLastAccessTime;
  389. }
  390. [HttpGet]
  391. [HandlerAjaxOnly]
  392. public ActionResult IsCheckInstall(string checkInstall)
  393. {
  394. string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,");
  395. if (Request.QueryString["cookie"] != null)
  396. { //有控件上传的Cookie值
  397. string strCookie = Request.QueryString["cookie"].ToString();
  398. //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  399. UpdateCheckInstall(strCookie);
  400. strValue = strValue + "上传的cookie:" + strCookie;
  401. }
  402. else if (checkInstall != null)
  403. {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况
  404. string strCookie = checkInstall;
  405. //读取最后访问的时间
  406. string strResult = "PrintControlInstall";
  407. bool bIsExist = false;
  408. DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist);
  409. if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now)
  410. {
  411. strResult = "NOT";
  412. }
  413. Response.Clear();
  414. Response.Write(strResult);
  415. strValue = strValue + "检测安装的值:" + strCookie;
  416. }
  417. WriteLog(strValue);
  418. return null;
  419. }
  420. [HttpGet]
  421. [HandlerAjaxOnly]
  422. public ActionResult IsCheckInstall()
  423. {
  424. string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,");
  425. if (Request.QueryString["cookie"] != null)
  426. { //有控件上传的Cookie值
  427. string strCookie = Request.QueryString["cookie"].ToString();
  428. //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  429. UpdateCheckInstall(strCookie);
  430. strValue = strValue + "上传的cookie:" + strCookie;
  431. }
  432. else if (Request.QueryString["checkInstall"] != null)
  433. {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况
  434. string strCookie = Request.QueryString["checkInstall"];
  435. //读取最后访问的时间
  436. string strResult = "PrintControlInstall";
  437. bool bIsExist = false;
  438. DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist);
  439. if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now)
  440. {
  441. strResult = "NOT";
  442. }
  443. Response.Clear();
  444. Response.Write(strResult);
  445. strValue = strValue + "检测安装的值:" + strCookie;
  446. }
  447. WriteLog(strValue);
  448. return null;
  449. }
  450. #endregion
  451. }
  452. }