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

📄 sqlstatloger.cs

📁 精通网络应用系统开发 光盘 该书是人民邮电出版社出版的
💻 CS
字号:
using System;
using webvisitStatistic;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using webvisitStatistic.Reporter.IPLook;
namespace webvisitStatistic.HitsHandler.DBLayer
{
	/// <summary>
	/// SqlStatLogger 的摘要说明。
	/// </summary>
	public class SqlStatLogger :	StatLoggerBaseImpl
	{

		public SqlStatLogger()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}

		#region IStatLogger 成员

		public override bool Init(String conn)
		{
			// TODO:  添加 SqlStatLogger.Init 实现
			if(null!=connString) return true;
			else
			{
				connString = conn;			
				if(connString==null) 
				{
					throw new Exception("获取数据库连接字符串失败");
				}
				return true;
			}
		}

		public override void Log(StatInfo statInfo)
		{
			// TODO:  添加 SqlStatLogger.webvisitStatistic.DBLayer.IStatLogger.Log 实现
			using(SqlConnection conn = new SqlConnection(connString))
			{
				SqlCommand cmd = conn.CreateCommand();
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.CommandText = sqlAddStatJournel;
				cmd.Parameters.Add("@webid",SqlDbType.BigInt).Value = statInfo.WebId;
				cmd.Parameters.Add("@ip",SqlDbType.Char,15).Value = IPFormat(statInfo.ClientIP);				
				cmd.Parameters.Add("@url",SqlDbType.Char,256).Value = statInfo.URL;
				cmd.Parameters.Add("@vtime",SqlDbType.DateTime,8).Value = statInfo.Time;
				cmd.Parameters.Add("@defLang",SqlDbType.Char,10).Value = statInfo.UserLanguage;
				cmd.Parameters.Add("@refurl",SqlDbType.Char,256).Value = statInfo.RefUrl;
				cmd.Parameters.Add("@client",SqlDbType.Int).Value = statInfo.Client.Code;
				// ippos
				IpLookTable iplooktable = IpLookTable.Instance();
				int index = iplooktable.SearchRangeOfStartIp(ParseIP(statInfo.ClientIP));
				if (-1!=index) {
					cmd.Parameters.Add("@ippos" ,SqlDbType.BigInt ).Value = iplooktable.Items[index].sip;
				}else{
					cmd.Parameters.Add("@ippos" ,SqlDbType.BigInt ).Value = -2;	// invalid value
				}

				conn.Open();
				cmd.ExecuteNonQuery();

			}
		}

		#endregion



		private String connString;
		private String sqlAddStatJournel = "AddStatJournel";
	}

}

⌨️ 快捷键说明

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