/// <summary> /// Get the info for the player out of the database and return in /// </summary> /// <param name="tag">The GamerTag of the player</param> /// <returns>PlayerInfo for the gamer</returns> private PlayerInfo GetPlayerInfo(String tag) { BattleBoatsDataSet dataset = new BattleBoatsDataSet(); PlayerInfo info = new PlayerInfo(); String select = "SELECT * FROM PlayerInfo WHERE UserName = \'" + tag + "\'"; SqlCeDataAdapter adapter = new SqlCeDataAdapter(select, conn); adapter.Fill(dataset, "PlayerInfo"); if (dataset.PlayerInfo.Rows.Count == 0)//New user, create table entries for them { BattleBoatsDataSet.PlayerInfoRow playerrow = dataset.PlayerInfo.NewPlayerInfoRow(); playerrow.UserName = tag; playerrow.AmmoUpgrades = 0; playerrow.ArmourUpgrades = 0; playerrow.Money = 0; playerrow.SpeedUpgrades = 0; playerrow.ShipModel = "Basic"; dataset.PlayerInfo.AddPlayerInfoRow(playerrow); SqlCeCommandBuilder builder = new SqlCeCommandBuilder(adapter); builder.QuotePrefix = "["; builder.QuoteSuffix = "]"; adapter.Update(dataset, "PlayerInfo"); } info.PlayerName = dataset.PlayerInfo[0].UserName; info.Ammo_Level = dataset.PlayerInfo[0].AmmoUpgrades; info.Armour_Level = dataset.PlayerInfo[0].ArmourUpgrades; info.Money = dataset.PlayerInfo[0].Money; info.Speed_Level = dataset.PlayerInfo[0].SpeedUpgrades; info.Ship_Model_Name = dataset.PlayerInfo[0].ShipModel; return info; }
/// <summary> /// Update the databse for a player /// </summary> /// <param name="newInfo"></param> private void UpdatePlayerInfo(PlayerInfo newInfo) { BattleBoatsDataSet dataset = new BattleBoatsDataSet(); PlayerInfo info = new PlayerInfo(); String select = "SELECT * FROM PlayerInfo WHERE UserName = \'" + newInfo.PlayerName + "\'"; SqlCeDataAdapter adapter = new SqlCeDataAdapter(select, conn); adapter.Fill(dataset, "PlayerInfo"); SqlCeCommandBuilder builder = new SqlCeCommandBuilder(adapter); string update = builder.GetUpdateCommand().CommandText; if (dataset.PlayerInfo.Rows.Count == 1)//New user, create table entries for them { dataset.PlayerInfo.Rows[0]["UserName"] = newInfo.PlayerName; dataset.PlayerInfo.Rows[0]["AmmoUpgrades"] = newInfo.Ammo_Level; dataset.PlayerInfo.Rows[0]["ArmourUpgrades"] = newInfo.Armour_Level; dataset.PlayerInfo.Rows[0]["Money"] = newInfo.Money; dataset.PlayerInfo.Rows[0]["SpeedUpgrades"] = newInfo.Speed_Level; dataset.PlayerInfo.Rows[0]["ShipModel"] = newInfo.Ship_Model_Name; adapter.Update(dataset, "PlayerInfo"); } }