Example #1
0
        public int InsertFriend(Model.Friend friend)
        {
            String sql = "insert into friend (u_id,friend_id,g_id,time,nick_name) values"
                         + " (@UId,@FriendId,@GId,@Time,@NickName)";
            List <SqlParameter> parameters = new List <SqlParameter>();
            SqlParameter        UId        = new SqlParameter("@UId", SqlDbType.Int);
            SqlParameter        FriendId   = new SqlParameter("@FriendId", SqlDbType.Int);
            SqlParameter        GId        = new SqlParameter("@GId", SqlDbType.Int);
            SqlParameter        Time       = new SqlParameter("@Time", SqlDbType.DateTime);
            SqlParameter        NickName   = new SqlParameter("@NickName", SqlDbType.VarChar, 50);

            UId.Value      = friend.UId;
            FriendId.Value = friend.FriendId;
            GId.Value      = friend.GId;
            Time.Value     = friend.Time;
            NickName.Value = friend.NickName;
            parameters.Add(UId);
            parameters.Add(FriendId);
            parameters.Add(GId);
            parameters.Add(Time);
            parameters.Add(NickName);

            int result = SqlDbHelper.ExecuteNoQuery(sql, CommandType.Text, parameters);

            return(result);
        }
Example #2
0
        //添加P2p消息
        public bool addP2pMessage(Model.P2pMessage Message)
        {
            string sql = "insert into [p2p_message](host_id ,guest_id ,contents ,time ,face ,image ) values(@host_id,@guest_id,@contents,@time,@face,@image);";
            List <SqlParameter> parameters = new List <SqlParameter>();
            SqlParameter        host_id    = new SqlParameter("@host_id", SqlDbType.Int);
            SqlParameter        guest_id   = new SqlParameter("@guest_id", SqlDbType.Int);
            SqlParameter        contents   = new SqlParameter("@contents", SqlDbType.Text);
            SqlParameter        time       = new SqlParameter("@time", SqlDbType.DateTime);
            SqlParameter        face       = new SqlParameter("@face", SqlDbType.Text);
            SqlParameter        image      = new SqlParameter("@image", SqlDbType.Text);

            host_id.Value  = Message.HostId;
            guest_id.Value = Message.GuestId;
            contents.Value = Message.Contents;
            time.Value     = Message.Time;
            face.Value     = Message.Face;
            image.Value    = Message.image;

            parameters.Add(host_id);
            parameters.Add(guest_id);
            parameters.Add(contents);
            parameters.Add(time);
            parameters.Add(face);
            parameters.Add(image);
            int result = SqlDbHelper.ExecuteNoQuery(sql, CommandType.Text, parameters);

            if (result == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        //插入组成员
        public bool insertGroupMember(GroupMember groupMember)
        {
            string sqlStr = "insert into [group_member](group_id,time,u_id) values(@G_ID,@Time,@UId)";
            List <SqlParameter> parameters = new List <SqlParameter>();
            SqlParameter        G_ID       = new SqlParameter("@G_ID", SqlDbType.Int);
            SqlParameter        Time       = new SqlParameter("@Time", SqlDbType.DateTime);
            SqlParameter        UId        = new SqlParameter("@UId", SqlDbType.Int);

            G_ID.Value = groupMember.GroupId;
            Time.Value = groupMember.Time;
            UId.Value  = groupMember.UId;
            parameters.Add(G_ID);
            parameters.Add(Time);
            parameters.Add(UId);

            int row = SqlDbHelper.ExecuteNoQuery(sqlStr, CommandType.Text, parameters);

            if (row >= 1)
            {
                return(false);
            }
            else
            {
                return(false);
            }
        }
Example #4
0
        //加入已存在的群聊天室
        public bool addMember(int UId, int c_id)
        {
            string sql = "insert into [chatroom_member] ([chatroom_id],[time],[u_id]) values (@CId,@Time,@LeaderId)";
            List <SqlParameter> parameters = new List <SqlParameter>();
            SqlParameter        CId        = new SqlParameter("@CId", SqlDbType.Int);
            SqlParameter        Time       = new SqlParameter("@Time", SqlDbType.DateTime);
            SqlParameter        LeaderId   = new SqlParameter("@LeaderId", SqlDbType.Int);

            Time.Value = System.DateTime.Now;
            parameters.Add(Time);
            LeaderId.Value = UId;
            parameters.Add(LeaderId);
            CId.Value = c_id;
            parameters.Add(CId);

            int result = SqlDbHelper.ExecuteNoQuery(sql, CommandType.Text, parameters);

            if (result != 1)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #5
0
        //添加好友分组
        public int addGroup(Model.Group group)
        {
            string sql = "insert into [group] ([u_id],[name]) values (@UId,@Name)";
            List <SqlParameter> parameters = new List <SqlParameter>();
            SqlParameter        UId        = new SqlParameter("@UId", SqlDbType.Int);
            SqlParameter        Name       = new SqlParameter("@Name", SqlDbType.VarChar, 50);

            UId.Value = group.UId;
            parameters.Add(UId);
            Name.Value = group.Name;
            parameters.Add(Name);
            int result = SqlDbHelper.ExecuteNoQuery(sql, CommandType.Text, parameters);

            return(result);
        }
Example #6
0
        //设置chatPoomport
        public bool setPort()
        {
            int    c_id   = getLasteID();
            int    port   = c_id + 9000;
            string sqlStr = "update [chatroom] set chatroom_port =" + port + " where c_id =" + c_id;
            int    row    = SqlDbHelper.ExecuteNoQuery(sqlStr, CommandType.Text, null);

            if (row >= 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #7
0
        //设置statue
        public bool updateOutStatue(int uId)
        {
            List <SqlParameter> parameters = new List <SqlParameter>();
            String sqlStr = "update [user] set status =0 where u_id=@uId;";

            parameters.Add(new SqlParameter("@uId", SqlDbType.Int));
            parameters[0].Value = uId;
            int row = SqlDbHelper.ExecuteNoQuery(sqlStr, CommandType.Text, parameters);

            if (row == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #8
0
        //增加群组成员
        public int addChatRoomMember(Model.Chatroom chatroom)
        {
            string sql = "insert into [chatroom_member] ([chatroom_id],[time],[u_id]) values (@CId,@Time,@LeaderId)";
            List <SqlParameter> parameters = new List <SqlParameter>();
            SqlParameter        CId        = new SqlParameter("@CId", SqlDbType.Int);
            SqlParameter        Time       = new SqlParameter("@Time", SqlDbType.DateTime);
            SqlParameter        LeaderId   = new SqlParameter("@LeaderId", SqlDbType.Int);

            Time.Value = chatroom.Time;
            parameters.Add(Time);
            LeaderId.Value = chatroom.LeaderId;
            parameters.Add(LeaderId);
            CId.Value = chatroom.CId;
            parameters.Add(CId);

            int result = SqlDbHelper.ExecuteNoQuery(sql, CommandType.Text, parameters);

            return(result);
        }
Example #9
0
        public int addChatRoom(Model.Chatroom chatroom)
        {
            string sql = "insert into [chatroom] ([name],[time],[limit_num],[leader_id]) values (@Name,@Time,@LimitNum,@LeaderId)";
            List <SqlParameter> parameters = new List <SqlParameter>();
            SqlParameter        Name       = new SqlParameter("@Name", SqlDbType.VarChar, 50);
            SqlParameter        Time       = new SqlParameter("@Time", SqlDbType.DateTime);
            SqlParameter        LimitNum   = new SqlParameter("@LimitNum", SqlDbType.Int);
            SqlParameter        LeaderId   = new SqlParameter("@LeaderId", SqlDbType.Int);

            Name.Value = chatroom.Name;
            parameters.Add(Name);
            Time.Value = chatroom.Time;
            parameters.Add(Time);
            LimitNum.Value = chatroom.LimitNum;
            parameters.Add(LimitNum);
            LeaderId.Value = chatroom.LeaderId;
            parameters.Add(LeaderId);
            int result = SqlDbHelper.ExecuteNoQuery(sql, CommandType.Text, parameters);

            setPort();//设置端口号
            return(result);
        }
Example #10
0
        public bool register(User user)
        {
            string sql = "insert into [user] (username,email,password,regTime,age,sex,sign,photo) values (@Username,@Email, @Password, @Time,@Age,@Sex,@Sign,@Photo)";

            List <SqlParameter> parameters = new List <SqlParameter>();

            parameters.Add(new SqlParameter("@Username", SqlDbType.VarChar, 50));
            parameters.Add(new SqlParameter("@Email", SqlDbType.VarChar, 50));
            parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 50));
            parameters.Add(new SqlParameter("@Time", SqlDbType.DateTime));

            parameters.Add(new SqlParameter("@Age", SqlDbType.Int, 50));
            parameters.Add(new SqlParameter("@Sex", SqlDbType.Int));
            parameters.Add(new SqlParameter("@Sign", SqlDbType.VarChar, 50));
            parameters.Add(new SqlParameter("@Photo", SqlDbType.Image));

            parameters[0].Value = user.Username;
            parameters[1].Value = user.Email;
            parameters[2].Value = AppUtil.Encrypt(user.Password);
            parameters[3].Value = DateTime.Now;

            parameters[4].Value = user.Age;
            parameters[5].Value = user.Sex;
            parameters[6].Value = user.Sign;
            parameters[7].Value = user.Photo;

            int row = SqlDbHelper.ExecuteNoQuery(sql, CommandType.Text, parameters);

            if (row == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #11
0
        public bool update(User user, int uId)
        {
            List <SqlParameter> parameters = new List <SqlParameter>();
            StringBuilder       sql        = new StringBuilder();

            sql.Append("update [user] set");

            if (!user.Username.Equals(""))
            {
                sql.Append(" username=@Username,");
                SqlParameter Username = new SqlParameter("@Username", SqlDbType.VarChar, 50);
                Username.Value = user.Username;
                parameters.Add(Username);
            }
            if (!user.Password.Equals(""))
            {
                sql.Append(" password=@Password,");
                SqlParameter Password = new SqlParameter("@Password", SqlDbType.VarChar, 50);
                Password.Value = user.Password;
                parameters.Add(Password);
            }
            if (user.Age != -1)
            {
                sql.Append(" age=@Age,");
                SqlParameter Age = new SqlParameter("@Age", SqlDbType.Int, 3);
                Age.Value = user.Age;
                parameters.Add(Age);
            }
            if (user.Sex != -1)
            {
                sql.Append(" sex=@Sex,");
                SqlParameter Sex = new SqlParameter("@Sex", SqlDbType.Int, 1);
                Sex.Value = user.Sex;
                parameters.Add(Sex);
            }
            if (!user.Sign.Equals(""))
            {
                sql.Append(" sign=@Sign,");
                SqlParameter Sign = new SqlParameter("@Sign", SqlDbType.VarChar, 200);
                Sign.Value = user.Sign;
                parameters.Add(Sign);
            }
            if (user.Photo != null)
            {
                sql.Append(" photo=@Photo,");
                SqlParameter Photo = new SqlParameter("@photo", SqlDbType.Image);
                Photo.Value = user.Photo;
                parameters.Add(Photo);
            }
            if (!user.LastLoginIp.Equals(""))
            {
                sql.Append(" last_login_ip=@LastLoginIp,");
                SqlParameter LastLoginIp = new SqlParameter("@LastLoginIp", SqlDbType.VarChar, 50);
                LastLoginIp.Value = user.LastLoginIp;
                parameters.Add(LastLoginIp);
            }
            if (user.LastLoginTime != null)
            {
                sql.Append(" last_login_time=@LastLoginTime,");
                SqlParameter LastLoginTime = new SqlParameter("@LastLoginTime", SqlDbType.VarChar, 50);
                LastLoginTime.Value = user.LastLoginTime;
                parameters.Add(LastLoginTime);
            }
            if (user.Status != -1)
            {
                sql.Append(" status=@Status,");
                SqlParameter Status = new SqlParameter("@Status", SqlDbType.Int, 1);
                Status.Value = user.Status;
                parameters.Add(Status);
            }


            string sqlStr = sql.ToString();

            sqlStr  = sqlStr.Substring(0, sqlStr.Length - 1);
            sqlStr += " where u_id=@Uid";
            SqlParameter UId = new SqlParameter("@Uid", SqlDbType.Int, 10);

            UId.Value = uId;
            parameters.Add(UId);

            Console.WriteLine("查询语句。。。。。。。。。。。。。。。" + sqlStr);
            int row = SqlDbHelper.ExecuteNoQuery(sqlStr, CommandType.Text, parameters);

            if (row >= 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }