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.

509 lines
17 KiB

3 weeks ago
  1. using Newtonsoft.Json;
  2. using NFine.Application.WMS;
  3. using NFine.Code;
  4. using NFine.Data.Extensions;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.Common;
  9. using System.Data.SqlClient;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Web;
  13. using System.Web.Mvc;
  14. namespace NFine.Web.Areas.WMS.Controllers
  15. {
  16. /// <summary>
  17. /// 检具管理(铭锋)
  18. /// </summary>
  19. public class CheckingFixtureController : ControllerBase
  20. {
  21. private CheckingFixtureApp app = new CheckingFixtureApp();
  22. // GET: WMS/CheckingFixture
  23. #region 检具档案
  24. public ActionResult CheckingFixtureQuery()
  25. {
  26. return View();
  27. }
  28. /// <summary>
  29. /// 模具档案封存
  30. /// </summary>
  31. /// <returns></returns>
  32. public ActionResult CheckingFixtureStopQuery()
  33. {
  34. return View();
  35. }
  36. /// <summary>
  37. /// 解封时间
  38. /// </summary>
  39. /// <returns></returns>
  40. public ActionResult UpdateTime()
  41. {
  42. return View();
  43. }
  44. public ActionResult CheckingFixtureEdit(string ids)
  45. {
  46. ViewData["ids"] = ids;
  47. //ViewData["line"] = line;
  48. return View();
  49. }
  50. /// <summary>
  51. /// 获取库位列表
  52. /// </summary>
  53. /// <param name="keyValue"></param>
  54. /// <returns></returns>
  55. [HttpGet]
  56. public ActionResult GetLocationList(string keyValue)
  57. {
  58. var dt = app.GetLocationList(keyValue);
  59. return Content(dt.ToJson());
  60. }
  61. /// <summary>
  62. /// 查询列表
  63. /// </summary>
  64. /// <param name="pagination"></param>
  65. /// <param name="queryJson"></param>
  66. /// <returns></returns>
  67. [HttpPost]
  68. [HandlerAjaxOnly]
  69. public ActionResult GetGridJsonChengPing(Pagination pagination, string type,string queryJson)
  70. {
  71. DataTable ListData = app.GetGridJsonChengPing(queryJson, type,ref pagination);
  72. var JsonData = new
  73. {
  74. total = pagination.total,
  75. page = pagination.page,
  76. records = pagination.records,
  77. rows = ListData,
  78. };
  79. return Content(JsonData.ToJson());
  80. }
  81. /// <summary>
  82. /// 保存
  83. /// </summary>
  84. /// <param name="keyValue"></param>
  85. /// <returns></returns>
  86. [HttpPost]
  87. [HandlerAjaxOnly]
  88. public ActionResult SaveCheckingFixture(string keyValue)
  89. {
  90. string msg = app.SaveCheckingFixture(keyValue);
  91. if (!string.IsNullOrEmpty(msg))
  92. {
  93. return Error(msg);
  94. }
  95. else
  96. {
  97. return Success("操作成功!");
  98. }
  99. }
  100. /// <summary>
  101. /// 获取单个
  102. /// </summary>
  103. /// <param name="keyValue"></param>
  104. /// <returns></returns>
  105. [HttpGet]
  106. [HandlerAjaxOnly]
  107. public ActionResult GetCheckingFixture(string keyValue)
  108. {
  109. var dt = app.GetCheckingFixture(keyValue);
  110. return Content(dt.ToJson());
  111. }
  112. /// <summary>
  113. /// 删除
  114. /// </summary>
  115. /// <param name="keyValue"></param>
  116. /// <returns></returns>
  117. [HttpPost]
  118. [HandlerAjaxOnly]
  119. public ActionResult DeleteCheckingFixture(string keyValue)
  120. {
  121. var msg = app.DeleteCheckingFixture(keyValue);
  122. if (!string.IsNullOrEmpty(msg))
  123. {
  124. return Error(msg);
  125. }
  126. else
  127. {
  128. return Success("操作成功!");
  129. }
  130. }
  131. /// <summary>
  132. /// 封存/解封
  133. /// </summary>
  134. /// <param name="keyValue"></param>
  135. /// <returns></returns>
  136. [HttpPost]
  137. [HandlerAjaxOnly]
  138. public ActionResult PostSealed(string type,string keyValue,string time)
  139. {
  140. var msg = app.PostSealed(type,keyValue,time);
  141. if (!string.IsNullOrEmpty(msg))
  142. {
  143. return Error(msg);
  144. }
  145. else
  146. {
  147. return Success("修改成功!");
  148. }
  149. }
  150. /// <summary>
  151. /// 导出列表
  152. /// </summary>
  153. /// <param name="pagination"></param>
  154. /// <param name="queryJson"></param>
  155. /// <returns></returns>
  156. [HttpPost]
  157. public void ExportAll(string id, string CheckFixtureName, string Status)
  158. {
  159. DataTable dt = app.ExportAll(id, CheckFixtureName, Status);
  160. AsposeCell.Export(dt);
  161. }
  162. /// <summary>
  163. /// 导入列表
  164. /// </summary>
  165. /// <param name="pagination"></param>
  166. /// <param name="queryJson"></param>
  167. /// <returns></returns>
  168. [HttpPost]
  169. public string UploadFile()
  170. {
  171. try
  172. {
  173. //string str_Year = Request.Form["txt_Year"];
  174. //String UPLoadType = Request.Form["UPLoadType"];
  175. HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files;
  176. if (hpFiles != null && hpFiles.Count > 0)
  177. {
  178. string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
  179. if (IsXls != ".xls" && IsXls != ".xlsx")
  180. {
  181. return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
  182. }
  183. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + IsXls; //获取Execle文件名 DateTime日期函数
  184. string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\CheckingFixture\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
  185. int iLen = hpFiles[0].ContentLength;
  186. if (Directory.Exists(savePath)) return "文件已存在";
  187. byte[] bData = new byte[iLen];
  188. hpFiles[0].InputStream.Read(bData, 0, iLen);
  189. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  190. newFile.Write(bData, 0, bData.Length);
  191. newFile.Flush();
  192. int _FileSizeTemp = hpFiles[0].ContentLength;
  193. newFile.Close();
  194. newFile.Dispose();
  195. //bool del = false;
  196. string mess = "";
  197. mess = app.SetData_PR(savePath);
  198. if (System.IO.File.Exists(savePath))//删除文件
  199. {
  200. System.IO.File.Delete(savePath);
  201. }
  202. return mess;
  203. }
  204. else
  205. {
  206. return "获取文件失败";
  207. }
  208. }
  209. catch (Exception ex)
  210. {
  211. return ex.ToString();
  212. }
  213. }
  214. /// <summary>
  215. /// 导出列表
  216. /// </summary>
  217. /// <param name="pagination"></param>
  218. /// <param name="queryJson"></param>
  219. /// <returns></returns>
  220. [HttpPost]
  221. public ActionResult PrintLabel(string keyValue)
  222. {
  223. //var msg = app.PrintLabel(keyValue);
  224. // return Success(msg);
  225. var JsonData = new
  226. {
  227. strPrintData_1 = "",
  228. bIsInstallPrintControl_1 = true,
  229. strPrintControlCookie_1 = "",
  230. msg=""
  231. };
  232. try
  233. {
  234. var strPrintData = "";
  235. List<SqlParameter> parameter = new List<SqlParameter>();
  236. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  237. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  238. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  239. //var sql
  240. var keyValues = JsonConvert.DeserializeObject<List<string>>(keyValue);
  241. if (keyValues == null || keyValues.Count == 0)
  242. {
  243. throw new Exception("参数为传入");
  244. }
  245. string strPrintFileName = Server.MapPath("/File/CheckingFixture/") + "检具4025.fr3";
  246. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  247. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  248. // SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  249. string strSql = @"select
  250. a.CheckFixtureNo as ,a.CheckFixtureName as ,a.CustomerItemCode as ,
  251. a.*
  252. from IcsCheckingFixture a with(nolock)
  253. where 1=1
  254. --and a.WorkPoint=@WorkPoint
  255. and a.CheckFixtureNo in ('" + string.Join("','", keyValues) + "')";
  256. parameter.Add(new SqlParameter("@WorkPoint", SqlDbType.VarChar) { Value = WorkPoint });
  257. DataTable dtInInfo = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, parameter.ToArray());
  258. DataTable newDT = new DataTable();
  259. newDT.Columns.Add("编码1", typeof(string));
  260. newDT.Columns.Add("客户名称1", typeof(string));
  261. newDT.Columns.Add("客户料号1", typeof(string));
  262. newDT.Columns.Add("编码2", typeof(string));
  263. newDT.Columns.Add("客户名称2", typeof(string));
  264. newDT.Columns.Add("客户料号2", typeof(string));
  265. // List<DataRow> listRow = new List<DataRow>();
  266. int rowCount = (dtInInfo.Rows.Count % 2)+(dtInInfo.Rows.Count / 2);
  267. List<DataRow> SingleRow = new List<DataRow>();
  268. List<DataRow> DoubleRow = new List<DataRow>();
  269. for (int i = 0; i < dtInInfo.Rows.Count; i++)
  270. {
  271. // 1,2 =>1 3,4 =>2
  272. if ((i + 1) % 2 == 1)
  273. {
  274. //基数行
  275. SingleRow.Add(dtInInfo.Rows[i]);
  276. }
  277. else
  278. {
  279. //偶数行
  280. DoubleRow.Add(dtInInfo.Rows[i]);
  281. }
  282. }
  283. for (int i = 0; i < rowCount; i++)
  284. {
  285. var newrow = newDT.NewRow();
  286. newrow["编码1"] = SingleRow[i]["编码"];
  287. newrow["客户名称1"] = SingleRow[i]["客户名称"];
  288. newrow["客户料号1"] = SingleRow[i]["客户料号"];
  289. if (i+1<= DoubleRow.Count)
  290. {
  291. newrow["编码2"] = DoubleRow[i]["编码"];
  292. newrow["客户名称2"] = DoubleRow[i]["客户名称"];
  293. newrow["客户料号2"] = DoubleRow[i]["客户料号"];
  294. }
  295. newDT.Rows.Add(newrow);
  296. }
  297. string strPrintTempFile = pJson.ShowReport(newDT);//产生ISON文件内容
  298. //把服务器的URL+此文件名 传递给控件,由控件下载还原数据进行打印
  299. string strServerURL = GetUrlPath() + "PrintTemp/";
  300. string strData = strServerURL + strPrintTempFile;
  301. strPrintData = PrintFunction.EnBase64(strData);
  302. JsonData = new
  303. {
  304. strPrintData_1 = strPrintData,
  305. bIsInstallPrintControl_1 = true,
  306. strPrintControlCookie_1 = "",
  307. msg="",
  308. };
  309. }
  310. catch (Exception ex)
  311. {
  312. JsonData = new
  313. {
  314. strPrintData_1 = "",
  315. bIsInstallPrintControl_1 = true,
  316. strPrintControlCookie_1 = "",
  317. msg = ex.Message
  318. };
  319. return Content(JsonData.ToJson());
  320. }
  321. return Content(JsonData.ToJson());
  322. }
  323. #endregion
  324. private string GetUrlPath()
  325. {
  326. string strUrl = Request.Url.ToString();
  327. int iEnd = strUrl.LastIndexOf("/");
  328. strUrl = strUrl.Substring(0, iEnd + 1);
  329. return strUrl;
  330. }
  331. #region 检具流转
  332. public ActionResult CheckingFixtureTransferQuery()
  333. {
  334. return View();
  335. }
  336. /// <summary>
  337. /// 查询列表
  338. /// </summary>
  339. /// <param name="pagination"></param>
  340. /// <param name="queryJson"></param>
  341. /// <returns></returns>
  342. [HttpPost]
  343. [HandlerAjaxOnly]
  344. public ActionResult QueryTransferList(Pagination pagination, string queryJson)
  345. {
  346. DataTable ListData = app.QueryTransferList(queryJson, ref pagination);
  347. var JsonData = new
  348. {
  349. total = pagination.total,
  350. page = pagination.page,
  351. records = pagination.records,
  352. rows = ListData,
  353. };
  354. return Content(JsonData.ToJson());
  355. }
  356. /// <summary>
  357. /// 转换操作
  358. /// </summary>
  359. /// <returns></returns>
  360. public ActionResult TransferInsert(string type)
  361. {
  362. ViewData["type"] = type;
  363. return View();
  364. }
  365. /// <summary>
  366. /// 转换操作
  367. /// </summary>
  368. /// <returns></returns>
  369. public ActionResult TransferInsertOther(string type)
  370. {
  371. ViewData["type"] = type;
  372. return View();
  373. }
  374. /// <summary>
  375. /// 新增转换
  376. /// </summary>
  377. /// <param name="keyValue"></param>
  378. /// <returns></returns>
  379. [HttpPost]
  380. [HandlerAjaxOnly]
  381. public ActionResult SaveTransfer(string keyValue)
  382. {
  383. string msg = app.SaveTransfer(keyValue);
  384. if (!string.IsNullOrEmpty(msg))
  385. {
  386. return Error(msg);
  387. }
  388. else
  389. {
  390. return Success("操作成功!");
  391. }
  392. }
  393. /// <summary>
  394. /// 获取人员
  395. /// </summary>
  396. /// <param name="keyValue"></param>
  397. /// <returns></returns>
  398. [HttpGet]
  399. [HandlerAjaxOnly]
  400. public ActionResult GetUserInfo(string keyValue)
  401. {
  402. var dt = app.GetUserInfo(keyValue);
  403. return Content(dt.ToJson());
  404. }
  405. /// <summary>
  406. /// 获取单个
  407. /// </summary>
  408. /// <param name="keyValue"></param>
  409. /// <returns></returns>
  410. [HttpGet]
  411. [HandlerAjaxOnly]
  412. public ActionResult GetCheckingFixtureByNo(string keyValue)
  413. {
  414. var dt = app.GetCheckingFixtureByNo(keyValue);
  415. return Content(dt.ToJson());
  416. }
  417. /// <summary>
  418. /// 删除转换日志
  419. /// </summary>
  420. /// <param name="keyValue"></param>
  421. /// <returns></returns>
  422. [HttpPost]
  423. [HandlerAjaxOnly]
  424. public ActionResult DeleteTransfer(string keyValue)
  425. {
  426. var msg = app.DeleteTransfer(keyValue);
  427. if (!string.IsNullOrEmpty(msg))
  428. {
  429. return Error(msg);
  430. }
  431. else
  432. {
  433. return Success("操作成功!");
  434. }
  435. }
  436. /// <summary>
  437. /// 导出列表
  438. /// </summary>
  439. /// <param name="pagination"></param>
  440. /// <param name="queryJson"></param>
  441. /// <returns></returns>
  442. [HttpPost]
  443. public void ExportAllTransfer(string CheckFixtureNo, string CheckFixtureName, string TransferNo, string TransferType)
  444. {
  445. DataTable dt = app.ExportAllTransfer(CheckFixtureNo, CheckFixtureName, TransferNo, TransferType);
  446. AsposeCell.Export(dt);
  447. }
  448. #endregion
  449. public ActionResult GetType(string type)
  450. {
  451. string sql = $@"select '' as Code,'' as Name
  452. UNION all
  453. select b.F_ItemCode as Code ,b.F_ItemName as Name from Sys_SRM_Items a left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  454. where a.F_EnCode='{type}' ";
  455. DataTable ListData = SqlHelper.GetDataTableBySql(sql);
  456. return Content(ListData.ToJson());
  457. }
  458. }
  459. }