/// <summary>
        /// Returns the configuration value for the schedule's day to daytipe
        /// assignments.
        /// </summary>
        /// <param name="TOUSchedule">A TOU server instance with a TOU schedule
        /// open</param>
        /// <returns>A TOU server's typical week packed into a 2 byte value to
        /// be used in the Sentinel or Image configuration</returns>
        ///
        //  Revision History
        //  MM/DD/YY who Version Issue# Description
        //  -------- --- ------- ------ ---------------------------------------
        //  06/22/06 mcm 7.30.00 N/A	Created
        private ushort GetTypicalWeek(CTOUSchedule TOUSchedule)
        {
            ushort usTypicalWeek = 0;
            ushort usDTIndex;


            // Day to Day Type Assignments:
            // 2 bits for each day (Sun – Sat & Holiday)
            usTypicalWeek = GetDaytypeIndex(TOUSchedule, eTypicalDay.SUNDAY);
            usDTIndex     = GetDaytypeIndex(TOUSchedule, eTypicalDay.MONDAY);
            usTypicalWeek = (ushort)(usTypicalWeek + usDTIndex * 0x0004);
            usDTIndex     = GetDaytypeIndex(TOUSchedule, eTypicalDay.TUESDAY);
            usTypicalWeek = (ushort)(usTypicalWeek + usDTIndex * 0x0010);
            usDTIndex     = GetDaytypeIndex(TOUSchedule, eTypicalDay.WEDNESDAY);
            usTypicalWeek = (ushort)(usTypicalWeek + usDTIndex * 0x0040);
            usDTIndex     = GetDaytypeIndex(TOUSchedule, eTypicalDay.THURSDAY);
            usTypicalWeek = (ushort)(usTypicalWeek + usDTIndex * 0x0100);
            usDTIndex     = GetDaytypeIndex(TOUSchedule, eTypicalDay.FRIDAY);
            usTypicalWeek = (ushort)(usTypicalWeek + usDTIndex * 0x0400);
            usDTIndex     = GetDaytypeIndex(TOUSchedule, eTypicalDay.SATURDAY);
            usTypicalWeek = (ushort)(usTypicalWeek + usDTIndex * 0x1000);

            // Holiday type always gets the holiday index
            usTypicalWeek = (ushort)(usTypicalWeek +
                                     TOUConfig.HOLIDAY_TYPE_INDEX * 0x4000);

            return(usTypicalWeek);
        } // GetTypicalWeek
示例#2
0
        }        // CDayType

        /// <summary>
        /// This method looks to see if this day type is being used within
        /// the typical week of the given TOU schedule.
        /// </summary>
        /// <param name="sched">
        /// Represents the TOU Schedule to search within.
        /// </param>
        /// <returns>
        /// Returns true if this day type is used in the typical week and
        /// false otherwise.
        /// </returns>
        /// Revision History
        /// MM/DD/YY who Version Issue# Description
        /// -------- --- ------- ------ ---------------------------------------
        /// 06/28/06 ach N/A	 N/A	Moved method from Day Types Form.cs
        public Boolean UsedByTypicalWeek(CTOUSchedule sched)
        {
            // Local Variables
            String[]      week = sched.TypicalWeek;
            List <string> days;
            Boolean       result = false;

            // Find out which array to look in for a match
            if (eDayType.HOLIDAY == Type)
            {
                days = sched.Holidays;
            }
            else
            {
                days = sched.NormalDays;
            }

            // Search the typical week to see if this day is used
            for (int intCount = 0; intCount < week.Length; intCount++)
            {
                if (week[intCount] == days[Index])
                {
                    result = true;
                }
            }

            return(result);
        }// UsedByTypicalWeek
