Ejemplo n.º 1
0
        public Result AddGroup(Group group)
        {

            string groupId = DALService.AddGroup(group);

            if (groupId == null)
                return new Result() { Status = MessageStatus.Failed };
            else
                return new Result() { Status = MessageStatus.OK, Group = new Group() { 
                    GroupId = groupId, 
                    Name = group.Name,
                    OwnerId = group.OwnerId,
                    GroupMember = new List<Member>() { DALService.GetMember(group.OwnerId) } } };
        }
Ejemplo n.º 2
0
        public static Group GetGroupByGroupId(string groupId)
        {
            MySqlCommand cmd = null;
            Group g = null;
            Dictionary<string, List<string>> tempIds = new Dictionary<string, List<string>>();
            try
            {
                string sql = String.Format("select * from tblGroup where groupId=?groupId");
                cmd = new MySqlCommand(sql, Conn);
                cmd.Parameters.AddWithValue("groupId", groupId);
                Prepare(cmd.Parameters);
                using (var reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                         g = new Group();
                        g.GroupId = reader["groupId"].ToString();
                        g.Name = reader["name"].ToString();
                        g.OwnerId = reader["ownerId"].ToString();
                        tempIds.Add(g.GroupId, GetNames(reader["groupMember"].ToString()));

                        
                    }
                }

                if (tempIds.Count > 0)
                {
                    List<Member> members = new List<Member>();
                    members.Add(GetMember(g.OwnerId));
                    foreach (string tempId in tempIds[g.GroupId])
                    {
                        members.Add(GetMember(tempId));
                    }
                    g.GroupMember = members;
                }
                return g;

            }
            catch (Exception e)
            {
                MyLogger.Logger.Error("获取群组时候出现错误", e);
                return null;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();


            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取组列表
        /// </summary>
        /// <param name="id">用户id</param>
        /// <returns></returns>

        public static List<Group> GetAllGroups(string id)
        {
            MySqlCommand cmd = null;
            List<Group> groups = new List<Group>();
            Dictionary<string, List<string>> tempIds = new Dictionary<string, List<string>>();
            try
            {
                string sql = String.Format("select * from tblGroup where ownerId=?ownerId");
                cmd = new MySqlCommand(sql, Conn);
                cmd.Parameters.AddWithValue("ownerId", id);
                Prepare(cmd.Parameters);
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Group g = new Group();
                        g.GroupId = reader["groupId"].ToString();
                        g.Name = reader["name"].ToString();
                        g.OwnerId = reader["ownerId"].ToString();
                        tempIds.Add(g.GroupId, GetNames(reader["groupMember"].ToString()));
                        groups.Add(g);
                    }
                }
                cmd.Parameters.Clear();
                cmd.CommandText = String.Format("select * from tblGroup where groupMember like ?groupMember");
                cmd.Parameters.AddWithValue("groupMember", "%"+id+"%");
                cmd.Parameters.AddWithValue("ownerId", id);
                Prepare(cmd.Parameters);
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Group g = new Group();
                        g.GroupId = reader["groupId"].ToString();
                        g.Name = reader["name"].ToString();
                        g.OwnerId = reader["ownerId"].ToString();
                        tempIds.Add(g.GroupId, GetNames(reader["groupMember"].ToString()));
                        groups.Add(g);
                    }
                }

                foreach (Group g in groups)
                {

                    List<Member> members = new List<Member>();
                    members.Add(GetMember(g.OwnerId));
                    foreach (string tempId in tempIds[g.GroupId])
                    {
                        members.Add(GetMember(tempId));
                    }
                    g.GroupMember = members;

                }

                return groups;

            }
            catch (Exception e)
            {
                MyLogger.Logger.Error("获取群组时候出现错误", e);
                return null;
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();


            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 添加群组
        /// </summary>
        /// <param name="group">群组</param>
        /// <returns></returns>
        public static string AddGroup(Group group)
        {
            MySqlCommand cmd = null;
            try
            {
                group.GroupId = NewGroupId(6);

                string sql = String.Format("insert into tblGroup(groupId,name,ownerId,groupMember) values(?groupId,?name,?ownerId,?groupMember)");
                cmd = new MySqlCommand(sql, Conn);
                cmd.Parameters.AddWithValue("groupId", group.GroupId);
                cmd.Parameters.AddWithValue("name", group.Name);
                cmd.Parameters.AddWithValue("ownerId", group.OwnerId);
               
                Prepare(cmd.Parameters);
                StringBuilder sb = new StringBuilder();
                if (group.GroupMember != null)
                    foreach (Member tempMember in group.GroupMember)
                    {
                        sb.Append(tempMember.Id + ";");
                    }
                cmd.Parameters.AddWithValue("groupMember", sb.ToString());

                int i1 = cmd.ExecuteNonQuery();




                if (i1 == 1)
                    return group.GroupId;
                else return null;
            }
            catch (Exception e)
            {
                MyLogger.Logger.Error("添加群组出现错误\n", e);

                return null;
            }

            finally
            {

                if (cmd != null)
                    cmd.Dispose();


            }
        }