Ejemplo n.º 1
0
        //
        // GET: /RPT/WIPMove/Detail
        public ActionResult Detail(WIPMoveDetailQueryViewModel model)
        {
            WIPMoveDetailGetParameter p = GetQueryCondition(model);

            //获取工序MOVE明细数据。
            using (WIPMoveServiceClient client = new WIPMoveServiceClient())
            {
                MethodReturnResult <DataSet> rst = client.GetDetail(ref p);
                if (rst.Code <= 0 && rst.Data != null && rst.Data.Tables.Count > 0)
                {
                    ViewBag.List         = rst.Data.Tables[0];
                    ViewBag.PagingConfig = new PagingConfig()
                    {
                        PageNo   = model.PageNo,
                        PageSize = model.PageSize,
                        Records  = p.TotalRecords
                    };
                }
            }
            model.TotalRecords = p.TotalRecords;
            if (Request.IsAjaxRequest())
            {
                return(PartialView("_DetailListPartial"));
            }
            else
            {
                return(View(model));
            }
        }
Ejemplo n.º 2
0
        public ActionResult ExportToExcel(WIPMoveDetailQueryViewModel model)
        {
            WIPMoveDetailGetParameter p = GetQueryCondition(model);

            p.PageSize = model.TotalRecords;
            DataTable dtData = new DataTable();

            using (WIPMoveServiceClient client = new WIPMoveServiceClient())
            {
                MethodReturnResult <DataSet> rst = client.GetDetail(ref p);
                if (rst.Code <= 0 && rst.Data != null && rst.Data.Tables.Count > 0)
                {
                    dtData = rst.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 < dtData.Rows.Count; j++)
            {
                if (j % 65535 == 0)
                {
                    ws = wb.CreateSheet();
                    IRow row = ws.CreateRow(0);
                    #region //列名
                    ICell cell = null;
                    foreach (DataColumn dc in dtData.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 dtData.Columns)
                {
                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    if (dc.DataType == typeof(double) || dc.DataType == typeof(float))
                    {
                        cellData.SetCellValue(Convert.ToDouble(dtData.Rows[j][dc]));
                    }
                    else if (dc.DataType == typeof(int))
                    {
                        cellData.SetCellValue(Convert.ToInt32(dtData.Rows[j][dc]));
                    }
                    else
                    {
                        cellData.SetCellValue(Convert.ToString(dtData.Rows[j][dc]));
                    }
                }
                #endregion
            }
            MemoryStream ms = new MemoryStream();
            wb.Write(ms);
            ms.Flush();
            ms.Position = 0;
            return(File(ms, "application/vnd.ms-excel", "WIPMoveDetailData.xls"));
        }