Ejemplo n.º 1
0
        // 更新 tlpImages 內部 Controls , 更新 lblNowPage , 指定畫邊框 ID
        public void RefreshtlpImagesControls(int nowPage, int paintRowID)
        {
            _nowPage = nowPage;
            // Clear  TableLayout of FlawImages's controls
            tlpFlawImages.Controls.Clear();
            // Calculate about init.
            int holderWidth = tlpFlawImages.Width / tlpFlawImages.ColumnCount;
            int holderHeight = tlpFlawImages.Height / tlpFlawImages.RowCount;
            int pageSize = tlpFlawImages.ColumnCount * tlpFlawImages.RowCount;
            lblNowPage.Text = nowPage.ToString();
            // Get now filter rows
            // Sort DataRow[]: 因為 _dtbFlaws.Select() 後資料排序會亂掉.
            string sortedColumn = dgvFlaw.SortedColumn.Name;
            string sortOrder = "";
            if (dgvFlaw.SortOrder.ToString() == "Ascending")
            {
                sortOrder = "ASC";
            }
            else
            {
                sortOrder = "DESC";
            }
            string sortString = string.Format("{0} {1}, FlawID", sortedColumn, sortOrder);
            DataRow[] rows = _dtbFlaws.Select(_dtbFlaws.DefaultView.RowFilter, sortString);
            int startFicIndex = (nowPage - 1) * pageSize;
            int endFicIndex = ((startFicIndex + pageSize) > _dtbFlaws.DefaultView.Count) ? _dtbFlaws.DefaultView.Count : (startFicIndex + pageSize);
            // Add FlawImageControl in tableLayout.
            for (int i = startFicIndex; i < endFicIndex; i++)
            {

                FlawImageControl fi = new FlawImageControl(rows[i], ref _units);
                SetDoubleBuffered(fi);
                // set draw border
                if(i == paintRowID)
                    fi.IsDrawBorder = true;
                else
                    fi.IsDrawBorder = false;
                fi.Width = holderWidth;
                fi.Height = holderHeight;
                fi.Dock = DockStyle.Fill;
                tlpFlawImages.Controls.Add(fi);

            }
        }
Ejemplo n.º 2
0
        public void DataTable_RowFilterChange(object sender, ListChangedEventArgs e)
        {
            // UNDONE: 這邊改成使用GirdView資料列, 因為GridView排序之後會和下面對不起來.
            // UNDONE: FlawImageControl加入時效能不佳須改善.
            // Clear tableLyout controls and search data.
            DataView dv = sender as DataView;
            tlpFlawImages.Controls.Clear();
            int holderWidth = tlpFlawImages.Width / tlpFlawImages.ColumnCount;
            int holderHeight = tlpFlawImages.Height / tlpFlawImages.RowCount;

            // Sort DataRow[]: 因為 _dtbFlaws.Select() 後資料排序會亂掉.
            string sortedColumn = dgvFlaw.SortedColumn.Name;
            string sortOrder = "";
            if (dgvFlaw.SortOrder.ToString() == "Ascending")
            {
                sortOrder = "ASC";
            }
            else
            {
                sortOrder = "DESC";
            }
            string sortString = string.Format("{0} {1}, FlawID", sortedColumn, sortOrder);
            DataRow[] rows = _dtbFlaws.Select(dv.RowFilter, sortString);

            // Calculate pages & set label and buttons
            int pageSize = tlpFlawImages.ColumnCount * tlpFlawImages.RowCount;
            _nowPage = 1;
            if (rows.Length <= pageSize)
                _totalPage = 1;
            else
            {
                _totalPage = rows.Length % pageSize == 0 ?
                             rows.Length / pageSize :
                             rows.Length / pageSize + 1;
            }
            lblNowPage.Text = _nowPage.ToString();
            lblTotalPage.Text = _totalPage.ToString();
            int startFicIndex = (_nowPage - 1) * pageSize;
            int endFicIndex = ((startFicIndex + pageSize) > rows.Length) ? rows.Length : (startFicIndex + pageSize);
            // 計算完之後,判斷直接跳頁按鈕可否使用.
            if (_totalPage > 1)
            {
                btnShowGoPage.Enabled = true;
            }
            else
            {
                btnShowGoPage.Enabled = false;
            }
            // Add FlawImageControl in tableLayout.
            for (int i = startFicIndex; i < endFicIndex; i++)
            {
                FlawImageControl fi = new FlawImageControl(rows[i], ref _units);
                SetDoubleBuffered(fi);
                fi.Width = holderWidth;
                fi.Height = holderHeight;
                fi.Dock = DockStyle.Fill;
                tlpFlawImages.Controls.Add(fi);
            }

            // Set can using buttons when oncut all button reset.
            if (_totalPage > 1)
            {
                btnNextFlawImages.Enabled = true;
                btnPrevFlawImages.Enabled = false;
            }
            else
            {
                btnNextFlawImages.Enabled = false;
                btnPrevFlawImages.Enabled = false;
            }
            dgvFlaw.ClearSelection();
        }