Ejemplo n.º 1
0
        /// <summary>
        /// 获取好友列表
        /// </summary>
        /// <param name="uid">ID</param>
        /// <returns>好友集合</returns>
        public static ArrayList getFriendList(String uid)
        {
            //查询所有好友
            Object[]  parameter = getParameterList(new SqlParameter[] { new SqlParameter("uid", uid) });
            ArrayList arr       = SQLUtil.rawQuery("Select * From FriendRelation Where SendUid = @uid Or AcceptUid = @uid", parameter);

            if (arr.Count > 0)
            {
                String[] arruid = new String[arr.Count];
                for (int i = 0; i < arr.Count; i++)
                {
                    Hashtable table = (Hashtable)arr[i];
                    if (table["SendUid"].ToString().Trim() == uid)
                    {
                        arruid[i] = table["AcceptUid"].ToString();
                    }
                    else
                    {
                        arruid[i] = table["SendUid"].ToString();
                    }
                }
                //查询所有好友基本信息
                ArrayList firendlist = new ArrayList();
                for (int i = 0; i < arruid.Length; i++)
                {
                    UserInfoModel user = BaseUtil.getUserInfo(arruid[i]);
                    firendlist.Add(user);
                }
                return(firendlist);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 发送好友请求
        /// </summary>
        /// <param name="senduid">发送ID</param>
        /// <param name="acceptuid">接受ID</param>
        /// <returns>执行结果 为Empty时发送请求成功</returns>
        public static String sendFriendRequest(String senduid, String acceptuid)
        {
            String error = String.Empty;

            //查询是否已发送过请求
            if (!BaseUtil.exist(acceptuid))
            {
                return("不存在此用户");
            }
            if (isFirend(senduid, acceptuid))
            {
                return("你们已经是好友");
            }
            Object[]  parameter = getParameterList(new SqlParameter[] { new SqlParameter("@senduid", senduid), new SqlParameter("@acceptuid", acceptuid) });
            ArrayList arr       = SQLUtil.rawQuery("Select id From FriendRequest Where SendUid = @senduid And AcceptUid = @acceptuid", parameter);

            if (arr != null)
            {
                if (arr.Count > 0)
                {
                    return("好友请求已存在,请勿重复发送好友请求");
                }
                else
                {
                    parameter = getParameterList(new SqlParameter[] { new SqlParameter("@senduid", senduid), new SqlParameter("@acceptuid", acceptuid) });
                    int result = SQLUtil.excuteSQL("Insert into  FriendRequest Values(@senduid,@acceptuid)", parameter);
                    return(result > 0 ? String.Empty : "发送好友请求失败");
                }
            }
            return("未知错误");
        }