Example #1
0
        public IList <Sidi.Sammy.Payment> GetPayments()
        {
            var session = new DkbSession(User, Password);

            session.Login();
            try
            {
                var t        = (IHTMLElement)session.GetSearchResultTable();
                var accounts = t.ParseTable();
                accounts = accounts.Take(accounts.Length - 1).ToArray();
                if (log.IsDebugEnabled)
                {
                    log.Debug(accounts.Dump());
                }

                var payments = new List <Sidi.Sammy.Payment>();

                int accountIndex = 0;
                foreach (var a in accounts)
                {
                    var url = String.Format("https://banking.dkb.de/dkb/-?$part=DkbTransactionBanking.content.banking.FinancialStatus.FinancialStatus&$event=paymentTransaction&table=cashTable&row={0}", accountIndex);
                    session.Navigate(url);
                    var transactions = session.GetSearchResultTable();

                    var transactionUrls = transactions.GetAllChildren()
                                          .Where(img => img.tagName.Equals("IMG", StringComparison.InvariantCultureIgnoreCase) && img.GetAttribute("alt").Equals("Details"))
                                          .Select(img => img.parentElement.GetAttribute("href"))
                                          .ToList();

                    log.Debug(transactionUrls.Join());

                    foreach (var transactionUrl in transactionUrls)
                    {
                        session.Navigate(transactionUrl);

                        var detailsTable = session.GetWhiteTable().ParseTable();
                        if (log.IsDebugEnabled)
                        {
                            log.Debug(detailsTable.Dump());
                        }
                        var details = new Dictionary <string, string>();
                        foreach (var i in detailsTable)
                        {
                            details[i[0].Trim()] = i[1].Trim();
                        }
                        if (log.IsDebugEnabled)
                        {
                            foreach (var i in details)
                            {
                                log.InfoFormat("{0}={1}", i.Key.Quote(), i.Value.Quote());
                            }
                        }

                        var p = new Payment();
                        p.OwnAcctNo   = a[0];
                        p.OwnName     = a[1];
                        p.OwnBankCode = "12030000";

                        var dateString = GetValue(details, "Buchungstag:", "Belegdatum:");
                        if (!String.IsNullOrEmpty(dateString))
                        {
                            p.EntryDate = DateTime.Parse(dateString, culture);
                        }

                        p.ValueDate = DateTime.Parse(details["Wertstellung:"], culture);
                        ParseValue(details["Betrag:"], out p.Value, out p.Currency);
                        details.TryGetValue("Auftraggeber/Begünstigter:", out p.Name);

                        if (details.ContainsKey(AcctNoKey))
                        {
                            var parts = Regex.Split(details[AcctNoKey], @"\s*/\s*");
                            p.AcctNo   = parts[0];
                            p.BankCode = parts[1];
                        }

                        p.EntryText = GetValue(details, "Buchungstext:");

                        p.Purpose = GetValue(details, "Verwendungszweck:", "Umsatzbeschreibung:");

                        payments.Add(p);
                    }
                    ++accountIndex;
                }

                return(payments);
            }
            finally
            {
                session.Logout();
            }
        }
Example #2
0
File: Dkb.cs Project: al-main/sammy
        public IList<Sidi.Sammy.Payment> GetPayments()
        {
            var session = new DkbSession(User, Password);
            session.Login();
            try
            {
                var t = (IHTMLElement) session.GetSearchResultTable();
                var accounts = t.ParseTable();
                accounts = accounts.Take(accounts.Length - 1).ToArray();
                if (log.IsDebugEnabled) log.Debug(accounts.Dump());

                var payments = new List<Sidi.Sammy.Payment>();

                int accountIndex = 0;
                foreach (var a in accounts)
                {
                    var url = String.Format("https://banking.dkb.de/dkb/-?$part=DkbTransactionBanking.content.banking.FinancialStatus.FinancialStatus&$event=paymentTransaction&table=cashTable&row={0}", accountIndex);
                    session.Navigate(url);
                    var transactions = session.GetSearchResultTable();

                    var transactionUrls = transactions.GetAllChildren()
                        .Where(img => img.tagName.Equals("IMG", StringComparison.InvariantCultureIgnoreCase) && img.GetAttribute("alt").Equals("Details"))
                        .Select(img => img.parentElement.GetAttribute("href"))
                        .ToList();

                    log.Debug(transactionUrls.Join());

                    foreach (var transactionUrl in transactionUrls)
                    {
                        session.Navigate(transactionUrl);

                        var detailsTable = session.GetWhiteTable().ParseTable();
                        if (log.IsDebugEnabled) log.Debug(detailsTable.Dump());
                        var details = new Dictionary<string, string>();
                        foreach (var i in detailsTable)
                        {
                            details[i[0].Trim()] = i[1].Trim();
                        }
                        if (log.IsDebugEnabled)
                        {
                            foreach (var i in details)
                            {
                                log.InfoFormat("{0}={1}", i.Key.Quote(), i.Value.Quote());
                            }
                        }

                        var p = new Payment();
                        p.OwnAcctNo = a[0];
                        p.OwnName = a[1];
                        p.OwnBankCode = "12030000";

                        var dateString = GetValue(details, "Buchungstag:", "Belegdatum:");
                        if (!String.IsNullOrEmpty(dateString))
                        {
                            p.EntryDate = DateTime.Parse(dateString, culture);
                        }

                        p.ValueDate = DateTime.Parse(details["Wertstellung:"], culture);
                        ParseValue(details["Betrag:"], out p.Value, out p.Currency);
                        details.TryGetValue("Auftraggeber/Begünstigter:", out p.Name);

                        if (details.ContainsKey(AcctNoKey))
                        {
                            var parts = Regex.Split(details[AcctNoKey], @"\s*/\s*");
                            p.AcctNo = parts[0];
                            p.BankCode = parts[1];
                        }

                        p.EntryText = GetValue(details, "Buchungstext:");

                        p.Purpose = GetValue(details, "Verwendungszweck:", "Umsatzbeschreibung:");

                        payments.Add(p);
                    }
                    ++accountIndex;
                }

                return payments;
            }
            finally
            {
                session.Logout();
            }
        }