[RESOLVIDO]If Else + textbox no C#

3 respostas
W

Galera, estou tentando criar um sistema de imposto pessoal, criei ele certinho, porém, quando vou criar o if/else ele tá erro,
A idéia é a seguinte:
Se o valor for > 1000 o imposto cobrado será de 15%, e se for menor que 1000 será de 10%.

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

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

        private void bd_impBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.bd_impBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.impostodbDataSet);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'impostodbDataSet.bd_imp' table. You can move, or remove it, as needed.
            this.bd_impTableAdapter.Fill(this.impostodbDataSet.bd_imp);

        }

    
        private void códigoTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void valorTextBox_TextChanged(object sender, EventArgs e)
        {
        
        }

        private void impostoTextBox_TextChanged(object sender, EventArgs e)
        {
            
        }

  [color=red]   private void button1_Click(object sender, EventArgs e)
        {
            if (impostoTextBox.Text > 1000)
            {
                this.impostoTextBox.Text = "" + this.valorTextBox.Text;

            }[/color]
        }
    }
}

3 Respostas

W

Consegui!!
Não sei se é o melhor caminho, mas deu certo...

private void button1_Click(object sender, EventArgs e)
        {

            int valor1, valor2;
            int imposto1;
            String valor3;

            valor1 = int.Parse(valorTextBox.Text);

            if (valor1 > 1000)
            {
                valor2 = (valor1 / 100) * 15;
                valor3 = valor2.ToString();
                this.impostoTextBox.Text = valor3;

            }
            else
            {
                valor2 = (valor1 / 100) * 10;
                valor3 = valor2.ToString();
                this.impostoTextBox.Text = valor3;


            }
JavaDreams

Se o post já foi resolvido, coloque RESOLVIDO no início do título do post.

drsmachado

Acho que assim fica bem melhor:

private void button1_Click(object sender, EventArgs e)  
{  
	int valor1, valor2;  
    int imposto1;  
    String valor3;  
  
    valor1 = int.Parse(valorTextBox.Text);  
  
    if (valor1 > 1000)  
    {  
		valor2 = (valor1 / 100) * 15;  
    }  
    else  
    {  
		valor2 = (valor1 / 100) * 10;
	}
	valor3 = valor2.ToString();  
	this.impostoTextBox.Text = valor3;
}
Criado 27 de agosto de 2013
Ultima resposta 27 de ago. de 2013
Respostas 3
Participantes 3