/// <summary>
        /// This facade method shows how to use the SDK to:
        /// * Create an expense report
        /// * Create an expense entry in the report
        /// * Create/attach an image to the expense entry
        /// </summary>
        /// <param name="reportName">Name chosen for the report. E.g. "Concur DevCon Expenses".</param>
        /// <param name="vendorDescription">Name/Description of the expense entry vendor. E.g. "Starbucks".</param>
        /// <param name="transactionAmount">Transaction amount for the expense entry. E.g. "12.44". </param>
        /// <param name="transactionCurrencyCode">Transaction currency code for the expense entry. E.g. "USD". </param>
        /// <param name="expenseTypeCode">Expense type code for the expense entry. The list of possible codes is obtained from the ExpenseGroupConfiguration object. E.g. "BRKFT". </param>
        /// <param name="transactionDate">Transaction date for the expense entry.</param>
        /// <param name="paymentTypeId">Payment type ID for the expense entry. The list of possible IDs is obtained from the ExpenseGroupConfiguration object, e.g. "nF0xyzYB6fmn2rKfJN8JMXbeF2QA". </param>
        /// <param name="expenseImageData">Byte array containing the expense receipt image data. This is usually obtained by reading the contents of an image file.</param>
        /// <param name="imageType">Type of the image whose bytes were provided by the above parameter.</param>
        /// <returns>The ID of the created report</returns>
        public static async Task <string> CreateReportWithImageAsync(
            string reportName,
            string vendorDescription,
            decimal?transactionAmount,
            string transactionCurrencyCode,
            string expenseTypeCode,
            DateTime?transactionDate,
            string paymentTypeId,
            byte[] expenseImageData,
            ReceiptFileType imageType)
        {
            var report = await serviceV3.CreateExpenseReportsAsync(new ReportPost { Name = reportName });

            var reportEntry = await serviceV3.CreateExpenseEntriesAsync(new EntryPost()
            {
                VendorDescription       = vendorDescription,
                TransactionAmount       = transactionAmount,
                TransactionCurrencyCode = transactionCurrencyCode,         //e/g "USD",
                ExpenseTypeCode         = expenseTypeCode,                 //e.g. "BRKFT", "BUSML",
                TransactionDate         = transactionDate,
                PaymentTypeID           = paymentTypeId,                   //e.g. "nF0xyzYB6fmn2rKfJN8JMXbeF2QA"
                ReportID = report.ID
            });

            if (expenseImageData != null)
            {
                await serviceV1.CreateExpenseEntryReceiptImagesAsync(expenseImageData, imageType, reportEntry.ID);
            }
            return(report.ID);
        }
Ejemplo n.º 2
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;
            }
        }