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.

1579 lines
52 KiB

3 weeks ago
  1. using NFine.Application.WMS;
  2. using System;
  3. using System.Data;
  4. using System.IO;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using NFine.Code;
  8. using System.Data.SqlClient;
  9. using NFine.Data.Extensions;
  10. using ICS.Application.Entity;
  11. using System.Linq;
  12. namespace NFine.Web.Areas.Boxes.Controllers
  13. {
  14. public class BasicSettingsController : ControllerBase
  15. {
  16. BasicSettingsApp App = new BasicSettingsApp();
  17. /// <summary>
  18. /// 加载周转箱
  19. /// </summary>
  20. /// <returns></returns>
  21. [HttpGet]
  22. public ActionResult ICSBoxes()
  23. {
  24. return View();
  25. }
  26. /// <summary>
  27. /// 周转箱台账
  28. /// </summary>
  29. /// <returns></returns>
  30. [HttpGet]
  31. public ActionResult ICSBoxAccount()
  32. {
  33. return View();
  34. }
  35. /// <summary>
  36. /// 加载模具
  37. /// </summary>
  38. /// <returns></returns>
  39. [HttpGet]
  40. public ActionResult ICSMould()
  41. {
  42. return View();
  43. }
  44. /// <summary>
  45. /// 加载模具台账
  46. /// </summary>
  47. /// <returns></returns>
  48. [HttpGet]
  49. public ActionResult ICSMouldAccountAdd()
  50. {
  51. return View();
  52. }
  53. /// <summary>
  54. /// 新增周转箱信息
  55. /// </summary>
  56. /// <returns></returns>
  57. [HttpGet]
  58. public ActionResult ICSBoxesAdd()
  59. {
  60. return View();
  61. }
  62. /// <summary>
  63. /// 周转箱使用记录
  64. /// </summary>
  65. /// <returns></returns>
  66. [HttpGet]
  67. public ActionResult ICSBoxesRecord()
  68. {
  69. return View();
  70. }
  71. /// <summary>
  72. /// 周转箱台账信息
  73. /// </summary>
  74. /// <returns></returns>
  75. [HttpGet]
  76. public ActionResult ICSBoxesAccountRecord()
  77. {
  78. return View();
  79. }
  80. /// <summary>
  81. /// 模具使用记录
  82. /// </summary>
  83. /// <returns></returns>
  84. [HttpGet]
  85. public ActionResult ICSMouldRecord()
  86. {
  87. return View();
  88. }
  89. /// <summary>
  90. /// 模具台账信息
  91. /// </summary>
  92. /// <returns></returns>
  93. [HttpGet]
  94. public ActionResult ICSMouldAccountRecord()
  95. {
  96. return View();
  97. }
  98. /// <summary>
  99. /// 新增模具信息
  100. /// </summary>
  101. /// <returns></returns>
  102. [HttpGet]
  103. public ActionResult ICSMouldAdd()
  104. {
  105. return View();
  106. }
  107. /// <summary>
  108. /// 新增模具维修报废
  109. /// </summary>
  110. /// <returns></returns>
  111. [HttpGet]
  112. public ActionResult ICSMouldMaintain()
  113. {
  114. return View();
  115. }
  116. /// <summary>
  117. /// 新增模具维修报废
  118. /// </summary>
  119. /// <returns></returns>
  120. [HttpGet]
  121. public ActionResult ICSMouldMaintainAdd()
  122. {
  123. return View();
  124. }
  125. //周转箱使用记录
  126. [HttpGet]
  127. [HandlerAjaxOnly]
  128. public ActionResult GetBoxesRecord(string queryJson, Pagination pagination)
  129. {
  130. DataTable ListData = App.GetBoxesRecord(queryJson, ref pagination);
  131. var JsonData = new
  132. {
  133. total = pagination.total,
  134. page = pagination.page,
  135. records = pagination.records,
  136. rows = ListData,
  137. };
  138. return Content(JsonData.ToJson());
  139. }
  140. //周转箱使用记录
  141. [HttpGet]
  142. [HandlerAjaxOnly]
  143. public ActionResult GetBoxesAccountRecord(string queryJson, Pagination pagination)
  144. {
  145. DataTable ListData = App.GetBoxesAccountRecord(queryJson, ref pagination);
  146. var JsonData = new
  147. {
  148. total = pagination.total,
  149. page = pagination.page,
  150. records = pagination.records,
  151. rows = ListData,
  152. };
  153. return Content(JsonData.ToJson());
  154. }
  155. //模具使用记录
  156. [HttpGet]
  157. [HandlerAjaxOnly]
  158. public ActionResult GetMouldRecord(string queryJson, Pagination pagination)
  159. {
  160. DataTable ListData = App.GetMouldRecord(queryJson, ref pagination);
  161. var JsonData = new
  162. {
  163. total = pagination.total,
  164. page = pagination.page,
  165. records = pagination.records,
  166. rows = ListData,
  167. };
  168. return Content(JsonData.ToJson());
  169. }
  170. //模具使用记录
  171. [HttpGet]
  172. [HandlerAjaxOnly]
  173. public ActionResult GetMouldAccountRecord(string queryJson, Pagination pagination)
  174. {
  175. DataTable ListData = App.GetMouldAccountRecord(queryJson, ref pagination);
  176. var JsonData = new
  177. {
  178. total = pagination.total,
  179. page = pagination.page,
  180. records = pagination.records,
  181. rows = ListData,
  182. };
  183. return Content(JsonData.ToJson());
  184. }
  185. /// <summary>
  186. /// 新增周转箱台账
  187. /// </summary>
  188. /// <returns></returns>
  189. [HttpGet]
  190. public ActionResult ICSBoxAccountAdd()
  191. {
  192. return View();
  193. }
  194. /// <summary>
  195. /// 新增模具台账
  196. /// </summary>
  197. /// <returns></returns>
  198. [HttpGet]
  199. public ActionResult ICSMouldAccount()
  200. {
  201. return View();
  202. }
  203. /// <summary>
  204. /// 删除周转箱
  205. /// </summary>
  206. /// <returns></returns>
  207. [HttpPost]
  208. [HandlerAjaxOnly]
  209. [ValidateAntiForgeryToken]
  210. public ActionResult DeleteBoxes(string keyValue)
  211. {
  212. string msg = App.DeleteBoxes(keyValue);
  213. if (string.IsNullOrEmpty(msg))
  214. {
  215. return Success("删除成功!");
  216. }
  217. else
  218. {
  219. return Error(msg);
  220. //throw new Exception(msg);
  221. }
  222. }
  223. /// <summary>
  224. /// 新增周转箱信息
  225. /// </summary>
  226. /// <param name="keyValue"></param>
  227. /// <returns></returns>
  228. [HttpPost]
  229. [HandlerAjaxOnly]
  230. public ActionResult InsertBoxes(string keyValue)
  231. {
  232. string msg = App.InsertBoxes(keyValue);
  233. if (!string.IsNullOrEmpty(msg))
  234. {
  235. return Error(msg);
  236. }
  237. else
  238. {
  239. return Success("添加成功!");
  240. }
  241. }
  242. /// <summary>
  243. /// 修改周转箱信息
  244. /// </summary>
  245. /// <param name="keyValue"></param>
  246. /// <returns></returns>
  247. [HttpPost]
  248. [HandlerAjaxOnly]
  249. public ActionResult UpdateBoxes(string keyValue)
  250. {
  251. string msg = App.UpdateBoxes(keyValue);
  252. if (!string.IsNullOrEmpty(msg))
  253. {
  254. return Error(msg);
  255. }
  256. else
  257. {
  258. return Success("修改成功!");
  259. }
  260. }
  261. /// <summary>
  262. /// 获周转箱类型信息
  263. /// </summary>
  264. /// <param name="tableName">表名</param>
  265. /// <returns></returns>
  266. public ActionResult GetType(string tableName)
  267. {
  268. DataTable dt = App.GetType(tableName);
  269. return Content(dt.ToJson());
  270. }
  271. /// <summary>
  272. /// 新增模具信息
  273. /// </summary>
  274. /// <param name="keyValue"></param>
  275. /// <returns></returns>
  276. [HttpPost]
  277. [HandlerAjaxOnly]
  278. public ActionResult InsertMould(string keyValue)
  279. {
  280. string msg = App.InsertMould(keyValue);
  281. if (!string.IsNullOrEmpty(msg))
  282. {
  283. return Error(msg);
  284. }
  285. else
  286. {
  287. return Success("添加成功!");
  288. }
  289. }
  290. /// <summary>
  291. /// 修改模具信息
  292. /// </summary>
  293. /// <param name="keyValue"></param>
  294. /// <returns></returns>
  295. [HttpPost]
  296. [HandlerAjaxOnly]
  297. public ActionResult UpdateMould(string keyValue)
  298. {
  299. string msg = App.UpdateMould(keyValue);
  300. if (!string.IsNullOrEmpty(msg))
  301. {
  302. return Error(msg);
  303. }
  304. else
  305. {
  306. return Success("修改成功!");
  307. }
  308. }
  309. /// <summary>
  310. /// 修改模具状态信息
  311. /// </summary>
  312. /// <param name="keyValue"></param>
  313. /// <returns></returns>
  314. [HttpPost]
  315. [HandlerAjaxOnly]
  316. public ActionResult UpdateMouldStatus(string keyValue)
  317. {
  318. string msg = App.UpdateMouldStatus(keyValue);
  319. if (!string.IsNullOrEmpty(msg))
  320. {
  321. return Error(msg);
  322. }
  323. else
  324. {
  325. return Success("修改成功!");
  326. }
  327. }
  328. /// <summary>
  329. /// 删除模具档案
  330. /// </summary>
  331. /// <returns></returns>
  332. [HttpPost]
  333. [HandlerAjaxOnly]
  334. [ValidateAntiForgeryToken]
  335. public ActionResult DeleteMould(string keyValue)
  336. {
  337. string msg = App.DeleteMould(keyValue);
  338. if (string.IsNullOrEmpty(msg))
  339. {
  340. return Success("删除成功!");
  341. }
  342. else
  343. {
  344. return Error(msg);
  345. //throw new Exception(msg);
  346. }
  347. }
  348. /// <summary>
  349. /// 删除模具台账
  350. /// </summary>
  351. /// <returns></returns>
  352. [HttpPost]
  353. [HandlerAjaxOnly]
  354. [ValidateAntiForgeryToken]
  355. public ActionResult DeleteMouldAccount(string keyValue)
  356. {
  357. string msg = App.DeleteMouldAccount(keyValue);
  358. if (string.IsNullOrEmpty(msg))
  359. {
  360. return Success("删除成功!");
  361. }
  362. else
  363. {
  364. return Error(msg);
  365. //throw new Exception(msg);
  366. }
  367. }
  368. /// <summary>
  369. /// 获周转箱编码信息
  370. /// </summary>
  371. /// <returns></returns>
  372. public ActionResult GetBoxNumber()
  373. {
  374. DataTable dt = App.GetBoxNumber();
  375. return Content(dt.ToJson());
  376. }
  377. /// <summary>
  378. /// 获取模具编码信息
  379. /// </summary>
  380. /// <returns></returns>
  381. public ActionResult GetMouldNumber()
  382. {
  383. DataTable dt = App.GetMouldNumber();
  384. return Content(dt.ToJson());
  385. }
  386. /// <summary>
  387. /// 获取模具代码信息
  388. /// </summary>
  389. /// <returns></returns>
  390. public ActionResult GetMouldCode()
  391. {
  392. DataTable dt = App.GetMouldCode();
  393. return Content(dt.ToJson());
  394. }
  395. /// <summary>
  396. /// 新增周转箱台账信息
  397. /// </summary>
  398. /// <param name="keyValue"></param>
  399. /// <returns></returns>
  400. [HttpPost]
  401. [HandlerAjaxOnly]
  402. public ActionResult InsertBoxAccount(string keyValue)
  403. {
  404. try
  405. {
  406. string msg = App.InsertBoxAccount(keyValue);
  407. if (!string.IsNullOrEmpty(msg))
  408. {
  409. return Error(msg);
  410. }
  411. else
  412. {
  413. return Success("添加成功!");
  414. }
  415. }
  416. catch (Exception ex)
  417. {
  418. return Error(ex.Message);
  419. }
  420. }
  421. /// <summary>
  422. /// 修改周转箱台账
  423. /// </summary>
  424. /// <param name="keyValue"></param>
  425. /// <returns></returns>
  426. [HttpPost]
  427. [HandlerAjaxOnly]
  428. public ActionResult UpdateBoxAccount(string keyValue)
  429. {
  430. try
  431. {
  432. string msg = App.UpdateBoxAccount(keyValue);
  433. if (!string.IsNullOrEmpty(msg))
  434. {
  435. return Error(msg);
  436. }
  437. else
  438. {
  439. return Success("修改成功!");
  440. }
  441. }
  442. catch (Exception ex)
  443. {
  444. return Error(ex.Message);
  445. }
  446. }
  447. /// <summary>
  448. /// 删除周转箱台账
  449. /// </summary>
  450. /// <returns></returns>
  451. [HttpPost]
  452. [HandlerAjaxOnly]
  453. [ValidateAntiForgeryToken]
  454. public ActionResult DeleteBoxAccount(string keyValue)
  455. {
  456. try
  457. {
  458. string msg = App.DeleteBoxAccount(keyValue);
  459. if (string.IsNullOrEmpty(msg))
  460. {
  461. return Success("删除成功!");
  462. }
  463. else
  464. {
  465. return Error(msg);
  466. }
  467. }
  468. catch (Exception ex)
  469. {
  470. return Error(ex.Message);
  471. }
  472. }
  473. /// <summary>
  474. /// 新增模具台账信息
  475. /// </summary>
  476. /// <param name="keyValue"></param>
  477. /// <returns></returns>
  478. [HttpPost]
  479. [HandlerAjaxOnly]
  480. public ActionResult InsertMouldAccount(string keyValue)
  481. {
  482. try
  483. {
  484. string msg = App.InsertMouldAccount(keyValue);
  485. if (!string.IsNullOrEmpty(msg))
  486. {
  487. return Error(msg);
  488. }
  489. else
  490. {
  491. return Success("添加成功!");
  492. }
  493. }
  494. catch (Exception ex)
  495. {
  496. return Error(ex.Message);
  497. }
  498. }
  499. /// <summary>
  500. /// 修改模具台账
  501. /// </summary>
  502. /// <param name="keyValue"></param>
  503. /// <returns></returns>
  504. [HttpPost]
  505. [HandlerAjaxOnly]
  506. public ActionResult UpdateMouldAccount(string keyValue)
  507. {
  508. try
  509. {
  510. string msg = App.UpdateMouldAccount(keyValue);
  511. if (!string.IsNullOrEmpty(msg))
  512. {
  513. return Error(msg);
  514. }
  515. else
  516. {
  517. return Success("修改成功!");
  518. }
  519. }
  520. catch (Exception ex)
  521. {
  522. return Error(ex.Message);
  523. }
  524. }
  525. #region 打印
  526. /// <summary>
  527. /// 打印数据参数:服务器的URL+打印的文件名,转化为Base64编码
  528. /// </summary>
  529. protected string strPrintData;
  530. /// <summary>
  531. /// 标识是否安装了控件
  532. /// </summary>
  533. protected bool bIsInstallPrintControl = true;
  534. /// <summary>
  535. /// 打印控件的Cookie值
  536. /// </summary>
  537. protected string strPrintControlCookie = "";
  538. /// <summary>
  539. /// 获取Url中去掉文件名的路径
  540. /// </summary>
  541. /// <returns></returns>
  542. private string GetUrlPath()
  543. {
  544. string strUrl = Request.Url.ToString();
  545. int iEnd = strUrl.LastIndexOf("/");
  546. strUrl = strUrl.Substring(0, iEnd + 1);
  547. return strUrl;
  548. }
  549. /// <summary>
  550. /// 设置控件调用的Cookie值,判断是否安装了打印控件
  551. /// </summary>
  552. /// <param name="pJson"></param>
  553. private void SetCookieAndURL(PrintJson pJson)
  554. {
  555. bIsInstallPrintControl = false;
  556. strPrintControlCookie = "";
  557. HttpCookie pCookieInstall = Request.Cookies["InstallPrintControl"];
  558. if (pCookieInstall != null)
  559. { //Cookie存在
  560. strPrintControlCookie = pCookieInstall.Value.ToString();
  561. //以Cookie值查找在数据表中是否存在
  562. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  563. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strPrintControlCookie) };
  564. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  565. {
  566. if (drCookie.Read())
  567. { //标识为已经安装
  568. bIsInstallPrintControl = true;
  569. }
  570. drCookie.Close();
  571. }
  572. //更新Cookie的保存时间
  573. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  574. Response.SetCookie(pCookieInstall);
  575. }
  576. else
  577. {//Cookie不存在,则新建Cookie
  578. strPrintControlCookie = System.Guid.NewGuid().ToString();
  579. pCookieInstall = new HttpCookie("InstallPrintControl", strPrintControlCookie);
  580. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  581. Response.Cookies.Add(pCookieInstall);
  582. }
  583. string strUrl = Server.MapPath("/PrintTemp/") + "IsCheckInstall";
  584. pJson.SetCookieAndURL(strPrintControlCookie, strUrl);
  585. }
  586. [HttpPost]
  587. [HandlerAjaxOnly]
  588. public ActionResult PrintStack(string keyValue)
  589. {
  590. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  591. string strPrintFileName = Server.MapPath("/ReportFile/") + "Stack.fr3";
  592. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  593. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  594. pJson.MasterOptions(1, "STNO", false); //主从关系
  595. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  596. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  597. string strSql = @"select a.LocationCode,
  598. a.ID,
  599. a.LocationName,
  600. b.WarehouseCode,
  601. b.WarehouseName,
  602. a.Musername as 'MUSER',
  603. a.MTIME
  604. from ICSLocation a WITH (NOLOCK)
  605. inner join ICSWarehouse b WITH (NOLOCK) on a.WHID=b.ID
  606. where 1=1
  607. and a.ID IN (" + keyValue.TrimEnd(',') + ")";
  608. DataTable dtInInfo = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  609. // strSql = @"SELECT Row_Number() OVER (partition BY a.STNO ORDER BY a.CREATETIME DESC) AS rowno,c.STNO,
  610. // c.PLANQTY,c.LotnoQTY,c.CartonNOQTY,c.ITEMCODE,b.INVNAME,b.INVSTD,b.INVPARSETYPE,d.StorageName,
  611. // CONVERT(VARCHAR,CAST(ISNULL(c.Qty,0) AS money),1) AS Qty,
  612. // CONVERT(VARCHAR,CAST(ISNULL(c.Meters,0) AS money),1) AS Meters,
  613. // c.STNO AS QRSTNO,c.TransNO,c.TransLine,c.MEMO,c.VenderLotNO,CONVERT(varchar(10), c.PRODUCTDATE, 23) as PRODUCTDATE,a.remark
  614. // FROM
  615. // (SELECT aa.STNO,aa.ITEMCODE,aa.WorkPoint,SUM(aa.PLANQTY) PLANQTY,SUM(cc.LOTQTY) Qty,
  616. // SUM(ISNULL(cc.Meters,0)) Meters,cc.TransNO,cc.TransLine,dd.MEMO,cc.VenderLotNO,cc.PRODUCTDATE,
  617. // COUNT(aa.LOTNO) LotnoQTY,COUNT(bb.CartonNO) CartonNOQTY
  618. // FROM ICSASNDETAIL aa
  619. // LEFT JOIN ICSITEMLot2Carton bb ON aa.LOTNO = bb.LotNO AND aa.WorkPoint = bb.WorkPoint
  620. // LEFT JOIN ICSITEMLot cc ON aa.LOTNO = cc.LotNO AND aa.WorkPoint = cc.WorkPoint
  621. // LEFT JOIN ICSPO_PoMain dd on dd.POCode=cc.TransNO and dd.PORow=cc.TransLine
  622. // GROUP BY aa.stno,aa.itemcode,aa.WorkPoint,cc.TransNO,cc.TransLine,dd.MEMO,cc.VenderLotNO,cc.PRODUCTDATE) c
  623. // LEFT JOIN ICSASN a on c.stno=a.stno AND c.WorkPoint=a.WorkPoint
  624. // LEFT JOIN dbo.ICSINVENTORY b ON c.ITEMCODE=b.INVCODE AND b.WorkPoint=c.WorkPoint
  625. // LEFT JOIN dbo.icsstorage d ON b.INVMACHINETYPE=d.StorageCode
  626. // WHERE c.STNO IN (" + keyValue.TrimEnd(',') + ") and c.WorkPoint='" + WorkPoint + "'";
  627. // DataTable dtInMaterial = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  628. string strPrintTempFile = pJson.ShowReport(dtInInfo, null); //产生JSON文件内容
  629. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  630. string strServerURL = Server.MapPath("/PrintTemp/");
  631. string strData = strServerURL + strPrintTempFile;
  632. strPrintData = PrintFunction.EnBase64(strData);
  633. var JsonData = new
  634. {
  635. strPrintData_1 = strPrintData,
  636. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  637. strPrintControlCookie_1 = strPrintControlCookie
  638. };
  639. // string sql = @"UPDATE dbo.ICSASN
  640. // SET ADDITION1=ISNULL(ADDITION1,0)+1,
  641. // ADDITION2=CONVERT(varchar(100), GETDATE(), 21)
  642. // WHERE STNO in (" + keyValue.TrimEnd(',') + ") and WorkPoint='" + WorkPoint + "'";
  643. // SqlHelper.ExecuteNonQuery(sql);
  644. return Content(JsonData.ToJson());
  645. }
  646. /// <summary>
  647. /// 写日志(用于跟踪)
  648. /// </summary>
  649. private void WriteLog(string strMessage)
  650. {
  651. string strLogFile = Server.MapPath("./Cookie_Log.txt");
  652. StreamWriter swLogFile = null;
  653. try
  654. {
  655. if (!System.IO.File.Exists(strLogFile))
  656. {
  657. swLogFile = System.IO.File.CreateText(strLogFile);
  658. }
  659. else
  660. {
  661. swLogFile = System.IO.File.AppendText(strLogFile);
  662. }
  663. swLogFile.WriteLine(strMessage);
  664. }
  665. catch
  666. {
  667. }
  668. finally
  669. {
  670. if (swLogFile != null)
  671. swLogFile.Close();
  672. }
  673. }
  674. /// <summary>
  675. ///判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  676. /// </summary>
  677. /// <param name="strCookie"></param>
  678. private void UpdateCheckInstall(string strCookie)
  679. {
  680. bool bIsExist = false;
  681. //判断记录是否存在
  682. GetLastAccessTime(strCookie, ref bIsExist);
  683. string strSql = "";
  684. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) };
  685. if (bIsExist)
  686. { //存在则更新最后访问的时间
  687. strSql = @"Update sys_SRM_CheckInstall
  688. Set LastAccessTime = getDate()
  689. Where Cookie = @Cookie";
  690. }
  691. else
  692. { //不存在则新建一条记录
  693. strSql = @"Insert into sys_SRM_CheckInstall(Cookie, LastAccessTime)
  694. Values( @Cookie, getDate() )";
  695. }
  696. DbHelper.ExecuteNonQuery(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie);
  697. }
  698. public DateTime ToDateTime(object SrcValue)
  699. {
  700. if (Convert.IsDBNull(SrcValue) == true)
  701. return DateTime.MinValue;
  702. else
  703. {
  704. try
  705. {
  706. return Convert.ToDateTime(SrcValue);
  707. }
  708. catch
  709. {
  710. return DateTime.MinValue;
  711. }
  712. }
  713. }
  714. /// <summary>
  715. /// 获取此Cookie的最后访问时间
  716. /// </summary>
  717. /// <param name="strCookie"></param>
  718. /// <returns></returns>
  719. private DateTime GetLastAccessTime(string strCookie, ref bool bIsExist)
  720. {
  721. DateTime dtLastAccessTime = DateTime.MinValue;
  722. bIsExist = false;
  723. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  724. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) };
  725. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  726. {
  727. if (drCookie.Read())
  728. {
  729. dtLastAccessTime = ToDateTime(drCookie["LastAccessTime"]);
  730. bIsExist = true;
  731. }
  732. drCookie.Close();
  733. }
  734. return dtLastAccessTime;
  735. }
  736. [HttpGet]
  737. [HandlerAjaxOnly]
  738. public ActionResult IsCheckInstall(string checkInstall)
  739. {
  740. string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,");
  741. if (Request.QueryString["cookie"] != null)
  742. { //有控件上传的Cookie值
  743. string strCookie = Request.QueryString["cookie"].ToString();
  744. //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  745. UpdateCheckInstall(strCookie);
  746. strValue = strValue + "上传的cookie:" + strCookie;
  747. }
  748. else if (checkInstall != null)
  749. {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况
  750. string strCookie = checkInstall;
  751. //读取最后访问的时间
  752. string strResult = "PrintControlInstall";
  753. bool bIsExist = false;
  754. DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist);
  755. if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now)
  756. {
  757. strResult = "NOT";
  758. }
  759. Response.Clear();
  760. Response.Write(strResult);
  761. strValue = strValue + "检测安装的值:" + strCookie;
  762. }
  763. WriteLog(strValue);
  764. return null;
  765. }
  766. [HttpGet]
  767. [HandlerAjaxOnly]
  768. public ActionResult IsCheckInstall()
  769. {
  770. string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,");
  771. if (Request.QueryString["cookie"] != null)
  772. { //有控件上传的Cookie值
  773. string strCookie = Request.QueryString["cookie"].ToString();
  774. //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  775. UpdateCheckInstall(strCookie);
  776. strValue = strValue + "上传的cookie:" + strCookie;
  777. }
  778. else if (Request.QueryString["checkInstall"] != null)
  779. {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况
  780. string strCookie = Request.QueryString["checkInstall"];
  781. //读取最后访问的时间
  782. string strResult = "PrintControlInstall";
  783. bool bIsExist = false;
  784. DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist);
  785. if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now)
  786. {
  787. strResult = "NOT";
  788. }
  789. Response.Clear();
  790. Response.Write(strResult);
  791. strValue = strValue + "检测安装的值:" + strCookie;
  792. }
  793. WriteLog(strValue);
  794. return null;
  795. }
  796. #endregion
  797. /// <summary>
  798. /// 导入Excel
  799. /// </summary>
  800. /// <param name="fileURL"></param>
  801. /// <returns></returns>
  802. [HttpPost]
  803. public ActionResult Import(string fileURL)
  804. {
  805. var fileName = "";
  806. var filePath = fileURL;
  807. string path = Path.Combine(filePath, fileName);
  808. //file.SaveAs(path);
  809. DataTable excelTable = new DataTable();
  810. //excelTable =SqlHelper.GetExcelDataTable(path);
  811. DataTable dbdata = new DataTable();
  812. dbdata.Columns.Add("LocationCode");
  813. dbdata.Columns.Add("LocationName");
  814. dbdata.Columns.Add("Musername");
  815. dbdata.Columns.Add("MUSER");
  816. dbdata.Columns.Add("EATTRIBUTE1");
  817. for (int i = 0; i < excelTable.Rows.Count; i++)
  818. {
  819. string LocationCode = "";
  820. string LocationName = "";
  821. DataRow dr = excelTable.Rows[i];
  822. DataRow dr_ = dbdata.NewRow();
  823. if (!string.IsNullOrWhiteSpace(dr["区"].ToString().ToUpper()))
  824. {
  825. LocationCode += "-" + dr["区"].ToString().ToUpper();
  826. LocationName += dr["区"].ToString().ToUpper() + "区";
  827. }
  828. if (!string.IsNullOrWhiteSpace(dr["排"].ToString().ToUpper()))
  829. {
  830. LocationCode += "-" + dr["排"].ToString().ToUpper();
  831. LocationName += dr["排"].ToString().ToUpper() + "排";
  832. }
  833. if (!string.IsNullOrWhiteSpace(dr["货架"].ToString().ToUpper()))
  834. {
  835. LocationCode += "-" + dr["货架"].ToString().ToUpper();
  836. LocationName += dr["货架"].ToString().ToUpper() + "货架";
  837. }
  838. if (!string.IsNullOrWhiteSpace(dr["层"].ToString().ToUpper()))
  839. {
  840. LocationCode += "-" + dr["层"].ToString().ToUpper();
  841. LocationName += dr["层"].ToString().ToUpper() + "层";
  842. }
  843. if (!string.IsNullOrWhiteSpace(dr["格"].ToString().ToUpper()))
  844. {
  845. LocationCode += "-" + dr["格"].ToString().ToUpper();
  846. LocationName += dr["格"].ToString().ToUpper() + "格";
  847. }
  848. dr_["LocationCode"] = LocationCode;
  849. dr_["LocationName"] = LocationName;
  850. dr_["Musername"] = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  851. dr_["MUSER"] = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  852. dr_["Musername"] = "";
  853. dbdata.Rows.Add(dr_);
  854. }
  855. SqlHelper.RemoveEmpty(dbdata);
  856. SqlHelper.SqlBulkCopyByDatatable( "ICSLocation", dbdata);
  857. return View();
  858. }
  859. //周转箱导入
  860. [HttpPost]
  861. /// <summary>
  862. /// 文件上传到本地
  863. /// </summary>
  864. public string UploadFile()
  865. {
  866. try
  867. {
  868. HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files;
  869. if (hpFiles != null && hpFiles.Count > 0)
  870. {
  871. string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
  872. if (IsXls != ".xls" && IsXls != ".xlsx")
  873. {
  874. return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
  875. }
  876. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Guid.NewGuid() + IsXls; //获取Execle文件名 DateTime日期函数
  877. string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
  878. int iLen = hpFiles[0].ContentLength;
  879. if (Directory.Exists(savePath)) return "文件已存在";
  880. byte[] bData = new byte[iLen];
  881. hpFiles[0].InputStream.Read(bData, 0, iLen);
  882. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  883. newFile.Write(bData, 0, bData.Length);
  884. newFile.Flush();
  885. int _FileSizeTemp = hpFiles[0].ContentLength;
  886. newFile.Close();
  887. newFile.Dispose();
  888. //bool del = false;
  889. string mess = "";
  890. mess = App.SetDataBoxes(savePath);
  891. if (System.IO.File.Exists(savePath))//删除文件
  892. {
  893. System.IO.File.Delete(savePath);
  894. }
  895. return mess;
  896. }
  897. else
  898. {
  899. return "获取文件失败";
  900. }
  901. }
  902. catch (Exception ex)
  903. {
  904. return ex.ToString();
  905. }
  906. }
  907. //周转箱台账导入
  908. [HttpPost]
  909. /// <summary>
  910. /// 文件上传到本地
  911. /// </summary>
  912. public string UploadBoxAccountFile()
  913. {
  914. try
  915. {
  916. HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files;
  917. if (hpFiles != null && hpFiles.Count > 0)
  918. {
  919. string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
  920. if (IsXls != ".xls" && IsXls != ".xlsx")
  921. {
  922. return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
  923. }
  924. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Guid.NewGuid() + IsXls; //获取Execle文件名 DateTime日期函数
  925. string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
  926. int iLen = hpFiles[0].ContentLength;
  927. if (Directory.Exists(savePath)) return "文件已存在";
  928. byte[] bData = new byte[iLen];
  929. hpFiles[0].InputStream.Read(bData, 0, iLen);
  930. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  931. newFile.Write(bData, 0, bData.Length);
  932. newFile.Flush();
  933. int _FileSizeTemp = hpFiles[0].ContentLength;
  934. newFile.Close();
  935. newFile.Dispose();
  936. //bool del = false;
  937. string mess = "";
  938. mess = App.SetDataBoxAccount(savePath);
  939. if (System.IO.File.Exists(savePath))//删除文件
  940. {
  941. System.IO.File.Delete(savePath);
  942. }
  943. return mess;
  944. }
  945. else
  946. {
  947. return "获取文件失败";
  948. }
  949. }
  950. catch (Exception ex)
  951. {
  952. return ex.ToString();
  953. }
  954. }
  955. //模具档案导入
  956. [HttpPost]
  957. /// <summary>
  958. /// 文件上传到本地
  959. /// </summary>
  960. public string UploadMouldFile()
  961. {
  962. try
  963. {
  964. HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files;
  965. if (hpFiles != null && hpFiles.Count > 0)
  966. {
  967. string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
  968. if (IsXls != ".xls" && IsXls != ".xlsx")
  969. {
  970. return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
  971. }
  972. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Guid.NewGuid() + IsXls; //获取Execle文件名 DateTime日期函数
  973. string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
  974. int iLen = hpFiles[0].ContentLength;
  975. if (Directory.Exists(savePath)) return "文件已存在";
  976. byte[] bData = new byte[iLen];
  977. hpFiles[0].InputStream.Read(bData, 0, iLen);
  978. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  979. newFile.Write(bData, 0, bData.Length);
  980. newFile.Flush();
  981. int _FileSizeTemp = hpFiles[0].ContentLength;
  982. newFile.Close();
  983. newFile.Dispose();
  984. //bool del = false;
  985. string mess = "";
  986. mess = App.SetDataMould(savePath);
  987. if (System.IO.File.Exists(savePath))//删除文件
  988. {
  989. System.IO.File.Delete(savePath);
  990. }
  991. return mess;
  992. }
  993. else
  994. {
  995. return "获取文件失败";
  996. }
  997. }
  998. catch (Exception ex)
  999. {
  1000. return ex.ToString();
  1001. }
  1002. }
  1003. //模具台账导入
  1004. [HttpPost]
  1005. /// <summary>
  1006. /// 文件上传到本地
  1007. /// </summary>
  1008. public string UploadMouldAccountFile()
  1009. {
  1010. try
  1011. {
  1012. HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files;
  1013. if (hpFiles != null && hpFiles.Count > 0)
  1014. {
  1015. string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
  1016. if (IsXls != ".xls" && IsXls != ".xlsx")
  1017. {
  1018. return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
  1019. }
  1020. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Guid.NewGuid() + IsXls; //获取Execle文件名 DateTime日期函数
  1021. string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
  1022. int iLen = hpFiles[0].ContentLength;
  1023. if (Directory.Exists(savePath)) return "文件已存在";
  1024. byte[] bData = new byte[iLen];
  1025. hpFiles[0].InputStream.Read(bData, 0, iLen);
  1026. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  1027. newFile.Write(bData, 0, bData.Length);
  1028. newFile.Flush();
  1029. int _FileSizeTemp = hpFiles[0].ContentLength;
  1030. newFile.Close();
  1031. newFile.Dispose();
  1032. //bool del = false;
  1033. string mess = "";
  1034. mess = App.SetDataMouldAccount(savePath);
  1035. if (System.IO.File.Exists(savePath))//删除文件
  1036. {
  1037. System.IO.File.Delete(savePath);
  1038. }
  1039. return mess;
  1040. }
  1041. else
  1042. {
  1043. return "获取文件失败";
  1044. }
  1045. }
  1046. catch (Exception ex)
  1047. {
  1048. return ex.ToString();
  1049. }
  1050. }
  1051. [HttpPost]
  1052. public ActionResult UpLoadFileImport()
  1053. {
  1054. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1055. string fileName = "";
  1056. //获取上传的文件集合
  1057. try
  1058. {
  1059. //上传图片格式数组声明
  1060. string[] fileter = new string[] { ".jpg", ".png", ".jpeg" };
  1061. HttpFileCollection httpFile = System.Web.HttpContext.Current.Request.Files;
  1062. for (int i = 0; i < httpFile.Count; i++)
  1063. {
  1064. //上传文件后缀
  1065. string fileSuffix = httpFile[i].FileName.Substring(httpFile[i].FileName.LastIndexOf(".")).ToLower();
  1066. //保存图片名称以时间格式
  1067. fileName = DateTime.Now.ToString("yyyyMMddhhmmssms") + fileSuffix;
  1068. //string fileName = Path.GetFileNameWithoutExtension(httpFile[i].FileName)
  1069. // + Path.GetExtension(httpFile[i].FileName);
  1070. string Paths = System.Web.HttpContext.Current.Server.MapPath("~\\File\\Picture\\");
  1071. if (!fileter.Contains(fileSuffix))
  1072. {
  1073. return Error("上传失败,请上传后缀名为.jpg、.png、.jpeg的图片");
  1074. }
  1075. if (httpFile[i].ContentLength > 2097152)
  1076. {
  1077. return Error("上传失败,上传图片过大");
  1078. }
  1079. if (!Directory.Exists(Paths))
  1080. {
  1081. Directory.CreateDirectory(Paths);
  1082. }
  1083. var filePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\Picture\\" + fileName);
  1084. int iLen = httpFile[0].ContentLength;
  1085. byte[] bData = new byte[iLen];
  1086. httpFile[0].InputStream.Read(bData, 0, iLen);
  1087. FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate);
  1088. fs.Write(bData, 0, bData.Length);
  1089. fs.Flush();
  1090. fs.Close();
  1091. fs.Dispose();
  1092. }
  1093. return Success("上传成功!", fileName);
  1094. }
  1095. catch (Exception ex)
  1096. {
  1097. return Error(ex.Message);
  1098. }
  1099. }
  1100. //新增标签数据源
  1101. [HttpPost]
  1102. [HandlerAjaxOnly]
  1103. public ActionResult CreateLableDataSource( string Sys_LableDataSource)
  1104. {
  1105. string msg = App.CreateLableDataSource(Sys_LableDataSource);
  1106. if (!string.IsNullOrEmpty(msg))
  1107. {
  1108. return Error(msg);
  1109. }
  1110. else
  1111. {
  1112. return Success("添加成功!");
  1113. }
  1114. }
  1115. [HttpGet]
  1116. [HandlerAjaxOnly]
  1117. public ActionResult GetTXT(string ID)
  1118. {
  1119. DataTable ListData = App.GetTXT(ID);
  1120. var JsonData = new
  1121. {
  1122. rows = ListData,
  1123. };
  1124. return Content(JsonData.ToJson());
  1125. }
  1126. //修改标签数据源
  1127. [HttpPost]
  1128. [HandlerAjaxOnly]
  1129. public ActionResult updateLableDataSource(string Sys_LableDataSource)
  1130. {
  1131. string msg = App.updateLableDataSource(Sys_LableDataSource);
  1132. if (!string.IsNullOrEmpty(msg))
  1133. {
  1134. return Error(msg);
  1135. }
  1136. else
  1137. {
  1138. return Success("添加成功!");
  1139. }
  1140. }
  1141. [HttpPost]
  1142. [HandlerAjaxOnly]
  1143. [ValidateAntiForgeryToken]
  1144. public ActionResult DeleteLableDataSource(string keyValue)
  1145. {
  1146. string msg = App.DeleteLableDataSource(keyValue);
  1147. if (string.IsNullOrEmpty(msg))
  1148. {
  1149. return Success("删除成功!");
  1150. }
  1151. else
  1152. {
  1153. return Error(msg);
  1154. }
  1155. }
  1156. [HttpGet]
  1157. [HandlerAjaxOnly]
  1158. public ActionResult GetLableType()
  1159. {
  1160. DataTable dt = App.GetLableType();
  1161. return Content(dt.ToJson());
  1162. }
  1163. [HttpGet]
  1164. [HandlerAjaxOnly]
  1165. public ActionResult GetSys_LablesID()
  1166. {
  1167. DataTable dt = App.GetSys_LablesID();
  1168. return Content(dt.ToJson());
  1169. }
  1170. //新增标签数据源
  1171. [HttpPost]
  1172. [HandlerAjaxOnly]
  1173. public ActionResult CreateLables(string txtLableName,string sel_LableType, string sel_LableSourceID )
  1174. {
  1175. string msg = App.CreateLables(txtLableName, sel_LableType, sel_LableSourceID);
  1176. if (!string.IsNullOrEmpty(msg))
  1177. {
  1178. return Error(msg);
  1179. }
  1180. else
  1181. {
  1182. return Success("添加成功!");
  1183. }
  1184. }
  1185. [HttpGet]
  1186. [HandlerAjaxOnly]
  1187. public ActionResult GetLabelTXT(string ID)
  1188. {
  1189. DataTable ListData = App.GetLabelTXT(ID);
  1190. var JsonData = new
  1191. {
  1192. rows = ListData,
  1193. };
  1194. return Content(JsonData.ToJson());
  1195. }
  1196. [HttpPost]
  1197. [HandlerAjaxOnly]
  1198. public ActionResult updateLables(string ID,string txtLableName, string sel_LableType, string sel_LableSourceID)
  1199. {
  1200. string msg = App.updateLables(ID,txtLableName, sel_LableType, sel_LableSourceID);
  1201. if (!string.IsNullOrEmpty(msg))
  1202. {
  1203. return Error(msg);
  1204. }
  1205. else
  1206. {
  1207. return Success("修改成功!");
  1208. }
  1209. }
  1210. [HttpPost]
  1211. [HandlerAjaxOnly]
  1212. [ValidateAntiForgeryToken]
  1213. public ActionResult DeleteICSLabelTemplate(string keyValue)
  1214. {
  1215. string msg = App.DeleteICSLabelTemplate(keyValue);
  1216. if (string.IsNullOrEmpty(msg))
  1217. {
  1218. return Success("删除成功!");
  1219. }
  1220. else
  1221. {
  1222. return Error(msg);
  1223. }
  1224. }
  1225. //获取父容器
  1226. [HttpGet]
  1227. [HandlerAjaxOnly]
  1228. public ActionResult GetContainerID()
  1229. {
  1230. DataTable dt = App.GetContainerID();
  1231. return Content(dt.ToJson());
  1232. }
  1233. //获取父容器
  1234. [HttpGet]
  1235. [HandlerAjaxOnly]
  1236. public ActionResult GetContainerType()
  1237. {
  1238. DataTable dt = App.GetContainerType();
  1239. return Content(dt.ToJson());
  1240. }
  1241. [HttpPost]
  1242. public ActionResult UpLoadLabelFile()
  1243. {
  1244. //获取上传的文件集合
  1245. HttpFileCollection httpFile = System.Web.HttpContext.Current.Request.Files;
  1246. //获取送货单号
  1247. string ID = Request.Form["ID"].ToString();
  1248. string LableName = Request.Form["LableName"].ToString();
  1249. string fileName = Path.GetFileNameWithoutExtension(httpFile[0].FileName)
  1250. + "_" + LableName + Path.GetExtension(httpFile[0].FileName);
  1251. string filePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\LablesFile\\" + fileName);
  1252. int iLen = httpFile[0].ContentLength;
  1253. byte[] bData = new byte[iLen];
  1254. httpFile[0].InputStream.Read(bData, 0, iLen);
  1255. FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate);
  1256. fs.Write(bData, 0, bData.Length);
  1257. fs.Flush();
  1258. fs.Close();
  1259. fs.Dispose();
  1260. int count = App.UpLoadLabelFile(ID, fileName);
  1261. if (count > 0)
  1262. {
  1263. return Success("上传成功!");
  1264. }
  1265. else
  1266. {
  1267. return Error("上传失败");
  1268. }
  1269. }
  1270. [HttpPost]
  1271. public ActionResult UpLoadFileTxT()
  1272. {
  1273. //获取上传的文件集合
  1274. HttpFileCollection httpFile = System.Web.HttpContext.Current.Request.Files;
  1275. //获取送货单号
  1276. string LotNo = Request.Form["LotNo"].ToString();
  1277. string fileName = Path.GetFileNameWithoutExtension(httpFile[0].FileName)
  1278. + Path.GetExtension(httpFile[0].FileName);
  1279. string filePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + fileName);
  1280. int iLen = httpFile[0].ContentLength;
  1281. byte[] bData = new byte[iLen];
  1282. httpFile[0].InputStream.Read(bData, 0, iLen);
  1283. FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate);
  1284. fs.Write(bData, 0, bData.Length);
  1285. fs.Flush();
  1286. fs.Close();
  1287. fs.Dispose();
  1288. int count = App.UpLoadFiles(LotNo, fileName);
  1289. if (count > 0)
  1290. {
  1291. return Success("上传成功!");
  1292. }
  1293. else
  1294. {
  1295. return Error("上传失败");
  1296. }
  1297. }
  1298. //料品不良组导入
  1299. [HttpPost]
  1300. /// <summary>
  1301. /// 文件上传到本地
  1302. /// </summary>
  1303. public string UploadFileInvBadGroup()
  1304. {
  1305. try
  1306. {
  1307. HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files;
  1308. if (hpFiles != null && hpFiles.Count > 0)
  1309. {
  1310. string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
  1311. if (IsXls != ".xls" && IsXls != ".xlsx")
  1312. {
  1313. return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
  1314. }
  1315. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Guid.NewGuid() + IsXls; //获取Execle文件名 DateTime日期函数
  1316. string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
  1317. int iLen = hpFiles[0].ContentLength;
  1318. if (Directory.Exists(savePath)) return "文件已存在";
  1319. byte[] bData = new byte[iLen];
  1320. hpFiles[0].InputStream.Read(bData, 0, iLen);
  1321. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  1322. newFile.Write(bData, 0, bData.Length);
  1323. newFile.Flush();
  1324. int _FileSizeTemp = hpFiles[0].ContentLength;
  1325. newFile.Close();
  1326. newFile.Dispose();
  1327. //bool del = false;
  1328. string mess = "";
  1329. mess = App.UploadFileInvBadGroup(savePath);
  1330. if (System.IO.File.Exists(savePath))//删除文件
  1331. {
  1332. System.IO.File.Delete(savePath);
  1333. }
  1334. return mess;
  1335. }
  1336. else
  1337. {
  1338. return "获取文件失败";
  1339. }
  1340. }
  1341. catch (Exception ex)
  1342. {
  1343. return ex.ToString();
  1344. }
  1345. }
  1346. //根据ID获取其他站点
  1347. public ActionResult GetWorkPointNotInID(string WorkPointCode)
  1348. {
  1349. DataTable dt = App.GetWorkPointNotInID(WorkPointCode);
  1350. return Content(dt.ToJson());
  1351. }
  1352. //克隆站点
  1353. [HttpPost]
  1354. [HandlerAjaxOnly]
  1355. public ActionResult CloneWorkPointByCode(string WorkPoint, string WorkPointCode)
  1356. {
  1357. string msg = App.CloneWorkPointByCode(WorkPoint, WorkPointCode);
  1358. if (!string.IsNullOrEmpty(msg))
  1359. {
  1360. return Error(msg);
  1361. }
  1362. else
  1363. {
  1364. return Success("修改成功!");
  1365. }
  1366. }
  1367. [HttpPost]
  1368. [HandlerAjaxOnly]
  1369. public ActionResult DeleteTableByCode(string TableCode)
  1370. {
  1371. string msg = App.DeleteTableByCode(TableCode);
  1372. if (!string.IsNullOrEmpty(msg))
  1373. {
  1374. return Error(msg);
  1375. }
  1376. else
  1377. {
  1378. return Success("添加成功!");
  1379. }
  1380. }
  1381. }
  1382. }