• OA项目之导出


    要导出页的前台:
    <asp:Button runat="server" ID="btnExport" Text="导出" CssClass="button_sm7"
                            onclick="btnExport_Click" />
    后台:
    protected void btnSearch_Click(object sender, EventArgs e)
            {
                   Response.Redirect("Export.aspx?uname=" + txtUNameS.Text + "&dep=" + this.ddlDepS.SelectedValue
                    + "&class=" + this.ddlClassS.SelectedValue + "&iyear=" + this.ddlYearS.SelectedValue);
            }

    Export.aspx (显示数据):
    <title>哎哎哎导出</title>
           <meta http-equiv="content-type" content="application/ms-excel; charset=UTF-8" />
    </head>
    <body>
        <form id="form1">
        <%
            string fileName = "哎哎哎.xls";  //导出后的文件名
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fileName));
           
        %>
        <table border="1" cellpadding="0" cellspacing="0">
            <tr align="center" style="font-weight: bold;">
                <td style=" 60px" rowspan="2">
                    序号
                </td>
                <td rowspan="2">
                    。。
                </td>
                <td rowspan="2">
                    。。
                </td>
                <td rowspan="2">
                    。。
                </td>
                <td rowspan="2">
                    。。
                </td>
                <td rowspan="2">
                    。。
                </td>
                <td rowspan="2">
                    。。
                </td>
                <td rowspan="2">
                    。。
                </td>
                <td colspan="4" style="text-align: center;">
                    。。
                </td>
            </tr>
            <tr>
                <td>
                    。。
                </td>
                <td>
                    。。
                </td>
                <td>
                    。。
                </td>
                <td>
                    。。
                </td>
            </tr>
            <asp:Repeater ID="rptStudentFee" runat="server">
                <ItemTemplate>
                    <tr>
                        <td>
                            <%#Eval("r_n") %>
                        </td>
                        <td>
                            <%#Eval("Department") %>
                        </td>
                        <td>
                            <%#Eval("CName") %>
                        </td>
                        <td>
                            '<%#Eval("TTCard") %>
                        </td>
                        <td>
                            <%#Eval("UName") %>
                        </td>
                        <td>
                            <%#DigitalCampus.Web.Common.pfunction.getPBCName(DigitalCampus.Web.Common.clsDictionaryData.Gender.ToString(),Eval("Gender").ToString()) %>
                        </td>
                        <td>
                            <%#DigitalCampus.Web.Common.pfunction.GetStrToShortDate(Eval("AdmissionDate").ToString())%>
                        </td>
                        <td>
                            <%#Eval("UName") %>
                        </td>
                        <td>
                            <%#Eval("SubYear")%>
                        </td>
                        <td>
                            <%#Eval("ShouldPayment")%>
                        </td>
                        <td>
                            <%#Eval("ActualPayment")%>
                        </td>
                        <td>
                            <%#Decimal.Parse(Eval("ShouldPayment").ToString()) - Decimal.Parse(Eval("ActualPayment").ToString())%>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
            <asp:Repeater runat="server" ID="rptCount">
                <ItemTemplate>
                    <tr style="font-weight: bold;">
                        <td>
                            合计
                        </td>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                           ¥ <%#Eval("ShouldPayment") %>
                        </td>
                        <td>
                           ¥ <%#Eval("ActualPayment")%>
                        </td>
                        <td>
                           ¥ <%#Decimal.Parse(Eval("ShouldPayment").ToString()) - Decimal.Parse(Eval("ActualPayment").ToString())%>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </table>
        </form>
    </body>
    </html>
    Export.aspx.cs(查数据):
    protected void Page_Load(object sender, EventArgs e)
            {
            
                if (!IsPostBack)
                {
                    GetFilesList();
                }
            }

            private void GetFilesList()
            {
                string sort = "";
                string strWhere = " where 1=1 ";
                if (!string.IsNullOrEmpty(Request["uname"]) && Request["uname"] != "TT卡号/身份证/姓名")
                {
                    strWhere += " and (vw.UName like '%" + Request["uname"] + "%' or vw.IdentityCard like '%" + Request["uname"] + "%' or vw.TTCard like '%" + Request["uname"] + "%')";
                }
                if (Request["dep"] != "-1")
                {
                    strWhere += " and vw.DepName='" + Request["dep"] + "'";
                }
                if (Request["class"] != "-1")
                {
                    strWhere += " and vw.ClassName='" + Request["class"] + "'";
                }
                if (Request["iyear"] != "-1")
                {
                    strWhere += " and sp.SubYear='" + Request["iyear"] + "'";
                }

                string strSql = @"select row_number() over(order by sp.SubYear,vw.DepName,vw.ClassName,vw.UName) as r_n,sp.*,vw.*
                        from (select StuID,SubYear,isnull(sum(ShouldPayment),0) ShouldPayment,isnull(sum(ActualPayment),0) ActualPayment from StudentShouldpay group by StuID,SubYear) sp inner join dbo.vw_StudentInfo vw on sp.StuID=vw.ID " + strWhere;
                DataTable dt = DbHelperSQL.Query(strSql).Tables[0];
                if (dt.Rows.Count == 0)
                {
                    Response.Write("<script>alert('数据不存在,导出失败!');history.back();</script>");
                    Response.End();
                }
                rptStudentFee.DataSource = dt;
                rptStudentFee.DataBind();
                if (dt.Rows.Count > 0)
                {
                    DataTable dt2 = new DataTable();
                    dt2 = DbHelperSQL.Query(@"select isnull(sum(ShouldPayment),0) ShouldPayment,isnull(sum(ActualPayment),0) ActualPayment from (select StuID,SubYear,isnull(sum(ShouldPayment),0) ShouldPayment,isnull(sum(ActualPayment),0) ActualPayment from StudentShouldpay group by StuID,SubYear) sp inner join dbo.vw_StudentInfo vw on sp.StuID=vw.ID " + strWhere).Tables[0];
                    rptCount.DataSource = dt2;
                    rptCount.DataBind();
                }

            }

  • 相关阅读:
    c++中sort等算法中比较操作的规则
    数据结构(c++)(1)-- 栈
    Problem 10: Summation of primes
    Problem 9: Special Pythagorean triplet
    Problem 7: 10001st prime
    Problem 8: Largest product in a series
    Problem 5: Smallest multiple
    Problem 6: Sum square difference
    Problem 4: Largest palindrome product
    Problem 3: Largest prime factor
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3290010.html
Copyright © 2020-2023  润新知