Beispiel #1
0
        /// <summary>
        /// <para>Initialize the project specific features of the PTU application:</para>
        /// <para>(1) check whether a WibuBox is required for the project and, if so, initialize it;</para>
        /// <para>(2) check whether the project uses a control panel and, if so, initialize it.</para>
        /// </summary>
        /// <param name="projectIdentifier">The project identifier string that was passed as a shortcut parameter.</param>
        private void InitializePTUProjectSpecific(string projectIdentifier)
        {
            #region - [WibuBox] -
            // Check whether the project requires a WibuBox security device.
            if (m_MenuInterfaceApplication.WibuBoxCheckIfRequired(projectIdentifier) == true)
            {
                // Yes, set up the WibuBox as follows: (a) set the WibuBox status label 'Visible' property to be true; (b) instantiate the WibuBox menu interface;
                // (c) initialize the WibuBox Timer control; and (d) check whether a valid WibuBox is connected to the USB port.
                try
                {
                    // Set the WibuBox status label 'Visible' property to be true.
                    m_StatusLabelWibuBoxStatus.Visible = true;

                    // Initialize the WibuBox timer. The event handler associated with this timer checks that a valid WibuBox
                    // security device is attached to the system. If it detects that the device has been removed it will set
                    // the current security level to the lowest security access level.
                    m_TimerWibuBox = new Timer();
                    m_TimerWibuBox.Tick += new EventHandler(WibuBoxCheck);
                    m_TimerWibuBox.Interval = IntervalMsWibuBoxUpdate;
                    m_TimerWibuBox.Enabled = true;
                    m_TimerWibuBox.Stop();

                    // Check whether a valid WibuBox is connected to the USB port and update the status label.
                    m_MenuInterfaceWibuKey = new MenuInterfaceWibuKey(this);
                    WibuBoxPresent = m_MenuInterfaceWibuKey.WibuBoxCheckForValidEntry(true);
                }
                catch (Exception)
                {
                    MessageBox.Show(Resources.MBTWibuKeyDeviceDriverNotInstalled + CommonConstants.NewPara + Resources.MBTWibuKeyInstall, Resources.MBCaptionError,
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            #endregion - [WibuBox] -

            #region - [Project Specific Control Panel] -
            // The NYCT project uses a Control Panel to activate the various menu options.
            switch (projectIdentifier)
            {
                case CommonConstants.ProjectIdNYCT:
                    this.SuspendLayout();
                    m_ControlPanel = new ControlPanel();
                    m_ControlPanel.Dock = DockStyle.Left;
                    m_ControlPanel.Parent = this;
                    m_ControlPanel.TabStop = false;
                    m_ControlPanel.TabIndex = 0;
                    m_ControlPanel.Name = CommonConstants.KeyControlPanel;
                    m_ControlPanel.InitializeControlPanel(this as IMainWindow);
                    this.Controls.RemoveByKey(CommonConstants.KeyPanelStatus);
                    this.Controls.RemoveByKey(CommonConstants.KeyMenuStrip);
                    this.Controls.RemoveByKey(CommonConstants.KeyToolStripFunctionKeys);
                    this.Controls.Add(this.m_ControlPanel);
                    this.Controls.Add(this.m_ToolStripFunctionKeys);
                    this.Controls.Add(this.m_MenuStrip);
                    this.Controls.Add(this.m_PanelStatus);
                    this.ResumeLayout(false);
                    this.PerformLayout();
                    break;
                default:
                    break;
            }
            #endregion - [Project Specific Control Panel] -
        }
Beispiel #2
0
        /// <summary>
        /// Clean up the resources used by the form.
        /// </summary>
        /// <param name="disposing">True to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Cleanup(bool disposing)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                // Provided that the form isn't minimized, update the WindowState setting.
                if (this.WindowState != FormWindowState.Minimized)
                {
                    Settings.Default.WindowState = this.WindowState;
                    Settings.Default.Save();
                }

                // If the WindowState property is normal, update the: Location and Size settings.
                if (this.WindowState == FormWindowState.Normal)
                {
                    Settings.Default.FormLocation = this.Location;
                    Settings.Default.FormSize = this.Size;
                    Settings.Default.Save();
                }

                CloseChildForms();
                DebugMode.Close();
                WinHlp32.Close(this.Handle.ToInt32());

                // Ensure that the communication port is closed.
                if (m_CommunicationInterface != null)
                {
                    CommunicationInterface.CloseCommunication(CommunicationInterface.CommunicationSetting.Protocol);
                }

                if (disposing)
                {
                    // Method called by consumer code. Call the Dispose method of any managed data members that implement the dispose method.
                    // Cleanup managed objects by calling their Dispose() methods.
                    if (components != null)
                    {
                        components.Dispose();
                    }

                    if (m_DataDictionary != null)
                    {
                        m_DataDictionary.Dispose();
                    }

                    if (m_ControlPanel != null)
                    {
                        m_ControlPanel.Dispose();
                    }

                    if (m_TimerWibuBox != null)
                    {
                        m_TimerWibuBox.Stop();
                        m_TimerWibuBox.Enabled = false;
                        m_TimerWibuBox.Tick -= new EventHandler(WibuBoxCheck);
                        m_TimerWibuBox.Dispose();
                    }
                }

                // Whether called by consumer code or the garbage collector free all unmanaged resources and set the value of managed data 
                // members to null.
                m_DataDictionary = null;
                m_TimerWibuBox = null;
                m_ControlPanel = null;
                m_CommunicationInterface = null;
                m_MenuInterfaceApplication = null;
                m_MenuInterfaceEvent = null;
                m_MenuInterfaceSelfTest = null;
                m_MenuInterfaceWatch = null;
                m_MenuInterfaceWibuKey = null;
                m_Security = null;
            }
            catch (Exception)
            {
                // Don't do anything, just ensure that an exception is not thrown.
            }
            this.Cursor = Cursors.Default;
        }
        /// <summary>
        /// Show the form which allows the user to log in, if currently logged out, and vice-versa.
        /// </summary>
        /// <param name="projectIdentifier">The project-identifier of the active project.</param>
        public void Login(string projectIdentifier)
        {
            MainWindow.Cursor = Cursors.WaitCursor;

            // If the user is currently logged out, display the login screen, else log the user out.
            Security security = new Security();
            if (security.SecurityLevelCurrent <= security.SecurityLevelBase)
            {
                try
                {
                    // ----------------------------------------------------
                    // Check whether a WibuBox security device is required.
                    // ----------------------------------------------------
                    if (WibuBoxCheckIfRequired(projectIdentifier) == true)
                    {
                        try
                        {
                            // Yes, check that a valid WibuBox is attached.
                            MenuInterfaceWibuKey menuInterfaceWibuKey = new MenuInterfaceWibuKey(MainWindow);
                            if (menuInterfaceWibuKey.WibuBoxCheckForValidEntry(false) == true)
                            {
                                FormLogin formLogin = new FormLogin();
                                MainWindow.ShowDialog(formLogin);
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show(Resources.MBTWibuKeyDeviceDriverNotInstalled + CommonConstants.NewPara + Resources.MBTWibuKeyInstall,
                                            Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        FormLogin formLogin = new FormLogin();
                        MainWindow.ShowDialog(formLogin);
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                finally
                {
                    MainWindow.Cursor = Cursors.Default;
                }
            }
            else
            {
                DialogResult dialogResult = MessageBox.Show(Resources.MBTSecurityQueryLogOut, Resources.MBCaptionInformation, MessageBoxButtons.YesNo,
                                                            MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    // Update the security clearance.
                    security.SecurityLevelCurrent = security.SecurityLevelBase;
                    MainWindow.ShowSecurityLevelChange(security);
                }
                MainWindow.Cursor = Cursors.Default;
            }
        }