本文整理汇总了C#中Transaction.Validate方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.Validate方法的具体用法?C# Transaction.Validate怎么用?C# Transaction.Validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction.Validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeTransaction
/// <summary>
/// Serialize a Transaction object to an XML writer.
/// </summary>
/// <param name="xmlWriter">XmlWriter to serialize to.</param>
public void SerializeTransaction( XmlWriter xmlWriter, Transaction trans )
{
xmlWriter.WriteStartElement( "Transaction" );
// Write attributes
xmlWriter.WriteAttributeString( "Id", trans.Id.ToString() );
if( ( trans.Flags & TransactionFlags.Recurring ) != 0 )
{
xmlWriter.WriteAttributeString( "Recurring", "true" );
}
if( ( trans.Flags & TransactionFlags.Pending ) != 0 )
{
xmlWriter.WriteAttributeString( "Pending", "true" );
}
if( ( trans.Flags & TransactionFlags.Void ) != 0 )
{
xmlWriter.WriteAttributeString( "Void", "true" );
}
xmlWriter.WriteWhitespace( Environment.NewLine );
trans.Validate();
SerializeTransactionBody( xmlWriter, trans );
xmlWriter.WriteEndElement(); // </Transaction>
}
示例2: Merge
/// <summary>
/// Merges the transactions from another ledger into this ledger.
/// </summary>
/// <param name="newLedger">Ledger to merge transactions from.</param>
public void Merge( Ledger newLedger )
{
foreach( Transaction trans in newLedger.Transactions )
{
Transaction newTrans = new Transaction();
newTrans.Id = GetNextTransactionId();
newTrans.Date = trans.Date;
newTrans.Amount = trans.Amount;
newTrans.Description = trans.Description;
newTrans.Memo = trans.Memo;
newTrans.Flags = trans.Flags;
foreach( LineItem lineItem in trans.LineItems )
{
LineItem newLineItem = new LineItem();
newLineItem.TransactionType = lineItem.TransactionType;
newLineItem.Amount = lineItem.Amount;
newLineItem.Memo = lineItem.Memo;
newLineItem.Number = lineItem.Number;
newLineItem.Account = GetAccount( lineItem.Account.AccountType, lineItem.Account.Name );
if( lineItem.CategoryObject != null )
newLineItem.CategoryObject = newLineItem.Account.GetCategory( lineItem.CategoryObject.Name );
newTrans.LineItems.Add( newLineItem );
}
newTrans.Validate();
AddTransaction( newTrans );
}
}
示例3: LoadTransaction
//.........这里部分代码省略.........
lineItemMemo = line.Substring( 1 );
break;
case '$':
// Split line item amount (like T above)
lineItemAmount = Decimal.Parse( line.Substring( 1 ) );
item = BuildLineItem( ledger, trans, lineItemCategory, lineItemMemo, lineItemAmount );
item.IsReconciled = isCleared;
trans.LineItems.Add( item );
break;
// Investment indicators
case 'Y': // security name
investmentName = line.Substring( 1 );
break;
case 'I': // price
investmentPrice = line.Substring( 1 );
break;
case 'Q': // quantity (shares)
investmentShares = line.Substring( 1 );
break;
case 'O': // commission
investmentCommission = line.Substring( 1 );
break;
default:
// Unrecognized - ignore
break;
}
lineNumber++;
} // while
if( trans.LineItems.Count > 0 )
{
// Transaction had splits.
// Add the transaction amount as the final split.
item = BuildLineItem( ledger, trans, transCategory, trans.Memo, -transAmount );
item.Number = checkNumber;
item.Account = account;
item.CategoryObject = null;
item.IsReconciled = isCleared;
trans.LineItems.Add( item );
// Adjust total transaction amount.
trans.Amount = trans.GetCreditLineItemSum();
}
else
{
// No splits. Must create a matching debit and credit.
Account otherAccount;
Category otherCategory;
otherAccount = ParseAccount( ledger, transCategory, transAmount, out otherCategory );
if( transAmount < 0 )
{
// Withdrawal
item = trans.CreateLineItem( TransactionType.Credit, account, Math.Abs( transAmount ), null );
item.Number = checkNumber;
item.IsReconciled = isCleared;
trans.LineItems.Add( item );
item = trans.CreateLineItem( TransactionType.Debit, otherAccount, Math.Abs( transAmount ), otherCategory );
trans.LineItems.Add( item );
}
else
{
// Deposit
item = trans.CreateLineItem( TransactionType.Credit, otherAccount, Math.Abs( transAmount ), otherCategory );
trans.LineItems.Add( item );
item = trans.CreateLineItem( TransactionType.Debit, account, Math.Abs( transAmount ), null );
item.IsReconciled = isCleared;
trans.LineItems.Add( item );
}
}
trans.LineItems.Sort();
trans.Validate();
// Special case "Opening Balance" line:
if( trans.Description == "Opening Balance" && account.GetLineItems().Count == 0 )
{
// The account name is given in the category
account.Name = transCategory.Trim( '[', ']' );
account.StartingBalance = account.IsLiability ? -transAmount : transAmount;
account.StartingDate = trans.Date;
}
else
{
trans.Id = ledger.GetNextTransactionId();
ledger.AddTransaction( trans );
}
}
catch( Exception ex )
{
// Don't add broken transactions
Console.WriteLine( "Error on line number " + lineNumber.ToString() );
Console.WriteLine( ex.ToString() );
throw;
}
return lineNumber;
}