protected void LoadData()
        {
            // load setting
            BizQuestionGameSettings settings = TNHelper.GetQuestionGameSettings();

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

            // load radom question and save to cache
            QuestionGame qgame = TNHelper.GetCurrentQuestionGame();

            if (qgame != null && qgame.Questionses.Count > 0)
            {
                string key = string.Format("Question-{0}", Guid.NewGuid().ToString());
                CMSCache.Insert(key, qgame);

                Question question = qgame.Questionses[0] as Question;
                LoadAnswerList(question);
                litQuestion.Text = question.QuestionName;
                litInfo.Text     = string.Format("Bạn đang trả lời câu hỏi {0}/{1}", 1, qgame.Questionses.Count);

                hfIndex.Value = "0";
                hfTotal.Value = qgame.Questionses.Count.ToString();
                hfCache.Value = key;
                hfID.Value    = question.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;
            }
        }
Beispiel #2
0
    public void SetQuest(NumericDataType numericData, int questionVariant)
    {
        QuestionGame questionGame = new QuestionGame(numericData, questionVariant);

        questionData = questionGame.CreateQuestion();

        questionGameHolder.SetValue(questionData.value);
        questionGameHolder.SetQuestion(questionData.question);
        questionGameHolder.SetAnswers(questionData.answers);
        questionGameHolder.SetClickAction(OnCalculate);
    }
Beispiel #3
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            string strId = Page.RouteData.Values["id"] as string;
            int    id    = 0;

            int.TryParse(strId, out id);

            QuestionGame obj = DomainManager.GetObject <QuestionGame>(id);

            if (obj != null)
            {
                DomainManager.Delete(obj);
                string msg = Page.Server.UrlEncode("Xóa bộ đề game trả lời câu hỏi thành công");
                Page.Response.Redirect(string.Format("/admincp/question-list?msg={0}", msg), true);
            }
        }
 protected void rptQG_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Item ||
         e.Item.ItemType == ListItemType.AlternatingItem)
     {
         QuestionGame qgame     = e.Item.DataItem as QuestionGame;
         LinkButton   lnkDelete = e.Item.FindControl("lnkDelete") as LinkButton;
         if (lnkDelete != null)
         {
             BizQuestionGameSettings biz = TNHelper.GetQuestionGameSettings();
             if (biz != null && biz.QuestionGameID == qgame.Id)
             {
                 lnkDelete.OnClientClick = "aler('Bạn khổng thế xóa bộ đề vì nó đang được cấu hình cho game trả lời câu hỏi'); return false";
             }
         }
     }
 }
        protected void btnNext_Click(object sender, EventArgs e)
        {
            pnlQuestion.Attributes.Remove("style");
            int index = int.Parse(hfIndex.Value);
            int total = int.Parse(hfTotal.Value);

            if (index < total)
            {
                SaveCurrentDataToCache();
            }

            index++;
            if (index < total)
            {
                hfIndex.Value = index.ToString();
                litInfo.Text  = string.Format("Bạn đang trả lời câu hỏi {0}/{1}", (index + 1), total);
                radList.ClearSelection();

                string       key   = hfCache.Value;
                QuestionGame qgame = CMSCache.Get(key) as QuestionGame;

                if (qgame != null && qgame.Questionses.Count == total && index < total)
                {
                    Question question = qgame.Questionses[index] as Question;
                    LoadAnswerList(question);
                    litQuestion.Text = question.QuestionName;
                    hfID.Value       = question.Id.ToString();
                }
            }

            if (index + 1 == total)
            {
                btnNext.Text     = "Xem kết quả";
                btnNext.CssClass = "buttonL last";
            }

            if (index == total)
            {
                btnSubmit_Click(btnSubmit, e);
            }
            else
            {
                pnlQuestion.Visible = true;
                pnlSummary.Visible  = false;
            }
        }
