Exemplo n.º 1
0
        /// <summary>
        /// Lista os pacientes de acordo com um filtro para o nome.
        /// </summary>
        /// <param name="filtro">Filtro para o nome.</param>
        /// <returns>Um DataSet tipado contendo os dados dos pacientes encontrados.</returns>
        public PacienteDs ListarPacientes(string filtro)
        {
            SqlConnection conn       = new SqlConnection(this.connectionStr);
            PacienteDs    pacienteDs = new PacienteDs();

            try
            {
                SqlDataAdapter adapter = new SqlDataAdapter("ListarPacientes", conn);
                adapter.SelectCommand.CommandType = CommandType.StoredProcedure;

                // parâmetros
                adapter.SelectCommand.Parameters.Add("@Filtro", SqlDbType.NVarChar, 100).Value = filtro;

                // preenche dataSet
                adapter.Fill(pacienteDs, pacienteDs.Paciente.TableName);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }

            return(pacienteDs);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Realiza listagem dos pacientes.
        /// </summary>
        private void ListarPacientes()
        {
            this.lstPacientes.DataSource = null;

            try
            {
                // componente de negócio
                PacienteBc pacienteBc = new PacienteBc();

                // lista pacientes
                PacienteDs pacienteDs = pacienteBc.ListarPacientes(this.txtNome.Text);

                // data bind
                this.lstPacientes.DataSource    = pacienteDs.Paciente;
                this.lstPacientes.DisplayMember = "Nome";
                this.lstPacientes.ValueMember   = "CodigoPaciente";
            }
            catch (Exception ex)
            {
                string strMessage = this.resourceMgr.GetString(ex.Message);

                if (strMessage == null)
                {
                    FrmErro frmErro = new FrmErro();
                    frmErro.Mensagem = ex.Message;
                    frmErro.ShowDialog(this);
                    frmErro.Dispose();
                }
                else
                {
                    FrmErro frmErro = new FrmErro();
                    frmErro.Mensagem = strMessage;
                    frmErro.ShowDialog(this);
                    frmErro.Dispose();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Criação de um paciente.
        /// </summary>
        private void btnCriar_Click(object sender, EventArgs e)
        {
            if (!ValidarCampos())
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                // componente de negócio
                PacienteBc pacienteBc = new PacienteBc();

                // dataSet do paciente
                PacienteDs pacienteDs = new PacienteDs();
                this.pacienteRow = pacienteDs.Paciente.NewPacienteRow();

                // valores dos controles
                this.pacienteRow.Nome                = this.txtNome.Text;
                this.pacienteRow.CPF                 = this.mtxtCPF.Text;
                this.pacienteRow.DataNascimento      = this.dtpDataNascimento.Value;
                this.pacienteRow.Endereco            = this.txtEndereco.Text;
                this.pacienteRow.Complemento         = this.txtComplemento.Text;
                this.pacienteRow.Bairro              = this.txtBairro.Text;
                this.pacienteRow.CEP                 = this.mtxtCEP.Text;
                this.pacienteRow.Cidade              = this.txtCidade.Text;
                this.pacienteRow.Estado              = this.cmbEstado.Text;
                this.pacienteRow.Sexo                = (this.cmbSexo.SelectedIndex == 1);
                this.pacienteRow.Nacionalidade       = this.txtNacionalidade.Text;
                this.pacienteRow.Email               = this.txtEmail.Text;
                this.pacienteRow.TelefoneResidencial = this.txtFoneResidencial.Text;
                this.pacienteRow.TelefoneComercial   = this.txtFoneComercial.Text;
                this.pacienteRow.TelefoneCelular     = this.txtFoneCelular.Text;
                this.pacienteRow.Observacoes         = this.txtObservacoesGerais.Text;

                // cria o paciente
                this.pacienteRow.CodigoPaciente = pacienteBc.CriarPaciente(this.pacienteRow);

                // muda o estado
                MudarEstado(Estado.Mostrando);
            }
            catch (Exception ex)
            {
                string strMessage = this.resourceMgr.GetString(ex.Message);

                if (strMessage == null)
                {
                    FrmErro frmErro = new FrmErro();
                    frmErro.Mensagem = ex.Message;
                    frmErro.ShowDialog(this);
                    frmErro.Dispose();
                }
                else
                {
                    FrmErro frmErro = new FrmErro();
                    frmErro.Mensagem = strMessage;
                    frmErro.ShowDialog(this);
                    frmErro.Dispose();
                }
            }

            Cursor.Current = Cursors.Default;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Busca por um paciente.
        /// </summary>
        /// <param name="codigoPaciente">Código do paciente.</param>
        /// <returns>Um DataSet tipado contendo os dados do paciente.</returns>
        public PacienteDs.PacienteRow BuscarPaciente(int codigoPaciente)
        {
            SqlConnection conn = new SqlConnection(this.connectionStr);
            SqlCommand    cmd  = new SqlCommand("BuscarPaciente", conn);

            cmd.CommandType = CommandType.StoredProcedure;

            // cria paciente
            PacienteDs pacienteDs = new PacienteDs();

            PacienteDs.PacienteRow pacienteRow = pacienteDs.Paciente.NewPacienteRow();

            // parâmetros
            cmd.Parameters.Add("@CodigoPaciente", SqlDbType.Int).Value           = codigoPaciente;
            cmd.Parameters.Add("@Nome", SqlDbType.NVarChar, 200).Direction       = ParameterDirection.Output;
            cmd.Parameters.Add("@CPF", SqlDbType.NChar, 11).Direction            = ParameterDirection.Output;
            cmd.Parameters.Add("@DataNascimento", SqlDbType.DateTime).Direction  = ParameterDirection.Output;
            cmd.Parameters.Add("@Endereco", SqlDbType.NVarChar, 200).Direction   = ParameterDirection.Output;
            cmd.Parameters.Add("@Complemento", SqlDbType.NVarChar, 40).Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@Bairro", SqlDbType.NVarChar, 100).Direction     = ParameterDirection.Output;
            cmd.Parameters.Add("@CEP", SqlDbType.NChar, 8).Direction             = ParameterDirection.Output;
            cmd.Parameters.Add("@Cidade", SqlDbType.NVarChar, 100).Direction     = ParameterDirection.Output;
            cmd.Parameters.Add("@Estado", SqlDbType.NChar, 2).Direction          = ParameterDirection.Output;
            cmd.Parameters.Add("@Sexo", SqlDbType.Bit).Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@Nacionalidade", SqlDbType.NVarChar, 50).Direction       = ParameterDirection.Output;
            cmd.Parameters.Add("@Email", SqlDbType.NVarChar, 80).Direction               = ParameterDirection.Output;
            cmd.Parameters.Add("@TelefoneResidencial", SqlDbType.NVarChar, 30).Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@TelefoneComercial", SqlDbType.NVarChar, 30).Direction   = ParameterDirection.Output;
            cmd.Parameters.Add("@TelefoneCelular", SqlDbType.NVarChar, 30).Direction     = ParameterDirection.Output;
            cmd.Parameters.Add("@Observacoes", SqlDbType.NVarChar, 1000).Direction       = ParameterDirection.Output;

            try
            {
                // abre conexão
                conn.Open();

                // executa comando
                cmd.ExecuteNonQuery();

                // dados do paciente
                pacienteRow.CodigoPaciente      = codigoPaciente;
                pacienteRow.Nome                = (string)cmd.Parameters["@Nome"].Value;
                pacienteRow.CPF                 = (string)cmd.Parameters["@CPF"].Value;
                pacienteRow.DataNascimento      = (DateTime)cmd.Parameters["@DataNascimento"].Value;
                pacienteRow.Endereco            = (string)cmd.Parameters["@Endereco"].Value;
                pacienteRow.Complemento         = (string)cmd.Parameters["@Complemento"].Value;
                pacienteRow.Bairro              = (string)cmd.Parameters["@Bairro"].Value;
                pacienteRow.CEP                 = ((string)cmd.Parameters["@CEP"].Value).Trim();
                pacienteRow.Cidade              = (string)cmd.Parameters["@Cidade"].Value;
                pacienteRow.Estado              = (string)cmd.Parameters["@Estado"].Value;
                pacienteRow.Sexo                = (bool)cmd.Parameters["@Sexo"].Value;
                pacienteRow.Nacionalidade       = (string)cmd.Parameters["@Nacionalidade"].Value;
                pacienteRow.Email               = (string)cmd.Parameters["@Email"].Value;
                pacienteRow.TelefoneResidencial = (string)cmd.Parameters["@TelefoneResidencial"].Value;
                pacienteRow.TelefoneComercial   = (string)cmd.Parameters["@TelefoneComercial"].Value;
                pacienteRow.TelefoneCelular     = (string)cmd.Parameters["@TelefoneCelular"].Value;
                pacienteRow.Observacoes         = (string)cmd.Parameters["@Observacoes"].Value;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }

            return(pacienteRow);
        }