Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class VoteP
- {
- const string conn = "server=localhost;username=root;password=123456;database=cq;";
- public static string InsertVOTE(string ip, uint uid)
- {
- bool CanVote = true;
- using (MySqlConnection cn = new MySqlConnection(conn))
- {
- cn.Open();
- bool Search = false;
- using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM votes WHERE IP=@ip", cn))
- {
- cmd.Parameters.AddWithValue("@ip", ip);
- using (MySqlDataReader rdr = cmd.ExecuteReader())
- {
- if (rdr.Read())
- {
- DateTime date = rdr.GetDateTime("LastVote");
- if (DateTime.Now < date.AddHours(12))
- CanVote = false;
- }
- else
- Search = true;
- }
- if (CanVote)
- {
- using (MySqlCommand cm2 = new MySqlCommand("UPDATE votes SET Claimed = 0 , LastVote=@d ,UID=@uid WHERE IP=@ip", cn))
- {
- cm2.Parameters.AddWithValue("@ip", ip);
- cm2.Parameters.AddWithValue("@uid", uid);
- cm2.Parameters.AddWithValue("@d", DateTime.Now);
- cm2.ExecuteNonQuery();
- }
- }
- if (Search)
- {
- using (MySqlCommand cm2 = new MySqlCommand("INSERT into votes VALUES(@ip,@date,0,@uid)", cn))
- {
- cm2.Parameters.AddWithValue("@ip", ip);
- cm2.Parameters.AddWithValue("@date", DateTime.Now);
- cm2.Parameters.AddWithValue("@uid", uid);
- cm2.ExecuteNonQuery();
- }
- }
- }
- }
- if (CanVote)
- return "You can now go claim your prize !";
- else
- return "You already voted.<br /> Vote tomorrow.";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement