//发表动态 public bool Friends(long userid, string dynamic, string path, out string message) { if (FriendsValidate(userid, dynamic, path, out message)) { lgk.Model.tb_user userInfo = userBLL.GetModel(userid); lgk.Model.tb_FriendDynamic friend = new lgk.Model.tb_FriendDynamic() { UserID = userid, Content = dynamic.Trim(), Pic = path.Trim(), AddTime = DateTime.Now, GoodNum = 0, CommentNum = 0, }; if (friendBLL.Add(friend) > 0) { message = "发送成功"; return(true); } else { message = "发送失败"; return(false); } } else { return(false); } }
/// <summary> /// 输入验证 /// </summary> /// <returns></returns> private bool FriendsValidate(long userid, string dynamic, string path, out string message) { lgk.Model.tb_FriendDynamic friendsInfo = new lgk.Model.tb_FriendDynamic(); if (dynamic.Trim() == "") { message = "动态内容不能为空"; return(false); } message = ""; return(true); }
/// <summary> /// 得到一个对象实体 /// </summary> public lgk.Model.tb_FriendDynamic GetModel(long ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select ID, UserID, Content, Pic, AddTime, GoodNum, CommentNum "); strSql.Append(" from tb_FriendDynamic "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.BigInt) }; parameters[0].Value = ID; lgk.Model.tb_FriendDynamic model = new lgk.Model.tb_FriendDynamic(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"].ToString() != "") { model.ID = long.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } if (ds.Tables[0].Rows[0]["UserID"].ToString() != "") { model.UserID = long.Parse(ds.Tables[0].Rows[0]["UserID"].ToString()); } model.Content = ds.Tables[0].Rows[0]["Content"].ToString(); model.Pic = ds.Tables[0].Rows[0]["Pic"].ToString(); if (ds.Tables[0].Rows[0]["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(ds.Tables[0].Rows[0]["AddTime"].ToString()); } if (ds.Tables[0].Rows[0]["GoodNum"].ToString() != "") { model.GoodNum = int.Parse(ds.Tables[0].Rows[0]["GoodNum"].ToString()); } if (ds.Tables[0].Rows[0]["CommentNum"].ToString() != "") { model.CommentNum = int.Parse(ds.Tables[0].Rows[0]["CommentNum"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(lgk.Model.tb_FriendDynamic model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_FriendDynamic set "); strSql.Append(" UserID = @UserID , "); strSql.Append(" Content = @Content , "); strSql.Append(" Pic = @Pic , "); strSql.Append(" AddTime = @AddTime , "); strSql.Append(" GoodNum = @GoodNum , "); strSql.Append(" CommentNum = @CommentNum "); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.BigInt, 8), new SqlParameter("@UserID", SqlDbType.BigInt, 8), new SqlParameter("@Content", SqlDbType.VarChar, -1), new SqlParameter("@Pic", SqlDbType.VarChar, 200), new SqlParameter("@AddTime", SqlDbType.DateTime), new SqlParameter("@GoodNum", SqlDbType.Int, 4), new SqlParameter("@CommentNum", SqlDbType.Int, 4) }; parameters[0].Value = model.ID; parameters[1].Value = model.UserID; parameters[2].Value = model.Content; parameters[3].Value = model.Pic; parameters[4].Value = model.AddTime; parameters[5].Value = model.GoodNum; parameters[6].Value = model.CommentNum; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public long Add(lgk.Model.tb_FriendDynamic model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_FriendDynamic("); strSql.Append("UserID,Content,Pic,AddTime,GoodNum,CommentNum"); strSql.Append(") values ("); strSql.Append("@UserID,@Content,@Pic,@AddTime,@GoodNum,@CommentNum"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserID", SqlDbType.BigInt, 8), new SqlParameter("@Content", SqlDbType.VarChar, -1), new SqlParameter("@Pic", SqlDbType.VarChar, 200), new SqlParameter("@AddTime", SqlDbType.DateTime), new SqlParameter("@GoodNum", SqlDbType.Int, 4), new SqlParameter("@CommentNum", SqlDbType.Int, 4) }; parameters[0].Value = model.UserID; parameters[1].Value = model.Content; parameters[2].Value = model.Pic; parameters[3].Value = model.AddTime; parameters[4].Value = model.GoodNum; parameters[5].Value = model.CommentNum; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt64(obj)); } }