public JsonResult LoadSearchDeliverBillReceiptsGrid(string sidx, string sord, int page, int rows, string startTime, string endTime, string customerName, string deliveryNo, string carNo, string destCountry, string destProvince, string destCity, string organId) { //读取数据 string strErrText; DeliverSystem deliver = new DeliverSystem(); List<DeliverBill> listDeliverBill = deliver.LoadDeliverBillReceiptsByConditions(startTime, endTime, customerName, deliveryNo, carNo, destCountry, destProvince, destCity, organId, LoginAccountId, LoginStaffName, out strErrText); if (listDeliverBill == null) { throw new Exception(strErrText); } //提取当前页面数据 int nTotalRows = listDeliverBill.Count; int nPageIndex = page; int nPageSize = rows; int nTotalPages = nTotalRows / nPageSize; if (nTotalRows % nPageSize > 0) nTotalPages++; string sortExpression = (sidx ?? "BillNo") + " " + (sord ?? "ASC"); var data = listDeliverBill.OrderBy(sortExpression).Skip((nPageIndex - 1) * nPageSize).Take(nPageSize).ToList(); //生成表格数据 var ret = new { total = nTotalPages, page = nPageIndex, records = nTotalRows, rows = ( from b in data select new { id = b.Id, cell = new string[] { b.Id.ToString(), b.BillNo, b.CreateTime.ToString("yyyy-MM-dd"), b.CustomerName, b.DeliveryNo, b.ReceiverCity, b.ReceiverName, b.CarNo, b.TotalPackages.ToString(), b.TotalTunnages.ToString("#0.######"), b.TotalPiles.ToString("#0.######"), b.TotalTenThousands.ToString("#0.######"), b.ReturnTime.ToString("yyyy-MM-dd"), b.DamageInfo } }).ToArray() }; return Json(ret, JsonRequestBehavior.AllowGet); }
public ActionResult ExportDeliverBillReceipts() { string strErrText; //提取查询条件 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 strCarNo = request.QueryString["carNo"] ?? string.Empty; string strDestCountry = request.QueryString["destCountry"] ?? string.Empty; string strDestProvince = request.QueryString["destProvince"] ?? string.Empty; string strDestCity = request.QueryString["destCity"] ?? string.Empty; string strOrganId = request.QueryString["organId"] ?? string.Empty; //读取回单数据 DeliverSystem deliver = new DeliverSystem(); List<DeliverBill> listDeliverBill = deliver.LoadDeliverBillReceiptsByConditions(strStartTime, strEndTime, strCustomerName, strDeliveryNo, strCarNo, strDestCountry, strDestProvince, strDestCity, strOrganId, LoginAccountId, LoginStaffName, out strErrText); if (listDeliverBill == null) { throw new Exception(strErrText); } //生成GridView BoundField colDeliverBillNo = new BoundField(); colDeliverBillNo.HeaderText = InnoSoft.LS.Resources.Labels.DeliverBillNo; colDeliverBillNo.DataField = "BillNo"; BoundField colDeliverDate = new BoundField(); colDeliverDate.HeaderText = InnoSoft.LS.Resources.Labels.DeliverDate; colDeliverDate.DataField = "CreateTime"; BoundField colCustomerName = new BoundField(); colCustomerName.HeaderText = InnoSoft.LS.Resources.Labels.CustomerName; colCustomerName.DataField = "CustomerName"; BoundField colDeliveryNo = new BoundField(); colDeliveryNo.HeaderText = InnoSoft.LS.Resources.Labels.DeliveryNo; colDeliveryNo.DataField = "DeliveryNo"; BoundField colReceiverCity = new BoundField(); colReceiverCity.HeaderText = InnoSoft.LS.Resources.Labels.DestPlace; colReceiverCity.DataField = "ReceiverCity"; BoundField colReceiverName = new BoundField(); colReceiverName.HeaderText = InnoSoft.LS.Resources.Labels.ReceiverName; colReceiverName.DataField = "ReceiverName"; BoundField colCarNo = new BoundField(); colCarNo.HeaderText = InnoSoft.LS.Resources.Labels.CarNo; colCarNo.DataField = "CarNo"; BoundField colPackages = new BoundField(); colPackages.HeaderText = InnoSoft.LS.Resources.Labels.Pieces; colPackages.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"; BoundField colReturnTime = new BoundField(); colReturnTime.HeaderText = InnoSoft.LS.Resources.Labels.ReturnTime; colReturnTime.DataField = "ReturnTime"; BoundField colDamageInfo = new BoundField(); colDamageInfo.HeaderText = InnoSoft.LS.Resources.Labels.DamageInfo; colDamageInfo.DataField = "DamageInfo"; var grid = new GridView(); grid.Columns.Add(colDeliverBillNo); grid.Columns.Add(colDeliverDate); grid.Columns.Add(colCustomerName); grid.Columns.Add(colDeliveryNo); grid.Columns.Add(colReceiverCity); grid.Columns.Add(colReceiverName); grid.Columns.Add(colCarNo); grid.Columns.Add(colPackages); grid.Columns.Add(colTunnages); grid.Columns.Add(colPiles); grid.Columns.Add(colTenThousands); grid.Columns.Add(colReturnTime); grid.Columns.Add(colDamageInfo); grid.AutoGenerateColumns = false; grid.DataSource = from bill in listDeliverBill select new { BillNo = bill.BillNo, CreateTime = bill.CreateTime.ToString("yyyy-MM-dd"), CustomerName = bill.CustomerName, DeliveryNo = bill.DeliveryNo, ReceiverCity = bill.ReceiverCity, ReceiverName = bill.ReceiverName, CarNo = bill.CarNo, Packages = bill.TotalPackages > 0 ? bill.TotalPackages.ToString() : string.Empty, Tunnages = bill.TotalTunnages > 0 ? bill.TotalTunnages.ToString("#0.######") : string.Empty, Piles = bill.TotalPiles > 0 ? bill.TotalPiles.ToString("#0.######") : string.Empty, TenThousands = bill.TotalTenThousands > 0 ? bill.TotalTenThousands.ToString("#0.######") : string.Empty, ReturnTime = bill.ReturnTime.ToString("yyyy-MM-dd"), DamageInfo = bill.DamageInfo }; 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=DeliverBillReceipts.xls"); StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); grid.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); return View("SearchDeliverBillReceipts"); }