/// <summary> /// 数据源导出总运单和承运单清单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gv_HAWB_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Eidt") { Guid id = (Guid)Session["UserID"]; ModulePrivilege Authority = _sysUserManagementService.GetPrivilegeByUserid(id); bool aPrivilege = (bool)Authority[Privilege.修改.ToString()]; bool aPrivilege2 = (bool)Authority[Privilege.导出.ToString()]; bool aPrivilege1 = (bool)Authority[Privilege.解锁.ToString()]; Response.Redirect("MawbDetails.aspx?Privilege=" + aPrivilege + "&BarCode=" + e.CommandArgument + "&aPrivilege1=" + aPrivilege1 + "&aPrivilege2=" + aPrivilege2 + ""); } if (e.CommandName == "Derive") { string barcode = e.CommandArgument.ToString(); MAWB mawb = _mawbService.FindMAWBByBarcode(barcode); IList<HAWB> hawbs = _hawbService.FindHAWBsByMID(mawb.MID.ToString()); if (hawbs.Count != 0) { var NpoiHelper = new NpoiHelper(mawb, hawbs, ExportType.运单号); NpoiHelper.ExportMAWB(); var str = (MemoryStream)NpoiHelper.RenderToExcel(); if (str == null) return; var data = str.ToArray(); var resp = Page.Response; resp.Buffer = true; resp.Clear(); resp.Charset = "utf-8"; resp.ContentEncoding = System.Text.Encoding.UTF8; resp.ContentType = "application/ms-excel"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(String.Format("{0}.xls", barcode + "总运单清单"), System.Text.Encoding.UTF8)); HttpContext.Current.Response.BinaryWrite(data); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); } else { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('该总运单下没有运单,不能导出!')", true); } } else if (e.CommandName == "DeriveAccept") { string barcode = e.CommandArgument.ToString(); MAWB mawb = _mawbService.FindMAWBByBarcode(barcode); IList<HAWB> hawbs = _hawbService.FindHAWBsByMID(mawb.MID.ToString()); if (hawbs.Count != 0) { var NpoiHelper = new NpoiHelper(mawb, hawbs, ExportType.承运单号); NpoiHelper.ExportMAWB(); var str = (MemoryStream)NpoiHelper.RenderToExcel(); if (str == null) return; var data = str.ToArray(); var resp = Page.Response; resp.Buffer = true; resp.Clear(); resp.Charset = "utf-8"; resp.ContentEncoding = System.Text.Encoding.UTF8; resp.ContentType = "application/ms-excel"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(String.Format("{0}.xls", barcode + "承运清单"), System.Text.Encoding.UTF8)); HttpContext.Current.Response.BinaryWrite(data); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); } else { ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "", "alert('该总运单下没有运单,不能导出!')", true); } } }
/// <summary> /// 导出承运公司清单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_DeriveAccept_Click(object sender, EventArgs e) { MAWB mawb = _mawbService.FindMAWBByBarcode(lbl_MAWBBarCode.Text); IList<HAWB> hawbs = _hawbService.FindHAWBsByMID(mawb.MID.ToString()); if (hawbs.Count != 0) { var NpoiHelper = new NpoiHelper(mawb, hawbs, ExportType.承运单号); NpoiHelper.ExportMAWB(); var str = (MemoryStream)NpoiHelper.RenderToExcel(); if (str == null) return; var data = str.ToArray(); var resp = Page.Response; resp.Buffer = true; resp.Clear(); resp.Charset = "utf-8"; resp.ContentEncoding = System.Text.Encoding.UTF8; resp.ContentType = "application/ms-excel"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(String.Format("{0}.xls", lbl_MAWBBarCode.Text + "承运清单"), System.Text.Encoding.UTF8)); HttpContext.Current.Response.BinaryWrite(data); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('该总运单下没有运单,不能导出!')</script>"); } }