using BLL;
|
using Common;
|
using Model;
|
using System.Collections.Generic;
|
using System.Linq;
|
using Lib;
|
using System.Web.Mvc;
|
using FastReport.Web;
|
using System.Data;
|
using System.Web;
|
using System;
|
using NPOI.SS.UserModel;
|
using NPOI.HSSF.UserModel;
|
using System.IO;
|
using NPOI.XSSF.UserModel;
|
|
namespace WMS.Areas.Business.Controllers
|
{
|
public class ErpOutController : MasterPage
|
{
|
// GET: Business/ErpOut
|
[LoginFilter]
|
public ActionResult Index()
|
{
|
ViewBag.StatuList = LocalHelper.GetDictionaryCodeHtml("CDStatu");
|
//ViewBag.AccessCode = LocalHelper.GetDictionaryCodeHtml("Access", this.LoginAccessCode);
|
ViewBag.AccessCode = LocalHelper.GetDictionaryCodeHtml("Access");
|
ViewBag.Title = "出库单管理";
|
return View();
|
}
|
|
[LoginFilter]
|
public ActionResult SetErpOutDetail()
|
{
|
string ordNo = Request.QueryString.Get("OrdNo");
|
Session["TEMPDATA_CACHE_ERPOUTPRODUCT"] = null;
|
if (string.IsNullOrEmpty(ordNo))
|
{
|
ViewBag.Admin = new ErpOut();
|
}
|
else
|
{
|
// 编辑出库单
|
IDALErpOut provider = new DALErpOut();
|
IList<StorePalno> erpMats = new List<StorePalno>();
|
ErpOut entity = provider.GetModel(ordNo, ref erpMats);
|
Session["TEMPDATA_CACHE_ERPOUTPRODUCT"] = erpMats;
|
entity = entity == null ? new ErpOut() : entity;
|
ViewBag.OrdTypeList = LocalHelper.GetOrdTypeList(entity.OrdType);
|
ViewBag.Admin = entity;
|
}
|
ViewBag.AccessCode = LocalHelper.GetDictionaryCodeHtml("Access", this.LoginAccessCode);
|
return View();
|
}
|
|
|
|
|
|
public ActionResult Add()
|
{
|
string OrdNo = Request.QueryString.Get("OrdNo");
|
Session["TEMPDATA_CACHE_ERPOUTPRODUCT"] = null;
|
if (string.IsNullOrEmpty(OrdNo))
|
{
|
ViewBag.Admin = new ErpOut();
|
ViewBag.OrdTypeList = LocalHelper.GetOrdTypeList(string.Empty);
|
}
|
else
|
{
|
IDALErpOut provider = new DALErpOut();
|
IList<StorePalno> erpMats = new List<StorePalno>();
|
ErpOut entity = provider.GetModel(OrdNo, ref erpMats);
|
Session["TEMPDATA_CACHE_ERPOUTPRODUCT"] = erpMats;
|
entity = entity == null ? new ErpOut() : entity;
|
ViewBag.OrdTypeList = LocalHelper.GetOrdTypeList(entity.OrdType);
|
ViewBag.Admin = entity;
|
}
|
|
return View();
|
}
|
public ActionResult AddProduct()
|
{
|
string MatNo = Request.QueryString.Get("MatNo");
|
string palno = Request.QueryString.Get("palno");
|
string Certificate = Request.QueryString.Get("Certificate");
|
if (MatNo.IsEmpty())
|
{
|
ViewBag.Admin = new StorePalno();
|
}
|
else
|
{
|
List<StorePalno> list = Session["TEMPDATA_CACHE_ERPOUTPRODUCT"] as List<StorePalno>;
|
List<StorePalno> list1 = new List<StorePalno>();
|
if (palno == "")
|
{
|
list1 = list.Where(a => a.MatNo == MatNo && a.Palno == null).ToList<StorePalno>();
|
if (list1.Count <= 0)
|
{//lijiangang修改:增加合格证Certificate条件
|
list1 = list.Where(a => a.MatNo == MatNo && a.Palno == "" && a.Certificate == Certificate).ToList<StorePalno>();
|
}
|
}
|
else
|
{//lijiangang修改:增加合格证Certificate条件
|
list1 = list.Where(a => a.MatNo == MatNo && a.Palno == palno && a.Certificate == Certificate).ToList<StorePalno>();
|
if (list1.Count == 0)
|
{
|
list1 = list.Where(a => a.MatNo == MatNo && a.Palno == palno && a.Certificate == null).ToList<StorePalno>();
|
}
|
}
|
DALErpOut provider = new DALErpOut();
|
//lijiangang修改:增加合格证Certificate条件
|
list1[0].Quant = provider.GetLogStore(MatNo, palno, Certificate);
|
ViewBag.Admin = list1[0];
|
}
|
return View();
|
}
|
|
public ActionResult Detail(string OrdNo)
|
{
|
if (!string.IsNullOrEmpty(OrdNo))
|
{
|
IDALErpOut provider = new DALErpOut();
|
ErpOut entity = provider.GetModel(OrdNo);
|
entity = entity == null ? new ErpOut() : entity;
|
ViewBag.Admin = entity;
|
}
|
return View();
|
}
|
|
public ActionResult ReportShow()
|
{
|
string ReportNo = Request["ReportNo"];
|
string OrdNo = Request["OrdNo"];
|
|
string[] ordNos = new string[] { OrdNo };
|
//点击打印更改状态为正在执行
|
//IDALErpOut dalErpin = new DALErpOut();
|
//bool result = dalErpin.UpdateClose(ordNos, "ER02");
|
//if (!result) { return Content(null); }
|
|
WebReport webReport = new WebReport();
|
webReport.Width = System.Web.UI.WebControls.Unit.Percentage(100);
|
webReport.Height = 600;
|
webReport.ToolbarIconsStyle = ToolbarIconsStyle.Black;
|
webReport.ToolbarIconsStyle = ToolbarIconsStyle.Black;
|
|
webReport.PrintInBrowser = false;
|
webReport.PrintInPdf = false;
|
webReport.ShowExports = false;
|
webReport.SinglePage = false;
|
//webReport.ToolbarStyle = ToolbarStyle.Small;
|
webReport.PrintInPdf = true;
|
webReport.ShowPrint = true;
|
webReport.PreviewMode = true;
|
|
DataSet ds = null;
|
|
if (ReportNo.IndexOf("采购单") >= 0)
|
{
|
ReportNo = "采购单2";
|
IDALPurchase purchase = new DALPurchase();
|
ds = purchase.GetPrintData(OrdNo);
|
}
|
else if (ReportNo.IndexOf("入库单") >= 0)
|
{
|
ReportNo = "入库单";
|
//ReportNo = "采购单2";
|
DALErpIn purchase = new DALErpIn();
|
ds = purchase.GetPrintData(OrdNo);
|
}
|
else if (ReportNo.IndexOf("出库单") >= 0)
|
{
|
ReportNo = "出库单";
|
//ReportNo = "采购单2";
|
DALErpOut purchase = new DALErpOut();
|
ds = purchase.GetPrintData(OrdNo);
|
}
|
|
//ds = new ReportProvider().GetDataSource(entity, list, orderType, orderNum);
|
string path = "~/Report/" + ReportNo + ".frx";
|
path = Server.MapPath(path);
|
//if (!Directory.Exists(path))
|
//{
|
// string template = Server.MapPath("~Report/Report.frx");
|
// System.IO.File.Copy(template, path, true);
|
//}
|
webReport.Report.Load(path);
|
if (ds != null && ds.Tables != null && ds.Tables.Count > 0)
|
{
|
webReport.Report.RegisterData(ds);
|
for (int i = 0; i < ds.Tables.Count; i++)
|
{
|
webReport.Report.GetDataSource(ds.Tables[i].TableName).Enabled = true;
|
}
|
}
|
webReport.ID = ReportNo;
|
ViewBag.WebReport = webReport;
|
|
return View();
|
|
}
|
/// <summary>
|
/// 导入Excel
|
/// </summary>
|
/// <param name="file"></param>
|
/// <returns></returns>
|
[HttpPost]
|
public JsonResult ExcelToUpload(HttpPostedFileBase file)
|
{
|
DataTable excelTable = new DataTable();
|
string msg = string.Empty;
|
if (Request.Files.Count > 0)
|
{
|
try
|
{
|
HttpPostedFileBase mypost = Request.Files[0];
|
string fileName = Request.Files[0].FileName;
|
//在文件夹Report 用来接收上传的文件
|
string serverpath = Server.MapPath(string.Format("~/{0}", "Report/") + fileName);
|
mypost.SaveAs(serverpath);
|
// excelTable = GetExcelDataTable(serverpath);
|
NPOIExcel nPOI = new NPOIExcel("", "", "");
|
excelTable = NPOIExcel.InputExcel(serverpath);
|
//删除服务器生成的文件
|
System.IO.File.Delete(serverpath);
|
//注意Excel表内容格式,第一行必须为列名与数据库列名匹配
|
//接下来为各列名对应下来的内容
|
string CreateUser = this.LoginUserCode;
|
msg = DALErpOut.ImportExcel(excelTable, CreateUser);// 写入基础数据
|
|
}
|
catch (Exception ex)
|
{
|
msg = ex.Message;
|
}
|
}
|
else
|
{
|
msg = "请选择文件";
|
}
|
return Json(msg);
|
}
|
public static DataTable GetExcelDataTable(string filePath)
|
{
|
IWorkbook Workbook;
|
DataTable table = new DataTable();
|
try
|
{
|
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
{
|
|
//XSSFWorkbook 适用XLSX格式,HSSFWorkbook 适用XLS格式
|
string fileExt = System.IO.Path.GetExtension(filePath).ToLower();
|
|
if (fileExt == ".xls")
|
{
|
Workbook = new HSSFWorkbook(fileStream);
|
}
|
else if (fileExt == ".xlsx")
|
{
|
|
Workbook = new XSSFWorkbook(fileStream);
|
}
|
else
|
{
|
Workbook = null;
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
|
//定位在第一个sheet
|
ISheet sheet = Workbook.GetSheetAt(0);
|
//第一行为标题行
|
IRow headerRow = sheet.GetRow(0);
|
int cellCount = headerRow.LastCellNum;
|
int rowCount = sheet.LastRowNum;
|
|
//循环添加标题列
|
for (int i = headerRow.FirstCellNum; i < cellCount; i++)
|
{
|
DataColumn column = new DataColumn(headerRow.GetCell(i).StringCellValue);
|
table.Columns.Add(column);
|
|
|
}
|
|
//数据
|
for (int i = (sheet.FirstRowNum + 1); i <= rowCount; i++)
|
{
|
IRow row = sheet.GetRow(i);
|
DataRow dataRow = table.NewRow();
|
if (row != null)
|
{
|
for (int j = row.FirstCellNum; j < cellCount; j++)
|
{
|
if (row.GetCell(j) != null)
|
{
|
dataRow[j] = GetCellValue(row.GetCell(j));
|
}
|
}
|
}
|
table.Rows.Add(dataRow);
|
}
|
return table;
|
}
|
|
private static string GetCellValue(ICell cell)
|
{
|
if (cell == null)
|
{
|
return string.Empty;
|
}
|
|
switch (cell.CellType)
|
{
|
case CellType.Blank:
|
return string.Empty;
|
case CellType.Boolean:
|
return cell.BooleanCellValue.ToString();
|
case CellType.Error:
|
return cell.ErrorCellValue.ToString();
|
case CellType.Numeric:
|
case CellType.Unknown:
|
default:
|
return cell.ToString();
|
case CellType.String:
|
return cell.StringCellValue;
|
case CellType.Formula:
|
try
|
{
|
HSSFFormulaEvaluator e = new HSSFFormulaEvaluator(cell.Sheet.Workbook);
|
e.EvaluateInCell(cell);
|
return cell.ToString();
|
}
|
catch
|
{
|
return cell.NumericCellValue.ToString();
|
}
|
}
|
}
|
}
|
}
|