Beispiel #1
0
        private void OnAfterDataBound(GridViewAfterDataBoundEventArgs e)
        {
            ModuleProc PROC = new ModuleProc("", "OnAfterDataBound");

            try
            {
                if (this.AfterDataBound != null)
                {
                    this.AfterDataBound(e);
                }
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }
        }
        private void OnAfterDataBound(GridViewAfterDataBoundEventArgs e)
        {
            ModuleProc PROC = new ModuleProc("", "OnAfterDataBound");

            try
            {
                if (this.AfterDataBound != null)
                {
                    this.AfterDataBound(e);
                }
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }
        }
        private void DataBind(int pageIndex)
        {
            ModuleProc PROC = new ModuleProc("", "Method");
            GridViewAfterDataBoundEventArgs args = new GridViewAfterDataBoundEventArgs();

            lock (_lockGrid)
            {
                try
                {
                    dgvRows.ClearSelection();
                    dgvRows.Rows.Clear();

                    _pageIndex = pageIndex;
                    int start = (_pageIndex - 1) * this.RowsPerPage;
                    int end = (_pageIndex * this.RowsPerPage) - 1;
                    if (end > (_totalRows - 1)) end = _totalRows - 1;
                    int records = (end - start + 1);
                    int availRecords = Math.Min(records, this.RowsPerPage);
                    args.Start = start + 1;
                    args.End = start + availRecords;
                    args.Total = _totalRows;
                    lblPageInfo.Text = string.Format("{0:D} - {1:D} ({2:D})", args.Start, args.End, args.Total);

                    object[] query = this.GridDataSource
                                                    .AsQueryable()
                                                    .OfType<Object>()
                                                    .Skip(start)
                                                    .Take(availRecords).ToArray();
                    if (this.ManualDataBinding &&
                        query != null &&
                        query.Length > 0)
                    {
                        if (_asyncActive != null)
                        {
                            try
                            {
                                _asyncActive.InitializeProgress(1, query.Length);
                            }
                            catch { }
                        }

                        int i = 1;
                        foreach (var item in query)
                        {
                            if (_asyncActive != null)
                            {
                                try
                                {
                                    if (_asyncActive.ExecutorService != null &&
                                        _asyncActive.ExecutorService.IsShutdown) break;
                                }
                                catch { }
                            }

                            int rowIndex = dgvRows.Rows.Add();
                            DataGridViewRow row = dgvRows.Rows[rowIndex];
                            row.Tag = item;

                            if (_asyncActive != null)
                            {
                                try
                                {
                                    _asyncActive.UpdateStatusProgress(i, string.Empty);
                                }
                                catch { }
                            }

                            ManualRowBindEventArgs e = new ManualRowBindEventArgs()
                            {
                                Row = row,
                                RowNumber = (start + rowIndex + 1),
                                GridRowNumber = (rowIndex + 1),
                                DataObject = item
                            };
                            this.OnManualRowBind(e);
                            e = null;
                            i++;
                        }
                    }
                    else
                    {
                        dgvRows.DataSource = query;
                    }
                }
                catch (Exception ex)
                {
                    Log.Exception(PROC, ex);                    
                }
            }

            try
            {

                if (dgvRows.Rows.Count > 0)
                    dgvRows.Rows[0].Selected = true;
                this.dgvRows_SelectionChanged(dgvRows, EventArgs.Empty);

                this.OnAfterDataBound(args);
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }
            finally
            {
                _asyncActive = null;
            }
        }
Beispiel #4
0
        private void DataBind(int pageIndex)
        {
            ModuleProc PROC = new ModuleProc("", "Method");
            GridViewAfterDataBoundEventArgs args = new GridViewAfterDataBoundEventArgs();

            lock (_lockGrid)
            {
                try
                {
                    dgvRows.ClearSelection();
                    dgvRows.Rows.Clear();

                    _pageIndex = pageIndex;
                    int start = (_pageIndex - 1) * this.RowsPerPage;
                    int end   = (_pageIndex * this.RowsPerPage) - 1;
                    if (end > (_totalRows - 1))
                    {
                        end = _totalRows - 1;
                    }
                    int records      = (end - start + 1);
                    int availRecords = Math.Min(records, this.RowsPerPage);
                    args.Start       = start + 1;
                    args.End         = start + availRecords;
                    args.Total       = _totalRows;
                    lblPageInfo.Text = string.Format("{0:D} - {1:D} ({2:D})", args.Start, args.End, args.Total);

                    object[] query = this.GridDataSource
                                     .AsQueryable()
                                     .OfType <Object>()
                                     .Skip(start)
                                     .Take(availRecords).ToArray();
                    if (this.ManualDataBinding &&
                        query != null &&
                        query.Length > 0)
                    {
                        if (_asyncActive != null)
                        {
                            try
                            {
                                _asyncActive.InitializeProgress(1, query.Length);
                            }
                            catch { }
                        }

                        int i = 1;
                        foreach (var item in query)
                        {
                            if (_asyncActive != null)
                            {
                                try
                                {
                                    if (_asyncActive.ExecutorService != null &&
                                        _asyncActive.ExecutorService.IsShutdown)
                                    {
                                        break;
                                    }
                                }
                                catch { }
                            }

                            int             rowIndex = dgvRows.Rows.Add();
                            DataGridViewRow row      = dgvRows.Rows[rowIndex];
                            row.Tag = item;

                            if (_asyncActive != null)
                            {
                                try
                                {
                                    _asyncActive.UpdateStatusProgress(i, string.Empty);
                                }
                                catch { }
                            }

                            ManualRowBindEventArgs e = new ManualRowBindEventArgs()
                            {
                                Row           = row,
                                RowNumber     = (start + rowIndex + 1),
                                GridRowNumber = (rowIndex + 1),
                                DataObject    = item
                            };
                            this.OnManualRowBind(e);
                            e = null;
                            i++;
                        }
                    }
                    else
                    {
                        dgvRows.DataSource = query;
                    }
                }
                catch (Exception ex)
                {
                    Log.Exception(PROC, ex);
                }
            }

            try
            {
                if (dgvRows.Rows.Count > 0)
                {
                    dgvRows.Rows[0].Selected = true;
                }
                this.dgvRows_SelectionChanged(dgvRows, EventArgs.Empty);

                this.OnAfterDataBound(args);
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }
            finally
            {
                _asyncActive = null;
            }
        }