示例#1
0
文件: CduSocket.cs 项目: erynet/IMS
 public static List<CduSocket.Info> GetCduSocketsByNo(int cduNo)
 {
     try
     {
         using (var ctx = new LocalDB())
         {
             var socks =
                 (from s in ctx.CduSocket where s.CduIdx == cduNo orderby s.No ascending select s).ToList();
             List<CduSocket.Info> result = new List<CduSocket.Info>();
             foreach (var s in socks)
             {
                 result.Add(new CduSocket.Info()
                 {
                     isUsing = s.Enabled,
                     cduIdx = s.CduIdx,
                     cduSocketIdx = s.Idx,
                     cduSocketNo = s.No,
                     cduSocketName = s.Name
                 });
             }
             return result;
         }
     }
     catch (Exception e)
     {
         Console.WriteLine($"GetCduSockets : {e.ToString()}");
         return new List<CduSocket.Info>();
     }
 }
示例#2
0
文件: UpsEvent.cs 项目: erynet/IMS
 public static List<UpsEvent.Info> GetRecentUpsEvent(int upsNo, int maxRow = 100)
 {
     try
     {
         using (var ctx = new LocalDB())
         {
             var ces =
                 (from s in ctx.UpsEvent where s.UpsNo == upsNo orderby s.Idx descending select s).Take(maxRow).ToList();
             List<UpsEvent.Info> result = new List<UpsEvent.Info>();
             foreach (var ce in ces)
             {
                 result.Add(new UpsEvent.Info()
                 {
                     idx = ce.Idx,
                     upsNo = ce.UpsNo,
                     title = ce.Title,
                     body = ce.Body,
                     priority = ce.Priority,
                     timeStamp = ce.TimeStamp
                 });
             }
             return result;
         }
     }
     catch (Exception e)
     {
         Console.WriteLine($"GetRecentUpsEvent : {e.ToString()}");
         return new List<UpsEvent.Info>();
     }
 }
示例#3
0
文件: EventLog.cs 项目: erynet/IMS
 public static List<EventLog.Info> GetEventLog(DateTime fromTime)
 {
     try
     {
         using (var ctx = new LocalDB())
         {
             var els = (from el in ctx.EventLog where el.TimeStamp >= fromTime orderby el.Idx descending select el).ToList();
             List<EventLog.Info> result = new List<EventLog.Info>();
             foreach (var el in els)
             {
                 result.Add(new EventLog.Info()
                 {
                     idx = el.Idx,
                     code = el.Code,
                     data = el.Data,
                     description = el.Description,
                     timeStamp = el.TimeStamp
                 });
             }
             return result;
         }
     }
     catch (Exception e)
     {
         Console.WriteLine($"GetEventLog : {e.ToString()}");
         return null;
     }
 }
示例#4
0
文件: UpsEvent.cs 项目: erynet/IMS
 public static List<UpsEvent.Info> GetUpsEventRange(int upsNo, DateTime fromTime, DateTime toTime)
 {
     try
     {
         using (var ctx = new LocalDB())
         {
             var ces =
                 (from s in ctx.UpsEvent where s.UpsNo == upsNo && (s.TimeStamp >= fromTime && s.TimeStamp <= toTime) orderby s.Idx descending select s).ToList();
             List<UpsEvent.Info> result = new List<UpsEvent.Info>();
             foreach (var ce in ces)
             {
                 result.Add(new UpsEvent.Info()
                 {
                     idx = ce.Idx,
                     upsNo = ce.UpsNo,
                     title = ce.Title,
                     body = ce.Body,
                     priority = ce.Priority,
                     timeStamp = ce.TimeStamp
                 });
             }
             return result;
         }
     }
     catch (Exception e)
     {
         Console.WriteLine($"GetUpsEventRange : {e.ToString()}");
         return new List<UpsEvent.Info>();
     }
 }
示例#5
0
文件: WarningLog.cs 项目: erynet/IMS
 public static List<WarningLog.Info> GetWarningLog(DateTime fromTime)
 {
     try
     {
         using (var ctx = new LocalDB())
         {
             var wls = (from wl in ctx.WarningLog where wl.TimeStamp >= fromTime orderby wl.Idx descending select wl).ToList();
             List<WarningLog.Info> result = new List<WarningLog.Info>();
             foreach (var wl in wls)
             {
                 result.Add(new WarningLog.Info()
                 {
                     idx = wl.Idx,
                     code = wl.Code,
                     data = wl.Data,
                     deviceNo = wl.DeviceNo,
                     priority = wl.Priority,
                     description = wl.Description,
                     timeStamp = wl.TimeStamp
                 });
             }
             return result;
         }
     }
     catch (Exception e)
     {
         Console.WriteLine($"GetWaringLog : {e.ToString()}");
         return null;
     }
 }
