private bool TemNumero() //verifica se há número na expressão { foreach (char possivelNumero in txtVisor.Text) { if (!Operacao.EhOperador(possivelNumero + "")) { return(true); } } return(false); }
private void btnFechaParenteses_Click(object sender, EventArgs e) // Método de quando o ) é selecionado { if (!string.IsNullOrEmpty(txtVisor.Text) && txtVisor.Text[txtVisor.Text.Length - 1] != '.' && (txtVisor.Text[txtVisor.Text.Length - 1] == ')' || !Operacao.EhOperador(txtVisor.Text[txtVisor.Text.Length - 1] + ""))) { txtVisor.Text += ((Button)sender).Text; jaTemVirgula = false; } }
private void btnAbreParenteses_Click(object sender, EventArgs e) // Método de quando o ( é selecionado { if (string.IsNullOrEmpty(txtVisor.Text) || (txtVisor.Text[txtVisor.Text.Length - 1] != ')' && Operacao.EhOperador(txtVisor.Text[txtVisor.Text.Length - 1].ToString()) && txtVisor.Text[txtVisor.Text.Length - 1] != '.')) { txtVisor.Text += ((Button)sender).Text; jaTemVirgula = false; } }
private void btnMultiplicacaoDivisao_Click(object sender, EventArgs e) // Método de quando * ou / é selecionado { if (!string.IsNullOrEmpty(txtVisor.Text) && txtVisor.Text[txtVisor.Text.Length - 1] != '(' && (!Operacao.EhOperador(txtVisor.Text[txtVisor.Text.Length - 1].ToString()) || txtVisor.Text[txtVisor.Text.Length - 1] == ')') && txtVisor.Text[txtVisor.Text.Length - 1] != '.') { txtVisor.Text += ((Button)sender).Text; jaTemVirgula = false; } }
private void btnAdicaoSubtracao_Click(object sender, EventArgs e) // Método de quando + ou - é selecionado { if (string.IsNullOrEmpty(txtVisor.Text) || (txtVisor.Text[txtVisor.Text.Length - 1] == 'V' || txtVisor.Text[txtVisor.Text.Length - 1] == '(' || !Operacao.EhOperador(txtVisor.Text[txtVisor.Text.Length - 1].ToString()) && txtVisor.Text[txtVisor.Text.Length - 1] != '.')) { txtVisor.Text += ((Button)sender).Text; jaTemVirgula = false; } }
private void btnPonto_Click(object sender, EventArgs e) // Método de quando o . é selecionado { if (txtVisor.Text != "" && !jaTemVirgula && txtVisor.Text[txtVisor.Text.Length - 1] != '.' && !Operacao.EhOperador(txtVisor.Text[txtVisor.Text.Length - 1] + "")) { txtVisor.Text += "."; jaTemVirgula = true; } }