Exemplo n.º 1
0
        void rptPUserAnswer_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item ||
                e.Item.ItemType == ListItemType.AlternatingItem)
            {
                PredictionAnswer answer       = e.Item.DataItem as PredictionAnswer;
                Literal          litAnswerCSS = e.Item.FindControl("litAnswerCSS") as Literal;

                if (litAnswerCSS != null)
                {
                    if (answer.IsUserAnswer)
                    {
                        if (answer.IsCorrectAnswer)
                        {
                            litAnswerCSS.Text = "class='yourAnswer'";
                        }
                        else if (answer.Prediction != null && answer.Prediction.PredictionGame != null && !answer.Prediction.PredictionGame.IsCalculate)
                        {
                            litAnswerCSS.Text = "class='yourAnswer'";
                        }
                        else
                        {
                            litAnswerCSS.Text = "class='yourAnswer incorectAnswer'";
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected void rptAnswers_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item ||
                e.Item.ItemType == ListItemType.AlternatingItem)
            {
                PredictionAnswer answer = e.Item.DataItem as PredictionAnswer;

                RadioButton radAnswer  = e.Item.FindControl("radAnswer") as RadioButton;
                TextBox     txtAnswer  = e.Item.FindControl("txtAnswer") as TextBox;
                HiddenField hfAnswerID = e.Item.FindControl("hfAnswerID") as HiddenField;

                if (radAnswer != null)
                {
                    radAnswer.Checked = answer.IsCorrectAnswer;
                }

                if (txtAnswer != null)
                {
                    txtAnswer.Text = answer.AnswerText;
                }

                if (hfAnswerID != null)
                {
                    hfAnswerID.Value = answer.Id.ToString();
                }
            }
        }
Exemplo n.º 3
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));
                }
            }
        }
Exemplo n.º 4
0
        private bool CheckUpdateAnswer(List <Prediction> lstQuestion)
        {
            if (lstQuestion != null)
            {
                foreach (Prediction prediction in lstQuestion)
                {
                    PredictionAnswer rightAnswer = prediction.PredictionAnswerses.Cast <PredictionAnswer>().Where(p => p.IsCorrectAnswer).FirstOrDefault();
                    if (rightAnswer == null)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 5
0
        private List <PredictionAnswer> GetAnswerList(Repeater rpt)
        {
            List <PredictionAnswer> lst = new List <PredictionAnswer>();

            if (rpt != null)
            {
                foreach (RepeaterItem item in rpt.Items)
                {
                    RadioButton radAnswer  = item.FindControl("radAnswer") as RadioButton;
                    TextBox     txtAnswer  = item.FindControl("txtAnswer") as TextBox;
                    HiddenField hfAnswerID = item.FindControl("hfAnswerID") as HiddenField;

                    bool   isCorrectAnswer = false;
                    string answerText      = string.Empty;
                    int    answerID        = 0;

                    if (radAnswer != null)
                    {
                        isCorrectAnswer = radAnswer.Checked;
                    }

                    if (txtAnswer != null)
                    {
                        answerText = txtAnswer.Text;
                    }

                    if (hfAnswerID != null)
                    {
                        int.TryParse(hfAnswerID.Value, out answerID);
                    }

                    PredictionAnswer answer = new PredictionAnswer();
                    answer.Id              = answerID;
                    answer.AnswerText      = answerText;
                    answer.IsCorrectAnswer = isCorrectAnswer;

                    lst.Add(answer);
                }
            }

            return(lst);
        }
Exemplo n.º 6
0
        private Prediction SavePrediction(Prediction question)
        {
            Prediction obj = new Prediction();

            obj.CreatedDate    = DateTime.Now;
            obj.ModifiedDate   = DateTime.Now;
            obj.PredictionName = question.PredictionName;
            obj.Active         = question.Active;
            obj.BonusPoint     = question.BonusPoint;
            foreach (PredictionAnswer answer in question.PredictionAnswerses)
            {
                PredictionAnswer ansObj = new PredictionAnswer();
                ansObj.AnswerText      = answer.AnswerText;
                ansObj.IsCorrectAnswer = answer.IsCorrectAnswer;
                ansObj.Prediction      = obj;
                obj.PredictionAnswerses.Add(ansObj);
            }

            DomainManager.Insert(obj);
            return(obj);
        }
Exemplo n.º 7
0
        void rptAnswer_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item ||
                e.Item.ItemType == ListItemType.AlternatingItem)
            {
                PredictionAnswer answer        = e.Item.DataItem as PredictionAnswer;
                Literal          litAnswerText = e.Item.FindControl("litAnswerText") as Literal;

                if (litAnswerText != null)
                {
                    if (answer.IsCorrectAnswer)
                    {
                        litAnswerText.Text = string.Format("<b style='color: #F00;'>{0}</b>", answer.AnswerText);
                    }
                    else
                    {
                        litAnswerText.Text = answer.AnswerText;
                    }
                }
            }
        }
Exemplo n.º 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 <Prediction> 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);

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

                qgame.PredictionGameName = TextInputUtil.GetSafeInput(txtQGName.Text);
                qgame.Active             = radYes.Checked;
                qgame.IsUpdateAnswer     = CheckUpdateAnswer(lstQuestion);
                if (qgame.Id > 0)
                {
                    DomainManager.Update(qgame);
                }
                else
                {
                    DomainManager.Insert(qgame);
                }

                if (lstQuestion != null)
                {
                    for (int i = 0; i < lstQuestion.Count; i++)
                    {
                        Prediction question = lstQuestion[i];
                        if (question.Id == 0)
                        {
                            // Prediction newPrediction = SavePrediction(question);
                            DomainManager.Insert(question);
                            question.PredictionGame = qgame;
                            qgame.Predictionses.Add(question);
                        }
                        else // update data
                        {
                            Prediction tmpQ = qgame.Predictionses.Cast <Prediction>().Where(p => p.Id == question.Id).FirstOrDefault();
                            if (tmpQ != null)
                            {
                                tmpQ.PredictionName = question.PredictionName;
                                tmpQ.BonusPoint     = question.BonusPoint;
                                foreach (PredictionAnswer ans in question.PredictionAnswerses.Cast <PredictionAnswer>())
                                {
                                    PredictionAnswer tmpA = tmpQ.PredictionAnswerses.Cast <PredictionAnswer>().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ộ đề dự đoán thành công");
                }
                else
                {
                    DomainManager.Insert(qgame);
                    msg = Page.Server.UrlEncode("Thêm bộ dự đoán thành công");
                }

                Page.Response.Redirect(string.Format("/admincp/prediction-list?msg={0}", msg), true);
            }
        }
Exemplo n.º 9
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();
                }
            }
        }