public void AddPurchase(WeaponPurchases w) { string sql = "INSERT INTO weapon_purchases (playerId, waponId) VALUES (@playerId, @weaponId)"; using (SqlCommand cmd = new SqlCommand(sql, conn)) { cmd.Parameters.AddWithValue("@playerId", w.PlayerId); cmd.Parameters.AddWithValue("@weaponId", w.WeaponId); int affectedRows = cmd.ExecuteNonQuery(); Debug.Log(affectedRows + " rows inserted!"); } }
public void BuyWeapon3() { decimal totCoin; decimal.TryParse(totalCoin.text, out totCoin); decimal laserP; decimal.TryParse(laserPrice.text, out laserP); if (totCoin <= 0 || totCoin < laserP) { weapon3Gun.onClick.RemoveListener(BuyWeapon3); weapon3Gun.onClick.AddListener(NoCoin); } else { try { totCoin = totCoin - laserP; weapon3GunText.text = "Equip"; weapon3Gun.onClick.RemoveListener(BuyWeapon3); weapon3Gun.onClick.AddListener(EquipWeapon); GlobalUserStats.logUser.TotalCoins = totCoin; db.UpdateTotalMoney(GlobalUserStats.logUser); WeaponPurchases w = new WeaponPurchases(GlobalUserStats.logUser.ID, 1); db.AddPurchase(w); shopPanel.SetActive(false); errorMessage.SetActive(true); mesTitle.text = "Weapon Buy"; mesMessage.text = "You have successfully bought this weapon.\n To equip it click the EQUIP button."; mesButton.onClick.AddListener(LoadBack); totalCoin.text = totCoin + ""; } catch (SqlException ex) { shopPanel.SetActive(false); errorMessage.SetActive(true); mesTitle.text = "SQL Error"; mesMessage.text = ex.Message; } } }
public List <WeaponPurchases> GetAllPurchaseForPlayer(int playerId) { List <WeaponPurchases> result = new List <WeaponPurchases>(); using (SqlCommand command = new SqlCommand("SELECT * FROM weapon_purchases WHERE playerId = @playerId", conn)) { command.Parameters.AddWithValue("@playerId", playerId); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { int id = (int)reader["id"]; int playerID = (int)reader["playerId"]; int weaponId = (int)reader["waponId"]; WeaponPurchases w = new WeaponPurchases(id, playerID, weaponId); result.Add(w); //Debug.LogFormat("{0},{1},{2},{3}", id, playerID, weaponId); } return(result); } } }