Пример #1
0
        public static string loyalty(string data)
        {
            string winner  = null;
            Random randNum = new Random();
            int    randomNumber;
            //temporary user list to enable looping
            List <entry <string, int, int> > eligibleUsers = loyaltyRaffle.Where(user => user.Won == 0 && !String.IsNullOrWhiteSpace(user.Name)).ToList();

            if (data.Equals("spin"))
            {
                //If the previous person wanted the prize (i.e. spin was hit again when there was already a winner), we need to update that the user won the prize in the db and then display the new image.
                if (loyaltyWinner.Name != null)
                {
                    if (!dbHelper("UPDATE kcgameon.prizes SET ClaimedBy = \'" + loyaltyWinner.Name + "\' WHERE Picture = \'" + prizeName + "\'"))
                    {
                        return("Fail");
                    }
                    imageSource = displayPrize();
                }
                if (eligibleUsers.Count > 0)
                {
                    randomNumber  = randNum.Next(eligibleUsers.Count);
                    loyaltyWinner = loyaltyRaffle.ElementAt(randomNumber);
                    var test = loyaltyRaffle.ElementAt(randomNumber);
                    winner  = userlist.Find(user => user.Username.ToUpper().Equals(loyaltyRaffle.ElementAt(randomNumber).Name.ToUpper())).First;
                    winner += " " + userlist.Find(user => user.Username.ToUpper().Equals(loyaltyRaffle.ElementAt(randomNumber).Name.ToUpper())).Last;

                    if (dbHelper("UPDATE kcgameon.EventArchive SET wonloyalty = 1 WHERE Username = \'" + loyaltyWinner.Name + "\' AND eventID = \'" + loyaltyWinner.Event + "\' LIMIT 1"))//actually commit the winner to DB, do we need to update prize table?
                    {
                        //if(dbHelper("UPDATE kcgameon.prizes SET ClaimedBy = \"" + loyaltyWinner.Name + "\" WHERE Prize = \"" + currentPrize + "\""))//TODO PRIZE
                        //loyaltyWinner.Name = null;
                        //return loyalty("skipSelection");//spin after committing
                        usersCheckedIn[loyaltyWinner.Name] = 1;
                        loyaltyRaffle.Single(t => t.Name.ToUpper().Equals(loyaltyWinner.Name.ToUpper()) && t.Event == loyaltyWinner.Event).Won = 1;
                        return(winner);
                    }
                    else
                    {
                        return("Fail");
                    }
                }
            }
            else if (data.Equals("skipSelection"))
            {
                if (loyaltyWinner.Name != null)
                {
                    if (dbHelper("UPDATE kcgameon.EventArchive SET wonloyalty = 2 WHERE Username = \'" + loyaltyWinner.Name + "\' AND eventID = \'" + loyaltyWinner.Event + "\' LIMIT 1"))
                    {
                        usersCheckedIn[loyaltyWinner.Name] = 2;

                        if (eligibleUsers.Count > 0)
                        {
                            randomNumber  = randNum.Next(eligibleUsers.Count);
                            loyaltyWinner = loyaltyRaffle.ElementAt(randomNumber);
                            winner        = userlist.Find(user => user.Username.ToUpper().Equals(loyaltyRaffle.ElementAt(randomNumber).Name.ToUpper())).First;
                            winner       += " " + userlist.Find(user => user.Username.ToUpper().Equals(loyaltyRaffle.ElementAt(randomNumber).Name.ToUpper())).Last;//Get user's first + last name
                            if (dbHelper("UPDATE kcgameon.EventArchive SET wonloyalty = 1 WHERE Username = \'" + loyaltyWinner.Name + "\' AND eventID = \'" + loyaltyWinner.Event + "\' LIMIT 1"))
                            {
                                usersCheckedIn[loyaltyWinner.Name] = 1;
                                return(winner);
                            }
                        }
                        else
                        {
                            return("Fail");
                        }
                    }
                    else
                    {
                        return("Fail");
                    }
                }
            }
            //else (data has a value not eqaul to NULL or skipSelection) AND (loyaltyWinner is null), which shoudln't ever happen, so just hit failure
            return("Fail");
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            userlist   = new List <UsersObject>();
            usernames  = new List <String>();
            firstnames = new List <String>();
            lastnames  = new List <String>();
            names      = new List <String>();
            populateEventDropdown();
            imageSource   = displayPrize();
            loyaltyWinner = new entry <string, int, int>();
            String          UserInfo = ConfigurationManager.ConnectionStrings["KcGameOnSQL"].ConnectionString;
            MySqlDataReader Reader   = null;
            MySqlCommand    cmd      = null;
            MySqlConnection conn     = null;

            try
            {
                conn = new MySqlConnection(UserInfo);
                conn.Open();
                userlist        = new List <UsersObject>();
                usernames       = new List <String>();
                firstnames      = new List <String>();
                lastnames       = new List <String>();
                names           = new List <String>();
                cmd             = new MySqlCommand("getUsers", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                IAsyncResult result = cmd.BeginExecuteReader();
                Reader = cmd.EndExecuteReader(result);
                //Reader = cmd.ExecuteReader();
                //DefaultHTML = new StringBuilder();

                while (Reader.Read())
                {
                    string      username = Reader.GetString("UserName").ToString();
                    string      first    = Reader.GetString("FirstName").ToString();
                    string      last     = Reader.GetString("LastName").ToString();
                    UsersObject newUser  = new UsersObject(username, first, last);
                    usernames.Add(username);
                    firstnames.Add(first);
                    lastnames.Add(last);
                    names.Add(first + ' ' + last);
                    userlist.Add(newUser);
                }
                Reader.Close();
                Reader = null;
                names.Sort();
                usernames.Sort();
                firstnames.Sort();
                lastnames.Sort();
                if (SessionVariables.UserName != null)
                {
                    if (current != null)
                    {
                        if (current.Username != SessionVariables.UserName)
                        {
                            foreach (var user in userlist)
                            {
                                if (user.Username == SessionVariables.UserName.ToLower())
                                {
                                    current = user;
                                }
                            }
                        }
                    }
                }

                //populate user table in admin page
                cmd             = new MySqlCommand("SELECT DISTINCT * FROM payTable WHERE eventID = (SELECT EventID FROM kcgameon.schedule WHERE Active = 1 order by ID LIMIT 1) AND verifiedPaid = \'Y\' AND activeIndicator=\'TRUE\'", new MySqlConnection(UserInfo));
                cmd.CommandType = System.Data.CommandType.Text;

                cmd.Connection.Open();
                Reader        = cmd.ExecuteReader();
                AdminUserHTML = new StringBuilder();

                while (Reader.Read())
                {
                    usersPaid.Add(Reader.GetString("userName"));
                }
                Reader.Close();

                foreach (UsersObject user in userlist)
                {
                    AdminUserHTML.AppendLine("<tr>");
                    AdminUserHTML.AppendLine("<td class=\"col-md-1\">").Append(user.Username).Append("</td>");

                    AdminUserHTML.AppendLine("<td class=\"col-md-1\">").Append(user.First).Append("</td>");
                    AdminUserHTML.AppendLine("<td class=\"col-md-1\">").Append(user.Last).Append("</td>");

                    if (usersPaid.Contains(user.Username))
                    {
                        AdminUserHTML.AppendLine("<td class=\"col-md-1\">").Append("<img src=\'/img/Button-Check-icon.png\' height=\"20px\" width=\"20px\"/>").Append("</td>");
                    }
                    else
                    {
                        AdminUserHTML.AppendLine("<td class=\"col-md-1\">").Append("<img src=\'/img/Actions-button-cancel-icon.png\' height=\"20px\" width=\"20px\"/>").Append("</td>");
                    }
                    AdminUserHTML.AppendLine("</tr>");
                }

                //raffle-populate user table in admin page
                cmd             = new MySqlCommand("select ea.Username, ua.FirstName, ua.LastName, ea.eventID, ea.wondoor, ea.wonloyalty from EventArchive ea inner join useraccount ua on ea.Username = ua.Username WHERE (eventID IN (SELECT EventID FROM kcgameon.schedule WHERE TournamentDate LIKE '%2016%' order by ID) OR eventID = '2016') and wondoor != 0 ", new MySqlConnection(UserInfo));
                cmd.CommandType = System.Data.CommandType.Text;

                cmd.Connection.Open();
                Reader     = cmd.ExecuteReader();
                RaffleHTML = new StringBuilder();

                while (Reader.Read())
                {
                    RaffleHTML.AppendLine("<tr>");
                    RaffleHTML.AppendLine("<td class=\"col-md-1\">").Append(Reader.GetString("Username")).Append("</td>");
                    RaffleHTML.AppendLine("<td class=\"col-md-1\">").Append(Reader.GetString("FirstName")).Append("</td>");
                    RaffleHTML.AppendLine("<td class=\"col-md-1\">").Append(Reader.GetString("LastName")).Append("</td>");
                    RaffleHTML.AppendLine("<td class=\"col-md-1\">").Append(Reader.GetString("eventID")).Append("</td>");
                    RaffleHTML.AppendLine("<td class=\"col-md-1\">").Append(Reader.GetString("wondoor")).Append("</td>");
                    RaffleHTML.AppendLine("<td class=\"col-md-1\">").Append(Reader.GetString("wonloyalty")).Append("</td>");
                    RaffleHTML.AppendLine("</tr>");
                }
                Reader.Close();

                //populate checked in users for raffle
                cmd             = new MySqlCommand("SELECT DISTINCT * FROM EventArchive WHERE eventID = (SELECT EventID FROM kcgameon.schedule WHERE Active = 1 order by ID LIMIT 1) AND checkedin = 1 AND activeIndicator = 1", new MySqlConnection(UserInfo));
                cmd.CommandType = System.Data.CommandType.Text;

                cmd.Connection.Open();
                Reader = cmd.ExecuteReader();


                while (Reader.Read())
                {
                    if (Reader["userName"] != DBNull.Value)
                    {
                        if (!usersCheckedIn.ContainsKey(Reader.GetString("userName")))
                        {
                            usersCheckedIn.Add(Reader.GetString("userName"), Reader.GetByte("wonloyalty"));
                        }
                    }
                }
                Reader.Close();

                //populate checked in users for loyalty event
                cmd             = new MySqlCommand("SELECT DISTINCT * FROM EventArchive WHERE eventID >=69 AND checkedin = 1 AND activeIndicator = 1;", new MySqlConnection(UserInfo));
                cmd.CommandType = System.Data.CommandType.Text;

                cmd.Connection.Open();
                Reader = cmd.ExecuteReader();


                while (Reader.Read())
                {
                    if (Reader["userName"] != DBNull.Value)
                    {
                        //If loyaltyRaffle does NOT have the existing userName and eventID pair, add it with
                        if (!(loyaltyRaffle.Any(entry => entry.Name.Contains(Reader.GetString("userName")) && entry.Event == Reader.GetInt32("eventID"))))
                        {
                            entry <string, int, int> user = new entry <string, int, int>();
                            user.Name = Reader.GetString("userName"); user.Event = Reader.GetInt32("eventID"); user.Won = Reader.GetByte("wonloyalty");
                            loyaltyRaffle.Add(user);
                        }
                    }
                }
                Reader.Close();
            }
            catch (Exception)
            {
            }
            finally
            {
                if (cmd.Connection != null)
                {
                    cmd.Connection.Close();
                }
                if (Reader != null)
                {
                    Reader.Close();
                }
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }