/// <summary> /// 添加访问量 /// </summary> /// <param name="r"></param> /// <returns></returns> public int addRead(R_Read r) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(@"INSERT INTO R_Read (News_ID, Read_IP, Read_Time, Read_Count) VALUES (@News_ID, @Read_IP, @Read_Time, @Read_Count)"); db.AddInParameter(cmd, "@News_ID", DbType.Int32, r.News_ID); db.AddInParameter(cmd, "@Read_IP", DbType.String, r.Read_IP); db.AddInParameter(cmd, "@Read_Time", DbType.Date, DateTime.Now.Date); db.AddInParameter(cmd, "@Read_Count", DbType.Int32, 1); return db.ExecuteNonQuery(cmd); }
private void bindData() { B_InforData bf=new B_InforData(); thisCP.NavigateUrl = bf.getCpByID(id)["Sort_Value"].ToString() + ".aspx"; thisCP.Text = bf.getCpByID(id)["Sort_Name"].ToString(); dataTableByID.InnerHtml = bf.getInforByID(id); GetIP g = new GetIP(); R_Read r = new R_Read(); r.News_ID = id; r.Read_IP = g.GetRealIP(); r.Read_Time = DateTime.Now.Date; B_News bn = new B_News(); webInfor.InnerHtml = bn.getWebInfor().Tables[0].Rows[0]["News_Content"].ToString(); B_Index bi=new B_Index(); try { bi.searchRead(r); } catch (Exception ex) { Response.Write(ex.Message); } }
/// <summary> /// 更新访问量 /// </summary> /// <param name="r"></param> /// <returns></returns> public int updateRead(R_Read r) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(@"update R_Read set Read_Time=@Read_Time,Read_Count=@Read_Count where News_ID=@News_ID and Read_IP=@Read_IP"); db.AddInParameter(cmd, "@Read_Time", DbType.Date, DateTime.Now.Date); db.AddInParameter(cmd, "@Read_Count", DbType.Int32, r.Read_Count); db.AddInParameter(cmd, "@News_ID", DbType.Int32, r.News_ID); db.AddInParameter(cmd, "@Read_IP", DbType.String, r.Read_IP); return db.ExecuteNonQuery(cmd); }
/// <summary> /// 查询文章今天是否访问过 /// </summary> /// <param name="r"></param> /// <returns></returns> public DataSet searchRead(R_Read r) { DataSet ds = new DataSet(); try { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(@"select * from R_Read where News_ID=@News_ID and Read_IP=@Read_IP"); db.AddInParameter(cmd, "@News_ID", DbType.Int32, r.News_ID); db.AddInParameter(cmd, "@Read_IP", DbType.String, r.Read_IP); ds = db.ExecuteDataSet(cmd); } catch (Exception) { } return ds; }
/// <summary> /// 添加访问量 /// </summary> /// <param name="r"></param> /// <returns></returns> public bool addRead(R_Read r) { return di.addRead(r) == 1 ? true : false; }
/// <summary> /// 更新访问量 /// </summary> /// <param name="r"></param> /// <returns></returns> public bool updateRead(R_Read r) { return di.updateRead(r) == 1 ? true : false; }
/// <summary> /// 查询文章今天是否访问过 /// </summary> /// <param name="r"></param> /// <returns></returns> public bool[] searchRead(R_Read r) { bool[] a = new bool[2]; DataTable dt = di.searchRead(r).Tables[0]; if (dt.Rows.Count == 0) { a[0] = addRead(r); } else { if(!dt.Rows[0]["Read_Time"].Equals(DateTime.Now.Date)) { r.Read_Count = (Convert.ToInt32(dt.Rows[0]["Read_Count"]) + 1).ToString(); a[1] = updateRead(r); } } return a; }