Example #1
0
        protected void LoadAnswerList(Prediction prediction)
        {
            if (prediction != null)
            {
                radList.DataSource     = prediction.PredictionAnswerses;
                radList.DataTextField  = "AnswerText";
                radList.DataValueField = "Id";
                radList.DataBind();

                PredictionGameUser pgu = PredictionGameUser;
                if (pgu != null && pgu.PredictionGameUserDetailses != null)
                {
                    foreach (PredictionGameUserDetail detail in pgu.PredictionGameUserDetailses)
                    {
                        if (detail.Prediction != null && detail.Prediction.Id == prediction.Id)
                        {
                            if (detail.PredictionAnswer != null)
                            {
                                ListItem item = radList.Items.FindByValue(detail.PredictionAnswer.Id.ToString());
                                if (item != null)
                                {
                                    item.Selected = true;
                                }
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        protected void rptPrediction_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item ||
                e.Item.ItemType == ListItemType.AlternatingItem)
            {
                PredictionGameUser pu = e.Item.DataItem as PredictionGameUser;
                Literal            litTotalQuestion = e.Item.FindControl("litTotalQuestion") as Literal;
                Literal            litRightAnswer   = e.Item.FindControl("litRightAnswer") as Literal;
                Literal            litBonusPoint    = e.Item.FindControl("litBonusPoint") as Literal;
                Literal            litOnSiteTime    = e.Item.FindControl("litOnSiteTime") as Literal;
                if (litTotalQuestion != null)
                {
                    litTotalQuestion.Text = pu.PredictionGameUserDetailses.Count.ToString("N0");
                }

                if (litRightAnswer != null)
                {
                    if (pu.PredictionGame != null && pu.PredictionGame.IsCalculate)
                    {
                        int count = 0;
                        foreach (PredictionGameUserDetail detail in pu.PredictionGameUserDetailses)
                        {
                            if (detail.Prediction != null)
                            {
                                PredictionAnswer rightAnswer = detail.Prediction.PredictionAnswerses.Cast <PredictionAnswer>().Where(p => p.IsCorrectAnswer).FirstOrDefault();
                                if (rightAnswer != null && detail.PredictionAnswer != null && rightAnswer.Id == detail.PredictionAnswer.Id)
                                {
                                    count++;
                                }
                            }
                        }
                        litRightAnswer.Text = count.ToString("N0");
                    }
                    else
                    {
                        litRightAnswer.Text = "Đang cập nhật";
                    }
                }

                if (litBonusPoint != null)
                {
                    if (pu.PredictionGame != null && pu.PredictionGame.IsCalculate)
                    {
                        litBonusPoint.Text = pu.WinPoint.ToString("N0");
                    }
                    else
                    {
                        litBonusPoint.Text = "Đang cập nhật";
                    }
                }

                if (litOnSiteTime != null)
                {
                    litOnSiteTime.Text = string.Format("{0} phút {1} giây", (pu.Time / 60), (pu.Time % 60));
                }
            }
        }
Example #3
0
        protected void LoadData()
        {
            string key = string.Format("Prediction-{0}", Guid.NewGuid().ToString());

            hfCache.Value = key;

            // load setting
            BizPredictionGameSettings settings = TNHelper.GetPredictionGameSettings();

            if (settings != null && settings.Timer > 0)
            {
                hfTimer.Value = settings.Timer.ToString();
                pnlQuestion.Attributes["style"] = "display: none";
            }

            // check user already play this game
            User user = Utils.GetCurrentUser();
            PredictionGameUser pgu = TNHelper.GetPredictionGameUserByGameId(settings.PredictionGameID, user.Id);

            prePlayedInfo.Visible = false;

            if (pgu != null)
            {
                PredictionGameUser               = pgu;
                prePlayedInfo.Visible            = true;
                divContainer.Attributes["class"] = "invisible " + divContainer.Attributes["class"];
            }

            // load radom question and save to cache
            PredictionGame pgame = TNHelper.GetCurrentPredictionGame();

            if (pgame != null && pgame.Predictionses.Count > 0)
            {
                Prediction prediction = pgame.Predictionses[0] as Prediction;
                LoadAnswerList(prediction);
                litQuestion.Text = prediction.PredictionName;
                litInfo.Text     = string.Format("Bạn đang trả lời câu hỏi {0}/{1}", 1, pgame.Predictionses.Count);
                CMSCache.Insert(key, pgame);

                hfIndex.Value = "0";
                hfTotal.Value = pgame.Predictionses.Count.ToString();

                hfID.Value = prediction.Id.ToString();
            }
            else
            {
                Utils.ShowMessage(lblMsg, "Mời bạn quay lại sau, bạn vui lòng xem thông báo ở cột bên phải để biết thêm chi tiết.");
                divContainer.Visible  = false;
                prePlayedInfo.Visible = false;
            }
        }
Example #4
0
        private void UpdateAnswer(PredictionGameUser pgu)
        {
            PredictionGameUser pre = DomainManager.GetObject <PredictionGameUser>(PredictionGameUser.Id);

            if (pre != null)
            {
                foreach (PredictionGameUserDetail detail in pre.PredictionGameUserDetailses)
                {
                    if (detail.Prediction != null)
                    {
                        PredictionGameUserDetail tmp = pgu.PredictionGameUserDetailses.Cast <PredictionGameUserDetail>().Where(p => p.Prediction.Id == detail.Prediction.Id).FirstOrDefault();
                        if (tmp != null)
                        {
                            detail.PredictionAnswer = tmp.PredictionAnswer;
                        }
                    }
                }

                DomainManager.Update(pre);
            }
        }
Example #5
0
        protected void rptPrediction_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item ||
                e.Item.ItemType == ListItemType.AlternatingItem)
            {
                BizPredictionGameSettings setting = TNHelper.GetPredictionGameSettings();
                PredictionGameUser        pu      = e.Item.DataItem as PredictionGameUser;
                Literal  litTotalQuestion         = e.Item.FindControl("litTotalQuestion") as Literal;
                Literal  litRightAnswer           = e.Item.FindControl("litRightAnswer") as Literal;
                Literal  litBonusPoint            = e.Item.FindControl("litBonusPoint") as Literal;
                Literal  litOnSiteTime            = e.Item.FindControl("litOnSiteTime") as Literal;
                Repeater rptPDetail      = e.Item.FindControl("rptPDetail") as Repeater;
                Literal  litPDetail      = e.Item.FindControl("litPDetail") as Literal;
                Panel    pnlPopupPDetail = e.Item.FindControl("pnlPopupPDetail") as Panel;

                if (litTotalQuestion != null)
                {
                    litTotalQuestion.Text = pu.PredictionGameUserDetailses.Count.ToString("N0");
                }

                if (litRightAnswer != null)
                {
                    if (pu.PredictionGame != null && pu.PredictionGame.IsCalculate)
                    {
                        int count = 0;
                        foreach (PredictionGameUserDetail detail in pu.PredictionGameUserDetailses)
                        {
                            if (detail.Prediction != null)
                            {
                                PredictionAnswer rightAnswer = detail.Prediction.PredictionAnswerses.Cast <PredictionAnswer>().Where(p => p.IsCorrectAnswer).FirstOrDefault();
                                if (rightAnswer != null && detail.PredictionAnswer != null && rightAnswer.Id == detail.PredictionAnswer.Id)
                                {
                                    count++;
                                }
                            }
                        }
                        litRightAnswer.Text = count.ToString("N0");
                    }
                    else
                    {
                        litRightAnswer.Text = "Đang cập nhật";
                    }
                }

                if (litBonusPoint != null)
                {
                    if (pu.PredictionGame != null && pu.PredictionGame.IsCalculate)
                    {
                        litBonusPoint.Text = pu.WinPoint.ToString("N0");
                    }
                    else
                    {
                        litBonusPoint.Text = "Đang cập nhật";
                    }
                }

                if (litOnSiteTime != null)
                {
                    litOnSiteTime.Text = string.Format("{0} phút {1} giây", (pu.Time / 60), (pu.Time % 60));
                }

                if (litPDetail != null)
                {
                    litPDetail.Text = string.Format("<a class='fancybox' href='#p{0}'>Chi tiết</a>", pu.Id);
                }

                if (rptPDetail != null && pu.PredictionGameUserDetailses != null)
                {
                    rptPDetail.DataSource     = pu.PredictionGameUserDetailses.Cast <PredictionGameUserDetail>();
                    rptPDetail.ItemDataBound += new RepeaterItemEventHandler(rptPDetail_ItemDataBound);
                    rptPDetail.DataBind();
                }
            }
        }
Example #6
0
        private void SavePlayGame()
        {
            User curenttUser = Utils.GetCurrentUser();

            curenttUser = DomainManager.GetObject <User>(curenttUser.Id);

            string         cacheKey = hfCache.Value;
            PredictionGame pgame    = CMSCache.Get(cacheKey) as PredictionGame;

            if (curenttUser != null && pgame != null)
            {
                PredictionGameUser pgu = new PredictionGameUser();
                pgu.PlayDate       = DateTime.Now;
                pgu.PredictionGame = pgame;
                pgu.User           = curenttUser;

                TimeSpan?onsiteTime = null;
                if (Page.Session[TNHelper.PredictionStarTimeKey] is DateTime)
                {
                    onsiteTime = DateTime.Now - (DateTime)Page.Session[TNHelper.PredictionStarTimeKey];
                    pgu.Time   = onsiteTime.Value.Seconds;
                }

                if (pgame != null && pgame.Predictionses.Count > 0)
                {
                    foreach (Prediction p in pgame.Predictionses.Cast <Prediction>().ToList())
                    {
                        int        answerValue = GetUserAnswer(p);
                        Prediction prediction  = DomainManager.GetObject <Prediction>(p.Id);

                        if (answerValue >= 0)
                        {
                            PredictionGameUserDetail detail = new PredictionGameUserDetail();
                            detail.PredictionGameUser = pgu;
                            detail.Prediction         = prediction;
                            detail.PredictionAnswer   = DomainManager.GetObject <PredictionAnswer>(answerValue);
                            pgu.PredictionGameUserDetailses.Add(detail);
                        }
                    }
                }

                if (PredictionGameUser is PredictionGameUser)
                {
                    if (pgu.PredictionGame != null)
                    {
                        UpdateAnswer(pgu);
                        TNHelper.LogAction(LogType.PredictionLog, string.Format("Cập nhận đáp án cho bộ đề <b>{0}</b>", pgu.PredictionGame.PredictionGameName));
                    }
                }
                else
                {
                    if (pgu.PredictionGame != null)
                    {
                        DomainManager.Insert(pgu);
                        TNHelper.LogAction(LogType.PredictionLog, "Chơi game thử tài dự đoán");
                    }
                }

                // remove all relate cache
                Utils.ResetCurrentUser();
                CMSCache.RemoveByPattern(cacheKey);
            }
        }