private void btnConsulta_Click(object sender, EventArgs e)
        {
            try
            {
                var rep = new Fiap.Persistencia.Hospital.DAO.Repositorio<Convenio>();

                if (txtConsultaOperadora.IsEmpty(true))
                {
                    gdvConvenio.DataSource = rep.Listar()
                                                .Where(x => x.Operadora.Contains(txtConsultaOperadora.Text) && x.dataExclusao==null)
                                                .OrderByDescending(x => x.IdConvenio)
                                                .Select(x => new { x.IdConvenio, x.Operadora , x.Plano, x.Acomodacao, x.Desconto})
                                                .ToList();
                }
                else
                    gdvConvenio.DataSource = rep.Listar(x=>  x.dataExclusao==null)
                                                .OrderByDescending(x => x.IdConvenio)
                                                .Take(10)
                                                 .Select(x => new { x.IdConvenio, x.Operadora, x.Plano, x.Acomodacao, x.Desconto })
                                                .ToList();

                gdvConvenio.ClearSelection();
            }
            catch (Exception)
            {
                MessageBox.Show("Erro ao Consultar", "Cadastro Convênio", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnConsulta_Click(object sender, EventArgs e)
        {
            try
            {
                var repM = new Fiap.Persistencia.Hospital.DAO.Repositorio<Enfermeiro>();

                if (txtConsultaCoren.IsEmpty(true))
                {
                    gdvEnfermeiro.DataSource = repM.Listar(x => x.dataExclusao == null)
                                                .Where(x => x.Coren == txtConsultaCoren.Text)
                                                .OrderByDescending(x => x.DatInc)
                                                 .Select(x => new { x.Coren, x.Nome, x.CPF })
                                                .ToList();
                }
                else if (txtConsultaNome.IsEmpty(true))
                    gdvEnfermeiro.DataSource = repM.Listar(x => x.dataExclusao == null)
                                                .Where(x => x.Nome.Contains(txtConsultaNome.Text.ToString()))
                                                .OrderByDescending(x => x.DatInc)
                                                 .Select(x => new { x.Coren, x.Nome, x.CPF })
                                                .ToList();
                else
                    gdvEnfermeiro.DataSource = repM.Listar(x => x.dataExclusao == null)
                                                .OrderByDescending(x => x.DatInc)
                                                .Take(10)
                                                 .Select(x => new { x.Coren, x.Nome, x.CPF })
                                                .ToList();

                gdvEnfermeiro.ClearSelection();
            }
            catch (Exception)
            {
                MessageBox.Show("Erro ao Consultar", "Cadastro Enfermeiro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnConsulta_Click(object sender, EventArgs e)
        {
            try
            {
                var repM = new Fiap.Persistencia.Hospital.DAO.Repositorio<Paciente>();

                if (txtConsultaCPF.IsEmpty(true))
                {
                    gdvPaciente.DataSource = repM.Listar(x=> x.dataExclusao==null)
                                                 .Where(x => x.CPF == txtConsultaCPF.Text)
                                                 .OrderByDescending(x => x.DatInc)
                                                 .Select(x => new { x.CPF, x.Nome, x.Cep, x.Uf, x.Cidade, x.Endereco, x.Telefone })
                                                 .ToList();
                }
                else if (txtConsultaNome.IsEmpty(true))
                    gdvPaciente.DataSource = repM.Listar(x => x.dataExclusao == null)
                                                 .Where(x => x.Nome.Contains(txtConsultaNome.Text.ToString()))
                                                 .OrderByDescending(x => x.DatInc)
                                                 .Select(x => new { x.CPF, x.Nome, x.Cep, x.Uf, x.Cidade, x.Endereco, x.Telefone })
                                                 .ToList();
                else
                    gdvPaciente.DataSource = repM.Listar(x => x.dataExclusao == null)
                                                 .OrderByDescending(x => x.DatInc)
                                                 .Select(x => new { x.CPF, x.Nome, x.Cep, x.Uf, x.Cidade, x.Endereco, x.Telefone })
                                                 .ToList();
            }
            catch (Exception)
            {
                MessageBox.Show("Erro ao Consultar", "Cadastro Paciente", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnConsulta_Click(object sender, EventArgs e)
        {
            var rep = new Fiap.Persistencia.Hospital.DAO.Repositorio<Tratamento>();

            try
            {
                IQueryable<Tratamento> query = rep.Listar(x=> x.dataExclusao==null);

                if (cboConsultaEspecialidade.SelectedValue.ToString() != "")
                {
                    int id = int.Parse(cboConsultaEspecialidade.SelectedValue.ToString());

                    query = query.Where(x => x.IdEspecialidade == id);
                }
                if (txtConsultaNome.Text != "")
                    query = query.Where(x => x.Nome.Contains(txtConsultaNome.Text));

                gdvTratamento.DataSource = query.OrderByDescending(x => x.DatInc)
                                                .Select(x => new
                                                {
                                                    Especialização = x.Especializacao.Nome,
                                                    x.IdTratamento,
                                                    x.Nome,
                                                    x.Valor
                                                })
                                                .ToList();

                gdvTratamento.ClearSelection();
            }
            catch (Exception)
            {
                throw;
            }
        }
        private void CarregaCombos()
        {
            try
            {
                var repA = new Fiap.Persistencia.Hospital.DAO.Repositorio<AgendamentoPaciente>(true);
                var agendamento = repA.Listar(a => a.codstatus == 1)
                                      .Select(x => new
                                      {
                                          x.IdAgendamento,
                                          Nome = x.Paciente.Nome,
                                          x.DataAgenda
                                      })
                                      .ToList();

                var agenda = agendamento.Select(x =>
                    new { x.IdAgendamento, Descricao = x.DataAgenda.ToString("dd/MM/yyyy") + " - " + x.Nome }).ToList();

                agenda.Insert(0, new { IdAgendamento = 0, Descricao = "Selecione" });

                cboAgendamento.Carrega(agenda.OrderBy(x => x.IdAgendamento).ToList(), "Descricao", "IdAgendamento");

                repA.Dispose();

                cboAgendamento.SelectedIndex = 0;
            }
            catch (Exception)
            {
                MessageBox.Show("Erro ao carregar combo de Agendamentos", "Cadastro prontuario", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                Especializacao esp = new Especializacao();

                if (txtEspecialização.IsEmpty())
                {
                    MessageBox.Show("Por favor digite uma especialização", "Cadastro Especialização", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtEspecialização.Focus();
                    return;
                }
                else
                    esp.Nome = txtEspecialização.Text;

                var rep = new Fiap.Persistencia.Hospital.DAO.Repositorio<Especializacao>();
                rep.Adicionar(esp);
                rep.Salvar();
                MessageBox.Show(string.Format("A especialização {0} \n\t adicionado com sucesso", esp.Nome));

                gdvEspecializacao.DataSource = rep.Listar().Select(x => new { x.IdEspecializacao, x.Nome }).ToList();

                var txts = this.GetTodosControles(typeof(TextBox));

                foreach (var item in txts)
                {
                    item.Text = "";
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Erro ao Salvar", "Cadastro Especialização", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnBuscarAgendamento_Click(object sender, EventArgs e)
        {
            try
            {
                if (Convert.ToString(cboAgendamento.SelectedValue) != "0")
                {
                    var repH = new Fiap.Persistencia.Hospital.DAO.Repositorio<AgendamentoPaciente>();

                    var agendamento = repH.Buscar(Convert.ToInt32(cboAgendamento.SelectedValue));

                    var repP = new Fiap.Persistencia.Hospital.DAO.Repositorio<Prontuario>();

                    gdvProntuarios.DataSource = repP.Listar(a => a.IdAgendamento.Equals(agendamento.IdAgendamento))
                                                    .OrderBy(a => a.DatInc)
                                                    .Select(x => new { x.CPF, x.CRM, x.Descricao, x.DatInc })
                                                    .ToList();
                }
                else
                {
                    MessageBox.Show("Por favor selecione um agendamento.", "Consulta Prontuario", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    cboAgendamento.Focus();
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Erro na busca de agendamento", "Consulta Prontuario", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                throw;
            }
        }
        private void btnConsulta_Click(object sender, EventArgs e)
        {
            try
            {
                var repM = new Fiap.Persistencia.Hospital.DAO.Repositorio<AgendamentoPaciente>();

                var lista = repM.Listar(x=> x.codstatus==0);

                if (!txtCPF.IsEmpty())
                {
                    lista = lista.Where(x => x.CPF == txtCPF.Text);
                }
                else
                {
                    var dataInicial =  DateTime.Parse(dtAgendaInicial.Text);
                    var dataFinal= DateTime.Parse(dtAgendaFinal.Text);

                    lista = lista.Where(x => x.DataAgenda >= dataInicial && x.DataAgenda<= dataFinal);

                    var idConvenio = cboConvenio.SelectedValue.ToString().CInt();

                    if (idConvenio > 0)
                    {
                        lista = lista.Where(x => x.IdConvenio == idConvenio);
                    }

                    if (!txtNome.IsEmpty())
                    {
                        lista = lista.Where(x => x.Paciente.Nome.Contains(txtCPF.Text));
                    }

                    var idMediEsp = cboMedicoEspecialidade.SelectedValue.ToString().CInt();

                    if (idMediEsp > 0)
                    {
                        lista = lista.Where(x => x.IdMedicoEspecializacao == idMediEsp);
                    }
                }

                gdvAgendamento.DataSource = lista.Select(x => new { x.IdAgendamento,
                    x.Paciente.Nome,
                    x.DataAgenda,
                    Medico = x.MedicoEspecializacao.Medico.Nome,
                    Especialide=x.MedicoEspecializacao.Especializacao.Nome,
                    Convenio=x.Convenio.Operadora + "-"+x.Convenio.Plano + "-" + x.Convenio.Acomodacao
                })
                .OrderBy(x=> x.DataAgenda)
                .ToList();

                gdvAgendamento.ClearSelection();
            }
            catch (Exception)
            {
                MessageBox.Show("Erro ao Consultar", "Cadastro Médico", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #9
0
        private void btnConsulta_Click(object sender, EventArgs e)
        {
            try
            {
                var rep = new Fiap.Persistencia.Hospital.DAO.Repositorio<Prontuario>();

                var dataInicial = DateTime.Parse(dtInicial.Text);
                var dataFinal = DateTime.Parse(dtFinal.Text);

                var faturamento =rep.Listar(x => x.DatInc >= dataInicial && x.DatInc <= dataFinal);

                var idConvenio =cboConvenio.SelectedValue.ToString().CInt();

                if (idConvenio > 0)
                {
                    faturamento = faturamento.Where(x => x.AgendamentoPaciente.IdConvenio == idConvenio);

                }
                else if (cboMedico.SelectedValue.ToString() != "")
                {
                   faturamento= faturamento.Where(x=> x.CRM==cboMedico.SelectedValue.ToString());

                }

              var result =  faturamento.Select(x => new
                    {
                        Médico = x.AgendamentoPaciente.MedicoEspecializacao.Medico.Nome,
                        Tratamento = x.Tratamento.Nome,
                        Convênio = x.AgendamentoPaciente.Convenio.Operadora + " - " + x.AgendamentoPaciente.Convenio.Plano + " - " + x.AgendamentoPaciente.Convenio.Acomodacao,
                        Desconto =x.AgendamentoPaciente.Convenio.Desconto,
                        Valor = x.Tratamento.Valor * (1 - x.AgendamentoPaciente.Convenio.Desconto/100),
                        valorMaterial = x.ProntuarioMaterialMedicamento.Sum(y=> y.MaterialMedicamento.ValorUnit),
                        Total = x.Tratamento.Valor * (1 - x.AgendamentoPaciente.Convenio.Desconto / 100) + x.ProntuarioMaterialMedicamento.Sum(y => y.MaterialMedicamento.ValorUnit)
                     }).ToList();
                gdvFaturamento.DataSource = result;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #10
0
        private void CarregaCombos()
        {
            try
            {
                var repC = new Fiap.Persistencia.Hospital.DAO.Repositorio<Convenio>();
                var convenio = repC.Listar()
                                   .Select(x => new
                                   {
                                       x.IdConvenio,
                                       Descricao = x.Operadora + " - " + x.Plano + " - " + x.Acomodacao
                                   })
                                   .OrderBy(x => x.Descricao)
                                   .ToList();
                convenio.Insert(0, new { IdConvenio = 0, Descricao = "Selecione" });
                cboConvenio.Carrega(convenio.OrderBy(x => x.IdConvenio).ToList(), "Descricao", "IdConvenio");
                repC.Dispose();

                cboConvenio.SelectedIndex = 0;

                //_____________________

                var repE = new Fiap.Persistencia.Hospital.DAO.Repositorio<Medico>();
                var esp = repE.Listar()
                              .OrderBy(x => x.Nome)
                              .Select(x => new { x.CRM, Descricao = x.Nome })
                              .ToList();
                esp.Insert(0, new { CRM = "", Descricao = "Selecione" });
                cboMedico.Carrega(esp, "Descricao", "CRM");
                repE.Dispose();
                cboMedico.SelectedIndex = 0;

            }
            catch (Exception)
            {
                MessageBox.Show("Erro ao carregar combo", "Cadastro agenda", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnConsulta_Click(object sender, EventArgs e)
        {
            var rep = new Fiap.Persistencia.Hospital.DAO.Repositorio<MaterialMedicamento>();

            try
            {
                IQueryable<MaterialMedicamento> query = rep.Listar();

                if (cboConsultaTipo.SelectedValue.ToString().CInt() > 0)
                {
                    int id = short.Parse(cboConsultaTipo.SelectedValue.ToString());

                    query = query.Where(x => x.Tipo == id);
                }
                if (txtConsultaMaterial.Text != "")
                    query = query.Where(x => x.Nome.Contains(txtConsultaMaterial.Text));

                gdvMateriais.DataSource = query.OrderByDescending(x => x.DatInc)
                                                   .Select(x => new
                                                   {
                                                       ID = x.IdMaterialMedicamento,
                                                       Material = x.Nome,
                                                       Tipo = x.TipoMaterialMedicamento.Descricao,
                                                       x.Saldo,
                                                       x.ValorUnit,
                                                       ValorTotal = x.Saldo * x.ValorUnit
                                                   })
                                .ToList();

                gdvMateriais.ClearSelection();
            }
            catch (Exception)
            {
                MessageBox.Show("Erro ao consultar", "Cadastro Materiais e Medicamentos", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void CarregaGrid()
 {
     var rep = new Fiap.Persistencia.Hospital.DAO.Repositorio<Especializacao>();
     gdvEspecializacao.DataSource = rep.Listar().Select(x => new { x.IdEspecializacao, x.Nome }).ToList();
 }
        /// <summary>
        /// Carrega o tipo de medicamento.
        /// </summary>
        private void CarregaTipo()
        {
            try
            {

                var rep = new Fiap.Persistencia.Hospital.DAO.Repositorio<TipoMaterialMedicamento>();

                var dados = rep.Listar().Select(x => new { x.IdTipo,x.Descricao}).ToList();

                dados.Insert(0, new { IdTipo = short.Parse("0"), Descricao = "Selecione" });

                cboTipo.Carrega(dados, "Descricao", "IdTipo");

                var dados2 = rep.Listar().Select(x => new { x.IdTipo, x.Descricao }).ToList();

                dados2.Insert(0, new { IdTipo = short.Parse("0"), Descricao = "Selecione" });
                cboConsultaTipo.Carrega(dados2, "Descricao", "IdTipo");
            }
            catch (Exception)
            {

                MessageBox.Show("Erro ao carregar os tipos", "Cadastro Materiais e Medicamentos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                Paciente paciente;
                var repP = new Fiap.Persistencia.Hospital.DAO.Repositorio<Paciente>();
                if (txtCPF.IsEmpty())
                {
                    MessageBox.Show("Por favor digite um email", "Cadastro Médico", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtCPF.Focus();
                    return;
                }
                else
                {
                    if (!Valida.IsCpf(txtCPF.Text))
                    {
                        MessageBox.Show("Por favor digite um CPF válido", "Cadastro Médico", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        txtCPF.Focus();
                        return;
                    }
                }
                paciente = repP.Buscar(txtCPF.Text);

                if (paciente == null)
                {
                    paciente = new Paciente();

                    paciente.CPF = txtCPF.Text;

                    if (txtNome.IsEmpty())
                    {
                        MessageBox.Show("Por favor digite um Nome", "Cadastro Médico", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        txtNome.Focus();
                        return;
                    }
                    else
                        paciente.Nome = txtNome.Text;

                    paciente.Endereco = txtEndereco.Text;
                    paciente.Numero = txtNumero.Text;
                    paciente.Cep = txtCEP.Text;
                    paciente.Uf = txtUf.Text;
                    paciente.Cidade = txtCidade.Text;
                    paciente.Telefone = txtTelefone.Text;
                    paciente.TelefoneCelular = txtCelular.Text;
                    paciente.DatInc = DateTime.Now;

                    repP.Adicionar(paciente);
                }
                else
                {
                    if (txtNome.IsEmpty())
                    {
                        MessageBox.Show("Por favor digite um Nome", "Cadastro Médico", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        txtNome.Focus();
                        return;
                    }
                    else
                        paciente.Nome = txtNome.Text;

                    paciente.Endereco = txtEndereco.Text;
                    paciente.Numero = txtNumero.Text;
                    paciente.Cep = txtCEP.Text;
                    paciente.Uf = txtUf.Text;
                    paciente.Cidade = txtCidade.Text;
                    paciente.Telefone = txtTelefone.Text;
                    paciente.TelefoneCelular = txtCelular.Text;
                }
                repP.Salvar();
                if (gdvPaciente.SelectedRows.Count == 0 && txtCPF.Enabled)
                {
                    MessageBox.Show(string.Format("Paciente {0} adicionado com sucesso", paciente.Nome));

                    gdvPaciente.DataSource = repP.Listar(x => x.dataExclusao == null)
                                                 .OrderByDescending(x => x.DatInc)
                                                 .Take(10)
                                                 .Select(x => new { x.CPF, x.Nome, x.Cep, x.Uf, x.Cidade, x.Endereco, x.Telefone })
                                                 .ToList();
                }
                else
                {
                    MessageBox.Show(string.Format("Médico {0} alterado com sucesso", paciente.Nome));
                    btnConsulta_Click(sender, e);
                }

                var txts = this.GetTodosControles(typeof(TextBox));

                foreach (var item in txts)
                {
                    item.Text = "";
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Erro ao Salvar", "Cadastro Paciente", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {

                var rep = new Fiap.Persistencia.Hospital.DAO.Repositorio<MaterialMedicamento>();
                var material = new MaterialMedicamento();
                if (gdvMateriais.SelectedRows.Count > 0)
                {
                    var id = int.Parse(gdvMateriais.SelectedRows[0].Cells[0].Value.ToString());
                    material = rep.Buscar(id);
                }
                if (material == null)
                    material = new MaterialMedicamento();

                if (txtNome.IsEmpty())
                {
                    MessageBox.Show("Por favor digite um nome", "Cadastro Materiais e Medicamentos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtNome.Focus();
                    return;

                }
                else
                    material.Nome = txtNome.Text;

                if (txtSaldo.IsEmpty())
                {
                    MessageBox.Show("Por favor digite um Saldo", "Cadastro Materiais e Medicamentos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtSaldo.Focus();
                    return;

                }
                else
                    material.Saldo = Convert.ToInt32(txtSaldo.Text);

                if (txtValorUnitario.IsEmpty())
                {
                    MessageBox.Show("Por favor digite um Valor Unitario", "Cadastro Materiais e Medicamentos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtValorUnitario.Focus();
                    return;

                }
                else
                {
                    material.ValorUnit = Convert.ToDecimal(txtValorUnitario.Text);
                }

                if (cboTipo.SelectedValue.ToString().CInt() > 0)
                {
                    material.Tipo = short.Parse(cboTipo.SelectedValue.ToString());
                    //material.TipoMaterialMedicamento = new TipoMaterialMedicamento()
                    //{
                    //    IdTipo = Convert.ToInt16(cboTipo.SelectedValue),
                    //    Descricao = cboTipo.Text
                    //};
                }
                else
                {
                    MessageBox.Show("Por favor selecione um tipo.", "Cadastro Materiais e Medicamentos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    cboTipo.Focus();
                    return;
                }

                //novo tratamento
                if (material.IdMaterialMedicamento == 0)
                {
                    material.DatInc = DateTime.Now;
                    rep.Adicionar(material);
                }

                rep.Salvar();

                if (gdvMateriais.SelectedRows.Count == 0)
                    MessageBox.Show(string.Format("Material/Medicamento {0} adicionado com sucesso", material.Nome));
                else
                    MessageBox.Show(string.Format("Material/Medicamento {0} alterado com sucesso", material.Nome));

                gdvMateriais.DataSource = rep.Listar().OrderByDescending(x => x.DatInc)
                                .Take(10)
                                 .Select(x => new
                                 {
                                     ID = x.IdMaterialMedicamento,
                                     Material = x.Nome,
                                     Tipo = x.TipoMaterialMedicamento.Descricao,
                                     x.Saldo,
                                     x.ValorUnit,
                                     ValorTotal = x.Saldo * x.ValorUnit
                                 })
                                .ToList();

                gdvMateriais.ClearSelection();

                var txts = this.GetTodosControles(typeof(TextBox));

                foreach (var item in txts)
                {
                    item.Text = "";
                    item.Enabled = true;
                }

                cboTipo.SelectedIndex = 0;

            }
            catch (Exception)
            {
                MessageBox.Show("Erro ao Salvar", "Cadastro Materiais e Medicamentos", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                Enfermeiro enfermeiro;

                var repM = new Fiap.Persistencia.Hospital.DAO.Repositorio<Enfermeiro>();

                if (txtCoren.IsEmpty() || !txtCoren.Text.IsNumeric())
                {
                    MessageBox.Show("Por favor digite um Coren válido", "Cadastro Enfermeiro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtCoren.Focus();
                    return;
                }

                enfermeiro = repM.Buscar(txtCoren.Text);

                if (enfermeiro == null)
                {
                    enfermeiro = new Enfermeiro();

                    enfermeiro.Coren = txtCoren.Text;

                    if (txtNome.IsEmpty())
                    {
                        MessageBox.Show("Por favor digite um Nome", "Cadastro Enfermeiro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        txtNome.Focus();
                        return;
                    }
                    else
                        enfermeiro.Nome = txtNome.Text;

                    ;

                    if (txtCPF.IsEmpty())
                    {
                        MessageBox.Show("Por favor digite um email", "Cadastro Enfermeiro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        txtCPF.Focus();
                        return;
                    }
                    else
                    {
                        if (Valida.IsCpf(txtCPF.Text))
                            enfermeiro.CPF = txtCPF.Text;
                        else
                        {
                            MessageBox.Show("Por favor digite um CPF válido", "Cadastro Enfermeiro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            txtCPF.Focus();
                            return;
                        }
                    }

                    enfermeiro.DatInc = DateTime.Now;

                    repM.Adicionar(enfermeiro);
                }
                else
                {

                    if (txtNome.IsEmpty())
                    {
                        MessageBox.Show("Por favor digite um Nome", "Cadastro Enfermeiro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        txtNome.Focus();
                        return;
                    }
                    else
                        enfermeiro.Nome = txtNome.Text;

                    if (txtCPF.IsEmpty())
                    {
                        MessageBox.Show("Por favor digite um email", "Cadastro Enfermeiro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        txtCPF.Focus();
                        return;
                    }
                    else
                    {
                        if (Valida.IsCpf(txtCPF.Text))
                            enfermeiro.CPF = txtCPF.Text;
                        else
                        {
                            MessageBox.Show("Por favor digite um CPF válido", "Cadastro Enfermeiro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            txtCPF.Focus();
                            return;
                        }
                    }

                }

                    repM.Salvar();

                    if (gdvEnfermeiro.SelectedRows.Count == 0 && txtCoren.Enabled)
                    {
                        MessageBox.Show(string.Format("Enfermeiro {0} adicionado com sucesso", enfermeiro.Nome));
                        gdvEnfermeiro.DataSource = repM.Listar()
                                                    .OrderByDescending(x => x.DatInc)
                                                    .Take(10)
                                                    .Select(x => new { x.Coren, x.Nome,x.CPF })
                                                    .ToList();
                    }
                    else
                    {
                        MessageBox.Show(string.Format("Enfermeiro {0} alterado com sucesso", enfermeiro.Nome));
                        btnConsulta_Click(sender, e);
                    }

                    btnNovo_Click(sender, e);

            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro ao Salvar", "Cadastro Enfermeiro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {

                var rep = new Fiap.Persistencia.Hospital.DAO.Repositorio<Tratamento>();
                var tratamento = new Tratamento();
                if (gdvTratamento.SelectedRows.Count > 0)
                {
                    var id = int.Parse(gdvTratamento.SelectedRows[0].Cells[1].Value.ToString());
                    tratamento = rep.Buscar(id);
                }
                if (tratamento == null)
                    tratamento = new Tratamento();

                if (txtNome.IsEmpty())
                {
                    MessageBox.Show("Por favor digite um nome", "Cadastro Tratamento", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtNome.Focus();
                    return;
                }
                else
                    tratamento.Nome = txtNome.Text;

                if (txtValor.IsEmpty())
                {
                    MessageBox.Show("Por favor digite um Valor", "Cadastro Tratamento", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtValor.Focus();
                    return;
                }
                else
                    tratamento.Valor = Convert.ToDecimal(txtValor.Text);

                if (cboEspecialidade.SelectedValue != "" && cboEspecialidade.SelectedValue != null)
                {
                    tratamento.IdEspecialidade = Convert.ToInt32(cboEspecialidade.SelectedValue);
                    //tratamento.Especializacao = new Especializacao()
                    //{
                    //    IdEspecializacao = Convert.ToInt32(cboEspecialidade.SelectedValue),
                    //    Nome = cboEspecialidade.Text
                    //};
                }
                else
                {
                    MessageBox.Show("Por favor selecione um tipo de especialidade.", "Cadastro Tratamento", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    cboEspecialidade.Focus();
                    return;
                }

                //novo tratamento
                if (tratamento.IdTratamento==0)
                {
                    tratamento.DatInc = DateTime.Now;
                    rep.Adicionar(tratamento);
                }

                rep.Salvar();

                MessageBox.Show(string.Format("Tratamento  {0} adicionado com sucesso", tratamento.Nome));

                gdvTratamento.DataSource = rep.Listar(x=> x.dataExclusao==null)
                                              .Take(10)
                                              .OrderByDescending(x => x.DatInc)
                                              .Select(x => new
                                              {
                                                  Especialização = x.Especializacao.Nome,
                                                  x.IdTratamento,
                                                  x.Nome,
                                                  x.Valor
                                              })
                                              .ToList();

                gdvTratamento.ClearSelection();

                var txts = this.groupBox1.GetTodosControles(typeof(TextBox));

                foreach (var item in txts)
                {
                    item.Text = "";
                    item.Enabled = true;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Erro ao Salvar", "Cadastro Tratamento", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void cboEspecialidade_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                int id = Convert.ToString(cboEspecialidade.SelectedValue).CInt();

                if (id > 0)
                {
                    var repE = new Fiap.Persistencia.Hospital.DAO.Repositorio<MedicoEspecializacao>(true);

                    var esp = repE.Listar(x => x.IdEspecializacao == id)
                                  .OrderBy(x => x.Medico.Nome)
                                  .Select(x => new { x.IdMedicoEspecializacao, Descricao = x.Medico.Nome })
                                  .ToList();

                    if (esp != null)
                    {
                        esp.Insert(0, new { IdMedicoEspecializacao = 0, Descricao = "Selecione" });
                        cboMedicoEspecialidade.Carrega(esp, "Descricao", "IdMedicoEspecializacao");
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Erro ao carregar encontrado", "Cadastro Agendamento", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void gdvEspecializacao_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0 && e.RowIndex >= 0)
            {
                try
                {
                    var result = MessageBox.Show("Deseja remover a Espcialidade " +
                                                 gdvEspecializacao.Rows[e.RowIndex].Cells[2].Value.ToString(),
                        "Especialidade",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question);

                    if (result.ToString() == "Yes")
                    {
                        var rep = new Fiap.Persistencia.Hospital.DAO.Repositorio<Especializacao>();
                        var id = int.Parse(gdvEspecializacao.Rows[e.RowIndex].Cells[1].Value.ToString());
                        rep.Remover(rep.Buscar(id));
                        rep.Salvar();
                        gdvEspecializacao.DataSource = rep.Listar().Select(x => new { x.IdEspecializacao, x.Nome }).ToList();
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Essa especialidade não pode ser excluída","Especialidade",MessageBoxButtons.OK,MessageBoxIcon.Information);
                }
            }
        }
        /// <summary>
        /// Carrega o tipo de especialização.
        /// </summary>
        private void CarregaTipo()
        {
            try
            {
                var rep = new Fiap.Persistencia.Hospital.DAO.Repositorio<Especializacao>();

                var dados = rep.Listar().ToList();

                cboEspecialidade.Carrega(dados, "Nome", "IdEspecializacao");

                var dados2 = rep.Listar().ToList();

                cboConsultaEspecialidade.Carrega(dados2, "Nome", "IdEspecializacao");
            }
            catch (Exception)
            {
                MessageBox.Show("Erro ao carregar os tipos", "Cadastro Tratamento", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void CarregaCombos()
        {
            try
            {
                var repC = new Fiap.Persistencia.Hospital.DAO.Repositorio<Convenio>();
                var convenio = repC.Listar(x=> x.dataExclusao==null)
                                   .Select(x => new
                                   {
                                       x.IdConvenio,
                                       Descricao = x.Operadora + " - " + x.Plano + " - " + x.Acomodacao
                                   })
                                   .OrderBy(x => x.Descricao)
                                   .ToList();
                convenio.Insert(0, new { IdConvenio = 0, Descricao = "Selecione" });
                cboConvenio.Carrega(convenio.OrderBy(x => x.IdConvenio).ToList(), "Descricao", "IdConvenio");
                repC.Dispose();

                cboConvenio.SelectedIndex = 0;

                //_____________________
                cboEspecialidade.SelectedIndexChanged -= cboEspecialidade_SelectedIndexChanged;
                var repE = new Fiap.Persistencia.Hospital.DAO.Repositorio<Especializacao>();
                var esp = repE.Listar(x => x.dataExclusao == null)
                              .OrderBy(x => x.IdEspecializacao)
                              .Select(x => new { x.IdEspecializacao, Descricao = x.Nome })
                              .ToList();
                esp.Insert(0, new { IdEspecializacao = 0, Descricao = "Selecione" });
                cboEspecialidade.Carrega(esp, "Descricao", "IdEspecializacao");
                repE.Dispose();
                cboEspecialidade.SelectedIndex = 0;
                cboEspecialidade.SelectedIndexChanged += cboEspecialidade_SelectedIndexChanged;
            }
            catch (Exception)
            {
                MessageBox.Show("Erro ao carregar combo", "Cadastro agenda", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void CarregaListBox()
        {
            var rep = new Fiap.Persistencia.Hospital.DAO.Repositorio<MaterialMedicamento>();

            ((ListBox)ckcListaMedicamentos).DataSource = rep.Listar().ToList();
            ((ListBox)ckcListaMedicamentos).DisplayMember = "Nome";
            ((ListBox)ckcListaMedicamentos).ValueMember = "IdMaterialMedicamento";
        }
        /// <summary>
        /// Carregas the tipo.
        /// </summary>
        private void CarregaTipo()
        {
            try
            {

                var rep = new Fiap.Persistencia.Hospital.DAO.Repositorio<TipoAcesso>();

                var dados =  rep.Listar().ToList();

                cboTipo.Carrega(dados, "Descricao", "IdTipoAcesso");

            }
            catch (Exception)
            {

                MessageBox.Show("Por favor digite uma senha válida ou confirme", "Cadastro Usuário", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                var rep = new Fiap.Persistencia.Hospital.DAO.Repositorio<Convenio>();

                Convenio convenio = new Convenio();
                if (gdvConvenio.SelectedRows.Count > 0)
                {
                    var id = gdvConvenio.SelectedRows[0].Cells[0].Value.ToString().CInt();

                    convenio = rep.Buscar(id);
                    if (convenio == null)
                    {
                        MessageBox.Show("O elemento seleciona não foi encontrado", "Cadastro convênio", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;

                    }

                }

                if (txtOperadora.IsEmpty())
                {
                    MessageBox.Show("Por favor digite uma operadora", "Cadastro Convenio", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtOperadora.Focus();
                    return;
                }
                else
                    convenio.Operadora = txtOperadora.Text;

                if (cboAcomodacao.SelectedIndex <= 0)
                {
                    MessageBox.Show("Por favor selecione uma acomodação", "Cadastro Convenio", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    cboAcomodacao.Focus();
                    return;
                }
                else
                    convenio.Acomodacao = cboAcomodacao.Text;

                if (txtPlano.IsEmpty())
                {
                    MessageBox.Show("Por favor digite um  plano", "Cadastro Convenio", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtPlano.Focus();
                    return;
                }
                else
                    convenio.Plano = txtPlano.Text;

                if (txtDesconto.IsEmpty())
                {
                    MessageBox.Show("Por favor digite o desconto do Convênio", "Cadastro Convenio", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtDesconto.Focus();
                    return;
                }
                else
                    convenio.Desconto = decimal.Parse(txtDesconto.Text);

                convenio.TelefoneOperadora = txtTelefone.Text;

                if (convenio.IdConvenio == 0)
                    rep.Adicionar(convenio);
                rep.Salvar();

                if (gdvConvenio.SelectedRows.Count > 0)
                    MessageBox.Show(string.Format("Convenio {0} adicionado com sucesso", convenio.Operadora));
                else
                    MessageBox.Show(string.Format("Convenio {0} alterado com sucesso", convenio.Operadora));

                gdvConvenio.DataSource = rep.Listar().OrderByDescending(x => x.IdConvenio)
                                                .Take(10)
                                                 .Select(x => new { x.IdConvenio, x.Operadora, x.Plano, x.Acomodacao, x.Desconto })
                                                .ToList();

                gdvConvenio.ClearSelection();

                var txts = this.GetTodosControles(typeof(TextBox));

                foreach (var item in txts)
                {
                    item.Text = "";
                    item.Enabled=true;
                }

                cboAcomodacao.SelectedIndex = 0;

            }
            catch (Exception)
            {

                MessageBox.Show("Erro ao salvar convenio", "Cadastro Convênio", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }