Ejemplo n.º 1
0
 /// <summary>Create a new Transaction object.</summary>
 public ITransaction NewTransaction()
 {
     XmlTransaction transaction = new XmlTransaction();
     transaction.Provider = this;
     transaction.Id = this.nextTransactionId++;
     this.transactions.Add( transaction.Id, transaction );
     return transaction;
 }
Ejemplo n.º 2
0
        public static XmlTransaction Deserialize( XmlReader xmlReader, Version version )
        {
            if( xmlReader.NodeType != XmlNodeType.Element
                || xmlReader.Name != ElementName )
                throw new ApplicationException( "Needs a Transaction node to deserialize an transaction object." );

            XmlTransaction trans = new XmlTransaction();

            if( xmlReader.GetAttribute( "id" ) != null )
                trans.Id = Int32.Parse( xmlReader.GetAttribute( "id" ) );

            string generatedAttribute = xmlReader.GetAttribute( "auto" );
            string voidAttribute = xmlReader.GetAttribute( "void" );

            // What's the best way to do a case-insensitive string compare?
            // Options:
            // x.Equals( y, StringComparison.OrdinalIgnoreCase)
            // x.ToLower() == y.ToLower()
            // string.Compare( x, y, true );
            // string.Compare( x, y, StringComparison.OrdinalIgnoreCase );

            if( string.Compare( voidAttribute, "true", StringComparison.OrdinalIgnoreCase ) == 0 )
                trans.IsVoided = true;
            if( string.Compare( generatedAttribute, "true", StringComparison.OrdinalIgnoreCase ) == 0 )
                trans.IsGenerated = true;

            while( xmlReader.Read() )
            {
                switch( xmlReader.NodeType )
                {
                    case XmlNodeType.Element:
                        switch( xmlReader.Name )
                        {
                            case "date":
                                trans.TransactionDate = DateTime.Parse( xmlReader.ReadString() );
                                break;
                            case "amount":
                                if( xmlReader.GetAttribute( "estimate" ) == "true" )
                                    trans.IsEstimated = true;
                                trans.Amount = Decimal.Parse( xmlReader.ReadString() );
                                break;
                            case "payee":
                                trans.Payee = xmlReader.ReadString();
                                break;
                            case "memo":
                                trans.Memo = xmlReader.ReadString();
                                break;
                            case "credit":
                            case "debit":
                                XmlLineItem item = XmlLineItem.Deserialize( xmlReader, version, trans );
                                item.SetTransaction( trans );
                                trans.AddLineItem( item );
                                break;
                            default:
                                break;
                        }
                        break;

                    case XmlNodeType.EndElement:
                        if( xmlReader.Name == ElementName ) goto exitloop;
                        break;
                }
            }

            exitloop:
            return trans;
        }