public static bool tratamentoCpnjFornecedor(TextBox txt) { if (txt.Text != "") { string cnpj = txt.Text.Replace(".", "").Replace("-", "").Replace("/", ""); if (ValidaCpf.IsCnpj(txt.Text) != true) { //MessageBox.Show("CNPJ inválido", "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Information); //txt.Focus(); //return false; return(FuncGeral.tratamentoCpfFornecedor(txt)); } else { txt.Text = Convert.ToUInt64(cnpj).ToString(@"00\.000\.000\/0000\.00"); SGAP.Modelo.SGAPContexto contexto = new SGAPContexto(); cnpj = txt.Text; Fornecedor fornecedor = contexto.Fornecedor.ToList().FirstOrDefault(t => t.cnpj.CompareTo(cnpj) == 0); if (fornecedor != null) { MessageBox.Show("Já existe um fornecedor cadastrado com este CNPJ!", "Alerta!", MessageBoxButtons.OK, MessageBoxIcon.Error); txt.Focus(); return(false); } else { return(true); } } } else { return(true); } }
public static bool tratamentoCpnjFornecedorNoBd(TextBox txt) { if (txt.Text != "") { string cnpj = txt.Text.Replace(".", "").Replace("-", "").Replace("/", ""); if (ValidaCpf.IsCnpj(txt.Text) != true) { MessageBox.Show("CNPJ inválido", "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Information); txt.Focus(); return(false); } else { txt.Text = Convert.ToUInt64(cnpj).ToString(@"00\.000\.000\/0000\.00"); return(true); } } else { return(true); } }