/// <summary>
        /// Process asynchronously the Create Report click.
        /// </summary>
        async void CreateReportButton_TouchUpInsideAsync()
        {
            try
            {
                // Clear the last displayed report creation status.
                StatusLabel.Text = "";

                // Get the expense code for the Expense Type selected in the UI.
                int    selectedExpenseTypeIndex = ExpenseTypePicker.SelectedRowInComponent(0);
                string expenseTypeCode          = ExpenseTypes[selectedExpenseTypeIndex].Code;

                // Get the ID for the Payment Type selected in the UI.
                int    selectedPaymentTypeIndex = PaymentTypePicker.SelectedRowInComponent(0);
                string paymentTypeId            = PaymentTypes[selectedPaymentTypeIndex].ID;

                // The facade will call Concur APIs to create an expense report with an expense entry and an expense image.
                string reportId = await ClientLibraryFacade.CreateReportWithImageAsync(
                    ReportNameTextField.Text,
                    VendorTextField.Text,
                    decimal.Parse(AmountTextField.Text),
                    CurrencyTextField.Text,
                    expenseTypeCode,
                    DateTime.Parse(DateTextField.Text),
                    paymentTypeId,
                    ExpenseImageData,
                    ReceiptFileType.Jpeg);

                // Show report creation success as the lastest status.
                StatusLabel.Text = "Success!!!  Report ID: " + reportId;
            }
            catch (Exception e)
            {
                DisplayException(e);
            }
        }
Example #2
0
        /// <summary>
        /// Asynchronous handler activated when the user clicks the Login button.
        /// </summary>
        private async void LoginButton_ClickAsync()
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                //Get the user oauth token
                OAuthTokenDetail oauthTokenDetail = await ClientLibraryFacade.LoginAsync(
                    LoginIdTextBox.Text,
                    PasswordTextBox.Text,
                    ClientIdTextBox.Text);

                //Get the user company expense configuration needed to submit expense reports.
                var groupConfig = await ClientLibraryFacade.GetGroupConfigurationAsync();

                //Determine the default expense policy out of the expense configuration,
                //so that the default policy will be selected by default on the UI.
                var policies           = groupConfig.Policies;
                int defaultPolicyIndex = -1;
                for (int i = 0; i < policies.Length; i++)
                {
                    if (policies[i].IsDefault.Value)
                    {
                        defaultPolicyIndex = i;
                        break;
                    }
                }

                //Display the list of expense policies obtained from the company configuration
                //and select the default policy
                ExpensePolicyListBox.DisplayMember = "Name";
                ExpensePolicyListBox.Items.AddRange(groupConfig.Policies);
                if (defaultPolicyIndex != -1)
                {
                    ExpensePolicyListBox.SelectedIndex = defaultPolicyIndex;
                }

                //Display the list of allowed payment types obtained from the company configuration.
                PaymentTypeComboBox.DisplayMember = "Name";
                PaymentTypeComboBox.Items.AddRange(groupConfig.PaymentTypes);
                if (groupConfig.PaymentTypes.Length > 0)
                {
                    PaymentTypeComboBox.SelectedIndex = 0;
                }

                //Display the oauth token obtained from the user login.
                OAuthTokenTextBox.Text         = oauthTokenDetail.AccessToken;
                CreateEverythingButton.Enabled = true;
            }
            catch (Exception except)
            {
                DisplayException(except);
            }
            finally {
                this.Cursor = Cursors.Default;
            }
        }
Example #3
0
        /// <summary>
        /// Process asynchronously the Login button click.
        /// </summary>
        protected async void LoginAsync()
        {
            try
            {
                // Clear status
                TextView statusView = FindViewById <TextView>(Resource.Id.statusTextView);
                statusView.Text = "";

                // Find the objects for Login view, Password view, and Client ID view
                var clientIdView = FindViewById <EditText>(Resource.Id.clientIdEditText);
                var loginIdView  = FindViewById <EditText>(Resource.Id.loginIdEditText);
                var passwordView = FindViewById <EditText>(Resource.Id.passwordEditText);

                // Facade calls Concur API to Login using the user provided LoginID, Password, and ClientID
                await ClientLibraryFacade.LoginAsync(loginIdView.Text, passwordView.Text, clientIdView.Text);

                // Facade calls Concur API to get the expense configuration needed by this use in order to create expense reports.
                ExpenseGroupConfiguration defaultGroupConfig = await ClientLibraryFacade.GetGroupConfigurationAsync();

                // Determine which expense policy is the default one.
                Policy defaultExpensePolicy = null;
                foreach (Policy policy in defaultGroupConfig.Policies)
                {
                    if (policy.IsDefault == true)
                    {
                        defaultExpensePolicy = policy;
                    }
                }

                // Determine, out of the expense configuration object, the allowed Expense Types and allowed Payment Types for this user
                expenseTypes = defaultExpensePolicy.ExpenseTypes;
                paymentTypes = defaultGroupConfig.PaymentTypes;
                var expenseTypeNames = new List <string>(); foreach (var type in expenseTypes)
                {
                    expenseTypeNames.Add(type.Name);
                }
                var paymentTypeNames = new List <string>(); foreach (var type in paymentTypes)
                {
                    paymentTypeNames.Add(type.Name);
                }

                // Populate the appropriate UI views for Payment Types and Expense Types
                PopulateSpinner(expenseTypeNames, Resource.Id.expenseTypeSpinner);
                PopulateSpinner(paymentTypeNames, Resource.Id.paymentTypeSpinner);
            }
            catch (Exception except)
            {
                DisplayException(except);
            }
        }
Example #4
0
        /// <summary>
        /// Process Create Report asynchronously
        /// </summary>
        protected async void CreateReportAsync()
        {
            try
            {
                // Clear status
                TextView statusView = FindViewById <TextView>(Resource.Id.statusTextView);
                statusView.Text = "";

                // Get the object for each view.
                var reportNameView  = FindViewById <EditText>(Resource.Id.reportNameEditText);
                var vendorView      = FindViewById <EditText>(Resource.Id.vendorEditText);
                var amountView      = FindViewById <EditText>(Resource.Id.amountEditText);
                var currencyView    = FindViewById <EditText>(Resource.Id.currencyEditText);
                var dateView        = FindViewById <EditText>(Resource.Id.dateEditText);
                var expenseTypeView = FindViewById <Spinner>(Resource.Id.expenseTypeSpinner);
                var paymentTypeView = FindViewById <Spinner>(Resource.Id.paymentTypeSpinner);

                // Verify if both Expense Type and Payment Type were selected.
                string selectedExpenseTypeName = (expenseTypeView.SelectedItem ?? "").ToString();
                string selectedPaymentTypeName = (paymentTypeView.SelectedItem ?? "").ToString();
                if (String.IsNullOrEmpty(selectedExpenseTypeName) || String.IsNullOrEmpty(selectedPaymentTypeName))
                {
                    throw new Exception("You forgot to select either an EXPENSE TYPE or a PAYMENT TYPE !!!");
                }

                // Determine the selected Expense Type code and the selected Payment Type ID
                string expenseTypeCode = Array.Find <ExpenseType>(expenseTypes, x => x.Name.Equals(selectedExpenseTypeName)).Code;
                string paymentTypeId   = Array.Find <PaymentType>(paymentTypes, x => x.Name.Equals(selectedPaymentTypeName)).ID;

                // The Facade calls Concur APIs to create an expense report, with an expense entry and an expense image.
                string reportId = await ClientLibraryFacade.CreateReportWithImageAsync(
                    reportNameView.Text,
                    vendorView.Text,
                    decimal.Parse(amountView.Text),
                    currencyView.Text,
                    expenseTypeCode,
                    DateTime.Parse(dateView.Text),
                    paymentTypeId,
                    expenseImageBytes,
                    Concur.Util.ReceiptFileType.Jpeg);

                // Set ReportID in the status
                statusView.Text = "Success!!!  Report ID: " + reportId;
            }
            catch (Exception except)
            {
                DisplayException(except);
            }
        }
Example #5
0
        /// <summary>
        /// Asynchronous handler activated when the user clicks the Create Report button.
        /// </summary>
        private async void CreateReportAsync()
        {
            try
            {
                string          filePath         = ExpenseEntryFileImagePathTextBox.Text;
                ReceiptFileType fileType         = ReceiptFileType.Jpeg;
                byte[]          expenseImageData = null;

                //Read the byte array out of the selected image file, and figure out which image type it is.
                if (!string.IsNullOrWhiteSpace(filePath))
                {
                    expenseImageData = System.IO.File.ReadAllBytes(filePath);
                    string fileTypeString = Path.GetExtension(filePath);
                    if (fileTypeString.StartsWith("."))
                    {
                        fileTypeString = fileTypeString.Substring(1);
                    }
                    if (fileTypeString.ToUpper() == "JPG")
                    {
                        fileTypeString = "JPEG";
                    }
                    Enum.TryParse <ReceiptFileType>(fileTypeString, true, out fileType);
                }

                this.Cursor = Cursors.WaitCursor;

                //Create a report, with one expense entry, and with one receipt image attached to the entry.
                string reportId = await ClientLibraryFacade.CreateReportWithImageAsync(
                    ReportNameBox.Text,
                    VendorDescriptionTextBox.Text,
                    Convert.ToDecimal(TransactionAmountTextBox.Text),
                    TransactionCurrencyTextBox.Text,
                    ((ExpenseType)(ExpenseTypeComboBox.SelectedItem)).Code,
                    Convert.ToDateTime(TransactionDateTextBox.Text),
                    ((PaymentType)(PaymentTypeComboBox.SelectedItem)).ID,
                    expenseImageData,
                    fileType);

                MessageBox.Show("Success creating report!!" + Environment.NewLine + "ReportID: " + reportId);
            }
            catch (Exception except)
            {
                DisplayException(except);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
        /// <summary>
        /// Asynchronous processing of the login button click.
        /// </summary>
        async void LoginButton_TouchUpInsideAsync()
        {
            try
            {
                // Clear the last displayed status.
                StatusLabel.Text = "";

                // The facade calls Concur API to login using the ClientID, LoginID, and Password entered by the user in the UI.
                await ClientLibraryFacade.LoginAsync(
                    LoginIdTextField.Text,
                    PasswordTextField.Text,
                    ClientIdTextField.Text);

                // The facade calls Concur API to get the configuration this user should use when creating expense reports.
                // Then get the list of allowed Payment Types and allowed Expense Types for this user for creating expense reports.
                var groupConfig = await ClientLibraryFacade.GetGroupConfigurationAsync();

                PaymentTypes = groupConfig.PaymentTypes;
                ExpenseTypes = groupConfig.Policies.First(p => p.IsDefault.Value == true).ExpenseTypes;

                // Display the Payment Types and the Expense Types
                (ExpenseTypePicker.Model as MyPickerModel).MyItems = ExpenseTypes.Select(t => t.Name).ToList();
                (PaymentTypePicker.Model as MyPickerModel).MyItems = PaymentTypes.Select(t => t.Name).ToList();

                // Refresh controls used for displaying and selecting Payment Type and Expense Type.
                ExpenseTypePicker.ReloadAllComponents();
                PaymentTypePicker.ReloadAllComponents();
                SetButtonTitleAsPickerSelection(ExpenseTypeExpandButton, ExpenseTypePicker);
                SetButtonTitleAsPickerSelection(PaymentTypeExpandButton, PaymentTypePicker);

                CreateReportButton.Enabled = true;
            }
            catch (Exception e)
            {
                DisplayException(e);
            }
        }