Exemplo n.º 1
0
        /// <summary>
        /// Handles the Click event of the lbDownload control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbDownload_Click(object sender, EventArgs e)
        {
            var parameters = RockPage.PageParameters();

            var records = GLRecordsForBatch(_batch, dpDate.SelectedDate.Value, tbAccountingPeriod.Text.Trim(), tbJournalType.Text.Trim());

            if (!UserCanEdit)
            {
                return;
            }

            //
            // Update the batch to reflect that it has been exported.
            //
            using (var rockContext = new RockContext())
            {
                FinancialBatch batch = new FinancialBatchService(rockContext).Get(_batch.Id);

                batch.LoadAttributes();
                batch.SetAttributeValue("GLExported", "true");
                batch.SaveAttributeValues(rockContext);
                IsExported = 1;

                rockContext.SaveChanges();
            }

            //
            // Send the results as a CSV file for download.
            //
            Page.EnableViewState = false;
            Page.Response.Clear();
            Page.Response.ContentType = "text/plain";
            Page.Response.AppendHeader("Content-Disposition", "attachment; filename=GLTRN2000.txt");
            Page.Response.Write(string.Join("\r\n", records.Select(r => r.ToString()).ToArray()));
            Page.Response.Flush();
            Page.Response.End();
        }