| | |
| | | using CY.Infrastructure.Common; |
| | | using CY.BLL; |
| | | using CY.WebForm.Pages.common; |
| | | using System.IO; |
| | | using CY.Infrastructure.Query; |
| | | using NPOI.SS.UserModel; |
| | | using NPOI.XSSF.UserModel; |
| | | |
| | | namespace CY.WebForm.Pages.business |
| | | { |
| | |
| | | { |
| | | try |
| | | { |
| | | if (Request["isSession"] != null) |
| | | { |
| | | if (!IsPostBack && !IsCallback) |
| | | Session["OrderList"] = null; |
| | | } |
| | | if (Request["downId"] != null) |
| | | { |
| | | int iDownId = Convert.ToInt32(Request["downId"]); |
| | |
| | | return isCan; |
| | | } |
| | | |
| | | |
| | | //查询事件 |
| | | protected void btn_Daochu_Click(object src, EventArgs e) |
| | | { |
| | | |
| | | byte[] fileBytes = ExportToExcel(); |
| | | if (fileBytes != null) |
| | | { |
| | | Response.Clear(); |
| | | Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; |
| | | Response.AppendHeader("Content-Disposition", "attachment; filename=订单导出.xlsx"); |
| | | Response.BinaryWrite(fileBytes); |
| | | Response.End(); |
| | | } |
| | | else |
| | | { |
| | | // 处理导出失败的情况 |
| | | Response.Write("导出失败,请稍后重试!"); |
| | | } |
| | | |
| | | } |
| | | |
| | | public byte[] ExportToExcel() |
| | | { |
| | | byte[] bt = null; |
| | | try |
| | | { |
| | | Pagination pa = new Pagination(); |
| | | pa.PageSize = 500; |
| | | pa.PageIndex = 1; |
| | | |
| | | Dictionary<int, object> searchParam = new Dictionary<int, object>(); |
| | | |
| | | SetParamValue(searchParam, 1, CurrentUser.MemberId); |
| | | SetParamValue(searchParam, 2, this.txtOrderId.Value.Trim()); |
| | | SetParamValue(searchParam, 3, this.txtCustormerName.Value.Trim()); |
| | | SetParamValue(searchParam, 4, this.txtBeginData.Value.Trim()); |
| | | SetParamValue(searchParam, 5, this.txtEndDate.Value.Trim()); |
| | | SetParamValue(searchParam, 6, this.selPrintTypes.Value); |
| | | SetParamValue(searchParam, 7, this.selOrderTypes.Value); |
| | | SetParamValue(searchParam, 8, this.selOrderStates.Value); |
| | | SetParamValue(searchParam, 9, this.selPayStates.Value); |
| | | SetParamValue(searchParam, 10, this.txtCreaterName.Value.Trim()); |
| | | SetParamValue(searchParam, 11, this.selCustormerLevels.Value); |
| | | SetParamValue(searchParam, 12, this.selCustormerManager.Value); |
| | | SetParamValue(searchParam, 13, this.selBusinessManager.Value); |
| | | SetParamValue(searchParam, 14, this.selPayType.SelectedValue); |
| | | SetParamValue(searchParam, 15, this.selReturnvisit.SelectedValue); |
| | | SetParamValue(searchParam, 16, this.selAppraise.SelectedValue); |
| | | SetParamValue(searchParam, 18, (CurrentUser.StaffId > 0 ? 0 : 0)); |
| | | SetParamValue(searchParam, 19, CurrentUser.TrueMemberId); |
| | | SetParamValue(searchParam, 20, CurrentUser.StaffId); |
| | | SetParamValue(searchParam, 21, CurrentUser.TrueName); |
| | | SetParamValue(searchParam, 28, this.txtSearchyjname.Value); |
| | | |
| | | var oA_WorkPlans = _eC_OrderBasicBLL.SelectModelPage_Seller(pa, searchParam); |
| | | |
| | | |
| | | // 创建工作簿 |
| | | IWorkbook workbook = new XSSFWorkbook(); |
| | | ISheet sheet = workbook.CreateSheet("导出数据"); |
| | | |
| | | // 创建表头 |
| | | IRow headerRow = sheet.CreateRow(0); |
| | | headerRow.CreateCell(0).SetCellValue("编号"); |
| | | headerRow.CreateCell(1).SetCellValue("订单号"); |
| | | headerRow.CreateCell(2).SetCellValue("客户名称"); |
| | | headerRow.CreateCell(3).SetCellValue("订单来源"); |
| | | headerRow.CreateCell(4).SetCellValue("订单类别"); |
| | | headerRow.CreateCell(5).SetCellValue("合同序号"); |
| | | headerRow.CreateCell(6).SetCellValue("印件名称"); |
| | | headerRow.CreateCell(7).SetCellValue("数量"); |
| | | headerRow.CreateCell(8).SetCellValue("单位"); |
| | | headerRow.CreateCell(9).SetCellValue("订单状态"); |
| | | headerRow.CreateCell(10).SetCellValue("收款状态"); |
| | | headerRow.CreateCell(11).SetCellValue("付款方式"); |
| | | headerRow.CreateCell(12).SetCellValue("金额"); |
| | | headerRow.CreateCell(13).SetCellValue("已收款"); |
| | | headerRow.CreateCell(14).SetCellValue("未付款"); |
| | | |
| | | // 添加数据 |
| | | int rowIndex = 1; |
| | | foreach (var order in oA_WorkPlans) |
| | | { |
| | | IRow row = sheet.CreateRow(rowIndex++); |
| | | row.CreateCell(0).SetCellValue((rowIndex - 1).ToString()); |
| | | row.CreateCell(1).SetCellValue(order.SellerOrderId); |
| | | row.CreateCell(2).SetCellValue(order.BuyerName); |
| | | row.CreateCell(3).SetCellValue(order.OrderType.Name); |
| | | row.CreateCell(4).SetCellValue(order.PrintType.PrintName); |
| | | row.CreateCell(5).SetCellValue(order.Duiyinghetongbianhao); |
| | | row.CreateCell(6).SetCellValue(order.DocumentName); |
| | | row.CreateCell(7).SetCellValue(order.OrderExtend.PrintNum.HasValue? order.OrderExtend.PrintNum.Value:0); |
| | | row.CreateCell(8).SetCellValue(order.yssldw); |
| | | row.CreateCell(9).SetCellValue(order.OrderStateObj.Name); |
| | | row.CreateCell(10).SetCellValue(order.PayStateObj.Name); |
| | | row.CreateCell(11).SetCellValue(order.PayType); |
| | | row.CreateCell(12).SetCellValue(order.SumPrice.HasValue? order.SumPrice.Value.ToDouble2().Value:0); |
| | | row.CreateCell(13).SetCellValue(order.TradingSingle.PayedMoney.HasValue ? order.TradingSingle.PayedMoney.Value.ToDouble2().Value : 0); |
| | | row.CreateCell(14).SetCellValue(order.UnPayedMoney.ToDouble2().Value); |
| | | |
| | | |
| | | } |
| | | |
| | | // 将工作簿写入内存流 |
| | | using (var ms = new MemoryStream()) |
| | | { |
| | | workbook.Write(ms); |
| | | bt = ms.ToArray(); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | bt = null; |
| | | // 记录日志 |
| | | |
| | | } |
| | | return bt; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 是否已经操作 |
| | | /// </summary> |