KSBM_SQKSXS_QK.aspx (导出excel、导出时数字自动转化成科学计算的处理)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="KSBM_SQKSXS_QK.aspx.cs" Inherits="GSAO.KSBM.KSBM_SQKSXS_QK" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>考试报名统计</title>
    <link href="../css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
      <asp:Label ID="lb_function_desc" runat="server" Visible="false" >
    功能说明:统计每个考试的报名情况,显示每个考试报名情况,交费情况!<br/>
    操作表为:KSBM_SQKSXS,KSBM_KSXM.
    </asp:Label>
    <table width="99%" class="tbDefault mb5 mt5">
        <tr>
             <td class="tdRight bgEFEFEF" width="120">考试项目名称:</td>
             <td class="tdLeft">
               <asp:TextBox ID="tb_KSXMMC" runat="server" CssClass="txt mr10"  Width="200"></asp:TextBox>
                &nbsp;&nbsp;
                <asp:Button ID="btn_search" runat="server" Text="查 询" CssClass="btnStyle mr10" 
                     onclick="btn_search_Click" />
               <asp:Button ID="btn_export" runat="server" Text="导 出" CssClass="btnStyle mr10" onclick="btn_export_Click" 
                    />    
               <asp:Label ID="lb_total" runat="server"></asp:Label>
            </td>
        </tr>
      </table>
       <asp:GridView ID="GridView1" runat="server" CssClass="tbGvw" Width="99%"   AllowPaging="true"  
          AutoGenerateColumns="false"     BorderStyle="Solid"  BorderWidth="1" 
           BorderColor="Silver"       PageSize="20" onpageindexchanged="GridView1_PageIndexChanged" 
           onrowdatabound="GridView1_RowDataBound" 
           onpageindexchanging="GridView1_PageIndexChanging">
            <PagerSettings PageButtonCount="20" FirstPageText="[ 首页 ]" LastPageText="[ 末页 ]" 
               Mode="NextPreviousFirstLast" NextPageText="[ 下一页 ]" Position="TopAndBottom" 
               PreviousPageText="[ 上一页 ]"   />
         <PagerTemplate>
            <table width="100%"> <tr> <td style="text-align:left; color:#996600;"><asp:Label id="lblPageIndex" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页 共<asp:Label id="lblPageCount" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageCount %>' />页 <asp:linkbutton id="btnFirst" runat="server" causesvalidation="False" commandargument="First" ForeColor="#996600" Font-Bold="true" commandname="Page" text="首页" /> <asp:linkbutton id="btnPrev" runat="server" causesvalidation="False" ForeColor="#996600" Font-Bold="true"  commandargument="Prev" commandname="Page" text="上一页" /> <asp:linkbutton id="btnNext" runat="server" ForeColor="#996600" Font-Bold="true"  causesvalidation="False" commandargument="Next" commandname="Page" text="下一页" /> <asp:linkbutton id="btnLast" runat="server" ForeColor="#996600" Font-Bold="true"  causesvalidation="False" commandargument="Last" commandname="Page" text="尾页" /></td> </tr> </table>
         </PagerTemplate>
        <HeaderStyle CssClass="tbHeader" />
        <RowStyle HorizontalAlign="Center" Wrap="False" Height="25px" ></RowStyle>
        <Columns>
            <asp:BoundField HeaderText="姓名"  ItemStyle-Width="80px" DataField="XM"/>
            <asp:BoundField HeaderText="性别"  ItemStyle-Width="50px" DataField="XB"/>  
            <asp:BoundField HeaderText="学号"  ItemStyle-Width="60px" DataField="XH"/> 
            <asp:TemplateField HeaderText="证件类型" ItemStyle-Width="100">
                <ItemTemplate>
                    <asp:Label ID="lb_SFZJLX" runat="server" Text="身份证"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField HeaderText="证件号码"  ItemStyle-Width="100px" DataField="SFZJH" /> 
            <asp:BoundField HeaderText="院系"  ItemStyle-Width="120px" DataField="YXSMC"/> 
            <asp:BoundField HeaderText="专业名称"  ItemStyle-Width="120px" DataField="ZY_MC"/>
            <asp:BoundField HeaderText="培养层次"  ItemStyle-Width="120px" DataField="PYCCMC"/> 
            <asp:BoundField HeaderText="年级"  ItemStyle-Width="50px" DataField="NJ"/>
            <asp:BoundField HeaderText="考试项目名称"   ItemStyle-CssClass="tdLeft wordBreak" DataField="KSXMMC"/>
            <asp:BoundField HeaderText="考试日期" DataFormatString="{0:yyyy-MM-dd}"  ItemStyle-Width="100px" DataField="KSRQ"/>
            <asp:BoundField HeaderText="所需费用"  ItemStyle-Width="80px" DataField="SXFY"/>
            <asp:BoundField HeaderText="申请日期" DataFormatString="{0:yyyy-MM-dd}"  ItemStyle-Width="80px" DataField="SQRQ"/>
        </Columns>
        <PagerStyle  Font-Size="10pt"  BorderColor="White" Font-Bold="False" ForeColor="#996600"></PagerStyle> 
      </asp:GridView>
    </form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace GSAO.KSBM
{
    public partial class KSBM_SQKSXS_QK : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind_gv();
            }
        }

        private void Bind_gv()
        {
            string where = "1=1";
            if (tb_KSXMMC.Text != "")
                where += " and KSBM_KSXM.KSXMMC like '%" + tb_KSXMMC.Text + "%'";
            where += " order by KSBM_KSXM.KSRQ desc";
            DAL_GSAO_KSBM.Controller.KSBM_SQKSXS C_KSBM_SQKSXS = new DAL_GSAO_KSBM.Controller.KSBM_SQKSXS();
            DataSet ds = C_KSBM_SQKSXS.GetList_Join_All(where);
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();

            GridView1.Columns[10].Visible = false;
            GridView1.Columns[11].Visible = false;
            GridView1.Columns[12].Visible = false;

            lb_total.Text = "总计-" + ds.Tables[0].Rows.Count.ToString() + "-项";
        }
        protected void GridView1_PageIndexChanged(object sender, EventArgs e)
        {
            Bind_gv();
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "if(style.backgroundColor!='#ffffd0'){oldcolor=style.backgroundColor;style.backgroundColor='#c4e4ff';}");
                e.Row.Attributes.Add("onmouseout", "if(style.backgroundColor!='#ffffd0')style.backgroundColor=oldcolor;");
                e.Row.Attributes.Add("onmousedown", "if(style.backgroundColor=='#ffffd0')style.backgroundColor='white';else style.backgroundColor='#ffffd0';");
                //导出时数字自动转化成科学计算的处理
                e.Row.Cells[4].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
            }
        }
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            try
            {
                GridView1.PageIndex = e.NewPageIndex;
            }
            catch
            {
                GridView1.PageIndex = 0;
            }
        }
        protected void btn_search_Click(object sender, EventArgs e)
        {
            Bind_gv();
        }
        public override void VerifyRenderingInServerForm(Control control)
        {
            //base.VerifyRenderingInServerForm(control);
        }


        //导出
        protected void btn_export_Click(object sender, EventArgs e)
        {
            if (GridView1.Rows.Count == 0)
            {
                Common_GSAO.Tools.ShowAlert("数据不能为空!");
                return;
            }
            GridView1.Columns[10].Visible = true;
            GridView1.Columns[11].Visible = true;
            GridView1.Columns[12].Visible = true;
            
            string ExcelFile = "KSBMQK_" + System.DateTime.Now.ToString("yyyyMMddHHmmss");
            string header = @"<table><tr><td colspan=13><center><b><u><font size='3'>汕头大学考试报名情况汇总表</font></u></b></center></td></tr>"
                + "<tr><td colspan=10></td><td>导出时间:</td><td>" + DateTime.Now.ToShortDateString() + "</td></tr></table>";
            string bottomer = "";
            Common_GSAO.Tools.OutputExcel(GridView1, ExcelFile, header, bottomer, lb_total);

            GridView1.Columns[10].Visible = false;
            GridView1.Columns[11].Visible = false;
            GridView1.Columns[12].Visible = false;
        }
    }
}

 

posted @ 2014-06-09 16:38  linyongqin  阅读(281)  评论(0编辑  收藏  举报