/// <summary>
 /// 导出运单发票
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btn_DeriveSince_Click(object sender, EventArgs e)
 {
     HAWB hawb = _hawbService.FindHAWBByBarCode(Txt_BarCode.Text.Trim());
     var NpoiHelper = new NpoiHelper(hawb, Txt_BarCode.Text);
     NpoiHelper.ExportInvoice();
     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", Txt_BarCode.Text+"运单发票"), System.Text.Encoding.UTF8));
     HttpContext.Current.Response.BinaryWrite(data);
     HttpContext.Current.Response.Flush();
     HttpContext.Current.Response.End();
 }
 /// <summary>
 /// 导出承运单发票
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btn_DeriveAccept_Click(object sender, EventArgs e)
 {
     HAWB hawb = _hawbService.FindHAWBByBarCode(Txt_BarCode.Text.Trim());
     if (!string.IsNullOrEmpty(Txt_CarrierHAWBBarCode.Text))
     {
         var NpoiHelper = new NpoiHelper(hawb, Txt_CarrierHAWBBarCode.Text);
         NpoiHelper.ExportInvoice();
         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", Txt_BarCode.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>");
     }
 }
        /// <summary>
        /// 数据源操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Gv_HAWB_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            Guid id = (Guid)Session["UserID"];
            ModulePrivilege Authority = _SysUserManagementService.GetPrivilegeByUserid(id);           
            if (e.CommandName == "Eidt")
            {
                bool aPrivilege = (bool)Authority[Privilege.修改.ToString()];
                bool aPrivilege1 = (bool)Authority[Privilege.导出.ToString()];
                int index = Convert.ToInt32(e.CommandArgument);
                string barCode = Gv_HAWB.DataKeys[index].Value.ToString();
                Response.Redirect("HAWBDetails.aspx?BarCode=" + barCode + "&Privilege=" + aPrivilege + "&Privilege1=" + aPrivilege1 + "");
            }
            else if (e.CommandName == "Updata")
            {
                string barCode = e.CommandArgument.ToString();
                int Update = 1;
                Response.Redirect("HAWBAdd.aspx?BarCode=" + barCode + "&update=" + Update + "");
            }
            else if (e.CommandName == "Del")
            {
                string barCode = e.CommandArgument.ToString();
                //_hawbService.RemoveHAWB(barCode);
            }
            else if (e.CommandName == "Derive")
            {
                string barCode = e.CommandArgument.ToString();
                HAWB hawb = _hawbService.FindHAWBByBarCode(barCode);
                var NpoiHelper = new NpoiHelper(hawb, barCode);
                NpoiHelper.ExportInvoice();
                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 if (e.CommandName == "DeriveAccept")
            {
                int index = ((GridViewRow)((LinkButton)(e.CommandSource)).Parent.Parent).RowIndex;
                string CarrierHAWBBarCode = e.CommandArgument.ToString();
                string barCode = Gv_HAWB.DataKeys[index].Value.ToString();
                HAWB hawb = _hawbService.FindHAWBByBarCode(barCode);
                if (!string.IsNullOrEmpty(CarrierHAWBBarCode))
                {
                    var NpoiHelper = new NpoiHelper(hawb, CarrierHAWBBarCode);
                    NpoiHelper.ExportInvoice();
                    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);
                }
            }

        }