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; } }
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(); } } }
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; } }
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; } }
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; } }
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; } }
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; } }
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; } }
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; } }
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; } }
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; } }