Exemple #1
0
        /// <summary>
        /// Loads and displays a data table in the grid.
        /// </summary>
        /// <param name="sFilePath">The path to the data table file.</param>
        public void LoadTable(string sFilePath)
        {
            if (m_loadedTable != null)
            {
                UnloadTable();
            }

            m_loadedTable             = new Table(sFilePath);
            m_lastLoadedTableFilePath = sFilePath;

            if (m_loadedTable.FileSize >= (50 * 1024 * 1024))
            {
                if (MessageBox.Show("The selected file is exceptionally large and could take a long time to load. Would you like to continue?",
                                    "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                {
                    goto Cancel;
                }
            }

            if (Settings.UseExternalDescriptors && !Descriptors.IsFileLoaded)
            {
                SetStatusText("Loading Definitions...");
                Descriptors.Load(Settings.ExternalDescriptorsFile);
            }

            SetStatusText("Loading Table...");

            m_loadedTable.ReadFile();
            m_loadedTable.ReadHeader();

            if (!m_loadedTable.IsValid)
            {
                MessageBox.Show("The loaded table did not match the expected file format!",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                goto Cancel;
            }

            m_loadedTable.ReadColumns();

            if (Settings.UseExternalDescriptors && Descriptors.ExistsForTable(ref m_loadedTable))
            {
                Descriptors.Apply(ref m_loadedTable);
            }

            m_loadedTable.ReadRows();
            m_loadedTable.CloseFile();

            if (m_loadedTable.ColumnCount == 0)
            {
                MessageBox.Show("The loaded table did not contain any columns!",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                goto Cancel;
            }

            if (m_loadedTable.RowCount == 0)
            {
                MessageBox.Show("The loaded table did not contain any rows!",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                goto Cancel;
            }

            MenuStrip_File_Export.Enabled       = true;
            MenuStrip_File_Close.Enabled        = true;
            MenuStrip_View_NextPage.Enabled     = true;
            MenuStrip_View_PreviousPage.Enabled = true;
            MenuStrip_View_ViewPage.Enabled     = true;
            StatusStrip_PageNumberLabel.Visible = true;

            TableGridView.Columns.Add("RowIndexColumn", "<Index>");
            TableGridView.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
            TableGridView.Columns[0].Visible  = MenuStrip_View_DisplayRowIndex.Checked;

            for (int i = 0; i < (int)m_loadedTable.ColumnCount; i++)
            {
                string sColumnName = m_loadedTable.Columns[i].Name;
                TableGridView.Columns.Add(sColumnName + "Column", sColumnName);
                TableGridView.Columns[i + 1].SortMode = DataGridViewColumnSortMode.NotSortable;
            }

            SetRowsPerPage(m_rowsPerPage);
            SetPageNumber(1);

            SetStatusText("Viewing Table: {0}.tbl", m_loadedTable.TableName);
            return;

Cancel:
            SetStatusText("Ready");
        }