数据库只保留某个用户10条浏览记录
public bool wbrowserinfo(int browsehid, string browsetitle, string browsepageurl, string browsetime, int userid)
{
sql = "select * from house_browselslist where userid=" + userid + " order by house_browsetime desc";
dt = DBUtility.DbHelperSQL.Query(sql).Tables[0];
DataTable mydt = null;
DataTable deldt = null;
int hupdaet = 0;
try
{
if (dt.Rows.Count >=10)
{
int topid = dt.Rows.Count - 10;
sql = "select top " + topid + " * from house_browselslist where userid=" + userid + " order by house_browsetime asc";
deldt = DBUtility.DbHelperSQL.Query(sql).Tables[0];
if (deldt.Rows.Count > 0)
{
for (int i = 0; i < deldt.Rows.Count; i++)
{
hupdaet = DBUtility.DbHelperSQL.ExecuteSql("delete from house_browselslist where house_browselsid=" + Convert.ToInt32(deldt.Rows[i]["house_browselsid"].ToString()) + "");
}
sql = "select * from house_browselslist where userid=" + userid + " and house_browsehid=" + browsehid + " and house_browsepageurl='" + browsepageurl + "' order by house_browsetime desc";
mydt = DBUtility.DbHelperSQL.Query(sql).Tables[0];
if (mydt.Rows.Count <= 0)
{
hupdaet = DBUtility.DbHelperSQL.ExecuteSql("insert into house_browselslist(house_browsehid,house_browsetitle,house_browsepageurl,house_browsetime,userid)values(" + browsehid + ",'" + browsetitle + "','" + browsepageurl + "','" + browsetime + "'," + userid + ")");
}
}
}
else
{
sql = "select * from house_browselslist where userid=" + userid + " and house_browsehid=" + browsehid + " and house_browsepageurl='" + browsepageurl + "' order by house_browsetime desc";
mydt = DBUtility.DbHelperSQL.Query(sql).Tables[0];
if (mydt.Rows.Count <= 0)
{
hupdaet = DBUtility.DbHelperSQL.ExecuteSql("insert into house_browselslist(house_browsehid,house_browsetitle,house_browsepageurl,house_browsetime,userid)values(" + browsehid + ",'" + browsetitle + "','" + browsepageurl + "','" + browsetime + "'," + userid + ")");
}
}
flag = true;
}
catch(Exception ex)
{
flag = false;
}
return flag;
}
{
sql = "select * from house_browselslist where userid=" + userid + " order by house_browsetime desc";
dt = DBUtility.DbHelperSQL.Query(sql).Tables[0];
DataTable mydt = null;
DataTable deldt = null;
int hupdaet = 0;
try
{
if (dt.Rows.Count >=10)
{
int topid = dt.Rows.Count - 10;
sql = "select top " + topid + " * from house_browselslist where userid=" + userid + " order by house_browsetime asc";
deldt = DBUtility.DbHelperSQL.Query(sql).Tables[0];
if (deldt.Rows.Count > 0)
{
for (int i = 0; i < deldt.Rows.Count; i++)
{
hupdaet = DBUtility.DbHelperSQL.ExecuteSql("delete from house_browselslist where house_browselsid=" + Convert.ToInt32(deldt.Rows[i]["house_browselsid"].ToString()) + "");
}
sql = "select * from house_browselslist where userid=" + userid + " and house_browsehid=" + browsehid + " and house_browsepageurl='" + browsepageurl + "' order by house_browsetime desc";
mydt = DBUtility.DbHelperSQL.Query(sql).Tables[0];
if (mydt.Rows.Count <= 0)
{
hupdaet = DBUtility.DbHelperSQL.ExecuteSql("insert into house_browselslist(house_browsehid,house_browsetitle,house_browsepageurl,house_browsetime,userid)values(" + browsehid + ",'" + browsetitle + "','" + browsepageurl + "','" + browsetime + "'," + userid + ")");
}
}
}
else
{
sql = "select * from house_browselslist where userid=" + userid + " and house_browsehid=" + browsehid + " and house_browsepageurl='" + browsepageurl + "' order by house_browsetime desc";
mydt = DBUtility.DbHelperSQL.Query(sql).Tables[0];
if (mydt.Rows.Count <= 0)
{
hupdaet = DBUtility.DbHelperSQL.ExecuteSql("insert into house_browselslist(house_browsehid,house_browsetitle,house_browsepageurl,house_browsetime,userid)values(" + browsehid + ",'" + browsetitle + "','" + browsepageurl + "','" + browsetime + "'," + userid + ")");
}
}
flag = true;
}
catch(Exception ex)
{
flag = false;
}
return flag;
}