示例#1
0
        public ActionResult ChestDetailQuery(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.GetChestDetailByDB(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("_ChestDetailListPartial", model));
            }
            else
            {
                return(View("ChestIndex", model));
            }
        }
示例#2
0
        public async Task <ActionResult> ExportToExcelChest(ChestDetailQueryViewModel model)
        {
            //IList<ChestDetail> lstChestDetail = new List<ChestDetail>();
            //using (PackageInChestServiceClient client = new PackageInChestServiceClient())
            //{
            //    await Task.Run(() =>
            //    {
            //        PagingConfig cfg = new PagingConfig()
            //        {
            //            IsPaging = false,
            //            OrderBy = "Key.ChestNo Desc,ItemNo Asc",
            //            Where = GetQueryCondition(model)
            //        };
            //        MethodReturnResult<IList<ChestDetail>> result = client.GetDetail(ref cfg);

            //        if (result.Code == 0)
            //        {
            //            lstChestDetail = result.Data;
            //        }
            //    });
            //}

            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.GetChestDetailByDB(ref param);

                    if (ds.Code == 0 && ds.Data != null && ds.Data.Tables.Count > 0)
                    {
                        dt = ds.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);

            ChestDetailQueryViewModel m = new ChestDetailQueryViewModel();
            ISheet ws = null;

            for (int j = 0; j < dt.Rows.Count; j++)
            {
                if (j % 65535 == 0)
                {
                    ws = wb.CreateSheet();
                    IRow row = ws.CreateRow(0);
                    #region //列名
                    ICell cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(StringResource.ItemNo);  //项目号

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("柜号");  //柜号

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("库位");  //库位

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("柜属性");  //柜属性

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("项目号");  //柜属性

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("包装号");  //包装号

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("托内数量");  //托内数量

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("工单号");  //工单号

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("产品编码");  //产品编码

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("等级");  //等级

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("花色");  //花色

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("功率档位");  //功率档位

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("电流档");  //电流档

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("入柜时间");  //入柜时间

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("托号状态");  //托号状态

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("入库单号");  //花色

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("入库单状态");  //功率档位

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("入库接收核对状态");  //电流档
                    #endregion
                    font.Boldweight = 5;
                }
                //Package package = m.GetPackage(lstChestDetail[j].Key.ObjectNumber);
                //Chest chest = m.GetChest(lstChestDetail[j].Key.ChestNo);
                //WOReportDetail woReportDetail = m.GetWOReportDetail(lstChestDetail[j].Key.ObjectNumber);
                //WOReport woReport = null;
                //if (woReportDetail != null)
                //{
                //    woReport = m.GetWOReport(woReportDetail.Key.BillCode);
                //}

                IRow rowData = ws.CreateRow(j + 1);

                #region //数据
                ICell 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]["托内数量"].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(((EnumPackageState)dt.Rows[j]["托号状态"]).GetDisplayName());  //托号状态

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

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                if (dt.Rows[j]["入库单状态"].ToString() == "")
                {
                    cellData.SetCellValue("");  //入库单状态
                }
                else
                {
                    cellData.SetCellValue(((EnumBillState)dt.Rows[j]["入库单状态"]).GetDisplayName());  //入库单状态
                }

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                if (dt.Rows[j]["入库接收核对状态"].ToString() == "")
                {
                    cellData.SetCellValue("");  //入库接收核对状态
                }
                else
                {
                    cellData.SetCellValue(((EnumPackageCheckState)dt.Rows[j]["入库接收核对状态"]).GetDisplayName());  //入库接收核对状态
                }
                #endregion
            }

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