示例#6
0
文件: CduSocket.cs 项目: erynet/IMS
        public static bool SetCduSocket(int cduIdx, List<CduSocket.Info> newInfo)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    var existSockets = (from s in ctx.CduSocket where s.CduIdx == cduIdx select s).ToList();
                    List<Database.LocalDB.Model.CduSocket> newSockets = new List<Database.LocalDB.Model.CduSocket>();
                    var ns = (from s in newInfo select s).ToList();
                    foreach (var s in ns)
                    {
                        newSockets.Add(new Database.LocalDB.Model.CduSocket()
                        {
                            CduIdx = s.cduIdx,
                            No = s.cduSocketNo,
                            Name = s.cduSocketName,
                            Enabled = s.isUsing
                        });
                    }

                    using (var trx = new TransactionScope())
                    {
                        ctx.CduSocket.RemoveRange(existSockets);
                        ctx.CduSocket.AddRange(newSockets);
                        ctx.SaveChanges();
                        trx.Complete();
                    }
                    return true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"SetCduSocket : {e.ToString()}");
                return false;
            }
        }
示例#7
0
文件: Ups.cs 项目: erynet/IMS
        public static bool DelUps(int upsIdx)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    var existUps = (from u in ctx.Ups where u.Idx == upsIdx select u).DefaultIfEmpty(null).First();
                    if (existUps == null)
                        return false;

                    using (var trx = new TransactionScope())
                    {
                        ctx.Ups.Remove(existUps);
                        ctx.SaveChanges();
                        trx.Complete();
                    }
                }
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine($"DelUps : {e.ToString()}");
                return false;
            }
        }
示例#8
0
文件: Ups.cs 项目: erynet/IMS
        public static bool SetUps(Ups.Info ups)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    var existUps =
                        (from u in ctx.Ups where u.Idx == ups.upsIdx select u).DefaultIfEmpty(null).First();
                    if (existUps == null)
                        return false;

                    //existCdu.GroupNo = cdu.
                    existUps.GroupNo = ups.groupNo;
                    existUps.No = ups.upsNo;
                    existUps.Name = ups.upsName;
                    existUps.MateList = ups.partnerNoList.ToString();
                    existUps.CduNo = ups.cduNo;
                    existUps.Specification = ups.batteryDescription;
                    existUps.Capacity = ups.batteryCapacity;
                    existUps.IpAddress = ups.ip;
                    existUps.Enabled = ups.isUsing;
                    existUps.InstallAt = ups.installDate;
                    //existCdu.Description = cdu.

                    using (var trx = new TransactionScope())
                    {
                        ctx.SaveChanges();
                        trx.Complete();
                    }
                }
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine($"SetUps : {e.ToString()}");
                return false;
            }
        }
