コード例 #1
0
ファイル: Group.cs プロジェクト: erynet/IMS
        public int AddGroup(IMSGroup g)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    Lib.LocalDB.Model.Group newGroup = new Group()
                    {
                        No = g.No,
                        Name = g.Name,
                        Display = g.Display,
                        CoordX = g.CoordX,
                        CoordY = g.CoordY,
                        //UpsList =
                        //    string.Join(",",
                        //        (from upsNo in g.UpsList orderby upsNo ascending select $"{upsNo}").ToArray()),
                        //CduList =
                        //    string.Join(",",
                        //        (from cudNo in g.CduList orderby cudNo ascending select $"{cudNo}").ToArray()),
                        Enabled = g.Enabled,
                        Description = g.Description
                    };
                    using (var trx = new TransactionScope())
                    {
                        ctx.Group.Add(newGroup);
                        ctx.SaveChanges();

                        trx.Complete();
                    }

                    return newGroup.Idx;
                }
            }
            catch (Exception)
            {
                return -1;
            }
        }
コード例 #2
0
ファイル: Group.cs プロジェクト: erynet/IMS
        public IMSGroups GetGroups()
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    var groups = (from g in ctx.Group orderby g.No ascending select g).ToList();
                    if (!groups.Any())
                        return null;

                    List<IMSGroup> groupList = new List<IMSGroup>();
                    foreach (var group in groups)
                    {
                        int[] upsNoArray = Regex.Split(group.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray();
                        IMSUps[] upss = (from u in ctx.Ups
                                         where upsNoArray.Contains(u.No)
                                         select new IMSUps()
                                         {
                                             Idx = u.Idx,
                                             GroupIdx = u.GroupIdx,
                                             No = u.No,
                                             Name = u.Name,
                                             MateList = u.MateList,
                                             CduNo = u.CduNo,
                                             Specification = u.Specification,
                                             Capacity = u.Capacity,
                                             IpAddress = u.IpAddress,
                                             Status = u.Status,
                                             Enabled = u.Enabled,
                                             InstallAt = u.InstallAt,
                                             Description = u.Description
                                         }).ToArray();

                        int[] cduNoArray = Regex.Split(group.CduList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray();
                        IMSCdu[] cdus = (from c in ctx.Cdu
                                         where cduNoArray.Contains(c.No)
                                         select new IMSCdu()
                                         {
                                             Idx = c.Idx,
                                             GroupIdx = c.GroupIdx,
                                             No = c.No,
                                             Name = c.Name,
                                             UpsList = c.UpsList,
                                             Extendable = c.Extendable,
                                             ContractCount = c.ContractCount,
                                             IpAddress = c.IpAddress,
                                             Status = c.Status,
                                             Enabled = c.Enabled,
                                             InstallAt = c.InstallAt,
                                             Description = c.Description
                                         }).ToArray();

                        IMSGroup imsGroup = new IMSGroup()
                        {
                            Idx = group.Idx,
                            No = group.No,
                            Name = group.Name,
                            Display = group.Display,
                            CoordX = group.CoordX,
                            CoordY = group.CoordY,
                            UpsList = upss.ToList(),
                            CduList = cdus.ToList(),
                            Status = group.Status,
                            Enabled = group.Enabled,
                            Description = group.Description
                        };
                        groupList.Add(imsGroup);
                    }

                    IMSGroups result = new IMSGroups()
                    {
                        Groups = groupList,
                        At = DateTime.Now
                    };

                    return result;
                }
            }
            catch (Exception)
            {
                return null;
            }
        }
