|
|
using NFine.Application.WMS;using NFine.Code;using NFine.Data.Extensions;using System;using System.Collections.Generic;using System.Data;using System.Data.SqlClient;using System.Dynamic;using System.IO;using System.Linq;using System.Web;using System.Web.Mvc;
namespace NFine.Web.Areas.WMS.Controllers{ public class IntelligentDeviceIntegrationController : ControllerBase { IntelligentDeviceIntegrationApp App = new IntelligentDeviceIntegrationApp(); // GET: WMS/IntelligentDeviceIntegration
public ActionResult RegionalMaxNum() { return View(); } public ActionResult RegionalMaxNumAdd() { return View(); } public ActionResult LocationBindingCoordinate() { return View(); } public ActionResult LocationBindingCoordinateAdd() { return View(); } public ActionResult AGVKanBan() { return View(); }
//获取仓库
[HttpGet] [HandlerAjaxOnly] public ActionResult GetWarehouseID() { DataTable dt = App.GetWarehouseID(); return Content(dt.ToJson()); }
//根据仓库获取区域
[HttpGet] [HandlerAjaxOnly] public ActionResult GetRegion(string WHID) { DataTable dt = App.GetRegion(WHID); return Content(dt.ToJson()); }
[HttpPost] [HandlerAjaxOnly] public ActionResult OperateICSCoordinate(string keyValue) { string msg = App.OperateICSCoordinate(keyValue); if (!string.IsNullOrEmpty(msg)) { return Error(msg); } else { return Success("操作成功!"); } }
[HttpGet] [HandlerAjaxOnly] public ActionResult GetInfo(string ID) { DataTable ListData = App.GetInfo(ID); var JsonData = new { rows = ListData, }; return Content(JsonData.ToJson()); }
[HttpPost] [HandlerAjaxOnly] public ActionResult OperateICSCoordinateLandmark(string keyValue) { string msg = App.OperateICSCoordinateLandmark(keyValue); if (!string.IsNullOrEmpty(msg)) { return Error(msg); } else { return Success("操作成功!"); } }
//[HttpPost]
//public JsonResult GetRegionRange(string WHID, string region)
//{
// DataTable ListData = App.GetRegionRange(WHID, region);
// if (ListData.Rows.Count > 0)
// {
// return Json(new { X = ListData.Rows[0]["X"].ToString(), Y = ListData.Rows[0]["Y"].ToString() }, JsonRequestBehavior.AllowGet);
// }
// return Json(new { X = 0, Y = 0 }, JsonRequestBehavior.AllowGet);
//}
//[HttpPost]
//public JsonResult GetLandmarkData(string WHID, string region)
//{
// DataTable ListData = App.GetLandmarkData(WHID, region);
// var result = new List<dynamic>();
// foreach (DataRow row in ListData.Rows)
// {
// dynamic item = new ExpandoObject();
// var dict = (IDictionary<string, object>)item;
// foreach (DataColumn column in ListData.Columns)
// {
// dict[column.ColumnName] = row[column];
// }
// result.Add(item);
// }
// return Json(result, JsonRequestBehavior.AllowGet);
//}
// AJAX接口:根据仓库+区域,获取坐标数据并渲染表格
[HttpPost] public ActionResult GetWarehouseGrid(string whid, string region) { try { // 1. 查询 ICSCoordinate,获取 X、Y 最大值
string sql = @"SELECT X, Y FROM dbo.ICSCoordinate WHERE WHID = '"+ whid + "' AND Region = '"+ region + "'"; DataTable coordinateTable = SqlHelper.GetDataTableBySql(sql); if (coordinateTable.Rows.Count == 0) { return Json(new { success = false, message = "未找到该仓库区域的坐标配置" }); }
DataRow coordinateRow = coordinateTable.Rows[0]; int maxX = Convert.ToInt32(coordinateRow["X"]); int maxY = Convert.ToInt32(coordinateRow["Y"]);
// 2. 查询 ICSCoordinateLandmark,获取库位数据
//string sql2 = @"SELECT cl.X, cl.Y, cl.Landmark, cl.State, cl.LocationID, c.WHID, c.Region
// FROM dbo.ICSCoordinateLandmark cl
// JOIN dbo.ICSCoordinate c ON cl.X <= c.X AND cl.Y <= c.Y
// WHERE WHID = '" + whid + "' AND Region = '" + region + "' ";
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
left join dbo.ICSLocation b on a.LocationID=b.ID and a.WorkPoint=b.WorkPoint left join ICSCoordinate c on b.WHID=c.WHID and b.Region = c.Region and a.WorkPoint=c.WorkPoint left join ICSSmartDevice d on a.LocationID=d.LocationID and b.LocationCode=d.LocationCode and a.WorkPoint=d.WorkPoint left join dbo.ICSInventoryLot e on d.LotNo=e.LotNo and a.WorkPoint=e.WorkPoint left join dbo.ICSInventory f on e.InvCode=f.InvCode and a.WorkPoint=f.WorkPoint left join dbo.ICSWareHouseLotInfo g on e.LotNo=g.LotNo and a.WorkPoint=g.WorkPoint WHERE c.WHID = '" + whid + "' AND c.Region = '" + region + "' ";
DataTable landmarkTable = SqlHelper.GetDataTableBySql(sql2);
// 3. 构造返回给前端的数据
var result = new { success = true, maxX = maxX, maxY = maxY, landmarks = landmarkTable.AsEnumerable().Select(row => new { X = row.Field<int>("X"), Y = row.Field<int>("Y"), LotNo = row.Field<string>("LotNo"), InvCode = row.Field<string>("InvCode"), InvName = row.Field<string>("InvName"), InDate = row.IsNull("InDate") ? null : row.Field<DateTime>("InDate").ToString("yyyy-MM-dd HH:mm:ss"), State = row.Field<string>("State") }).ToList() };
return Json(result); } catch (Exception ex) { return Json(new { success = false, message = ex.Message }); } }
[HttpPost] /// <summary>
/// 文件上传到本地
/// </summary>
public string UploadFile(string Type) { try { HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files; if (hpFiles != null && hpFiles.Count > 0) {
string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名
if (IsXls != ".xls" && IsXls != ".xlsx") {
return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回
} string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Guid.NewGuid() + IsXls; //获取Execle文件名 DateTime日期函数
string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\UPLoadFile\\" + filename);//Server.MapPath 获得虚拟服务器相对路径
int iLen = hpFiles[0].ContentLength; if (Directory.Exists(savePath)) return "文件已存在"; byte[] bData = new byte[iLen]; hpFiles[0].InputStream.Read(bData, 0, iLen);
FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate); newFile.Write(bData, 0, bData.Length); newFile.Flush(); int _FileSizeTemp = hpFiles[0].ContentLength;
newFile.Close(); newFile.Dispose(); //bool del = false;
string mess = ""; mess = App.SetData_PR(savePath, Type); if (System.IO.File.Exists(savePath))//删除文件
{
System.IO.File.Delete(savePath); } if (!string.IsNullOrEmpty(mess)) { mess = "导入失败:" + mess; } else { mess = "导入成功!"; } return mess;
} else { return "获取文件失败"; } } catch (Exception ex) {
return ex.ToString(); } }
}}
|