/// <summary> /// 获取结果图信息 /// </summary> /// <param name="contex"></param> /// <returns></returns> private string GetDiInfos(HttpContext contex) { string autoId = contex.Request["autoId"]; ChartDataModel chartData = new ChartDataModel(); ChartDataModelSub chartDataSub = new ChartDataModelSub(); chartData.categories = new List <string>(); chartData.series = new List <ChartDataModelSub>(); BLLJIMP.Model.TheVoteInfo voteInfo = bllJuActivity.Get <BLLJIMP.Model.TheVoteInfo>(string.Format(" AutoId={0}", autoId)); if (voteInfo == null) { resp.Status = -1; resp.Msg = "系统出错!!!"; goto OutF; } chartDataSub.name = voteInfo.VoteName; chartDataSub.data = new List <int>(); List <BLLJIMP.Model.DictionaryInfo> diInfo = bllJuActivity.GetList <BLLJIMP.Model.DictionaryInfo>(string.Format(" ForeignKey={0}", autoId)); foreach (BLLJIMP.Model.DictionaryInfo item in diInfo) { chartData.categories.Add(item.ValueStr); chartDataSub.data.Add(item.VoteNums); } chartData.series.Add(chartDataSub); resp.Status = 0; resp.ExObj = chartData; OutF: return(Common.JSONHelper.ObjectToJson(resp)); }
/// <summary> /// 获取投票信息 /// </summary> /// <param name="context"></param> private string GetTheVoteInfo(HttpContext context) { string id = context.Request["Autoid"]; if (string.IsNullOrEmpty(id)) { resp.Status = -1; resp.Msg = "系统出错,请联系管理员"; goto OutF; } StringBuilder sbWhere = new StringBuilder(string.Format(" websiteOwner='{0}'", bll.WebsiteOwner)); sbWhere.AppendFormat(" AND AutoId ={0}", id); BLLJIMP.Model.TheVoteInfo tvInfo = bllJuActivity.Get <BLLJIMP.Model.TheVoteInfo>(sbWhere.ToString()); tvInfo.diInfos = bllJuActivity.GetList <BLLJIMP.Model.DictionaryInfo>(" ForeignKey=" + tvInfo.AutoId); if (tvInfo != null) { resp.Status = 0; resp.ExObj = tvInfo; } else { resp.Status = 0; resp.Msg = "系统出错,请联系管理员!!!"; } OutF: return(Common.JSONHelper.ObjectToJson(resp)); }
private void GetTheVoteInfo(string autoId) { StringBuilder str = new StringBuilder(); tvInfo = bll.Get <BLLJIMP.Model.TheVoteInfo>(" autoId=" + autoId); if (tvInfo != null) { needList.InnerHtml = ToHtml(tvInfo); } else { str.AppendFormat("<li>"); str.AppendFormat("<div>{0}</div>", "没有数据"); str.AppendFormat("</li>"); needList.InnerHtml = str.ToString(); } }
/// <summary> /// 保存投票信息 /// </summary> /// <param name="context"></param> /// <returns></returns> private string SaveDataInfo(HttpContext context) { string autoId = context.Request["AutoId"]; string ids = context.Request["Ids"]; if (string.IsNullOrEmpty(ids)) { resp.Status = -1; resp.Msg = "请选择投票内容"; goto OutF; } ids = ids.Replace("0,", ""); BLLJIMP.Model.TheVoteInfo voteInfo = bllUser.Get <BLLJIMP.Model.TheVoteInfo>(string.Format(" AutoId=" + autoId)); if (voteInfo.MaxSelectItemCount > 0) { if (ids.Split(',').Length > voteInfo.MaxSelectItemCount) { resp.Status = -1; resp.Msg = "最多可以同时选中" + voteInfo.MaxSelectItemCount + "个选项"; goto OutF; } } if (DateTime.Now > voteInfo.TheVoteOverDate) { resp.Status = -1; resp.Msg = "投票结束"; goto OutF; } ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction(); int count = 0; if (currentUserInfo != null) { count = bllJuActivity.GetCount <BLLJIMP.Model.UserVoteInfo>(string.Format(" UserId='{0}' AND VoteId='{1}'", currentUserInfo.UserID, autoId)); } else { //currentUserInfo = new BLLJIMP.Model.UserInfo() //{ // UserID = "user" //}; } if (count > 0) { resp.Status = -1; resp.Msg = "您已经投过票,不可再次投票。"; goto OutF; } bool isSuccess = bllUser.Add(new BLLJIMP.Model.UserVoteInfo() { UserId = currentUserInfo.UserID, VoteId = autoId, DiInfoId = ids }, tran); string[] idsArry = ids.Split(','); voteInfo.PNumber = voteInfo.PNumber + 1; //int num = idsArry.Length; //if (idsArry.Length > 1) //{ // num = idsArry.Length - 1; //} //else //{ // num = idsArry.Length; //} //voteInfo.VoteNumbers = (voteInfo.VoteNumbers + num); bll.Update(voteInfo, string.Format(" PNumber+=1,VoteNumbers+={0}", idsArry.Length), string.Format(" AutoId={0}", voteInfo.AutoId)); //bllUser.Update(voteInfo, tran); for (int i = 0; i < idsArry.Length; i++) { BLLJIMP.Model.DictionaryInfo diInfo = bllUser.Get <BLLJIMP.Model.DictionaryInfo>(" AutoID=" + idsArry[i]); if (diInfo != null) { diInfo.VoteNums = diInfo.VoteNums + 1; bll.Update(diInfo, string.Format("VoteNums+=1"), string.Format(" AutoID={0}", diInfo.AutoID)); //bllUser.Update(diInfo, tran); } } if (isSuccess) { resp.Status = 0; resp.Msg = "投票成功"; tran.Commit(); } else { resp.Status = -1; resp.Msg = "投票失败"; tran.Rollback(); } OutF: return(Common.JSONHelper.ObjectToJson(resp)); }
/// <summary> /// 插入或修改数据 /// </summary> /// <param name="context"></param> /// <returns></returns> private string InsertTheVoteInfo(HttpContext context) { string autoId = string.IsNullOrEmpty(context.Request["AutoId"]) ? "0" : context.Request["AutoId"]; string voteName = context.Request["VoteName"]; string isVoteOpen = context.Request["IsVoteOpen"]; string votePosition = context.Request["VotePosition"]; string answer = context.Request["Answer"]; string aotoId = context.Request["Aid"]; string voteOverDate = context.Request["VoteOverDate"]; string maxSelectItemCount = context.Request["MaxSelectItemCount"]; string summary = context.Request["Summary"]; string thumbnailsPath = context.Request["ThumbnailsPath"]; if (string.IsNullOrEmpty(maxSelectItemCount)) { maxSelectItemCount = "0"; } ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction(); if (string.IsNullOrEmpty(voteName)) { resp.Status = -1; resp.Msg = "请填写完整信息"; goto OutF; } BLLJIMP.Model.TheVoteInfo voteInfo = bllJuActivity.Get <BLLJIMP.Model.TheVoteInfo>(" AutoId=" + autoId); if (voteInfo != null) { List <BLLJIMP.Model.DictionaryInfo> dics = new List <BLLJIMP.Model.DictionaryInfo>(); voteInfo.VoteName = voteName; voteInfo.VoteSelect = votePosition; voteInfo.UserId = currentUserInfo.UserID; voteInfo.websiteOwner = bll.WebsiteOwner; voteInfo.MaxSelectItemCount = int.Parse(maxSelectItemCount); voteInfo.TheVoteOverDate = Convert.ToDateTime(voteOverDate); voteInfo.Summary = summary; voteInfo.ThumbnailsPath = thumbnailsPath; if (bllJuActivity.Update(voteInfo, tran)) { string[] answersArry = answer.Split(','); string[] aotoidArry = aotoId.Split(','); if (answersArry.Length > 0) { for (int i = 0; i < answersArry.Length; i++) { if (!string.IsNullOrEmpty(answersArry[i])) { if (string.IsNullOrEmpty(aotoidArry[i])) { bllJuActivity.Add(new BLLJIMP.Model.DictionaryInfo { KeyStr = Guid.NewGuid().ToString(), ValueStr = answersArry[i], ForeignKey = voteInfo.AutoId.ToString() }, tran); } else { BLLJIMP.Model.DictionaryInfo model = bll.Get <DictionaryInfo>(string.Format("AutoID={0}", aotoidArry[i])); if (model != null) { model.ValueStr = answersArry[i]; if (bll.Update(model)) { } } //bllJuActivity.Update(new BLLJIMP.Model.DictionaryInfo //{ // AutoID = Convert.ToInt32(aotoidArry[i]), // KeyStr = Guid.NewGuid().ToString(), // ValueStr = answersArry[i], // ForeignKey = voteInfo.AutoId.ToString() //}, tran); } } } } resp.Status = 1; resp.Msg = "修改成功!!!"; tran.Commit(); bllLog.Add(BLLJIMP.Enums.EnumLogType.Marketing, BLLJIMP.Enums.EnumLogTypeAction.Update, bllLog.GetCurrUserID(), "编辑选题投票[id=" + autoId + "]"); } else { resp.Status = 0; resp.Msg = "修改失败!!!"; tran.Rollback(); } } else { voteInfo = new BLLJIMP.Model.TheVoteInfo { VoteName = voteName, IsVoteOpen = isVoteOpen, VoteSelect = votePosition, TheVoteOverDate = Convert.ToDateTime(voteOverDate), InsetDate = DateTime.Now, websiteOwner = bll.WebsiteOwner, UserId = currentUserInfo.UserID, TheVoteGUID = this.bllJuActivity.GetGUID(BLLJIMP.TransacType.AddVoteId), MaxSelectItemCount = int.Parse(maxSelectItemCount), Summary = summary, ThumbnailsPath = thumbnailsPath }; if (bllJuActivity.Add(voteInfo, tran)) { tran.Commit(); voteInfo = bllJuActivity.Get <BLLJIMP.Model.TheVoteInfo>(string.Format(" VoteName='{0}' and UserId='{1}'", voteName, currentUserInfo.UserID )); string[] answers = answer.Split(','); if (answers.Length > 0) { for (int i = 0; i < answers.Length; i++) { if (!string.IsNullOrEmpty(answers[i])) { bllJuActivity.Add(new BLLJIMP.Model.DictionaryInfo { KeyStr = Guid.NewGuid().ToString(), ValueStr = answers[i], ForeignKey = voteInfo.AutoId.ToString() }); } } } resp.Status = 1; resp.Msg = "添加成功!!!"; bllLog.Add(BLLJIMP.Enums.EnumLogType.Marketing, BLLJIMP.Enums.EnumLogTypeAction.Add, bllLog.GetCurrUserID(), "添加选题投票"); } else { resp.Status = 0; resp.Msg = "添加失败!!!"; tran.Rollback(); } } OutF: return(Common.JSONHelper.ObjectToJson(resp)); }
/// <summary> /// 返回投票内容 /// </summary> /// <param name="tvInfo"></param> /// <returns></returns> private string ToHtml(BLLJIMP.Model.TheVoteInfo tvInfo) { StringBuilder htmlStr = new StringBuilder(); string classStr = ""; string selectStr = ""; string str = ""; BLLJIMP.Model.UserVoteInfo uvInfo = null; if (bll.IsLogin) { this.userInfo = DataLoadTool.GetCurrUserModel(); string whereStr = string.Format(" UserId='{0}' and VoteId='{1}'", userInfo.UserID, tvInfo.AutoId); uvInfo = bll.Get <BLLJIMP.Model.UserVoteInfo>(whereStr); } //uvInfo = null; if (uvInfo != null) { classStr = "toupiaobox toupiaoover"; } else { if (tvInfo.VoteSelect == "1") { classStr = "toupiaobox"; selectStr = "radio"; str = "以下选项为单选"; } else if (tvInfo.VoteSelect == "2") { classStr = "toupiaobox duoxuan"; selectStr = "checkbox"; str = "以下选项为多选"; } } htmlStr.AppendFormat("<link rel=\"stylesheet\" href=\"styles/css/style.css?v=0.0.1\">"); htmlStr.AppendFormat("<div id=\"toupiao\" class=\"{0}\">", classStr); htmlStr.AppendFormat("<div><img src=\"{0}\"></div>", tvInfo.ThumbnailsPath); htmlStr.AppendFormat("<div class=\"title\">{0}</div>", tvInfo.VoteName); htmlStr.AppendFormat("<p class=\"note\">{0}</p>", str); htmlStr.AppendFormat("<input type=\"hidden\" id=\"SelectStr\" value=\"{0}\" />", selectStr); htmlStr.AppendFormat("<input type=\"hidden\" id=\"AutoId\" value=\"{0}\" />", tvInfo.AutoId); List <BLLJIMP.Model.DictionaryInfo> dInfos = bll.GetList <BLLJIMP.Model.DictionaryInfo>(" ForeignKey='" + tvInfo.AutoId + "'"); foreach (var item in dInfos) { htmlStr.AppendFormat("<input name=\"radiocheck2\" type=\"{0}\" class=\"radioinput\" id=\"{1}\" value=\"\" v=\"{2}\">", selectStr, selectStr + item.AutoID, item.AutoID); htmlStr.AppendFormat("<div class=\"mainconcent\">"); htmlStr.AppendFormat("<label class=\"inputlabel\" for=\"{0}\"></label>", selectStr + item.AutoID); htmlStr.AppendFormat("<span class=\"inputicon\"><span class=\"icon\"></span></span>"); htmlStr.AppendFormat("<div class=\"inputtext\" >{0}</div>", item.ValueStr); htmlStr.AppendFormat("<div class=\"jindubar\">"); double f = 0; if (tvInfo.VoteNumbers != 0) { f = Math.Round((Convert.ToDouble(item.VoteNums) / Convert.ToDouble(tvInfo.VoteNumbers)) * 100, 0); } htmlStr.AppendFormat("<span class=\"jindu\" style=\"width:{0}%;\"></span>", f); htmlStr.AppendFormat("<span class=\"peoplenum\">{0}票数</span>", item.VoteNums); htmlStr.AppendFormat("<span class=\"pecent\">{0}%</span>", f); htmlStr.AppendFormat("</div></div>"); } string dName = ""; if (uvInfo != null) { dInfos = bll.GetList <BLLJIMP.Model.DictionaryInfo>(" AutoId in (" + uvInfo.DiInfoId + ")"); if (dInfos != null) { foreach (BLLJIMP.Model.DictionaryInfo item in dInfos) { dName += item.ValueStr + " "; } } } htmlStr.AppendFormat("<span class=\"button\" id=\"btnSave\" onclick=\"SaveInfo()\">投票</span>"); htmlStr.AppendFormat("<span class=\"toupiaoinfo\" >你已投过票,投票项为\"{0}\"</span>", dName); htmlStr.AppendFormat("</div>"); return(htmlStr.ToString()); }
private void GetTheVoteInfo(string AutoId) { model = jubll.Get <BLLJIMP.Model.TheVoteInfo>(" AutoID=" + AutoId); }