/// <summary>
 /// Remove selected active day or actions.
 /// </summary>
 private void DayProfilePassiveRemoveBtn_Click(object sender, EventArgs e)
 {
     try
     {
         if (PassiveActionList.SelectedItems.Count == 0)
         {
             GXDLMSActivityCalendar target = Target as GXDLMSActivityCalendar;
             while (PassiveDaysList.SelectedItems.Count == 1)
             {
                 RemoveDayId(target, 9, PassiveDaysList);
             }
         }
         else
         {
             GXDLMSDayProfile target = PassiveDaysList.SelectedItems[0].Tag as GXDLMSDayProfile;
             if (PassiveActionList.SelectedItems.Count != 0)
             {
                 RemoveDayAction(target, 9, PassiveActionList);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(Parent, ex.Message, "Error",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void AddDayAction(GXDLMSActivityCalendar c, GXDLMSDayProfile target, int index, ListView li)
        {
            GXDLMSDayProfileAction          item = new GXDLMSDayProfileAction();
            GXDLMSActivityCalendarActionDlg dlg  = new GXDLMSActivityCalendarActionDlg(item, Target.Parent.GetObjects(ObjectType.ScriptTable));

            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                List <GXDLMSDayProfileAction> items = new List <GXDLMSDayProfileAction>();
                if (target.DaySchedules != null)
                {
                    items.AddRange(target.DaySchedules);
                }
                items.Add(item);
                target.DaySchedules = items.ToArray();
                if (index == 5)
                {
                    ActiveDaysList_SelectedIndexChanged(null, null);
                }
                else
                {
                    PassiveDaysList_SelectedIndexChanged(null, null);
                }
                errorProvider1.SetError(li, Properties.Resources.ValueChangedTxt);
                c.UpdateDirty(index, target.DaySchedules);
            }
        }
        private void EditDayId(GXDLMSActivityCalendar target, GXDLMSDayProfile[] list, int index, ListViewItem li, ListView lv)
        {
            GXDLMSDayProfile item = (GXDLMSDayProfile)li.Tag;
            GXDLMSActivityCalendarDayProfileDlg dlg = new GXDLMSActivityCalendarDayProfileDlg(item);

            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                UpdateDayProfile(item, li, index);
                errorProvider1.SetError(lv, Properties.Resources.ValueChangedTxt);
                Target.UpdateDirty(index, list);
            }
        }
 /// <summary>
 /// Add new active action.
 /// </summary>
 private void ActiveActionAddBtn_Click(object sender, EventArgs e)
 {
     try
     {
         if (ActiveDaysList.SelectedItems.Count == 1)
         {
             GXDLMSDayProfile       it     = (GXDLMSDayProfile)ActiveDaysList.SelectedItems[0].Tag;
             GXDLMSActivityCalendar target = Target as GXDLMSActivityCalendar;
             AddDayAction(target, it, 5, ActiveDaysList);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(Parent, ex.Message, "Error",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void RemoveDayAction(GXDLMSDayProfile target, int index, ListView lv)
        {
            List <GXDLMSDayProfileAction> entries = new List <GXDLMSDayProfileAction>();

            entries.AddRange(target.DaySchedules);

            while (lv.SelectedItems.Count != 0)
            {
                ListViewItem           li   = lv.SelectedItems[0];
                GXDLMSDayProfileAction item = (GXDLMSDayProfileAction)li.Tag;
                li.Remove();
                errorProvider1.SetError(lv, Properties.Resources.ValueChangedTxt);
                Target.UpdateDirty(index, target.DaySchedules);
                entries.Remove(item);
            }
            target.DaySchedules = entries.ToArray();
        }
        private void RemoveDayId(GXDLMSActivityCalendar target, int index, ListView lv)
        {
            List <GXDLMSDayProfile> entries = new List <GXDLMSDayProfile>();

            if (index == 5)
            {
                if (target.DayProfileTableActive != null)
                {
                    entries.AddRange(target.DayProfileTableActive);
                }
            }
            else
            {
                if (target.DayProfileTablePassive != null)
                {
                    entries.AddRange(target.DayProfileTablePassive);
                }
            }

            while (lv.SelectedItems.Count != 0)
            {
                ListViewItem     li   = lv.SelectedItems[0];
                GXDLMSDayProfile item = (GXDLMSDayProfile)li.Tag;
                li.Remove();
                errorProvider1.SetError(lv, Properties.Resources.ValueChangedTxt);
                if (index == 5)
                {
                    Target.UpdateDirty(index, target.DayProfileTableActive);
                }
                else
                {
                    Target.UpdateDirty(index, target.DayProfileTablePassive);
                }
                entries.Remove(item);
            }
            if (index == 5)
            {
                target.DayProfileTableActive = entries.ToArray();
            }
            else
            {
                target.DayProfileTablePassive = entries.ToArray();
            }
        }
 private void PassiveDaysList_SelectedIndexChanged(object sender, EventArgs e)
 {
     PassiveActionList.Items.Clear();
     if (PassiveDaysList.SelectedItems.Count == 1)
     {
         GXDLMSDayProfile it = (GXDLMSDayProfile)PassiveDaysList.SelectedItems[0].Tag;
         if (it.DaySchedules != null)
         {
             ListViewItem li;
             foreach (GXDLMSDayProfileAction day in it.DaySchedules)
             {
                 li = PassiveActionList.Items.Add(day.StartTime.ToFormatString());
                 li.SubItems.Add(day.ScriptLogicalName);
                 li.SubItems.Add(day.ScriptSelector.ToString());
                 li.Tag = day;
             }
         }
     }
 }
        private void UpdateDayProfile(GXDLMSDayProfile it, ListViewItem li, int index)
        {
            ListView list;

            if (index == 5)
            {
                list = ActiveDaysList;
            }
            else
            {
                list = PassiveDaysList;
            }

            if (li == null)
            {
                li     = list.Items.Add(it.DayId.ToString());
                li.Tag = it;
            }
            else
            {
                li.SubItems[0].Text = it.DayId.ToString();
            }
        }
        private void AddDayId(GXDLMSActivityCalendar target, int index, ListView li)
        {
            GXDLMSDayProfile item = new GXDLMSDayProfile();

            GXDLMSDayProfile[] list;
            if (index == 5)
            {
                list = target.DayProfileTableActive;
            }
            else
            {
                list = target.DayProfileTablePassive;
            }
            GXDLMSActivityCalendarDayProfileDlg dlg = new GXDLMSActivityCalendarDayProfileDlg(item);

            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                List <GXDLMSDayProfile> items = new List <GXDLMSDayProfile>();
                if (list != null)
                {
                    items.AddRange(list);
                }
                items.Add(item);
                if (index == 5)
                {
                    target.DayProfileTableActive = items.ToArray();
                }
                else
                {
                    target.DayProfileTablePassive = items.ToArray();
                }
                UpdateDayProfile(item, null, index);
                errorProvider1.SetError(li, Properties.Resources.ValueChangedTxt);
                target.UpdateDirty(index, list);
            }
        }
 public GXDLMSActivityCalendarDayProfileDlg(GXDLMSDayProfile target)
 {
     InitializeComponent();
     Target    = target;
     IdTb.Text = Target.DayId.ToString();
 }