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.

512 lines
19 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 InvoiceManageAdminController : 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.GetGridJsonAdmin(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. [HttpGet]
  89. [HandlerAjaxOnly]
  90. public ActionResult GetSubGridJsonByCreate(string POCode, string PORow)
  91. {
  92. DataTable ListData = App.GetSubGridJsonByCreate(POCode, PORow);
  93. var JsonData = new
  94. {
  95. rows = ListData,
  96. };
  97. return Content(JsonData.ToJson());
  98. }
  99. [HttpGet]
  100. [HandlerAjaxOnly]
  101. public ActionResult GetVendorLotNo(string VenCode, string WorkPoint)
  102. {
  103. DataTable ListData = App.GetVendorLotNo(VenCode, WorkPoint);
  104. var JsonData = new
  105. {
  106. VendorLotNo = ListData.Rows[0][0].ToString(),
  107. };
  108. return Content(JsonData.ToJson());
  109. }
  110. [HttpPost]
  111. [HandlerAjaxOnly]
  112. [ValidateAntiForgeryToken]
  113. public ActionResult DeleteDocNo(string keyValue, string WorkPoint)
  114. {
  115. string msg = App.DeleteDocNo(keyValue, WorkPoint);
  116. if (string.IsNullOrEmpty(msg))
  117. {
  118. return Success("删除成功!");
  119. }
  120. else
  121. {
  122. return Error(msg);
  123. }
  124. }
  125. [HttpPost]
  126. [HandlerAjaxOnly]
  127. [ValidateAntiForgeryToken]
  128. public ActionResult UpDateByDocNo(string keyValue, string Status, string WorkPoint)
  129. {
  130. int result = App.UpDateByDocNo(keyValue, Status, WorkPoint);
  131. if (result > 0)
  132. {
  133. return Success("操作成功!");
  134. }
  135. else
  136. {
  137. return Error("操作失败!");
  138. }
  139. }
  140. [HttpPost]
  141. [HandlerAjaxOnly]
  142. [ValidateAntiForgeryToken]
  143. public ActionResult Bookkeeping(string keyValue, string PaperNo, string WorkPoint)
  144. {
  145. //try
  146. //{
  147. // App.Bookkeeping(keyValue, PaperNo, WorkPoint);
  148. // return Success("记账成功");
  149. //}
  150. //catch (Exception ex)
  151. //{
  152. // return Error(ex.Message);
  153. //}
  154. string msg = App.Bookkeeping(keyValue, PaperNo, WorkPoint);
  155. if (string.IsNullOrEmpty(msg))
  156. {
  157. return Success("记账成功!");
  158. }
  159. else
  160. {
  161. return Error("" + msg + "");
  162. }
  163. }
  164. [HttpPost]
  165. [HandlerAjaxOnly]
  166. [ValidateAntiForgeryToken]
  167. public ActionResult ReturnByDocNo(string keyValue, string WorkPoint)
  168. {
  169. int result = App.ReturnByDocNo(keyValue, WorkPoint);
  170. if (result > 0)
  171. {
  172. return Success("操作成功!");
  173. }
  174. else
  175. {
  176. return Error("操作失败!");
  177. }
  178. }
  179. [HttpGet]
  180. [HandlerAjaxOnly]
  181. public ActionResult CheckIsAll(string STNO)
  182. {
  183. string _result = App.CheckIsAll(STNO);
  184. var JsonData = new
  185. {
  186. result = _result
  187. };
  188. return Content(JsonData.ToJson());
  189. }
  190. #region 打印
  191. /// <summary>
  192. /// 打印数据参数:服务器的URL+打印的文件名,转化为Base64编码
  193. /// </summary>
  194. protected string strPrintData;
  195. /// <summary>
  196. /// 标识是否安装了控件
  197. /// </summary>
  198. protected bool bIsInstallPrintControl = true;
  199. /// <summary>
  200. /// 打印控件的Cookie值
  201. /// </summary>
  202. protected string strPrintControlCookie = "";
  203. /// <summary>
  204. /// 获取Url中去掉文件名的路径
  205. /// </summary>
  206. /// <returns></returns>
  207. private string GetUrlPath()
  208. {
  209. string strUrl = Request.Url.ToString();
  210. int iEnd = strUrl.LastIndexOf("/");
  211. strUrl = strUrl.Substring(0, iEnd + 1);
  212. return strUrl;
  213. }
  214. /// <summary>
  215. /// 设置控件调用的Cookie值,判断是否安装了打印控件
  216. /// </summary>
  217. /// <param name="pJson"></param>
  218. private void SetCookieAndURL(PrintJson pJson)
  219. {
  220. bIsInstallPrintControl = false;
  221. strPrintControlCookie = "";
  222. HttpCookie pCookieInstall = Request.Cookies["InstallPrintControl"];
  223. if (pCookieInstall != null)
  224. { //Cookie存在
  225. strPrintControlCookie = pCookieInstall.Value.ToString();
  226. //以Cookie值查找在数据表中是否存在
  227. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  228. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strPrintControlCookie) };
  229. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  230. {
  231. if (drCookie.Read())
  232. { //标识为已经安装
  233. bIsInstallPrintControl = true;
  234. }
  235. drCookie.Close();
  236. }
  237. //更新Cookie的保存时间
  238. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  239. Response.SetCookie(pCookieInstall);
  240. }
  241. else
  242. {//Cookie不存在,则新建Cookie
  243. strPrintControlCookie = System.Guid.NewGuid().ToString();
  244. pCookieInstall = new HttpCookie("InstallPrintControl", strPrintControlCookie);
  245. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  246. Response.Cookies.Add(pCookieInstall);
  247. }
  248. string strUrl = Server.MapPath("/PrintTemp/") + "IsCheckInstall";
  249. pJson.SetCookieAndURL(strPrintControlCookie, strUrl);
  250. }
  251. [HttpPost]
  252. [HandlerAjaxOnly]
  253. public ActionResult PrintItemLot(string keyValue, string WorkPoint)
  254. {
  255. //string sqlU9 = "SELECT DBIpAddress,DBName FROM dbo.Sys_DataBase WHERE DBSourceName='ERP'";
  256. //DataTable dtU9 = SqlHelper.GetDataTableBySql(sqlU9);
  257. //string U9IP = dtU9.Rows[0]["DBIpAddress"].ToString();
  258. //string DBName = dtU9.Rows[0]["DBName"].ToString();
  259. string DBLANK = SqlHelper.GetItemsDetails("ERP001", WorkPoint);
  260. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  261. WorkPoint = WorkPoint.Substring(1, WorkPoint.Length - 2);
  262. string strPrintFileName = "";
  263. if (WorkPoint == "01")
  264. {
  265. strPrintFileName = Server.MapPath("/ReportFile/") + "ASN发票.fr3";
  266. }
  267. else if (WorkPoint == "02")
  268. {
  269. strPrintFileName = Server.MapPath("/ReportFile/") + "ASN发票02.fr3";
  270. }
  271. else if (WorkPoint == "03")
  272. {
  273. strPrintFileName = Server.MapPath("/ReportFile/") + "ASN发票03.fr3";
  274. }
  275. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  276. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  277. pJson.MasterOptions(1, "DocNO", false); //主从关系
  278. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  279. string strSql = @"select paperNO,MUSERName,DocNO from ICSInvoiceNew a
  280. WHERE a.DocNo IN (" + keyValue.TrimEnd(',') + ") and a.WorkPoint='" + WorkPoint + "'";
  281. DataTable dtInInfo = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  282. strSql = @"SELECT DISTINCT a.DocNO, a.ID,a.InvCode,j.InvName,a.Qty,j.InvUnit AS InvUom,j.invstd,e.Tax,
  283. CAST(a.TaxPriceSell AS DECIMAL(18,2)) AS Price,CAST(g.ioriSum AS DECIMAL(18,2)) AS Total,
  284. a.Src_CADocNo AS CACOde,f.POCode,ISNULL(g.iOriMoney,0) AS iOriMoney,ISNULL(g.iOriTaxPrice,0) AS iOriTaxPrice
  285. FROM ICSInvoiceNewDetail a
  286. left join ICSCANew c on a.Src_CADocNo=c.DocNo and a.WorkPoint=c.WorkPoint
  287. LEFT JOIN ICSCANewdetail e ON c.DocNo=e.DocNo AND a.Src_CADocLineNo=e.DocLineNo AND a.InvCode=e.InvCode
  288. LEFT JOIN (SELECT ioriSum,AutoID,iOriMoney,iOriTaxPrice FROM {2}.dbo.rdrecords01 with(nolock)) g ON e.EATTRIBUTE1=g.AutoID
  289. LEFT JOIN dbo.ICSPurchaseOrder f ON e.POCode=f.POCode AND e.porow=f.Sequence and e.WorkPoint=f.WorkPoint and e.InvCode=f.InvCode
  290. LEFT JOIN ICSINVENTORY j ON f.invcode=j.invCode AND j.WorkPoint=f.WorkPoint
  291. WHERE a.DocNO IN (" + keyValue.TrimEnd(',') + ") and a.WorkPoint='" + WorkPoint + "'";
  292. strSql = string.Format(strSql, keyValue.TrimEnd(','), WorkPoint, DBLANK);
  293. DataTable dtInMaterial = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  294. string strPrintTempFile = pJson.ShowReport(dtInInfo, dtInMaterial); //产生JSON文件内容
  295. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  296. string strServerURL = GetUrlPath() + "PrintTemp/";
  297. string strData = strServerURL + strPrintTempFile;
  298. strPrintData = PrintFunction.EnBase64(strData);
  299. var JsonData = new
  300. {
  301. strPrintData_1 = strPrintData,
  302. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  303. strPrintControlCookie_1 = strPrintControlCookie
  304. };
  305. string sql = @"UPDATE dbo.ICSASN
  306. SET ADDITION1=ISNULL(ADDITION1,0)+1,
  307. ADDITION2=CONVERT(varchar(100), GETDATE(), 21)
  308. WHERE STNO in (" + keyValue.TrimEnd(',') + ") and WorkPoint='" + WorkPoint + "'";
  309. SqlHelper.ExecuteNonQuery(sql);
  310. return Content(JsonData.ToJson());
  311. }
  312. /// <summary>
  313. /// 写日志(用于跟踪)
  314. /// </summary>
  315. private void WriteLog(string strMessage)
  316. {
  317. string strLogFile = Server.MapPath("./Cookie_Log.txt");
  318. StreamWriter swLogFile = null;
  319. try
  320. {
  321. if (!System.IO.File.Exists(strLogFile))
  322. {
  323. swLogFile = System.IO.File.CreateText(strLogFile);
  324. }
  325. else
  326. {
  327. swLogFile = System.IO.File.AppendText(strLogFile);
  328. }
  329. swLogFile.WriteLine(strMessage);
  330. }
  331. catch
  332. {
  333. }
  334. finally
  335. {
  336. if (swLogFile != null)
  337. swLogFile.Close();
  338. }
  339. }
  340. /// <summary>
  341. ///判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  342. /// </summary>
  343. /// <param name="strCookie"></param>
  344. private void UpdateCheckInstall(string strCookie)
  345. {
  346. bool bIsExist = false;
  347. //判断记录是否存在
  348. GetLastAccessTime(strCookie, ref bIsExist);
  349. string strSql = "";
  350. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) };
  351. if (bIsExist)
  352. { //存在则更新最后访问的时间
  353. strSql = @"Update sys_SRM_CheckInstall
  354. Set LastAccessTime = getDate()
  355. Where Cookie = @Cookie";
  356. }
  357. else
  358. { //不存在则新建一条记录
  359. strSql = @"Insert into sys_SRM_CheckInstall(Cookie, LastAccessTime)
  360. Values( @Cookie, getDate() )";
  361. }
  362. DbHelper.ExecuteNonQuery(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie);
  363. }
  364. public DateTime ToDateTime(object SrcValue)
  365. {
  366. if (Convert.IsDBNull(SrcValue) == true)
  367. return DateTime.MinValue;
  368. else
  369. {
  370. try
  371. {
  372. return Convert.ToDateTime(SrcValue);
  373. }
  374. catch
  375. {
  376. return DateTime.MinValue;
  377. }
  378. }
  379. }
  380. /// <summary>
  381. /// 获取此Cookie的最后访问时间
  382. /// </summary>
  383. /// <param name="strCookie"></param>
  384. /// <returns></returns>
  385. private DateTime GetLastAccessTime(string strCookie, ref bool bIsExist)
  386. {
  387. DateTime dtLastAccessTime = DateTime.MinValue;
  388. bIsExist = false;
  389. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  390. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) };
  391. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  392. {
  393. if (drCookie.Read())
  394. {
  395. dtLastAccessTime = ToDateTime(drCookie["LastAccessTime"]);
  396. bIsExist = true;
  397. }
  398. drCookie.Close();
  399. }
  400. return dtLastAccessTime;
  401. }
  402. [HttpGet]
  403. [HandlerAjaxOnly]
  404. public ActionResult IsCheckInstall(string checkInstall)
  405. {
  406. string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,");
  407. if (Request.QueryString["cookie"] != null)
  408. { //有控件上传的Cookie值
  409. string strCookie = Request.QueryString["cookie"].ToString();
  410. //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  411. UpdateCheckInstall(strCookie);
  412. strValue = strValue + "上传的cookie:" + strCookie;
  413. }
  414. else if (checkInstall != null)
  415. {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况
  416. string strCookie = checkInstall;
  417. //读取最后访问的时间
  418. string strResult = "PrintControlInstall";
  419. bool bIsExist = false;
  420. DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist);
  421. if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now)
  422. {
  423. strResult = "NOT";
  424. }
  425. Response.Clear();
  426. Response.Write(strResult);
  427. strValue = strValue + "检测安装的值:" + strCookie;
  428. }
  429. WriteLog(strValue);
  430. return null;
  431. }
  432. [HttpGet]
  433. [HandlerAjaxOnly]
  434. public ActionResult IsCheckInstall()
  435. {
  436. string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,");
  437. if (Request.QueryString["cookie"] != null)
  438. { //有控件上传的Cookie值
  439. string strCookie = Request.QueryString["cookie"].ToString();
  440. //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  441. UpdateCheckInstall(strCookie);
  442. strValue = strValue + "上传的cookie:" + strCookie;
  443. }
  444. else if (Request.QueryString["checkInstall"] != null)
  445. {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况
  446. string strCookie = Request.QueryString["checkInstall"];
  447. //读取最后访问的时间
  448. string strResult = "PrintControlInstall";
  449. bool bIsExist = false;
  450. DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist);
  451. if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now)
  452. {
  453. strResult = "NOT";
  454. }
  455. Response.Clear();
  456. Response.Write(strResult);
  457. strValue = strValue + "检测安装的值:" + strCookie;
  458. }
  459. WriteLog(strValue);
  460. return null;
  461. }
  462. #endregion
  463. }
  464. }