public DTOUsuario GetDTO(string user, string pass) { DTOUsuario dto = new DTOUsuario(); if (UsuarioValido(user, pass)) { string sql = $@"SELECT * FROM usuario WHERE nome = '{user}' AND senha = '{pass}';"; My.ExecuteReader(sql); if (My.HasRows()) { My.ReadNextRecord(); dto.Id = My.GetInt("id"); dto.Nome = My.GetString("nome"); dto.Tipo = My.GetInt("tipo"); dto.Senha = My.GetString("senha"); } My.FechaConexao(); } else { dto = null; } return(dto); }
public int GetIdByName(string nome) { int id = 0; string sql = $@"SELECT id FROM MILITAR WHERE CONCAT(graduacao, ' ', nome) = '{nome}' ORDER BY id DESC LIMIT 1;"; My.ExecuteReader(sql); if (My.HasRows()) { My.ReadNextRecord(); id = My.GetInt("id"); } My.FechaConexao(); return(id); }
public ArrayList GetRelatorio(DateTime inicio, DateTime fim) { ArrayList array = new ArrayList(); string sql = $@"SELECT * FROM GERENCIAMENTO WHERE saida >= '{inicio.ToString("yyyy-MM-dd")}' AND saida <= '{fim.ToString("yyyy-MM-dd")} 23:59:59';"; My.ExecuteReader(sql); if (My.HasRows()) { while (My.ReadNextRecord()) { DTOGerenciamento dto = new DTOGerenciamento(); dto.Motivo = My.GetString("motivo"); dto.Saida = DateTime.ParseExact(My.GetString("saida"), "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); string retorno = My.GetString("retorno"); if (!string.IsNullOrEmpty(retorno)) { dto.Retorno = DateTime.ParseExact(My.GetString("retorno"), "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); } Militar militar = new Militar(); dto.DTOMilitar = militar.GetDTO(My.GetString("id_militar")); array.Add(dto); } } My.FechaConexao(); return(array); }