/// <summary> /// Called whenever the comments collection has changed. /// </summary> /// <param name="sender">Object that has raised the event</param> /// <param name="e">Information about the change</param> protected void OnCommentsChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { foreach (Comment comment in e.NewItems) { _Comment implComment = comment as _Comment; if (implComment == null) { throw new ArgumentException("A comment element created outside the model " + "library has been added to this element!"); } } } else if (e.Action == NotifyCollectionChangedAction.Remove) { foreach (Comment comment in e.OldItems) { _Comment implComment = (_Comment)comment; } } }
public ActionResult UpdateComments(string id) { SqlConnection connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=PAP1;Integrated Security=True"); SqlDataAdapter dataAdapter2 = new SqlDataAdapter("SELECT * FROM Comment Where video=" + id + " Order By createdAt", connection); DataSet dataSet2 = new DataSet(); dataAdapter2.Fill(dataSet2); List <_Comment> Comments = new List <_Comment>(); foreach (DataRow row2 in dataSet2.Tables[0].Rows) { _Comment C = new _Comment(); C.id = int.Parse(row2["id"].ToString()); C.comment = row2["comment"].ToString(); C.username = row2["username"].ToString(); C.discriminator = int.Parse(row2["discriminator"].ToString()); C.createdAt = DateTime.Parse(row2["createdAt"].ToString()); Comments.Add(C); } return(PartialView("VideoComments", Comments)); }
/// <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(); }