Пример #1
0
        /// <summary>
        /// Event handler for the form 'Shown' event. Loads the PTU configuration file and initializes the communication interface.
        /// </summary>
        /// <param name="sender">Reference to the object that raised the event.</param>
        /// <param name="e">Parameter passed from the object that raised the event.</param>
        private void MdiPTU_Shown(object sender, EventArgs e)
        {
            // Skip, if the Dispose() method has been called.
            if (IsDisposed)
            {
                return;
            }

            this.Update();
            Cursor = Cursors.WaitCursor;

            // ----------------------------------
            // Load the XML data dictionary file.
            // ----------------------------------
            m_DataDictionary = new DataDictionary();

            // Check whether the default XML configuration file is to be used.
            if (m_FilenameDataDictionary == Resources.FilenameDefaultDataDictionary)
            {
                // Yes - Check whether the default configuration file exists.
                string fullFilename = DirectoryManager.PathPTUConfigurationFiles + @"\" + m_FilenameDataDictionary;
                FileInfo fileInfo = new FileInfo(fullFilename);
                if (fileInfo.Exists == false)
                {
                    MessageBox.Show(string.Format(Resources.MBTConfigDefaultNotFound, Resources.FilenameDefaultDataDictionary), Resources.MBCaptionWarning,
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Security.Initialize();
                    m_Security = new Security();
                    ShowSecurityLevelChange(m_Security);
                    Cursor = Cursors.Default;
                    SetMode(Mode.Setup);
                    return;
                }
            }
            
            // Read the XML configuration file.
            try
            {
                // If the XML file hasn't been updated to include the YearCodeSize field of the CONFIGUREPTU table, the other fields of the table are still
                // read in correctly. If an attempt is made to access 'm_DataDictionary.CONFIGUREPTU[0].YearCodeSize' an exception is thrown.
                m_DataDictionary.ReadXml(DirectoryManager.PathPTUConfigurationFiles + CommonConstants.BindingFilename + m_FilenameDataDictionary);
            }
            catch (Exception)
            {
                MessageBox.Show(string.Format(Resources.MBTConfigInvalid, m_FilenameDataDictionary) + CommonConstants.Space + Resources.MBTConfigReselect,
                                              Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Security.Initialize();
                m_Security = new Security();
                ShowSecurityLevelChange(m_Security);
                Cursor = Cursors.Default;
                SetMode(Mode.Setup);
                return;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }

            Cursor = Cursors.WaitCursor;
            LoadDictionary(m_DataDictionary);
            Cursor = Cursors.Default;
        }