public static List <PlayerDefesas> SelectAllByPlayer(PlayerDefesas obj) { //idplayer = idplauer SqlConnection conexao = new SqlConnection(); SqlCommand command = new SqlCommand(); conexao.ConnectionString = BLO.Conexao.ObterStringConexao2(); StringBuilder select = new StringBuilder(); select.AppendLine("SET DATEFORMAT dmy;"); select.AppendLine("select ID,IdPlayer,NomeOponente,NomeGuilda,Vitoria,DataHora from dbo.PlayerDefesas "); select.AppendLine("where IdPlayer = @IdPlayer"); command.Parameters.Add(new SqlParameter("@IdPlayer", System.Data.SqlDbType.BigInt)); command.Parameters["@IdPlayer"].Value = obj.IdPlayer; command.CommandText = select.ToString(); command.CommandType = System.Data.CommandType.Text; PlayerDefesas objPlayerDefesa; List <PlayerDefesas> objRetorno = new List <PlayerDefesas>(); conexao.Open(); command.Connection = conexao; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { objPlayerDefesa = new PlayerDefesas(); objPlayerDefesa.ID = long.Parse(reader["ID"].ToString()); objPlayerDefesa.DataHora = DateTime.Parse(reader["DataHora"].ToString()); objPlayerDefesa.IdPlayer = long.Parse(reader["IdPlayer"].ToString()); objPlayerDefesa.NomeGuilda = reader["NomeGuilda"].ToString(); objPlayerDefesa.NomeOponente = reader["NomeOponente"].ToString(); objPlayerDefesa.Player = DAO_Player._SelectByID(new Player() { ID = Convert.ToInt32(obj.IdPlayer) }); objPlayerDefesa.Vitoria = int.Parse(reader["Vitoria"].ToString()); objRetorno.Add(objPlayerDefesa); } conexao.Close(); conexao.Dispose(); return(objRetorno); }
public static PlayerStatus _SelectByID(PlayerStatus obj) { SqlConnection conexao = new SqlConnection(); SqlCommand command = new SqlCommand(); conexao.ConnectionString = BLO.Conexao.ObterStringConexao2(); StringBuilder select = new StringBuilder(); select.AppendLine("SET DATEFORMAT dmy;"); select.AppendLine("select id, IdPlayer,IdBatalha,Status from dbo.PlayerStatus "); select.AppendLine("where IdBatalha = @IdBatalha and IdPlayer=@IdPlayer"); command.Parameters.Add(new SqlParameter("@IdBatalha", System.Data.SqlDbType.BigInt)); command.Parameters["@IdBatalha"].Value = obj.IdBatalha; command.Parameters.Add(new SqlParameter("@IdPlayer", System.Data.SqlDbType.BigInt)); command.Parameters["@IdPlayer"].Value = obj.IdPlayer; command.CommandText = select.ToString(); command.CommandType = System.Data.CommandType.Text; PlayerStatus objPlayerStatus = new PlayerStatus(); conexao.Open(); command.Connection = conexao; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { objPlayerStatus = new PlayerStatus(); objPlayerStatus.ID = long.Parse(reader["ID"].ToString()); objPlayerStatus.IdBatalha = long.Parse(reader["IdBatalha"].ToString()); objPlayerStatus.IdPlayer = long.Parse(reader["IdPlayer"].ToString()); objPlayerStatus.Player = DAO_Player._SelectByID(new Player() { ID = Convert.ToInt32(obj.IdPlayer) }); objPlayerStatus.Status = reader["Status"].ToString(); //TODO: Batalhas //objPlayerStatus.Batalhas } conexao.Close(); conexao.Dispose(); return(objPlayerStatus); }