示例#1
0
        /// <summary>
        /// Returns list of all transactions in OFX document
        /// </summary>
        /// <param name="doc">OFX document</param>
        /// <returns>List of transactions found in OFX document</returns>
        private void ImportTransations(OFXDocument ofxDocument, XmlDocument doc)
        {
            var xpath = GetXPath(ofxDocument.AccType, OFXSection.TRANSACTIONS);

            //ofxDocument.StatementStart = doc.GetValue(xpath + "//DTSTART").ToDate();
            //ofxDocument.StatementEnd = doc.GetValue(xpath + "//DTEND").ToDate();

            var transactionNodes = doc.SelectNodes(xpath + "//STMTTRN");

            ofxDocument.Transactions = new List<Transaction>();

            foreach (XmlNode node in transactionNodes)
                ofxDocument.Transactions.Add(new Transaction(node, ofxDocument.Currency));
        }
示例#2
0
        /// <summary>
        /// Returns list of all transactions in OFX document
        /// </summary>
        /// <param name="doc">OFX document</param>
        /// <returns>List of transactions found in OFX document</returns>
        public override void ImportTransactions(OFXDocumentParser parser, OFXDocument ofx, XmlDocument doc)
        {
            XmlNodeList transactionNodes = null;
            var         xpath            = parser.GetXPath(AccountType, OFXDocumentParser.OFXSection.TRANSACTIONS);

            ofx.StatementStart = doc.GetValue(xpath + "//DTSTART").ToDate();
            ofx.StatementEnd   = doc.GetValue(xpath + "//DTEND").ToDate();

            transactionNodes = doc.SelectNodes(xpath + "//STMTTRN");

            foreach (XmlNode node in transactionNodes)
            {
                Transactions.Add(new BankTransaction(node, ofx.Currency));
            }
        }
示例#3
0
        public void ImportPositions(string xpath, OFXDocument ofx, XmlDocument doc)
        {
            XmlNodeList positionNodes = null;

            Positions = new List <Position>();

            //Import Position Transactions
            positionNodes = doc.SelectNodes(xpath + "//POSSTOCK");
            foreach (XmlNode node in positionNodes)
            {
                Positions.Add(new Position(node));
            }
            positionNodes = doc.SelectNodes(xpath + "//POSOTHER");
            foreach (XmlNode node in positionNodes)
            {
                Positions.Add(new Position(node));
            }
            positionNodes = doc.SelectNodes(xpath + "//POSMF");
            foreach (XmlNode node in positionNodes)
            {
                Positions.Add(new Position(node));
            }
        }
示例#4
0
        private OFXDocument Parse(string ofxString)
        {
            var ofx = new OFXDocument {
                AccType = GetAccountType(ofxString)
            };

            //Load into xml document
            var doc = new XmlDocument();

            doc.Load(new StringReader(ofxString));

            var currencyNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.CURRENCY));

            if (currencyNode != null)
            {
                ofx.Currency = currencyNode.FirstChild.Value;
            }
            else
            {
                throw new OFXParseException("Currency not found");
            }

            //Get sign on node from OFX file
            var signOnNode = doc.SelectSingleNode(Resources.SignOn);

            //If exists, populate signon obj, else throw parse error
            if (signOnNode != null)
            {
                ofx.SignOn = new SignOn(signOnNode);
            }
            else
            {
                throw new OFXParseException("Sign On information not found");
            }

            //Get Account information for ofx doc
            var accountNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.ACCOUNTINFO));

            //If account info present, populate account object
            if (accountNode != null)
            {
                ofx.Account = new Account(accountNode, ofx.AccType);
            }
            else
            {
                throw new OFXParseException("Account information not found");
            }

            //Get list of transactions
            ImportTransations(ofx, doc);

            //Get balance info from ofx doc
            var ledgerNode    = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.BALANCE) + "/LEDGERBAL");
            var avaliableNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.BALANCE) + "/AVAILBAL");

            //If balance info present, populate balance object
            // ***** OFX files from my bank don't have the 'avaliableNode' node, so i manage a 'null' situation
            if (ledgerNode != null) // && avaliableNode != null
            {
                ofx.Balance = new Balance(ledgerNode, avaliableNode);
            }
            else
            {
                throw new OFXParseException("Balance information not found");
            }

            return(ofx);
        }
示例#5
0
 public override void ImportTransactions(OFXDocumentParser parser, OFXDocument ofx, XmlDocument doc)
 {
 }
示例#6
0
 public abstract void ImportTransactions(OFXDocumentParser parser, OFXDocument ofx, XmlDocument doc);
