2017-05-09 1 views
-5

나는 이미 ArrayList에 현재 거래일에 3 일을 추가해야하는 버튼이 있습니다.현재 거래일에 3 일을 더해야합니다

어떻게 수행하나요? 당신은 더 이상 코드가 필요하면

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

은 알려 주시기 바랍니다 다음과 같이

코드입니다. 당신은 그런 일이 필요

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 클래스는 어떤 모습입니까? 그것을 수정할 수있는 DateTime 필드가 있습니까? 그리고 우리는 왜 당신이 "만약"조건으로 원하는 것을 알고 있습니까? –

+0

글쎄, 당신은 거래를하고있어, "if"는 아마도 거래 클래스의 어떤 것에 조건부 체크를해야 할 것이다. 그래서 if는 if (item. [Property] == [value])와 같을 것입니다. 또한 Transaction 클래스의 일부 속성을 설정하여 업데이트해야합니다. (DateProperty) = item. [DateProperty] .AddDays (3); – Aaron

답변

0

:

그래서 여기 내 Transaction.cs 코드

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'에 특정 값이있는 경우) –

관련 문제