示例#9
0
文件: Program.cs 项目: erynet/IMS
        static void Main(string[] args)
        {
            using (var ctx = new LocalDB())
            {
                ctx.Database.Initialize(true);

                Group g1 = new Group()
                {
                    No = 1,
                    Name = "그룹01",
                    Display = true,
                    CoordX = 400,
                    CoordY = 600,
                    Status = 0,
                    Enabled = true,
                    Description = null
                };

                Group g2 = new Group()
                {
                    No = 2,
                    Name = "그룹02",
                    Display = true,
                    CoordX = 600,
                    CoordY = 800,
                    Status = 0,
                    Enabled = true,
                    Description = null
                };

                using (var trx = new TransactionScope())
                {
                    ctx.Group.Add(g1);
                    ctx.Group.Add(g2);
                    ctx.SaveChanges();

                    trx.Complete();
                }

                CDU c1 = new CDU()
                {
                    GroupNo = 1,
                    No = 1,
                    Name = "CDU01",
                    Extendable = true,
                    IpAddress = "192.168.1.2",
                    Status = 0,
                    Enabled = true,
                    InstallAt = "2015.1.14",
                    Description = null
                };

                CDU c2 = new CDU()
                {
                    GroupNo = 1,
                    No = 2,
                    Name = "CDU02",
                    Extendable = true,
                    IpAddress = "192.168.1.3",
                    Status = 0,
                    Enabled = true,
                    InstallAt = "2015.1.14",
                    Description = null
                };

                CDU c3 = new CDU()
                {
                    GroupNo = 1,
                    No = 3,
                    Name = "CDU03",
                    Extendable = true,
                    IpAddress = "192.168.1.4",
                    Status = 0,
                    Enabled = true,
                    InstallAt = "2015.1.14",
                    Description = null
                };

                using (var trx = new TransactionScope())
                {
                    ctx.Cdu.Add(c1);
                    ctx.Cdu.Add(c2);
                    ctx.Cdu.Add(c3);
                    ctx.SaveChanges();

                    trx.Complete();
                }

                UPS u1 = new UPS()
                {
                    GroupNo = 1,
                    No = 1,
                    Name = "UPS01",
                    MateList = null,
                    CduNo = 1,
                    Specification = "듀라셀",
                    Capacity = "2Kw",
                    IpAddress = "192.168.0.2",
                    Status = 0,
                    Enabled = true,
                    InstallAt = "2016.1.15",
                    Description = null
                };

                UPS u2 = new UPS()
                {
                    GroupNo = 1,
                    No = 2,
                    Name = "UPS02",
                    MateList = null,
                    CduNo = 1,
                    Specification = "듀라셀",
                    Capacity = "2Kw",
                    IpAddress = "192.168.0.3",
                    Status = 0,
                    Enabled = true,
                    InstallAt = "2016.1.15",
                    Description = null
                };
                
                UPS u3 = new UPS()
                {
                    GroupNo = 1,
                    No = 3,
                    Name = "UPS03",
                    MateList = null,
                    CduNo = 2,
                    Specification = "듀라셀",
                    Capacity = "2Kw",
                    IpAddress = "192.168.0.4",
                    Status = 0,
                    Enabled = true,
                    InstallAt = "2016.1.15",
                    Description = null
                };
                
                UPS u4 = new UPS()
                {
                    GroupNo = 2,
                    No = 4,
                    Name = "UPS04",
                    MateList = null,
                    CduNo = 3,
                    Specification = "로케트",
                    Capacity = "2Kw",
                    IpAddress = "192.168.0.5",
                    Status = 0,
                    Enabled = true,
                    InstallAt = "2016.1.15",
                    Description = null
                };

                UPS u5 = new UPS()
                {
                    GroupNo = 2,
                    No = 5,
                    Name = "UPS05",
                    MateList = null,
                    CduNo = 3,
                    Specification = "로케트",
                    Capacity = "2Kw",
                    IpAddress = "192.168.0.6",
                    Status = 0,
                    Enabled = true,
                    InstallAt = "2016.1.15",
                    Description = null
                };

                using (var trx = new TransactionScope())
                {
                    ctx.Ups.Add(u1);
                    ctx.Ups.Add(u2);
                    ctx.Ups.Add(u3);
                    ctx.Ups.Add(u4);
                    ctx.Ups.Add(u5);
                    ctx.SaveChanges();

                    trx.Complete();
                }

                
            }
        }
