Esempio n. 1
0
        // Get a regulation of a known ID (from cache)
        public RegulatedHours_ExperimentalDBSchemaV1DTO GetRegulationByID(int regulatedHoursID)
        {
            // Protect this section with our ReadWriterLockAlt that handles concurrency issues for us
            using (_cacheReadWriteLocker.ReadLock())
            {
                RegulatedHours_ExperimentalDBSchemaV1DTO result = _cachedRegulations.Find(item => item.ID_PrimaryKey == regulatedHoursID);

                // Update the cache in background thread. The update routine will return immediately if the cache isn't expired yet
                var task = new Task(() => { UpdateMemAndXmlCacheForCustomerFromDB(result.CID, false); });
                task.Start();

                return(result);
            }
        }
Esempio n. 2
0
        public bool CompareCustomerID(RegulatedHours_ExperimentalDBSchemaV1DTO pObject)
        {
            bool cidIsSame = false;

            // Compare CustomerID (Null and -1 will be treated as the same value)
            if ((this._CID == null) || (this._CID.HasValue == false) || (this._CID.Value == -1))
            {
                cidIsSame = true;
            }
            else
            {
                cidIsSame = (this._CID.Value == pObject.CID);
            }

            return(cidIsSame);
        }
Esempio n. 3
0
        public bool CompareVariableScope(RegulatedHours_ExperimentalDBSchemaV1DTO pObject)
        {
            bool cidIsSame       = false;
            bool bayNumberIsSame = false;
            bool midIsSame       = false;

            // Compare CustomerID (Null and -1 will be treated as the same value)
            if ((this._CID == null) || (this._CID.HasValue == false) || (this._CID.Value == -1))
            {
                cidIsSame = true;
            }
            else
            {
                cidIsSame = (this._CID.Value == pObject.CID);
            }

            // Compare MeterID (Null and -1 will be treated as the same value)
            if ((this._MID == null) || (this._MID.HasValue == false) || (this._MID.Value == -1))
            {
                midIsSame = true;
            }
            else
            {
                midIsSame = (this._MID.Value == pObject.MID);
            }

            // Compare BayNumber (Null and -1 will be treated as the same value)
            if ((this._BayNumber == null) || (this._BayNumber.HasValue == false) || (this._BayNumber.Value == -1))
            {
                bayNumberIsSame = true;
            }
            else
            {
                bayNumberIsSame = (this._BayNumber.Value == pObject.BayNumber);
            }


            return((cidIsSame) && (bayNumberIsSame) && (midIsSame));
        }
        public Object GetData(IDataReader reader)
        {
            // This is where we define the mapping between the object properties and the
            // data columns. The convention that should be used is that the object property
            // names are exactly the same as the column names. However if there is some
            // compelling reason for the names to be different the mapping can be defined here.

            // We assume the reader has data and is already on the row that contains the data
            // we need. We don't need to call read. As a general rule, assume that every field must
            // be null  checked. If a field is null then the nullvalue for that field has already
            // been set by the DTO constructor, we don't have to change it.

            // For reference, here is an example of SQL that gathers data from the db

            /*
             * SELECT rh.ID, rh.ParkingSpaceId, rh.DayOfWeek, rh.RegulatedStartTime, rh.RegulatedEndTime, rh.MaxStayMinute,
             * ps.CustomerId, ps.AreaId, ps.MeterId, ps.BayNumber
             * FROM RegulatedHours as rh, ParkingSpaces ps
             * where rh.ParkingSpaceId = ps.ParkingSpaceId
             * and ps.CustomerId = @CustomerId
             * order by ps.MeterId, ps.BayNumber, rh.DayOfWeek, rh.RegulatedStartTime
             */

            if (!_isInitialized)
            {
                InitializeMapper(reader);
            }

            // Now we can load the data
            RegulatedHours_ExperimentalDBSchemaV1DTO dto = new RegulatedHours_ExperimentalDBSchemaV1DTO();

            if (!reader.IsDBNull(_ordinal_ID))
            {
                dto.ID_PrimaryKey = reader.GetInt32(_ordinal_ID);
            }
            if (!reader.IsDBNull(_ordinal_ParkingSpaceID))
            {
                dto.ParkingSpaceID = reader.GetInt64(_ordinal_ParkingSpaceID);
            }

            if (!reader.IsDBNull(_ordinal_DayOfWeek))
            {
                dto.DayOfWeek = (DayOfWeek)(reader.GetByte(_ordinal_DayOfWeek) - 1);
            }

            if (!reader.IsDBNull(_ordinal_RegulatedStartTime))
            {
                dto.RegulatedStartTime_Minutes = reader.GetInt32(_ordinal_RegulatedStartTime);
            }
            if (!reader.IsDBNull(_ordinal_RegulatedEndTime))
            {
                dto.RegulatedEndTime_Minutes = reader.GetInt32(_ordinal_RegulatedEndTime);
            }
            if (!reader.IsDBNull(_ordinal_MaxStayMinute))
            {
                dto.MaxStayMinute = reader.GetInt32(_ordinal_MaxStayMinute);
            }

            if (!reader.IsDBNull(_ordinal_CustomerID))
            {
                dto.CID = Convert.ToInt32(reader[_ordinal_CustomerID]);
            }                                                                                                      // This isn't optimal, but safer incase its not an Int32 in DB (for example, might be tinyint or smallint)
            if (!reader.IsDBNull(_ordinal_AreaID))
            {
                dto.AID = Convert.ToInt32(reader[_ordinal_AreaID]);
            }
            if (!reader.IsDBNull(_ordinal_MeterID))
            {
                dto.MID = Convert.ToInt32(reader[_ordinal_MeterID]);
            }
            if (!reader.IsDBNull(_ordinal_BayNumber))
            {
                dto.BayNumber = Convert.ToInt32(reader[_ordinal_BayNumber]);
            }
            return(dto);
        }