asp.net环境下的链接点击计数--方案3

来源:互联网 发布:淘宝客推广怎么操作 编辑:程序博客网 时间:2024/05/17 16:43

 文件opus.aspx:

 

<%@ Page Language="C#" AutoEventWireup="true" Inherits="opus" CodeFile="opus.aspx.cs" %>

<%@ Register TagPrefix="cc1" Namespace="LtpPageControl" Assembly="LtpPageControl" %>
<!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" />
    <script id="script1" type="text/javascript">

      function Hellow(id,pageindex)
      {
        window.location="CountClick.aspx?id="+id+"&Page="+pageindex;
      }
    </script>

    <%--<script id="script2" type="text/javascript" src="CountClick.aspx?id=4">//这里可以作方法4使用,
    function statistic()
    {
    }
    </script>--%>

</head>
<body>
    <form id="form1" runat="server">
        <%--        <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
            <Scripts>
                <asp:ScriptReference Path="~/activity/Clicks.js" />
            </Scripts>
            <Services>
                <asp:ServiceReference Path="~/WSClicks.asmx" />
            </Services>
        </asp:ScriptManager>--%>
        <div id="opus" style="width: 672px; height: 402px; background: #e5e5e5; padding: 40px 0 40px 51px;">
            <asp:Repeater ID="Repeater1" runat="server">
                <ItemTemplate>
                    <%--DisplaySWF.aspx?id=<%#Eval("FF_Id") %>--%>
                    <dl>
                        <%--/activity/flash/<%#Eval("FF_FileName") %> <script type='text/javascript' src='../displayswf.aspx&id=<%#Eval('FF_Id')%>'></script>--%>
                        <dt><a href="/activity/flash/<%#Eval("FF_FileName") %>" onclick="Hellow(<%#Eval("FF_Id")%>,<%=Page021.Page_Current %>)" target="_blank">
                            <img alt="" src="/activity/images/<%#Eval("FF_Thumnails")%>">
                        </a></dt>
                        <dd>
                            <a href="/activity/flash/<%#Eval("FF_FileName") %>" onclick="Hellow(<%#Eval("FF_Id")%>,<%=Page021.Page_Current %>)"
                                target="_blank">
                                <%#Eval("FF_Description")%>
                            </a>
                        </dd>
                    </dl>
                </ItemTemplate>
            </asp:Repeater>
            <br />
            <cc1:Page04 ID="Page021" runat="server" Page_Index="opus.aspx" Page_Size="9" Page_Width="622"
                Height="402px" Page_Background="images/bg_38.jpg" Tagp_Background="images/bg_38.jpg">
            </cc1:Page04>
        </div>
    </form>
</body>
</html>

 

opus.aspx.cs:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using Maticsoft;
//using System.Web.Services;

public partial class opus : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            InitStatus();
        }
        //根据分页显示
        if (!String.IsNullOrEmpty(Request.Params["Page"] ))
        {
            int current = Convert.ToInt32(Request.Params["Page"].ToString());
            DataBind(current);
            //Page011.Page_Current = current;
            Page021.Page_Current = current;
        }
        else
        {   //显示第1页
            DataBind(1);
        }
        //if (Session["conn"] == null)
        //{
        //    string conn = Maticsoft.DBUtility.DESEncrypt.Decrypt(ConfigurationManager.AppSettings.Get("ConnectionString"));
        //    Session["conn"] = conn;
        //}
    }
    public string GetThumnails(object filename)
    {
        string strFileName = filename.ToString();
        if ((new Regex(".swf")).IsMatch(strFileName))
        {
            return strFileName.Substring(0, strFileName.Length - 4);
        }
        else
            return strFileName;
    }
    /// <summary>
    /// 初始化页面状态
    /// </summary>
    /// <param name="PageSize"></param>
    /// <param name="Count"></param>
    private void InitStatus()
    {
        int iCountPerPage = Convert.ToInt32(ConfigurationManager.AppSettings.Get("CountPerPage"));
        //当配置文件中的CountPerPage为空或非法字符串时,设默认值为10
        if (iCountPerPage == 0) iCountPerPage = 9;
        Tb_FlashFile bll = new Tb_FlashFile();
        int Count = bll.GetCount();
        int PageCount = int.Parse(Math.Ceiling((double)Count / iCountPerPage).ToString());
        //this.Page011.Record_Count = Count;
        //页面总数
        //Page011.Page_Count = PageCount;
        Page021.Page_Count = PageCount;
        //设置每页显示10条记录
        //Page011.Page_Size = iCountPerPage;
        Page021.Page_Size = iCountPerPage;
        //初始化分页界面
        //Page011.Page_Width = 600;
        Page021.PageStep = 1;
        //Page021.Page_Width = 572;
    }
    /// <summary>
    /// 绑定数据
    /// </summary>
    /// <param name="pageIndex"></param>
    private void DataBind(int pageIndex)
    {
        Tb_FlashFile bbl = new Tb_FlashFile();

        DataSet ds = bbl.GetListForFrontByPageIndex(pageIndex);
        //grid.CurrentPageIndex = pageIndex;
        Repeater1.DataSource = ds;
        Repeater1.DataBind();
    }
    //[WebMethod]
    //public static void IncreaseClicks(object FF_Id)
    //{
    //    int id = Convert.ToInt32(FF_Id);
    //    Tb_FlashFile bll = new Tb_FlashFile();
    //    bll.GetModel(id);
    //    bll.FF_Clicks += 1;
    //    bll.Update();

    //}

}

 


(下面的两个文件--CountClick.aspx和CountClick.aspx.cs仅作后台使用,不显示,通过Response.Redirect实现页面加载后即关闭)

CountClick.aspx:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CountClick.aspx.cs" Inherits="activity_CountClick" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
</body>

</html>

 

CountClick.aspx.cs:(该文件实现链接计数功能)

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic;
using Maticsoft;
public partial class activity_CountClick : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.Params["id"] == null ||
                !Information.IsNumeric(Request.Params["id"])) return;
            Tb_FlashFile bbl = new Tb_FlashFile();
            bbl.GetModel(Convert.ToInt32(Request.Params["id"]));
            bbl.FF_Clicks = bbl.FF_Clicks + 1;
            bbl.Update();

            Response.Redirect("opus.aspx?Page=" + Request.Params["Page"]);//通过页面跳转的方式实现页面隐藏,

            //仅仅执行它的后台代码
        }
    }
}

原创粉丝点击