示例#10
0
文件: Group.cs 项目: erynet/IMS
        public static List<Group.Info> GetGroups(bool ascending = true)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    var upsTotal = (from u in ctx.Ups orderby u.Idx ascending select u).ToList();

                    if (ascending)
                    {
                        var grs = (from g in ctx.Group orderby g.No ascending select g).ToList();
                        //var grs = (from g in ctx.Group select g).First();
                        List<Group.Info> result = new List<Group.Info>();
                        foreach (var g in grs)
                        {
                            result.Add(new Group.Info()
                            {
                                isUsing = g.Enabled,
                                groupIdx = g.Idx,
                                groupNo = g.No,
                                isGroupVisible = g.Display,
                                groupName = g.Name,
                                coordinate = new Point(g.CoordX, g.CoordY),
                                //upsIdxList = new IntList((from u in upsTotal where Regex.Split(g.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToList().Contains(u.No) select u.Idx).ToArray()),
                                //upsNoList = new IntList(Regex.Split(g.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray())
                                upsIdxList = new IntList((from u in upsTotal where u.GroupNo == g.No orderby u.No ascending select u.Idx).ToArray()),
                                upsNoList = new IntList((from u in upsTotal where u.GroupNo == g.No orderby u.No ascending select u.No).ToArray())
                            });
                        }
                        return result;
                    }
                    //return (from g in ctx.Group
                    //        orderby g.No ascending
                    //        select new Group.Info()
                    //        {
                    //            isUsing = g.Enabled,
                    //            groupIdx = g.Idx,
                    //            groupNo = g.No,
                    //            isGroupVisible = g.Display,
                    //            groupName = g.Name,
                    //            coordinate = new Point(g.CoordX, g.CoordY),
                    //            //upsIdxList = new IntList((from u in upsTotal where Regex.Split(g.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToList().Contains(u.No) select u.Idx).ToArray()),
                    //            //upsNoList = new IntList(Regex.Split(g.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray())
                    //            upsIdxList = new IntList((from u in upsTotal where u.GroupNo == g.Idx orderby u.No ascending select u.Idx).ToArray()),
                    //            upsNoList = new IntList((from u in upsTotal where u.GroupNo == g.Idx orderby u.No ascending select u.No).ToArray())
                    //        }).ToList();
                    else
                    {
                        var grs = (from g in ctx.Group orderby g.No ascending select g).ToList();
                        List<Group.Info> result = new List<Group.Info>();
                        foreach (var g in grs)
                        {
                            result.Add(new Group.Info()
                            {
                                isUsing = g.Enabled,
                                groupIdx = g.Idx,
                                groupNo = g.No,
                                isGroupVisible = g.Display,
                                groupName = g.Name,
                                coordinate = new Point(g.CoordX, g.CoordY),
                                //upsIdxList = new IntList((from u in upsTotal where Regex.Split(g.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToList().Contains(u.No) select u.Idx).ToArray()),
                                //upsNoList = new IntList(Regex.Split(g.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray())
                                upsIdxList = new IntList((from u in upsTotal where u.GroupNo == g.No orderby u.No ascending select u.Idx).ToArray()),
                                upsNoList = new IntList((from u in upsTotal where u.GroupNo == g.No orderby u.No ascending select u.No).ToArray())
                            });
                        }
                        return result;
                    }
                    //return (from g in ctx.Group
                    //        orderby g.No descending
                    //        select new Group.Info()
                    //        {
                    //            isUsing = g.Enabled,
                    //            groupIdx = g.Idx,
                    //            groupNo = g.No,
                    //            isGroupVisible = g.Display,
                    //            groupName = g.Name,
                    //            coordinate = new Point(g.CoordX, g.CoordY),
                    //            //upsIdxList = new IntList((from u in upsTotal where Regex.Split(g.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToList().Contains(u.No) select u.Idx).ToArray()),
                    //            //upsNoList = new IntList(Regex.Split(g.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray())
                    //            upsIdxList = new IntList((from u in upsTotal where u.GroupNo == g.Idx orderby u.No ascending select u.Idx).ToArray()),
                    //            upsNoList = new IntList((from u in upsTotal where u.GroupNo == g.Idx orderby u.No ascending select u.No).ToArray())
                    //        }).ToList();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"GetGroups : {e.ToString()}");
                return new List<Group.Info>();
            }
        }
示例#11
0
文件: Cdu.cs 项目: erynet/IMS
        public static bool AddCdu(Cdu.Info cdu)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    Database.LocalDB.Model.CDU newcdu = new Database.LocalDB.Model.CDU()
                    {
                        No = cdu.cduNo,
                        Name = cdu.cduName,
                        Extendable = cdu.isExtended,
                        IpAddress = cdu.ip,
                        Enabled = cdu.isUsing,
                        InstallAt = cdu.installDate,
                    };

                    using (var trx = new TransactionScope())
                    {
                        ctx.Cdu.Add(newcdu);
                        ctx.SaveChanges();
                        trx.Complete();
                    }
                }
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine($"AddCdu : {e.ToString()}");
                return false;
            }
        }
