/**********************************************************/

        private void btnNewSchedule_Click(object sender, EventArgs e)
        {
            frmNewScheduleView newSchedule = new frmNewScheduleView();

            DialogResult result = newSchedule.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            OptScheduleModel optScheduleModel = newSchedule.getOptScheduleModel();

            ListViewItem lvi = new ListViewItem(optScheduleModel.Name);

            lvi.SubItems.Add(optScheduleModel.OptID);
            lvi.SubItems.Add("False");
            lstSchedules.Items.Add(lvi);

            m_scheduleLvi.Add(optScheduleModel.OptID, lvi);

            m_schedulesByOptId.Add(optScheduleModel.OptID, optScheduleModel);

            // createOptSchedules(optScheduleModel);
        }
        /********************************************************************************/

        private void lstSchedules_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lstSchedules.SelectedItems.Count == 0)
            {
                return;
            }

            string optID = lstSchedules.SelectedItems[0].SubItems[1].Text;

            OptScheduleModel optScheduleModel = m_schedulesByOptId[optID];

            MethodInvoker mi = new MethodInvoker(delegate
            {
                try
                {
                    ucOptScheduleView1.viewOptScheduleModel(optScheduleModel);
                }
                catch (Exception ex)
                {
                    Logger.logException(ex);
                }
            });

            // BeginInvoke only needs to be called if we're tyring to update the UI from
            // a thread that did not create it
            if (this.InvokeRequired)
            {
                this.BeginInvoke(mi);
            }
            else
            {
                mi.Invoke();
            }
        }
Example #3
0
        /**********************************************************/

        public OptScheduleModel getOptScheduleModel()
        {
            OptScheduleModel optScheduleModel = ucOptScheduleView1.getOptScheduleModel();

            optScheduleModel.Name = tbScheduleName.TextBoxText;

            return(optScheduleModel);
        }
        /**********************************************************/

        private void createOptSchedules(OptScheduleModel optScheduleModel)
        {
            oadrlib.lib.oadr2b.OptSchedule optSchedule;

            if ((optSchedule = optScheduleModel.getOptInSchedule()) != null)
            {
                m_manageOptSchedules.createOptSchedule(optSchedule);
            }

            if ((optSchedule = optScheduleModel.getOptOutSchedule()) != null)
            {
                m_manageOptSchedules.createOptSchedule(optSchedule);
            }
        }
        /********************************************************************************/

        public void viewOptScheduleModel(OptScheduleModel optScheduleModel)
        {
            dtStart.Value = optScheduleModel.StartDate;
            dtEnd.Value   = optScheduleModel.EndDate;

            cmbOptInReason.SelectedItem  = optScheduleModel.OptInReason;
            cmbOptOutReason.SelectedItem = optScheduleModel.OptOutReason;

            foreach (string weekDay in m_weekDays)
            {
                for (int hour = 0; hour < 24; hour++)
                {
                    m_buttons[weekDay][hour].ButtonState = optScheduleModel.getButtonState(weekDay, hour);
                }
            }
        }
        /********************************************************************************/

        public OptScheduleModel getOptScheduleModel()
        {
            OptScheduleModel optScheduleModel = new OptScheduleModel();

            optScheduleModel.StartDate = dtStart.Value;
            optScheduleModel.EndDate   = dtEnd.Value;

            optScheduleModel.OptInReason  = cmbOptInReason.SelectedItem.ToString();
            optScheduleModel.OptOutReason = cmbOptOutReason.SelectedItem.ToString();

            foreach (string weekDay in m_weekDays)
            {
                for (int hour = 0; hour < 24; hour++)
                {
                    optScheduleModel.setButtonState(weekDay, hour, m_buttons[weekDay][hour].ButtonState);
                }
            }

            return(optScheduleModel);
        }
        /********************************************************************************/

        private void sendToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lstSchedules.SelectedItems.Count == 0)
            {
                return;
            }

            DialogResult result = MessageBox.Show("This action will send the opt schedule to the VTN.  Click OK to confirm.", "Resend Opt Schedule?", MessageBoxButtons.OKCancel);

            if (result != DialogResult.OK)
            {
                return;
            }

            string optID = lstSchedules.SelectedItems[0].SubItems[1].Text;

            OptScheduleModel optScheduleModel = m_schedulesByOptId[optID];

            createOptSchedules(optScheduleModel);
        }
        /********************************************************************************/

        private void cancelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lstSchedules.SelectedItems.Count == 0)
            {
                return;
            }

            DialogResult result = MessageBox.Show("This action will cancel the opt schedule on the VTN.  Click OK to confirm.", "Cancel Opt Schedule?", MessageBoxButtons.OKCancel);

            if (result != DialogResult.OK)
            {
                return;
            }

            string optID = lstSchedules.SelectedItems[0].SubItems[1].Text;

            OptScheduleModel optScheduleModel = m_schedulesByOptId[optID];

            // TODO: only send a cancel for the schedule(s) that were created
            m_manageOptSchedules.cancelOptSchedule(optScheduleModel.OptID + "-IN");
            m_manageOptSchedules.cancelOptSchedule(optScheduleModel.OptID + "-OUT");
        }
        /********************************************************************************/

        public void addOptSchedule(CreateOpt createOpt)
        {
            MethodInvoker mi = new MethodInvoker(delegate
            {
                try
                {
                    string optId = createOpt.response.optID.Split('-')[0];

                    if (!m_schedulesByOptId.ContainsKey(optId))
                    {
                        return;
                    }

                    OptScheduleModel optScheduleModel = m_schedulesByOptId[optId];

                    optScheduleModel.OptInRegistered  = true;
                    optScheduleModel.OptOutRegistered = true;

                    m_scheduleLvi[optId].SubItems[2].Text = "True";
                }
                catch (Exception ex)
                {
                    Logger.logException(ex);
                }

                // lstSchedules.Items.Add(createOpt.response.optID);
            });

            // BeginInvoke only needs to be called if we're tyring to update the UI from
            // a thread that did not create it
            if (this.InvokeRequired)
            {
                this.BeginInvoke(mi);
            }
            else
            {
                mi.Invoke();
            }
        }