示例#1
0
 /// <summary>
 /// 获取查询条件下所有数据
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public MethodReturnResult <DataSet> GetAllData(LotMaterialListOutViewModel model)
 {
     using (LotMaterialListServiceClient client = new LotMaterialListServiceClient())
     {
         MaterialDataParameter p = new MaterialDataParameter()
         {
             ProductMaterialCode = model.ProductMaterialCode,
             BomMaterialCode     = model.BomMaterialCode,
             BomMaterialName     = model.BomMaterialName,
             OutPackageNo        = model.OutPackageNo,
             OutStartTime        = model.OutStartTime,
             OutEndTime          = model.OutEndTime,
             PageSize            = model.PageSize,
             PageNo = 0
         };
         MethodReturnResult <DataSet> result = client.GetRPTMaterialData(ref p);
         AllRecords = p.Records;
         if (result.Code == 0 && result.Data != null && result.Data.Tables.Count > 0)
         {
             return(result);
         }
         else
         {
             return(null);
         }
     }
 }
示例#2
0
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <returns></returns>
        public DataTable GetPageData(LotMaterialListOutViewModel model)
        {
            DataTable dataTable  = Resulted.Data.Tables[0];
            DataTable dataTables = new DataTable();

            dataTables = dataTable.Clone();
            for (int i = 0; i < model.PageSize; i++)
            {
                if ((i + (model.PageSize * model.PageNo)) < AllRecords)
                {
                    dataTables.Rows.Add(dataTable.Rows[i + (model.PageSize * model.PageNo)].ItemArray);
                }
            }
            return(dataTables);
        }
示例#3
0
 public ActionResult PagingQuery(LotMaterialListOutViewModel model)
 {
     if (ModelState.IsValid)
     {
         DataTable result = GetPageData(model);
         if (result != null && result.Rows.Count > 0)
         {
             ViewBag.ListData     = result;
             ViewBag.PagingConfig = new PagingConfig()
             {
                 PageNo   = model.PageNo,
                 PageSize = model.PageSize,
                 Records  = AllRecords
             };
         }
         else
         {
             ViewBag.Message = "无数据";
         }
     }
     return(PartialView("_ListPartialMaterial", new LotMaterialListOutViewModel()));
 }