示例#12
0
文件: Cdu.cs 项目: erynet/IMS
        public static bool DelCdu(int cduIdx)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    var existCdu = (from c in ctx.Cdu where c.Idx == cduIdx select c).DefaultIfEmpty(null).First();
                    if (existCdu == null)
                        return false;

                    using (var trx = new TransactionScope())
                    {
                        ctx.Cdu.Remove(existCdu);
                        ctx.SaveChanges();
                        trx.Complete();
                    }
                }
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine($"DelCdu : {e.ToString()}");
                return false;
            }
        }
示例#13
0
文件: Cdu.cs 项目: erynet/IMS
        public static Cdu.Info GetCduByNo(int cduNo)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    var upsTotal = (from u in ctx.Ups orderby u.Idx ascending select u).ToList();

                    var c = (from cdu in ctx.Cdu where cdu.No == cduNo select cdu).DefaultIfEmpty(null).First();
                    if (c == null)
                        return null;

                    return new Cdu.Info()
                    {
                        isUsing = c.Enabled,
                        cduIdx = c.Idx,
                        cduNo = c.No,
                        cduName = c.Name,
                        isExtended = c.Extendable,
                        upsIdxList = new IntList((from u in upsTotal where u.CduNo == c.No orderby u.No ascending select u.Idx).ToArray()),
                        upsNoList = new IntList((from u in upsTotal where u.CduNo == c.No orderby u.No ascending select u.No).ToArray()),
                        installDate = c.InstallAt,
                        ip = c.IpAddress
                    };

                    //return (from c in ctx.Cdu
                    //        where c.No == cduNo
                    //        select new Cdu.Info()
                    //        {
                    //            isUsing = c.Enabled,
                    //            cduIdx = c.Idx,
                    //            cduNo = c.No,
                    //            cduName = c.Name,
                    //            isExtended = c.Extendable,
                    //            //upsIdxList = new IntList((from u in upsTotal where Regex.Split(c.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToList().Contains(u.No) select u.Idx).ToArray()),
                    //            //upsNoList = new IntList(Regex.Split(c.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray()),
                    //            upsIdxList = new IntList((from u in upsTotal where u.CduNo == c.No orderby u.No ascending select u.Idx).ToArray()),
                    //            upsNoList = new IntList((from u in upsTotal where u.CduNo == c.No orderby u.No ascending select u.No).ToArray()),
                    //            installDate = c.InstallAt,
                    //            ip = c.IpAddress
                    //        }).DefaultIfEmpty(null).First();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"GetCduByNo : {e.ToString()}");
                return null;
            }
        }
示例#14
0
文件: Cdu.cs 项目: erynet/IMS
        public static bool SetCdu(Cdu.Info cdu)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    var existCdu =
                        (from c in ctx.Cdu where c.Idx == cdu.cduIdx select c).DefaultIfEmpty(null).First();
                    if (existCdu == null)
                        return false;

                    //existCdu.GroupNo = cdu.
                    existCdu.No = cdu.cduNo;
                    existCdu.Name = cdu.cduName;
                    existCdu.Extendable = cdu.isExtended;
                    existCdu.IpAddress = cdu.ip;
                    existCdu.Enabled = cdu.isUsing;
                    existCdu.InstallAt = cdu.installDate;
                    //existCdu.Description = cdu.

                    using (var trx = new TransactionScope())
                    {
                        ctx.SaveChanges();
                        trx.Complete();
                    }
                }
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine($"SetCdu : {e.ToString()}");
                return false;
            }
        }
示例#15
0
文件: Ups.cs 项目: erynet/IMS
        public static bool AddUps(Ups.Info ups)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    UPS newUps = new UPS()
                    {
                        GroupNo = ups.groupNo,
                        No = ups.upsNo,
                        Name = ups.upsName,
                        MateList = ups.partnerNoList.ToString(),
                        CduNo = ups.cduNo,
                        Specification = ups.batteryDescription,
                        Capacity = ups.batteryCapacity,
                        IpAddress = ups.ip,
                        Enabled = ups.isUsing,
                        InstallAt = ups.installDate,
                    };

                    using (var trx = new TransactionScope())
                    {
                        ctx.Ups.Add(newUps);
                        ctx.SaveChanges();
                        trx.Complete();
                    }
                }
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine($"AddUps : {e.ToString()}");
                return false;
            }
        }
示例#16
0
文件: Cdu.cs 项目: erynet/IMS
        public static List<Cdu.Info> GetCdus(bool ascending = true)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    var upsTotal = (from u in ctx.Ups orderby u.Idx ascending select u).ToList();

                    if (ascending)
                    {
                        var cdus = (from c in ctx.Cdu orderby c.No ascending select c).ToList();
                        List<Cdu.Info> result = new List<Cdu.Info>();
                        foreach (var c in cdus)
                        {
                            result.Add(new Cdu.Info()
                            {
                                isUsing = c.Enabled,
                                cduIdx = c.Idx,
                                cduNo = c.No,
                                cduName = c.Name,
                                isExtended = c.Extendable,
                                //upsIdxList = new IntList((from u in upsTotal where u.GroupNo == g.Idx orderby u.No ascending select u.Idx).ToArray()),
                                //upsNoList = new IntList((from u in upsTotal where u.GroupNo == g.Idx orderby u.No ascending select u.No).ToArray())
                                //upsIdxList = new IntList((from u in upsTotal where Regex.Split(c.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToList().Contains(u.No) select u.Idx).ToArray()),
                                //upsNoList = new IntList(Regex.Split(c.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray()),
                                upsIdxList = new IntList((from u in upsTotal where u.CduNo == c.No orderby u.No ascending select u.Idx).ToArray()),
                                upsNoList = new IntList((from u in upsTotal where u.CduNo == c.No orderby u.No ascending select u.No).ToArray()),
                                installDate = c.InstallAt,
                                ip = c.IpAddress
                            });
                        }
                        return result;
                    }
                        //return (from c in ctx.Cdu
                        //        orderby c.No ascending
                        //        select new Cdu.Info()
                        //        {
                        //            isUsing = c.Enabled,
                        //            cduIdx = c.Idx,
                        //            upsNo = c.No,
                        //            cduName = c.Name,
                        //            isExtended = c.Extendable,
                        //            //upsIdxList = new IntList((from u in upsTotal where u.GroupNo == g.Idx orderby u.No ascending select u.Idx).ToArray()),
                        //            //upsNoList = new IntList((from u in upsTotal where u.GroupNo == g.Idx orderby u.No ascending select u.No).ToArray())
                        //            //upsIdxList = new IntList((from u in upsTotal where Regex.Split(c.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToList().Contains(u.No) select u.Idx).ToArray()),
                        //            //upsNoList = new IntList(Regex.Split(c.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray()),
                        //            upsIdxList = new IntList((from u in upsTotal where u.CduNo == c.No orderby u.No ascending select u.Idx).ToArray()),
                        //            upsNoList = new IntList((from u in upsTotal where u.CduNo == c.No orderby u.No ascending select u.No).ToArray()),
                        //            installDate = c.InstallAt,
                        //            ip = c.IpAddress
                        //        }).ToList();
                    else
                    {
                        var cdus = (from c in ctx.Cdu orderby c.No descending select c).ToList();
                        List<Cdu.Info> result = new List<Cdu.Info>();
                        foreach (var c in cdus)
                        {
                            result.Add(new Cdu.Info()
                            {
                                isUsing = c.Enabled,
                                cduIdx = c.Idx,
                                cduNo = c.No,
                                cduName = c.Name,
                                isExtended = c.Extendable,
                                //upsIdxList = new IntList((from u in upsTotal where u.GroupNo == g.Idx orderby u.No ascending select u.Idx).ToArray()),
                                //upsNoList = new IntList((from u in upsTotal where u.GroupNo == g.Idx orderby u.No ascending select u.No).ToArray())
                                //upsIdxList = new IntList((from u in upsTotal where Regex.Split(c.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToList().Contains(u.No) select u.Idx).ToArray()),
                                //upsNoList = new IntList(Regex.Split(c.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray()),
                                upsIdxList = new IntList((from u in upsTotal where u.CduNo == c.No orderby u.No ascending select u.Idx).ToArray()),
                                upsNoList = new IntList((from u in upsTotal where u.CduNo == c.No orderby u.No ascending select u.No).ToArray()),
                                installDate = c.InstallAt,
                                ip = c.IpAddress
                            });
                        }
                        return result;
                    }
                    //return (from c in ctx.Cdu
                    //        orderby c.No descending
                    //        select new Cdu.Info()
                    //        {
                    //            isUsing = c.Enabled,
                    //            cduIdx = c.Idx,
                    //            upsNo = c.No,
                    //            cduName = c.Name,
                    //            isExtended = c.Extendable,
                    //            //upsIdxList = new IntList((from u in upsTotal where Regex.Split(c.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToList().Contains(u.No) select u.Idx).ToArray()),
                    //            //upsNoList = new IntList(Regex.Split(c.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray()),
                    //            upsIdxList = new IntList((from u in upsTotal where u.CduNo == c.No orderby u.No ascending select u.Idx).ToArray()),
                    //            upsNoList = new IntList((from u in upsTotal where u.CduNo == c.No orderby u.No ascending select u.No).ToArray()),
                    //            installDate = c.InstallAt,
                    //            ip = c.IpAddress
                    //        }).ToList();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"GetCdus : {e.ToString()}");
                return new List<Cdu.Info>();
            }
        }
