Esempio n. 1
0
        public Domain.PowerZone Save(PowerZoneSaverInput input, Domain.Building building)
        {
            return(_dbExecutor.Query(c =>
            {
                c.Attach(building);

                Domain.PowerZone powerZone = null;

                if (input.PowerZoneId.HasValue)
                {
                    powerZone = building.PowerZones.SingleOrDefault(z => z.PowerZoneId == input.PowerZoneId.Value);
                }

                if (powerZone == null)
                {
                    powerZone = new Domain.PowerZone {
                        BuildingId = building.BuildingId
                    };
                    building.PowerZones.Add(powerZone);
                }

                powerZone.Name = input.Name;
                powerZone.MaxUsage = input.PowerLimitValue;
                powerZone.UsageUnit = input.PowerLimitUnit;
                powerZone.RoundRobinIntervalMinutes = input.RoundRobinIntervalMinutes;
                powerZone.SwitchDelayBetweenOutputsSeconds = input.SwitchDelay;

                MergeHeaters(input, c, powerZone);

                c.SaveChanges();

                return powerZone;
            }));
        }
        public Domain.Zone Save(ZoneSaverInput input, Domain.Building building)
        {
            return(_dbExecutor.Query(c =>
            {
                c.Attach(building);

                Domain.Zone zone = null;

                if (input.ZoneId.HasValue)
                {
                    zone = building.Zones.SingleOrDefault(z => z.ZoneId == input.ZoneId.Value);

                    TryClearSchedule(input, zone);
                }

                if (zone == null)
                {
                    zone = new Domain.Zone {
                        BuildingId = building.BuildingId
                    };
                    building.Zones.Add(zone);
                }

                zone.Name = input.Name;
                zone.NameDashboardEn = input.NameDashboardEn ?? input.Name;

                MergeTemperatureControlledZone(input, c, zone);
                MergeHeaters(input, c, zone);

                c.SaveChanges();

                return zone;
            }));
        }
 /// <summary>
 ///     add a Building to the Instutite
 /// </summary>
 /// <param name="building">The Building to add</param>
 public void addBuilding(Building building)
 {
     if (buildingList == null)
     {
         buildingList = new LinkedList();
     }
     buildingList.addAtTail(building);
 }
        /// <summary>
        /// find room for a building
        /// </summary>
        /// <param name="build">the building the rooms are in</param>
        /// <returns>linked list of rooms in a building</returns>
        public LinkedList getRoomList(Building build)
        {
            LinkedList list = new LinkedList();
            Node roomNode = roomList.head;

            while (roomNode != null)
            {
                Room tempRoom = (Room)roomNode.data;
                if (tempRoom.buildingId == build.ID)
                {
                    list.addAtTail(tempRoom);
                }
            }
            return list;
        }
Esempio n. 5
0
        public Domain.Heater Save(HeaterSaverInput input, Domain.Building building)
        {
            return(_dbExecutor.Query(c =>
            {
                c.Attach(building);

                Domain.Heater heater = null;

                if (input.HeaterId.HasValue)
                {
                    heater = c.Heaters.Find(input.HeaterId.Value);
                }

                if (heater == null)
                {
                    heater = new Domain.Heater {
                        BuildingId = building.BuildingId, DigitalOutput = new DigitalOutput()
                    };

                    building.Heaters.Add(heater);
                }
                else
                {
                    if (heater.PowerZoneId.HasValue &&
                        heater.UsageUnit != input.UsageUnit)
                    {
                        heater.PowerZone = null;
                        heater.PowerZoneId = null;

                        Logger.Info(Localization.NotificationMessage.HeaterRemovedFromPowerZoneDueToUsageUnitChange.FormatWith(input.Name));
                    }
                }

                heater.Name = input.Name;
                heater.UsageUnit = input.UsageUnit;
                heater.UsagePerHour = input.UsagePerHour;
                heater.MinimumStateChangeIntervalSeconds = input.MinimumStateChangeIntervalSeconds;
                heater.DigitalOutput.ProtocolName = input.PowerOutputProtocolName;
                heater.DigitalOutput.OutputDescriptor = Newtonsoft.Json.JsonConvert.SerializeObject(input.PowerOutputDescriptor);
                heater.DigitalOutput.DeviceId = -1;

                c.SaveChanges();

                return heater;
            }));
        }
Esempio n. 6
0
        public void Remove(Domain.Zone zone, Domain.Building building)
        {
            _dbExecutor.Execute(c =>
            {
                c.Attach(building);

                building.Zones.Remove(zone);

                c.Zones.Remove(zone);

                if (zone.TemperatureControlledZone != null)
                {
                    c.Set <Domain.TemperatureControlledZone>().Remove(zone.TemperatureControlledZone);
                }

                if (zone.Schedule.Count > 0)
                {
                    c.Set <ScheduleItem>().RemoveRange(zone.Schedule);
                }

                c.SaveChanges();
            });
        }
Esempio n. 7
0
        /// <summary>
        /// load all the buildings from the database
        /// </summary>
        private void loadBuildingList()
        {
            Building tempBuild;
            string sqlStatment = "SELECT * FROM Building";
            try
            {
                OpenConection();
                cmd = new OleDbCommand(sqlStatment, conn);
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    if (reader["Deleted"].ToString().Equals("False"))
                    {
                        tempBuild = new Building(
                            reader["ID"].ToString(), 
                            reader["Building_Name"].ToString());
                        buildingList.addAtTail(tempBuild);
                    }
                }
                CloseConnection();
            }
            catch 
            {

            }
        }
Esempio n. 8
0
 /// <summary>
 /// update a building
 /// </summary>
 /// <param name="build"></param>
 public void updateBuild(Building build)
 {
     string sql;
     sql = "Update Building Building_Name=";
     sql += "'" + build.name + "'";
     excuteNonQuery(sql);
 }
Esempio n. 9
0
 /// <summary>
 ///     Load all rooms
 /// </summary>
 /// <summary>
 /// insert building into database
 /// </summary>
 /// <param name="build"></param>
 public void insertBuild(Building build)
 {
     string sql = "INSERT INTO Building  VALUES('" + build.name + "')";
     excuteNonQuery(sql);
 }
 /// <summary>
 ///     Load the LinkedList of Room for a Building
 /// </summary>
 /// <param name="building">The Building the Rooms are in</param>
 /// <returns>Linked List of rooms</returns>
 public LinkedList loadRoomList(Building building)
 {
     LinkedList roomList = new LinkedList();
     Room tempRoom;
     string sqlStatment = "SELECT * FROM Room WHERE BuildingID LIKE  " + building.getID();
     try
     {
         OpenConection();
         cmd = new OleDbCommand(sqlStatment, conn);
         reader = cmd.ExecuteReader();
         while (reader.Read())
         {
             if (reader["Deleted"].ToString().Equals("False"))
             {
                 tempRoom = new Room();
                 tempRoom.setID(reader["ID"].ToString());
                 tempRoom.setRoomNumber(reader["Number"].ToString());
                 tempRoom.setCapacity(Convert.ToInt32(reader["Capacity"]));
                 tempRoom.setRoomType(reader["RoomType"].ToString());
                 tempRoom.setSlotsOff(reader["SlotsOff"].ToString());
                 roomList.addAtTail(tempRoom);
             }
         }
         CloseConnection();
     }
     catch
     {
         // MessageBox.Show("Failed to get data from source");
     }
     return roomList;
 }
        /// <summary>
        ///     Returns a list of buildings
        /// </summary>
        /// <param name="institute">The Institute the Buildings are in</param>
        /// <returns>A LinkedList of Buildings</returns>
        public LinkedList loadBuildingList(Institute institute)
        {
            LinkedList buildingList = new LinkedList();
            Building tempBuild;
            string sqlStatment = "SELECT * FROM Building";
            try
            {
                OpenConection();
                cmd = new OleDbCommand(sqlStatment, conn);
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    if (reader["Deleted"].ToString().Equals("False"))
                    {
                        tempBuild = new Building();
                        tempBuild.setId(reader["ID"].ToString());
                        tempBuild.setName("Building_Name");
                        tempBuild.setRoomList(loadRoomList(tempBuild));
                        buildingList.addAtTail(tempBuild);
                    }
                }
                CloseConnection();
            }
            catch
            {

            }
            return buildingList;
        }