Rock.Apps.CheckScannerUtility.BatchPage.UpdateBatchUI C# (CSharp) Méthode

UpdateBatchUI() private méthode

Updates the batch UI.
private UpdateBatchUI ( FinancialBatch selectedBatch ) : void
selectedBatch FinancialBatch The selected batch.
Résultat void
        private void UpdateBatchUI( FinancialBatch selectedBatch )
        {
            if ( selectedBatch == null )
            {
                grdBatchItems.DataContext = null;
                DisplayTransactionCount();
                HideBatch();
                return;
            }
            else
            {
                ShowBatch( false );
            }

            RockConfig rockConfig = RockConfig.Load();
            RockRestClient client = new RockRestClient( rockConfig.RockBaseUrl );
            client.Login( rockConfig.Username, rockConfig.Password );
            SelectedFinancialBatch = selectedBatch;
            lblBatchNameReadOnly.Content = selectedBatch.Name;
            lblBatchIdReadOnly.Content = string.Format( "Batch Id: {0}", selectedBatch.Id );

            lblBatchCampusReadOnly.Content = selectedBatch.CampusId.HasValue ? client.GetData<Campus>( string.Format( "api/Campuses/{0}", selectedBatch.CampusId ?? 0 ) ).Name : string.Empty;
            lblBatchDateReadOnly.Content = selectedBatch.BatchStartDateTime.Value.ToString( "d" );
            var createdByPerson = client.GetData<Person>( string.Format( "api/People/GetByPersonAliasId/{0}", selectedBatch.CreatedByPersonAliasId ?? 0 ) );
            if ( createdByPerson != null )
            {
                lblBatchCreatedByReadOnly.Content = string.Format("{0} {1}", createdByPerson.NickName, createdByPerson.LastName);
            }
            else
            {
                lblBatchCreatedByReadOnly.Content = string.Empty;
            }

            lblBatchControlAmountReadOnly.Content = selectedBatch.ControlAmount.ToString( "F" );

            txtBatchName.Text = selectedBatch.Name;
            if ( selectedBatch.CampusId.HasValue )
            {
                cbCampus.SelectedValue = selectedBatch.CampusId;
            }
            else
            {
                cbCampus.SelectedValue = 0;
            }

            dpBatchDate.SelectedDate = selectedBatch.BatchStartDateTime;
            lblCreatedBy.Content = lblBatchCreatedByReadOnly.Content as string;
            txtControlAmount.Text = selectedBatch.ControlAmount.ToString( "F" );
            txtNote.Text = selectedBatch.Note;

            // start a background thread to download transactions since this could take a little while and we want a Wait cursor
            BackgroundWorker bw = new BackgroundWorker();
            Rock.Wpf.WpfHelper.FadeOut( lblCount, 0 );
            lblCount.Content = "Loading...";
            Rock.Wpf.WpfHelper.FadeIn( lblCount, 300 );
            List<FinancialTransaction> transactions = null;
            grdBatchItems.DataContext = null;
            bw.DoWork += delegate( object s, DoWorkEventArgs ee )
            {
                ee.Result = null;

                transactions = client.GetData<List<FinancialTransaction>>( "api/FinancialTransactions/", string.Format( "BatchId eq {0}", selectedBatch.Id ) );
            };

            bw.RunWorkerCompleted += delegate( object s, RunWorkerCompletedEventArgs ee )
            {
                this.Cursor = null;
                foreach ( var transaction in transactions )
                {
                    if ( transaction.FinancialPaymentDetailId.HasValue )
                    {
                        transaction.FinancialPaymentDetail = transaction.FinancialPaymentDetail ?? client.GetData<FinancialPaymentDetail>( string.Format( "api/FinancialPaymentDetails/{0}", transaction.FinancialPaymentDetailId ?? 0 ) );
                        if ( transaction.FinancialPaymentDetail != null )
                        {
                            transaction.FinancialPaymentDetail.CurrencyTypeValue = this.CurrencyValueList.FirstOrDefault( a => a.Id == transaction.FinancialPaymentDetail.CurrencyTypeValueId );
                        }
                    }
                }

                // sort starting with most recent first
                var bindingList = new BindingList<FinancialTransaction>( transactions.OrderByDescending( a => a.CreatedDateTime ).ToList() );
                bindingList.RaiseListChangedEvents = true;
                bindingList.ListChanged += bindingList_ListChanged;

                grdBatchItems.DataContext = bindingList;
                DisplayTransactionCount();
            };

            this.Cursor = Cursors.Wait;
            bw.RunWorkerAsync();
        }

