예제 #1
0
        private async void Form1_Shown(object sender, EventArgs e)
        {
            //var waitForm = new WaitForm() {TopLevel =  true, TopMost = true};
            //waitForm.Show();
            //try
            //{
            //    _customersBindingSource = new BindingSourceDataTable { DataSource = await _operations.LoadCustomerData() };
            //}
            //finally
            //{
            //    waitForm.Dispose();
            //}

            _customersBindingSource = new BindingSourceDataTable {
                DataSource = await _operations.LoadCustomerData()
            };

            if (_operations.IsSuccessFul)
            {
                customerDataGridView.DataSource = _customersBindingSource;
                bindingNavigator1.BindingSource = _customersBindingSource;

                _customersBindingSource.Sort    = "CompanyName";
                customerDataGridView.DataError += CustomerDataGridView_DataError;
                customerDataGridView.ExpandColumns();
            }
            else
            {
                MessageBox.Show($"Encountered the following issues\n{_operations.LastExceptionMessage}");
            }
        }
예제 #2
0
        private async void IterateDataForm_Shown(object sender, EventArgs e)
        {
            _recordCount = await _operations.PersonTableAsyncCountTask();

            var progress = new Progress <string>(s => label1.Text = $"Loading {s} of {_recordCount}");

            try
            {
                _contactsBindingSource = new BindingSourceDataTable {
                    DataSource = await _operations.LoadPeopleAsyncWithCancellationTask(progress, _cancellationTokenSource.Token)
                };
                if (_operations.IsSuccessFul)
                {
                    dataGridView1.DataSource        = _contactsBindingSource;
                    bindingNavigator1.BindingSource = _contactsBindingSource;

                    _contactsBindingSource.Sort = "LastName";

                    dataGridView1.Columns["id"].Visible = false;
                    dataGridView1.DataError            += DataGridView1_DataError;
                    dataGridView1.ExpandColumns();

                    if (_cancellationTokenSource.IsCancellationRequested)
                    {
                        MessageBox.Show($"Operation cancelled with {_contactsBindingSource.Count} of {_recordCount} records.");
                    }

                    dataGridView1.KeyDown += DataGridView1_KeyDown;
                    ActiveControl          = dataGridView1;
                }
                else
                {
                    MessageBox.Show(_operations.LastExceptionMessage);
                }
            }
            catch (OperationCanceledException)
            {
                MessageBox.Show("Loading of data has been cancelled");
            }
            catch (Exception exception)
            {
                MessageBox.Show($"Encountered issues\n{exception.Message}");
            }
        }