private static LocationDevice AssignFields([NotNull] DataReader dr, [NotNull] string connectionString, bool ignoreMissingFields,
                                                   [NotNull] AllItemCollections aic)
        {
            var locdevID = dr.GetIntFromLong("ID");
            var locID    = dr.GetIntFromLong("LocationID");
            var deviceID = dr.GetIntFromLong("DeviceID");
            var assignableDeviceTypeInt = dr.GetIntFromLong("AssignableDeviceType", false);
            var assignableDeviceType    = (AssignableDeviceType)assignableDeviceTypeInt;
            IAssignableDevice device;

            if (assignableDeviceType == AssignableDeviceType.Device)
            {
                device = aic.RealDevices.FirstOrDefault(mydevice => mydevice.ID == deviceID);
            }
            else
            {
                device = aic.DeviceCategories.FirstOrDefault(mydeviceCat => mydeviceCat.ID == deviceID);
            }
            var name = "(no name)";

            if (device != null)
            {
                name = device.Name;
            }
            var guid   = GetGuid(dr, ignoreMissingFields);
            var locdev = new LocationDevice(locdevID, device, locID, connectionString, name, guid);

            return(locdev);
        }
        public static void LoadFromDatabase([ItemNotNull][NotNull] ObservableCollection <Location> result, [NotNull] string connectionString,
                                            [ItemNotNull][NotNull] ObservableCollection <RealDevice> devices, [ItemNotNull][NotNull] ObservableCollection <DeviceCategory> deviceCategories,
                                            [ItemNotNull][NotNull] ObservableCollection <VLoadType> loadTypes, bool ignoreMissingTables)
        {
            var aic = new AllItemCollections();

            LoadAllFromDatabase(result, connectionString, TableName, AssignFields, aic, ignoreMissingTables, true);
            var ld = new ObservableCollection <LocationDevice>();

            LocationDevice.LoadFromDatabase(ld, connectionString, devices, deviceCategories, loadTypes,
                                            ignoreMissingTables);
            SetSubitems(new List <DBBase>(result), new List <DBBase>(ld), IsCorrectLocationDeviceParent,
                        ignoreMissingTables);
        }
        public void AddDevice([NotNull] IAssignableDevice device, bool save = true)
        {
            if (device.ConnectionString != ConnectionString)
            {
                throw new LPGException("A device from another DB was just added!");
            }
            var locdev = new LocationDevice(null, device, IntID, ConnectionString, device.Name, System.Guid.NewGuid().ToStrGuid());

            _locDevs.Add(locdev);
            if (save)
            {
                locdev.SaveToDB();
            }
            _locDevs.Sort();
        }
 public void DeleteDevice([NotNull] LocationDevice ld)
 {
     ld.DeleteFromDB();
     _locDevs.Remove(ld);
 }