示例#4
0
        /// <summary>
        /// 首页查询方法
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult Querys(LotMaterialListOutViewModel model)
        {
            //如果出货包装号不为空且为多个
            if (model.OutPackageNo != "" && model.OutPackageNo != null)
            {
                if (model.OutPackageNo.IndexOf(",") != -1)
                {
                    model.OutPackageNo = model.OutPackageNo.Replace(",", "','");
                }
            }
            //如果查询条件均为空
            if ((model.BomMaterialCode == "" || model.BomMaterialCode == null) &&
                (model.BomMaterialName == "" || model.BomMaterialName == null) &&
                (model.ProductMaterialCode == "" || model.ProductMaterialCode == null) &&
                (model.OutPackageNo == "" || model.OutPackageNo == null) &&
                model.OutStartTime == null && model.OutEndTime == null)
            {
                ViewBag.Message = "请输入查询条件!";
            }

            //如果查询条件不为空
            else
            {
                //如果产品编码不为空
                if (model.ProductMaterialCode != "" && model.ProductMaterialCode != null)
                {
                    //如果物料编码或物料名称或出库托号全部为空
                    if ((model.BomMaterialCode == "" || model.BomMaterialCode == null) &&
                        (model.BomMaterialName == "" || model.BomMaterialName == null) &&
                        (model.OutPackageNo == "" || model.OutPackageNo == null))
                    {
                        ViewBag.Message = "查询条件不足,请增加物料编码或物料名称筛选条件!";
                    }
                    //如果物料编码或物料名称或出库托号至少有一个不为空
                    else
                    {
                        Resulted = GetAllData(model);
                        if (Resulted.Code == 0 && Resulted.Data != null && Resulted.Data.Tables.Count > 0)
                        {
                            model.PageNo = 0;
                            DataTable result = GetPageData(model);
                            if (result != null && result.Rows.Count > 0)
                            {
                                ViewBag.ListData     = result;
                                ViewBag.PagingConfig = new PagingConfig()
                                {
                                    PageNo   = model.PageNo,
                                    PageSize = model.PageSize,
                                    Records  = AllRecords
                                };
                            }
                            else
                            {
                                ViewBag.Message = "无数据";
                            }
                        }
                    }
                }
                //如果产品编码为空
                else
                {
                    //如果物料编码或物料名称或出库托号全部为空
                    if ((model.BomMaterialCode == "" || model.BomMaterialCode == null) &&
                        (model.BomMaterialName == "" || model.BomMaterialName == null) &&
                        (model.OutPackageNo == "" || model.OutPackageNo == null))
                    {
                        ViewBag.Message = "查询条件不足,请增加筛选条件!";
                    }
                    //如果物料编码或物料名称或出库托号至少有一个不为空
                    else
                    {
                        //如果物料名称不为空
                        if (model.BomMaterialName != "" || model.BomMaterialName != null)
                        {
                            //如果物料编码或出库托号全部为空
                            if ((model.BomMaterialCode == "" || model.BomMaterialCode == null) &&
                                (model.OutPackageNo == "" || model.OutPackageNo == null))
                            {
                                ViewBag.Message = "查询条件不足,请增加物料编码或出库托号筛选条件!";
                            }
                            else
                            {
                                Resulted = GetAllData(model);
                                if (Resulted.Code == 0 && Resulted.Data != null && Resulted.Data.Tables.Count > 0)
                                {
                                    model.PageNo = 0;
                                    DataTable result = GetPageData(model);
                                    if (result != null && result.Rows.Count > 0)
                                    {
                                        ViewBag.ListData     = result;
                                        ViewBag.PagingConfig = new PagingConfig()
                                        {
                                            PageNo   = model.PageNo,
                                            PageSize = model.PageSize,
                                            Records  = AllRecords
                                        };
                                    }
                                    else
                                    {
                                        ViewBag.Message = "无数据";
                                    }
                                }
                            }
                        }
                        //如果物料名称为空
                        else
                        {
                            Resulted = GetAllData(model);
                            if (Resulted.Code == 0 && Resulted.Data != null && Resulted.Data.Tables.Count > 0)
                            {
                                model.PageNo = 0;
                                DataTable result = GetPageData(model);
                                if (result != null && result.Rows.Count > 0)
                                {
                                    ViewBag.ListData     = result;
                                    ViewBag.PagingConfig = new PagingConfig()
                                    {
                                        PageNo   = model.PageNo,
                                        PageSize = model.PageSize,
                                        Records  = AllRecords
                                    };
                                }
                                else
                                {
                                    ViewBag.Message = "无数据";
                                }
                            }
                        }
                    }
                }
            }
            if (Request.IsAjaxRequest())
            {
                return(PartialView("_ListPartialMaterial", model));
            }
            else
            {
                return(View("IndexMaterial", model));
            }
        }
示例#5
0
        /// <summary>
        /// 导出批次物料出库数据到Excel
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ActionResult> ExportOutToExcel(LotMaterialListOutViewModel model)
        {
            DataTable dt = new DataTable();

            if (Resulted.Code == 0 && Resulted.Data != null && Resulted.Data.Tables.Count > 0)
            {
                dt = Resulted.Data.Tables[0];
            }
            else
            {
                using (LotMaterialListServiceClient client = new LotMaterialListServiceClient())
                {
                    MaterialDataParameter p = new MaterialDataParameter()
                    {
                        ProductMaterialCode = model.ProductMaterialCode,
                        BomMaterialCode     = model.BomMaterialCode,
                        BomMaterialName     = model.BomMaterialName,
                        OutPackageNo        = model.OutPackageNo,
                        OutStartTime        = model.OutStartTime,
                        OutEndTime          = model.OutEndTime,
                        PageSize            = model.PageSize,
                        PageNo = 0
                    };
                    await Task.Run(() =>
                    {
                        MethodReturnResult <DataSet> ds = client.GetRPTMaterialData(ref p);
                        dt = ds.Data.Tables[0];
                    });
                }
            }
            #region 导出到EXCEL
            string     filePath = System.Web.HttpContext.Current.Server.MapPath("~/LotMaterialOutData.xlsx");
            FileStream fs       = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Read);
            //创建工作薄。
            IWorkbook wb = new XSSFWorkbook();
            //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 == 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
            }
            var ms = new NpoiMemoryStream();
            ms.AllowClose = false;
            wb.Write(fs);
            wb.Write(ms);
            ms.Flush();
            ms.Position   = 0;
            ms.AllowClose = false;
            return(File(ms, "application/vnd.ms-excel", "LotMaterialOutData.xlsx"));

            #endregion
        }