2016-06-01 3 views
0

텍스트 상자가 있고 값이 자연 양수입니다. 일부 계산을 수행 한 후 다른 텍스트 상자에서 생성하고 있으므로 텍스트 상자에 숫자가 맞으면 결과가 분명합니다. 값을 정수로 변환합니다. 텍스트 상자는 0보다 크고 전혀 null이 아닌 값을 유지하면서 항상 0을 제공합니다.
는 나 또한 내가
여기 내 코드는 내가 텍스트를 변환 한 후 두 텍스트 상자에 텍스트와 정수 값의 결과를 볼 2 브레이크 포인트를 만들고 여기에 설립 TryParse 방법 Convert textbox text to integer
을 시도 msdn
여기에 모두 변환 방법을 시도 : TextBox 텍스트를 정수로 변환합니다.

MessageBox.Show(updateProductTQ.Text, "Quantity"); 
p.ProductQuantity = int.Parse(updateProductTQ.Text); 
MessageBox.Show(p.ProductQuantity.ToString(), "Quantity"); 

updateProductTQ

내 텍스트 상자에 이름이, p.ProductQuantity는 정수
MessageBox 출력되는 텍스트 상자,855,132에 표시된 번호 10 지금
두 번째 MessageBox 출력이 크다 0

누군가 내가 왜 0을 얻을 수 있는지 말해 줄 수 있습니까 ???

public int ProductQuantity 
    { 
     get 
     { 
      if (ProductCartoons >= 0) 
      { 
       if (ProductBigBox > 0 && ProductSmallBox > 0 && ProductMedBox > 0 && ProductItems >= 0) 
       { 
        _ProdQuan = ProductCartoons * ProductBigBox * ProductMedBox * ProductSmallBox * ProductItems; 
       } 
       else 
       if (ProductBigBox > 0 && ProductMedBox > 0 && ProductItems >= 0) 
       { 
        _ProdQuan = ProductCartoons * ProductBigBox * ProductMedBox * ProductItems; 
       } 
       else 
       if (ProductBigBox>0 && ProductSmallBox > 0 && ProductItems >= 0) 
       { 
        _ProdQuan = ProductCartoons * ProductBigBox * ProductSmallBox * ProductItems; 
       } 
       else 
       if (ProductMedBox > 0 && ProductSmallBox > 0 && ProductItems >= 0) 
       { 
        _ProdQuan = ProductCartoons * ProductMedBox * ProductSmallBox * ProductItems; 
       } 
       else 
       if (ProductBigBox>0 && ProductItems >= 0) 
       { 
        _ProdQuan = ProductCartoons * ProductBigBox * ProductItems; 
       } 
       else 
       if (ProductMedBox > 0 && ProductItems >= 0) 
       { 
        _ProdQuan = ProductCartoons * ProductMedBox * ProductItems; 
       } 
       else 
       if (ProductSmallBox > 0 && ProductItems >= 0) 
       { 
        _ProdQuan = ProductCartoons * ProductSmallBox * ProductItems; 
       } 
       else 
       if (ProductItems >= 0) 
       { 
        _ProdQuan = ProductCartoons * ProductItems; 
       } 
      } 
      return _ProdQuan; 
     } 
     set { _ProdQuan = value; } 
    } 

하고이 텍스트 상자에 의해 제기 된 모든 바인딩에 의해 수행 : 그건 정말 내 ProductQuantity 정의는 이상한 것은

여기

입니다
내가 다른 텍스트 상자에 유지 수의 변환을 시도하고 그것을 잘 작동합니다 그것은 잘 작동 :이

public int ProductCartoons 
    { 
     get { return _Cartoons; } 
     set 
     { 
      _Cartoons = value; 
      RaisePropertyChangedEvent("ProductQuantity"); 
     } 
    } 

    public int ProductBigBox 
    { 
     get { return _BigBox; } 
     set 
     { 
      _BigBox = value; 
      RaisePropertyChangedEvent("ProductQuantity"); 
     } 
    } 

    public int ProductMedBox 
    { 
     get { return _MedBox; } 
     set 
     { 
      _MedBox = value; 
      RaisePropertyChangedEvent("ProductQuantity"); 
     } 
    } 

    public int ProductSmallBox 
    { 
     get { return _SmallBox; } 
     set 
     { 
      _SmallBox = value; 
      RaisePropertyChangedEvent("ProductQuantity"); 
     } 
    } 

    public int ProductItems 
    { 
     get { return _Items; } 
     set 
     { 
      _Items = value; 
      RaisePropertyChangedEvent("ProductQuantity"); 
     } 
    } 
+0

'updateProductTQ.Text'의 값을 게시 할 수 있습니까? –

+2

'ProductQuantity' 속성 정의 방법을 보여줄 수 있습니까? –

+0

테스트 한 경우'ProductCartoons> 0'입니까? 그런 다음 저장된 '_ProdQuan'을 직접 반환하지는 않지만 다시 계산하십시오. –

답변

0

이 있습니다 (게터에) 당신이 ProductQuantity 정의를 알 경우이 값이다, 이유를보고이 값이 경우, ProductCartoons에 따라 달라집니다 0이면 ProductQuantity에 대해 항상 0이 표시됩니다.

디버거를 사용하고 단계별로 진행하여이 경우 0이 무엇인지 확인하십시오.

+0

'ProductCartoons'이 '0'이면'ProductQuantity'가 전혀 없습니다 '0' 'ProductItems '과 동일합니다 알아요.하지만 0이 아닙니다 –

+0

'ProductCartoons'은 _zero_가 아니십니까? –

+0

예 'ProductCartoons'은'0' 코드가 아닙니다. –

관련 문제