Beispiel #1
0
        public ActionResult ExportEnterWarehouseBills()
        {
            //读取条件
            var request = HttpContext.Request;

            string strStartTime = request.QueryString["startTime"] ?? string.Empty;
            string strEndTime = request.QueryString["endTime"] ?? string.Empty;
            string strCustomerName = request.QueryString["customerName"] ?? string.Empty;
            string strDeliveryNo = request.QueryString["deliveryNo"] ?? string.Empty;
            string strEnterWarehouseBillNo = request.QueryString["enterWarehouseBillNo"] ?? string.Empty;
            string strGoodsNo = request.QueryString["goodsNo"] ?? string.Empty;
            string strGoodsName = request.QueryString["goodsName"] ?? string.Empty;
            string strSpecModel = request.QueryString["specModel"] ?? string.Empty;
            string strBatchNo = request.QueryString["batchNo"] ?? string.Empty;
            string strEnterType = request.QueryString["enterType"] ?? string.Empty;
            string strWarehouse = request.QueryString["warehouse"] ?? string.Empty;
            string strIsConsigning = request.QueryString["isConsigning"] ?? "false";
            string strHasDrayage = request.QueryString["hasDrayage"] ?? "false";

            //读取数据
            string strErrText;
            StockSystem stock = new StockSystem();
            List<EnterWarehouseBillGoods> listGoods = stock.LoadEnterWarehouseBillGoodsByConditions(strStartTime, strEndTime, strCustomerName, strDeliveryNo, strEnterWarehouseBillNo, strGoodsNo, strGoodsName, strSpecModel, strBatchNo, strEnterType, strWarehouse, strIsConsigning, strHasDrayage, LoginAccountId, LoginStaffName, out strErrText);
            if (listGoods == null)
            {
                throw new Exception(strErrText);
            }

            //生成GridView
            BoundField colCreateTime = new BoundField();
            colCreateTime.HeaderText = InnoSoft.LS.Resources.Labels.EnterWarehouseTime;
            colCreateTime.DataField = "CreateTime";

            BoundField colEnterWarehouseBillNo = new BoundField();
            colEnterWarehouseBillNo.HeaderText = InnoSoft.LS.Resources.Labels.EnterWarehouseBillNo;
            colEnterWarehouseBillNo.DataField = "EnterWarehouseBillNo";

            BoundField colDeliveryNo = new BoundField();
            colDeliveryNo.HeaderText = InnoSoft.LS.Resources.Labels.DeliveryNo;
            colDeliveryNo.DataField = "DeliveryNo";

            BoundField colCustomerName = new BoundField();
            colCustomerName.HeaderText = InnoSoft.LS.Resources.Labels.CustomerName;
            colCustomerName.DataField = "CustomerName";

            BoundField colGoodsNo = new BoundField();
            colGoodsNo.HeaderText = InnoSoft.LS.Resources.Labels.GoodsNo;
            colGoodsNo.DataField = "GoodsNo";

            BoundField colGoodsName = new BoundField();
            colGoodsName.HeaderText = InnoSoft.LS.Resources.Labels.GoodsName;
            colGoodsName.DataField = "GoodsName";

            BoundField colBrand = new BoundField();
            colBrand.HeaderText = InnoSoft.LS.Resources.Labels.Brand;
            colBrand.DataField = "Brand";

            BoundField colSpecModel = new BoundField();
            colSpecModel.HeaderText = InnoSoft.LS.Resources.Labels.Specification;
            colSpecModel.DataField = "SpecModel";

            BoundField colGWeight = new BoundField();
            colGWeight.HeaderText = InnoSoft.LS.Resources.Labels.GrammeWeight;
            colGWeight.DataField = "GWeight";

            BoundField colGrade = new BoundField();
            colGrade.HeaderText = InnoSoft.LS.Resources.Labels.Grade;
            colGrade.DataField = "Grade";

            BoundField colPacking = new BoundField();
            colPacking.HeaderText = InnoSoft.LS.Resources.Labels.PackingSpecification;
            colPacking.DataField = "Packing";

            BoundField colBatchNo = new BoundField();
            colBatchNo.HeaderText = InnoSoft.LS.Resources.Labels.BatchNo;
            colBatchNo.DataField = "BatchNo";

            BoundField colWarehouse = new BoundField();
            colWarehouse.HeaderText = InnoSoft.LS.Resources.Labels.Warehouse;
            colWarehouse.DataField = "Warehouse";

            BoundField colLocation = new BoundField();
            colLocation.HeaderText = InnoSoft.LS.Resources.Labels.Location;
            colLocation.DataField = "Location";

            BoundField colPackages = new BoundField();
            colPackages.HeaderText = InnoSoft.LS.Resources.Labels.Pieces;
            colPackages.DataField = "Packages";

            BoundField colPieceWeight = new BoundField();
            colPieceWeight.HeaderText = InnoSoft.LS.Resources.Labels.PieceWeight;
            colPieceWeight.DataField = "PieceWeight";

            BoundField colTunnages = new BoundField();
            colTunnages.HeaderText = InnoSoft.LS.Resources.Labels.Tunnages;
            colTunnages.DataField = "Tunnages";

            BoundField colPiles = new BoundField();
            colPiles.HeaderText = InnoSoft.LS.Resources.Labels.Piles;
            colPiles.DataField = "Piles";

            BoundField colTenThousands = new BoundField();
            colTenThousands.HeaderText = InnoSoft.LS.Resources.Labels.TenThousands;
            colTenThousands.DataField = "TenThousands";

            BoundField colProductionDate = new BoundField();
            colProductionDate.HeaderText = InnoSoft.LS.Resources.Labels.ProductionDate;
            colProductionDate.DataField = "ProductionDate";

            var grid = new GridView();
            grid.Columns.Add(colCreateTime);
            grid.Columns.Add(colEnterWarehouseBillNo);
            grid.Columns.Add(colDeliveryNo);
            grid.Columns.Add(colCustomerName);
            grid.Columns.Add(colGoodsNo);
            grid.Columns.Add(colGoodsName);
            grid.Columns.Add(colBrand);
            grid.Columns.Add(colSpecModel);
            grid.Columns.Add(colGWeight);
            grid.Columns.Add(colGrade);
            grid.Columns.Add(colPacking);
            grid.Columns.Add(colBatchNo);
            grid.Columns.Add(colWarehouse);
            grid.Columns.Add(colLocation);
            grid.Columns.Add(colPackages);
            grid.Columns.Add(colPieceWeight);
            grid.Columns.Add(colTunnages);
            grid.Columns.Add(colPiles);
            grid.Columns.Add(colTenThousands);
            grid.Columns.Add(colProductionDate);

            grid.AutoGenerateColumns = false;

            grid.RowDataBound += new GridViewRowEventHandler(EnterWarehouseBillsGrid_RowDataBound);
            grid.DataSource = from g in listGoods
                              select new
                              {
                                  CreateTime = g.CreateTime.ToString("yyyy-MM-dd"),
                                  EnterWarehouseBillNo = g.EnterWarehouseBillNo,
                                  DeliveryNo = g.DeliveryNo,
                                  CustomerName = g.CustomerName,
                                  GoodsNo = g.GoodsNo,
                                  GoodsName = g.GoodsName,
                                  Brand = g.Brand,
                                  SpecModel = g.SpecModel,
                                  GWeight = g.GWeight,
                                  Grade = g.Grade,
                                  Packing = g.Packing,
                                  BatchNo = g.BatchNo,
                                  Warehouse = g.Warehouse,
                                  Location = g.Location,
                                  Packages = g.Packages.ToString(),
                                  PieceWeight = g.PieceWeight.ToString("#0.######"),
                                  Tunnages = g.Tunnages.ToString("#0.######"),
                                  Piles = g.Piles.ToString("#0.######"),
                                  TenThousands = g.TenThousands.ToString("#0.######"),
                                  ProductionDate = g.ProductionDate
                              };
            grid.DataBind();

            //导出GridView
            Response.ClearContent();
            Response.Charset = InnoSoft.LS.Resources.Encoding.ExcelCharset;
            Response.ContentEncoding = System.Text.Encoding.GetEncoding(InnoSoft.LS.Resources.Encoding.ExcelContent);
            Response.ContentType = "application/ms-excel";
            Response.Write("<meta http-equiv=Content-Type content=text/html charset=" + InnoSoft.LS.Resources.Encoding.ExcelCharset + ">");
            Response.AddHeader("content-disposition", "attachment; filename=EnterWarehouseBills.xls");
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            grid.RenderControl(htw);
            Response.Write(@"<style> .text { mso-number-format:'\@'; } </style>");//定义字符串转换样式
            Response.Write(sw.ToString());
            Response.End();

            return View("SearchEnterWarehouseBills");
        }
