public ResResultModel GetAssetInStore(AssetInStoreModel model) { try { if (model.PageIndex < 1) { model.PageIndex = 1; } if (model.PageSize < 1) { model.PageSize = 10; } int totalRecord = 0; var bll = new AssetInStore(); var list = bll.GetListByJoin(model.PageIndex, model.PageSize, out totalRecord, "", null); if (totalRecord == 0) { return(ResResult.Response(true, "", "{\"total\":0,\"rows\":[]}")); } var dgData = "{\"total\":" + totalRecord + ",\"rows\":" + JsonConvert.SerializeObject(list) + "}"; return(ResResult.Response(true, "", dgData)); } catch (Exception ex) { return(ResResult.Response(false, ex.Message, "")); } }
private void OnExportByAssetInStore(HttpContext context) { try { AssetInStore aisBll = new AssetInStore(); var list = aisBll.GetListByJoin(); if (list == null || list.Count == 0) { context.Response.Write(ResResult.ResJsonString(false, "无数据", "")); return; } var colAppend = "照片,资产条码,资产名称,资产类别,规格型号,SN号,计量单位,金额,使用公司,使用部门,使用人,区域,存放地点,管理员,所属公司,购入时间,供应商,使用期限"; var cols = colAppend.Split(','); var dt = new DataTable("dtAssetInStore"); foreach (var item in cols) { dt.Columns.Add(new DataColumn(item, System.Type.GetType("System.String"))); } foreach (var model in list) { var dr = dt.NewRow(); for (var i = 0; i < cols.Length; i++) { var text = ""; switch (i) { case 0: text = ""; break; case 1: text = model.Barcode; break; case 2: text = model.Named; break; case 3: text = model.CategoryName; break; case 4: text = model.SpecModel; break; case 5: text = model.SNCode; break; case 6: text = model.Unit; break; case 7: text = model.Price.ToString(); break; default: break; } dr[i] = text; } dt.Rows.Add(dr); } //NpoiHelper npoi = new NpoiHelper(); //var fileUrl = npoi.ExportExcel(dt, "资产列表.xlsx"); var fileUrl = ""; context.Response.Write(ResResult.ResJsonString(true, "", fileUrl)); } catch (Exception ex) { context.Response.Write(ResResult.ResJsonString(false, ex.Message, "")); } }