/// <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);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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;
            }
        }