⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 counter.aspx

📁 ASP.net动画教程
💻 ASPX
字号:
<% @ Page Language="C#" %>
<% @ Import Namespace="System.Drawing" %>
<% @ Import Namespace="System.Drawing.Imaging" %>
<% @ Import Namespace="System.Drawing.Text" %>	 
<% @ Import Namespace="System.IO" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.SqlClient" %>
<Script Language="C#" Runat="Server">

public void Page_Load(Object src,EventArgs e)
{
	/*
		首先获得从外面传来的URL数据
		我们这里有两个数据
		username 表示用户名
		style	 表示计数器样式 	
	*/
	string UserName = Request.QueryString["username"];
	string Style	= Request.QueryString["style"];

	string  strFontName;		//字体名
	int		intFontSize;		//字体大小
	int		intWidth;			//图像宽
	int		intHeight;			//图像长

	//取得统计人数
	string strCount = GetUserCount(UserName);
	
	//根据样式确定字体和大小
	switch(Style)
	{
		case "1":
			strFontName = "仿宋_GB2312";
			intFontSize = 8;
			intWidth	= 40;
			intHeight	= 20;	
			break;
		case "2":
			strFontName = "宋体";
			intFontSize = 10;
			intWidth	= 50;
			intHeight	= 20;
			break;
		case "3":
			strFontName = "黑体";
			intFontSize = 12;
			intWidth	= 60;
			intHeight	= 25;
			break;
		case "4":
			strFontName = "楷体_GB2312";
			intFontSize = 100;
			intWidth	= 280;
			intHeight	= 30;
			break;
		default:
			strFontName = "新宋体";
			intFontSize = 10;
			intWidth	= 50;
			intHeight	= 20;
			break;
	}


	//背景颜色
	Color bgColor = Color.Yellow;
	//前景颜色
	Color foreColor = Color.Red;

	//字体产生
	Font foreFont = new Font(strFontName,intFontSize,FontStyle.Bold);

	/*
		从这里开始产生
		首先产生一个画布
	*/
	Bitmap newBitmap = new Bitmap(intWidth,intHeight,PixelFormat.Format32bppArgb);
	Graphics g = Graphics.FromImage(newBitmap);
	Rectangle newRect = new Rectangle(0,0,intWidth,intHeight);
	//涂上背景色
	g.FillRectangle(new SolidBrush(bgColor),newRect);
	//写字
	g.DrawString(strCount.ToString(),foreFont,new SolidBrush(foreColor),2,2);
	MemoryStream mStream = new MemoryStream();
	//存入MemoryStream
	newBitmap.Save(mStream,ImageFormat.Gif);
	g.Dispose();
	newBitmap.Dispose();
	//发送
	Response.ClearContent();
	Response.ContentType = "image/GIF";
	Response.BinaryWrite(mStream.ToArray());
	Response.End();
}

//取得用户的统计人数
private string GetUserCount(string UserName)
{
	//连结数据库
	string strProvider = "server=(local);database=aspcn;Trusted_Connection=yes";
	SqlConnection MyConn = new SqlConnection(strProvider);
	MyConn.Open();
	string strIndex = "select * from Counter where UserName='"+UserName+"'";
	SqlCommand MyComm = new SqlCommand(strIndex,MyConn);
	//读取数据
	SqlDataReader dr = MyComm.ExecuteReader();
	string Count;
	if(dr.Read())
	{
		Count = ((int)dr["Count"]+1).ToString();
		if(Count.Length<8)
		{
			for(int i=1;i<=8-Count.Length;i++)
				Count="0"+Count;
		}
		dr.Close();
		//更新Count值 
		string strUpdate = "Update Counter Set Count=Count+1 Where UserName='"+UserName+"'";
		SqlCommand MyUpdate = new SqlCommand(strUpdate,MyConn);
		MyUpdate.ExecuteNonQuery();

	}
	else
	{
		Count = "请确认用户名";
	}
	MyConn.Close();
	return Count;
		
}

</script>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -