Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. public class VoteP
  2. {
  3. const string conn = "server=localhost;username=root;password=123456;database=cq;";
  4. public static string InsertVOTE(string ip, uint uid)
  5. {
  6. bool CanVote = true;
  7. using (MySqlConnection cn = new MySqlConnection(conn))
  8. {
  9. cn.Open();
  10. bool Search = false;
  11. using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM votes WHERE IP=@ip", cn))
  12. {
  13. cmd.Parameters.AddWithValue("@ip", ip);
  14. using (MySqlDataReader rdr = cmd.ExecuteReader())
  15. {
  16. if (rdr.Read())
  17. {
  18. DateTime date = rdr.GetDateTime("LastVote");
  19. if (DateTime.Now < date.AddHours(12))
  20. CanVote = false;
  21. }
  22. else
  23. Search = true;
  24.  
  25. }
  26. if (CanVote)
  27. {
  28. using (MySqlCommand cm2 = new MySqlCommand("UPDATE votes SET Claimed = 0 , LastVote=@d ,UID=@uid WHERE IP=@ip", cn))
  29. {
  30. cm2.Parameters.AddWithValue("@ip", ip);
  31. cm2.Parameters.AddWithValue("@uid", uid);
  32. cm2.Parameters.AddWithValue("@d", DateTime.Now);
  33. cm2.ExecuteNonQuery();
  34. }
  35. }
  36. if (Search)
  37. {
  38. using (MySqlCommand cm2 = new MySqlCommand("INSERT into votes VALUES(@ip,@date,0,@uid)", cn))
  39. {
  40. cm2.Parameters.AddWithValue("@ip", ip);
  41. cm2.Parameters.AddWithValue("@date", DateTime.Now);
  42. cm2.Parameters.AddWithValue("@uid", uid);
  43. cm2.ExecuteNonQuery();
  44. }
  45. }
  46. }
  47. }
  48. if (CanVote)
  49. return "You can now go claim your prize !";
  50. else
  51. return "You already voted.<br /> Vote tomorrow.";
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement