public bool setAccusation(int _AccuselID, string _AccusedAvatar, int _AccusedID) { Accusation_Table At = new Accusation_Table(); At.MemberID = Viewbag.member.MemberID; // At.MemberID = 3; At.AccuseID = _AccuselID + 1; At.AccusedAvatar = _AccusedAvatar; At.AccusedID = _AccusedID.ToString(); DE.Accusation_Table.Add(At); DE.SaveChanges(); if (_AccusedAvatar == "0") { Recipe_Table q = (from n in DE.Recipe_Table where n.RecipeID == _AccusedID select n).FirstOrDefault(); q.DisVisible = true; } else if (_AccusedAvatar == "1") { CommentSection_Table q = (from n in DE.CommentSection_Table where n.CommentID == _AccusedID select n).FirstOrDefault(); q.DisVisible = true; } DE.SaveChanges(); return(true); }
//評論區 private void btn_SendComment_Click(object sender, EventArgs e) { string comment = tb_Comment.Text.Trim(); string URL = tb_CommentVideo.Text; byte[] bytes; MemoryStream ms = new MemoryStream();//建立一個資料流物件 if (pb_UploadIMG.Image != null) { pb_UploadIMG.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); //儲存成jpeg格式到ms bytes = ms.GetBuffer(); //將資料流轉換成byte[]陣列 } else { bytes = null; } if (comment == "") { MessageBox.Show("評論不可為空白"); } else if (URL != "" && (!URL.Contains("youtu.be") && !URL.Contains("youtube"))) { MessageBox.Show("非YouTube網址"); } else { try { CommentSection_Table table = new CommentSection_Table() { RecipeID = rpid, CommentFloor = floor + 1, MemberID = memberData.MemberID, Comment = comment, Picture = bytes, Video = URL, PostTime = DateTime.Now, DisVisible = false, DeleteOrNot = false }; Delicious.CommentSection_Table.Add(table); Delicious.SaveChanges(); MessageBox.Show("新增評論成功"); LoadComment(); CommentShade(); tb_Comment.Text = ""; tb_CommentVideo.Text = ""; pb_UploadIMG.Image = null; } catch (Exception) { MessageBox.Show("新增評論失敗,請聯絡管理員"); } } }
private void btn_UpdateComment_Click(object sender, EventArgs e) { string comment = tb_Comment.Text.Trim(); string URL = tb_CommentVideo.Text; byte[] bytes; try { MemoryStream ms = new MemoryStream(); CommentSection_Table commentTB = Delicious.CommentSection_Table.Where(c => c.CommentID == cmid).FirstOrDefault(); if (pb_UploadIMG.Image != null) { pb_UploadIMG.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); //儲存成jpeg格式到ms bytes = ms.GetBuffer(); //將資料流轉換成byte[]陣列 } else { bytes = null; } if (comment == "") { MessageBox.Show("評論不可為空白"); } else if (URL != "" && (!URL.Contains("youtu.be") && !URL.Contains("youtube"))) { MessageBox.Show("非YouTube網址"); } else { commentTB.Comment = comment; commentTB.Picture = bytes; commentTB.Video = URL; Delicious.SaveChanges(); MessageBox.Show("評論更新成功"); LoadComment(); CommentShade(); btn_SendComment.Click -= btn_UpdateComment_Click; btn_SendComment.Click += btn_SendComment_Click; btn_EditComment.Click -= btn_CancelEditComment_Click; btn_EditComment.Click += btn_EditComment_Click; btn_deComment.Enabled = true; btn_EditComment.Text = "編輯"; btn_SendComment.Text = "發表評論"; pb_UploadIMG.Image = null; tb_Comment.Text = ""; tb_CommentVideo.Text = ""; } } catch (Exception) { MessageBox.Show("更新失敗"); } }
private void btn_deComment_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("確定刪除?", "系統提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { try { CommentSection_Table table = Delicious.CommentSection_Table.Where(c => c.CommentID == cmid).FirstOrDefault(); table.DeleteOrNot = true; Delicious.SaveChanges(); MessageBox.Show("刪除留言成功"); } catch (Exception) { MessageBox.Show("刪除失敗"); } } LoadComment(); CommentShade(); }
private void button2_Click(object sender, EventArgs e) { int get_select = Convert.ToInt32(dataGridView1.CurrentRow.Cells["AccusedID"].Value); int get_select_Accusation = Convert.ToInt32(dataGridView1.CurrentRow.Cells["AccusationRightID"].Value); CommentSection_Table q = (from n in DE.CommentSection_Table where n.CommentID == get_select select n).FirstOrDefault(); q.DisVisible = false; DE.SaveChanges(); var q2 = (from n in DE.Accusation_Table where n.AccusationRightID == get_select_Accusation select n).FirstOrDefault(); q2.ProgressID = 1; DE.SaveChanges(); var result = (from n in DE.CommentSection_Table where n.CommentID == get_select select new { n.RecipeID, n.CommentID, n.MemberID, n.Comment, n.DisVisible }); dataGridView2.DataSource = result.ToList(); }