예제 #1
0
        // Send Calendar settings
        private void SendCalendar(Item item)
        {
            int calStart = item.Location.calStart;
            int calCount = item.Location.calCount;

            for (int i = 0; i < item.Date.Length; i++)
            {
                Date date = item.Date[i];
                if (date.Block <= calCount && int.TryParse(date.SubstitutionRule, out int ruleNumber) && ruleNumber > 0)
                {
                    if (date.Offset != null || date.ZeroSuppress != null || date.Substitute != null || date.TimeCount != null || date.Shifts != null)
                    {
                        Log?.Invoke(p, $" \n// Load settings for Substitution rule {1}\n ");
                        p.SetAttribute(ccIDX.Start_Stop_Management_Flag, 1);
                        p.SetAttribute(ccIDX.Substitution_Rule, ruleNumber); // date.SubstitutionRule
                        p.SetAttribute(ccIDX.Start_Stop_Management_Flag, 2);

                        int index = calStart + date.Block - 2; // Cal start and date.Block are both 1-origin
                        Log?.Invoke(p, $" \n// Set up calendar {index + 1}\n ");
                        p.SetAttribute(ccIDX.Start_Stop_Management_Flag, 1);
                        // Process Offset
                        Offset o = date.Offset;
                        if (o != null)
                        {
                            XMLwriter.WriteStartElement("Offset");
                            if (o.Year != 0)
                            {
                                p.SetAttribute(ccCal.Offset_Year, index, o.Year);
                            }
                            if (o.Month != 0)
                            {
                                p.SetAttribute(ccCal.Offset_Month, index, o.Month);
                            }
                            if (o.Day != 0)
                            {
                                p.SetAttribute(ccCal.Offset_Day, index, o.Day);
                            }
                            if (o.Hour != 0)
                            {
                                p.SetAttribute(ccCal.Offset_Hour, index, o.Hour);
                            }
                            if (o.Minute != 0)
                            {
                                p.SetAttribute(ccCal.Offset_Minute, index, o.Minute);
                            }
                            XMLwriter.WriteEndElement();
                        }

                        // Process Zero Suppress
                        ZeroSuppress zs = date.ZeroSuppress;
                        if (zs != null)
                        {
                            XMLwriter.WriteStartElement("ZeroSuppress");
                            if (zs.Year != ZS.None)
                            {
                                p.SetAttribute(ccCal.Zero_Suppress_Year, index, zs.Year);
                            }
                            if (zs.Month != ZS.None)
                            {
                                p.SetAttribute(ccCal.Zero_Suppress_Month, index, zs.Month);
                            }
                            if (zs.Day != ZS.None)
                            {
                                p.SetAttribute(ccCal.Zero_Suppress_Day, index, zs.Day);
                            }
                            if (zs.Hour != ZS.None)
                            {
                                p.SetAttribute(ccCal.Zero_Suppress_Hour, index, zs.Hour);
                            }
                            if (zs.Minute != ZS.None)
                            {
                                p.SetAttribute(ccCal.Zero_Suppress_Minute, index, zs.Minute);
                            }
                            if (zs.Week != ZS.None)
                            {
                                p.SetAttribute(ccCal.Zero_Suppress_Weeks, index, zs.Week);
                            }
                            if (zs.DayOfWeek != ZS.None)
                            {
                                p.SetAttribute(ccCal.Zero_Suppress_DayOfWeek, index, zs.DayOfWeek);
                            }
                            XMLwriter.WriteEndElement();
                        }

                        // Process Substitutions
                        Substitute s = date.Substitute;
                        if (s != null)
                        {
                            XMLwriter.WriteStartElement("Substitutions");
                            if (s.Year != ED.Disable)
                            {
                                p.SetAttribute(ccCal.Substitute_Year, index, s.Year);
                            }
                            if (s.Month != ED.Disable)
                            {
                                p.SetAttribute(ccCal.Substitute_Month, index, s.Month);
                            }
                            if (s.Day != ED.Disable)
                            {
                                p.SetAttribute(ccCal.Substitute_Day, index, s.Day);
                            }
                            if (s.Hour != ED.Disable)
                            {
                                p.SetAttribute(ccCal.Substitute_Hour, index, s.Hour);
                            }
                            if (s.Minute != ED.Disable)
                            {
                                p.SetAttribute(ccCal.Substitute_Minute, index, s.Minute);
                            }
                            if (s.Week != ED.Disable)
                            {
                                p.SetAttribute(ccCal.Substitute_Weeks, index, s.Week);
                            }
                            if (s.DayOfWeek != ED.Disable)
                            {
                                p.SetAttribute(ccCal.Substitute_DayOfWeek, index, s.DayOfWeek);
                            }
                            XMLwriter.WriteEndElement();
                        }

                        // Process shifts
                        if (date.Shifts != null)
                        {
                            Log?.Invoke(p, $" \n// Set up shifts\n ");
                            XMLwriter.WriteStartElement("Shifts");
                            for (int j = 0; j < date.Shifts.Length; j++)
                            {
                                XMLwriter.WriteStartElement("Shift");
                                XMLwriter.WriteAttributeString("Shift", (j + 1).ToString());
                                p.SetAttribute(ccSR.Shift_Start_Hour, j, date.Shifts[j].StartHour);
                                p.SetAttribute(ccSR.Shift_Start_Minute, j, date.Shifts[j].StartMinute);
                                p.SetAttribute(ccSR.Shift_End_Hour, j, date.Shifts[j].EndHour);
                                p.SetAttribute(ccSR.Shift_End_Minute, j, date.Shifts[j].EndMinute);
                                p.SetAttribute(ccSR.Shift_String_Value, j, date.Shifts[j].ShiftCode);
                                XMLwriter.WriteEndElement();
                            }
                            XMLwriter.WriteEndElement();
                        }

                        // Process TimeCount
                        TimeCount tc = date.TimeCount;
                        if (tc != null)
                        {
                            Log?.Invoke(p, $" \n// Set up Time Count\n ");
                            XMLwriter.WriteStartElement("TimeCount");
                            p.SetAttribute(ccIDX.Start_Stop_Management_Flag, 1);
                            p.SetAttribute(ccSR.Update_Interval_Value, tc.Interval);
                            p.SetAttribute(ccSR.Time_Count_Start_Value, tc.Start);
                            p.SetAttribute(ccSR.Time_Count_End_Value, tc.End);
                            p.SetAttribute(ccSR.Reset_Time_Value, tc.ResetTime);
                            p.SetAttribute(ccSR.Time_Count_Reset_Value, tc.ResetValue);
                            p.SetAttribute(ccIDX.Start_Stop_Management_Flag, 2);
                            XMLwriter.WriteEndElement();
                        }
                        p.SetAttribute(ccIDX.Start_Stop_Management_Flag, 2);
                    }
                }
            }
        }
