using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Configuration; using System.Text; using System.IO; using System.Reflection; using System.Web; using System.Web.Mvc; using System.Web.Mvc.Html; using QMFrameWork.Common.Serialization; using QMFrameWork.Common.ExcelOperation; using QMAPP.Common.Web.Models; namespace QMAPP.Common.Web.Controllers { /// /// 信息输出控制器 /// public class MessageOutputController : Controller { #region 输出导入数据提示信息 public ActionResult OutputImportMessage(ImportMessageModel model) { string fileName = ""; try { //获取导入配置信息 SheetInfo mainInfo = new IEExcelHelper().GetMainInfo(model.InfoName); model.TotalRecordCount = model.ErrorDt.Rows.Count; //过滤异常数据 for (int i = model.ErrorDt.Rows.Count - 1; i >= 0; i--) { if (model.ErrorDt.Rows[i]["InfoError"] == System.DBNull.Value || model.ErrorDt.Rows[i]["InfoError"].ToString() == "") { model.ErrorDt.Rows.RemoveAt(i); } } #region 构成异常数据表格 model.TableHtml = ""; model.TableHtml += "
"; model.TableHtml += ""; model.TableHtml += ""; foreach (CellInfo item in mainInfo.ColInfos) { model.TableHtml += string.Format("", item.ColumnName, item.ColumnTitle); } model.TableHtml += string.Format(""); model.TableHtml += ""; model.TableHtml += ""; for (int i = 0; i < model.ErrorDt.Rows.Count; i++) { model.TableHtml += ""; for (int j = 0; j < model.ErrorDt.Columns.Count; j++) { model.TableHtml += string.Format("", model.ErrorDt.Rows[i][model.ErrorDt.Columns[j].ColumnName].ToString()); } model.TableHtml += ""; } model.TableHtml += ""; model.TableHtml += "
{1}错误信息
{0}
"; model.TableHtml += "
"; //model.TableHtml += ""; #region 生成导出文件 fileName = Guid.NewGuid().ToString() + ".xlsx"; //生成导出文件 QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool(); byte[] fileContent = efTool.GetExcelFileContent(model.InfoName, fileName, model.ErrorDt); using (FileStream fs = System.IO.File.Create(QController.PhysicsRootPath + "Temp\\" + fileName)) { fs.Write(fileContent, 0, fileContent.Length); } model.ErrorFile = fileName; #endregion model.ErrorDt.Rows.Clear(); model.ErrorDt.Dispose(); #endregion #region 返回现实视图 ViewResult vr = null; vr = new ViewResult { ViewName = "OutputImportMessage", MasterName = "AppMaster", ViewData = new ViewDataDictionary(model) }; return vr; #endregion } catch (Exception ex) { throw ex; } } #endregion #region 下载模板 /// /// 下载导入模板 /// /// [HttpPost] public FilePathResult GetErrorFile() { try { string path = AppDomain.CurrentDomain.BaseDirectory + "Temp\\"; string fileName = Request.Form["ErrorFile"]; return File(path + fileName, "application/vnd.ms-excel", Url.Encode("错误信息列表.xlsx")); } catch (Exception ex) { throw ex; } } #endregion } }