private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { int index = e.ColumnIndex; string str = dataGridView1.Rows[e.RowIndex].Cells["PostId"].Value.ToString(); int postId = Convert.ToInt32(str); postNow = PostServices.GetPostByPostId(postId); if (index == 5) //查看详情 { Form_postDetail form = new Form_postDetail(postNow); form.Show(); } else if (index == 6)//收藏 { //已经收藏 if (ManagePostsServices.GetCollectByUserIdAndPostId(UserNow.UserId, postNow.PostId) != 0) { MessageBox.Show("已收藏过该帖子!"); return; } //未收藏 Collect c = new Collect(postNow.PostId, UserNow.UserId, DateTime.Now); ManagePostsServices.Collect(c); MessageBox.Show("收藏成功!"); } }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { int index = e.ColumnIndex; string str = dataGridView1.Rows[e.RowIndex].Cells["PostId"].Value.ToString(); int postId = Convert.ToInt32(str); postNow = PostServices.GetPostByPostId(postId); if (index == 7) //查看详情 { Form_postDetail form = new Form_postDetail(postNow); form.Show(); } else if (index == 8)//删除 { if (label_myPostsOrCollects.Text == "收藏") { int collectId = ManagePostsServices.GetCollectByUserIdAndPostId(user.UserId, postId); ManagePostsServices.DeleteCollect(collectId); MessageBox.Show("取消收藏成功!"); } else //我的帖子 { PostServices.DeletePost(user.UserId, postId); MessageBox.Show("删除成功!"); } } else if (index == 9)//修改 { } }