文章访问的历史记录 创建:章学敏 2007-06-16
#region 文章访问的历史记录 创建:章学敏 2007-06-16
/**//// <summary>
/// 获取文章的最新浏览用户
/// 章学敏
/// 2007-6-16
/// </summary>
/// <param name="articleID">文章ID</param>
/// <param name="userID">用户ID</param>
/// <returns></returns>
public IList<Forum_AuthorInfo> GetLastViewers(string articleID,string userID)
...{
IList<Forum_AuthorInfo> lastViewer = new List<Forum_AuthorInfo>();
//如果是匿名用户,则不更新浏览记录
if (Convert.ToInt32(userID) == 0)
...{}
else
...{
UpdateLastViewer(userID, articleID);
}
string users = GetLastViewUsers(articleID);
if (string.IsNullOrEmpty(users))
...{
lastViewer = null;
}
else
...{
string[] userlist = users.Split(',');
for (int i = userlist.Length - 1; i >= 0; i--)
...{
SqlDataReader sdr = null;
int UserID = Convert.ToInt32(userlist[i]);
SqlParameter param = MakeSqlInParameter(POST_USERID, UserID);
sdr = RunReaderProcedure("Forum_GetAuthorInfoByAuthorID", param);
while (sdr.Read())
...{
lastViewer.Add(new Forum_AuthorInfo(sdr.GetInt32(0), "1", "1", sdr.GetString(1), "1", sdr.GetString(2), "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1"));//修改存储过程可以扩展
}
sdr.Close();
sdr.Dispose();
}
}
return lastViewer;
}
/**//// <summary>
/// 获取数据库中的最近访问的用户
/// 章学敏
/// 2007-6-16
/// </summary>
/// <param name="articleID">文章的ID</param>
/// <param name="userID">用户ID</param>
/// <returns></returns>
private string GetLastViewUsers(string articleID)
...{
SqlParameter param = MakeSqlInParameter(POST_ID, articleID); //读取前的跟新
try
...{
string users = RunScalar("Forum_GetLastViewUsers", param);
return users;
}
catch ...{ return " "; }
}
/**//// <summary>
/// 跟新文章的访问
/// 章学敏
/// 2007-06-15
/// </summary>
/// <param name="userID"></param>
/// <param name="articleID"></param>
private void UpdateLastViewer(string userID,string articleID)
...{
string LastViews=GetLastViewUser(GetLastViewUsers(articleID),userID);
SqlParameter[] paramList =...{MakeSqlInParameter("@LastViewUsers",LastViews),
MakeSqlInParameter(POST_ID,articleID)};
RunNoneQueryProcedure("Forum_UpdateLastViewers", paramList);
}
/**//// <summary>
/// 截取文章最近访问的6个人
/// 章学敏
/// 2007-06-15
/// <remarks>
/// 该函数主要是实现对访问某一文章的人进行记录和添加
/// 如果访问人数是制定的访问人数
/// 如果是第一次访问
/// 如果访问人数为达到制定的人数
/// 三种情况
/// </remarks>
/// </summary>
private string GetLastViewUser(string lastViewUser,string userID)
...{
int selectValue = 6;
int i = 0;
int j = 20;
int t = 0;
int flag = 0;
int k = selectValue;
string[] temp1 = lastViewUser.Split(',');
string result = "";
if (temp1.Length < selectValue)
...{
k = temp1.Length + 1;
}
else
...{
k = selectValue;
}
string[] temp2 = new string[k];
for (i = 0; i < temp1.Length; i++)
...{
if (temp1[i] == userID)
...{
j = i;
flag = 1;
break;
}
}
if (j == 20)
...{
if (string.IsNullOrEmpty(lastViewUser))
...{
temp2[0] = userID;
}
else
...{
if (temp1.Length != selectValue)
...{
for (i = 0; i < temp1.Length; i++)
...{
temp2[i] = temp1[i];
}
temp2[i] = userID;
}
else
...{
for (i = 0; i < temp1.Length - 1; i++)
...{
temp2[i] = temp1[i + 1];
t = i;
}
temp2[i] = userID;
}
}
}
else
...{
if (string.IsNullOrEmpty(lastViewUser))
...{
temp2[0] = userID;
}
else
...{
for (i = 0; i < temp1.Length; i++)
...{
if (i < j)
...{
temp2[i] = temp1[i];
}
else if (i < temp1.Length - 1)
...{
temp2[i] = temp1[i + 1];
}
else
...{
temp2[i] = userID;
}
}
}
}
for (i = 0; i < k; i++)
...{
if (i < k - 1)
...{
if (flag == 0)
...{
if (string.IsNullOrEmpty(lastViewUser))
...{
result = temp2[0];
break;
}
result = result + temp2[i] + ",";
}
else
...{
if (i < k - 2)
...{
result = result + temp2[i] + ",";
}
else
...{
result = result + temp2[i];
break;
}
}
}
else
result = result + temp2[i];
}
return result;
}
#endregion
/**//// <summary>
/// 获取文章的最新浏览用户
/// 章学敏
/// 2007-6-16
/// </summary>
/// <param name="articleID">文章ID</param>
/// <param name="userID">用户ID</param>
/// <returns></returns>
public IList<Forum_AuthorInfo> GetLastViewers(string articleID,string userID)
...{
IList<Forum_AuthorInfo> lastViewer = new List<Forum_AuthorInfo>();
//如果是匿名用户,则不更新浏览记录
if (Convert.ToInt32(userID) == 0)
...{}
else
...{
UpdateLastViewer(userID, articleID);
}
string users = GetLastViewUsers(articleID);
if (string.IsNullOrEmpty(users))
...{
lastViewer = null;
}
else
...{
string[] userlist = users.Split(',');
for (int i = userlist.Length - 1; i >= 0; i--)
...{
SqlDataReader sdr = null;
int UserID = Convert.ToInt32(userlist[i]);
SqlParameter param = MakeSqlInParameter(POST_USERID, UserID);
sdr = RunReaderProcedure("Forum_GetAuthorInfoByAuthorID", param);
while (sdr.Read())
...{
lastViewer.Add(new Forum_AuthorInfo(sdr.GetInt32(0), "1", "1", sdr.GetString(1), "1", sdr.GetString(2), "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1"));//修改存储过程可以扩展
}
sdr.Close();
sdr.Dispose();
}
}
return lastViewer;
}
/**//// <summary>
/// 获取数据库中的最近访问的用户
/// 章学敏
/// 2007-6-16
/// </summary>
/// <param name="articleID">文章的ID</param>
/// <param name="userID">用户ID</param>
/// <returns></returns>
private string GetLastViewUsers(string articleID)
...{
SqlParameter param = MakeSqlInParameter(POST_ID, articleID); //读取前的跟新
try
...{
string users = RunScalar("Forum_GetLastViewUsers", param);
return users;
}
catch ...{ return " "; }
}
/**//// <summary>
/// 跟新文章的访问
/// 章学敏
/// 2007-06-15
/// </summary>
/// <param name="userID"></param>
/// <param name="articleID"></param>
private void UpdateLastViewer(string userID,string articleID)
...{
string LastViews=GetLastViewUser(GetLastViewUsers(articleID),userID);
SqlParameter[] paramList =...{MakeSqlInParameter("@LastViewUsers",LastViews),
MakeSqlInParameter(POST_ID,articleID)};
RunNoneQueryProcedure("Forum_UpdateLastViewers", paramList);
}
/**//// <summary>
/// 截取文章最近访问的6个人
/// 章学敏
/// 2007-06-15
/// <remarks>
/// 该函数主要是实现对访问某一文章的人进行记录和添加
/// 如果访问人数是制定的访问人数
/// 如果是第一次访问
/// 如果访问人数为达到制定的人数
/// 三种情况
/// </remarks>
/// </summary>
private string GetLastViewUser(string lastViewUser,string userID)
...{
int selectValue = 6;
int i = 0;
int j = 20;
int t = 0;
int flag = 0;
int k = selectValue;
string[] temp1 = lastViewUser.Split(',');
string result = "";
if (temp1.Length < selectValue)
...{
k = temp1.Length + 1;
}
else
...{
k = selectValue;
}
string[] temp2 = new string[k];
for (i = 0; i < temp1.Length; i++)
...{
if (temp1[i] == userID)
...{
j = i;
flag = 1;
break;
}
}
if (j == 20)
...{
if (string.IsNullOrEmpty(lastViewUser))
...{
temp2[0] = userID;
}
else
...{
if (temp1.Length != selectValue)
...{
for (i = 0; i < temp1.Length; i++)
...{
temp2[i] = temp1[i];
}
temp2[i] = userID;
}
else
...{
for (i = 0; i < temp1.Length - 1; i++)
...{
temp2[i] = temp1[i + 1];
t = i;
}
temp2[i] = userID;
}
}
}
else
...{
if (string.IsNullOrEmpty(lastViewUser))
...{
temp2[0] = userID;
}
else
...{
for (i = 0; i < temp1.Length; i++)
...{
if (i < j)
...{
temp2[i] = temp1[i];
}
else if (i < temp1.Length - 1)
...{
temp2[i] = temp1[i + 1];
}
else
...{
temp2[i] = userID;
}
}
}
}
for (i = 0; i < k; i++)
...{
if (i < k - 1)
...{
if (flag == 0)
...{
if (string.IsNullOrEmpty(lastViewUser))
...{
result = temp2[0];
break;
}
result = result + temp2[i] + ",";
}
else
...{
if (i < k - 2)
...{
result = result + temp2[i] + ",";
}
else
...{
result = result + temp2[i];
break;
}
}
}
else
result = result + temp2[i];
}
return result;
}
#endregion
以上是一个记录用户访问的函数,主要功能是记录文章或博客的访问者信息。