예제 #1
0
        public async Task <ActionResult> ExportToExcel(ChestDetailQueryViewModel model)
        {
            //JsonResult JsonResult = null;
            DataTable      dt    = new DataTable();
            ChestParameter param = new ChestParameter();

            if (model.PackageNo != "" && model.PackageNo != null)
            {
                param.PackageNo = model.PackageNo;
            }
            else
            {
                param.PackageNo = "";
            }
            if (model.ChestNo != "" && model.ChestNo != null)
            {
                param.ChestNo = model.ChestNo;
            }
            else
            {
                param.ChestNo = "";
            }
            if (model.MaterialCode != "" && model.MaterialCode != null)
            {
                param.MaterialCode = model.MaterialCode;
            }
            else
            {
                param.MaterialCode = "";
            }
            if (model.ChestDate != "" && model.ChestDate != null)
            {
                param.ChestDateStart = model.ChestDate;
                param.ChestDateEnd   = Convert.ToDateTime(model.ChestDate).AddDays(1).ToString("yyyy-MM-dd");
            }
            else
            {
                param.ChestDateStart = "";
                param.ChestDateEnd   = "";
            }
            if (model.LotNumber != "" && model.LotNumber != null)
            {
                param.LotNumber = model.LotNumber;
            }
            else
            {
                param.LotNumber = "";
            }
            if (model.OrderNumber != "" && model.OrderNumber != null)
            {
                param.OrderNumber = model.OrderNumber;
            }
            else
            {
                param.OrderNumber = "";
            }
            param.PageSize = model.PageSize;
            param.PageNo   = -1;
            await Task.Run(() =>
            {
                using (PackageInChestServiceClient client = new PackageInChestServiceClient())
                {
                    MethodReturnResult <DataSet> ds = client.GetChestDetail(ref param);

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

            string     template_path = Server.MapPath("~\\Labels\\");//模板路径
            string     template_file = template_path + "报检数据.xls";
            FileInfo   tempFileInfo  = new FileInfo(template_file);
            FileStream file          = new FileStream(template_file, FileMode.Open, FileAccess.Read);
            IWorkbook  hssfworkbook  = new HSSFWorkbook(file);

            //创建sheet
            NPOI.SS.UserModel.ISheet sheet1 = hssfworkbook.GetSheet("Sheet0");

            //创建单元格和单元格样式
            ICellStyle styles = hssfworkbook.CreateCellStyle();

            styles.FillForegroundColor = 10;
            styles.BorderBottom        = BorderStyle.Thin;
            styles.BorderLeft          = BorderStyle.Thin;
            styles.BorderRight         = BorderStyle.Thin;
            styles.BorderTop           = BorderStyle.Thin;
            styles.VerticalAlignment   = VerticalAlignment.Center;
            styles.Alignment           = HorizontalAlignment.Center;

            IFont font = hssfworkbook.CreateFont();

            font.Boldweight = 10;
            styles.SetFont(font);
            ICellStyle style = hssfworkbook.CreateCellStyle();

            style.FillForegroundColor = 10;
            style.BorderBottom        = BorderStyle.Thin;
            style.BorderLeft          = BorderStyle.Thin;
            style.BorderRight         = BorderStyle.Thin;
            style.BorderTop           = BorderStyle.Thin;
            style.VerticalAlignment   = VerticalAlignment.Center;
            IFont fonts = hssfworkbook.CreateFont();

            font.Boldweight = 10;

            for (int j = 0; j < dt.Rows.Count; j++)
            {
                ICell cellData = null;
                IRow  rowData  = null;
                //string isLast;

                rowData = sheet1.CreateRow(j + 1);

                #region //数据
                //cellData = rowData.CreateCell(rowData.Cells.Count);
                //cellData.CellStyle = style;
                //cellData.SetCellValue(j + 1);  //序号

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["组件号"].ToString());//组件号

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["入库日期"].ToString());//入库日期

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["托盘号"].ToString());//托盘号

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["柜号"].ToString());//柜号

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["组件型号"].ToString());//组件型号

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["VOC (V)"].ToString());//VOC (V)

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["ISC(A)"].ToString());//ISC(A)

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["Vmpp (V)"].ToString());//Vmpp (V)

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["Impp(A)"].ToString());//Impp(A)

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["Pmpp(W)"].ToString());//Pmpp(W)

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["FF(%)"].ToString());//FF(%)

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["SurfTemp"].ToString());//SurfTemp

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["电流分档"].ToString());//电流分档

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["标称功率"].ToString());//标称功率

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["电池片厂家"].ToString());//电池片厂家

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["栅线数量"].ToString());//栅线数量

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["电池片档位"].ToString());//电池片档位

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["背板厂家+规格"].ToString());//背板厂家+规格

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["EVA厂家+型号"].ToString());//EVA厂家+型号

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["玻璃厂家型号"].ToString());//玻璃厂家型号

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["镀膜与否"].ToString());//镀膜与否

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["接线盒厂家+型号+承载电压"].ToString());//接线盒厂家+型号+承载电压

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["线缆长度"].ToString());//线缆长度

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["接线端子型号"].ToString());//接线端子型号

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["铝框厂家+型号+颜色+有无加强筋"].ToString());//铝框厂家+型号+颜色+有无加强筋

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["涂锡带厂家"].ToString());//涂锡带厂家

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["硅胶厂家+型号"].ToString());//硅胶厂家+型号

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["灌封胶厂家+型号"].ToString());//灌封胶厂家+型号

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["认证类型"].ToString());//认证类型

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["包装方式"].ToString());//包装方式

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["组件类型+耐压"].ToString());//组件类型+耐压

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["电池片数"].ToString());//电池片数

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["电池片类型"].ToString());//电池片类型

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["电池片工艺"].ToString());//电池片工艺

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(dt.Rows[j]["单位号"].ToString());//单位号

                #endregion
            }
            MemoryStream ms = new MemoryStream();
            hssfworkbook.Write(ms);
            ms.Flush();
            ms.Position = 0;
            return(File(ms, "application/vnd.ms-excel", "报检数据.xls"));
        }
