示例#1
0
        public ActionResult ExportOutWarehouseBills()
        {
            //读取条件
            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 strOutWarehouseBillNo = request.QueryString["outWarehouseBillNo"] ?? string.Empty;
            string strGoodsNo = request.QueryString["goodsNo"] ?? string.Empty;
            string strBatchNo = request.QueryString["batchNo"] ?? string.Empty;
            string strCarNo = request.QueryString["carNo"] ?? string.Empty;
            string strReceiverName = request.QueryString["receiverName"] ?? string.Empty;
            string strOutType = request.QueryString["outType"] ?? string.Empty;
            string strWarehouse = request.QueryString["warehouse"] ?? string.Empty;
            string strReceiveType = request.QueryString["receiveType"] ?? string.Empty;

            //读取数据
            string strErrText;
            StockSystem stock = new StockSystem();
            List<OutWarehouseBillGoods> listGoods = stock.LoadOutWarehouseBillGoodsByConditions(strStartTime, strEndTime, strCustomerName, strDeliveryNo, strOutWarehouseBillNo, strGoodsNo, strBatchNo, strCarNo, strReceiverName, strOutType, strWarehouse, strReceiveType, LoginAccountId, LoginStaffName, out strErrText);
            if (listGoods == null)
            {
                throw new Exception(strErrText);
            }

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

            BoundField colOutWarehouseBillNo = new BoundField();
            colOutWarehouseBillNo.HeaderText = InnoSoft.LS.Resources.Labels.OutWarehouseBillNo;
            colOutWarehouseBillNo.DataField = "OutWarehouseBillNo";

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

            BoundField colCarNo = new BoundField();
            colCarNo.HeaderText = InnoSoft.LS.Resources.Labels.CarNo;
            colCarNo.DataField = "CarNo";

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

            BoundField colReceiverName = new BoundField();
            colReceiverName.HeaderText = InnoSoft.LS.Resources.Labels.ReceiverName;
            colReceiverName.DataField = "ReceiverName";

            BoundField colReceiverAddress = new BoundField();
            colReceiverAddress.HeaderText = InnoSoft.LS.Resources.Labels.ReceiverAddress;
            colReceiverAddress.DataField = "ReceiverAddress";

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

            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 colBatchNo = new BoundField();
            colBatchNo.HeaderText = InnoSoft.LS.Resources.Labels.BatchNo;
            colBatchNo.DataField = "BatchNo";

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

            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";

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

            var grid = new GridView();
            grid.Columns.Add(colCreateTime);
            grid.Columns.Add(colOutWarehouseBillNo);
            grid.Columns.Add(colDeliveryNo);
            grid.Columns.Add(colCarNo);
            grid.Columns.Add(colCustomerName);
            grid.Columns.Add(colReceiverName);
            grid.Columns.Add(colReceiverAddress);
            grid.Columns.Add(colWarehouse);
            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(colBatchNo);
            grid.Columns.Add(colPacking);
            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.Columns.Add(colEnterWarehouseBillNo);

            grid.AutoGenerateColumns = false;

            grid.RowDataBound += new GridViewRowEventHandler(OutWarehouseBillsGrid_RowDataBound);
            grid.DataSource = from g in listGoods
                              select new
                              {
                                  CreateTime = g.CreateTime.ToString("yyyy-MM-dd"),
                                  OutWarehouseBillNo = g.OutWarehouseBillNo,
                                  DeliveryNo = g.DeliveryNo,
                                  CarNo = g.CarNo,
                                  CustomerName = g.CustomerName,
                                  ReceiverName = g.ReceiverName,
                                  ReceiverAddress = g.ReceiverAddress,
                                  Warehouse = g.Warehouse,
                                  GoodsNo = g.GoodsNo,
                                  GoodsName = g.GoodsName,
                                  Brand = g.Brand,
                                  SpecModel = g.SpecModel,
                                  GWeight = g.GWeight,
                                  Grade = g.Grade,
                                  BatchNo = g.BatchNo,
                                  Packing = g.Packing,
                                  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,
                                  EnterWarehouseBillNo = g.EnterWarehouseBillNo
                              };
            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=OutWarehouseBills.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("SearchOutWarehouseBills");
        }
示例#2
0
        public JsonResult LoadSearchOutWarehouseBillsGrid(string sidx, string sord, int page, int rows, string startTime, string endTime, string customerName, string deliveryNo, string outWarehouseBillNo, string goodsNo, string batchNo, string carNo, string receiverName, string outType, string warehouse, string receiveType)
        {
            //读取数据
            string strErrText;
            StockSystem stock = new StockSystem();
            List<OutWarehouseBillGoods> listGoods = stock.LoadOutWarehouseBillGoodsByConditions(startTime, endTime, customerName, deliveryNo, outWarehouseBillNo, goodsNo, batchNo, carNo, receiverName, outType, warehouse, receiveType, 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.OutWarehouseBillId.ToString(),
                              g.OutWarehouseBillNo,
                              g.DeliveryNo,
                              g.CarNo,
                              g.CustomerName,
                              g.ReceiverName,
                              g.ReceiverProvince + g.ReceiverCity + g.ReceiverAddress,
                              g.Warehouse,
                              g.GoodsNo,
                              g.GoodsName,
                              g.Brand,
                              g.SpecModel,
                              g.GWeight,
                              g.Grade,
                              g.BatchNo,
                              g.ProductionDate,
                              g.Packing,
                              g.Location,
                              g.Packages.ToString(),
                              g.PieceWeight.ToString("#0.######"),
                              g.Tunnages.ToString("#0.######"),
                              g.Piles.ToString("#0.######"),
                              g.TenThousands.ToString("#0.######"),
                              g.EnterWarehouseBillNo
                          }
                      }).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);
        }