Beispiel #1
0
        /// <summary>
        /// Обновляет GridView.
        /// </summary>
        public void ShowAircraftGridView(bool autoPosition, int page)
        {
            if (AircraftGridView.InvokeRequired)
            {
                AircraftGridView.BeginInvoke(new Action <bool, int>(ShowAircraftGridView), new object[] { autoPosition, page });
                return;
            }
            string f = "";

            if (search)
            {
                f = filter();
            }
            double AllPage = Convert.ToDouble(SQL.query("SELECT COUNT(*) FROM [Aircraft] " + f).Rows[0][0]) / RowOfPage;

            if (AllPage > Math.Truncate(AllPage))
            {
                AllPage = Math.Truncate(AllPage) + 1;
            }
            if (AllPage == 0)
            {
                AllPage++;
            }
            UpdateDataGridView(SQL.query("SELECT TOP " + RowOfPage.ToString() + " * FROM (SELECT TOP " + Convert.ToString(page * RowOfPage) + " [Id], [TargetAddress] AS 'ICAO24',[Country] AS 'Государство', [Registration] AS 'Бортовой', [ICAOTypeCode] AS 'ICAOType', [TypeAircraft] AS 'Тип', [EmitterCategory] AS 'Категория', [Class] AS 'Класс', [UserText] AS 'Примечание' FROM [Aircraft] " + f + " ORDER BY [Id] desc) t ORDER BY [Id]"), autoPosition);
            if (page == 1)
            {
                Back.Enabled = false;
            }
            if ((AllPage > 1) && (page != AllPage))
            {
                Up.Enabled = true;
            }
            PageTextBox.Text    = page.ToString();
            AllPageTextBox.Text = AllPage.ToString();
        }
Beispiel #2
0
        /// <summary>
        /// Обновляет данные в AircraftGridView.
        /// </summary>
        /// <param name="table">Таблица данных.</param>
        /// <param name="autoPosition">Фиксация положения в таблице. Использовать только при добавлении данных в таблицу (когда предыдущие строки не изменяются).</param>
        public void UpdateDataGridView(DataTable table, bool autoPosition)
        {
            if (AircraftGridView.InvokeRequired)
            {
                AircraftGridView.BeginInvoke(new Action <DataTable, bool>(UpdateDataGridView), new object[] { table, autoPosition });
                return;
            }

            int selectedId   = 0;
            int firstRow     = 0;
            int sortedColumn = 0;
            ListSortDirection sortDirection = ListSortDirection.Descending;

            if (AircraftGridView.Rows.Count > 0)
            {
                if (AircraftGridView.CurrentCell != null)
                {
                    selectedId = Convert.ToInt32(AircraftGridView[0, AircraftGridView.CurrentCell.RowIndex].Value);
                }
                if (AircraftGridView.FirstDisplayedScrollingRowIndex >= 0)
                {
                    firstRow = AircraftGridView.FirstDisplayedScrollingRowIndex;
                }
            }

            if (AircraftGridView.SortedColumn != null)
            {
                sortedColumn = AircraftGridView.SortedColumn.Index;
                if (AircraftGridView.SortOrder == System.Windows.Forms.SortOrder.Ascending)
                {
                    sortDirection = ListSortDirection.Ascending;
                }
                else
                {
                    sortDirection = ListSortDirection.Descending;
                }
            }

            AircraftGridView.DataSource            = table;
            AircraftGridView.Columns["Id"].Visible = false;

            AircraftGridView.Sort(AircraftGridView.Columns[sortedColumn], sortDirection);

            if (AircraftGridView.Rows.Count > 0)
            {
                if (autoPosition)
                {
                    for (int row = 0; row < AircraftGridView.Rows.Count; row++)
                    {
                        if (Convert.ToInt32(AircraftGridView[0, row].Value) == selectedId)
                        {
                            AircraftGridView.CurrentCell = AircraftGridView[1, row];
                            break;
                        }
                    }
                    AircraftGridView.FirstDisplayedScrollingRowIndex = firstRow;
                }
            }
        }