예제 #2
0
        public ActionResult DetailQuery(ChestDetailQueryViewModel model)
        {
            string strErrorMessage = string.Empty;
            MethodReturnResult <DataSet> result = new MethodReturnResult <DataSet>();

            try
            {
                ChestParameter param = new ChestParameter();
                if (model.PackageNo != "" && model.PackageNo != null)
                {
                    param.PackageNo = model.PackageNo;
                }
                else
                {
                    param.PackageNo = "";
                }
                if (model.ChestNo != "" && model.ChestNo != null)
                {
                    param.ChestNo = model.ChestNo;
                }
                else
                {
                    param.ChestNo = "";
                }
                if (model.MaterialCode != "" && model.MaterialCode != null)
                {
                    param.MaterialCode = model.MaterialCode;
                }
                else
                {
                    param.MaterialCode = "";
                }
                if (model.ChestDate != "" && model.ChestDate != null)
                {
                    param.ChestDateStart = model.ChestDate;
                    param.ChestDateEnd   = Convert.ToDateTime(model.ChestDate).AddDays(1).ToString("yyyy-MM-dd");
                }
                else
                {
                    param.ChestDateStart = "";
                    param.ChestDateEnd   = "";
                }
                if (model.LotNumber != "" && model.LotNumber != null)
                {
                    param.LotNumber = model.LotNumber;
                }
                else
                {
                    param.LotNumber = "";
                }
                if (model.OrderNumber != "" && model.OrderNumber != null)
                {
                    param.OrderNumber = model.OrderNumber;
                }
                else
                {
                    param.OrderNumber = "";
                }
                param.PageSize = model.PageSize;
                param.PageNo   = model.PageNo;
                using (PackageInChestServiceClient client = new PackageInChestServiceClient())
                {
                    MethodReturnResult <DataSet> ds = client.GetChestDetail(ref param);
                    if (ds.Code > 0)
                    {
                        result.Code    = ds.Code;
                        result.Message = ds.Message;
                        result.Detail  = ds.Detail;

                        return(Json(result));
                    }

                    ViewBag.ListData     = ds.Data.Tables[0];
                    ViewBag.PagingConfig = new PagingConfig()
                    {
                        PageNo   = model.PageNo,
                        PageSize = model.PageSize,
                        Records  = param.TotalRecords
                    };
                    model.TotalRecords = param.TotalRecords;
                }
            }
            catch (Exception ex)
            {
                result.Code    = 1000;
                result.Message = ex.Message;
                result.Detail  = ex.ToString();
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_DetailListPartial", model));
            }
            else
            {
                return(View("Index", model));
            }
        }