Beispiel #1
0
 public List<ChatInfo> GetAllChatInfo()
 {
     var result = new List<ChatInfo>();
     const string sql = "select c.ChatId, c.UserIds, c.Name from Chat c "
         + "order by c.LastTime desc";
     using (var reader = DbUtil.ExecuteSql(LyncDb.GetDb().SqlCnn, sql, null))
     {
         if (reader == null)
             return result;
         while (reader.Read())
         {
             long chatId = reader.GetInt64(0);
             string userIds = reader.GetString(1);
             string name = reader.IsDBNull(2) ? "" : reader.GetString(2);
             var data = userIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
             var info = new ChatInfo
             {
                 Name = name,
                 ChatId = chatId,
                 UserIds = new List<long>()
             };
             foreach (var id in data)
             {
                 if (id.Length > 0)
                     info.UserIds.Add(Int64.Parse(id));
             }
             result.Add(info);
         }
     }
     return result;
 }
Beispiel #2
0
 public ChatInfo GetChatInfoById(long chatId)
 {
     const string sql = "select c.UserIds, c.Name from Chat c where c.ChatId=@ChatId";
     using (var reader = DbUtil.ExecuteSql(LyncDb.GetDb().SqlCnn, sql, new[]
     {
             DbUtil.BuildParameter("@ChatId", DbType.Int64, chatId),
     }))
     {
         while (reader.Read())
         {
             string userIds = reader.GetString(0);
             string name = reader.IsDBNull(1) ? "" : reader.GetString(1);
             var data = userIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
             var info = new ChatInfo
             {
                 Name = name,
                 ChatId = chatId,
                 UserIds = new List<long>()
             };
             foreach (var id in data)
             {
                 if (id.Length > 0)
                     info.UserIds.Add(Int64.Parse(id));
             }
             return info;
         }
     }
     return null;
 }