Beispiel #2
0
        public JsonResult LoadSearchEnterWarehouseBillsGrid(string sidx, string sord, int page, int rows, string startTime, string endTime, string customerName, string deliveryNo, string enterWarehouseBillNo, string goodsNo, string goodsName, string specModel, string batchNo, string enterType, string warehouse, string isConsigning, string hasDrayage)
        {
            //读取数据
            string strErrText;
            StockSystem stock = new StockSystem();
            List<EnterWarehouseBillGoods> listGoods = stock.LoadEnterWarehouseBillGoodsByConditions(startTime, endTime, customerName, deliveryNo, enterWarehouseBillNo, goodsNo, goodsName, specModel, batchNo, enterType, warehouse, isConsigning, hasDrayage, LoginAccountId, LoginStaffName, out strErrText);
            if (listGoods == null)
            {
                throw new Exception(strErrText);
            }

            //提取当前页面数据
            int nTotalRows = listGoods.Count;
            int nPageIndex = page;
            int nPageSize = rows;
            int nTotalPages = nTotalRows / nPageSize;
            if (nTotalRows % nPageSize > 0)
                nTotalPages++;

            string sortExpression = (sidx ?? "CreateTime") + " " + (sord ?? "ASC");
            var data = listGoods.OrderBy(sortExpression).Skip((nPageIndex - 1) * nPageSize).Take(nPageSize).ToList();

            //生成表格数据
            var ret = new
            {
                total = nTotalPages,
                page = nPageIndex,
                records = nTotalRows,
                rows = (
                      from g in data
                      select new
                      {
                          id = g.Id,
                          cell = new string[] {
                              g.Id.ToString(),
                              g.CreateTime.ToString("yyyy-MM-dd"),
                              g.EnterWarehouseBillId.ToString(),
                              g.EnterWarehouseBillNo,
                              g.DeliveryNo,
                              g.CustomerName,
                              g.EnterType,
                              g.GoodsNo,
                              g.GoodsName,
                              g.Brand,
                              g.SpecModel,
                              g.GWeight,
                              g.Grade,
                              g.Packing,
                              g.BatchNo,
                              g.Warehouse,
                              g.Location,
                              g.Packages.ToString(),
                              g.PieceWeight.ToString("#0.######"),
                              g.Tunnages.ToString("#0.######"),
                              g.Piles.ToString("#0.######"),
                              g.TenThousands.ToString("#0.######"),
                              g.ProductionDate
                          }
                      }).ToArray(),
                userdata = new
                {
                    CreateTime = InnoSoft.LS.Resources.Labels.Total,
                    Packages = data.Sum(s => s.Packages),
                    Tunnages = data.Sum(s => s.Tunnages),
                    Piles = data.Sum(s => s.Piles),
                    TenThousands = data.Sum(s => s.TenThousands)
                }
            };
            return Json(ret, JsonRequestBehavior.AllowGet);
        }