123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using WMS.Core;
- using WMS.Util;
- using WMS.Info;
- using System.Web;
- using System.Text;
- using WMS.Core.ImportExecl;
- using Microsoft.AspNetCore.Mvc;
- using WMS.BZWeb;
- using System.Net;
- using WMS.BZModels;
- using WMS.BZServices.HJ;
- using WMS.BZUtil;
- using WMS.BZServices;
- //using FastReport.Web;
- //using FastReport;
- namespace WMS.BZWeb.Controllers
- {
- /// <summary>
- /// 描 述:通用控制器,处理通用的接口
- /// </summary>
- //[HandlerLogin(EFilterMode.Ignore)]
- public class UtilityController : MvcControllerBase
- {
- private readonly WarehouseService _warehouseService;
- private readonly AnnexesFileService _annexesFileService;
- private readonly ImportDataOrExcelService _importDataOrExeclService;
- public UtilityController(WarehouseService warehouse, AnnexesFileService annexesFileService, ImportDataOrExcelService importDataOrExeclService)
- {
- _warehouseService = warehouse;
- _annexesFileService = annexesFileService;
- _importDataOrExeclService = importDataOrExeclService;
- }
- AnnexesFileCore AnnexesFile = new AnnexesFileCore();
- /// <summary>
- /// 图标的选择
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- ///[HandlerLogin(EFilterMode.Enforce)]
- public ActionResult Icon()
- {
- return View();
- }
- /// <summary>
- /// 移动图标的选择
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- //[HandlerLogin(EFilterMode.Enforce)]
- public ActionResult AppIcon()
- {
- return View();
- }
- /// <summary>
- /// 导入数据
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- //[HandlerLogin(EFilterMode.Enforce)]
- public ActionResult ImportForm()
- {
- return View();
- }
- /// <summary>
- /// 请选择要导出的字段页面
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- //[HandlerLogin(EFilterMode.Enforce)]
- public ActionResult ExcelExportForm()
- {
- return View();
- }
- [HttpGet]
- public ActionResult ExcelExportColumn()
- {
- return View();
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- //[HttpGet]
- //public ActionResult FastReportIndex(int id)
- //{
- // FastReport.Web.WebReport webReport = new FastReport.Web.WebReport();
- // SetReport(webReport);
- // webReport.Width = "1080";
- // webReport.Height = "925";
- // // webReport.ToolbarIconsStyle = ToolbarIconsStyle.Black;
- // // webReport.LocalizationFile = "~/Localization/German.frl";
- // webReport.EmbedPictures = true;
- // //webReport.XlsxPageBreaks = false;
- // // webReport.XlsxSeamless = true;
- // // webReport.ZoomMode = ZoomMode.Width;
- // //本地化文件 this.Server.MapPath("~/DataFiles/FastReport/") ConfigHelper.GetValue<string>("baseDir")
- // webReport.LocalizationFile = ConfigHelper.GetValue<string>("baseDir") + "/wwwroot/DataFiles/FastReport/Localization/Chinese (Simplified).frl";
- // //webReport.PrintInPdf = false;
- // // fill the parameters on startup
- // //webReport.Report.SetParameterValue("Test parameter 1", "Value of parameter 1 from application code");
- // //webReport.Report.SetParameterValue("parameter2", "1002");
- // ViewBag.WebReport = webReport;
- // return View();
- //}
- //private void SetReport(WebReport webReport)
- //{
- // string report_path = GetReportPath();
- // System.Data.DataSet dataSet = new System.Data.DataSet();
- // dataSet.ReadXml(report_path + "nwind.xml");
- // webReport.Report.Load(Path.Combine(report_path, "Simple List.frx"));
- // webReport.Report.RegisterData(dataSet, "NorthWind");
- // //model.WebReport.SinglePage = true;
- // webReport.Designer.Path = "/WebReportDesigner/index.html";
- // //model.WebReport.Designer.SaveCallBack = "/SaveDesignedReport";
- // webReport.Designer.SaveMethod = (string reportID, string filename, string report) =>
- // {
- // string pathToSave = Path.Combine(report_path, "DesignedReports", filename);
- // if (!Directory.Exists(pathToSave))
- // Directory.CreateDirectory(Path.GetDirectoryName(pathToSave));
- // System.IO.File.WriteAllTextAsync(pathToSave, report);
- // return "OK";
- // };
- // // tab 4
- // //Report report4 = new Report();
- // //webReport.Report.Load(report_path + "wcsdevices.frx");
- // //report4.SetParameterValue("parameter2", "1002");
- // //webReport.Report.SetParameterValue("parameter2", "1002");
- // //webReport.CurrentTab.Name = "wcsdevices";
- // //System.Data.DataSet dataSet = new System.Data.DataSet();
- // //dataSet.ReadXml(report_path + "nwind.xml");
- // //Report report = new Report();
- // //report.RegisterData(dataSet, "NorthWind");
- // //report.Load(report_path + "Simple List.frx");
- // //report.SetParameterValue("Test parameter 1", "Value of parameter 1 from application code");
- // // webReport.CurrentTab.Name = "Simple List";
- // // webReport.AddTab(report, "Simple List");
- // // tab 2
- // //Report report2 = new Report();
- // //report2.RegisterData(dataSet, "NorthWind");
- // //report2.Load(report_path + "Chart.frx");
- // //webReport.AddTab(report2, "Charts");
- // // tab 3
- // //Report report3 = new Report();
- // //report3.RegisterData(dataSet, "NorthWind");
- // //report3.Load(report_path + "Master-Detail.frx");
- // //webReport.AddTab(report3, "Master-Detail");
- // //Report report5 = new Report();
- // //report5.Report.Load(report_path + "wcsdevices.frx");
- // //report5.SetParameterValue("parameter2", "1003");
- // //webReport.Report.SetParameterValue("parameter2", "1003");
- // //webReport.AddTab(report5, "wcsdevices5");
- //}
- private string GetReportPath()
- {
- // this.Server.MapPath("~/DataFiles/FastReport/");
- return ConfigHelper.GetValue<string>("baseDir") +"/wwwroot/DataFiles/FastReport/";
- }
- [HttpPost ]
- public IActionResult ExportExcel(string fileName, string columnJson, string dataJson, string orderJson, string exportField)
- {
- //设置导出格式
- ExcelConfig excelconfig = new ExcelConfig();
- excelconfig.Title = WebUtility.UrlDecode(fileName);
- excelconfig.TitleFont = "微软雅黑";
- excelconfig.TitlePoint = 15;
- excelconfig.FileName = WebUtility.UrlDecode(fileName)+DateTime.Now.Ticks + ".xls";
- excelconfig.IsAllSizeColumn = true;
- excelconfig.ColumnEntity = new List<ColumnModel>();
- //表头
- List<jfGridModel> columnList = columnJson.ToList<jfGridModel>();
- string columns = string.Empty;
- //写入Excel表头
- Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
- if (!string.IsNullOrEmpty(exportField))
- {
- string[] exportFields = exportField.Split(',');
- foreach (var field in exportFields)
- {
- if (field == "F_ORDERNOSPLIT")
- //columns += "(case when regexp_substr(F_FROMORDERNO,'[^_]+',1,2) is null then F_FROMORDERNO else regexp_substr(F_FROMORDERNO,'[^_]+',1,2) end) F_ORDERNOSPLIT,";
- columns += "F_FROMORDERNO F_ORDERNOSPLIT,";
- else
- columns += field + ",";
- if (!exportFieldMap.ContainsKey(field))
- {
- exportFieldMap.Add(field, "1");
- }
- }
- }
- else
- {
- throw new Exception("没找到表头");
- }
- columns = columns.Trim(',');
- //行数据
- DataTable rowData = null;
- // 如果表头数据为空,则表示按照表头导出
- if (string.IsNullOrEmpty(orderJson))
- {
- try
- {
- rowData = dataJson.ToTable();
- }
- catch (Exception ex)
- {
- throw;
- }
- }
- else
- {
- //string keyNo = string.Empty;
- //if (orderJson.ToTable().Columns.Contains("F_NOSPLIT"))
- // keyNo = "F_NOSPLIT";
- //else
- // keyNo = "F_NO";
- //var orderlist = orderJson.ToTable().AsEnumerable().Select(v => Convert.ToString(v.Field<string>(keyNo))).ToArray();
- //rowData = new OrderCore().GetOrderItem(orderlist, columns);
- }
- foreach (jfGridModel columnModel in columnList)
- {
- if (exportFieldMap.ContainsKey(columnModel.name) || string.IsNullOrEmpty(exportField))
- {
- excelconfig.ColumnEntity.Add(new ColumnModel()
- {
- Column = columnModel.name,
- ExcelColumn = columnModel.label,
- Alignment = columnModel.align,
- });
- }
- }
- // ExcelHelper.ExcelDownload(rowData, excelconfig);
- return File(ExcelHelper.ExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
- }
- /// <summary>
- /// 上传附件分片数据
- /// </summary>
- /// <param name="fileGuid">文件主键</param>
- /// <param name="chunk">分片序号</param>
- /// <param name="Filedata">文件数据</param>
- /// <returns></returns>
- [HttpPost]
- [ValidateAntiForgeryToken]
- //public ActionResult UploadAnnexesFileChunk(string fileGuid, int chunk, int chunks, IFormFile Filedata)
- //{
- // //没有文件上传,直接返回
- // if (Filedata == null || string.IsNullOrEmpty(Filedata.FileName) || Filedata.Length == 0)
- // {
-
- // return null;
-
- // }
- // AnnexesFile.SaveChunkAnnexes(fileGuid, chunk, Filedata.OpenReadStream());
- // return Success("保存成功");
- //}
- /// <summary>
- /// 上传附件分片数据
- /// </summary>
- /// <param name="fileGuid">文件主键</param>
- /// <param name="chunk">分片序号</param>
- /// <param name="Filedata">文件数据</param>
- /// <returns></returns>
- [HttpPost]
- public IActionResult UploadAnnexesFileChunk(string fileGuid, int chunk, int chunks)
- {
- var files = Request.Form.Files;
- //没有文件上传,直接返回
- if (files[0].Length == 0 || string.IsNullOrEmpty(files[0].FileName))
- {
- return Fail("没有文件信息");
- }
- byte[] bytes = new byte[files[0].Length];
- MemoryStream ms = new MemoryStream();
- files[0].CopyTo(ms);
- ms.Flush();
- ms.Position = 0;
- ms.Read(bytes, 0, bytes.Length);
- ms.Close();
- ms.Dispose();
- // FileHelper.WriteCache(chunk + "_" + fileGuid, bytes);
- _annexesFileService.SaveChunkAnnexes(fileGuid, chunk, bytes);
- return Success("保存成功");
- }
- #region 下载文件
- /// <summary>
- /// 下载文件
- /// </summary>
- /// <param name="fileId">文件id</param>
- /// <returns></returns>
- [HttpPost]
- [ValidateAntiForgeryToken]
- public IActionResult DownSchemeFile(int bustype)
- {
- return AnnexesFile.DownSchemeFile(bustype);
- }
- /// <summary>
- /// excel文件导入(通用)
- /// </summary>
- /// <param name="templateId">模板Id</param>
- /// <param name="fileId">文件主键</param>
- /// <param name="chunks">分片数</param>
- /// <param name="ext">文件扩展名</param>
- /// <returns></returns>
- [HttpPost]
- //////[AjaxOnly]
- ////[HandlerValidateAntiForgeryToken]
- public ActionResult ExecuteImportExcel(string fileId, int ordertype, int chunks, string ext) // EOrderType
- {
- try
- {
- JsonExecl json = null;
- LoginUserInfo LoginUser = GetLoginUser();
- DataTable dt = _annexesFileService.SaveAnnexesToDataTable(fileId, ext, chunks);
- if (ordertype == 100)
- json = _importDataOrExeclService.ImportBillMatInfo(dt, (int)ordertype, LoginUser.UserNo);
- //else
- // json = itmp.ImportData(dt, (int)ordertype, LoginBLLCore.GetLoginUser().UserNo);
- if (json.Type == 0)
- // 异常
- return FailEx(json.Message);
- else if (json.Type == 1)
- {
- if (json.dtSou == null || json.dtSou.Rows.Count == 0)
- return FailEx(json.Message);
- AnnexesFile.SaveErrJsonExecl(fileId, json);
- return Fail(json.Message);
- }
- else
- // 成功
- return Success(json.Message);
- }
- catch (Exception ex)
- {
- return ToJsonResult(SysExCore.GetResErr(ex));
- }
- }
- /// <summary>
- /// 下载文件(导入文件未被导入的数据)
- /// </summary>
- /// <param name="fileId">文件id</param>
- /// <returns></returns>
- [HttpPost]
- [ValidateAntiForgeryToken]
- public void DownImportErrorFile(string fileId, string fileName)
- {
- string fname = WebUtility.UrlDecode("未导入错误数据【" + fileName + "】") + ".xls";
- AnnexesFile.DownErrJsonExecl(fileId, fname);
- }
- /// <summary>
- /// 移除附件分片数据
- /// </summary>
- /// <param name="fileGuid">文件主键</param>
- /// <param name="chunks">总分片数</param>
- /// <returns></returns>
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult RemoveAnnexesFileChunk(string fileGuid, int chunks)
- {
- AnnexesFile.RemoveChunkAnnexes(fileGuid, chunks);
- return Success("移除成功");
- }
- #endregion
- #region jfgrid弹层选择
- /// <summary>
- /// 列表选择弹层
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- //[HandlerLogin(FilterMode.Enforce)]
- public ActionResult JfGirdLayerForm()
- {
- return View();
- }
- #endregion
- /// <summary>
- /// 获取仓库的树形数据
- /// </summary>
- /// <param name="parentId">父级id</param>
- /// <returns></returns>
- [HttpGet]
- ////[AjaxOnly]
- public ActionResult GetWareHouseTree(string parentId)
- {
- var data = _warehouseService.GetTree(parentId);
- return Success("", data);
- }
- [HttpGet]
- public ActionResult WearHouseList()
- {
- return Success(_warehouseService.WearHouseList());
- }
-
- }
- }
|