Esempio n. 1
0
        private void BatchBallot(HttpContext context, OleDbConnection conn)
        {
            Dal.Models.UserInfo user   = (Dal.Models.UserInfo)context.Session["UserInfo"];
            Dal.Models.Expert   expert = BLL.Expert.GetExpertByUserID(user.UserID.Value, conn);

            int iPrizeID = 0;

            int.TryParse(context.Request["PrizeID"], out iPrizeID);
            string strVoteCode  = context.Request["VoteCode"];
            string strLevelCode = context.Request["LevelCode"];

            if (strLevelCode == "0404")
            {
                strLevelCode = "";
            }

            Dal.Models.Prize prize = BLL.Prize.GetPrize(iPrizeID, conn);

            if (prize == null || prize.IsStopVote)
            {
                context.Response.Write("当前奖项及轮次已结束投票。");
                return;
            }

            OleDbTransaction tran = conn.BeginTransaction();

            try
            {
                //根据专家和奖项获评奖项目
                List <Dal.Models.Vote> lstVote = BLL.Vote.GetVoteDeclarationList(expert, prize, conn, tran);

                //获取每个奖项的已评奖数量
                Dictionary <string, int> dicVote = new Dictionary <string, int>();

                //获取每个奖项未评奖数量
                Dictionary <string, int> dicRemain = new Dictionary <string, int>();

                GetLimit(prize, lstVote, ref dicVote, ref dicRemain);

                //if (strVoteCode == "0601" && (dicRemain["Recommended"] == 0
                //    || (strLevelCode == "0401" && dicRemain["FirstPrize"] == 0)
                //    || (strLevelCode == "0402" && dicRemain["SecondPrize"] == 0)
                //    || (strLevelCode == "0403" && dicRemain["ThirdPrize"] == 0)))
                //{
                //    throw new Exception("所投选项名额已满,请重新投票!");
                //}

                Dal.Models.Vote vote = new Dal.Models.Vote()
                {
                    UserID            = user.UserID.Value,
                    Votor             = expert.ExpertID.Value,
                    ActivityID        = prize.ActivityID.Value,
                    MultipleVoteRound = prize.MultipleVoteRound ?? 1,
                    VoteRound         = prize.MultipleVoteRound ?? 1,
                    IsSubmit          = false,
                    PrizeID           = prize.PrizeID.Value,
                    VoteCode          = strVoteCode,
                    PrizeLevelCode    = strLevelCode,
                    VoteType          = "0502"
                };

                BLL.Vote.BatchBallot(vote, conn, tran);

                tran.Commit();
                context.Response.Write(JsonConvert.SerializeObject("投票成功!"));
            }
            catch (Exception ex)
            {
                tran.Rollback();
                context.Response.Write(JsonConvert.SerializeObject(ex.Message));
            }
        }
