Пример #1
0
        private void btnSalvar_Click(object sender, System.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 {
                Telefone telefone = new Telefone()
                {
                    email      = txtEmail.Text.Trim(),
                    id_contato = Convert.ToInt32(cbxContato.SelectedValue),
                    site       = txtSite.Text.Trim(),
                    telefone   = txtTelefone.Text,
                    tipo       = cbxTipo.Text
                };
                telefoneDao.Inserir(telefone);
                limpar();
                MessageBox.Show("Telefone cadastrado com Sucesso!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information);
            } catch (Exception ex) {
                MessageBox.Show("Erro ao cadastrar: " + ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }