コード例 #1
0
        public static DataSet GetRecipientGiftStatementDataSet(Dictionary <String, TVariant> AParameters)
        {
            string ReportType = AParameters["param_report_type"].ToString();

            FDbAdapter = new TReportingDbAdapter(false);
            TLogging.SetStatusBarProcedure(WriteToStatusBar);
            DataSet ReturnDataSet = new DataSet();

            // get recipients
            DataTable Recipients = TFinanceReportingWebConnector.RecipientGiftStatementRecipientTable(AParameters, FDbAdapter);

            if (FDbAdapter.IsCancelled || (Recipients == null))
            {
                return(null);
            }

            DataTable RecipientTotals = new DataTable("RecipientTotals");

            RecipientTotals.Columns.Add("PreviousYearTotal", typeof(decimal));
            RecipientTotals.Columns.Add("CurrentYearTotal", typeof(decimal));
            DataTable Donors = new DataTable("Donors");

            foreach (DataRow Row in Recipients.Rows)
            {
                if (ReportType == "Complete")
                {
                    // get year totals for recipient
                    RecipientTotals.Merge(TFinanceReportingWebConnector.RecipientGiftStatementTotalsTable(AParameters, (Int64)Row["RecipientKey"],
                                                                                                          FDbAdapter));
                }

                // get donor information for each recipient
                Donors.Merge(TFinanceReportingWebConnector.RecipientGiftStatementDonorTable(AParameters, (Int64)Row["RecipientKey"], FDbAdapter));

                if (FDbAdapter.IsCancelled)
                {
                    return(null);
                }
            }

            DataView  View           = new DataView(Donors);
            DataTable DistinctDonors = new DataTable();

            if (View.Count > 0)
            {
                DistinctDonors = View.ToTable(true, "DonorKey");
            }

            DataTable DonorAddresses = new DataTable("DonorAddresses");

            if ((ReportType == "Complete") || (ReportType == "Donors Only"))
            {
                foreach (DataRow Row in DistinctDonors.Rows)
                {
                    // get best address for each distinct donor
                    DonorAddresses.Merge(TFinanceReportingWebConnector.RecipientGiftStatementDonorAddressesTable(Convert.ToInt64(Row["DonorKey"]),
                                                                                                                 FDbAdapter));

                    if (FDbAdapter.IsCancelled)
                    {
                        return(null);
                    }
                }
            }
            else
            {
                DonorAddresses.Merge(DistinctDonors);
            }

            // We only want distinct donors for this report (i.e. no more than one per recipient)
            if (ReportType == "Donors Only")
            {
                if (View.Count > 0)
                {
                    DistinctDonors = View.ToTable(true, "DonorKey", "DonorName", "RecipientKey");
                    Donors.Clear();
                    Donors.Merge(DistinctDonors);
                }
                else // I should return an empty table with just columns, to keep the client happy:
                {
                    DistinctDonors = new DataTable();
                    DistinctDonors.Columns.Add("DonorKey", typeof(Int64));
                    DistinctDonors.Columns.Add("DonorName", typeof(String));
                    DistinctDonors.Columns.Add("RecipientKey", typeof(Int64));
                }
            }

            ReturnDataSet.Tables.Add(Recipients);
            ReturnDataSet.Tables.Add(RecipientTotals);
            ReturnDataSet.Tables.Add(Donors);
            ReturnDataSet.Tables.Add(DonorAddresses);

            return((FDbAdapter.IsCancelled) ? null : ReturnDataSet);
        }