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.

285 lines
9.4 KiB

3 weeks ago
  1. using NFine.Application.WMS;
  2. using NFine.Code;
  3. using NFine.Data.Extensions;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Dynamic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Web;
  12. using System.Web.Mvc;
  13. namespace NFine.Web.Areas.WMS.Controllers
  14. {
  15. public class IntelligentDeviceIntegrationController : ControllerBase
  16. {
  17. IntelligentDeviceIntegrationApp App = new IntelligentDeviceIntegrationApp();
  18. // GET: WMS/IntelligentDeviceIntegration
  19. public ActionResult RegionalMaxNum()
  20. {
  21. return View();
  22. }
  23. public ActionResult RegionalMaxNumAdd()
  24. {
  25. return View();
  26. }
  27. public ActionResult LocationBindingCoordinate()
  28. {
  29. return View();
  30. }
  31. public ActionResult LocationBindingCoordinateAdd()
  32. {
  33. return View();
  34. }
  35. public ActionResult AGVKanBan()
  36. {
  37. return View();
  38. }
  39. //获取仓库
  40. [HttpGet]
  41. [HandlerAjaxOnly]
  42. public ActionResult GetWarehouseID()
  43. {
  44. DataTable dt = App.GetWarehouseID();
  45. return Content(dt.ToJson());
  46. }
  47. //根据仓库获取区域
  48. [HttpGet]
  49. [HandlerAjaxOnly]
  50. public ActionResult GetRegion(string WHID)
  51. {
  52. DataTable dt = App.GetRegion(WHID);
  53. return Content(dt.ToJson());
  54. }
  55. [HttpPost]
  56. [HandlerAjaxOnly]
  57. public ActionResult OperateICSCoordinate(string keyValue)
  58. {
  59. string msg = App.OperateICSCoordinate(keyValue);
  60. if (!string.IsNullOrEmpty(msg))
  61. {
  62. return Error(msg);
  63. }
  64. else
  65. {
  66. return Success("操作成功!");
  67. }
  68. }
  69. [HttpGet]
  70. [HandlerAjaxOnly]
  71. public ActionResult GetInfo(string ID)
  72. {
  73. DataTable ListData = App.GetInfo(ID);
  74. var JsonData = new
  75. {
  76. rows = ListData,
  77. };
  78. return Content(JsonData.ToJson());
  79. }
  80. [HttpPost]
  81. [HandlerAjaxOnly]
  82. public ActionResult OperateICSCoordinateLandmark(string keyValue)
  83. {
  84. string msg = App.OperateICSCoordinateLandmark(keyValue);
  85. if (!string.IsNullOrEmpty(msg))
  86. {
  87. return Error(msg);
  88. }
  89. else
  90. {
  91. return Success("操作成功!");
  92. }
  93. }
  94. //[HttpPost]
  95. //public JsonResult GetRegionRange(string WHID, string region)
  96. //{
  97. // DataTable ListData = App.GetRegionRange(WHID, region);
  98. // if (ListData.Rows.Count > 0)
  99. // {
  100. // return Json(new { X = ListData.Rows[0]["X"].ToString(), Y = ListData.Rows[0]["Y"].ToString() }, JsonRequestBehavior.AllowGet);
  101. // }
  102. // return Json(new { X = 0, Y = 0 }, JsonRequestBehavior.AllowGet);
  103. //}
  104. //[HttpPost]
  105. //public JsonResult GetLandmarkData(string WHID, string region)
  106. //{
  107. // DataTable ListData = App.GetLandmarkData(WHID, region);
  108. // var result = new List<dynamic>();
  109. // foreach (DataRow row in ListData.Rows)
  110. // {
  111. // dynamic item = new ExpandoObject();
  112. // var dict = (IDictionary<string, object>)item;
  113. // foreach (DataColumn column in ListData.Columns)
  114. // {
  115. // dict[column.ColumnName] = row[column];
  116. // }
  117. // result.Add(item);
  118. // }
  119. // return Json(result, JsonRequestBehavior.AllowGet);
  120. //}
  121. // AJAX接口:根据仓库+区域,获取坐标数据并渲染表格
  122. [HttpPost]
  123. public ActionResult GetWarehouseGrid(string whid, string region)
  124. {
  125. try
  126. {
  127. // 1. 查询 ICSCoordinate,获取 X、Y 最大值
  128. string sql = @"SELECT X, Y FROM dbo.ICSCoordinate WHERE WHID = '"+ whid + "' AND Region = '"+ region + "'";
  129. DataTable coordinateTable = SqlHelper.GetDataTableBySql(sql);
  130. if (coordinateTable.Rows.Count == 0)
  131. {
  132. return Json(new { success = false, message = "未找到该仓库区域的坐标配置" });
  133. }
  134. DataRow coordinateRow = coordinateTable.Rows[0];
  135. int maxX = Convert.ToInt32(coordinateRow["X"]);
  136. int maxY = Convert.ToInt32(coordinateRow["Y"]);
  137. // 2. 查询 ICSCoordinateLandmark,获取库位数据
  138. //string sql2 = @"SELECT cl.X, cl.Y, cl.Landmark, cl.State, cl.LocationID, c.WHID, c.Region
  139. // FROM dbo.ICSCoordinateLandmark cl
  140. // JOIN dbo.ICSCoordinate c ON cl.X <= c.X AND cl.Y <= c.Y
  141. // WHERE WHID = '" + whid + "' AND Region = '" + region + "' ";
  142. string sql2 = @"select a.X, a.Y, a.Landmark, a.State, a.LocationID,c.WHID, c.Region ,d.LotNo,e.InvCode,f.InvName,g.InDate from ICSCoordinateLandmark a
  143. left join dbo.ICSLocation b on a.LocationID=b.ID and a.WorkPoint=b.WorkPoint
  144. left join ICSCoordinate c on b.WHID=c.WHID and b.Region = c.Region and a.WorkPoint=c.WorkPoint
  145. left join ICSSmartDevice d on a.LocationID=d.LocationID and b.LocationCode=d.LocationCode and a.WorkPoint=d.WorkPoint
  146. left join dbo.ICSInventoryLot e on d.LotNo=e.LotNo and a.WorkPoint=e.WorkPoint
  147. left join dbo.ICSInventory f on e.InvCode=f.InvCode and a.WorkPoint=f.WorkPoint
  148. left join dbo.ICSWareHouseLotInfo g on e.LotNo=g.LotNo and a.WorkPoint=g.WorkPoint
  149. WHERE c.WHID = '" + whid + "' AND c.Region = '" + region + "' ";
  150. DataTable landmarkTable = SqlHelper.GetDataTableBySql(sql2);
  151. // 3. 构造返回给前端的数据
  152. var result = new
  153. {
  154. success = true,
  155. maxX = maxX,
  156. maxY = maxY,
  157. landmarks = landmarkTable.AsEnumerable().Select(row => new
  158. {
  159. X = row.Field<int>("X"),
  160. Y = row.Field<int>("Y"),
  161. LotNo = row.Field<string>("LotNo"),
  162. InvCode = row.Field<string>("InvCode"),
  163. InvName = row.Field<string>("InvName"),
  164. InDate = row.IsNull("InDate")
  165. ? null
  166. : row.Field<DateTime>("InDate").ToString("yyyy-MM-dd HH:mm:ss"),
  167. State = row.Field<string>("State")
  168. }).ToList()
  169. };
  170. return Json(result);
  171. }
  172. catch (Exception ex)
  173. {
  174. return Json(new { success = false, message = ex.Message });
  175. }
  176. }
  177. [HttpPost]
  178. /// <summary>
  179. /// 文件上传到本地
  180. /// </summary>
  181. public string UploadFile(string Type)
  182. {
  183. try
  184. {
  185. HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files;
  186. if (hpFiles != null && hpFiles.Count > 0)
  187. {
  188. string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
  189. if (IsXls != ".xls" && IsXls != ".xlsx")
  190. {
  191. return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
  192. }
  193. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Guid.NewGuid() + IsXls; //获取Execle文件名 DateTime日期函数
  194. string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
  195. int iLen = hpFiles[0].ContentLength;
  196. if (Directory.Exists(savePath)) return "文件已存在";
  197. byte[] bData = new byte[iLen];
  198. hpFiles[0].InputStream.Read(bData, 0, iLen);
  199. FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate);
  200. newFile.Write(bData, 0, bData.Length);
  201. newFile.Flush();
  202. int _FileSizeTemp = hpFiles[0].ContentLength;
  203. newFile.Close();
  204. newFile.Dispose();
  205. //bool del = false;
  206. string mess = "";
  207. mess = App.SetData_PR(savePath, Type);
  208. if (System.IO.File.Exists(savePath))//删除文件
  209. {
  210. System.IO.File.Delete(savePath);
  211. }
  212. if (!string.IsNullOrEmpty(mess))
  213. {
  214. mess = "导入失败:" + mess;
  215. }
  216. else
  217. {
  218. mess = "导入成功!";
  219. }
  220. return mess;
  221. }
  222. else
  223. {
  224. return "获取文件失败";
  225. }
  226. }
  227. catch (Exception ex)
  228. {
  229. return ex.ToString();
  230. }
  231. }
  232. }
  233. }