示例#7
0
        /// <summary>
        /// Returns list of all transactions in OFX document
        /// </summary>
        /// <param name="doc">OFX document</param>
        /// <returns>List of transactions found in OFX document</returns>
        public override void ImportTransactions(OFXDocumentParser parser, OFXDocument ofx, XmlDocument doc)
        {
            XmlNodeList transactionNodes = null;
            var         xpath            = parser.GetXPath(ofx.AccType, OFXDocumentParser.OFXSection.TRANSACTIONS);

            ofx.StatementStart = doc.GetValue(xpath + "//DTSTART").ToDate();
            ofx.StatementEnd   = doc.GetValue(xpath + "//DTEND").ToDate();

            //Import Income Transactions
            transactionNodes = doc.SelectNodes(xpath + "//INCOME");
            foreach (XmlNode node in transactionNodes)
            {
                Transactions.Add(new IncomeTransaction(node, ofx.Currency));
            }

            //Import Cash Transfer Transactions
            transactionNodes = doc.SelectNodes(xpath + "//INVBANKTRAN");
            foreach (XmlNode node in transactionNodes)
            {
                Transactions.Add(new InvestmentTransferTransaction(node, ofx.Currency));
            }

            //Import Stock Transfer Transactions
            transactionNodes = doc.SelectNodes(xpath + "//TRANSFER");
            foreach (XmlNode node in transactionNodes)
            {
                Transactions.Add(new StockTransferTransaction(node, ofx.Currency));
            }

            //Import Buy Stock Transactions
            transactionNodes = doc.SelectNodes(xpath + "//BUYSTOCK");
            foreach (XmlNode node in transactionNodes)
            {
                Transactions.Add(new BuySellStockTransaction(node, ofx.Currency));
            }

            //Import Buy Option Transactions
            transactionNodes = doc.SelectNodes(xpath + "//BUYOPT");
            foreach (XmlNode node in transactionNodes)
            {
                Transactions.Add(new BuySellStockOptionTransaction(node, ofx.Currency));
            }

            //Import Sell Stock Transactions
            transactionNodes = doc.SelectNodes(xpath + "//SELLSTOCK");
            foreach (XmlNode node in transactionNodes)
            {
                Transactions.Add(new BuySellStockTransaction(node, ofx.Currency));
            }

            //Import Buy Option Transactions
            transactionNodes = doc.SelectNodes(xpath + "//SELLOPT");
            foreach (XmlNode node in transactionNodes)
            {
                Transactions.Add(new BuySellStockOptionTransaction(node, ofx.Currency));
            }

            //Import Sell Other Stock Transactions
            transactionNodes = doc.SelectNodes(xpath + "//SELLOTHER");
            foreach (XmlNode node in transactionNodes)
            {
                Transactions.Add(new BuySellStockTransaction(node, ofx.Currency));
            }
        }
示例#8
0
        private OFXDocument Parse(string ofxString)
        {
            var ofx = new OFXDocument {AccType = GetAccountType(ofxString)};

             //Load into xml document
             var doc = new XmlDocument();
             doc.Load(new StringReader(ofxString));

             var currencyNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.CURRENCY));

             if (currencyNode != null)
             {
            ofx.Currency = currencyNode.FirstChild.Value;
             }
             else
             {
            throw new OFXParseException("Currency not found");
             }

             //Get sign on node from OFX file
             var signOnNode = doc.SelectSingleNode(Resources.SignOn);

             //If exists, populate signon obj, else throw parse error
             if (signOnNode != null)
             {
            ofx.SignOn = new SignOn(signOnNode);
             }
             else
             {
            throw new OFXParseException("Sign On information not found");
             }

             //Get Account information for ofx doc
             var accountNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.ACCOUNTINFO));

             //If account info present, populate account object
             if (accountNode != null)
             {
            ofx.Account = new Account(accountNode, ofx.AccType);
             }
             else
             {
            throw new OFXParseException("Account information not found");
             }

             //Get list of transactions
             ImportTransations(ofx, doc);

             //Get balance info from ofx doc
             var ledgerNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.BALANCE) + "/LEDGERBAL");
             var avaliableNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.BALANCE) + "/AVAILBAL");

             //If balance info present, populate balance object
             // ***** OFX files from my bank don't have the 'avaliableNode' node, so i manage a 'null' situation
             if (ledgerNode != null) // && avaliableNode != null
             {
            ofx.Balance = new Balance(ledgerNode, avaliableNode);
             }
             else
             {
            throw new OFXParseException("Balance information not found");
             }

             return ofx;
        }
