Example #1
0
 /// <summary>
 /// 开启事务
 /// </summary>
 /// <returns></returns>
 protected void BeginTran()
 {
     TranHelper = new TranHelper();
     Tran       = TranHelper.Tran;
     Conn       = TranHelper.Conn;
 }
Example #2
0
 protected void BeginTranEF()
 {
     TranHelper = new TranHelper(ConfigurationManager.ConnectionStrings["AmazonBBSDBContext"].ConnectionString);
     Tran       = TranHelper.Tran;
 }
Example #3
0
        /// <summary>
        /// 处理每个帖子的优秀答题者(按最多点赞来)(---每24小时刷新一次---)
        /// </summary>
        private void NiceAnswer()
        {
            Thread t = new Thread(() =>
            {
                //计划每天凌晨3点执行吧
                DateTime now = DateTime.Now;
                int hours    = 0;
                if (now.Hour > 3)
                {
                    hours = 27 - now.Hour;
                    Thread.Sleep(hours * 60 * 60 * 1000);
                }

                var coinSource = CoinSourceEnum.NiceAnswer.GetHashCode();
                while (true)
                {
                    List <_QuestionInfo> questions = QuestionBLL.Instance.GetALLQuestion();
                    questions.ForEach(question =>
                    {
                        if (question.CommentCount > 1)
                        {
                            _Comment niceComment = QuestionBLL.Instance.GetNiceComment(question.QuestionId, question.BestAnswerId);
                            if (niceComment != null)
                            {
                                if (question.NiceAnswerId != niceComment.CommentId)
                                {
                                    TranHelper tranHelper = new TranHelper();
                                    try
                                    {
                                        if (SqlHelper.ExecuteSql(tranHelper.Tran, System.Data.CommandType.Text, "update Question set NiceAnswerId={0} where QuestionId={1}".FormatWith(niceComment.CommentId, question.QuestionId)) > 0)
                                        {
                                            int coin           = Convert.ToInt32(question.Coin);
                                            int coinType       = Convert.ToInt32(question.CoinType);
                                            long commentUserId = Convert.ToInt64(niceComment.CommentUserID);
                                            if (coinType != 0)
                                            {
                                                //判断是否已赠送过积分
                                                if (!ScoreCoinLogBLL.Instance.HasGiveScore(commentUserId, question.QuestionId, coinType, coinSource, tranHelper.Tran))
                                                {
                                                    //未赠送过,则赠送积分
                                                    if (UserExtBLL.Instance.AddScore(commentUserId, coin * 7 / 10, coinType, tranHelper.Tran))
                                                    {
                                                        if (ScoreCoinLogBLL.Instance.Log(coin * 7 / 10, coinType, CoinSourceEnum.NiceAnswer, commentUserId, niceComment.UserName, tranHelper.Tran, question.QuestionId))
                                                        {
                                                            tranHelper.Commit();
                                                        }
                                                        else
                                                        {
                                                            tranHelper.RollBack();
                                                        }
                                                        tranHelper.Dispose();
                                                    }
                                                    else
                                                    {
                                                        tranHelper.RollBack();
                                                        tranHelper.Dispose();
                                                    }
                                                }
                                                else
                                                {
                                                    tranHelper.RollBack();
                                                    tranHelper.Dispose();
                                                }
                                            }
                                            else
                                            {
                                                tranHelper.Commit();
                                            }
                                        }
                                        else
                                        {
                                            tranHelper.RollBack();
                                            tranHelper.Dispose();
                                        }
                                    }
                                    catch
                                    {
                                        tranHelper.RollBack();
                                        tranHelper.Dispose();
                                    }
                                    finally
                                    {
                                        //Thread.Sleep(1 * 10 * 1000);
                                    }
                                }
                            }
                        }
                    });
                    Thread.Sleep(24 * 60 * 60 * 1000);
                }
            });

            t.IsBackground = true;
            t.Start();
        }