Ejemplo n.º 1
0
        /// <summary>
        /// 获取一定事件范围内,特定好友的聊天记录
        /// </summary>
        /// <param name="hostid"></param>
        /// <param name="friendId"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        public MessageList GetWeMsg(int hostid, int friendId, DateTime time)
        {
            DbOperate dbo = new DbOperate();
            dbo.TableName = MessageOperator.TABLENAME;
            MessageList returnList = new MessageList();

            SqlCommand com = new SqlCommand();
            com.CommandText = "select * from Messages where toUserId=@hostID and fromUSerid=@friendId and MessageState=0 and MessageTime between @startTime and @endTime";

            SqlParameter hostPar = new SqlParameter("@hostID",SqlDbType.Int);
            hostPar.Value = hostid;

            SqlParameter friendPar = new SqlParameter("@friendId",SqlDbType.Int);
            friendPar.Value = friendId;

            SqlParameter start = new SqlParameter("@startTime",SqlDbType.DateTime);
            start.Value = time.AddSeconds(-2);

            SqlParameter end = new SqlParameter("@endTime",SqlDbType.DateTime);
            end.Value = time.AddSeconds(1);

            com.Parameters.Add(hostPar);
            com.Parameters.Add(friendPar);
            com.Parameters.Add(start);
            com.Parameters.Add(end);

            DataSet ds = dbo.Select(com);

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                MessageItem item = new MessageItem();
                item.Id = Convert.ToInt32(row["Id"]);
                item.FromUserId = Convert.ToInt32(row["FromUserId"]);
                item.ToUserId = hostid;
                item.Message = row["Message"].ToString();
                item.MessageTypeId = Convert.ToInt32(row["MessageTypeId"]);
                item.MessageState = (MessageState)Convert.ToInt32(row["MessageState"]);
                item.MessageTime = Convert.ToDateTime(row["MessageTime"]);

                returnList.Add(item);
            }

            return returnList;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更新消息列表中的消息为已读消息
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public MessageList UpdateMsg2Readed(MessageList list)
        {
            DbOperate dbo = new DbOperate();
            dbo.TableName = MessageOperator.TABLENAME;
            MessageList returnList = new MessageList();

            foreach (MessageItem item in list)
            {
                SqlCommand com = new SqlCommand();
                com.CommandText = "update Messages set MessageState=1 where Id=@MessageId";

                SqlParameter Idpar = new SqlParameter("@MessageId", SqlDbType.Int);
                Idpar.Value = item.Id;

                com.Parameters.Add(Idpar);
                dbo.UpDate(com);

                MessageItem upItem = this.GetMessage(item.Id);
                returnList.Add(upItem);
            }

            return returnList;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 返回某用户的好友列表对象
        /// </summary>
        /// <param name="fromUserId">用户的MyQQ号</param>
        /// <returns></returns>
        public MessageList GetOwnerMsgByFromUser(int fromUserId)
        {
            DbOperate dbo = new DbOperate();
            dbo.TableName = MessageOperator.TABLENAME;

            SqlCommand com = new SqlCommand();
            com.CommandText = "select * from Messages where fromUserId=@fromUserId";

            SqlParameter fUserId = new SqlParameter("@fromUserId",SqlDbType.Int);
            fUserId.Value = fromUserId;

            dbo.TableName = MessageOperator.TABLENAME;
            com.Parameters.Add(fUserId);

            DataSet ds = dbo.Select(com);
            MessageList list = new MessageList();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                MessageItem item = new MessageItem();
                item.Id = Convert.ToInt32(row["Id"]);
                item.FromUserId = Convert.ToInt32(row["FromUserId"]);
                item.ToUserId =Convert.ToInt32(row["TouserId"]);
                item.Message = row["Message"].ToString();
                item.MessageTypeId = Convert.ToInt32(row["MessageTypeId"]);
                item.MessageState = (MessageState)Convert.ToInt32(row["MessageState"]);
                item.MessageTime = Convert.ToDateTime(row["MessageTime"]);

                list.Add(item);
            }

            return list;
        }