Example #1
0
        public string GetRoomLifeInfoByUser(string userId)
        {
            //只考虑玩家
            int roomId = GetRoomIdByUser(int.Parse(userId));

            string sql = "select user_id from room_user where room_id = @roomId";
            //获取用户列表
            List <object> list = MySqlExecuteTools.GetSingleFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@roomId", roomId) });


            if (list.Count > 0)
            {
                List <string> resultStr = new List <string>();
                list.ForEach((id) =>
                {
                    resultStr.Add(id.ToString());
                });
                string result = StrUtil.ConnetString(resultStr, ",");
                sql = "select * from life where userId in  (" + result + ")";
                List <Life> lifes = MySqlExecuteTools.GetObjectResult <Life>(sql, null);
                lifes.ForEach((life) =>
                {
                    life.userName = MySqlExecuteTools.GetSingleFieldResult("select name from user  where id = @id", new MySqlParameter[] { new MySqlParameter("@id", life.userId) })[0].ToString();
                });

                return(Utils.CollectionsConvert.ToJSON(lifes));
            }
            else
            {
                return("");
            }
        }
Example #2
0
        private List <UserName> GetUserList(List <Room_User> roomUserList)
        {
            List <string> ids = new List <string>();

            roomUserList.ForEach((item) => {
                ids.Add(item.user_id.ToString());
            });

            string          result     = StrUtil.ConnetString(ids, ",");
            string          sql        = "select * from user where id in  (" + result + ")";
            List <UserName> resultData = MySqlExecuteTools.GetObjectResult <UserName>(sql, null);

            resultData.ForEach((user) => {
                int runState  = roomUserList.Where((item) => item.user_id == user.id).FirstOrDefault <Room_User>().runState;
                user.runState = runState;
            });

            return(resultData);
        }