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 BuyEmote(EmoteInfo aEmoteInfo, float aAmount, string 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 totalCost; totalCost = aAmount * aEmoteInfo.GetValue(); //Check for error if (totalCost <= 0) { Console.WriteLine("Error: total cost is less than 0, something went wrong"); Console.WriteLine("Emote Value: " + aEmoteInfo.GetValue()); return(false); } //Check if user has enough money to buy that amount if (totalCost > userMoney) { Console.WriteLine("User does not have enough money to buy the amount they want"); Console.WriteLine("Total Cost: " + totalCost + " UserMoney: " + userMoney); return(false); } //Update the amount of that emote that was bought aEmoteInfo.SetAmountBought(aEmoteInfo.GetAmountBought() + aAmount); userMoney -= totalCost; userMoney *= -1; SetMoney(aUsername, userMoney); //Effect market value float valueIncrease; valueIncrease = aEmoteInfo.GetValue() / totalCost; aEmoteInfo.SetValue(aEmoteInfo.GetValue() + valueIncrease); //Update the user amount for that emote int ID = GetUserID(aUsername); //Make a query to check if we need to put that emote into the db for that user string queryCheckIfInEmoteCount = "SELECT COUNT(*) FROM emotecount WHERE EmoteName = '" + aEmoteInfo.GetName() + "' AND DatabaseUserID = " + ID; MySqlCommand cmdCheckEmoteCount = new MySqlCommand(queryCheckIfInEmoteCount, m_Connection); if (m_Connection.Ping() == false) { m_Connection.Open(); } if (Convert.ToInt32(cmdCheckEmoteCount.ExecuteScalar()) == 0) { /* * string queryUpdateEmoteCount = "INSERT INTO emotecount VALUES ('" + aEmoteInfo.GetName() + "', " + ID + ", 0)"; * MySqlCommand cmdUpdateEmoteCount = new MySqlCommand(queryUpdateEmoteCount, m_Connection); * * cmdUpdateEmoteCount.ExecuteNonQuery(); */ this.AddToEmoteCount(aUsername, aEmoteInfo.GetName()); } if (m_Connection.Ping() == false) { m_Connection.Open(); } string updateUserAmount = "UPDATE emotecount SET Amount = Amount + " + aAmount + " WHERE EmoteName = '" + aEmoteInfo.GetName() + "' AND DatabaseUserID = " + ID; MySqlCommand cmdUpdateUserEmoteData = new MySqlCommand(updateUserAmount, m_Connection); cmdUpdateUserEmoteData.ExecuteNonQuery(); this.CloseConnection(); return(true); }