Beispiel #1
0
        protected void imgbtn_cardOne_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["User"] != null)
            {
                user = (UserObject)Session["User"];

                cardBattle = dataController.getCardBattleToday();

                if (cardBattle != null && (int)cardBattle.cardBattleId == cardBattleID)
                {
                    int? cardPickId = dataController.insertCardPick((int)user.userId, (int)cardBattle.cardBattleId, (int)cardBattle.cardOne.cardId);

                    if (cardPickId != null)
                    {
                        lbl_popupMessage.Text = "Thank you for voting!";
                        popupext_vote.Show();
                    }
                    else
                    {
                        lbl_popupMessage.Text = "There was an error with your vote.  Please contact an admin for support.";
                        popupext_vote.Show();
                    }
                }
                else
                {
                    lbl_popupMessage.Text = "This battle is no longer available for voting.";
                    popupext_vote.Show();
                }
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Adds or updates a battle
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_addBattle_Click(object sender, EventArgs e)
        {
            CardBattleObject cardBattle = new CardBattleObject();

            cardBattle.cardBattleId = cardBattleID;
            cardBattle.cardOne = dataController.getCard(Convert.ToInt32(drpdwn_cardOne.SelectedValue));
            cardBattle.cardTwo = dataController.getCard(Convert.ToInt32(drpdwn_cardTwo.SelectedValue));
            cardBattle.battleDate = DateTime.ParseExact(txt_battleDate.Text, "MMM dd, yyyy", null);

            if (dataController.checkIfBattleDateAvailable((DateTime)cardBattle.battleDate))
            {
                if (cardBattleID == -1)
                {
                    int? newCardBattleId = dataController.insertCardBattle(cardBattle);

                    if (newCardBattleId != null)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "SuccessfulInsert", "alert('Battle successfully created.'); window.location='Battle.aspx?ID=" + (int)newCardBattleId + "';", true);
                    }
                }

                else
                {
                    bool? successfulUpdate = dataController.updateCardBattle(cardBattle);

                    if (successfulUpdate != null && (bool)successfulUpdate)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "SuccessfulInsert", "alert('Battle successfully updated.'); window.location='Battle.aspx?ID=" + (int)cardBattle.cardBattleId + "';", true);
                    }
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ErrorInsert", "alert('Another battle is already scheduled on the selected date.');", true);
            }
        }
Beispiel #3
0
        private void loadBattle()
        {
            cardBattle = dataController.getCardBattleToday();

            if (cardBattle != null)
            {
                cardBattleID = (int)cardBattle.cardBattleId;

                lbl_cardOne.Text = cardBattle.cardOne.name;
                imgbtn_cardOne.ImageUrl = IMAGE_OPEN_LOCATION + (int)cardBattle.cardOne.cardId + "/" + cardBattle.cardOne.imageURL;
                imgbtn_cardOne.ToolTip = cardBattle.cardOne.description;
                imgbtn_cardOne.Visible = true;

                imgbtn_cardTwo.ImageUrl = IMAGE_OPEN_LOCATION + (int)cardBattle.cardTwo.cardId + "/" + cardBattle.cardTwo.imageURL;
                lbl_cardTwo.Text = cardBattle.cardTwo.name;
                imgbtn_cardTwo.ToolTip = cardBattle.cardTwo.description;
                imgbtn_cardTwo.Visible = true;

                img_vs.Visible = true;

                if (Session["User"] != null)
                {
                    user = (UserObject)Session["User"];

                    if (dataController.checkIfVotedToday((int)user.userId, (int)cardBattle.cardBattleId))
                    {
                        imgbtn_cardOne.OnClientClick = "return false;";
                        imgbtn_cardTwo.OnClientClick = "return false;";
                        conbtnext_cardOne.Enabled = false;
                        conbtnext_cardTwo.Enabled = false;

                        lbl_voteMessage.Text = "You have voted today!";
                    }
                }
                else
                {
                    imgbtn_cardOne.OnClientClick = "return false;";
                    imgbtn_cardTwo.OnClientClick = "return false;";
                    conbtnext_cardOne.Enabled = false;
                    conbtnext_cardTwo.Enabled = false;

                    lbl_voteMessage.Visible = false;
                    tblcell_login.Visible = true;
                }

                DateTime battleDate = (DateTime)cardBattle.battleDate;
                DateTime battleDateEnd = battleDate.AddDays(1);

                countDownClock.Attributes["src"] = clockURL + battleDateEnd.ToString("yyyy-MM-dd") + "T00:00:00";
                countDownClock.Visible = true;
                countDownClock.Attributes.Add("onclick", "return false;");
                //2014-05-08T00:00:00"
            }
            else
            {
                lbl_message.Text = "There is no battle today.";
                lbl_message.Visible = true;

                lbl_voteMessage.Visible = false;

                lbl_cardOne.Visible = false;
                lbl_cardTwo.Visible = false;
            }

            CardBattleObject cardBattleTomorrow = dataController.getCardBattleTomorrow();

            if (cardBattleTomorrow != null)
            {
                int cardBattleIDTomorrow = (int)cardBattleTomorrow.cardBattleId;

                //lbl_cardOne.Text = cardBattleTomorrow.cardOne.name;
                img_cardOneTomorrow.ImageUrl = IMAGE_OPEN_LOCATION + (int)cardBattleTomorrow.cardOne.cardId + "/" + cardBattleTomorrow.cardOne.imageURL;
                img_cardOneTomorrow.ToolTip = cardBattleTomorrow.cardOne.description;
                img_cardOneTomorrow.Visible = true;

                //lbl_cardTwo.Text = cardBattleTomorrow.cardTwo.name;
                img_cardTwoTomorrow.ImageUrl = IMAGE_OPEN_LOCATION + (int)cardBattleTomorrow.cardTwo.cardId + "/" + cardBattleTomorrow.cardTwo.imageURL;
                img_cardTwoTomorrow.ToolTip = cardBattleTomorrow.cardTwo.description;
                img_cardTwoTomorrow.Visible = true;

                tbl_tomorrowBattle.Visible = true;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Inserts a battle
        /// </summary>
        /// <param name="card"></param>
        /// <returns></returns>
        public int? insertCardBattle(CardBattleObject cardBattle)
        {
            openSQLConnection();

            int? cardBattleId = null;

            using (SqlCommand cmd = new SqlCommand("monbattle.InsertCardBattle", this.sqlConnection))
            {
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@BattleDate", SqlDbType.DateTime);
                cmd.Parameters["@BattleDate"].Value = cardBattle.battleDate;

                cmd.Parameters.Add("@CardOneID", SqlDbType.Int);
                cmd.Parameters["@CardOneID"].Value = cardBattle.cardOne.cardId;

                cmd.Parameters.Add("@CardTwoID", SqlDbType.Int);
                cmd.Parameters["@CardTwoID"].Value = cardBattle.cardTwo.cardId;

                SqlParameter parameter = cmd.Parameters.Add("@CardBattleID", SqlDbType.Int);
                parameter.Direction = ParameterDirection.Output;

                try
                {
                    cmd.ExecuteNonQuery();
                    cardBattleId = (int)cmd.Parameters["@CardBattleID"].Value;
                }
                catch (SqlException e)
                {
                    throw e;
                }
                finally
                {
                    closeSQLConnection();
                }
            }
            return cardBattleId;
        }
Beispiel #5
0
        /// <summary>
        /// Updates a card battle
        /// </summary>
        /// <param name="card"></param>
        /// <returns></returns>
        public bool? updateCardBattle(CardBattleObject cardBattle)
        {
            openSQLConnection();

            bool? updateSuccessful = false;

            using (SqlCommand cmd = new SqlCommand("monbattle.UpdateCard", this.sqlConnection))
            {
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@CardBattleID", SqlDbType.Int);
                cmd.Parameters["@CardBattleID"].Value = cardBattle.cardBattleId;

                cmd.Parameters.Add("@BattleDate", SqlDbType.DateTime);
                cmd.Parameters["@BattleDate"].Value = cardBattle.battleDate;

                cmd.Parameters.Add("@CardOneID", SqlDbType.Int);
                cmd.Parameters["@CardOneID"].Value = cardBattle.cardOne;

                cmd.Parameters.Add("@CardTwoID", SqlDbType.Int);
                cmd.Parameters["@CardTwoID"].Value = cardBattle.cardTwo;

                try
                {
                    cmd.ExecuteNonQuery();
                    updateSuccessful = true;
                }
                catch (SqlException e)
                {
                    throw e;
                }
                finally
                {
                    closeSQLConnection();
                }
            }
            return updateSuccessful;
        }
Beispiel #6
0
        private CardBattleObject getCardBattleHelper(SqlDataReader cardBattleResult)
        {
            CardBattleObject cardBattle = null;
            CardObject cardOne = null;
            CardObject cardTwo = null;

            if (cardBattleResult.Read())
            {
                int? CardBattleId = null;
                int? winnerCardId = null;
                DateTime? battleDate = null;
                int? cardOneVotes = null;
                int? cardTwoVotes = null;

                if (!cardBattleResult.IsDBNull(cardBattleResult.GetOrdinal("CardBattleID")))
                {
                    CardBattleId = cardBattleResult.GetInt32(cardBattleResult.GetOrdinal("CardBattleID"));
                }

                if (!cardBattleResult.IsDBNull(cardBattleResult.GetOrdinal("CardOneID")))
                {
                    int cardOneId = cardBattleResult.GetInt32(cardBattleResult.GetOrdinal("CardOneID"));
                    cardOne = getCard(cardOneId);
                }

                if (!cardBattleResult.IsDBNull(cardBattleResult.GetOrdinal("CardTwoID")))
                {
                    int cardTwoId = cardBattleResult.GetInt32(cardBattleResult.GetOrdinal("CardTwoID"));
                    cardTwo = getCard(cardTwoId);
                }

                if (!cardBattleResult.IsDBNull(cardBattleResult.GetOrdinal("WinnerCardID")))
                {
                    winnerCardId = cardBattleResult.GetInt32(cardBattleResult.GetOrdinal("WinnerCardID"));
                }

                if (!cardBattleResult.IsDBNull(cardBattleResult.GetOrdinal("BattleDate")))
                {
                    battleDate = cardBattleResult.GetDateTime(cardBattleResult.GetOrdinal("BattleDate"));
                }

                if (!cardBattleResult.IsDBNull(cardBattleResult.GetOrdinal("CardOneVotes")))
                {
                    cardOneVotes = cardBattleResult.GetInt32(cardBattleResult.GetOrdinal("CardOneVotes"));
                }

                if (!cardBattleResult.IsDBNull(cardBattleResult.GetOrdinal("CardTwoVotes")))
                {
                    cardTwoVotes = cardBattleResult.GetInt32(cardBattleResult.GetOrdinal("CardTwoVotes"));
                }

                cardBattle = new CardBattleObject(CardBattleId, battleDate, cardOne, cardTwo, winnerCardId, cardOneVotes, cardTwoVotes);
            }
            cardBattleResult.Close();
            return cardBattle;
        }
Beispiel #7
0
        /// <summary>
        /// Update a card battle
        /// </summary>
        /// <param name="cardBattle"></param>
        /// <returns></returns>
        public bool? updateCardBattle(CardBattleObject cardBattle)
        {
            bool? successfulUpdate = dataModel.updateCardBattle(cardBattle);

            return successfulUpdate;
        }
Beispiel #8
0
        /// <summary>
        /// Insert a new card battle
        /// </summary>
        /// <param name="cardBattle"></param>
        /// <returns></returns>
        public int? insertCardBattle(CardBattleObject cardBattle)
        {
            int? cardBattleId = dataModel.insertCardBattle(cardBattle);

            return cardBattleId;
        }