예제 #2
0
        // Send Calendar settings
        private void SendCalendar(Item item)
        {
            int span;
            int calStart = item.Location.calStart;
            int calCount = item.Location.calCount;

            for (int i = 0; i < item.Date.Length; i++)
            {
                Date date = item.Date[i];
                if (date.Block <= calCount)
                {
                    if (date.Offset != null || date.ZeroSuppress != null || date.Substitute != null)
                    {
                        int index = calStart + date.Block - 2; // Cal start and date.Block are both 1-origin
                        p.LogIt($" \n// Set up calendar block {index + 1}\n ");

                        Section <ccCal> cs = new Section <ccCal>(p, ccCal.Offset_Year, ccCal.Zero_Suppress_DayOfWeek, index, false);
                        {                                                     // No pre-read since all will be filled in
                            cs.SetAttribute(ccCal.Substitute_Rule, index, 1); // Only substitution rule 1?

                            Offset o = date.Offset;
                            if (o != null)
                            {
                                cs.SetAttribute(ccCal.Offset_Year, index, o.Year);
                                cs.SetAttribute(ccCal.Offset_Month, index, o.Month);
                                cs.SetAttribute(ccCal.Offset_Day, index, o.Day);
                                cs.SetAttribute(ccCal.Offset_Hour, index, o.Hour);
                                cs.SetAttribute(ccCal.Offset_Minute, index, o.Minute);
                            }

                            ZeroSuppress zs = date.ZeroSuppress;
                            if (zs != null)
                            {
                                cs.SetAttribute(ccCal.Zero_Suppress_Year, index, zs.Year);
                                cs.SetAttribute(ccCal.Zero_Suppress_Month, index, zs.Month);
                                cs.SetAttribute(ccCal.Zero_Suppress_Day, index, zs.Day);
                                cs.SetAttribute(ccCal.Zero_Suppress_Hour, index, zs.Hour);
                                cs.SetAttribute(ccCal.Zero_Suppress_Minute, index, zs.Minute);
                                cs.SetAttribute(ccCal.Zero_Suppress_Weeks, index, zs.Week);
                                cs.SetAttribute(ccCal.Zero_Suppress_DayOfWeek, index, zs.DayOfWeek);
                            }

                            Substitute s = date.Substitute;
                            if (s != null)
                            {
                                cs.SetAttribute(ccCal.Substitute_Year, index, s.Year);
                                cs.SetAttribute(ccCal.Substitute_Month, index, s.Month);
                                cs.SetAttribute(ccCal.Substitute_Day, index, s.Day);
                                cs.SetAttribute(ccCal.Substitute_Hour, index, s.Hour);
                                cs.SetAttribute(ccCal.Substitute_Minute, index, s.Minute);
                                cs.SetAttribute(ccCal.Substitute_Weeks, index, s.Week);
                                cs.SetAttribute(ccCal.Substitute_DayOfWeek, index, s.DayOfWeek);
                            }
                        }
                        cs.WriteSection();
                    }

                    if (date.Shifts != null)
                    {
                        p.LogIt($" \n// Set up shifts\n ");
                        AttrData attr = p.GetAttrData(ccSR.Shift_Start_Hour);
                        span = attr.Stride * date.Shifts.Length;
                        Section <ccSR> ss = new Section <ccSR>(p, ccSR.Shift_Start_Hour, 0, span, false);
                        {
                            for (int j = 0; j < date.Shifts.Length; j++)
                            {
                                Shift ds = date.Shifts[j];
                                ss.SetAttribute(ccSR.Shift_Start_Hour, j, ds.StartHour);
                                ss.SetAttribute(ccSR.Shift_Start_Minute, j, ds.StartMinute);
                                ss.SetAttribute(ccSR.Shift_End_Hour, j, ds.EndHour);
                                ss.SetAttribute(ccSR.Shift_End_Minute, j, ds.EndMinute);
                                ss.SetAttribute(ccSR.Shift_String_Value, j, ds.ShiftCode);
                            }
                        }
                        ss.WriteSection();
                    }

                    if (date.TimeCount != null)
                    {
                        TimeCount tc = date.TimeCount;
                        p.LogIt($" \n// Set up Time Count\n ");
                        Section <ccSR> tcs = new Section <ccSR>(p, ccSR.Time_Count_Start_Value, ccSR.Update_Interval_Value, 0, false);
                        {
                            tcs.SetAttribute(ccSR.Time_Count_Start_Value, tc.Start);
                            tcs.SetAttribute(ccSR.Time_Count_End_Value, tc.End);
                            tcs.SetAttribute(ccSR.Time_Count_Reset_Value, tc.ResetValue);
                            tcs.SetAttribute(ccSR.Reset_Time_Value, tc.ResetTime);
                            tcs.SetAttribute(ccSR.Update_Interval_Value, tc.Interval);
                            tcs.WriteSection();
                        }
                    }
                }
            }
        }
        private void SendCalendar(Item item)
        {
            int calStart = item.Location.calStart;
            int calCount = item.Location.calCount;

            for (int i = 0; i < item.Date.Length; i++)
            {
                Date date = item.Date[i];
                if (date.Block <= calCount)
                {
                    SetAttribute(ccIDX.Substitution_Rule, date.SubstitutionRule);
                    SetAttribute(ccIDX.Calendar_Block, calStart + date.Block - 1);

                    // Process Offset
                    Offset o = date.Offset;
                    if (o != null)
                    {
                        if (o.Year != 0)
                        {
                            SetAttribute(ccCal.Offset_Year, o.Year);
                        }
                        if (o.Month != 0)
                        {
                            SetAttribute(ccCal.Offset_Month, o.Month);
                        }
                        if (o.Day != 0)
                        {
                            SetAttribute(ccCal.Offset_Day, o.Day);
                        }
                        if (o.Hour != 0)
                        {
                            SetAttribute(ccCal.Offset_Hour, o.Hour);
                        }
                        if (o.Minute != 0)
                        {
                            SetAttribute(ccCal.Offset_Minute, o.Minute);
                        }
                    }

                    // Process Zero Suppress
                    ZeroSuppress zs = date.ZeroSuppress;
                    if (zs != null)
                    {
                        if (zs.Year != ZS.None)
                        {
                            SetAttribute(ccCal.Zero_Suppress_Year, zs.Year);
                        }
                        if (zs.Month != ZS.None)
                        {
                            SetAttribute(ccCal.Zero_Suppress_Month, zs.Month);
                        }
                        if (zs.Day != ZS.None)
                        {
                            SetAttribute(ccCal.Zero_Suppress_Day, zs.Day);
                        }
                        if (zs.Hour != ZS.None)
                        {
                            SetAttribute(ccCal.Zero_Suppress_Hour, zs.Hour);
                        }
                        if (zs.Minute != ZS.None)
                        {
                            SetAttribute(ccCal.Zero_Suppress_Minute, zs.Minute);
                        }
                        if (zs.Week != ZS.None)
                        {
                            SetAttribute(ccCal.Zero_Suppress_Weeks, zs.Week);
                        }
                        if (zs.DayOfWeek != ZS.None)
                        {
                            SetAttribute(ccCal.Zero_Suppress_DayOfWeek, zs.DayOfWeek);
                        }
                    }

                    // Process Substitutions
                    Substitute s = date.Substitute;
                    if (s != null)
                    {
                        if (s.Year != ED.Disable)
                        {
                            SetAttribute(ccCal.Substitute_Year, s.Year);
                        }
                        if (s.Month != ED.Disable)
                        {
                            SetAttribute(ccCal.Substitute_Month, s.Month);
                        }
                        if (s.Day != ED.Disable)
                        {
                            SetAttribute(ccCal.Substitute_Day, s.Day);
                        }
                        if (s.Hour != ED.Disable)
                        {
                            SetAttribute(ccCal.Substitute_Hour, s.Hour);
                        }
                        if (s.Minute != ED.Disable)
                        {
                            SetAttribute(ccCal.Substitute_Minute, s.Minute);
                        }
                        if (s.Week != ED.Disable)
                        {
                            SetAttribute(ccCal.Substitute_Weeks, s.Week);
                        }
                        if (s.DayOfWeek != ED.Disable)
                        {
                            SetAttribute(ccCal.Substitute_DayOfWeek, s.DayOfWeek);
                        }
                    }
                    // Process Shifts
                    if (date.Shifts != null)
                    {
                        for (int j = 0; j < date.Shifts.Length; j++)
                        {
                            SetAttribute(ccIDX.Calendar_Block, j + 1);
                            SetAttribute(ccCal.Shift_Start_Hour, date.Shifts[j].StartHour);
                            SetAttribute(ccCal.Shift_Start_Minute, date.Shifts[j].StartMinute);
                            SetAttribute(ccCal.Shift_String_Value, date.Shifts[j].ShiftCode);
                        }
                    }
                    if (date.TimeCount != null)
                    {
                        TimeCount tc = date.TimeCount;
                        if (tc != null)
                        {
                            SetAttribute(ccCal.Update_Interval_Value, tc.Interval);
                            SetAttribute(ccCal.Time_Count_Start_Value, tc.Start);
                            SetAttribute(ccCal.Time_Count_End_Value, tc.End);
                            SetAttribute(ccCal.Reset_Time_Value, tc.ResetTime);
                            SetAttribute(ccCal.Time_Count_Reset_Value, tc.ResetValue);
                        }
                    }
                }
            }
        }