private void alergiasPaciente()
        {
            try
            {
                conn.Open();
                com.Connection = conn;
                SqlCommand cmd = new SqlCommand("select alergia.Nome, alergiaP.data, alergiaP.observacoes from AlergiaPaciente alergiaP JOIN Alergia alergia ON alergia.IdAlergia = AlergiaP.IdAlergia WHERE IdPaciente = @IdPaciente ", conn);
                cmd.Parameters.AddWithValue("@IdPaciente", paciente.IdPaciente);
                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    string data = DateTime.ParseExact(reader["data"].ToString(), "dd/MM/yyyy HH:mm:ss", null).ToString("dd/MM/yyyy");

                    DoencaPaciente doencaPaciente = new DoencaPaciente
                    {
                        nome        = (string)reader["Nome"],
                        data        = data,
                        observacoes = (string)reader["observacoes"],
                    };
                    listaAlergiaPacientes.Add(doencaPaciente);
                }
                conn.Close();
                UpdateDataGridViewAlergias();
            }
            catch (Exception)
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                MessageBox.Show("Por erro interno é impossível visualizar os dados das alergias!", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        private void UpdateDataGridView()
        {
            try
            {
                alergiasPacientes.Clear();
                conn.Open();
                com.Connection = conn;
                SqlCommand cmd = new SqlCommand("select alergia.Nome, alergiaP.data, alergiaP.observacoes from AlergiaPaciente alergiaP JOIN Alergia alergia ON alergia.IdAlergia = AlergiaP.IdAlergia WHERE IdPaciente = @IdPaciente ORDER BY alergiaP.data, alergia.Nome", conn);
                cmd.Parameters.AddWithValue("@IdPaciente", paciente.IdPaciente);
                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    string data = DateTime.ParseExact(reader["data"].ToString(), "dd/MM/yyyy HH:mm:ss", null).ToString("dd/MM/yyyy");

                    DoencaPaciente doencaPaciente = new DoencaPaciente
                    {
                        nome        = (string)reader["Nome"],
                        data        = data,
                        observacoes = (string)reader["observacoes"],
                    };
                    alergiasPacientes.Add(doencaPaciente);
                }
                var bindingSource1 = new System.Windows.Forms.BindingSource {
                    DataSource = alergiasPacientes
                };
                dataGridViewAlergias.DataSource            = bindingSource1;
                dataGridViewAlergias.Columns[0].HeaderText = "Alergia";
                dataGridViewAlergias.Columns[1].HeaderText = "Data de Diagnóstico";
                dataGridViewAlergias.Columns[2].HeaderText = "Observações";

                conn.Close();
                dataGridViewAlergias.Update();
                dataGridViewAlergias.Refresh();
            }
            catch (Exception)
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                MessageBox.Show("Por erro interno é impossível selecionar as alergias do paciente!", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }