Exemple #1
0
        //根据用户名查找用户
        public SqlDataReader searchFriendByName(string name)
        {
            string        sqlStr = "select * from [user] where username like '%" + name + "%'";
            SqlDataReader result = SqlDbHelper.ExecuteReader(sqlStr, CommandType.Text, null);

            return(result);
        }
Exemple #2
0
        //获得g_ID
        public int get_g_ID(int uId, string name)
        {
            int    g_ID   = 0;
            string sqlStr = "select [g_id] from [group] where u_id=@UId and name=@Name";
            List <SqlParameter> parameters = new List <SqlParameter>();
            SqlParameter        UId        = new SqlParameter("@UId", SqlDbType.Int);
            SqlParameter        Name       = new SqlParameter("@Name", SqlDbType.VarChar);

            UId.Value  = uId;
            Name.Value = name;
            parameters.Add(UId);
            parameters.Add(Name);
            Console.WriteLine(parameters.ToString() + "------>" + uId);
            SqlDataReader reader = SqlDbHelper.ExecuteReader(sqlStr, CommandType.Text, parameters);

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    if (!(reader["g_id"] is System.DBNull))
                    {
                        g_ID = Convert.ToInt32(reader["g_id"].ToString().Trim());
                    }
                }
            }
            return(g_ID);
        }
Exemple #3
0
        //搜索群
        public SqlDataReader searchChatRoomByName(string Name)
        {
            string        sqlStr = "select [c_id] as [c_id],[name] as [name],[chatroom].[time] as [time],[limit_num] as [limit_num],[leader_id] as [leader_id],[u_id] as [u_id] from [chatroom],[chatroom_member] where [chatroom].[c_id] = [chatroom_member].chatroom_id and [chatroom].name like '%" + Name + "%'";
            SqlDataReader result = SqlDbHelper.ExecuteReader(sqlStr, CommandType.Text, null);

            return(result);
        }
Exemple #4
0
        //查询最新插入的chatRoom的端口
        public int getLastePort()
        {
            string        sqlStr = "select top 1 [chatroom_port] as port  from [chatRoom] order by time Desc";
            int           port   = 0;
            SqlDataReader reader = SqlDbHelper.ExecuteReader(sqlStr, CommandType.Text, null);

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    port = Convert.ToInt32(reader["port"].ToString());
                }
            }

            return(port);
        }
Exemple #5
0
        //查询最新插入的chatRoom的id
        public int getLasteID()
        {
            string        sqlStr = "select top 1 [c_id] as c_id  from [chatRoom] order by time Desc";
            int           id     = 0;
            SqlDataReader reader = SqlDbHelper.ExecuteReader(sqlStr, CommandType.Text, null);

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    id = Convert.ToInt32(reader["c_id"].ToString());
                }
            }

            return(id);
        }
Exemple #6
0
        //发起群组聊天,查找群内成员在线人员IP
        public ArrayList searchIp(int Cid)
        {
            string              sqlStr      = "select last_login_ip from [user] where status=1 and u_id in (select u_id from [chatroom_member] where chatroom_id=@Cid)";
            ArrayList           onlineIp    = new ArrayList();
            List <SqlParameter> parameters  = new List <SqlParameter>();
            SqlParameter        chatroom_id = new SqlParameter("@Cid", SqlDbType.Int);

            chatroom_id.Value = Cid;
            parameters.Add(chatroom_id);
            SqlDataReader reader = SqlDbHelper.ExecuteReader(sqlStr, CommandType.Text, parameters);

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    onlineIp.Add(reader["last_login_ip"].ToString());
                }
            }

            return(onlineIp);
        }
Exemple #7
0
        //添加用户到对应的分组
        //获得到用户最大的groupID
        public int getMax_g_ID(int uId)
        {
            int    maxID  = 0;
            string sqlStr = "select MAX([g_id]) as g_max_id from [group] where u_id=@UId";
            List <SqlParameter> parameters = new List <SqlParameter>();
            SqlParameter        UId        = new SqlParameter("@UId", SqlDbType.Int);

            UId.Value = uId;
            parameters.Add(UId);
            Console.WriteLine(parameters.ToString() + "------>" + uId);
            SqlDataReader reader = SqlDbHelper.ExecuteReader(sqlStr, CommandType.Text, parameters);

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    if (!(reader["g_max_id"] is System.DBNull))
                    {
                        maxID = Convert.ToInt32(reader["g_max_id"].ToString().Trim());
                    }
                }
            }
            return(maxID);
        }