示例#3
0
        }// UsedByTypicalWeek

        /// <summary>
        /// This method looks to see if this day type is being used in a
        /// holiday within the given TOU Schedule
        /// </summary>
        /// <param name="sched">
        /// Represents the TOU Schedule to search within.
        /// </param>
        /// <returns>
        /// Returns true if this day type is used in a holiday and
        /// false otherwise.
        /// </returns>
        /// Revision History
        /// MM/DD/YY who Version Issue# Description
        /// -------- --- ------- ------ ---------------------------------------
        /// 06/28/06 ach N/A	 N/A	Moved method from Day Types Form.cs
        public Boolean UsedByHoliday(CTOUSchedule sched)
        {
            // Local Variables
            CYearCollection  years = sched.Years;
            CEventCollection events;
            String           name   = sched.Holidays[Index];
            Boolean          result = false;

            // If this day type is not a holiday then stop
            // and return false
            if (eDayType.NORMAL == Type)
            {
                return(false);
            }

            // Search through all the years within the schedule
            foreach (CYear year in years)
            {
                events = year.Events;

                // Search each event in the year
                foreach (CEvent yearEvent in events)
                {
                    if (eEventType.HOLIDAY == yearEvent.Type &&
                        name == yearEvent.Name)
                    {
                        result = true;
                    }
                }
            }

            return(result);
        }// UsedByHoliday
        /// <summary>
        /// Returns a TOU schedule based on the tou schedule name provided.
        /// </summary>
        /// <param name="iTOUID">
        /// The ID of the TOU schedule to find.
        /// </param>
        /// <returns>
        /// Returns a CTOUSchedule if the schedule exists or it returns null.
        /// </returns>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ ---------------------------------------------
        //  07/17/07 mrj 9.00.00		Created
        //
        public CTOUSchedule FindSchedule(int iTOUID)
        {
            CTOUSchedule     TOUSchedule = null;
            CTOUScheduleFile TOUFile     = Find(iTOUID);

            if (TOUFile != null)
            {
                try
                {
                    TOUSchedule = new CTOUSchedule(TOUFile.FilePath);
                }
                catch
                {
                    TOUSchedule = null;
                }
            }

            return(TOUSchedule);
        }
        /// <summary>
        /// Returns a TOU schedule based on the tou schedule name provided.
        /// </summary>
        /// <param name="strTOUName">
        /// The name of the TOU schedule to find.
        /// </param>
        /// <returns>
        /// Returns a CTOUSchedule if the schedule exists or it returns null.
        /// </returns>
        //  Revision History
        //  MM/DD/YY Who Version Issue# Description
        //  -------- --- ------- ------ ---------------------------------------------
        //  07/17/07 mrj 9.00.00		Created
        //
        public CTOUSchedule FindSchedule(string strTOUName)
        {
            CTOUSchedule     TOUSchedule = null;
            CTOUScheduleFile TOUFile     = Find(strTOUName);

            if (TOUFile != null)
            {
                try
                {
                    TOUSchedule = new CTOUSchedule(TOUFile.FilePath);
                }
                catch
                {
                    TOUSchedule = null;
                }
            }

            return(TOUSchedule);
        }
        } // GetTypicalWeek

        /// <summary>
        /// Returns the schedule's Daytype Type and index into a index (1..4).
        /// Normal Daytype 1 = 1, Normal Daytype 3 = 3, Holiday type 1 = 4.
        /// </summary>
        /// <param name="TOUSchedule">A TOU server instance with a TOU schedule
        /// open</param>
        /// <param name="Day">Day of the week to translate</param>
        /// <returns>Daytype index used by GetTypicalWeek</returns>
        ///
        //  Revision History
        //  MM/DD/YY who Version Issue# Description
        //  -------- --- ------- ------ ---------------------------------------
        //  06/22/06 mcm 7.30.00 N/A	Created
        private ushort GetDaytypeIndex(CTOUSchedule TOUSchedule,
                                       eTypicalDay Day)
        {
            CDayType DayType;
            ushort   DaytypeIndex = 0;


            // The Image and Sentinel meters store the day of the week to
            // daytype associations for the season as a ushort
            DayType = TOUSchedule.GetDayType(TOUSchedule.TypicalWeek[(int)Day]);
            if (eDayType.NORMAL == DayType.Type)
            {
                DaytypeIndex = (ushort)DayType.Index;
            }
            else
            {
                DaytypeIndex = TOUConfig.HOLIDAY_TYPE_INDEX;
            }

            return(DaytypeIndex);
        } // GetDaytypeIndex
        // Note: The following source codes are for TOU and DST reconfiguration.
        // Note: Due to circular dependency issue, those codes are here temporarily, later we need to do reflection.

        /// <summary>
        /// This method imports the TOU configuration into the file.
        /// </summary>
        /// <param name="strTOUFileName">The TOU schedule file name.</param>
        // Revision History
        // MM/DD/YY who Version Issue# Description
        // -------- --- ------- ------ ---------------------------------------
        // 11/16/10 jrf 2.45.13        Created
        // 12/01/10 deo 9.70.12        fix for CQ165091
        private void ImportTOU(string strTOUFileName)
        {
            CTOUSchedule TOUSchedule = new CTOUSchedule(strTOUFileName);

            int[] aiIndex1 = { 0 };
            int[] aiIndex2 = { 0, 0 };
            int[] aiIndex3 = { 0, 0, 0 };

            //TODO: Update CentronTblEnum values based on updates Steve makes...
            //Calendar ID
            m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_CALENDAR_ID, null, TOUSchedule.TOUID);

            //DemandReset/Season Change Options
            int SeasonChgOption = 1; //  Demand reset at the season change.

            m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_DEMAND_RESET, null, (byte)SeasonChgOption);

            //DST Hour
            m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_DST_HOUR, null, 0);
            //DST Minute
            m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_DST_MINUTE, null, 0);
            //DST Offset
            m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_DST_OFFSET, null, 0);

            //Calendar Years
            for (int iYear = 0; iYear < TOUSchedule.Years.Count; iYear++)
            {
                CYear Year = TOUSchedule.Years[iYear];
                aiIndex1[0] = iYear;
                aiIndex2[0] = iYear;

                //Year
                m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_CALENDAR_YEAR, aiIndex1, Year.Year - 2000);

                //Day Events
                for (int iEvent = 0; iEvent < TOUSchedule.Years[iYear].Events.Count; iEvent++)
                {
                    CEvent Event = Year.Events[iEvent];
                    aiIndex2[1] = iEvent;
                    byte bytCalEvent = 0;

                    // Translate TOU schedule event to CalendarConfig event
                    // fix for CQ 165091

                    if (Itron.Metering.TOU.eEventType.HOLIDAY == Event.Type)
                    {
                        bytCalEvent = (byte)CalendarEvent.CalendarEventType.HOLIDAY + 1;
                    }
                    else if (Itron.Metering.TOU.eEventType.SEASON == Event.Type)
                    {
                        bytCalEvent = (byte)((int)CalendarEvent.CalendarEventType.SEASON1 + Event.Index + 1);
                    }
                    else
                    {
                        bytCalEvent = 0;
                    }
                    //Event
                    m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_CALENDAR_EVENT, aiIndex2, bytCalEvent);
                    //Month
                    m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_CALENDAR_MONTH, aiIndex2, Event.Date.Month - 1);
                    //Day Of Month
                    m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_CALENDAR_DAY_OF_MONTH, aiIndex2, Event.Date.Day - 1);
                }
            }

            //This value is the same for all seasons
            ushort usDayToDayType = GetTypicalWeek(TOUSchedule);

            //Seasons
            for (int iSeason = 0; iSeason < TOUSchedule.Seasons.Count; iSeason++)
            {
                CSeason Season                    = TOUSchedule.Seasons[iSeason];
                int     iTODEvent                 = 0;
                int     iPatternIndex             = 0;
                bool    blnEventsNeedSorting      = false;
                TOUConfig.TOU_Season ConfigSeason = new TOUConfig.TOU_Season(24, 4);

                aiIndex1[SEASON_INDEX] = iSeason;
                aiIndex3[SEASON_INDEX] = iSeason;

                //Programmed
                m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_PROGRAMMED, aiIndex1, 1);

                //Day to Day Types
                m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_DAY_TO_DAY_TYPE, aiIndex1, usDayToDayType);

                // Configure the normal daytypes (0..2)
                for (int DaytypeIndex = 0;
                     DaytypeIndex < Season.NormalDays.Count;
                     DaytypeIndex++)
                {
                    // Get the index of the pattern in the schedule's
                    // pattern collection that's assigned to this
                    // daytype, so we can add its switchpoints
                    iPatternIndex = TOUSchedule.Patterns.SearchID(
                        Season.NormalDays[DaytypeIndex]);

                    iTODEvent = 0;
                    for (int EventIndex = 0;
                         EventIndex < TOUSchedule.Patterns[iPatternIndex].SwitchPoints.Count;
                         EventIndex++)
                    {
                        // Outputs switchpoints are a special case. A start and end
                        // event must be added for outputs.
                        CSwitchPoint SP = TOUSchedule.Patterns[iPatternIndex].SwitchPoints[EventIndex];

                        ConfigSeason.TimeOfDayEvents[DaytypeIndex, iTODEvent++] = GetDayEvent(SP);

                        // Unlike rate switchpoints, outputs can overlap, so we
                        // have to add the end point too.
                        if (eSwitchPointType.OUTPUT == SP.SwitchPointType)
                        {
                            ConfigSeason.TimeOfDayEvents[DaytypeIndex, iTODEvent++] = GetOutputOffEvent(SP);

                            // We'll need to sort the events since we added one
                            blnEventsNeedSorting = true;
                        }
                    } // For each switchpoint
                }

                // Configure the Holiday daytype if it exists
                if (0 != Season.Holidays.Count)
                {
                    // Get the index of the pattern in the schedule's
                    // pattern collection that's assigned to this
                    // (holiday) daytype, so we can add its switchpoints
                    iPatternIndex = TOUSchedule.Patterns.SearchID(Season.Holidays[0]);

                    iTODEvent = 0;
                    for (int EventIndex = 0;
                         EventIndex < TOUSchedule.Patterns[iPatternIndex].SwitchPoints.Count;
                         EventIndex++)
                    {
                        // Outputs switchpoints are a special case. A start and end
                        // event must be added for outputs.
                        CSwitchPoint SP = TOUSchedule.Patterns[iPatternIndex].SwitchPoints[EventIndex];

                        ConfigSeason.TimeOfDayEvents[TOUConfig.HOLIDAY_TYPE_INDEX, iTODEvent++] = GetDayEvent(SP);

                        // Unlike rate switchpoints, outputs can overlap, so we
                        // have to add the end point too.
                        if (eSwitchPointType.OUTPUT == SP.SwitchPointType)
                        {
                            ConfigSeason.TimeOfDayEvents[TOUConfig.HOLIDAY_TYPE_INDEX, iTODEvent++] = GetOutputOffEvent(SP);

                            // We'll need to sort the events since we added one
                            blnEventsNeedSorting = true;
                        }
                    } // For each switchpoint
                }

                // Sort the events if we added any
                if (blnEventsNeedSorting)
                {
                    ConfigSeason.Sort();
                }

                for (int DaytypeIndex = 0; DaytypeIndex < ConfigSeason.TimeOfDayEvents.GetLength(0); DaytypeIndex++)
                {
                    for (int EventIndex = 0; EventIndex < ConfigSeason.TimeOfDayEvents.GetLength(1);
                         EventIndex++)
                    {
                        TOUConfig.DayEvent DayEvt = ConfigSeason.TimeOfDayEvents[DaytypeIndex, EventIndex];

                        aiIndex3[DAY_TYPE_INDEX]       = DaytypeIndex;
                        aiIndex3[DAY_TYPE_EVENT_INDEX] = EventIndex;

                        m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_TOU_DAY_TYPE_RATE_EVENT, aiIndex3, DayEvt.EventType);
                        m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_TOU_DAY_TYPE_HOUR, aiIndex3, DayEvt.Hour);
                        m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_TOU_DAY_TYPE_MINUTE, aiIndex3, DayEvt.Minute);
                    }
                }

                if (0 != Season.Holidays.Count)
                {
                    for (int EventIndex = 0; EventIndex < ConfigSeason.TimeOfDayEvents.GetLength(1);
                         EventIndex++)
                    {
                        TOUConfig.DayEvent DayEvt = ConfigSeason.TimeOfDayEvents[TOUConfig.HOLIDAY_TYPE_INDEX, EventIndex];

                        aiIndex3[DAY_TYPE_INDEX]       = TOUConfig.HOLIDAY_TYPE_INDEX;
                        aiIndex3[DAY_TYPE_EVENT_INDEX] = EventIndex;

                        m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_TOU_DAY_TYPE_RATE_EVENT, aiIndex3, DayEvt.EventType);
                        m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_TOU_DAY_TYPE_HOUR, aiIndex3, DayEvt.Hour);
                        m_TOUTables.SetValue(CentronTblEnum.MFGTBL42_TOU_DAY_TYPE_MINUTE, aiIndex3, DayEvt.Minute);
                    }
                }
            }
        }