コード例 #3
0
ファイル: Group.cs プロジェクト: erynet/IMS
        public bool SetGroup(IMSGroup g)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    var existGroup = (from gr in ctx.Group where gr.Idx == g.Idx select gr).DefaultIfEmpty(null).First();
                    if (existGroup == null)
                        return false;

                    existGroup.No = g.No;
                    existGroup.Name = g.Name;
                    existGroup.Display = g.Display;
                    existGroup.CoordX = g.CoordX;
                    existGroup.CoordY = g.CoordY;
                    // 이 부분에서 실제로 하위의 것들도 같은 관계가 되어 있는지 발리데이션 해야 한다.
                    // 그냥 
                    //existGroup.UpsList =
                    //    string.Join(",",
                    //        (from upsNo in g.UpsList orderby upsNo ascending select $"{upsNo}").ToArray());
                    //existGroup.CduList =
                    //    string.Join(",",
                    //        (from cudNo in g.CduList orderby cudNo ascending select $"{cudNo}").ToArray());
                    existGroup.Enabled = g.Enabled;
                    if (existGroup.Enabled)
                    {
                        var subUpsArray = (from u in ctx.Ups
                                           where
                                               (Regex.Split(existGroup.UpsList, @"\D+")
                                                   .Select(n => Convert.ToInt32(n))
                                                   .ToList()
                                                   .Contains(u.No))
                                           select u).ToArray();
                        foreach (var subUps in subUpsArray)
                        {
                            subUps.Enabled = g.Enabled;
                        }

                        var subCduArray = (from c in ctx.Cdu
                                           where
                                               (Regex.Split(existGroup.CduList, @"\D+")
                                                   .Select(n => Convert.ToInt32(n))
                                                   .ToList()
                                                   .Contains(c.No))
                                           select c).ToArray();
                        foreach (var subCdu in subCduArray)
                        {
                            subCdu.Enabled = g.Enabled;
                        }
                    }
                    
                    existGroup.Description = g.Description;

                    using (var trx = new TransactionScope())
                    {
                        ctx.SaveChanges();
                        trx.Complete();
                    }
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
コード例 #4
0
ファイル: Group.cs プロジェクト: erynet/IMS
        public IMSGroup GetGroup(int groupIdx)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    var group = (from g in ctx.Group where g.Idx == groupIdx select g).DefaultIfEmpty(null).First();
                    if (group == null)
                        return null;

                    int[] upsNoArray = Regex.Split(group.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray();
                    IMSUps[] upss = (from u in ctx.Ups
                                     where upsNoArray.Contains(u.No)
                                     select new IMSUps()
                                     {
                                         Idx = u.Idx,
                                         GroupIdx = u.GroupIdx,
                                         No = u.No,
                                         Name = u.Name,
                                         MateList = u.MateList,
                                         CduNo = u.CduNo,
                                         Specification = u.Specification,
                                         Capacity = u.Capacity,
                                         IpAddress = u.IpAddress,
                                         Status = u.Status,
                                         Enabled = u.Enabled,
                                         InstallAt = u.InstallAt,
                                         Description = u.Description
                                     }).ToArray();

                    int[] cduNoArray = Regex.Split(group.CduList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray();
                    IMSCdu[] cdus = (from c in ctx.Cdu
                                     where cduNoArray.Contains(c.No)
                                     select new IMSCdu()
                                     {
                                         Idx = c.Idx,
                                         GroupIdx = c.GroupIdx,
                                         No = c.No,
                                         Name = c.Name,
                                         UpsList = c.UpsList,
                                         Extendable = c.Extendable,
                                         ContractCount = c.ContractCount,
                                         IpAddress = c.IpAddress,
                                         Status = c.Status,
                                         Enabled = c.Enabled,
                                         InstallAt = c.InstallAt,
                                         Description = c.Description
                                     }).ToArray();

                    IMSGroup result = new IMSGroup()
                    {
                        Idx = group.Idx,
                        No = group.No,
                        Name = group.Name,
                        Display = group.Display,
                        CoordX = group.CoordX,
                        CoordY = group.CoordY,
                        UpsList = upss.ToList(),
                        CduList = cdus.ToList(),
                        Status = group.Status,
                        Enabled = group.Enabled,
                        Description = group.Description
                    };
                    return result;
                }
            }
            catch (Exception)
            {
                return null;
            }
        }