Esempio n. 2
0
        //public void FinishVote(HttpContext context, OleDbConnection conn)
        //{
        //    Dal.Models.UserInfo user = (Dal.Models.UserInfo)context.Session["UserInfo"];

        //    //Issubmit="1",是投票结果的状态为提交,专家不能再更改投票结果,投票时,此字段默认值为0
        //    string strIsSubmit = "1";

        //    //获取当前活动类型编码
        //    string strActivityType = context.Session["ActivityType"].ToString();

        //    //获取当前活动ID
        //    int iActivityID = BLL.Activity.GetActivity(strActivityType, conn).ActivityID.Value;

        //    //获取当前活动时间节点
        //    Dal.Models.Schedule schedule = BLL.Schedule.GetActivitySchedule(iActivityID, conn);

        //    //获取所有本次活动的奖项

        //    List<Dal.Models.Prize> lstPrize = BLL.Prize.GetPrizeList(user, strActivityType, "", conn);

        //    //修改Schedule的投票阶段
        //    BLL.Vote.UpdateScheduleVoteFinish(schedule.ScheduleID.Value, false, conn);

        //    foreach (var item in lstPrize)
        //    {
        //        List<Dal.Models.Vote> lstVote = BLL.Vote.GetActivityPrizeVoteList(item.PrizeID.Value, conn);
        //        foreach (var Vote in lstVote)
        //        {
        //            //修改Vote为已经提交
        //            BLL.Vote.SubmitVote(Vote.VoteID.Value, strIsSubmit, conn);
        //        }
        //    }
        //    context.Response.Write("投票已提交");
        //}

        private void Ballot(HttpContext context, OleDbConnection conn)
        {
            Dal.Models.UserInfo user   = (Dal.Models.UserInfo)context.Session["UserInfo"];
            Dal.Models.Expert   expert = BLL.Expert.GetExpertByUserID(user.UserID.Value, conn);
            OleDbTransaction    tran   = conn.BeginTransaction();

            try
            {
                int iDeclarationID     = 0;
                int iPrizeID           = 0;
                int iMultipleVoteRound = 0;
                if (!int.TryParse(context.Request["DeclarationID"], out iDeclarationID) ||
                    !int.TryParse(context.Request["PrizeID"], out iPrizeID) ||
                    !int.TryParse(context.Request["MultipleVoteRound"], out iMultipleVoteRound))
                {
                    throw new Exception("参数错误!");
                }

                Dal.Models.Prize prize = BLL.Prize.GetPrize(iPrizeID, conn, tran);
                if (prize == null || prize.IsStopVote)
                {
                    throw new Exception("当前奖项及轮次已结束投票。");
                }


                string strVoteCode  = context.Request["VoteCode"];
                string strLevelCode = context.Request["LevelCode"];
                if (strLevelCode == "0404")
                {
                    strLevelCode = "";
                }

                Dal.Models.Declaration decl = BLL.Declaration.GetDeclaration(iDeclarationID, conn, tran);
                if (decl.PrizeID != iPrizeID)
                {
                    throw new Exception("参数错误!");
                }

                prize = BLL.Prize.GetPrize(decl.AdjustedPrize.Value, conn, tran);
                if (prize.MultipleVoteRound != iMultipleVoteRound)
                {
                    throw new Exception("当前已进入新一轮投票,请重新进入本页面进行投票!");
                }

                Dal.Models.Vote vote = new Dal.Models.Vote()
                {
                    UserID            = user.UserID.Value,
                    Votor             = expert.ExpertID.Value,
                    DeclarationID     = iDeclarationID,
                    ActivityID        = decl.ActivityID.Value,
                    MultipleVoteRound = prize.MultipleVoteRound ?? 1,
                    RevoteCode        = prize.RevoteCode ?? "",
                    RevoteRound       = prize.RevoteRound ?? 0,
                    IsSubmit          = false,
                    PrizeID           = prize.PrizeID.Value,
                    VoteCode          = strVoteCode,
                    PrizeLevelCode    = strLevelCode,
                    VoteType          = "0502"
                };

                BLL.Vote.Ballot(vote, conn, tran);

                //根据专家和奖项获评奖项目
                List <Dal.Models.Vote> lstVote = BLL.Vote.GetVoteDeclarationList(expert, prize, conn, tran);

                //获取每个奖项的已评奖数量
                Dictionary <string, int> dicVote = new Dictionary <string, int>();

                //获取每个奖项未评奖数量
                Dictionary <string, int> dicRemain = new Dictionary <string, int>();

                GetLimit(prize, lstVote, ref dicVote, ref dicRemain);

                string Message = "";
                //if (strVoteCode == "0601" && (dicRemain["Recommended"] == 0
                //    || (strLevelCode == "0401" && dicRemain["FirstPrize"] == 0)
                //    || (strLevelCode == "0402" && dicRemain["SecondPrize"] == 0)
                //    || (strLevelCode == "0403" && dicRemain["ThirdPrize"] == 0)))
                //{
                //    Message = "所投选项名额已满,请注意!";
                //}
                //else
                //{
                Message = "投票成功!";
                //}

                tran.Commit();

                object[] obj = { prize, lstVote, dicVote, dicRemain, Message };

                context.Response.Write(JsonConvert.SerializeObject(obj));
            }
            catch (Exception ex)
            {
                tran.Rollback();
                context.Response.Write(JsonConvert.SerializeObject(new object[] { ex.Message }));
            }
        }