2017-05-09 78 views
-5

我有一個按鈕,需要添加3天到當前交易日期已在ArrayList需要添加3天到當前交易日期

如何做到這一點?

的代碼如下:

private void btnCheckCleared_Click(object sender, EventArgs e) 
{ 
    foreach (Transaction item in tranArray) 
    { 
     if (What goes here?) 
     { 
      DateTime.Today.AddDays(3).ToLongDateString(); 
     } 
    } 
} 

如果您需要更多的代碼,請讓我知道。

因此,這裏是我的Transaction.cs代碼:

namespace TEXT TEXT TEXT 

{ 
    public class Transaction 
    { 
     //data hiding (blackbox) 
     //visible only to class itself 
     //fields (variables) 
     //4 member variables (instantiate object) 
     private decimal decAmount; 
     private DateTime dteTransactionDate; 
     private string strCheckNumber; 
     private string strPayee; 
     private string strTypeTrans; 
     public bool CheckCleared; 

     public decimal Amount 
     { 
      get 
      { 
       return decAmount; 
      } 
      set 
      { 
       decAmount = value; 
      } 
     } 

     public string CheckNumber 
     { 
      get 
      { 
       return strCheckNumber; 
      } 
      set 
      { 
       strCheckNumber = value; 
      } 
     } 

     public string Payee 
     { 
      get 
      { 
       return strPayee; 
      } 
      set 
      { 
       strPayee = value; 
      } 
     } 

     public DateTime TransactionDate 
     { 
      get 
      { 
       return dteTransactionDate; 
      } 
      set 
      { 
       dteTransactionDate = value; 
      } 
     } 


     public TransactionType TypeTrans; 

     //constructor 
     public Transaction(string payee, decimal amount, TransactionType typeTrans, DateTime transactionDate) 
     { 
      this.Payee = payee; //assignment operator = 
      this.Amount = amount; //this is to qualify 
      this.TypeTrans = typeTrans; 
      this.TransactionDate = transactionDate; 
     } 

     public Transaction(string payee, decimal amount, TransactionType typeTrans, DateTime transactionDate, string checkNumber) 
     { 
      this.Payee = payee; //assignment operator = 
      this.Amount = amount; //this is to qualify 
      this.CheckNumber = checkNumber; 
      this.TypeTrans = typeTrans; 
      this.TransactionDate = transactionDate; 
     } 

     //public Transaction() 

     public override string ToString() 
     { 
      return this.TransactionDate.ToShortDateString() + " " + this.Amount.ToString("C") + "\t" + this.TypeTrans; 
     } 
    } 
} 
+2

你的問題不清楚,你能解釋一下嗎? –

+1

Transaction類是什麼樣的?它是否有修改的日期時間字段?我們爲什麼會知道你想要什麼作爲「如果」條件? –

+0

那麼,你正在使用一個事務,所以你的「如果」可能需要對事務類中的某些事情進行有條件的檢查。因此,你的if將會是「if(item。[Property] == [value])。另外,你需要設置Transaction類的一些屬性來更新它。你可能想要添加3天到所以:item。[DateProperty] = item。[DateProperty] .AddDays(3); – Aaron

回答

0

你需要類似的東西:

private void btnCheckCleared_Click(object sender, EventArgs e) 
{ 
    foreach (Transaction item in tranArray) 
    { 
     if (/*Whatever your condition looks like*/) 
     { 
      item.TransactionDate = item.TransactionDate.AddDays(3); 
     } 
    } 
} 

AddDays修改給出DateTime但返回DateTime,這就是爲什麼它被分配回item.TransactionDate

+0

我應該放什麼樣的條件? – dhoctran

+0

如果您想更新數組中的每個項目,則不需要條件。只有在*有條件時才指定它*應更新哪些項目的條件(例如,如果'TransactionDate'具有特定值) –