//添加好友 public bool AddFriend(string userid, string friendCode, out string usercode, out long IMFriendID, out string message) { usercode = string.Empty; IMFriendID = 0; long _userid = 0; Int64.TryParse(userid, out _userid); var user = userBLL.GetModel(_userid); if (user == null) { message = "用户ID不存在"; return(false); } var friendmodel = userBLL.GetModel(userBLL.GetUserID(friendCode)); if (friendmodel == null) { message = "好友用户编号不存在"; return(false); } if (_userid == friendmodel.UserID) { message = "不能添加自己为好友"; return(false); } var exmodel = imFriendBLL.GetModel(_userid, friendmodel.UserID); if (exmodel != null) { message = "好友已存在"; return(false); } lgk.Model.tb_IMFriend model = new lgk.Model.tb_IMFriend(); model.AddTime = DateTime.Now; model.UserID = _userid; model.UserCode = user.UserCode; model.FriendID = friendmodel.UserID; model.FriendCode = friendmodel.UserCode; IMFriendID = imFriendBLL.Add(model); usercode = user.UserCode; message = "添加好友成功"; return(true); }
/// <summary> /// 得到一个对象实体 /// </summary> public lgk.Model.tb_IMFriend GetModel(long UserID, long FriendID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select ID, UserID, UserCode, FriendCode, FriendID, AddTime "); strSql.Append(" from tb_IMFriend "); strSql.Append(" where UserID=@UserID and FriendID=@FriendID"); SqlParameter[] parameters = { new SqlParameter("@UserID", SqlDbType.BigInt), new SqlParameter("@FriendID", SqlDbType.BigInt) }; parameters[0].Value = UserID; parameters[1].Value = FriendID; lgk.Model.tb_IMFriend model = new lgk.Model.tb_IMFriend(); 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.UserCode = ds.Tables[0].Rows[0]["UserCode"].ToString(); model.FriendCode = ds.Tables[0].Rows[0]["FriendCode"].ToString(); if (ds.Tables[0].Rows[0]["FriendID"].ToString() != "") { model.FriendID = long.Parse(ds.Tables[0].Rows[0]["FriendID"].ToString()); } if (ds.Tables[0].Rows[0]["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(ds.Tables[0].Rows[0]["AddTime"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(lgk.Model.tb_IMFriend model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_IMFriend set "); strSql.Append(" UserID = @UserID , "); strSql.Append(" UserCode = @UserCode , "); strSql.Append(" FriendCode = @FriendCode , "); strSql.Append(" FriendID = @FriendID , "); strSql.Append(" AddTime = @AddTime "); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.BigInt, 8), new SqlParameter("@UserID", SqlDbType.BigInt, 8), new SqlParameter("@UserCode", SqlDbType.VarChar, 50), new SqlParameter("@FriendCode", SqlDbType.VarChar, 50), new SqlParameter("@FriendID", SqlDbType.BigInt, 8), new SqlParameter("@AddTime", SqlDbType.DateTime) }; parameters[0].Value = model.ID; parameters[1].Value = model.UserID; parameters[2].Value = model.UserCode; parameters[3].Value = model.FriendCode; parameters[4].Value = model.FriendID; parameters[5].Value = model.AddTime; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public long Add(lgk.Model.tb_IMFriend model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_IMFriend("); strSql.Append("UserID,UserCode,FriendCode,FriendID,AddTime"); strSql.Append(") values ("); strSql.Append("@UserID,@UserCode,@FriendCode,@FriendID,@AddTime"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserID", SqlDbType.BigInt, 8), new SqlParameter("@UserCode", SqlDbType.VarChar, 50), new SqlParameter("@FriendCode", SqlDbType.VarChar, 50), new SqlParameter("@FriendID", SqlDbType.BigInt, 8), new SqlParameter("@AddTime", SqlDbType.DateTime) }; parameters[0].Value = model.UserID; parameters[1].Value = model.UserCode; parameters[2].Value = model.FriendCode; parameters[3].Value = model.FriendID; parameters[4].Value = model.AddTime; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt64(obj)); } }