Beispiel #6
0
        protected void LoadEditData()
        {
            string strId = Page.RouteData.Values["id"] as string;
            int    id    = 0;

            int.TryParse(strId, out id);

            QuestionGame obj = DomainManager.GetObject <QuestionGame>(id);

            if (obj != null)
            {
                BizQuestionGameSettings biz = TNHelper.GetQuestionGameSettings();
                bool isPermit = true;
                if (biz != null)
                {
                    isPermit = biz.QuestionGameID == obj.Id ? false : true;
                }

                btnDelete.Enabled = isPermit;
                btnSave.Enabled   = isPermit;
                trAdd.Visible     = isPermit;

                txtQGName.Text = obj.QuestionGameName;
                radYes.Checked = obj.Active;
                radNo.Checked  = !obj.Active;

                rptQuestion.DataSource = obj.Questionses;
                rptQuestion.DataBind();
            }
            else if (!string.IsNullOrEmpty(strId))
            {
                Utils.ShowMessage(lblMsg, "Không tìm thấy dữ liệu của bộ đề bạn yêu cầu");
            }

            LoadDefaultData();
            btnDelete.Visible = (id > 0);
        }
        protected void rptQG_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (string.Compare(e.CommandName, "delete", true) == 0)
            {
                int id = 0;
                int.TryParse(e.CommandArgument.ToString(), out id);

                QuestionGame            qgame = DomainManager.GetObject <QuestionGame>(id);
                BizQuestionGameSettings biz   = TNHelper.GetQuestionGameSettings();
                if (qgame != null)
                {
                    if (biz.QuestionGameID != qgame.Id)
                    {
                        DomainManager.Delete(qgame);
                        Utils.ShowMessage(lblMsgQG, "Xóa bộ đề game trả lời câu hỏi thành công");
                        LoadData();
                    }
                    else
                    {
                        Utils.ShowMessage(lblMsgQG, "Bộ đề này đang được sử dụng trong cấu hình game trả lời câu hỏi. Bạn không thể xóa bộ đề này.");
                    }
                }
            }
        }
Beispiel #8
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            #region Valid data

            if (txtQGName.Text.Trim().Length == 0)
            {
                Utils.ShowMessage(lblMsg, "Tên bộ đè không thể rỗng");
                return;
            }

            List <Question> lstQuestion = GetQuestionList();
            if (lstQuestion == null || (lstQuestion != null && lstQuestion.Count == 0))
            {
                Utils.ShowMessage(lblMsg, "Bạn chưa nhập câu hỏi");
                return;
            }

            #endregion

            if (Page.IsValid)
            {
                string strId = Page.RouteData.Values["id"] as string;
                int    id    = 0;
                int.TryParse(strId, out id);

                QuestionGame qgame = DomainManager.GetObject <QuestionGame>(id);
                if (qgame == null)
                {
                    qgame             = new QuestionGame();
                    qgame.CreatedDate = DateTime.Now;
                    qgame.User        = Utils.GetCurrentUser();
                }

                qgame.QuestionGameName = TextInputUtil.GetSafeInput(txtQGName.Text);
                qgame.Active           = radYes.Checked;

                if (qgame.Id > 0)
                {
                    DomainManager.Update(qgame);
                }
                else
                {
                    DomainManager.Insert(qgame);
                }

                // qgame = DomainManager.GetObject<QuestionGame>(qgame.Id);

                if (lstQuestion != null)
                {
                    for (int i = 0; i < lstQuestion.Count; i++)
                    {
                        Question question = lstQuestion[i];
                        if (question.Id == 0)
                        {
                            DomainManager.Insert(question);
                            question.QuestionGame = qgame;
                            qgame.Questionses.Add(question);
                        }
                        else // update data
                        {
                            Question tmpQ = qgame.Questionses.Cast <Question>().Where(p => p.Id == question.Id).FirstOrDefault();
                            if (tmpQ != null)
                            {
                                tmpQ.QuestionName = question.QuestionName;
                                tmpQ.BonusPoint   = question.BonusPoint;
                                foreach (Answer ans in question.Answerses.Cast <Answer>())
                                {
                                    Answer tmpA = tmpQ.Answerses.Cast <Answer>().Where(p => p.Id == ans.Id).FirstOrDefault();
                                    if (tmpA != null)
                                    {
                                        tmpA.AnswerText      = ans.AnswerText;
                                        tmpA.IsCorrectAnswer = ans.IsCorrectAnswer;
                                    }
                                }
                            }
                        }
                    }
                }

                string msg = string.Empty;
                if (qgame.Id > 0)
                {
                    DomainManager.Update(qgame);
                    msg = Page.Server.UrlEncode("Cập nhật bộ đề câu hỏi thành công");
                }
                else
                {
                    DomainManager.Insert(qgame);
                    msg = Page.Server.UrlEncode("Thêm bộ đề game trả lời câu hỏi thành công");
                }

                Page.Response.Redirect(string.Format("/admincp/question-list?msg={0}", msg), true);
            }
        }
        private void LoadData()
        {
            pnlList.Visible         = false;
            pnlRank.Visible         = false;
            pnlQuestionGame.Visible = false;

            if (IsRanking)
            {
                DataTable      dt       = new Database().GetDataTable("uxp_GetQuestionRank", CommandType.StoredProcedure);
                int            totalRow = 0;
                List <DataRow> lstRow   = new List <DataRow>();
                if (dt != null)
                {
                    totalRow = dt.Rows.Count;
                    lstRow   = dt.Rows.Cast <DataRow>()
                               .Skip((PageIndex - 1) * PageSize)
                               .Take(PageSize).ToList();
                }

                rptRank.DataSource = lstRow;
                rptRank.DataBind();

                pager.ItemCount = totalRow;
                pnlRank.Visible = true;

                if (totalRow == 0)
                {
                    Utils.ShowMessage(lblMsg2, "Không tìm thấy dữ liệu bảng xếp hạng game trả lời câu hỏi");
                    rptRank.Visible = false;
                }
            }
            else if (IsDetail)
            {
                string strId = Page.RouteData.Values["id"] as string;
                int    id    = 0;
                int.TryParse(strId, out id);
                QuestionGame qgame = DomainManager.GetObject <QuestionGame>(id);
                if (qgame != null)
                {
                    litQGName.Text = qgame.QuestionGameName;
                    List <Question> lst      = new List <Question>();
                    int             totalRow = 0;
                    if (qgame.Questionses != null)
                    {
                        totalRow = qgame.Questionses.Count;
                        lst      = qgame.Questionses.Cast <Question>()
                                   .Skip((PageIndex - 1) * PageSize)
                                   .Take(PageSize)
                                   .ToList();
                    }

                    pager.ItemCount = totalRow;
                    pnlList.Visible = true;

                    rptList.DataSource = lst;
                    rptList.DataBind();

                    if (totalRow == 0)
                    {
                        Utils.ShowMessage(lblMsg, "Không tìm thấy dữ liệu game trả lời câu hỏi");
                        rptList.Visible = false;
                    }
                }
            }
            else
            {
                IList <QuestionGame> lst = DomainManager.GetAll <QuestionGame>();
                if (lst != null)
                {
                    lst = lst.OrderBy(p => p.QuestionGameName)
                          .ToList();
                }

                int totalRow = 0;
                if (lst != null)
                {
                    totalRow = lst.Count;
                    lst      = lst.Skip((PageIndex - 1) * PageSize)
                               .Take(PageSize).ToList();
                }
                pager.ItemCount         = totalRow;
                pnlQuestionGame.Visible = true;

                rptQG.DataSource = lst;
                rptQG.DataBind();

                if (totalRow == 0)
                {
                    Utils.ShowMessage(lblMsg, "Không tìm thấy dữ bộ đề game câu hỏi");
                    rptList.Visible = false;
                }
            }
        }
        private void SavePlayGame(out int rightAnswer, out int bonusPoint)
        {
            bonusPoint  = 0;
            rightAnswer = 0;

            User curenttUser = Utils.GetCurrentUser();

            curenttUser = DomainManager.GetObject <User>(curenttUser.Id);
            if (curenttUser != null)
            {
                int          time = 0;
                QuestionUser qu   = new QuestionUser();
                qu.PlayDate = DateTime.Now;
                qu.User     = curenttUser;
                qu.Time     = time;

                string       key2  = hfCache.Value;
                QuestionGame qgame = CMSCache.Get(key2) as QuestionGame;
                if (qgame != null)
                {
                    qu.QuestionGame = qgame;

                    foreach (Question p in qgame.Questionses.Cast <Question>())
                    {
                        Answer   userAnswer = GetUserAnswer(p);
                        Question question   = DomainManager.GetObject <Question>(p.Id);

                        if (userAnswer != null)
                        {
                            QuestionUserDetail detail = new QuestionUserDetail();
                            detail.QuestionUser = qu;
                            detail.Question     = question;
                            detail.Answer       = userAnswer;
                            qu.QuestionUserDetailses.Add(detail);
                        }

                        if (question != null && question.CorrectAnswer != null &&
                            userAnswer != null && question.CorrectAnswer.Id == userAnswer.Id)
                        {
                            bonusPoint += question.BonusPoint;
                            rightAnswer++;
                        }
                    }
                }


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

                qu.WinPoint = bonusPoint;
                if (qu.QuestionGame != null)
                {
                    DomainManager.Insert(qu);

                    curenttUser.PointQuestion += bonusPoint; // cộng vào tổng điểm của game trả lời câu hỏi
                    curenttUser.Point         += bonusPoint; // cộng điểm thưởng vào tổng điểm của game cá cược

                    DomainManager.Insert(curenttUser);
                    Utils.ResetCurrentUser();
                    if (bonusPoint == 0)
                    {
                        TNHelper.LogAction(LogType.QuestionLog, "Chơi game thử tài kiến thức");
                    }
                    else
                    {
                        TNHelper.LogAction(LogType.QuestionLog, string.Format("Cộng {0} điểm thưởng vào tổng điểm game thử tài kiến thức.<br/>Cộng {0} điểm thưởng vào tổng điểm game phân tích trận đấu", bonusPoint));
                    }
                }
                // remove all relate cache
                CMSCache.RemoveByPattern(hfCache.Value);
            }
        }