コード例 #1
0
ファイル: StockController.cs プロジェクト: zjchenxk/SYLS
        public ActionResult ExportStocktaking()
        {
            //读取条件
            var request = HttpContext.Request;

            string warehouse = request.QueryString["Warehouse"] ?? string.Empty;
            string location = request.QueryString["Location"] ?? string.Empty;

            //读取库存数据
            string strErrText;
            StockSystem stock = new StockSystem();
            List<Stock> listStock = stock.LoadStocktakingByConditions(warehouse, location, LoginAccountId, LoginStaffName, out strErrText);
            if (listStock == null)
            {
                throw new Exception(strErrText);
            }

            //生成GridView数据源
            int nTotalPackages = 0;
            decimal decTotalTunnages = 0;
            decimal decTotalPiles = 0;
            decimal decTotalTenThousands = 0;

            List<Stock> listSource = new List<Stock>();

            //var grpWarehouses = from s in listStock
            //                    group s by s.Warehouse;
            var grpWarehouses = listStock.GroupBy(s => s.Warehouse).OrderBy(s => s.Key);
            foreach (var grpWarehouse in grpWarehouses)
            {
                string strWarehouse = grpWarehouse.Key;
                int nWarehouseTotalPackages = grpWarehouse.Sum(s => s.Packages);
                decimal decWarehouseTotalTunnages = grpWarehouse.Sum(s => s.Tunnages);
                decimal decWarehouseTotalPiles = grpWarehouse.Sum(s => s.Piles);
                decimal decWarehouseTotalTenThousands = grpWarehouse.Sum(s => s.TenThousands);

                nTotalPackages += nWarehouseTotalPackages;
                decTotalTunnages += decWarehouseTotalTunnages;
                decTotalPiles += decWarehouseTotalPiles;
                decTotalTenThousands += decWarehouseTotalTenThousands;

                //生成货位数据
                //var grpLocations = from s in listStock
                //                   where s.Warehouse == strWarehouse
                //                   group s by s.Location;
                var grpLocations = grpWarehouse.GroupBy(s => s.Location).OrderBy(s => s.Key);
                foreach (var grpLocation in grpLocations)
                {
                    string strLocation = grpLocation.Key;
                    int nLocationTotalPackages = grpLocation.Sum(s => s.Packages);
                    decimal decLocationTotalTunnages = grpLocation.Sum(s => s.Tunnages);
                    decimal decLocationTotalPiles = grpLocation.Sum(s => s.Piles);
                    decimal decLocationTotalTenThousands = grpLocation.Sum(s => s.TenThousands);

                    //生成货位明细数据
                    //var goods = from s in listStock
                    //            where s.Warehouse == strWarehouse && s.Location == strLocation
                    //            select new
                    //            {
                    //                s.GoodsNo,
                    //                s.GoodsName,
                    //                s.SpecModel,
                    //                s.GWeight,
                    //                s.Grade,
                    //                s.CustomerName,
                    //                s.Packages,
                    //                s.Tunnages
                    //            };

                    var goods = from s in grpLocation
                                select new
                                {
                                    s.GoodsNo,
                                    s.GoodsName,
                                    s.SpecModel,
                                    s.GWeight,
                                    s.Grade,
                                    s.CustomerName,
                                    s.Packages,
                                    s.Tunnages,
                                    s.Piles,
                                    s.TenThousands
                                };

                    foreach (var g in goods)
                    {
                        Stock g2 = new Stock();
                        g2.Warehouse = strWarehouse;
                        g2.Location = strLocation;
                        g2.GoodsNo = g.GoodsNo;
                        g2.GoodsName = g.GoodsName;
                        g2.SpecModel = g.SpecModel;
                        g2.GWeight = g.GWeight;
                        g2.Grade = g.Grade;
                        g2.CustomerName = g.CustomerName;
                        g2.Packages = g.Packages;
                        g2.Tunnages = g.Tunnages;
                        g2.Piles = g.Piles;
                        g2.TenThousands = g.TenThousands;
                        listSource.Add(g2);
                    }

                    //货位小计
                    Stock l = new Stock();
                    l.Warehouse = strWarehouse;
                    l.Location = strLocation;
                    l.GoodsNo = InnoSoft.LS.Resources.Labels.Subtotal;
                    l.Packages = nLocationTotalPackages;
                    l.Tunnages = decLocationTotalTunnages;
                    l.Piles = decLocationTotalPiles;
                    l.TenThousands = decLocationTotalTenThousands;
                    listSource.Add(l);
                }

                //仓库合计
                Stock w = new Stock();
                w.Warehouse = strWarehouse;
                w.Location = InnoSoft.LS.Resources.Labels.Total;
                w.Packages = nWarehouseTotalPackages;
                w.Tunnages = decWarehouseTotalTunnages;
                w.Piles = decWarehouseTotalPiles;
                w.TenThousands = decWarehouseTotalTenThousands;
                listSource.Add(w);
            }

            //总计
            Stock t = new Stock();
            t.Warehouse = InnoSoft.LS.Resources.Labels.FinalTotal;
            t.Packages = nTotalPackages;
            t.Tunnages = decTotalTunnages;
            t.Piles = decTotalPiles;
            t.TenThousands = decTotalTenThousands;
            listSource.Add(t);

            //生成GridView
            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 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 colSpecification = new BoundField();
            colSpecification.HeaderText = InnoSoft.LS.Resources.Labels.Specification;
            colSpecification.DataField = "SpecModel";

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

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

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

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

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

            var grid = new GridView();
            grid.Columns.Add(colWarehouse);
            grid.Columns.Add(colLocation);
            grid.Columns.Add(colGoodsNo);
            grid.Columns.Add(colGoodsName);
            grid.Columns.Add(colSpecification);
            grid.Columns.Add(colGrammeWeight);
            grid.Columns.Add(colGrade);
            grid.Columns.Add(colCustomerName);
            grid.Columns.Add(colPieces);
            grid.Columns.Add(colTunnages);
            grid.Columns.Add(colPiles);
            grid.Columns.Add(colTenThousands);
            grid.AutoGenerateColumns = false;

            grid.DataSource = from s in listSource
                              select new
                              {
                                  Warehouse = s.Warehouse,
                                  Location = s.Location,
                                  GoodsNo = s.GoodsNo,
                                  GoodsName = s.GoodsName,
                                  SpecModel = s.SpecModel,
                                  GWeight = s.GWeight,
                                  Grade = s.Grade,
                                  CustomerName = s.CustomerName,
                                  Packages = s.Packages > 0 ? s.Packages.ToString() : string.Empty,
                                  Tunnages = s.Tunnages > 0 ? s.Tunnages.ToString("#0.######") : string.Empty,
                                  Piles = s.Piles > 0 ? s.Piles.ToString("#0.######") : string.Empty,
                                  TenThousands = s.TenThousands > 0 ? s.TenThousands.ToString("#0.######") : string.Empty
                              };
            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=Stocktaking.xls");
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            grid.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();

            return View("PrintStocktaking");
        }
コード例 #2
0
ファイル: StockController.cs プロジェクト: zjchenxk/SYLS
        public ActionResult ExportStockEndDifferences()
        {
            string strErrText;

            var request = HttpContext.Request;

            string strCustomerName = request.QueryString["customerName"] ?? string.Empty;
            string strWarehouse = request.QueryString["warehouse"] ?? string.Empty;
            string strIsConsigning = request.QueryString["isConsigning"] ?? "false";

            //读取数据
            StockSystem stock = new StockSystem();
            List<Stock> listStock = stock.LoadStockEndDifferencesByConditions(strCustomerName, string.Empty, strWarehouse, strIsConsigning, string.Empty, LoginAccountId, LoginStaffName, out strErrText);
            if (listStock == null)
            {
                throw new Exception(strErrText);
            }

            //汇总
            List<Stock> listStat = new List<Stock>();
            {
                //按客户分组
                var grpCustomerNames = listStock.GroupBy(s => s.CustomerName).OrderBy(s => s.Key);
                foreach (var grpCustomerName in grpCustomerNames)
                {
                    List<Stock> listCustomerNameDetail = grpCustomerName.OrderBy(s => s.GoodsNo).ToList<Stock>();

                    listStat.AddRange(listCustomerNameDetail);

                    //小计
                    Stock subTotal = new Stock();
                    subTotal.CustomerName = InnoSoft.LS.Resources.Labels.Subtotal;
                    subTotal.Tunnages = listCustomerNameDetail.Sum(s => s.Tunnages);
                    listStat.Add(subTotal);
                }

                //总计
                Stock total = new Stock();
                total.CustomerName = InnoSoft.LS.Resources.Labels.Total;
                total.Tunnages = listStock.Sum(s => s.Tunnages);
                listStat.Add(total);
            }

            //生成GridView
            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 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 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 colTunnages = new BoundField();
            colTunnages.HeaderText = InnoSoft.LS.Resources.Labels.Tunnages;
            colTunnages.DataField = "Tunnages";

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

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

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

            var grid = new GridView();
            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(colBatchNo);
            grid.Columns.Add(colPacking);
            grid.Columns.Add(colWarehouse);
            grid.Columns.Add(colLocation);
            grid.Columns.Add(colTunnages);
            grid.Columns.Add(colProductionDate);
            grid.Columns.Add(colDeliveryNo);
            grid.Columns.Add(colEnterWarehouseBillNo);

            grid.AutoGenerateColumns = false;

            grid.DataSource = from s in listStat
                              select new
                              {
                                  CustomerName = s.CustomerName,
                                  GoodsNo = s.GoodsNo,
                                  GoodsName = s.GoodsName,
                                  Brand = s.Brand,
                                  SpecModel = s.SpecModel,
                                  GWeight = s.GWeight,
                                  Grade = s.Grade,
                                  BatchNo = s.BatchNo,
                                  Packing = s.Packing,
                                  Warehouse = s.Warehouse,
                                  Location = s.Location,
                                  Tunnages = s.Tunnages.ToString("#0.######"),
                                  ProductionDate = s.ProductionDate,
                                  DeliveryNo = s.DeliveryNo,
                                  EnterWarehouseBillNo = s.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=StockEndDifferences.xls");
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            grid.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();

            return View("SearchStockEndDifferences");
        }