Usage Example

Exemple #1
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            _rockConfig.CaptureAmountOnScan = chkCaptureAmountOnScan.IsChecked == true;

            _rockConfig.RequireControlAmount    = chkRequireControlAmount.IsChecked == true;
            _rockConfig.RequireControlItemCount = chkRequireControlItemCount.IsChecked == true;
            AddAccountsForAmountsToSave();
            if (_rockConfig.CaptureAmountOnScan && _rockConfig.SelectedAccountForAmountsIds.Count() == 0)
            {
                MessageBox.Show("Please select at least one account", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            try
            {
                txtRockUrl.Text = txtRockUrl.Text.Trim();
                Uri rockUrl      = new Uri(txtRockUrl.Text);
                var validSchemes = new string[] { Uri.UriSchemeHttp, Uri.UriSchemeHttps };
                if (!validSchemes.Contains(rockUrl.Scheme))
                {
                    txtRockUrl.Text = "http://" + rockUrl.AbsoluteUri;
                }

                RockRestClient client = new RockRestClient(txtRockUrl.Text);
                client.Login(_rockConfig.Username, _rockConfig.Password);
                BatchPage.LoggedInPerson = client.GetData <Person>(string.Format("api/People/GetByUserName/{0}", _rockConfig.Username));
            }
            catch (WebException wex)
            {
                HttpWebResponse response = wex.Response as HttpWebResponse;
                if (response != null)
                {
                    if (response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        // valid URL but invalid login, so navigate back to the LoginPage
                        _rockConfig.RockBaseUrl = txtRockUrl.Text;
                        _rockConfig.Save();
                        LoginPage loginPage = new LoginPage(true);
                        this.NavigationService.Navigate(loginPage);
                        return;
                    }
                }

                lblAlert.Content    = wex.Message;
                lblAlert.Visibility = Visibility.Visible;
                return;
            }
            catch (Exception ex)
            {
                App.LogException(ex);
                lblAlert.Content    = ex.Message;
                lblAlert.Visibility = Visibility.Visible;
                return;
            }

            _rockConfig.RockBaseUrl = txtRockUrl.Text;

            switch (cboScannerInterfaceType.SelectedItem as string)
            {
            case "MagTek COM":
                _rockConfig.ScannerInterfaceType = RockConfig.InterfaceType.MICRImageRS232;
                break;

            case "MagTek Image Safe":
                _rockConfig.ScannerInterfaceType = RockConfig.InterfaceType.MagTekImageSafe;
                break;

            default:
                _rockConfig.ScannerInterfaceType = RockConfig.InterfaceType.RangerApi;
                break;
            }

            string imageOption = cboImageOption.SelectedValue as string;

            _rockConfig.Sensitivity = txtSensitivity.Text.Trim().AsInteger().ToString();
            _rockConfig.Plurality   = txtPlurality.Text.Trim().AsInteger().ToString();

            switch (imageOption)
            {
            case "Grayscale":
                _rockConfig.ImageColorType = RangerImageColorTypes.ImageColorTypeGrayscale;
                break;

            case "Color":
                _rockConfig.ImageColorType = RangerImageColorTypes.ImageColorTypeColor;
                break;

            default:
                _rockConfig.ImageColorType = RangerImageColorTypes.ImageColorTypeBitonal;
                break;
            }

            string comPortName = cboMagTekCommPort.SelectedItem as string;

            if (!string.IsNullOrWhiteSpace(comPortName))
            {
                _rockConfig.MICRImageComPort = short.Parse(comPortName.Replace("COM", string.Empty));
            }

            var campusFilter = cboCampusFilter.SelectedItem as Campus;

            _rockConfig.CampusIdFilter = campusFilter?.Id;

            _rockConfig.Save();
            BatchPage.LoadLookups();

            // shutdown the scanner so that options will be reloaded when the batch page loads
            if (BatchPage.rangerScanner != null)
            {
                BatchPage.rangerScanner.ShutDown();
            }

            BatchPage.UnbindAllEvents();
            BatchPage.BindDeviceToPage();
            BatchPage.ConnectToScanner();
            BatchPage.LoadFinancialBatchesGrid();
            BatchPage.UpdateBatchUI(BatchPage.SelectedFinancialBatch);

            this.NavigationService.Navigate(BatchPage);
        }