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.
|
|
using NFine.Application.PNWMS;using NFine.Code;using NFine.Data.Extensions;using System;using System.Collections.Generic;using System.Data;using System.Data.SqlClient;using System.IO;using System.Linq;using System.Web;using System.Web.Mvc;
namespace NFine.Web.Areas.PNWMS.Controllers{ public class BasicSettingsController : ControllerBase { BasicSettingsApp App = new BasicSettingsApp(); // GET: PNWMS/BasicSettings
public ActionResult ICSStackWMS() { return View(); } public ActionResult ICSStackWMSAdd() { return View(); }
/// <summary>
/// 删除库位
/// </summary>
/// <returns></returns>
[HttpPost] [HandlerAjaxOnly] [ValidateAntiForgeryToken] public ActionResult DeleteStack(string keyValue) { string msg = App.DeleteStack(keyValue); if (string.IsNullOrEmpty(msg)) { return Success("删除成功!"); } else { return Error(msg); //throw new Exception(msg);
} }
//库位导入
[HttpPost] /// <summary>
/// 文件上传到本地
/// </summary>
public string UploadFile() { 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); if (System.IO.File.Exists(savePath))//删除文件
{
System.IO.File.Delete(savePath); } return mess;
} else { return "获取文件失败"; } } catch (Exception ex) {
return ex.ToString(); } }
/// <summary>
/// 导入Excel
/// </summary>
/// <param name="fileURL"></param>
/// <returns></returns>
[HttpPost] public ActionResult Import(string fileURL) { var fileName = ""; var filePath = fileURL; string path = Path.Combine(filePath, fileName); //file.SaveAs(path);
DataTable excelTable = new DataTable(); //excelTable =SqlHelper.GetExcelDataTable(path);
DataTable dbdata = new DataTable(); dbdata.Columns.Add("LocationCode"); dbdata.Columns.Add("LocationName"); dbdata.Columns.Add("Musername"); dbdata.Columns.Add("MUSER"); dbdata.Columns.Add("EATTRIBUTE1"); for (int i = 0; i < excelTable.Rows.Count; i++) { string LocationCode = ""; string LocationName = ""; DataRow dr = excelTable.Rows[i]; DataRow dr_ = dbdata.NewRow(); if (!string.IsNullOrWhiteSpace(dr["区"].ToString().ToUpper())) { LocationCode += "-" + dr["区"].ToString().ToUpper(); LocationName += dr["区"].ToString().ToUpper() + "区"; } if (!string.IsNullOrWhiteSpace(dr["排"].ToString().ToUpper())) { LocationCode += "-" + dr["排"].ToString().ToUpper(); LocationName += dr["排"].ToString().ToUpper() + "排"; } if (!string.IsNullOrWhiteSpace(dr["货架"].ToString().ToUpper())) { LocationCode += "-" + dr["货架"].ToString().ToUpper(); LocationName += dr["货架"].ToString().ToUpper() + "货架"; } if (!string.IsNullOrWhiteSpace(dr["层"].ToString().ToUpper())) { LocationCode += "-" + dr["层"].ToString().ToUpper(); LocationName += dr["层"].ToString().ToUpper() + "层"; } if (!string.IsNullOrWhiteSpace(dr["格"].ToString().ToUpper())) { LocationCode += "-" + dr["格"].ToString().ToUpper(); LocationName += dr["格"].ToString().ToUpper() + "格"; } dr_["LocationCode"] = LocationCode; dr_["LocationName"] = LocationName; dr_["Musername"] = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; dr_["MUSER"] = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; dr_["Musername"] = ""; dbdata.Rows.Add(dr_); } SqlHelper.RemoveEmpty(dbdata); SqlHelper.SqlBulkCopyByDatatable("ICSLocation", dbdata);
return View(); }
/// <summary>
/// 获取库位信息
/// </summary>
/// <returns></returns>
public ActionResult GetWarehouse() { DataTable dt = App.GetWarehouse(); return Content(dt.ToJson()); }
[HttpPost] [HandlerAjaxOnly] public ActionResult UpdateStack(string keyValue) { string msg = App.UpdateStack(keyValue); if (!string.IsNullOrEmpty(msg)) { return Error(msg); } else { return Success("修改成功!"); } }
[HttpPost] [HandlerAjaxOnly] public ActionResult InsertStack(string keyValue) { string msg = App.InsertStack(keyValue); if (!string.IsNullOrEmpty(msg)) { return Error(msg); } else { return Success("添加成功!"); } }
}}
|