コード例 #1
0
ファイル: Matching.cs プロジェクト: TheBigBear/openpetra
        /// <summary>
        /// store historic Gift matches
        /// </summary>
        private static void StoreCurrentMatches(BankImportTDS AMatchDS, string ABankAccountCode)
        {
            TLogging.LogAtLevel(1, "StoreCurrentMatches...");

            DataView GiftDetailView = new DataView(
                AMatchDS.AGiftDetail, string.Empty,
                BankImportTDSAGiftDetailTable.GetGiftTransactionNumberDBName() + "," +
                BankImportTDSAGiftDetailTable.GetDetailNumberDBName(),
                DataViewRowState.CurrentRows);

            SortedList <string, AEpMatchRow> MatchesToAddLater = new SortedList <string, AEpMatchRow>();

            // for speed reasons, use a sortedlist instead of a dataview
            SortedList <string, AEpMatchRow> MatchesByText = new SortedList <string, AEpMatchRow>();

            foreach (AEpMatchRow r in AMatchDS.AEpMatch.Rows)
            {
                MatchesByText[r.MatchText + ":::" + r.Detail.ToString()] = r;
            }

            foreach (BankImportTDSAEpTransactionRow tr in AMatchDS.AEpTransaction.Rows)
            {
                // create a match text which uniquely identifies this transaction
                string MatchText = CalculateMatchText(ABankAccountCode, tr);

                if (tr.MatchAction != MFinanceConstants.BANK_STMT_STATUS_MATCHED)
                {
                    continue;
                }

                // get the gift details assigned to this transaction
                StringCollection GiftDetailNumbers = StringHelper.GetCSVList(tr.GiftDetailNumbers, ",", false);

                foreach (string strDetailNumber in GiftDetailNumbers)
                {
                    DataRowView[] FilteredGiftDetails =
                        GiftDetailView.FindRows(
                            new object[] {
                        tr.GiftTransactionNumber,
                        Convert.ToInt32(strDetailNumber)
                    });

                    // add new matches, and modify existing matches
                    UpdateMatches(
                        AMatchDS,
                        (BankImportTDSAGiftDetailRow)FilteredGiftDetails[0].Row,
                        MatchText,
                        Convert.ToInt32(strDetailNumber) - 1,
                        MatchesByText,
                        MatchesToAddLater);
                }
            }

            // for speed reasons, add the new rows at the end
            foreach (AEpMatchRow m in MatchesToAddLater.Values)
            {
                AMatchDS.AEpMatch.Rows.Add(m);
            }

            AMatchDS.PBankingDetails.Clear();
            AMatchDS.AGiftDetail.Clear();
            AMatchDS.AGift.Clear();

            AMatchDS.ThrowAwayAfterSubmitChanges = true;

            TLogging.LogAtLevel(1, "before submitchanges");

            BankImportTDSAccess.SubmitChanges(AMatchDS);

            TLogging.LogAtLevel(1, "after submitchanges");
        }
コード例 #2
0
        /// <summary>
        /// store historic Gift matches
        /// </summary>
        private static void StoreCurrentMatches(BankImportTDS AMatchDS, string ABankAccountCode)
        {
            DataView GiftDetailView = new DataView(
                AMatchDS.AGiftDetail, string.Empty,
                BankImportTDSAGiftDetailTable.GetGiftTransactionNumberDBName() + "," +
                BankImportTDSAGiftDetailTable.GetDetailNumberDBName(),
                DataViewRowState.CurrentRows);

            SortedList <string, AEpMatchRow> MatchesToAddLater = new SortedList <string, AEpMatchRow>();
            List <string> MatchesToDelete = new List <string>();

            foreach (BankImportTDSAEpTransactionRow tr in AMatchDS.AEpTransaction.Rows)
            {
                // create a match text which uniquely identifies this transaction
                string MatchText = CalculateMatchText(ABankAccountCode, tr);

                // delete existing matches
                MatchesToDelete.Add(MatchText);

                if (tr.MatchAction != MFinanceConstants.BANK_STMT_STATUS_MATCHED)
                {
                    continue;
                }

                // get the gift details assigned to this transaction
                StringCollection GiftDetailNumbers = StringHelper.GetCSVList(tr.GiftDetailNumbers, ",", false);

                foreach (string strDetailNumber in GiftDetailNumbers)
                {
                    DataRowView[] FilteredGiftDetails =
                        GiftDetailView.FindRows(
                            new object[] {
                        tr.GiftTransactionNumber,
                        Convert.ToInt32(strDetailNumber)
                    });

                    // add new matches
                    // do not assign tr.EpMatchKey, because we cannot delete the old matches then
                    CreateNewMatches(
                        AMatchDS,
                        (BankImportTDSAGiftDetailRow)FilteredGiftDetails[0].Row,
                        MatchText,
                        MatchesToAddLater);
                }
            }

            DataView MatchesByText = new DataView(
                AMatchDS.AEpMatch, string.Empty,
                AEpMatchTable.GetMatchTextDBName(),
                DataViewRowState.CurrentRows);

            foreach (string MatchToDelete in MatchesToDelete)
            {
                DataRowView[] MatchesToDeleteRv = MatchesByText.FindRows(MatchToDelete);

                foreach (DataRowView rv in MatchesToDeleteRv)
                {
                    rv.Row.Delete();
                }
            }

            MatchesByText.Sort      = string.Empty;
            MatchesByText.RowFilter = string.Empty;

            // for speed reasons, add the new rows at the end
            foreach (AEpMatchRow m in MatchesToAddLater.Values)
            {
                AMatchDS.AEpMatch.Rows.Add(m);
            }

            AMatchDS.PBankingDetails.Clear();
            AMatchDS.AGiftDetail.Clear();
            AMatchDS.AGift.Clear();

            AMatchDS.ThrowAwayAfterSubmitChanges = true;

            if (TLogging.DebugLevel > 0)
            {
                TLogging.Log("before submitchanges");
            }

            BankImportTDSAccess.SubmitChanges(AMatchDS);

            if (TLogging.DebugLevel > 0)
            {
                TLogging.Log("after submitchanges");
            }
        }