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

LoadLookups() public méthode

Loads the combo boxes.
public LoadLookups ( ) : void
Résultat void
        public void LoadLookups()
        {
            RockConfig rockConfig = RockConfig.Load();
            RockRestClient client = new RockRestClient( rockConfig.RockBaseUrl );
            client.Login( rockConfig.Username, rockConfig.Password );
            List<Campus> campusList = client.GetData<List<Campus>>( "api/Campuses" );

            cbCampus.SelectedValuePath = "Id";
            cbCampus.DisplayMemberPath = "Name";
            cbCampus.Items.Clear();
            cbCampus.Items.Add( new Campus { Id = 0, Name = string.Empty } );
            foreach ( var campus in campusList.OrderBy( a => a.Name ) )
            {
                cbCampus.Items.Add( campus );
            }

            cbCampus.SelectedIndex = 0;

            var currencyTypeDefinedType = client.GetDataByGuid<DefinedType>( "api/DefinedTypes", Rock.Client.SystemGuid.DefinedType.FINANCIAL_CURRENCY_TYPE.AsGuid() );
            this.CurrencyValueList = client.GetData<List<DefinedValue>>( "api/DefinedValues", "DefinedTypeId eq " + currencyTypeDefinedType.Id.ToString() );

            //// load all the Transaction Source values and fetch the attributes so that we can filter the selectable ones (core.ShowInCheckScanner=true)
            //// when populating the dropdown on the scanning prompt page.
            //// don't filter them here because we might be viewing transactions that have an unselectable Transaction Source Type
            var sourceTypeDefinedType = client.GetDataByGuid<DefinedType>( "api/DefinedTypes", Rock.Client.SystemGuid.DefinedType.FINANCIAL_SOURCE_TYPE.AsGuid() );
            var sourceTypeUri = string.Format( "api/DefinedValues?$filter=DefinedTypeId eq {0}&loadAttributes=simple", sourceTypeDefinedType.Id.ToString() );
            this.SourceTypeValueList = client.GetData<List<DefinedValue>>( sourceTypeUri );
        }

Usage Example

        /// <summary>
        /// Handles the Click event of the btnLogin 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 btnLogin_Click(object sender, RoutedEventArgs e)
        {
            lblLoginWarning.Visibility = Visibility.Hidden;
            txtUsername.Text           = txtUsername.Text.Trim();
            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 = "https://" + rockUrl.AbsoluteUri;
            }

            RockRestClient rockRestClient = new RockRestClient(txtRockUrl.Text);

            string userName = txtUsername.Text;
            string password = txtPassword.Password;

            if (string.IsNullOrWhiteSpace(userName))
            {
                lblLoginWarning.Content    = "Username cannot be blank";
                lblLoginWarning.Visibility = Visibility.Visible;
                return;
            }

            // start a background thread to Login since this could take a little while and we want a Wait cursor
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += delegate(object s, DoWorkEventArgs ee)
            {
                ee.Result = null;
                rockRestClient.Login(userName, password);
            };

            // when the Background Worker is done with the Login, run this
            bw.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs ee)
            {
                this.Cursor        = null;
                btnLogin.IsEnabled = true;
                try
                {
                    if (ee.Error != null)
                    {
                        throw ee.Error;
                    }

                    Person     person     = rockRestClient.GetData <Person>(string.Format("api/People/GetByUserName/{0}", userName));
                    RockConfig rockConfig = RockConfig.Load();
                    rockConfig.RockBaseUrl = txtRockUrl.Text;
                    rockConfig.Username    = txtUsername.Text;
                    rockConfig.Password    = txtPassword.Password;
                    rockConfig.Save();

                    BatchPage batchPage = new BatchPage(person);

                    if (this.NavigationService.CanGoBack)
                    {
                        // if we got here from some other Page, go back
                        this.NavigationService.GoBack();
                    }
                    else
                    {
                        try
                        {
                            batchPage.LoadLookups();
                            batchPage.LoadFinancialBatchesGrid();
                        }
                        catch (HttpErrorException ex)
                        {
                            if (ex.Response != null && ex.Response.StatusCode.Equals(HttpStatusCode.Unauthorized))
                            {
                                lblLoginWarning.Content    = "Not Authorized for Financial Batches";
                                lblLoginWarning.Visibility = Visibility.Visible;
                                return;
                            }
                            else
                            {
                                throw ex;
                            }
                        }

                        this.NavigationService.Navigate(batchPage);
                    }
                }
                catch (WebException wex)
                {
                    // show WebException on the form, but any others should end up in the ExceptionDialog
                    HttpWebResponse response = wex.Response as HttpWebResponse;
                    if (response != null)
                    {
                        if (response.StatusCode.Equals(HttpStatusCode.Unauthorized))
                        {
                            lblLoginWarning.Content    = "Invalid Login";
                            lblLoginWarning.Visibility = Visibility.Visible;
                            return;
                        }
                    }

                    string message = wex.Message;
                    if (wex.InnerException != null)
                    {
                        message += "\n" + wex.InnerException.Message;
                    }

                    lblRockUrl.Visibility      = Visibility.Visible;
                    txtRockUrl.Visibility      = Visibility.Visible;
                    lblLoginWarning.Content    = message;
                    lblLoginWarning.Visibility = Visibility.Visible;
                    return;
                }
            };

            // set the cursor to Wait, disable the login button, and start the login background process
            this.Cursor        = Cursors.Wait;
            btnLogin.IsEnabled = false;
            bw.RunWorkerAsync();
        }
All Usage Examples Of Rock.Apps.CheckScannerUtility.BatchPage::LoadLookups