示例#1
0
        public ActionResult Query(LotMaterialListViewModel model)
        {
            using (LotMaterialListServiceClient client = new LotMaterialListServiceClient())
            {
                model.TotalRecords = 0;
                LotMaterialListQueryParameter p = new LotMaterialListQueryParameter()
                {
                    OrderNumber     = model.OrderNumber,
                    LocationName    = model.LocationName,
                    EndCreateTime   = model.EndCreateTime,
                    StartCreateTime = model.StartCreateTime,
                    LotNumber       = model.LotNumber,
                    LotNumber1      = model.LotNumber1,
                    PageSize        = model.PageSize,
                    PageNo          = model.PageNo
                };
                MethodReturnResult <DataSet> result = client.Get(ref p);

                if (result.Code == 0 && result.Data != null && result.Data.Tables.Count > 0)
                {
                    ViewBag.ListData     = result.Data.Tables[0];
                    ViewBag.PagingConfig = new PagingConfig()
                    {
                        PageNo   = p.PageNo,
                        PageSize = p.PageSize,
                        Records  = p.TotalRecords
                    };
                    model.TotalRecords = p.TotalRecords;
                }
                else
                {
                    ViewBag.Message = result.Message;
                }
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_ListPartial", model));
            }
            else
            {
                return(View("Index", model));
            }
        }
示例#2
0
        public ActionResult ExportToExcel(LotMaterialListViewModel model)
        {
            DataTable dt = new DataTable();

            using (LotMaterialListServiceClient client = new LotMaterialListServiceClient())
            {
                LotMaterialListQueryParameter p = new LotMaterialListQueryParameter()
                {
                    OrderNumber     = model.OrderNumber,
                    LocationName    = model.LocationName,
                    EndCreateTime   = model.EndCreateTime,
                    StartCreateTime = model.StartCreateTime,
                    LotNumber       = model.LotNumber,
                    LotNumber1      = model.LotNumber1,
                    PageSize        = model.TotalRecords,
                    PageNo          = 0
                };
                MethodReturnResult <DataSet> result = client.Get(ref p);

                if (result.Code == 0 && result.Data != null && result.Data.Tables.Count > 0)
                {
                    dt = result.Data.Tables[0];
                }
            }

            //创建工作薄。
            IWorkbook wb = new HSSFWorkbook();
            //设置EXCEL格式
            ICellStyle style = wb.CreateCellStyle();

            style.FillForegroundColor = 10;
            //有边框
            style.BorderBottom = BorderStyle.Thin;
            style.BorderLeft   = BorderStyle.Thin;
            style.BorderRight  = BorderStyle.Thin;
            style.BorderTop    = BorderStyle.Thin;
            IFont font = wb.CreateFont();

            font.Boldweight = 10;
            style.SetFont(font);

            ISheet ws = null;

            for (int j = 0; j < dt.Rows.Count; j++)
            {
                if (j % 65535 == 0)
                {
                    ws = wb.CreateSheet();
                    IRow  row  = ws.CreateRow(0);
                    ICell cell = null;
                    #region //列名
                    foreach (DataColumn dc in dt.Columns)
                    {
                        cell           = row.CreateCell(row.Cells.Count);
                        cell.CellStyle = style;
                        cell.SetCellValue(dc.Caption);
                    }
                    #endregion
                    font.Boldweight = 5;
                }
                IRow rowData = ws.CreateRow(j + 1);
                #region //数据
                ICell cellData = null;
                foreach (DataColumn dc in dt.Columns)
                {
                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;

                    if (dc.DataType == typeof(double) || dc.DataType == typeof(float))
                    {
                        cellData.SetCellValue(Convert.ToDouble(dt.Rows[j][dc]));
                    }
                    else if (dc.DataType == typeof(int))
                    {
                        cellData.SetCellValue(Convert.ToInt32(dt.Rows[j][dc]));
                    }
                    else
                    {
                        cellData.SetCellValue(Convert.ToString(dt.Rows[j][dc]));
                    }
                }
                #endregion
            }

            MemoryStream ms = new MemoryStream();
            wb.Write(ms);
            ms.Flush();
            ms.Position = 0;
            return(File(ms, "application/vnd.ms-excel", "LotMaterialData.xls"));
        }