示例#1
0
        public static VotingModel GetVotingById(int id)
        {
            var model = new VotingModel();
            var sql = string.Format(@"Select top 1 * from VotingModels  where ID={0}", id);
            var dt = GetDataTable(sql);

            foreach (DataRow row in dt.Rows)
            {
                model.ID = int.Parse(row["ID"].ToString());
                model.Exciting = int.Parse(row["Exciting"].ToString());
                model.Gender = (Gender)Enum.Parse(typeof(Gender), row["Gender"].ToString());
                model.Happy = int.Parse(row["Happy"].ToString());
                model.Sad = int.Parse(row["Sad"].ToString());
                model.Upset = int.Parse(row["Upset"].ToString());
                model.VotingDate = DateTime.Parse(row["VotingDate"].ToString());
            }

            return model;
        }
示例#2
0
        /// <summary>
        /// 是否是今天第一次投票
        /// </summary>
        /// <param name="votingModel">The voting model.</param>
        /// <returns>True / False</returns>
        private bool IsFirstVoteToday(VotingModel votingModel)
        {
            var hasMaleRecord = db.Votings.Where(a => a.Gender == Gender.男生 && votingModel.VotingDate == a.VotingDate).Any();
            var hasFemaleRecord = db.Votings.Where(a => a.Gender == Gender.女生 && votingModel.VotingDate == a.VotingDate).Any();
            //var hasMaleRecord = SqlHelper.HasMaleRecord();
            //var hasFemaleRecord = SqlHelper.HasFemaleRecord();

            if (hasMaleRecord == false && votingModel.Gender == Gender.男生)
            {
                return true;
            }

            if (hasFemaleRecord == false && votingModel.Gender == Gender.女生)
            {
                return true;
            }

            return false;
        }
示例#3
0
 private void InsertVoting(VotingModel votingModel)
 {
     db.Votings.Add(votingModel);
     db.SaveChanges();
     //SqlHelper.InsertVoting(votingModel);
 }
示例#4
0
        /// <summary>
        /// 是否是今天第一次投票
        /// </summary>
        /// <param name="votingModel">The voting model.</param>
        /// <returns>True / False</returns>
        private bool IsFirstVoteToday(VotingModel votingModel)
        {
            var hasMaleRecord = SqlHelper.HasMaleRecord();
            var hasFemaleRecord = SqlHelper.HasFemaleRecord();

            if (hasMaleRecord == false && votingModel.Gender == Gender.男生)
            {
                return true;
            }

            if (hasFemaleRecord == false && votingModel.Gender == Gender.女生)
            {
                return true;
            }

            return false;
        }
示例#5
0
 private void InsertVoting(VotingModel votingModel)
 {
     SqlHelper.InsertVoting(votingModel);
 }
示例#6
0
        public static void InsertVoting(VotingModel votingModel)
        {
            var sql = string.Format(@"Insert into VotingModels (Gender, Emotion, Exciting, Happy, Sad, Upset, VotingDate)  values({0},{1},{2},{3},{4},{5},'{6}')",
                (int)votingModel.Gender,
                (int)votingModel.Emotion,
                votingModel.Exciting,
                votingModel.Happy,
                votingModel.Sad,
                votingModel.Upset,
                votingModel.VotingDate);

            bool result = ExecuteSql(sql);
        }
示例#7
0
        public static void UpdateVotingById(VotingModel votingModel)
        {
            var sql = string.Format(@"Update VotingModels set Exciting={0}, Happy={1}, Sad={2}, Upset={3} where ID={4}",
                votingModel.Exciting,
                votingModel.Happy,
                votingModel.Sad,
                votingModel.Upset,
                votingModel.ID);

            bool result = ExecuteSql(sql);
        }