争怎路由网:是一个主要分享无线路由器安装设置经验的网站,汇总WiFi常见问题的解决方法。

为.Text Blog 添加 计数器

时间:2024/7/5作者:未知来源:争怎路由网人气:

<%@ control language="C#" classname="DottextBlogCounter"  inherits="Dottext.Web.UI.Controls.BaseControl"%>
<
%@import namespace="System.Data" %>
<
%@import namespace="System.Data.SqlClient" %>
<
%@import namespace="Dottext.Framework.Data"%>
<script runat="server">
// DottextBlogCounter created on 4/25/2005 by:
//*daqingshu
http://blog.csdn.net/daqingshu

/// <summary>
/// Use session or cookie?
/// </summary>
void Page_Load(object sender, System.EventArgs e)

 string number = "";
 string strSQL = "";
 string conn = Dottext.Framework.Providers.DbProvider.Instance().ConnectionString;
 HttpCookie oldCookie = Request.Cookies["counter"];
 if(oldCookie == null)//if cookie exist,do not count
 {
  HttpCookie cookie = new HttpCookie("counter");
  DateTime dtNow = DateTime.Now;
  TimeSpan tsMinute = new TimeSpan(0, 1, 0, 0);//cookie expire time 1 hour
  cookie.Expires = dtNow + tsMinute;
  Response.Cookies.Add(cookie);  
  
  strSQL = "UPDATE blog_Config set PageVisitCount = PageVisitCount + 1";
  SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSQL, null);  
  
 }
 strSQL = "SELECT PageVisitCount FROM  blog_Config WHERE BlogID = " + Convert.ToInt32(CurrentBlog.BlogID);
 SqlDataReader rdr =  SqlHelper.ExecuteReader(conn, CommandType.Text, strSQL, null);
 if(rdr.Read()){
  number = rdr[0].ToString();
 }
 rdr.Close();
 
 if(number.Length <= 8)
 {
  for(int i = 8; i >= number.Length; --i)
  {
   number = "0" + number;
  }
 }
 
 NumberToPicture(number);
}

private void NumberToPicture(string number)
{
 System.Web.UI.WebControls.Literal Literal1 = new Literal();
 System.Web.UI.WebControls.Literal Literal2 = new Literal();
 Literal1.Text = "您是第"; 
 phImage.Controls.Add(Literal1); 
 if(number.Length > 0)
 {
  for(int i = 0; i < number.Length; ++i)
  {
   StringBuilder strImage = new StringBuilder();//maybe I missing the System.text namespace if it doesn't work
   strImage.Append("~/Images/counter/eggBlue/");
   strImage.Append(number[i]);
   strImage.Append(".gif");
   System.Web.UI.WebControls.Image image = new System.Web.UI.WebControls.Image();
   image.ID = "image" + i.ToString();   
   image.ImageUrl = strImage.ToString();
   phImage.Controls.Add(image);
  }
 
 }
 Literal2.Text = "位访客。";
 phImage.Controls.Add(Literal2); 
}

</script>
<asp:PlaceHolder runat="server" ID="phImage"></asp:PlaceHolder>
的确是个很简单很小的功能,还修改了数据库结构,在表blog_Config里面
添加PageVisitCount字段,使用的时候,需要修改PageTemplate.ascx文件,在里面添加
<%@ Register TagPrefix="overflow" TagName="DottextBlogCounter" Src="~/Skins/DottextBlogCounter.ascx" %>
合适的位置添加
<overflow:DottextBlogCounter id="DottextBlogCounter" runat="server"></overflow:DottextBlogCounter>



关键词:为.Text Blog 添加 计数器




Copyright © 2012-2018 争怎路由网(http://www.zhengzen.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版