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.

1539 lines
51 KiB

  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. string msg = App.InsertBoxAccount(keyValue);
  405. if (!string.IsNullOrEmpty(msg))
  406. {
  407. return Error(msg);
  408. }
  409. else
  410. {
  411. return Success("添加成功!");
  412. }
  413. }
  414. /// <summary>
  415. /// 修改周转箱台账
  416. /// </summary>
  417. /// <param name="keyValue"></param>
  418. /// <returns></returns>
  419. [HttpPost]
  420. [HandlerAjaxOnly]
  421. public ActionResult UpdateBoxAccount(string keyValue)
  422. {
  423. string msg = App.UpdateBoxAccount(keyValue);
  424. if (!string.IsNullOrEmpty(msg))
  425. {
  426. return Error(msg);
  427. }
  428. else
  429. {
  430. return Success("修改成功!");
  431. }
  432. }
  433. /// <summary>
  434. /// 删除周转箱台账
  435. /// </summary>
  436. /// <returns></returns>
  437. [HttpPost]
  438. [HandlerAjaxOnly]
  439. [ValidateAntiForgeryToken]
  440. public ActionResult DeleteBoxAccount(string keyValue)
  441. {
  442. string msg = App.DeleteBoxAccount(keyValue);
  443. if (string.IsNullOrEmpty(msg))
  444. {
  445. return Success("删除成功!");
  446. }
  447. else
  448. {
  449. return Error(msg);
  450. }
  451. }
  452. /// <summary>
  453. /// 新增模具台账信息
  454. /// </summary>
  455. /// <param name="keyValue"></param>
  456. /// <returns></returns>
  457. [HttpPost]
  458. [HandlerAjaxOnly]
  459. public ActionResult InsertMouldAccount(string keyValue)
  460. {
  461. string msg = App.InsertMouldAccount(keyValue);
  462. if (!string.IsNullOrEmpty(msg))
  463. {
  464. return Error(msg);
  465. }
  466. else
  467. {
  468. return Success("添加成功!");
  469. }
  470. }
  471. /// <summary>
  472. /// 修改模具台账
  473. /// </summary>
  474. /// <param name="keyValue"></param>
  475. /// <returns></returns>
  476. [HttpPost]
  477. [HandlerAjaxOnly]
  478. public ActionResult UpdateMouldAccount(string keyValue)
  479. {
  480. string msg = App.UpdateMouldAccount(keyValue);
  481. if (!string.IsNullOrEmpty(msg))
  482. {
  483. return Error(msg);
  484. }
  485. else
  486. {
  487. return Success("修改成功!");
  488. }
  489. }
  490. #region 打印
  491. /// <summary>
  492. /// 打印数据参数:服务器的URL+打印的文件名,转化为Base64编码
  493. /// </summary>
  494. protected string strPrintData;
  495. /// <summary>
  496. /// 标识是否安装了控件
  497. /// </summary>
  498. protected bool bIsInstallPrintControl = true;
  499. /// <summary>
  500. /// 打印控件的Cookie值
  501. /// </summary>
  502. protected string strPrintControlCookie = "";
  503. /// <summary>
  504. /// 获取Url中去掉文件名的路径
  505. /// </summary>
  506. /// <returns></returns>
  507. private string GetUrlPath()
  508. {
  509. string strUrl = Request.Url.ToString();
  510. int iEnd = strUrl.LastIndexOf("/");
  511. strUrl = strUrl.Substring(0, iEnd + 1);
  512. return strUrl;
  513. }
  514. /// <summary>
  515. /// 设置控件调用的Cookie值,判断是否安装了打印控件
  516. /// </summary>
  517. /// <param name="pJson"></param>
  518. private void SetCookieAndURL(PrintJson pJson)
  519. {
  520. bIsInstallPrintControl = false;
  521. strPrintControlCookie = "";
  522. HttpCookie pCookieInstall = Request.Cookies["InstallPrintControl"];
  523. if (pCookieInstall != null)
  524. { //Cookie存在
  525. strPrintControlCookie = pCookieInstall.Value.ToString();
  526. //以Cookie值查找在数据表中是否存在
  527. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  528. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strPrintControlCookie) };
  529. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  530. {
  531. if (drCookie.Read())
  532. { //标识为已经安装
  533. bIsInstallPrintControl = true;
  534. }
  535. drCookie.Close();
  536. }
  537. //更新Cookie的保存时间
  538. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  539. Response.SetCookie(pCookieInstall);
  540. }
  541. else
  542. {//Cookie不存在,则新建Cookie
  543. strPrintControlCookie = System.Guid.NewGuid().ToString();
  544. pCookieInstall = new HttpCookie("InstallPrintControl", strPrintControlCookie);
  545. pCookieInstall.Expires = DateTime.Now.AddYears(10);
  546. Response.Cookies.Add(pCookieInstall);
  547. }
  548. string strUrl = Server.MapPath("/PrintTemp/") + "IsCheckInstall";
  549. pJson.SetCookieAndURL(strPrintControlCookie, strUrl);
  550. }
  551. [HttpPost]
  552. [HandlerAjaxOnly]
  553. public ActionResult PrintStack(string keyValue)
  554. {
  555. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  556. string strPrintFileName = Server.MapPath("/ReportFile/") + "Stack.fr3";
  557. PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName);
  558. pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息
  559. pJson.MasterOptions(1, "STNO", false); //主从关系
  560. SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  561. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  562. string strSql = @"select a.LocationCode,
  563. a.ID,
  564. a.LocationName,
  565. b.WarehouseCode,
  566. b.WarehouseName,
  567. a.Musername as 'MUSER',
  568. a.MTIME
  569. from ICSLocation a WITH (NOLOCK)
  570. inner join ICSWarehouse b WITH (NOLOCK) on a.WHID=b.ID
  571. where 1=1
  572. and a.ID IN (" + keyValue.TrimEnd(',') + ")";
  573. DataTable dtInInfo = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  574. // strSql = @"SELECT Row_Number() OVER (partition BY a.STNO ORDER BY a.CREATETIME DESC) AS rowno,c.STNO,
  575. // c.PLANQTY,c.LotnoQTY,c.CartonNOQTY,c.ITEMCODE,b.INVNAME,b.INVSTD,b.INVPARSETYPE,d.StorageName,
  576. // CONVERT(VARCHAR,CAST(ISNULL(c.Qty,0) AS money),1) AS Qty,
  577. // CONVERT(VARCHAR,CAST(ISNULL(c.Meters,0) AS money),1) AS Meters,
  578. // c.STNO AS QRSTNO,c.TransNO,c.TransLine,c.MEMO,c.VenderLotNO,CONVERT(varchar(10), c.PRODUCTDATE, 23) as PRODUCTDATE,a.remark
  579. // FROM
  580. // (SELECT aa.STNO,aa.ITEMCODE,aa.WorkPoint,SUM(aa.PLANQTY) PLANQTY,SUM(cc.LOTQTY) Qty,
  581. // SUM(ISNULL(cc.Meters,0)) Meters,cc.TransNO,cc.TransLine,dd.MEMO,cc.VenderLotNO,cc.PRODUCTDATE,
  582. // COUNT(aa.LOTNO) LotnoQTY,COUNT(bb.CartonNO) CartonNOQTY
  583. // FROM ICSASNDETAIL aa
  584. // LEFT JOIN ICSITEMLot2Carton bb ON aa.LOTNO = bb.LotNO AND aa.WorkPoint = bb.WorkPoint
  585. // LEFT JOIN ICSITEMLot cc ON aa.LOTNO = cc.LotNO AND aa.WorkPoint = cc.WorkPoint
  586. // LEFT JOIN ICSPO_PoMain dd on dd.POCode=cc.TransNO and dd.PORow=cc.TransLine
  587. // GROUP BY aa.stno,aa.itemcode,aa.WorkPoint,cc.TransNO,cc.TransLine,dd.MEMO,cc.VenderLotNO,cc.PRODUCTDATE) c
  588. // LEFT JOIN ICSASN a on c.stno=a.stno AND c.WorkPoint=a.WorkPoint
  589. // LEFT JOIN dbo.ICSINVENTORY b ON c.ITEMCODE=b.INVCODE AND b.WorkPoint=c.WorkPoint
  590. // LEFT JOIN dbo.icsstorage d ON b.INVMACHINETYPE=d.StorageCode
  591. // WHERE c.STNO IN (" + keyValue.TrimEnd(',') + ") and c.WorkPoint='" + WorkPoint + "'";
  592. // DataTable dtInMaterial = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null);
  593. string strPrintTempFile = pJson.ShowReport(dtInInfo, null); //产生JSON文件内容
  594. //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印
  595. string strServerURL = Server.MapPath("/PrintTemp/");
  596. string strData = strServerURL + strPrintTempFile;
  597. strPrintData = PrintFunction.EnBase64(strData);
  598. var JsonData = new
  599. {
  600. strPrintData_1 = strPrintData,
  601. bIsInstallPrintControl_1 = bIsInstallPrintControl,
  602. strPrintControlCookie_1 = strPrintControlCookie
  603. };
  604. // string sql = @"UPDATE dbo.ICSASN
  605. // SET ADDITION1=ISNULL(ADDITION1,0)+1,
  606. // ADDITION2=CONVERT(varchar(100), GETDATE(), 21)
  607. // WHERE STNO in (" + keyValue.TrimEnd(',') + ") and WorkPoint='" + WorkPoint + "'";
  608. // SqlHelper.ExecuteNonQuery(sql);
  609. return Content(JsonData.ToJson());
  610. }
  611. /// <summary>
  612. /// 写日志(用于跟踪)
  613. /// </summary>
  614. private void WriteLog(string strMessage)
  615. {
  616. string strLogFile = Server.MapPath("./Cookie_Log.txt");
  617. StreamWriter swLogFile = null;
  618. try
  619. {
  620. if (!System.IO.File.Exists(strLogFile))
  621. {
  622. swLogFile = System.IO.File.CreateText(strLogFile);
  623. }
  624. else
  625. {
  626. swLogFile = System.IO.File.AppendText(strLogFile);
  627. }
  628. swLogFile.WriteLine(strMessage);
  629. }
  630. catch
  631. {
  632. }
  633. finally
  634. {
  635. if (swLogFile != null)
  636. swLogFile.Close();
  637. }
  638. }
  639. /// <summary>
  640. ///判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  641. /// </summary>
  642. /// <param name="strCookie"></param>
  643. private void UpdateCheckInstall(string strCookie)
  644. {
  645. bool bIsExist = false;
  646. //判断记录是否存在
  647. GetLastAccessTime(strCookie, ref bIsExist);
  648. string strSql = "";
  649. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) };
  650. if (bIsExist)
  651. { //存在则更新最后访问的时间
  652. strSql = @"Update sys_SRM_CheckInstall
  653. Set LastAccessTime = getDate()
  654. Where Cookie = @Cookie";
  655. }
  656. else
  657. { //不存在则新建一条记录
  658. strSql = @"Insert into sys_SRM_CheckInstall(Cookie, LastAccessTime)
  659. Values( @Cookie, getDate() )";
  660. }
  661. DbHelper.ExecuteNonQuery(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie);
  662. }
  663. public DateTime ToDateTime(object SrcValue)
  664. {
  665. if (Convert.IsDBNull(SrcValue) == true)
  666. return DateTime.MinValue;
  667. else
  668. {
  669. try
  670. {
  671. return Convert.ToDateTime(SrcValue);
  672. }
  673. catch
  674. {
  675. return DateTime.MinValue;
  676. }
  677. }
  678. }
  679. /// <summary>
  680. /// 获取此Cookie的最后访问时间
  681. /// </summary>
  682. /// <param name="strCookie"></param>
  683. /// <returns></returns>
  684. private DateTime GetLastAccessTime(string strCookie, ref bool bIsExist)
  685. {
  686. DateTime dtLastAccessTime = DateTime.MinValue;
  687. bIsExist = false;
  688. string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie";
  689. SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) };
  690. using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie))
  691. {
  692. if (drCookie.Read())
  693. {
  694. dtLastAccessTime = ToDateTime(drCookie["LastAccessTime"]);
  695. bIsExist = true;
  696. }
  697. drCookie.Close();
  698. }
  699. return dtLastAccessTime;
  700. }
  701. [HttpGet]
  702. [HandlerAjaxOnly]
  703. public ActionResult IsCheckInstall(string checkInstall)
  704. {
  705. string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,");
  706. if (Request.QueryString["cookie"] != null)
  707. { //有控件上传的Cookie值
  708. string strCookie = Request.QueryString["cookie"].ToString();
  709. //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  710. UpdateCheckInstall(strCookie);
  711. strValue = strValue + "上传的cookie:" + strCookie;
  712. }
  713. else if (checkInstall != null)
  714. {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况
  715. string strCookie = checkInstall;
  716. //读取最后访问的时间
  717. string strResult = "PrintControlInstall";
  718. bool bIsExist = false;
  719. DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist);
  720. if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now)
  721. {
  722. strResult = "NOT";
  723. }
  724. Response.Clear();
  725. Response.Write(strResult);
  726. strValue = strValue + "检测安装的值:" + strCookie;
  727. }
  728. WriteLog(strValue);
  729. return null;
  730. }
  731. [HttpGet]
  732. [HandlerAjaxOnly]
  733. public ActionResult IsCheckInstall()
  734. {
  735. string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,");
  736. if (Request.QueryString["cookie"] != null)
  737. { //有控件上传的Cookie值
  738. string strCookie = Request.QueryString["cookie"].ToString();
  739. //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间
  740. UpdateCheckInstall(strCookie);
  741. strValue = strValue + "上传的cookie:" + strCookie;
  742. }
  743. else if (Request.QueryString["checkInstall"] != null)
  744. {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况
  745. string strCookie = Request.QueryString["checkInstall"];
  746. //读取最后访问的时间
  747. string strResult = "PrintControlInstall";
  748. bool bIsExist = false;
  749. DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist);
  750. if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now)
  751. {
  752. strResult = "NOT";
  753. }
  754. Response.Clear();
  755. Response.Write(strResult);
  756. strValue = strValue + "检测安装的值:" + strCookie;
  757. }
  758. WriteLog(strValue);
  759. return null;
  760. }
  761. #endregion
  762. /// <summary>
  763. /// 导入Excel
  764. /// </summary>
  765. /// <param name="fileURL"></param>
  766. /// <returns></returns>
  767. [HttpPost]
  768. public ActionResult Import(string fileURL)
  769. {
  770. var fileName = "";
  771. var filePath = fileURL;
  772. string path = Path.Combine(filePath, fileName);
  773. //file.SaveAs(path);
  774. DataTable excelTable = new DataTable();
  775. //excelTable =SqlHelper.GetExcelDataTable(path);
  776. DataTable dbdata = new DataTable();
  777. dbdata.Columns.Add("LocationCode");
  778. dbdata.Columns.Add("LocationName");
  779. dbdata.Columns.Add("Musername");
  780. dbdata.Columns.Add("MUSER");
  781. dbdata.Columns.Add("EATTRIBUTE1");
  782. for (int i = 0; i < excelTable.Rows.Count; i++)
  783. {
  784. string LocationCode = "";
  785. string LocationName = "";
  786. DataRow dr = excelTable.Rows[i];
  787. DataRow dr_ = dbdata.NewRow();
  788. if (!string.IsNullOrWhiteSpace(dr["区"].ToString().ToUpper()))
  789. {
  790. LocationCode += "-" + dr["区"].ToString().ToUpper();
  791. LocationName += dr["区"].ToString().ToUpper() + "区";
  792. }
  793. if (!string.IsNullOrWhiteSpace(dr["排"].ToString().ToUpper()))
  794. {
  795. LocationCode += "-" + dr["排"].ToString().ToUpper();
  796. LocationName += dr["排"].ToString().ToUpper() + "排";
  797. }
  798. if (!string.IsNullOrWhiteSpace(dr["货架"].ToString().ToUpper()))
  799. {
  800. LocationCode += "-" + dr["货架"].ToString().ToUpper();
  801. LocationName += dr["货架"].ToString().ToUpper() + "货架";
  802. }
  803. if (!string.IsNullOrWhiteSpace(dr["层"].ToString().ToUpper()))
  804. {
  805. LocationCode += "-" + dr["层"].ToString().ToUpper();
  806. LocationName += dr["层"].ToString().ToUpper() + "层";
  807. }
  808. if (!string.IsNullOrWhiteSpace(dr["格"].ToString().ToUpper()))
  809. {
  810. LocationCode += "-" + dr["格"].ToString().ToUpper();
  811. LocationName += dr["格"].ToString().ToUpper() + "格";
  812. }
  813. dr_["LocationCode"] = LocationCode;
  814. dr_["LocationName"] = LocationName;
  815. dr_["Musername"] = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  816. dr_["MUSER"] = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  817. dr_["Musername"] = "";
  818. dbdata.Rows.Add(dr_);
  819. }
  820. SqlHelper.RemoveEmpty(dbdata);
  821. SqlHelper.SqlBulkCopyByDatatable( "ICSLocation", dbdata);
  822. return View();
  823. }
  824. //周转箱导入
  825. [HttpPost]
  826. /// <summary>
  827. /// 文件上传到本地
  828. /// </summary>
  829. public string UploadFile()
  830. {
  831. try
  832. {
  833. HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files;
  834. if (hpFiles != null && hpFiles.Count > 0)
  835. {
  836. string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
  837. if (IsXls != ".xls" && IsXls != ".xlsx")
  838. {
  839. return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
  840. }
  841. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Guid.NewGuid() + IsXls; //获取Execle文件名 DateTime日期函数
  842. string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
  843. int iLen = hpFiles[0].ContentLength;
  844. if (Directory.Exists(savePath)) return "文件已存在";
  845. byte[] bData = new byte[iLen];
  846. hpFiles[0].InputStream.Read(bData, 0, iLen);
  847. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  848. newFile.Write(bData, 0, bData.Length);
  849. newFile.Flush();
  850. int _FileSizeTemp = hpFiles[0].ContentLength;
  851. newFile.Close();
  852. newFile.Dispose();
  853. //bool del = false;
  854. string mess = "";
  855. mess = App.SetDataBoxes(savePath);
  856. if (System.IO.File.Exists(savePath))//删除文件
  857. {
  858. System.IO.File.Delete(savePath);
  859. }
  860. return mess;
  861. }
  862. else
  863. {
  864. return "获取文件失败";
  865. }
  866. }
  867. catch (Exception ex)
  868. {
  869. return ex.ToString();
  870. }
  871. }
  872. //周转箱台账导入
  873. [HttpPost]
  874. /// <summary>
  875. /// 文件上传到本地
  876. /// </summary>
  877. public string UploadBoxAccountFile()
  878. {
  879. try
  880. {
  881. HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files;
  882. if (hpFiles != null && hpFiles.Count > 0)
  883. {
  884. string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
  885. if (IsXls != ".xls" && IsXls != ".xlsx")
  886. {
  887. return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
  888. }
  889. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Guid.NewGuid() + IsXls; //获取Execle文件名 DateTime日期函数
  890. string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
  891. int iLen = hpFiles[0].ContentLength;
  892. if (Directory.Exists(savePath)) return "文件已存在";
  893. byte[] bData = new byte[iLen];
  894. hpFiles[0].InputStream.Read(bData, 0, iLen);
  895. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  896. newFile.Write(bData, 0, bData.Length);
  897. newFile.Flush();
  898. int _FileSizeTemp = hpFiles[0].ContentLength;
  899. newFile.Close();
  900. newFile.Dispose();
  901. //bool del = false;
  902. string mess = "";
  903. mess = App.SetDataBoxAccount(savePath);
  904. if (System.IO.File.Exists(savePath))//删除文件
  905. {
  906. System.IO.File.Delete(savePath);
  907. }
  908. return mess;
  909. }
  910. else
  911. {
  912. return "获取文件失败";
  913. }
  914. }
  915. catch (Exception ex)
  916. {
  917. return ex.ToString();
  918. }
  919. }
  920. //模具档案导入
  921. [HttpPost]
  922. /// <summary>
  923. /// 文件上传到本地
  924. /// </summary>
  925. public string UploadMouldFile()
  926. {
  927. try
  928. {
  929. HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files;
  930. if (hpFiles != null && hpFiles.Count > 0)
  931. {
  932. string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
  933. if (IsXls != ".xls" && IsXls != ".xlsx")
  934. {
  935. return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
  936. }
  937. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Guid.NewGuid() + IsXls; //获取Execle文件名 DateTime日期函数
  938. string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
  939. int iLen = hpFiles[0].ContentLength;
  940. if (Directory.Exists(savePath)) return "文件已存在";
  941. byte[] bData = new byte[iLen];
  942. hpFiles[0].InputStream.Read(bData, 0, iLen);
  943. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  944. newFile.Write(bData, 0, bData.Length);
  945. newFile.Flush();
  946. int _FileSizeTemp = hpFiles[0].ContentLength;
  947. newFile.Close();
  948. newFile.Dispose();
  949. //bool del = false;
  950. string mess = "";
  951. mess = App.SetDataMould(savePath);
  952. if (System.IO.File.Exists(savePath))//删除文件
  953. {
  954. System.IO.File.Delete(savePath);
  955. }
  956. return mess;
  957. }
  958. else
  959. {
  960. return "获取文件失败";
  961. }
  962. }
  963. catch (Exception ex)
  964. {
  965. return ex.ToString();
  966. }
  967. }
  968. //模具台账导入
  969. [HttpPost]
  970. /// <summary>
  971. /// 文件上传到本地
  972. /// </summary>
  973. public string UploadMouldAccountFile()
  974. {
  975. try
  976. {
  977. HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files;
  978. if (hpFiles != null && hpFiles.Count > 0)
  979. {
  980. string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
  981. if (IsXls != ".xls" && IsXls != ".xlsx")
  982. {
  983. return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
  984. }
  985. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Guid.NewGuid() + IsXls; //获取Execle文件名 DateTime日期函数
  986. string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
  987. int iLen = hpFiles[0].ContentLength;
  988. if (Directory.Exists(savePath)) return "文件已存在";
  989. byte[] bData = new byte[iLen];
  990. hpFiles[0].InputStream.Read(bData, 0, iLen);
  991. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  992. newFile.Write(bData, 0, bData.Length);
  993. newFile.Flush();
  994. int _FileSizeTemp = hpFiles[0].ContentLength;
  995. newFile.Close();
  996. newFile.Dispose();
  997. //bool del = false;
  998. string mess = "";
  999. mess = App.SetDataMouldAccount(savePath);
  1000. if (System.IO.File.Exists(savePath))//删除文件
  1001. {
  1002. System.IO.File.Delete(savePath);
  1003. }
  1004. return mess;
  1005. }
  1006. else
  1007. {
  1008. return "获取文件失败";
  1009. }
  1010. }
  1011. catch (Exception ex)
  1012. {
  1013. return ex.ToString();
  1014. }
  1015. }
  1016. [HttpPost]
  1017. public ActionResult UpLoadFileImport()
  1018. {
  1019. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1020. string fileName = "";
  1021. //获取上传的文件集合
  1022. try
  1023. {
  1024. //上传图片格式数组声明
  1025. string[] fileter = new string[] { ".jpg", ".png", ".jpeg" };
  1026. HttpFileCollection httpFile = System.Web.HttpContext.Current.Request.Files;
  1027. for (int i = 0; i < httpFile.Count; i++)
  1028. {
  1029. //上传文件后缀
  1030. string fileSuffix = httpFile[i].FileName.Substring(httpFile[i].FileName.LastIndexOf(".")).ToLower();
  1031. //保存图片名称以时间格式
  1032. fileName = DateTime.Now.ToString("yyyyMMddhhmmssms") + fileSuffix;
  1033. //string fileName = Path.GetFileNameWithoutExtension(httpFile[i].FileName)
  1034. // + Path.GetExtension(httpFile[i].FileName);
  1035. string Paths = System.Web.HttpContext.Current.Server.MapPath("~\\File\\Picture\\");
  1036. if (!fileter.Contains(fileSuffix))
  1037. {
  1038. return Error("上传失败,请上传后缀名为.jpg、.png、.jpeg的图片");
  1039. }
  1040. if (httpFile[i].ContentLength > 2097152)
  1041. {
  1042. return Error("上传失败,上传图片过大");
  1043. }
  1044. if (!Directory.Exists(Paths))
  1045. {
  1046. Directory.CreateDirectory(Paths);
  1047. }
  1048. var filePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\Picture\\" + fileName);
  1049. int iLen = httpFile[0].ContentLength;
  1050. byte[] bData = new byte[iLen];
  1051. httpFile[0].InputStream.Read(bData, 0, iLen);
  1052. FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate);
  1053. fs.Write(bData, 0, bData.Length);
  1054. fs.Flush();
  1055. fs.Close();
  1056. fs.Dispose();
  1057. }
  1058. return Success("上传成功!", fileName);
  1059. }
  1060. catch (Exception ex)
  1061. {
  1062. return Error(ex.Message);
  1063. }
  1064. }
  1065. //新增标签数据源
  1066. [HttpPost]
  1067. [HandlerAjaxOnly]
  1068. public ActionResult CreateLableDataSource( string Sys_LableDataSource)
  1069. {
  1070. string msg = App.CreateLableDataSource(Sys_LableDataSource);
  1071. if (!string.IsNullOrEmpty(msg))
  1072. {
  1073. return Error(msg);
  1074. }
  1075. else
  1076. {
  1077. return Success("添加成功!");
  1078. }
  1079. }
  1080. [HttpGet]
  1081. [HandlerAjaxOnly]
  1082. public ActionResult GetTXT(string ID)
  1083. {
  1084. DataTable ListData = App.GetTXT(ID);
  1085. var JsonData = new
  1086. {
  1087. rows = ListData,
  1088. };
  1089. return Content(JsonData.ToJson());
  1090. }
  1091. //修改标签数据源
  1092. [HttpPost]
  1093. [HandlerAjaxOnly]
  1094. public ActionResult updateLableDataSource(string Sys_LableDataSource)
  1095. {
  1096. string msg = App.updateLableDataSource(Sys_LableDataSource);
  1097. if (!string.IsNullOrEmpty(msg))
  1098. {
  1099. return Error(msg);
  1100. }
  1101. else
  1102. {
  1103. return Success("添加成功!");
  1104. }
  1105. }
  1106. [HttpPost]
  1107. [HandlerAjaxOnly]
  1108. [ValidateAntiForgeryToken]
  1109. public ActionResult DeleteLableDataSource(string keyValue)
  1110. {
  1111. string msg = App.DeleteLableDataSource(keyValue);
  1112. if (string.IsNullOrEmpty(msg))
  1113. {
  1114. return Success("删除成功!");
  1115. }
  1116. else
  1117. {
  1118. return Error(msg);
  1119. }
  1120. }
  1121. [HttpGet]
  1122. [HandlerAjaxOnly]
  1123. public ActionResult GetLableType()
  1124. {
  1125. DataTable dt = App.GetLableType();
  1126. return Content(dt.ToJson());
  1127. }
  1128. [HttpGet]
  1129. [HandlerAjaxOnly]
  1130. public ActionResult GetSys_LablesID()
  1131. {
  1132. DataTable dt = App.GetSys_LablesID();
  1133. return Content(dt.ToJson());
  1134. }
  1135. //新增标签数据源
  1136. [HttpPost]
  1137. [HandlerAjaxOnly]
  1138. public ActionResult CreateLables(string txtLableName,string sel_LableType, string sel_LableSourceID )
  1139. {
  1140. string msg = App.CreateLables(txtLableName, sel_LableType, sel_LableSourceID);
  1141. if (!string.IsNullOrEmpty(msg))
  1142. {
  1143. return Error(msg);
  1144. }
  1145. else
  1146. {
  1147. return Success("添加成功!");
  1148. }
  1149. }
  1150. [HttpGet]
  1151. [HandlerAjaxOnly]
  1152. public ActionResult GetLabelTXT(string ID)
  1153. {
  1154. DataTable ListData = App.GetLabelTXT(ID);
  1155. var JsonData = new
  1156. {
  1157. rows = ListData,
  1158. };
  1159. return Content(JsonData.ToJson());
  1160. }
  1161. [HttpPost]
  1162. [HandlerAjaxOnly]
  1163. public ActionResult updateLables(string ID,string txtLableName, string sel_LableType, string sel_LableSourceID)
  1164. {
  1165. string msg = App.updateLables(ID,txtLableName, sel_LableType, sel_LableSourceID);
  1166. if (!string.IsNullOrEmpty(msg))
  1167. {
  1168. return Error(msg);
  1169. }
  1170. else
  1171. {
  1172. return Success("修改成功!");
  1173. }
  1174. }
  1175. [HttpPost]
  1176. [HandlerAjaxOnly]
  1177. [ValidateAntiForgeryToken]
  1178. public ActionResult DeleteICSLabelTemplate(string keyValue)
  1179. {
  1180. string msg = App.DeleteICSLabelTemplate(keyValue);
  1181. if (string.IsNullOrEmpty(msg))
  1182. {
  1183. return Success("删除成功!");
  1184. }
  1185. else
  1186. {
  1187. return Error(msg);
  1188. }
  1189. }
  1190. //获取父容器
  1191. [HttpGet]
  1192. [HandlerAjaxOnly]
  1193. public ActionResult GetContainerID()
  1194. {
  1195. DataTable dt = App.GetContainerID();
  1196. return Content(dt.ToJson());
  1197. }
  1198. //获取父容器
  1199. [HttpGet]
  1200. [HandlerAjaxOnly]
  1201. public ActionResult GetContainerType()
  1202. {
  1203. DataTable dt = App.GetContainerType();
  1204. return Content(dt.ToJson());
  1205. }
  1206. [HttpPost]
  1207. public ActionResult UpLoadLabelFile()
  1208. {
  1209. //获取上传的文件集合
  1210. HttpFileCollection httpFile = System.Web.HttpContext.Current.Request.Files;
  1211. //获取送货单号
  1212. string ID = Request.Form["ID"].ToString();
  1213. string LableName = Request.Form["LableName"].ToString();
  1214. string fileName = Path.GetFileNameWithoutExtension(httpFile[0].FileName)
  1215. + "_" + LableName + Path.GetExtension(httpFile[0].FileName);
  1216. string filePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\LablesFile\\" + fileName);
  1217. int iLen = httpFile[0].ContentLength;
  1218. byte[] bData = new byte[iLen];
  1219. httpFile[0].InputStream.Read(bData, 0, iLen);
  1220. FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate);
  1221. fs.Write(bData, 0, bData.Length);
  1222. fs.Flush();
  1223. fs.Close();
  1224. fs.Dispose();
  1225. int count = App.UpLoadLabelFile(ID, fileName);
  1226. if (count > 0)
  1227. {
  1228. return Success("上传成功!");
  1229. }
  1230. else
  1231. {
  1232. return Error("上传失败");
  1233. }
  1234. }
  1235. [HttpPost]
  1236. public ActionResult UpLoadFileTxT()
  1237. {
  1238. //获取上传的文件集合
  1239. HttpFileCollection httpFile = System.Web.HttpContext.Current.Request.Files;
  1240. //获取送货单号
  1241. string LotNo = Request.Form["LotNo"].ToString();
  1242. string fileName = Path.GetFileNameWithoutExtension(httpFile[0].FileName)
  1243. + Path.GetExtension(httpFile[0].FileName);
  1244. string filePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + fileName);
  1245. int iLen = httpFile[0].ContentLength;
  1246. byte[] bData = new byte[iLen];
  1247. httpFile[0].InputStream.Read(bData, 0, iLen);
  1248. FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate);
  1249. fs.Write(bData, 0, bData.Length);
  1250. fs.Flush();
  1251. fs.Close();
  1252. fs.Dispose();
  1253. int count = App.UpLoadFiles(LotNo, fileName);
  1254. if (count > 0)
  1255. {
  1256. return Success("上传成功!");
  1257. }
  1258. else
  1259. {
  1260. return Error("上传失败");
  1261. }
  1262. }
  1263. //料品不良组导入
  1264. [HttpPost]
  1265. /// <summary>
  1266. /// 文件上传到本地
  1267. /// </summary>
  1268. public string UploadFileInvBadGroup()
  1269. {
  1270. try
  1271. {
  1272. HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files;
  1273. if (hpFiles != null && hpFiles.Count > 0)
  1274. {
  1275. string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
  1276. if (IsXls != ".xls" && IsXls != ".xlsx")
  1277. {
  1278. return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
  1279. }
  1280. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Guid.NewGuid() + IsXls; //获取Execle文件名 DateTime日期函数
  1281. string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
  1282. int iLen = hpFiles[0].ContentLength;
  1283. if (Directory.Exists(savePath)) return "文件已存在";
  1284. byte[] bData = new byte[iLen];
  1285. hpFiles[0].InputStream.Read(bData, 0, iLen);
  1286. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  1287. newFile.Write(bData, 0, bData.Length);
  1288. newFile.Flush();
  1289. int _FileSizeTemp = hpFiles[0].ContentLength;
  1290. newFile.Close();
  1291. newFile.Dispose();
  1292. //bool del = false;
  1293. string mess = "";
  1294. mess = App.UploadFileInvBadGroup(savePath);
  1295. if (System.IO.File.Exists(savePath))//删除文件
  1296. {
  1297. System.IO.File.Delete(savePath);
  1298. }
  1299. return mess;
  1300. }
  1301. else
  1302. {
  1303. return "获取文件失败";
  1304. }
  1305. }
  1306. catch (Exception ex)
  1307. {
  1308. return ex.ToString();
  1309. }
  1310. }
  1311. //根据ID获取其他站点
  1312. public ActionResult GetWorkPointNotInID(string WorkPointCode)
  1313. {
  1314. DataTable dt = App.GetWorkPointNotInID(WorkPointCode);
  1315. return Content(dt.ToJson());
  1316. }
  1317. //克隆站点
  1318. [HttpPost]
  1319. [HandlerAjaxOnly]
  1320. public ActionResult CloneWorkPointByCode(string WorkPoint, string WorkPointCode)
  1321. {
  1322. string msg = App.CloneWorkPointByCode(WorkPoint, WorkPointCode);
  1323. if (!string.IsNullOrEmpty(msg))
  1324. {
  1325. return Error(msg);
  1326. }
  1327. else
  1328. {
  1329. return Success("修改成功!");
  1330. }
  1331. }
  1332. [HttpPost]
  1333. [HandlerAjaxOnly]
  1334. public ActionResult DeleteTableByCode(string TableCode)
  1335. {
  1336. string msg = App.DeleteTableByCode(TableCode);
  1337. if (!string.IsNullOrEmpty(msg))
  1338. {
  1339. return Error(msg);
  1340. }
  1341. else
  1342. {
  1343. return Success("添加成功!");
  1344. }
  1345. }
  1346. }
  1347. }