Commit 758f140f authored by NEBOIT Jean-Charles's avatar NEBOIT Jean-Charles
Browse files

Ajout des fonctions du TP1 depuis la BDD

parent 96ce9267
......@@ -11,17 +11,24 @@ namespace DataAccessLayer
{
class SqlServer : DataBaseBridge
{
private string _connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=\"H:\\Documents\\ThronesTournamentConsole\\Base de donnée\\db.mdf\";Integrated Security=True;Connect Timeout=30";
private string _connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=H:\\Documents\\ThronesTournamentConsole\\Database\\db.mdf;Integrated Security=True;Connect Timeout=30";
private DataTable SelectByDataAdapter(string request)
{
DataTable results = new DataTable();
using (SqlConnection sqlConnection = new SqlConnection(_connectionString))
{
SqlCommand sqlCommand = new SqlCommand(request, sqlConnection);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
sqlDataAdapter.Fill(results);
try
{
SqlCommand sqlCommand = new SqlCommand(request, sqlConnection);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
sqlDataAdapter.Fill(results);
}
catch (SqlException e)
{
Console.WriteLine(e.Message);
}
}
return results;
......@@ -31,12 +38,17 @@ namespace DataAccessLayer
{
List<Character> res = new List<Character>();
DataTable dataTable = SelectByDataAdapter("Select * From Charater");
DataTable dataTable = SelectByDataAdapter("Select * From Character");
foreach (DataRow row in dataTable.Rows)
{
// Character character = new Character(Convert.ToInt32(row["Id"]), row["FirstName"].ToString(), row[");
// res.Add(character);
int id_house = Convert.ToInt32(row["id_house"]);
DataTable houseData = SelectByDataAdapter("Select * From House Where Id=" + id_house);
DataRow houseRow = houseData.Rows[0];
House house = new House(Convert.ToInt32(houseRow["Id"]), houseRow["name"].ToString(), Convert.ToInt32(houseRow["nbUnits"]));
Character character = new Character(Convert.ToInt32(row["Id"]), row["FirstName"].ToString(), row["LastName"].ToString(), Convert.ToUInt32(row["PV"]), (CharacterType)Convert.ToInt32(row["Type"]), Convert.ToInt32(row["Bravoury"]), Convert.ToInt32(row["Crazyness"]), house);
res.Add(character);
}
return res;
......@@ -60,7 +72,8 @@ namespace DataAccessLayer
public List<Fight> FightsList()
{
throw new NotImplementedException();
List<Fight> res = new List<Fight>();
return res;
}
public List<House> HousesList()
......@@ -95,23 +108,38 @@ namespace DataAccessLayer
public List<Territory> TerritoriesList()
{
throw new NotImplementedException();
List<Territory> res = new List<Territory>();
DataTable dataTable = SelectByDataAdapter("Select * From Territory");
foreach (DataRow row in dataTable.Rows)
{
int id_house = Convert.ToInt32(row["id_house"]);
DataTable houseData = SelectByDataAdapter("Select * From House Where Id=" + id_house);
DataRow houseRow = houseData.Rows[0];
House owner = new House(Convert.ToInt32(houseRow["Id"]), houseRow["name"].ToString(), Convert.ToInt32(houseRow["nbUnits"]));
Territory territory = new Territory(Convert.ToInt32(row["Id"]), (TerritoryType)Convert.ToInt32(row["type"]), owner);
res.Add(territory);
}
return res;
}
public void addCharacter(Character character)
{
throw new NotImplementedException();
}
public void deleteCharacter(int id)
{
throw new NotImplementedException();
}
public void updateCharacter(Character character)
{
throw new NotImplementedException();
}
}
}
No preview for this file type
No preview for this file type
......@@ -18,8 +18,9 @@ namespace EntitiesLayer
public TerritoryType Type { get; set; }
public House Owner { get; set; }
public Territory(TerritoryType type, House owner)
public Territory(int id, TerritoryType type, House owner)
{
ID = id;
Type = type;
Owner = owner;
}
......
......@@ -47,8 +47,8 @@ namespace StubDataAccessLayer
Sansa.AddRelatives(Tyrion, RelationshipType.FRIENDSHIP);
Arya.AddRelatives(Sansa, RelationshipType.LOVE);
_territoryList.Add(new Territory(TerritoryType.MOUNTAIN, Lannister));
_territoryList.Add(new Territory(TerritoryType.LAND, Stark));
_territoryList.Add(new Territory(0, TerritoryType.MOUNTAIN, Lannister));
_territoryList.Add(new Territory(1, TerritoryType.LAND, Stark));
}
public List<House> HousesList()
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment