public void Export(QueryBfCodeDto queryParams) { try { var bfCodeList = (new BfCodeInfoManager()).GetItems(queryParams); var bfCodeDtlList = (new BfCodeDetailInfoManager()).SelectBfCodeDetailByBfCodeIds(bfCodeList); var dataTable = new DataTable(); string fileName = "系统参数.xls"; LogHelper.Info(this.GetType(), "生成Excel,请稍后..."); #region 添加列 dataTable.Columns.Add("CODE"); dataTable.Columns.Add("DESCRIPTION"); dataTable.Columns.Add("DETAILCODE"); dataTable.Columns.Add("DETAILNAME"); dataTable.Columns.Add("SEQ_NUM"); #endregion #region 添加行 foreach (var dtl in bfCodeDtlList) { var bfCode = bfCodeList.Find(a => a.ID == dtl.BF_CODE_ID); DataRow dataRow = dataTable.NewRow(); dataRow["CODE"] = bfCode.CODE; dataRow["DESCRIPTION"] = bfCode.DESCRIPTION; dataRow["DETAILCODE"] = dtl.CODE; dataRow["DETAILNAME"] = dtl.NAME; dataRow["SEQ_NUM"] = dtl.SEQ_NUM; dataTable.Rows.Add(dataRow); } #endregion #region 设置列名 dataTable.Columns["CODE"].ColumnName = "编码"; dataTable.Columns["DESCRIPTION"].ColumnName = "描述"; dataTable.Columns["DETAILCODE"].ColumnName = "明细编码"; dataTable.Columns["DETAILNAME"].ColumnName = "明细名称"; dataTable.Columns["SEQ_NUM"].ColumnName = "明细排序号"; #endregion System.Web.HttpContext.Current.Response.Charset = "utf-8"; System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); if (System.Web.HttpContext.Current.Request.Browser.Browser != "Firefox") { fileName = System.Web.HttpUtility.UrlEncode(fileName, Encoding.UTF8); } FileNPOI.Export(System.Web.HttpContext.Current, fileName, dataTable); } catch (Exception ex) { LogHelper.Error(this.GetType(), "", ex); } }
public ActionResult QueryBfCode(JQueryDataTablesModel jQueryDataTablesModel, QueryBfCodeDto query) { var queryParam = new QueryBfCodeDto { PageIndex = jQueryDataTablesModel.PageIndex, PageSize = jQueryDataTablesModel.PageSize, CODE = query.CODE, DESCRIPTION = query.DESCRIPTION, SortField = jQueryDataTablesModel.SortField, SortDirection = jQueryDataTablesModel.Direction }; var pageList = (new BfCodeInfoManager()).GetPagedList(queryParam); return(DataTablesJson(pageList, jQueryDataTablesModel.GridKey)); }