示例#17
0
文件: Ups.cs 项目: erynet/IMS
        public static Ups.Info GetUpsByNo(int upsNo)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    var groupTotal = (from g in ctx.Group orderby g.No ascending select g).ToArray();
                    var upsTotal = (from ups in ctx.Ups orderby ups.No ascending select ups).ToArray();
                    var cduTotal = (from c in ctx.Cdu orderby c.No ascending select c).ToArray();

                    var u = (from ups in ctx.Ups where ups.No == upsNo select ups).DefaultIfEmpty(null).First();
                    if (u == null)
                        return null;

                    IntList tempPartnerIdxList;
                    IntList tempPartnerNoList;
                    if ((u.MateList == null) || (u.MateList.Length == 0))
                    {
                        tempPartnerIdxList = new IntList();
                        tempPartnerNoList = new IntList();
                    }
                    else
                    {
                        tempPartnerIdxList = new IntList((from iu in upsTotal where (Regex.Split(u.MateList, @"\D+").Select(n => Convert.ToInt32(n)).Contains(iu.No)) orderby iu.No ascending select iu.Idx).ToArray());
                        tempPartnerNoList = new IntList(Regex.Split(u.MateList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray());
                    }

                    return new Ups.Info()
                    {
                        isUsing = u.Enabled,
                        upsIdx = u.Idx,
                        upsNo = u.No,
                        groupIdx = u.GroupNo,
                        groupNo = (from g in groupTotal where g.Idx == u.GroupNo select g.No).DefaultIfEmpty(0).FirstOrDefault(),
                        upsName = u.Name,
                        partnerIdxList = tempPartnerIdxList,
                        partnerNoList = tempPartnerNoList,
                        cduIdx = (from c in cduTotal where c.Idx == u.CduNo select c.Idx).DefaultIfEmpty(0).FirstOrDefault(),
                        cduNo = u.CduNo,
                        batteryDescription = u.Specification,
                        batteryCapacity = u.Capacity,
                        ip = u.IpAddress,
                        installDate = u.InstallAt
                    };

                    //return (from u in ctx.Ups
                    //        where u.No == upsNo
                    //        select new Ups.Info()
                    //        {
                    //            isUsing = u.Enabled,
                    //            upsIdx = u.Idx,
                    //            upsNo = u.No,
                    //            groupIdx = (from g in groupTotal where g.No == u.GroupNo select g.Idx).DefaultIfEmpty(0).FirstOrDefault(),
                    //            groupNo = u.GroupNo,
                    //            upsName = u.Name,
                    //            partnerIdxList = new IntList((from iu in upsTotal where Regex.Split(u.MateList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray().Contains(iu.No) orderby iu.No ascending select iu.Idx).ToArray()),
                    //            partnerNoList = new IntList(Regex.Split(u.MateList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray()),
                    //            cduIdx = (from c in cduTotal where c.Idx == u.CduNo select c.Idx).DefaultIfEmpty(0).FirstOrDefault(),
                    //            cduNo = u.CduNo,
                    //            batteryDescription = u.Specification,
                    //            batteryCapacity = u.Capacity,
                    //            ip = u.IpAddress,
                    //            installDate = u.InstallAt
                    //        }).DefaultIfEmpty(null).First();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"GetUpsByNo : {e.ToString()}");
                return null;
            }
        }
