예제 #1
0
        private void SubmitVote()
        {
            SqlHelper  sqlhelper  = SqlFactory.GetSqlhelper();
            AjaxResult result     = new AjaxResult();
            string     session    = Fun.GetSession("openid");
            int        primaryKey = int.Parse(HttpContext.Current.Request.Form["voteid"]);

            if (string.IsNullOrEmpty(session))
            {
                result.ErrCode = -1;
                result.Message = "已超期,请重新进入页面";
            }
            else if (sqlhelper.Count <VoteDetail>("where openid='" + session + "' and datediff(dd,votedate,getdate())=0", new object[0]) > 0)
            {
                result.ErrCode = -1;
                result.Message = "您今天已投过票,无法继续投票";
            }
            else
            {
                VoteInfos infos = sqlhelper.SingleById <VoteInfos>(primaryKey);
                TimeSpan  span  = (TimeSpan)(DateTime.Now - infos.ValidStartDate);
                if (span.TotalDays < 0.0)
                {
                    result.ErrCode = -1;
                    result.Message = "该投票尚未开始";
                }
                else
                {
                    TimeSpan span2 = (TimeSpan)(DateTime.Now - infos.ValidEndDate);
                    if (span2.TotalDays > 1.0)
                    {
                        result.ErrCode = -1;
                        result.Message = "该投票已经结束";
                    }
                    else
                    {
                        string[] strArray = HttpContext.Current.Request.Form["ids"].Split(new char[] { ',' });
                        for (int i = 0; i < strArray.Length; i++)
                        {
                            VotePersons persons = sqlhelper.SingleById <VotePersons>(strArray[i]);
                            VoteDetail  detail  = new VoteDetail {
                                VoteID = primaryKey,
                                Person = persons.RealName,
                                OpenID = session
                            };
                            sqlhelper.Execute("insert into votedetail(voteid,person,openid)values(@0,@1,@2)", new object[] { primaryKey, persons.RealName, session });
                        }
                        result.ErrCode = 0;
                        result.Message = "提交成功";
                        //判断每人的中奖次数
                        if (Fun.HasBonus(session))
                        {
                            result.Tag = "enable";
                            HttpContext.Current.Session["BonusEnable"] = "1";
                        }
                    }
                }
            }
            HttpContext.Current.Response.Write(JsonConvert.SerializeObject(result));
        }
예제 #2
0
 public ActionResult MiniPost(PostModel postModel, int id)
 {
     try
     {
         VoteInfos infos          = SqlFactory.GetSqlhelper().SingleById <VoteInfos>(id);
         string    token          = infos.Token;
         string    encodingAESKey = infos.EncodingAESKey;
         string    corpID         = infos.CorpID;
         base.Session["VoteInfo"] = infos;
         if (!CheckSignature.Check(postModel.Signature, postModel.Timestamp, postModel.Nonce, token))
         {
             return(new WeixinResult("参数错误!"));
         }
         postModel.Token          = token;
         postModel.EncodingAESKey = encodingAESKey;
         postModel.AppId          = corpID;
         Senparc.Weixin.MP.Sample.CommonService.CustomMessageHandler.CustomMessageHandler messageHandlerDocument = new Senparc.Weixin.MP.Sample.CommonService.CustomMessageHandler.CustomMessageHandler(base.Request.InputStream, postModel, 10);
         messageHandlerDocument.Execute();
         return(new FixWeixinBugWeixinResult(messageHandlerDocument));
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
예제 #3
0
 public CustomMessageHandlernew(Stream inputStream, PostModel postModel, int maxRecordCount = 0)
     : base(inputStream, postModel, maxRecordCount, null)
 {
     this.agentUrl   = WebConfigurationManager.AppSettings["WeixinAgentUrl"];
     this.agentToken = WebConfigurationManager.AppSettings["WeixinAgentToken"];
     this.wiweihiKey = WebConfigurationManager.AppSettings["WeixinAgentWeiweihiKey"];
     this.voteinfo   = HttpContext.Current.Session["voteinfo"] as VoteInfos;
     if (this.voteinfo != null)
     {
         this.appId     = this.voteinfo.CorpID;
         this.appSecret = this.voteinfo.Secret;
     }
     this.WeixinContext.ExpireMinutes = 3.0;
     if (!string.IsNullOrEmpty(postModel.AppId))
     {
         this.appId = postModel.AppId;
     }
     base.OmitRepeatedMessageFunc = delegate(IRequestMessageBase requestMessage) {
         RequestMessageText text = requestMessage as RequestMessageText;
         if ((text != null) && (text.Content == "容错"))
         {
             return(false);
         }
         return(true);
     };
 }
        public CustomMessageHandler(Stream inputStream, PostModel postModel, int maxRecordCount = 0)
            : base(inputStream, postModel, maxRecordCount)
        {
            //这里设置仅用于测试,实际开发可以在外部更全局的地方设置,
            //比如MessageHandler<MessageContext>.GlobalWeixinContext.ExpireMinutes = 3。
            WeixinContext.ExpireMinutes = 3;
            this.voteinfo = HttpContext.Current.Session["voteinfo"] as VoteInfos;
            if (this.voteinfo != null)
            {
                this.appId     = this.voteinfo.CorpID;
                this.appSecret = this.voteinfo.Secret;
            }
            this.WeixinContext.ExpireMinutes = 3.0;
            if (!string.IsNullOrEmpty(postModel.AppId))
            {
                this.appId = postModel.AppId;
            }
            if (!string.IsNullOrEmpty(postModel.AppId))
            {
                appId = postModel.AppId;//通过第三方开放平台发送过来的请求
            }

            //在指定条件下,不使用消息去重
            base.OmitRepeatedMessageFunc = requestMessage =>
            {
                var textRequestMessage = requestMessage as RequestMessageText;
                if (textRequestMessage != null && textRequestMessage.Content == "容错")
                {
                    return(false);
                }
                return(true);
            };
        }
예제 #5
0
        public static void ValidVoteID(int voteid, out VoteInfos voteinfo)
        {
            voteinfo = SqlFactory.GetSqlhelper().SingleOrDefaultById <VoteInfos>(voteid);
            if (voteinfo == null)
            {
                Error("未找到对应投票");
            }
            WeAPI eapi = new WeAPI(voteinfo.CorpID, voteinfo.Secret);

            if (HttpContext.Current.Session["openid"] == null)
            {
                if (string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["code"]))
                {
                    if (voteinfo.MPType == 0)
                    {
                        HttpContext.Current.Response.Redirect("/MPage/Subscribe.aspx?voteid=" + voteinfo.ID);
                    }
                    string url = eapi.OAuthApi.GetAuthorizeUrl(HttpContext.Current.Request.Url.ToString(), "", OAuthScope.snsapi_base, "code");
                    HttpContext.Current.Response.Redirect(url);
                }
                else
                {
                    string code = HttpContext.Current.Request.QueryString["code"];
                    OAuthAccessTokenResult token = eapi.OAuthApi.GetToken(code, "authorization_code");
                    if (!string.IsNullOrEmpty(token.openid))
                    {
                        string openid = token.openid;
                        if (eapi.UserApi.Info(openid, "zh_CN").subscribe == 0)
                        {
                            HttpContext.Current.Response.Redirect("Subscribe.aspx?voteid=" + voteid);
                        }
                        HttpContext.Current.Session["openid"] = openid;
                    }
                    else
                    {
                        HttpContext.Current.Response.Redirect("Index.aspx?voteid=" + voteid);
                    }
                }
            }
        }
예제 #6
0
        //public ElectionAnalyzerSingleName(Election election, ResultSummary resultSummary, List<Result> results,
        //                                  List<VoteInfo> voteinfos, List<Ballot> ballots, Func<Result, Result> deleteResult,
        //                                  Func<Result, Result> addResult
        //                                  , Func<int> saveChanges, List<Person> people)
        //  : base(election, resultSummary, results, people, ballots, voteinfos, deleteResult, addResult, saveChanges)
        //{
        //}

        public override void AnalyzeEverything()
        {
            PrepareForAnalysis();

            // for single name elections, # votes = # ballots
            ResultSummaryCalc.BallotsReceived
                    = ResultSummaryCalc.NumVoters
                    = ResultSummaryCalc.TotalVotes
                    = VoteInfos.Sum(vi => vi.SingleNameElectionCount).AsInt();

            var invalidBallotGuids =
                Ballots.Where(bi => bi.StatusCode != BallotStatusEnum.Ok).Select(ib => ib.BallotGuid).ToList();

            //VoteInfos.Where(vi => vi.BallotStatusCode != "Ok").Select(ib => ib.BallotGuid).Distinct().ToList();

            ResultSummaryCalc.SpoiledBallots = invalidBallotGuids.Count();

            ResultSummaryCalc.SpoiledVotes =
                VoteInfos.Where(vi => !invalidBallotGuids.Contains(vi.BallotGuid) && vi.VoteStatusCode != VoteStatusCode.Ok).Sum(
                    vi => vi.SingleNameElectionCount).AsInt();

            // vote == ballot for this election
            ResultSummaryCalc.BallotsNeedingReview =
                //Ballots.Count(BallotAnalyzer.BallotNeedsReview);
                VoteInfos.Count(VoteAnalyzer.VoteNeedReview);

            // clear any existing results
            Results.ForEach(InitializeSomeProperties);

            var electionGuid = TargetElection.ElectionGuid;

            _hub.StatusUpdate("Processing votes", true);
            var numDone = 0;

            // collect only valid votes
            foreach (var voteInfo in VoteInfos.Where(vi => vi.VoteStatusCode == VoteStatusCode.Ok))
            {
                numDone++;
//        if (numDone % 10 == 0)
//        {
//          _hub.StatusUpdate("Processed {0} vote{1}".FilledWith(numDone, numDone.Plural()), true);
//        }
//
                // get existing result record for this person, if available
                var result =
                    Results.SingleOrDefault(r => r.ElectionGuid == electionGuid && r.PersonGuid == voteInfo.PersonGuid);
                if (result == null)
                {
                    result = new Result
                    {
                        ElectionGuid = electionGuid,
                        PersonGuid   = voteInfo.PersonGuid.AsGuid()
                    };
                    InitializeSomeProperties(result);
                    Savers.ResultSaver(DbAction.Add, result);
                    Results.Add(result);
                }

                var voteCount = result.VoteCount.AsInt() + voteInfo.SingleNameElectionCount;
                result.VoteCount = voteCount;
            }
            _hub.StatusUpdate("Processed {0} unspoiled vote{1}".FilledWith(numDone, numDone.Plural()));

            FinalizeResultsAndTies();
            FinalizeSummaries();

            var readyForReports = ResultSummaryFinal.UseOnReports.AsBoolean();

            if (UserSession.CurrentElectionStatus == ElectionTallyStatusEnum.Finalized && !readyForReports)
            {
                new ElectionModel().SetTallyStatus(ElectionTallyStatusEnum.Tallying);
            }

            _hub.StatusUpdate("Saving");

            Db.SaveChanges();

            new ResultSummaryCacher(Db).DropThisCache();
            new ResultTieCacher(Db).DropThisCache();
        }
예제 #7
0
        public override void AnalyzeEverything()
        {
            PrepareForAnalysis();

            ResultSummaryCalc.BallotsNeedingReview = Ballots.Count(BallotAnalyzer.BallotNeedsReview);

            ResultSummaryCalc.TotalVotes = Ballots.Count * TargetElection.NumberToElect;

            var invalidBallotGuids =
                Ballots.Where(b => b.StatusCode != BallotStatusEnum.Ok).Select(b => b.BallotGuid).ToList();

            ResultSummaryCalc.SpoiledBallots = invalidBallotGuids.Count();
            ResultSummaryCalc.SpoiledVotes   =
                VoteInfos.Count(vi => !invalidBallotGuids.Contains(vi.BallotGuid) && vi.VoteStatusCode != VoteHelper.VoteStatusCode.Ok);

            ResultSummaryCalc.BallotsReceived = Ballots.Count - ResultSummaryCalc.SpoiledBallots;

            var electionGuid = TargetElection.ElectionGuid;


            // collect only valid ballots
            _hub.StatusUpdate("Processing ballots", true);
            var numDone       = 0;
            var numVotesTotal = 0;

            foreach (var ballot in Ballots.Where(bi => bi.StatusCode == BallotStatusEnum.Ok))
            {
                numDone++;
                if (numDone % 10 == 0)
                {
                    _hub.StatusUpdate("Processed {0} ballot{1} ({2} votes)".FilledWith(numDone, numDone.Plural(), numVotesTotal), true);
                }

                var ballotGuid = ballot.BallotGuid;
                // collect only valid votes
                foreach (
                    var voteInfoRaw in
                    VoteInfos.Where(vi => vi.BallotGuid == ballotGuid && vi.VoteStatusCode == VoteHelper.VoteStatusCode.Ok))
                {
                    var voteInfo = voteInfoRaw;
                    numVotesTotal++;
                    // get existing result record for this person, if available
                    var result = Results.FirstOrDefault(r => r.ElectionGuid == electionGuid && r.PersonGuid == voteInfo.PersonGuid);
                    //Result result = null;
                    //if (results.Count == 1)
                    //{
                    //  result = results[0];
                    //}
                    //else if (results.Count > 1) {
                    //  // old/bad data!
                    //  foreach (var r in results)
                    //  {
                    //    Savers.ResultSaver(DbAction.AttachAndRemove, r);
                    //    Results.Remove(r);
                    //  }
                    //}
                    if (result == null)
                    {
                        result = new Result
                        {
                            ElectionGuid = electionGuid,
                            PersonGuid   = voteInfo.PersonGuid.AsGuid()
                        };
                        InitializeSomeProperties(result);

                        Savers.ResultSaver(DbAction.Add, result);
                        Results.Add(result);
                    }

                    var voteCount = result.VoteCount.AsInt() + 1;
                    result.VoteCount = voteCount;
                }
            }
            _hub.StatusUpdate("Processed {0} unspoiled ballot{1} ({2} votes)".FilledWith(numDone, numDone.Plural(), numVotesTotal));

            FinalizeResultsAndTies();
            FinalizeSummaries();

            var readyForReports = ResultSummaryFinal.UseOnReports.AsBoolean();

            if (UserSession.CurrentElectionStatus == ElectionTallyStatusEnum.Finalized && !readyForReports)
            {
                new ElectionModel().SetTallyStatus(ElectionTallyStatusEnum.Tallying);
            }

            _hub.StatusUpdate("Saving");

            Db.SaveChanges();

            new ResultSummaryCacher(Db).DropThisCache();
            new ResultTieCacher(Db).DropThisCache();
        }