Ejemplo n.º 1
0
        private void btnApagar_Click(object sender, EventArgs e)
        {
            AGENDAMENTOEntities db = new AGENDAMENTOEntities();

            try
            {
                DialogResult deletar = MessageBox.Show("Deseja apagar esse contato", "AVISO", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (deletar == DialogResult.Yes)
                {
                    var contato = db.AGENDA.Where(s => s.ID_AGENDA == VerAgendamento.idContato).FirstOrDefault();
                    contato.FLAG_EXCLUIDO = "S";
                    db.SaveChanges();
                    MessageBox.Show("Contato Excluido com sucesso", "SUCESSO", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    VerAgendamento va = new VerAgendamento();
                    va.carregarGrid();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                db.Dispose();
            }
        }
Ejemplo n.º 2
0
        private void btnACadastrar_Click(object sender, EventArgs e)
        {
            AGENDAMENTOEntities db = new AGENDAMENTOEntities();

            try
            {
                TELEFONE telefone = new TELEFONE();
                if (cbxTipoTel.SelectedIndex == 2)
                {
                    telefone.TIPO_TEL = txtTipoTel.Text;
                }
                else
                {
                    telefone.TIPO_TEL = cbxTipoTel.SelectedItem.ToString();
                }
                telefone.AGENDA_ID_AGENDA = VerAgendamento.idContato;
                telefone.TEL = txtTelefone.Text;
                db.TELEFONE.Add(telefone);
                db.SaveChanges();
                MessageBox.Show("telefone cadastrado com sucesso", "SUCESSO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                db.Dispose();
            }
        }
Ejemplo n.º 3
0
        private void btnCadastrar_Click(object sender, EventArgs e)
        {
            AGENDAMENTOEntities db = new AGENDAMENTOEntities();

            try
            {
                EMAIL email = new EMAIL();
                if (cbxTipoEmail.SelectedIndex == 2)
                {
                    email.TIPO_EMAIL = txtTipoEmail.Text;
                }
                else
                {
                    email.TIPO_EMAIL = cbxTipoEmail.SelectedItem.ToString();
                }
                email.EMAIL1           = txtEmail.Text;
                email.AGENDA_ID_AGENDA = VerAgendamento.idContato;
                db.EMAIL.Add(email);
                db.SaveChanges();
                MessageBox.Show("Email alterado com sucesso", "SUCESSO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                db.Dispose();
            }
        }
Ejemplo n.º 4
0
        private void btnAlterar_Click(object sender, EventArgs e)
        {
            AGENDAMENTOEntities db = new AGENDAMENTOEntities();

            try
            {
                var telefone = db.TELEFONE.Where(s => s.ID_TELEFONE == VerContatos.idTel).FirstOrDefault();
                if (cbxTipoTel.SelectedIndex == 2)
                {
                    telefone.TIPO_TEL = txtTipoTel.Text;
                }
                else
                {
                    telefone.TIPO_TEL = cbxTipoTel.SelectedItem.ToString();
                }
                telefone.TEL = txtTelefone.Text;
                db.SaveChanges();
                MessageBox.Show("telefone alterado com sucesso", "SUCESSO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                db.Dispose();
            }
        }
Ejemplo n.º 5
0
        private void btnApagar_Click(object sender, EventArgs e)
        {
            AGENDAMENTOEntities db = new AGENDAMENTOEntities();

            try
            {
                var telefone = db.TELEFONE.Where(s => s.ID_TELEFONE == VerContatos.idTel).FirstOrDefault();
                db.TELEFONE.Remove(telefone);
                db.SaveChanges();
                MessageBox.Show("Email apagado com sucesso", "SUCESSO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                db.Dispose();
            }
        }
Ejemplo n.º 6
0
        private void btnAlterar_Click(object sender, EventArgs e)
        {
            AGENDAMENTOEntities db = new AGENDAMENTOEntities();

            try
            {
                var contato = db.AGENDA.Where(s => s.ID_AGENDA == VerAgendamento.idContato).FirstOrDefault();
                contato.NOME = txtNomeContato.Text;

                string tipoTelPrincipal = "";
                if (cbxTipoTelPrincipal.SelectedIndex == 2)
                {
                    tipoTelPrincipal = txtTipoTelPrincipal.Text;
                }
                if (cbxTipoTelPrincipal.SelectedIndex != 2)
                {
                    tipoTelPrincipal = cbxTipoTelPrincipal.SelectedItem.ToString();
                }
                contato.TIPO_TEL_PRINCIPAL = tipoTelPrincipal;
                contato.TEL_PRINCIPAL      = txtTelPrincipal.Text;
                if (chkResidencial.Checked)
                {
                    //passa todos os campos de texto para as variaveis
                    string cepResidencial         = txtCepResidencial.Text;
                    string UFResidencial          = txtUFResidencial.Text;
                    string localidadeResidencial  = txtLocalidadeResidencial.Text;
                    string logradouroResidencial  = txtLogradouroResidencial.Text;
                    string numeroResidencial      = txtNumeroResidencial.Text;
                    string complementoResidencial = txtComplementoResidencial.Text;
                    string bairroResidencial      = txtBairroResidencial.Text;

                    //insere os dados na tabela
                    contato.CEP_RESIDENCIAL         = cepResidencial;
                    contato.UF_RESIDENCIAL          = UFResidencial;
                    contato.LOCALIDADE_RESIDENCIAL  = localidadeResidencial;
                    contato.LOGRADOURO_RESIDENCIAL  = logradouroResidencial;
                    contato.NUMERO_RESIDENCIAL      = numeroResidencial;
                    contato.COMPLEMENTO_RESIDENCIAL = complementoResidencial;
                    contato.BAIRRO_RESIDENCIAL      = bairroResidencial;
                }
                else
                {
                    //passa todos os campos de texto para as variaveis
                    string cepResidencial         = null;
                    string UFResidencial          = null;
                    string localidadeResidencial  = null;
                    string logradouroResidencial  = null;
                    string numeroResidencial      = null;
                    string complementoResidencial = null;
                    string bairroResidencial      = null;

                    //insere os dados na tabela
                    contato.CEP_RESIDENCIAL         = cepResidencial;
                    contato.UF_RESIDENCIAL          = UFResidencial;
                    contato.LOCALIDADE_RESIDENCIAL  = localidadeResidencial;
                    contato.LOGRADOURO_RESIDENCIAL  = logradouroResidencial;
                    contato.NUMERO_RESIDENCIAL      = numeroResidencial;
                    contato.COMPLEMENTO_RESIDENCIAL = complementoResidencial;
                    contato.BAIRRO_RESIDENCIAL      = bairroResidencial;
                }

                //Caso a checkbox de inserir dados de endereço da empresa estiver selecionada sera incluido tambem no banco
                if (chkEmpresa.Checked)
                {
                    //passa todos os campos de texto para as variaveis
                    string nomeEmpresa        = txtNomeEmpresa.Text;
                    string cargo              = txtCargo.Text;
                    string cepEmpresa         = txtCepEmpresa.Text;
                    string UFEmpresa          = txtUFEmpresa.Text;
                    string localidadeEmpresa  = txtLocalidadeEmpresa.Text;
                    string logradouroEmpresa  = txtLogradouroEmpresa.Text;
                    string numeroEmpresa      = txtNumeroEmpresa.Text;
                    string complementoEmpresa = txtComplementoEmpresa.Text;
                    string bairroEmpresa      = txtBairroEmpresa.Text;

                    //insere os dados na tabela
                    contato.NOME_EMPRESA        = nomeEmpresa;
                    contato.CARGO_EMPRESA       = cargo;
                    contato.CEP_EMPRESA         = cepEmpresa;
                    contato.UF_EMPRESA          = UFEmpresa;
                    contato.LOCALIDADE_EMPRESA  = localidadeEmpresa;
                    contato.LOGRADOURO_EMPRESA  = logradouroEmpresa;
                    contato.NUMERO_EMPRESA      = numeroEmpresa;
                    contato.COMPLEMENTO_EMPRESA = complementoEmpresa;
                    contato.BAIRRO_EMPRESA      = bairroEmpresa;
                }
                else
                {
                    //passa todos os campos de texto para as variaveis
                    string nomeEmpresa        = null;
                    string cargo              = null;
                    string cepEmpresa         = null;
                    string UFEmpresa          = null;
                    string localidadeEmpresa  = null;
                    string logradouroEmpresa  = null;
                    string numeroEmpresa      = null;
                    string complementoEmpresa = null;
                    string bairroEmpresa      = null;

                    //insere os dados na tabela
                    contato.NOME_EMPRESA        = nomeEmpresa;
                    contato.CARGO_EMPRESA       = cargo;
                    contato.CEP_EMPRESA         = cepEmpresa;
                    contato.UF_EMPRESA          = UFEmpresa;
                    contato.LOCALIDADE_EMPRESA  = localidadeEmpresa;
                    contato.LOGRADOURO_EMPRESA  = logradouroEmpresa;
                    contato.NUMERO_EMPRESA      = numeroEmpresa;
                    contato.COMPLEMENTO_EMPRESA = complementoEmpresa;
                    contato.BAIRRO_EMPRESA      = bairroEmpresa;
                }
                db.SaveChanges();
                MessageBox.Show("Contato Alterado com sucesso", "SUCESSO", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                db.Dispose();
            }
        }
Ejemplo n.º 7
0
        //insere os dados no banco
        private void btnCadastrar_Click(object sender, EventArgs e)
        {
            AGENDAMENTOEntities db = new AGENDAMENTOEntities();

            try
            {
                AGENDA agen = new AGENDA();
                //Atribui em variaveis osc campo do nome de contato e o telefone principal
                string nomeContato      = txtNomeContato.Text;
                string tipoTelPrincipal = "";
                if (cbxTipoTelPrincipal.SelectedIndex == 2)
                {
                    tipoTelPrincipal = txtTipoTelPrincipal.Text;
                }
                if (cbxTipoTelPrincipal.SelectedIndex != 2)
                {
                    tipoTelPrincipal = cbxTipoTelPrincipal.SelectedItem.ToString();
                }
                string telPrincipal = txtTelPrincipal.Text;

                //passa os obrigatorios para a tabela
                agen.NOME               = nomeContato;
                agen.TEL_PRINCIPAL      = telPrincipal;
                agen.TIPO_TEL_PRINCIPAL = tipoTelPrincipal;

                //Caso a checkbox de inserir dados de endereço residencial estiver selecionada sera incluido tambem no banco
                if (chkResidencial.Checked)
                {
                    //passa todos os campos de texto para as variaveis
                    string cepResidencial         = txtCepResidencial.Text;
                    string UFResidencial          = txtUFResidencial.Text;
                    string localidadeResidencial  = txtLocalidadeResidencial.Text;
                    string logradouroResidencial  = txtLogradouroResidencial.Text;
                    string numeroResidencial      = txtNumeroResidencial.Text;
                    string complementoResidencial = txtComplementoResidencial.Text;
                    string bairroResidencial      = txtBairroResidencial.Text;

                    //insere os dados na tabela
                    agen.CEP_RESIDENCIAL         = cepResidencial;
                    agen.UF_RESIDENCIAL          = UFResidencial;
                    agen.LOCALIDADE_RESIDENCIAL  = localidadeResidencial;
                    agen.LOGRADOURO_RESIDENCIAL  = logradouroResidencial;
                    agen.NUMERO_RESIDENCIAL      = numeroResidencial;
                    agen.COMPLEMENTO_RESIDENCIAL = complementoResidencial;
                    agen.BAIRRO_RESIDENCIAL      = bairroResidencial;
                }

                //Caso a checkbox de inserir dados de endereço da empresa estiver selecionada sera incluido tambem no banco
                if (chkEmpresa.Checked)
                {
                    //passa todos os campos de texto para as variaveis
                    string nomeEmpresa        = txtNomeEmpresa.Text;
                    string cargo              = txtCargo.Text;
                    string cepEmpresa         = txtCepEmpresa.Text;
                    string UFEmpresa          = txtUFEmpresa.Text;
                    string localidadeEmpresa  = txtLocalidadeEmpresa.Text;
                    string logradouroEmpresa  = txtLogradouroEmpresa.Text;
                    string numeroEmpresa      = txtNumeroEmpresa.Text;
                    string complementoEmpresa = txtComplementoEmpresa.Text;
                    string bairroEmpresa      = txtBairroEmpresa.Text;

                    //insere os dados na tabela
                    agen.NOME_EMPRESA        = nomeEmpresa;
                    agen.CARGO_EMPRESA       = cargo;
                    agen.CEP_EMPRESA         = cepEmpresa;
                    agen.UF_EMPRESA          = UFEmpresa;
                    agen.LOCALIDADE_EMPRESA  = localidadeEmpresa;
                    agen.LOGRADOURO_EMPRESA  = logradouroEmpresa;
                    agen.NUMERO_EMPRESA      = numeroEmpresa;
                    agen.COMPLEMENTO_EMPRESA = complementoEmpresa;
                    agen.BAIRRO_EMPRESA      = bairroEmpresa;
                }
                //adciona na agenda
                db.AGENDA.Add(agen);
                db.SaveChanges();
                //busca o contato que foi cadastrado para relacionar o contato com a lista de telefones e emails opcionais
                var ContatoCadastrado = db.AGENDA.OrderByDescending(s => s.ID_AGENDA).FirstOrDefault();

                //Cria variaveis list para atribuir todos os telefones e emails cadastrados nas listbox
                List <TELEFONE> telOp   = new List <TELEFONE>();
                List <EMAIL>    emailOp = new List <EMAIL>();

                if (listTelOpcional.Items.Count > 0 || ListEmail.Items.Count > 0)
                {
                    //se a lista de telefones Opcionais possui a quantidade de registros maior que 0 sera atribuido a lista
                    if (listTelOpcional.Items.Count > 0)
                    {
                        //percorre pela listbox e insere cada um no banco
                        foreach (var item in listTelOpcional.Items)
                        {
                            //Salva os dados do telefone na string
                            string teletipo = item.ToString();
                            //separa a string de acordo com a quantidade de char que possui
                            string[] teletipoSep = teletipo.Split(new char[1] {
                                ';'
                            });
                            string tipoTel = teletipoSep[0];
                            string Tel     = teletipoSep[1];
                            telOp.Add(new TELEFONE
                            {
                                AGENDA_ID_AGENDA = ContatoCadastrado.ID_AGENDA,
                                TIPO_TEL         = tipoTel,
                                TEL = Tel
                            });
                        }
                        db.TELEFONE.AddRange(telOp);
                    }
                    //Caso se a lista com os emails for > 0 ira entrar no if
                    if (ListEmail.Items.Count > 0)
                    {
                        //percorre toda listBox para inserir na lista de emails
                        foreach (var item in ListEmail.Items)
                        {
                            string   emailTipo    = item.ToString();
                            string[] emailtipoSep = emailTipo.Split(new char[1] {
                                ';'
                            });
                            string tipoEmail = emailtipoSep[0];
                            string email     = emailtipoSep[1];
                            //insere na lista o email
                            emailOp.Add(new EMAIL
                            {
                                AGENDA_ID_AGENDA = ContatoCadastrado.ID_AGENDA,
                                TIPO_EMAIL       = tipoEmail,
                                EMAIL1           = email
                            });
                        }
                        //Adiciona todos os email na tabela de email
                        db.EMAIL.AddRange(emailOp);
                    }
                    //adiciona os telefones e emails opcionais no banco
                    db.SaveChanges();
                }
                MessageBox.Show("Cadastro Efetuado com sucesso", "SUCESSO", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message);
            }
            finally
            {
                db.Dispose();
            }
        }