protected void btAcesso_Click(object sender, EventArgs e) { lblMsg.Text = ""; ClearTable(); clsEmpresa empresa_class = new clsEmpresa(); if (string.IsNullOrWhiteSpace(txtIM.Text) && string.IsNullOrWhiteSpace(txtCNPJ.Text)) { lblMsg.Text = "Erro: Informação necessária."; } else { if (!string.IsNullOrWhiteSpace(txtIM.Text) && !string.IsNullOrWhiteSpace(txtCNPJ.Text)) { lblMsg.Text = "Erro: Digite a inscrição municipal ou o cnpj da empresa."; } else { if (!string.IsNullOrWhiteSpace(txtIM.Text)) { if (!empresa_class.ExisteEmpresa(Convert.ToInt32(txtIM.Text))) { lblMsg.Text = "Erro: Cadastro inexistente."; } else { FillTable(); } } else { string sCnpj = txtCNPJ.Text.PadLeft(14, '0'); int nCodigo = empresa_class.ExisteEmpresaCnpj(sCnpj); if (!string.IsNullOrWhiteSpace(sCnpj) && nCodigo == 0) { lblMsg.Text = "Erro: Cadastro inexistente."; } else { txtIM.Text = nCodigo.ToString("000000"); FillTable(); } } } } }