public void UploadEmoteValues(EmoteInfo aEmoteInfo) { string query = "UPDATE emoteinfo SET CurrentValue = " + aEmoteInfo.GetValue() + ", LowestValue = " + aEmoteInfo.GetLowestValue() + ", HighestValue = " + aEmoteInfo.GetHighestValue() + ", AmountBought = " + aEmoteInfo.GetAmountBought() + ", AmountSold = " + aEmoteInfo.GetAmountSold() + ", Average = " + aEmoteInfo.GetAverage() + " WHERE EmoteName = '" + aEmoteInfo.GetName() + "'"; MySqlCommand cmd = new MySqlCommand(query, m_Connection); if (m_Connection.Ping() == false) { m_Connection.Open(); } cmd.ExecuteNonQuery(); this.CloseConnection(); return; }
public bool SellEmote(EmoteInfo aEmoteInfo, float aAmount, string aUsername) { //Update the user amount for that emote int ID = GetUserID(aUsername); string queryEmoteCost = "SELECT CurrentValue FROM emoteinfo WHERE EmoteName = '" + aEmoteInfo.GetName() + "'"; float emoteCost = -1; string queryCheckIfEmoteInDB = "SELECT COUNT(EmoteName) FROM emoteinfo WHERE EmoteName = '" + aEmoteInfo.GetName() + "'"; MySqlCommand cmdCost = new MySqlCommand(queryEmoteCost, m_Connection); MySqlCommand cmdCheck = new MySqlCommand(queryCheckIfEmoteInDB, m_Connection); if (m_Connection.Ping() == false) { m_Connection.Open(); } if (Convert.ToInt32(cmdCheck.ExecuteScalar()) == 0) { Console.WriteLine("Tried looking for an emote, but it does not exist in the database"); return(false); } emoteCost = Convert.ToSingle(cmdCost.ExecuteScalar()); float userMoney = GetMoney(aUsername); //Check if user is even in the database for moneywise if (userMoney == -1) { return(false); } float totalSellValue; totalSellValue = aAmount * aEmoteInfo.GetValue(); //Check for error if (totalSellValue <= 0) { Console.WriteLine("Error: sell value is less than 0, something went wrong"); Console.WriteLine("Emote Value: " + aEmoteInfo.GetValue()); return(false); } //Check if they have enough in the database string queryCheckSellAmount = "SELECT Amount FROM emotecount WHERE EmoteName = '" + aEmoteInfo.GetName() + "' AND DatabaseUserID = " + ID; MySqlCommand cmdGetAmountOfEmote = new MySqlCommand(queryCheckSellAmount, m_Connection); if (m_Connection.Ping() == false) { m_Connection.Open(); } float emoteAmount = Convert.ToSingle(cmdGetAmountOfEmote.ExecuteScalar()); if (emoteAmount < aAmount) { Console.WriteLine("Not enough emotes to sell."); this.CloseConnection(); return(false); } //Update the amount of that emote that was bought aEmoteInfo.SetAmountSold(aEmoteInfo.GetAmountSold() + aAmount); userMoney += totalSellValue; SetMoney(aUsername, userMoney); //Effect market value float valueDecrease; valueDecrease = aEmoteInfo.GetValue() / totalSellValue; aEmoteInfo.SetValue(aEmoteInfo.GetValue() - valueDecrease); if (m_Connection.Ping() == false) { m_Connection.Open(); } string queryUpdateUserAmount = "UPDATE emotecount SET Amount = Amount - " + aAmount + " WHERE EmoteName = '" + aEmoteInfo.GetName() + "' AND DatabaseUserID = " + ID; MySqlCommand cmdUpdateUserEmoteData = new MySqlCommand(queryUpdateUserAmount, m_Connection); cmdUpdateUserEmoteData.ExecuteNonQuery(); this.CloseConnection(); return(true); }