/// <summary> /// 获取前几行主贴轮播 /// </summary> /// <returns>数据表</returns> public DataSet GetModels() { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 3"); strSql.Append(" tid,TTopic,TContents "); strSql.Append(" FROM BBSTopic,BBSSection "); strSql.Append(" where SID=2 and BBSTopic.tsid=BBSSection.SID "); strSql.Append(" order by TTime desc"); Model.BBSTopic model = new Model.BBSTopic(); DataSet ds = DbHelperSQL.Query(strSql.ToString()); return(ds); }
/// <summary> /// 得到一个对象实体 /// </summary> /// <param name="Uid">用户id</param> /// <returns>对象实体</returns> public Model.BBSTopic GetModel(int Uid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 "); strSql.Append(" TTopic,tsid,TContents,TClickCount,TLastClickT,TGoodCount "); strSql.Append(" from BBSTopic "); strSql.Append(" where tid =" + Uid + ""); Model.BBSTopic model = new Model.BBSTopic(); DataSet ds = DbHelperSQL.Query(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { model.TTopic = ds.Tables[0].Rows[0][0].ToString(); model.Tsid = int.Parse(ds.Tables[0].Rows[0][1].ToString()); model.TContents = ds.Tables[0].Rows[0][2].ToString(); model.TClickCount = int.Parse(ds.Tables[0].Rows[0][3].ToString()); model.TLastClickT = DateTime.Parse(ds.Tables[0].Rows[0][4].ToString()); model.TGoodCount = int.Parse(ds.Tables[0].Rows[0][5].ToString()); //更新点击次数 StringBuilder strSql1 = new StringBuilder(); strSql1.Append("select TClickCount from BBSTopic where tid =" + Uid + ""); DbHelperSQL db = new DbHelperSQL(); object ds1 = DbHelperSQL.GetSingle(strSql1.ToString()); int count = int.Parse(ds1.ToString()) + 1; strSql1.Clear(); strSql1.Append("update BBSTopic set TClickCount=" + count + "where tid=" + Uid + ""); ds1 = DbHelperSQL.GetSingle(strSql1.ToString()); //更新最后点击时间 strSql1.Clear(); //获取当前时间 string dt = DateTime.Now.ToString(); strSql1.Append("update BBSTopic set TLastClickT='" + dt + "'where tid=" + Uid + ""); ds1 = DbHelperSQL.GetSingle(strSql1.ToString()); return(model); } else { return(null); } }
/// <summary> /// 增加一条帖子记录 /// </summary> /// <param name="model">帖子实体</param> /// <returns>帖子id</returns> public int add(Model.BBSTopic model) { //获取当前用户的最大编号 //string bir = model.UBirthday; string sql = string.Format(@"INSERT INTO [dbo].[BBSTopic] ([tsid] ,[tuid] ,[treplycount] ,[TTopic] ,[TContents] ,[TTime] ,[TClickCount] ,[TLastClickT]) VALUES ({0} ,{1} ,{2} ,'{3}' ,'{4}' ,'{5}' ,{6} ,'{7}')", model.Tsid, model.Tuid, model.Treplycount, model.TTopic, model.TContents, model.TTime, model.TClickCount, model.TLastClickT );//为用户表增加数据 //sql 字符串类型的值要用‘’。数字、日期类型不需要‘’ string sql1 = string.Format(@"select top 1 tid from BBSTopic where TTopic='{0}'", model.TTopic); object ob = DbHelperSQL.GetSingle(sql); object ob1 = DbHelperSQL.GetSingle(sql1.ToString()); if (ob1 == null) { return(0); } else { return(Convert.ToInt32(ob1)); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string json = "{'info':'增加数据失败'}"; //获取动作的类型 string action = context.Request.Form["Action"]; if (action == "add") { //获取GET方法传递参数:Request.QueryString["参数名称"]; //获取POST方法传递参数:Request.Form["参数名称"]; //保存文本框对象,提高效率 string ttopic = context.Request.Form["ttopic"]; //帖子标题 string tcontents = context.Request.Form["tcontents"]; //帖子内容 string rsid = context.Request.Form["rsid"]; //帖子所属板块 //string Model.BBSTopic model = new Model.BBSTopic(); model.TTopic = ttopic; model.TContents = tcontents; model.Tsid = int.Parse(rsid); model.TTime = DateTime.Now;//发帖时间 model.Tuid = Convert.ToInt32(context.Session["ID"]); model.Treplycount = 0; model.TLastClickT = DateTime.Now; model.TClickCount = 0; BLL.BBSTopic bll = new BLL.BBSTopic(); int n = bll.add(model); //返回单个文字信息 if (n > 0) { json = "{'info':'增加数据成功,编号是:" + n + "'}"; } } context.Response.Write(json); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string json = "{'info':'增加数据失败'}"; string action = context.Request.Form["Action"]; if (action == "Show")//显示数据页 { string UserID = context.Request.Form["UserID"]; BLL.BBSTopic bll = new BLL.BBSTopic(); // Model.Admin前必须加 [Serializable] Model.BBSTopic model = bll.GetModel(int.Parse(UserID)); //返回一个类的对象 JavaScriptSerializer serializer = new JavaScriptSerializer(); string jsonString = serializer.Serialize(model); context.Response.Write(jsonString); } else if (action == "Load")//检查是否已经登录 { if (context.Session["ID"] == null) { json = "{'info':'no'}"; } context.Response.Write(json); } else if (action == "reply") //回帖操作 { int id = int.Parse(context.Session["ID"].ToString()); //获取当前用户的ID context.Response.ContentType = "text/plain"; json = "{'info':'回帖失败','ID':-1}"; string txtReply = context.Request.Form["txtreply"]; //回帖内容 string txtTitle = context.Request.Form["txttitle"]; //回帖标题 int tid = int.Parse(context.Request.Form["tid"]); //主贴编号 int sid = int.Parse(context.Request.Form["sid"]); //板块编号 BLL.BBSReply bll = new BLL.BBSReply(); int n = bll.add(txtReply, txtTitle, tid, sid, id); //返回单个文字信息; if (n > 0) { json = "{'info':'回帖成功!'}"; } context.Response.Write(json); } else if (action == "good") { BLL.BBSTopic bll = new BLL.BBSTopic(); int tid = int.Parse(context.Request.Form["tid"]); if (bll.changegood(tid)) { json = "{'info':'点赞成功!'}"; } else { json = "{'info':'点赞失败!'}"; } } else if (action == "ShowReply") { BLL.BBSReply bll = new BLL.BBSReply(); int tid = int.Parse(context.Request.Form["TID"]); DataSet ds = bll.GetList(tid, 3); //调用业务逻辑层的方法 ds.Tables[0].TableName = "Admin"; //为数据表改名 //返回列表 json = WEB.DataConvertJson.DataTable2Json(ds.Tables[0]); //调用把datatable转为json的方法 context.Response.Write(json); } }
/// <summary> /// 增加帖子 /// </summary> /// <param name="model"></param> /// <returns></returns> public int add(Model.BBSTopic model) { return(dal.add(model)); }