示例#9
0
        /// <summary>
        /// Returns list of all transactions in OFX document
        /// </summary>
        /// <param name="doc">OFX document</param>
        /// <returns>List of transactions found in OFX document</returns>
        private void ImportTransations(OFXDocument ofxDocument, XmlDocument doc)
        {
            var xpath = GetXPath(ofxDocument.AccType, OFXSection.TRANSACTIONS);

             ofxDocument.StatementStart = doc.GetValue(xpath + "/DTSTART").ToDate();
             ofxDocument.StatementEnd = doc.GetValue(xpath + "/DTEND").ToDate();

             var transactionNodes = doc.SelectNodes(xpath + "/STMTTRN");

             ofxDocument.Transactions = new List<Transaction>();

             foreach (XmlNode node in transactionNodes)
            ofxDocument.Transactions.Add(new Transaction(node, ofxDocument.Currency));
        }
示例#10
0
文件: FrmMain.cs 项目: GregXP/XP
        //private void FillAccountInfo()
        //{
        //    if (ofxDoc != null)
        //    {
        //        AddAccountInfo("ID Banco", ofxDoc.OFXAccount.BankID);
        //        AddAccountInfo("Nome Banco", ofxDoc.OFXSignOn.Organism);
        //        AddAccountInfo("Num Agência", ofxDoc.OFXAccount.BranchID);
        //        AddAccountInfo("Num Conta", ofxDoc.OFXAccount.AccountID);
        //        AddAccountInfo("Tipo Conta", ofxDoc.OFXAccount.OFXAccountType.ToString());
        //        AddAccountInfo("Tipo Conta banco", ofxDoc.OFXAccount.BankAccountType.ToString());
        //        AddAccountInfo("Saldo", ofxDoc.OFXBalance.LedgerBalance.ToString());
        //        AddAccountInfo("Data Saldo", ofxDoc.OFXBalance.LedgerBalanceDate.ToShortDateString());
        //        AddAccountInfo("Moeda", ofxDoc.Currency);
        //    }
        //}
        //private void AddAccountInfo(String nome, String valor)
        //{
        //    ListViewItem item = _lstAccount.Items.Add(nome);
        //    item.SubItems.Add(valor);
        //}
        //private void FillTransactionsInfo()
        //{
        //    if (ofxDoc != null)
        //    {
        //        foreach (OFXTransaction ofxtrans in ofxDoc.OFXTransactions)
        //        {
        //            AddTransactionInfo(ofxtrans);
        //        }
        //    }
        //}
        //private void AddTransactionInfo(OFXTransaction ofxtrans)
        //{
        //    String ID = ofxDoc.OFXAccount.AccountID;
        //    if (ofxtrans.OFXTransactionSenderAccount != null)
        //    {
        //        ID = ofxtrans.OFXTransactionSenderAccount.AccountID;
        //    }
        //    ListViewItem item = _lstTransactions.Items.Add(ID);
        //    item.SubItems.Add(ofxtrans.Date.ToShortDateString());
        //    item.SubItems.Add(ofxtrans.Amount.ToString());
        //    item.SubItems.Add(ofxtrans.TransactionID);
        //    item.SubItems.Add(ofxtrans.Memo);
        //    item.SubItems.Add(ofxtrans.CheckNum);
        //    item.SubItems.Add(ofxtrans.ReferenceNumber);
        //}
        //private void _btnInsert_Click(object sender, EventArgs e)
        //{
        //    InsereBanco();
        //    InsereConta();
        //    InsereTransacoes();
        //}
        //private void InsereBanco()
        //{
        //    int id = int.Parse(ofxDoc.OFXAccount.BankID);
        //    Banco banco = Banco.Get(id);
        //    if (banco == null)
        //    {
        //        banco = new Banco { ID = id, Nome = ofxDoc.OFXSignOn.Organism };
        //        int res = banco.Insert();
        //        if (res != 1)
        //        {
        //            MessageBox.Show("Banco não inserido");
        //        }
        //    }
        //    else
        //    {
        //        MessageBox.Show("Banco já existe em base");
        //    }
        //}
        //private void InsereConta()
        //{
        //    String agencia = ofxDoc.OFXAccount.BranchID;
        //    String numConta = ofxDoc.OFXAccount.AccountID;
        //    Conta conta = Conta.Get(agencia, numConta);
        //    if (conta == null)
        //    {
        //        conta = new Conta
        //        {
        //            IDCarteira = Program.MainCarteira.ID,
        //            IDBanco = int.Parse(ofxDoc.OFXAccount.BankID),
        //            Agencia = agencia,
        //            NumConta = numConta,
        //            TipoConta = ofxDoc.OFXAccount.OFXAccountType.ToString(),
        //            TipoContaBanco = ofxDoc.OFXAccount.BankAccountType.ToString(),
        //            Saldo = ofxDoc.OFXBalance.LedgerBalance,
        //            DataSaldo = ofxDoc.OFXBalance.LedgerBalanceDate,
        //            Moeda = ofxDoc.Currency
        //        };
        //        int res = conta.Insert();
        //        if (res != 1)
        //        {
        //            MessageBox.Show("Conta não inserida");
        //        }
        //    }
        //    else
        //    {
        //        MessageBox.Show("Conta já existe em base");
        //    }
        //}
        private void InsereTransacoes(OFXDocument ofxDoc, Conta conta)
        {
            foreach (OFXTransaction ofxtrans in ofxDoc.OFXTransactions)
            {
                String id = ofxtrans.TransactionID;
                bool exists = Transacao.Exists(id);
                if (!exists)
                {
                    Transacao trans = new Transacao
                    {
                        TransID = ofxtrans.TransactionID,
                        IDConta = conta.ID,
                        Memo = ofxtrans.Memo,
                        Data = ofxtrans.Date,
                        NumCheck = ofxtrans.CheckNum,
                        RefNum = ofxtrans.ReferenceNumber,
                        Valor = ofxtrans.Amount
                    };

                    int res = trans.Insert();
                    if (res != 1)
                    {
                        MessageBox.Show("Transacao não inserida");
                    }
                }
                else
                {
                    MessageBox.Show(String.Format("Transacao {0} já existe em base", ofxtrans.TransactionID));
                }
            }
        }
示例#11
0
文件: FrmMain.cs 项目: GregXP/XP
        private Conta GetContaOFX(OFXDocument ofxDoc)
        {
            Conta retConta = null;
            if (ofxDoc != null)
            {
                foreach (Conta conta in Carteira.ListContas)
                {
                    bool ok = true;
                    ok &= (conta.IDBanco == int.Parse(ofxDoc.OFXAccount.BankID));
                    ok &= (conta.Agencia.ToString() == ofxDoc.OFXAccount.BranchID);
                    ok &= (conta.NumConta.ToString() == ofxDoc.OFXAccount.AccountID);
                    if (ok)
                    {
                        retConta = conta;
                        break;
                    }
                }
            }

            return retConta;
        }
示例#12
0
文件: FrmMain.cs 项目: GregXP/XP
        private void FillAccountInfo(OFXDocument ofxDoc)
        {
            if (ofxDoc != null)
            {
                Conta conta = GetContaOFX(ofxDoc);

                if (conta == null)
                {
                    //seleciona a conta onde as transações vão ser importadas
                    DialogResult res = MessageBox.Show("A conta definida no arquivo não existe na base, deseja cria-la ?", "Conta", MessageBoxButtons.YesNo);
                    if (res == System.Windows.Forms.DialogResult.Yes)
                    {
                        conta = new Conta()
                        {
                            IDCarteira = Program.MainCarteira.ID,
                            IDBanco = int.Parse(ofxDoc.OFXAccount.BankID),
                            Agencia = ofxDoc.OFXAccount.BranchID,
                            NumConta = ofxDoc.OFXAccount.AccountID,
                            TipoConta = ofxDoc.OFXAccount.OFXAccountType.ToString(),
                            TipoContaBanco = ofxDoc.OFXAccount.BankAccountType.ToString(),
                            Saldo = ofxDoc.OFXBalance.LedgerBalance,
                            DataSaldo = ofxDoc.OFXBalance.LedgerBalanceDate,
                            SaldoInicial = 0,
                            DataSaldoInicial = DateTime.MinValue,
                            Moeda = ofxDoc.Currency
                        };

                        int ret = FrmNovaConta.CriaNovaConta(conta);
                        if (ret != 1)
                        {
                            //MessageBox.Show("Problema ao criar a conta");
                        }
                        else
                        {
                            FillAccountInfo();

                            MessageBox.Show("Conta criada com sucesso!");
                        }

                    }
                }

                if (conta != null)
                {
                    InsereTransacoes(ofxDoc, conta);
                }
            }
        }
示例#13
0
        private OFXDocument Parse(string ofxString)
        {
            OFXDocument ofx = new OFXDocument {
                AccType = GetAccountType(ofxString)
            };
            XmlNode ledgerNode;
            XmlNode availableNode;

            //Load into xml document
            var doc = new XmlDocument();

            doc.Load(new StringReader(ofxString));

            //Get sign on node from OFX file
            var signOnNode = doc.SelectSingleNode(Resources.SignOn);

            //If exists, populate signon obj, else throw parse error
            if (signOnNode != null)
            {
                ofx.SignOn = new SignOn(signOnNode);
            }
            else
            {
                throw new OFXParseException("Sign On information not found");
            }

            XmlNode accountNodeRoot = doc.SelectSingleNode("//ACCTINFOTRNRS//ACCTINFORS");

            if (accountNodeRoot != null)
            {
                XmlNodeList accountNodes = accountNodeRoot.SelectNodes(".//ACCTINFO");
                foreach (XmlNode node in accountNodes)
                {
                    XmlNode investmentAccountNode = node.SelectSingleNode(".//INVACCTINFO");
                    XmlNode ccAccountNode         = node.SelectSingleNode(".//CCACCTINFO");
                    if (investmentAccountNode != null)
                    {
                        InvestmentAccountInfo iai = new InvestmentAccountInfo(node, investmentAccountNode);
                        ofx.AccountInfos.Add(iai);
                    }
                    else if (ccAccountNode != null)
                    {
                        CCAccountInfo ccai = new CCAccountInfo(node, ccAccountNode);
                        ofx.AccountInfos.Add(ccai);
                    }
                    else
                    {
                        AccountInfo ai = new AccountInfo(node);
                        ofx.AccountInfos.Add(ai);
                    }
                }
            }


            if (ofx.AccType == AccountType.NA)
            {
                return(ofx);
            }

            var currencyNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.CURRENCY));

            if (currencyNode != null)
            {
                ofx.Currency = currencyNode.FirstChild.Value;
            }
            else
            {
                throw new OFXParseException("Currency not found");
            }

            //Get Account information for ofx doc
            var accountNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.ACCOUNTINFO));

            //If account info present, populate account object
            if (accountNode != null)
            {
                switch (ofx.AccType)
                {
                case AccountType.BANK:
                    ofx.Account = new BankAccount(accountNode);
                    //Get list of transactions
                    ofx.Account.ImportTransactions(this, ofx, doc);

                    //Get balance info from ofx doc
                    ledgerNode    = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.BALANCE) + "/LEDGERBAL");
                    availableNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.BALANCE) + "/AVAILBAL");

                    //If balance info present, populate balance object
                    // ***** OFX files from my bank don't have the 'avaliableNode' node, so i manage a 'null' situation
                    if (ledgerNode != null)     // && avaliableNode != null
                    {
                        ofx.Balance = new BankBalance(ledgerNode, availableNode);
                    }
                    else
                    {
                        throw new OFXParseException("Balance information not found");
                    }

                    break;

                case AccountType.CC:
                    ofx.Account = new CreditCardAccount(accountNode);
                    //Get list of transactions
                    ofx.Account.ImportTransactions(this, ofx, doc);

                    //Get balance info from ofx doc
                    ledgerNode    = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.BALANCE) + "/LEDGERBAL");
                    availableNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.BALANCE) + "/AVAILBAL");

                    //If balance info present, populate balance object
                    // ***** OFX files from my bank don't have the 'avaliableNode' node, so i manage a 'null' situation
                    if (ledgerNode != null)     // && avaliableNode != null
                    {
                        ofx.Balance = new CreditCardBalance(ledgerNode, availableNode);
                    }
                    else
                    {
                        throw new OFXParseException("Balance information not found");
                    }

                    break;

                case AccountType.AP:
                    ofx.Account = new APAccount(accountNode);
                    break;

                case AccountType.AR:
                    ofx.Account = new ARAccount(accountNode);
                    break;

                case AccountType.INVESTMENT:
                    ofx.Account = new InvestmentAccount(accountNode);

                    //Get list of transactions
                    ofx.Account.ImportTransactions(this, ofx, doc);

                    //Get list of positions (requires downcast)
                    ((InvestmentAccount)ofx.Account).ImportPositions(GetXPath(ofx.AccType, OFXDocumentParser.OFXSection.POSITIONS), ofx, doc);

                    //If balance info present, populate balance object
                    var balanceNode = doc.SelectSingleNode(GetXPath(ofx.AccType, OFXSection.BALANCE));
                    if (balanceNode != null)
                    {
                        ofx.Balance = new InvestmentBalance(balanceNode);
                    }
                    else
                    {
                        throw new OFXParseException("Balance information not found");
                    }

                    //Process Stock Quote Prices, if present
                    var SECListNode = doc.SelectSingleNode(Resources.SecurityList);
                    if (SECListNode != null)
                    {
                        //Requires downcast
                        ((InvestmentAccount)ofx.Account).ImportSECList(SECListNode);
                    }
                    break;

                default:
                    throw new OFXParseException("Invalid Account type.");
                }
            }
            else
            {
                throw new OFXParseException("Account information not found");
            }

            return(ofx);
        }