2013-09-29 6 views
-2

'계산'버튼을 누르면 '추가 프로그램'및 '설치'텍스트 상자가 0으로 돌아가고 '청구서'가 지정된 고객 유형의 기본 가격으로 바뀝니다. 코드 내에서계산 프로그램 - 입력 텍스트 상자

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace Bus432_Assignment2 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void btnCalculate_Click(object sender, EventArgs e) 
     { 
     const double RES_HOME = 99; 
     const double RES_HOME_ADD = 49; 
     const double ENT_ADD_PRO = 10; 
     const double ENT_BASIC = 249; 
     const double ENT_PER_PRO = 99; 
     const double ENT_ADD_INSTALL_CHARGE = .10; 
     const double UNLIM_BASIC = 999; 


    char customerType; 
     double addpro = 0; 
     double install = 0; 
     double bill = 0; 

    // Check to make sure type has been entered. 
    if (txtCustomerType.Text == "") 
    { 
     MessageBox.Show("Customer type is required.", 
      Text, MessageBoxButtons.OK, MessageBoxIcon.Information); 
     txtCustomerType.Focus(); 
     return; 
    } 

    // Get customer type 
    customerType = char.Parse(txtCustomerType.Text); 
    customerType = char.ToUpper(customerType); 
    txtCustomerType.Text = customerType.ToString(); 

    // Check customer type, programs, installations 
    txtInstall.Text = install.ToString(); 
    txtAddPro.Text = addpro.ToString(); 


    if (customerType == 'H' || customerType == 'E') 
    { 
     if (txtInstall.Text == "") 
     { 
      MessageBox.Show("For home use customer plan, enter installations", 
       Text, MessageBoxButtons.OK, MessageBoxIcon.Information); 

      if (txtInstall.Text == "") 
      { 
       txtInstall.Focus(); 
      } 

      return; 
     } 


    } 

    else if (customerType == 'E' || customerType == 'H') 
    { 
     if (txtAddPro.Text == "") 
     { 
      MessageBox.Show("For enterprise or home use customer, enter additional programs", 
       Text, MessageBoxButtons.OK, MessageBoxIcon.Information); 
      if (txtAddPro.Text == "") 
      { 
       txtAddPro.Focus(); 
      } 

      return; 
     } 


    else if (customerType != 'E' || customerType != 'H' || customerType != 'U') 
     { 
      MessageBox.Show("Customer type must be E, H, or U.", 
       Text, MessageBoxButtons.OK, MessageBoxIcon.Information); 
      //txtInstall.Focus(); 
      return; 
     } 


     // Get Additional Programs and installations 
     addpro = double.Parse(txtAddPro.Text); 
     install = double.Parse(txtInstall.Text); 

     if (addpro < 0) 
     { 
      MessageBox.Show("Number of additional programs must not be negative.", 
       Text, MessageBoxButtons.OK, MessageBoxIcon.Information); 
      txtAddPro.Focus(); 
      return; 
     } 

     else if (install < 0) 
     { 
      MessageBox.Show("Number of installations must not be negative.", 
       Text, MessageBoxButtons.OK, MessageBoxIcon.Information); 
      txtInstall.Focus(); 
      return; 
     } 
    } 



    // Calculate Bill 
    switch(customerType) 
    { 
     case 'H': 
      bill = RES_HOME + addpro * RES_HOME_ADD; 
      break; 
     case 'E': 
      bill = ENT_BASIC + addpro * ENT_PER_PRO *(1+ENT_ADD_INSTALL_CHARGE*(install-ENT_ADD_PRO)); 
      break; 
     case 'U': 
      bill = UNLIM_BASIC; 
      break; 
    } 

    // Display the result. 
    txtBill.Text = bill.ToString("C"); 
} 

    private void btnClose_Click(object sender, EventArgs e) 
    { 
     Close(); 
    } 
} 

    } 
+0

* * *에 대한 도움말? –

+0

내가 맞았을 때 '추가 프로그램'과 '설치'계산은 다른 숫자를 입력하면 0으로 간다. – MSmits23

답변

0

,이 두 변수

다음
double addpro = 0; 
double install = 0; 

당신이이 선언 한 후에, 당신이 이제까지하지 않고, 그들을 동일하게 상자의 텍스트를 설정하는 선언 한 : 내 코드는 아래에 나는 당신이 달성하려고하는 것을 너무 확실하지 않다, 그래서 대신이 있어야한다 무엇을 제안 할 수 0

txtInstall.Text = install.ToString(); 
txtAddPro.Text = addpro.ToString(); 

아무것도하지만 자신의 값을 설정, 그러나 그것은 sourc입니다 전자 텍스트 필드에 0 표시에 관한 문제.