Ejemplo n.º 1
0
        /// <summary>
        /// Explicity Loads the info about that day (and optionally its DAY_DEF info if created) from the Database.
        /// That method is automatically called when needed, but it can be called explicity too.
        /// </summary>
        public void Load()
        {
            if (_id != -1)
            {
                return;                                                 // Call UnLoad explicity first
            }
            // Load data from days
            CmpDaysDB cmpdays = new CmpDaysDB();
            DataTable days    = cmpdays.GetData(null, "[email protected]_DATE@", new object[] { _day });

            if (days.Rows.Count > 0)
            {
                if (days.Rows.Count > 1)
                {
                    // TODO: Log the incoherence.
                }
                _id   = Convert.ToInt32(days.Rows[0]["DAY_ID"]);
                _desc = Convert.ToString(days.Rows[0]["DAY_DESC"]);
            }

            // Load data from daysdef
            if (_daysdef != null)
            {
                _daysdef.Load();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Obtains the tariff associated to the ID and day (or day_type) specified.
        /// </summary>
        /// <param name="cmpDaysDef">CmpDaysDef with the info about days_def assigned to the current Date.</param>
        /// <returns>ArrayList of Tarifs objects</returns>
        public ArrayList ObtainTariff(CmpDay cmpday)
        {
            ArrayList  tariffs    = new ArrayList();
            CmpDaysDef cmpdaysdef = cmpday.DaysDef;

            // Filter the TARIFF table by TAR_ID. As a result we will found a set of registers
            //	Foreach row that the TAR_DAY_ID is NOT NULL check if TAR_DAY_ID is a DAY_ID of the pInDate day.
            //  If it is we have found a tariff.
            //  If none of the registers have TAR_DAY_ID not NULL or we have not found the tariff yet, we get all
            //  registers with a TAR_DDAY_ID NOT NULL, and find the 1st that his DDAY_ID has the current day.

            CmpTariffsDB cmp       = new CmpTariffsDB();
            string       swhere    = "TAR_ID = @TARIFFS.TAR_ID@ AND (TAR_INIDATE <[email protected]_INIDATE@ OR TAR_INIDATE IS NULL) AND (TAR_ENDDATE>= @TARIFFS.TAR_ENDDATE@ OR TAR_ENDDATE IS NULL)";
            DataTable    dtTariffs = cmp.GetData(null, swhere, new object[] { _tarId, _pInDate, _pInDate });

            // Step 1: Check all TAR_DAY_ID not null
            DataRow [] tarDayId = dtTariffs.Select("TAR_DAY_ID IS NOT NULL");
            if (tarDayId.Length > 0)
            {
                // Get all DAY_ID that correspond to _pInDate (can be more than one).
                if (cmpday.Count > 0)
                {
                    // Finally checks every DAY_ID of the TARIFFS found to IDs stored in daysid array
                    foreach (DataRow drTariff in tarDayId)
                    {
                        int dayid = Convert.ToInt32(drTariff["TAR_DAY_ID"]);
                        // Check if the DAY with day_id is the same day of _pInDate. If it is we have found the tariff (a part
                        // of the tarif, because remember that we can have more than one register).
                        if (dayid == cmpday.Id)
                        {
                            // We have found it!!! We have found it!!
                            tariffs.Add(new Tariff(drTariff));
                        }
                    }
                }
            }

            // Search now by day_def and acumulate the results.
            DataRow[] tarDdayId = dtTariffs.Select("TAR_DDAY_ID IS NOT NULL");
            if (tarDdayId.Length > 0)
            {
                // Get al DDAY_ID that contains the _pInDate (that is, have a 1 in the mask for the _pInDate day) and store
                // them all (CmpDaysDef will store them for us ;))
                if (!cmpdaysdef.IsLoaded)
                {
                    cmpdaysdef.Load();
                }
                if (cmpdaysdef.Count > 0)
                {
                    // If we have found at least one DDAY_ID that contains the pInDate process the tariffs...
                    foreach (DataRow drTariff in tarDdayId)
                    {
                        int ddayid = Convert.ToInt32(drTariff["TAR_DDAY_ID"]);
                        // Check if DDAY_ID is a day_def including the day _pInDate. If it is we have found de tariff
                        if (cmpdaysdef.ContainsId(ddayid))
                        {
                            // We have found it!!! We have found it!!
                            tariffs.Add(new Tariff(drTariff));
                        }
                    }
                }
            }
            return(tariffs);                                     // If no tariff was found will have Count == 0
        }