private void btnSalvar_Click(object sender, EventArgs e) { errorProvider1.SetError(txtTelefone, ""); if (txtTelefone.Text.Replace("_", "").Replace("(", "").Replace(")", "").Replace("-", "").Trim().Length < 10) { errorProvider1.SetError(txtTelefone, "Telefone inválido."); return; } if (!string.IsNullOrEmpty(txtEmail.Text) && !Funcoes.validarEmail(txtEmail, errorProvider1)) { return; } if (!string.IsNullOrEmpty(txtSite.Text) && !Funcoes.validarURL(txtSite, errorProvider1)) { return; } try { TelefonesRepository repositorioTelefone = new TelefonesRepository(); Telefones telefoneModel = new Telefones(); telefoneModel.email = txtEmail.Text.Trim(); telefoneModel.id_contatos = Convert.ToInt32(cbxContatos.SelectedValue); telefoneModel.site = txtSite.Text.Trim(); telefoneModel.telefone = txtTelefone.Text.Trim(); telefoneModel.tipo = cbxTipo.Text; repositorioTelefone.Inserir(telefoneModel); Limpar(); MessageBox.Show("Registro cadastro com sucesso!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Erro ao cadastrar telefone: " + ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void button1_Click(object sender, EventArgs e) { TelefonesRepository dao = new TelefonesRepository(); var consulta = dao.Consultar(c => c.id > 0); foreach (var item in consulta) { MessageBox.Show(item.telefone); } }