示例#1
0
        public JsonResult LoadSearchStockEndDifferencesGrid(string sidx, string sord, int page, int rows, string customerName, string warehouse, string isConsigning)
        {
            //读取数据
            string strErrText;
            StockSystem stock = new StockSystem();
            List<Stock> listStock = stock.LoadStockEndDifferencesByConditions(customerName, string.Empty, warehouse, isConsigning, string.Empty, LoginAccountId, LoginStaffName, out strErrText);
            if (listStock == null)
            {
                throw new Exception(strErrText);
            }

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

            var data = listStock.OrderBy(s => s.CustomerName).ThenBy(s => s.GoodsNo).Skip((nPageIndex - 1) * nPageSize).Take(nPageSize).ToList();

            //生成表格数据
            var ret = new
            {
                total = nTotalPages,
                page = nPageIndex,
                records = nTotalRows,
                rows = (
                      from s in data
                      select new
                      {
                          id = s.Id,
                          cell = new string[] {
                              s.CustomerName,
                              s.GoodsNo,
                              s.GoodsName,
                              s.Brand,
                              s.SpecModel,
                              s.GWeight,
                              s.Grade,
                              s.BatchNo,
                              s.Packing,
                              s.Warehouse,
                              s.Location,
                              s.Tunnages.ToString("#0.######"),
                              s.ProductionDate,
                              s.DeliveryNo,
                              s.EnterWarehouseBillNo
                          }
                      }).ToArray(),
                userdata = new
                {
                    CustomerName = InnoSoft.LS.Resources.Labels.Total,
                    Tunnages = data.Sum(s => s.Tunnages)
                }
            };
            return Json(ret, JsonRequestBehavior.AllowGet);
        }
示例#2
0
        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");
        }