Exemple #1
0
        public ActionResult RenderToExcel(PubPage fg)
        {
            string sql = "select Telephone,Pwd from SystemUser";
            var    dt  = _iSysUserServices.ToDataTable(sql, null);

            string[] Telephone = { "手机号", "密码" };
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                dt.Columns[i].ColumnName = Telephone[i];
            }
            var ms   = NpoiHelper.RenderToExcel(dt);
            var xlsx = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            var xls  = "application/vnd.ms-excel";

            return(File(ms, xls, "用户信息" + DateTime.Now.ToString("yyyy-MM-dd") + ".xls"));
        }
 /// <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 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 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 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);
                }
            }

        }
 /// <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>");
     }
 }
        /// <summary>
        /// 导出报关文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport_Click(object sender, EventArgs e)
        {
            IList<HAWB> hawbs = new List<HAWB>();//实例化
            for (int i = 0; i < RGMAWB.MasterTableView.Items.Count; i++)
            {
                GridDataItem row = RGMAWB.MasterTableView.Items[i];
                if (((CheckBox)row.FindControl("CBSelect")).Checked)
                {
                    //获取选中的运单编号
                    string hawbBarcode =
                        RGMAWB.MasterTableView.DataKeyValues[row.ItemIndex]["BarCode"].ToString();
                    //获取运单信息
                    HAWB hawb = _hawbService.FindHAWBByBarCode(hawbBarcode);
                    hawbs.Add(hawb);
                }

            }

            MAWB mawb = _mawbService.FindMAWBByBarcode(MAWBNo);
            var NpoiHelper = new NpoiHelper(mawb, hawbs);
            NpoiHelper.ExportClearance();
            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.GetEncoding("GB2312");
            resp.ContentType = "application/ms-excel";
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("电子出口清单.xls", Encoding.UTF8));
            HttpContext.Current.Response.BinaryWrite(data);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }