Rock.Apps.CheckScannerUtility.BatchItemDetailPage.Page_Loaded C# (CSharp) Method

Page_Loaded() private method

Handles the Loaded event of the Page control.
private Page_Loaded ( object sender, RoutedEventArgs e ) : void
sender object The source of the event.
e System.Windows.RoutedEventArgs The instance containing the event data.
return void
        private void Page_Loaded( object sender, RoutedEventArgs e )
        {
            var financialTransaction = this.FinancialTransaction;
            var images = financialTransaction.Images.OrderBy( a => a.Order ).ToList();

            RockConfig config = RockConfig.Load();
            RockRestClient client = new RockRestClient( config.RockBaseUrl );
            client.Login( config.Username, config.Password );

            if ( images.Count > 0 )
            {
                var imageUrl = string.Format( "{0}GetImage.ashx?Id={1}", config.RockBaseUrl.EnsureTrailingForwardslash(), images[0].BinaryFileId );
                var imageBytes = client.DownloadData( imageUrl );

                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = new MemoryStream( imageBytes );
                bitmapImage.EndInit();
                imgFront.Source = bitmapImage;
            }
            else
            {
                imgFront.Source = null;
            }

            if ( images.Count > 1 )
            {
                var imageUrl = string.Format( "{0}GetImage.ashx?Id={1}", config.RockBaseUrl.EnsureTrailingForwardslash(), images[1].BinaryFileId );
                var imageBytes = client.DownloadData( imageUrl );

                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = new MemoryStream( imageBytes );
                bitmapImage.EndInit();
                imgBack.Source = bitmapImage;
            }
            else
            {
                imgBack.Source = null;
            }

            lblFront.Visibility = imgFront.Source != null ? Visibility.Visible : Visibility.Collapsed;
            lblBack.Visibility = imgBack.Source != null ? Visibility.Visible : Visibility.Collapsed;

            lblScannedDateTime.Content = financialTransaction.CreatedDateTime.HasValue ? financialTransaction.CreatedDateTime.Value.ToString( "g" ) : null;
            lblTransactionDateTime.Content = financialTransaction.TransactionDateTime.HasValue ? financialTransaction.TransactionDateTime.Value.ToString( "g" ) : null;
            lblBatch.Content = batchPage.SelectedFinancialBatch.Name;

            financialTransaction.SourceTypeValue = financialTransaction.SourceTypeValue ?? batchPage.SourceTypeValueList.FirstOrDefault( a => a.Id == financialTransaction.SourceTypeValueId );
            lblSource.Content = financialTransaction.SourceTypeValue != null ? financialTransaction.SourceTypeValue.Value : null;

            // only show Transaction Code if it has one
            lblTransactionCodeValue.Content = financialTransaction.TransactionCode;
            bool hasTransactionCode = !string.IsNullOrWhiteSpace( financialTransaction.TransactionCode );
            lblTransactionCodeLabel.Visibility = hasTransactionCode ? Visibility.Visible : Visibility.Collapsed;
            lblTransactionCodeValue.Visibility = hasTransactionCode ? Visibility.Visible : Visibility.Collapsed;

            if ( financialTransaction.FinancialPaymentDetailId.HasValue )
            {
                financialTransaction.FinancialPaymentDetail = financialTransaction.FinancialPaymentDetail ?? client.GetData<FinancialPaymentDetail>( string.Format( "api/FinancialPaymentDetails/{0}", financialTransaction.FinancialPaymentDetailId ?? 0 ) );
            }

            if ( financialTransaction.FinancialPaymentDetail != null )
            {
                financialTransaction.FinancialPaymentDetail.CurrencyTypeValue = financialTransaction.FinancialPaymentDetail.CurrencyTypeValue ?? batchPage.CurrencyValueList.FirstOrDefault( a => a.Id == financialTransaction.FinancialPaymentDetail.CurrencyTypeValueId );
                lblCurrencyType.Content = financialTransaction.FinancialPaymentDetail.CurrencyTypeValue != null ? financialTransaction.FinancialPaymentDetail.CurrencyTypeValue.Value : null;
            }
            else
            {
                lblCurrencyType.Content = string.Empty;
            }
        }