示例#18
0
文件: Group.cs 项目: erynet/IMS
        public static bool DelGroup(int groupIdx)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    var existGroup = (from g in ctx.Group where g.Idx == groupIdx select g).DefaultIfEmpty(null).First();
                    if (existGroup == null)
                        return false;

                    using (var trx = new TransactionScope())
                    {
                        ctx.Group.Remove(existGroup);
                        ctx.SaveChanges();
                        trx.Complete();
                    }
                }
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine($"DelGroup : {e.ToString()}");
                return false;
            }
        }
示例#19
0
文件: Group.cs 项目: erynet/IMS
        public static bool AddGroup(Group.Info gr)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    Database.LocalDB.Model.Group newGroup = new Database.LocalDB.Model.Group()
                    {
                        No = gr.groupNo,
                        Name = gr.groupName,
                        Display = gr.isGroupVisible,
                        CoordX = gr.coordinate.X,
                        CoordY = gr.coordinate.Y,
                        Enabled = gr.isUsing
                    };

                    using (var trx = new TransactionScope())
                    {
                        ctx.Group.Add(newGroup);
                        ctx.SaveChanges();
                        trx.Complete();
                    }
                }
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine($"AddGroup : {e.ToString()}");
                return false;
            }
        }
示例#20
0
文件: Group.cs 项目: erynet/IMS
        public static bool SetGroup(Group.Info gr)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    var existGroup =
                        (from g in ctx.Group where g.Idx == gr.groupIdx select g).DefaultIfEmpty(null).First();
                    if (existGroup == null)
                        return false;

                    existGroup.No = gr.groupNo;
                    existGroup.Name = gr.groupName;
                    existGroup.Display = gr.isGroupVisible;
                    existGroup.CoordX = gr.coordinate.X;
                    existGroup.CoordY = gr.coordinate.Y;
                    existGroup.Enabled = gr.isUsing;

                    using (var trx = new TransactionScope())
                    {
                        ctx.SaveChanges();
                        trx.Complete();
                    }
                }
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine($"SetGroup : {e.ToString()}");
                return false;
            }
        }
示例#21
0
文件: Group.cs 项目: erynet/IMS
        public static Group.Info GetGroupByNo(int groupNo)
        {
            try
            {
                using (var ctx = new LocalDB())
                {
                    var upsTotal = (from u in ctx.Ups orderby u.Idx ascending select u).ToList();

                    var gr = (from g in ctx.Group
                              where g.Idx == groupNo
                              select g).DefaultIfEmpty(null).First();
                    if (gr == null)
                        return null;

                    return new Group.Info()
                    {
                        isUsing = gr.Enabled,
                        groupIdx = gr.Idx,
                        groupNo = gr.No,
                        isGroupVisible = gr.Display,
                        groupName = gr.Name,
                        coordinate = new Point(gr.CoordX, gr.CoordY),
                        //upsIdxList = new IntList((from u in upsTotal where Regex.Split(g.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToList().Contains(u.No) select u.Idx).ToArray()),
                        //upsNoList = new IntList(Regex.Split(g.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray())
                        upsIdxList = new IntList((from u in upsTotal where u.GroupNo == gr.Idx orderby u.No ascending select u.Idx).ToArray()),
                        upsNoList = new IntList((from u in upsTotal where u.GroupNo == gr.Idx orderby u.No ascending select u.No).ToArray())
                    };

                    //return (from g in ctx.Group
                    //        where g.No == groupNo
                    //        select new Group.Info()
                    //        {
                    //            isUsing = g.Enabled,
                    //            groupIdx = g.Idx,
                    //            groupNo = g.No,
                    //            isGroupVisible = g.Display,
                    //            groupName = g.Name,
                    //            coordinate = new Point(g.CoordX, g.CoordY),
                    //            //upsIdxList = new IntList((from u in upsTotal where Regex.Split(g.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToList().Contains(u.No) select u.Idx).ToArray()),
                    //            //upsNoList = new IntList(Regex.Split(g.UpsList, @"\D+").Select(n => Convert.ToInt32(n)).ToArray())
                    //            upsIdxList = new IntList((from u in upsTotal where u.GroupNo == g.Idx orderby u.No ascending select u.Idx).ToArray()),
                    //            upsNoList = new IntList((from u in upsTotal where u.GroupNo == g.Idx orderby u.No ascending select u.No).ToArray())
                    //        }).DefaultIfEmpty(null).First();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"GetGroupByNo : {e.ToString()}");
                return null;
            }
        }