protected void rptQG_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { PredictionGame qgame = e.Item.DataItem as PredictionGame; LinkButton lnkDelete = e.Item.FindControl("lnkDelete") as LinkButton; LinkButton lnkCalculate = e.Item.FindControl("lnkCalculate") as LinkButton; BizPredictionGameSettings biz = TNHelper.GetPredictionGameSettings(); if (lnkDelete != null) { if (biz != null && biz.PredictionGameID == qgame.Id) { lnkDelete.OnClientClick = "aler('Bạn khổng thế xóa bộ đề vì nó đang được cấu hình cho game dự đoán'); return false"; } } if (lnkCalculate != null) { lnkCalculate.Visible = false; if (biz != null && !qgame.IsCalculate) { lnkCalculate.Visible = true; } } } }
protected void rptQuestion_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string strId = Page.RouteData.Values["id"] as string; int gameid = 0; int.TryParse(strId, out gameid); Prediction question = e.Item.DataItem as Prediction; Repeater rptAnswer = e.Item.FindControl("rptAnswer") as Repeater; LinkButton lnkDelete = e.Item.FindControl("lnkDelete") as LinkButton; TextBox txtQuestionName = e.Item.FindControl("txtQuestionName") as TextBox; TextBox txtBonus = e.Item.FindControl("txtBonus") as TextBox; BizPredictionGameSettings biz = TNHelper.GetPredictionGameSettings(); PredictionGame pgame = DomainManager.GetObject <PredictionGame>(gameid); if ((biz.PredictionGameID == gameid) || (pgame != null && pgame.PredictionGameUsers.Count > 0)) { if (txtQuestionName != null) { txtQuestionName.Enabled = false; } if (txtBonus != null) { txtBonus.Enabled = false; } } if (lnkDelete != null) { if ((biz != null && biz.PredictionGameID == gameid)) { lnkDelete.Enabled = false; lnkDelete.OnClientClick = ""; } else { // những dự đoán có người chơi sẽ không đựoc xóa câu hỏi if (pgame != null && pgame.PredictionGameUsers.Count > 0) { lnkDelete.Enabled = false; lnkDelete.OnClientClick = ""; } } } if (rptAnswer != null) { rptAnswer.DataSource = question.PredictionAnswerses; rptAnswer.DataBind(); } } }
protected void LoadEditData() { string strId = Page.RouteData.Values["id"] as string; int id = 0; int.TryParse(strId, out id); PredictionGame obj = DomainManager.GetObject <PredictionGame>(id); if (obj != null) { BizPredictionGameSettings biz = TNHelper.GetPredictionGameSettings(); bool isPermit = true; if (biz != null) { isPermit = biz.PredictionGameID == obj.Id ? false : true; if (obj.PredictionGameUsers.Count > 0) { isPermit = false; } } btnDelete.Enabled = isPermit; trAdd.Visible = isPermit; if (obj.IsCalculate) { btnDelete.Enabled = false; btnSave.Enabled = false; trAdd.Visible = false; } txtQGName.Text = obj.PredictionGameName; radYes.Checked = obj.Active; radNo.Checked = !obj.Active; txtQGName.Enabled = isPermit; radYes.Enabled = isPermit; radNo.Enabled = isPermit; rptQuestion.DataSource = obj.Predictionses; 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 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; } }
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; PredictionGame pgame = CMSCache.Get(key) as PredictionGame; if (pgame != null && pgame.Predictionses.Count == total && index < total) { Prediction prediction = pgame.Predictionses[index] as Prediction; LoadAnswerList(prediction); litQuestion.Text = prediction.PredictionName; hfID.Value = prediction.Id.ToString(); } } if (index + 1 == total) { btnNext.Text = "Xem kết quả"; if (PredictionGameUser is PredictionGameUser) { btnNext.Text = "Cập nhật"; } btnNext.CssClass = "buttonL last"; } if (index == total) { btnSubmit_Click(btnSubmit, e); } else { pnlQuestion.Visible = true; pnlSummary.Visible = false; } }
protected void btnDelete_Click(object sender, EventArgs e) { string strId = Page.RouteData.Values["id"] as string; int id = 0; int.TryParse(strId, out id); PredictionGame obj = DomainManager.GetObject <PredictionGame>(id); if (obj != null) { DomainManager.Delete(obj); string msg = Page.Server.UrlEncode("Xóa bộ đề game dự đoán thành công"); Page.Response.Redirect(string.Format("/admincp/prediction-list?msg={0}", msg), true); } }
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); PredictionGame qgame = DomainManager.GetObject <PredictionGame>(id); BizPredictionGameSettings biz = TNHelper.GetPredictionGameSettings(); if (qgame != null) { if (biz.PredictionGameID != qgame.Id) { DomainManager.Delete(qgame); Utils.ShowMessage(lblMsgQG, "Xóa bộ đề dự đoán thành công"); LoadData(); } else { Utils.ShowMessage(lblMsgQG, "Bộ đề này đang được sử dụng trong cấu hình game dự đoán. Bạn không thể xóa."); } } } else if (string.Compare(e.CommandName, "calculate", true) == 0) { int id = 0; int.TryParse(e.CommandArgument.ToString(), out id); PredictionGame qgame = DomainManager.GetObject <PredictionGame>(id); BizPredictionGameSettings biz = TNHelper.GetPredictionGameSettings(); if (qgame != null)// && qgame.IsUpdateAnswer) { TNHelper.CalculatePredcitionGame(qgame); TNHelper.RemoveRankingCaches(); Utils.ShowMessage(lblMsgQG, "Tính điểm cho người chơi thành chơi thành công"); LoadData(); } else { Utils.ShowMessage(lblMsgQG, "Bạn chưa cập nhật trả lời cho tất cả câu hỏi dự đoán. Hãy cập nhật tất cả câu trả lời trước khi tính điểm"); } } }
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); } }
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); } }
private void LoadData() { pnlList.Visible = false; pnlRank.Visible = false; pnlQuestionGame.Visible = false; if (IsRanking) { DataTable dt = new Database().GetDataTable("uxp_GetPredictionRank", 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 dự đoán"); rptRank.Visible = false; } } else if (IsDetail) { string strId = Page.RouteData.Values["id"] as string; int id = 0; int.TryParse(strId, out id); PredictionGame qgame = DomainManager.GetObject <PredictionGame>(id); List <Prediction> lst = new List <Prediction>(); int totalRow = 0; if (qgame != null) { litQGName.Text = qgame.PredictionGameName; if (qgame.Predictionses != null) { totalRow = qgame.Predictionses.Count; lst = qgame.Predictionses.Cast <Prediction>() .Skip((PageIndex - 1) * PageSize) .Take(PageSize) .ToList(); } } rptList.DataSource = lst; rptList.DataBind(); pager.ItemCount = totalRow; pnlList.Visible = true; if (totalRow == 0) { Utils.ShowMessage(lblMsg, "Không tìm thấy dữ liệu câu hỏi của game dự đoán"); rptList.Visible = false; } } else { IList <PredictionGame> lst = DomainManager.GetAll <PredictionGame>(); if (lst != null) { lst = lst.OrderBy(p => p.PredictionGameName) .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 dự đoán"); rptList.Visible = false; } } }