/// <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)); }