public Agenda ObterAgendamentoPorCodigo(int Codigo, int CodigoClinica) { Agenda Agenda = new Agenda(); using (FbConnection Conexao = new FbConnection(Firebird.StringConexao)) { try { Conexao.Open(); string TxtSQL = @" SELECT * FROM AGENDA INNER JOIN PACIENTE ON (A_PACIENTE = P_CODIGO) INNER JOIN TRATAMENTO ON (A_TRATAMENTO = T_CODIGO) INNER JOIN USUARIO ON (A_PROFISSIONAL = U_CODIGO) WHERE A_CODIGO =@A_CODIGO AND A_CLINICA =@A_CLINICA"; using (FbCommand cmdSelect = new FbCommand(TxtSQL, Conexao)) { cmdSelect.Parameters.AddWithValue("A_CODIGO", Codigo); cmdSelect.Parameters.AddWithValue("A_CLINICA", CodigoClinica); using (FbDataReader drSelect = cmdSelect.ExecuteReader()) { if (drSelect.Read()) { Agenda.Codigo = drSelect.GetInt32(drSelect.GetOrdinal("A_CODIGO")); Agenda.Paciente = new Paciente() { Codigo = drSelect.GetInt32(drSelect.GetOrdinal("P_CODIGO")), Nome = drSelect.GetString(drSelect.GetOrdinal("P_NOME")) }; Agenda.Titulo = Agenda.Paciente.Nome; Agenda.DataHoraInicial = DateTime.Parse(string.Concat(drSelect.GetString(drSelect.GetOrdinal("A_DATAINICIAL")).Replace("00:00:00", drSelect.GetString(drSelect.GetOrdinal("A_HORAINICIAL"))))); Agenda.DataHoraFinal = DateTime.Parse(string.Concat(drSelect.GetString(drSelect.GetOrdinal("A_DATAFINAL")).Replace("00:00:00", drSelect.GetString(drSelect.GetOrdinal("A_HORAFINAL"))))); Agenda.BgColor = drSelect.GetString(drSelect.GetOrdinal("A_BGCOLOR")); Agenda.TextColor = drSelect.GetString(drSelect.GetOrdinal("A_TEXTCOLOR")); Agenda.Tratamento = new Models.Tratamento { Codigo = drSelect.GetInt32(drSelect.GetOrdinal("T_CODIGO")), Descricao = drSelect.GetString(drSelect.GetOrdinal("T_DESCRICAO")) }; Agenda.Status = drSelect.GetString(drSelect.GetOrdinal("A_STATUS")); Agenda.Profissional = new Usuario() { Codigo = drSelect.GetInt32(drSelect.GetOrdinal("U_CODIGO")), Nome = drSelect.GetString(drSelect.GetOrdinal("U_NOME")), Email = drSelect.GetString(drSelect.GetOrdinal("U_EMAIL")) }; } } } } finally { Conexao.Close(); } } return(Agenda); }
public void CarregarAgendamentos(int CodigoClinica, int CodigoProfissional = 0) { Agenda a = new Agenda(); this.Agendamentos = a.ObterAgendamentos(CodigoClinica, this.Codigo, CodigoProfissional); }