Web and Desktop - comment threads

This commit is contained in:
Dimitar Byalkov
2023-05-04 21:10:00 +02:00
parent 913bb39ba8
commit eea8cf9aac
13 changed files with 786 additions and 28 deletions

View File

@@ -28,9 +28,9 @@ namespace StudentHouseDashboard.Managers
{
return announcementRepository.CreateAnnouncement(title, description, author, publishDate, isImportant, isSticky);
}
public bool UpdateAnnouncement(int id, string title, string description, User author, DateTime publishDate, bool isImportant, bool isSticky)
public bool UpdateAnnouncement(int id, string title, string description, bool isImportant, bool isSticky)
{
return announcementRepository.UpdateAnnouncement(id, title, description, author, publishDate, isImportant, isSticky);
return announcementRepository.UpdateAnnouncement(id, title, description, isImportant, isSticky);
}
public bool DeleteAnnouncement(int id)
{

View File

@@ -1,6 +1,40 @@
namespace StudentHouseDashboard.Managers;
using StudentHouseDashboard.Models;
using StudentHouseDashboard.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class CommentManager
namespace StudentHouseDashboard.Managers
{
//TODO: CRUD
}
public class CommentManager
{
private CommentRepository commentRepository;
public CommentManager()
{
commentRepository = new CommentRepository();
}
public void CreateCommentToAnnouncement(User author, string description, string title, DateTime publishDate, int announcementId)
{
commentRepository.CreateCommentOnAnnouncement(author, description, title, publishDate, announcementId);
}
public void CreateResponseToComment(User author, string description, string title, DateTime publishDate, int commentId)
{
commentRepository.CreateResponseOnComment(author, description, title, publishDate, commentId);
}
public void UpdateComment(int id, string description)
{
commentRepository.UpdateComment(id, description);
}
public void DeleteCommentOnAnnouncement(int commentId, int announcementId)
{
commentRepository.DeleteCommentOnAnnouncement(commentId, announcementId);
}
public void DeleteResponseOnComment(int responseId, int commentId)
{
commentRepository.DeleteResponseOnComment(responseId, commentId);
}
}
}

View File

@@ -22,5 +22,9 @@ namespace StudentHouseDashboard.Models
{
throw new NotImplementedException();
}
public override string ToString()
{
return $"{Author.Name} ({PublishDate.ToString("g")}) - {Description.PadRight(100).Trim()}";
}
}
}

View File

@@ -90,18 +90,16 @@ namespace StudentHouseDashboard.Repositories
else return false;
}
}
public bool UpdateAnnouncement(int id, string title, string description, User author, DateTime publishDate, bool isImportant, bool isSticky)
public bool UpdateAnnouncement(int id, string title, string description, bool isImportant, bool isSticky)
{
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
{
string sql = "UPDATE Announcements " +
"SET Author = @author, Description = @desc, Title = @title, PublishDate = @date, IsImportant = @important, IsSticky = @sticky " +
"SET Description = @desc, Title = @title, IsImportant = @important, IsSticky = @sticky " +
"WHERE Id = @id;";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@author", author.ID);
cmd.Parameters.AddWithValue("@desc", description);
cmd.Parameters.AddWithValue("@title", title);
cmd.Parameters.AddWithValue("@date", publishDate);
cmd.Parameters.AddWithValue("@important", isImportant);
cmd.Parameters.AddWithValue("@sticky", isSticky);
cmd.Parameters.AddWithValue("@id", id);

View File

@@ -1,3 +1,4 @@
using System.ComponentModel.Design;
using System.Data.SqlClient;
using StudentHouseDashboard.Models;
@@ -7,7 +8,7 @@ public class CommentRepository
{
public CommentRepository()
{
}
public List<Comment> GetAllCommentsOnAnnouncement(int announcementId)
@@ -65,4 +66,119 @@ public class CommentRepository
return responses;
}
public Comment GetCommentById(int id)
{
using (SqlConnection connection = SqlConnectionHelper.CreateConnection())
{
string sql = "SELECT c.ID, c.Author, c.Description, c.Title, c.PublishDate, " +
"u.ID UserID, u.Name UserName, u.Password, u.Role FROM Comments c " +
"INNER JOIN Users u ON u.ID = c.Author " +
"WHERE c.ID = @commentID;";
SqlCommand sqlCommand = new SqlCommand(sql, connection);
sqlCommand.Parameters.AddWithValue("@commentID", id);
var reader = sqlCommand.ExecuteReader();
reader.Read();
Comment newComment = new Comment((int)reader["ID"],
new User((int)reader["UserID"], reader["UserName"].ToString(),
reader["Password"].ToString(), (UserRole)reader["Role"]),
reader["Description"].ToString(), reader["Title"].ToString(),
(DateTime)reader["PublishDate"]);
newComment.Responses = GetAllCommentResponses(newComment.ID);
return newComment;
}
}
public void UpdateComment(int id, string description)
{
using (SqlConnection connection = SqlConnectionHelper.CreateConnection())
{
string sql = "UPDATE Comments " +
"SET Description = @desc " +
"WHERE Id = @id;";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.Parameters.AddWithValue("@desc", description);
cmd.Parameters.AddWithValue("@id", id);
int writer = cmd.ExecuteNonQuery();
}
}
private Comment CreateComment(User author, string description, string title, DateTime publishDate)
{
using (SqlConnection connection = SqlConnectionHelper.CreateConnection())
{
string sql = "INSERT INTO Comments (Author, Description, Title, PublishDate) " +
"VALUES (@author, @desc, @title, @date); " +
"SELECT SCOPE_IDENTITY();";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.Parameters.AddWithValue("@author", author.ID);
cmd.Parameters.AddWithValue("@desc", description);
cmd.Parameters.AddWithValue("@title", title);
cmd.Parameters.AddWithValue("@date", publishDate);
return GetCommentById(Convert.ToInt32(cmd.ExecuteScalar()));
}
}
public void CreateCommentOnAnnouncement(User author, string description, string title, DateTime publishDate, int announcementId)
{
Comment comment = CreateComment(author, description, title, publishDate);
using (SqlConnection connection = SqlConnectionHelper.CreateConnection())
{
string sql = "INSERT INTO AnnouncementsComments (AnnouncementID, CommentID) VALUES (@announcementID, @commentID);";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.Parameters.AddWithValue("@announcementID", announcementId);
cmd.Parameters.AddWithValue("@commentID", comment.ID);
int writer = cmd.ExecuteNonQuery();
}
}
public void CreateResponseOnComment(User author, string description, string title, DateTime publishDate, int commentId)
{
Comment response = CreateComment(author, description, title, publishDate);
using (SqlConnection connection = SqlConnectionHelper.CreateConnection())
{
string sql = "INSERT INTO CommentsResponses (CommentID, ResponseID) VALUES (@commentID, @responseID);";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.Parameters.AddWithValue("@commentID", commentId);
cmd.Parameters.AddWithValue("@responseID", response.ID);
int writer = cmd.ExecuteNonQuery();
}
}
private void DeleteComment(int id)
{
using (SqlConnection connection = SqlConnectionHelper.CreateConnection())
{
string sql = "DELETE FROM Comments " +
"WHERE Id = @id;";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.Parameters.AddWithValue("@id", id);
int writer = cmd.ExecuteNonQuery();
}
}
public void DeleteCommentOnAnnouncement(int commentId, int announcementId)
{
using (SqlConnection connection = SqlConnectionHelper.CreateConnection())
{
string sql = "DELETE FROM AnnouncementsComments " +
"WHERE CommentID = @commentId AND AnnouncementID = @announcementId";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.Parameters.AddWithValue("@commentId", commentId);
cmd.Parameters.AddWithValue("@announcementId", announcementId);
int writer = cmd.ExecuteNonQuery();
}
DeleteComment(commentId);
}
public void DeleteResponseOnComment(int responseId, int commentId)
{
using (SqlConnection connection = SqlConnectionHelper.CreateConnection())
{
string sql = "DELETE FROM AnnouncementsComments " +
"WHERE CommentID = @commentId AND ResponseID = @responseId";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.Parameters.AddWithValue("@commentId", commentId);
cmd.Parameters.AddWithValue("@responseId", responseId);
int writer = cmd.ExecuteNonQuery();
}
DeleteComment(commentId);
}
}

View File

@@ -8,6 +8,8 @@
int currentPage = @Convert.ToInt32(ViewData["page"]);
}
@foreach (Announcement announcement in announcements)
{
<div class="card" style="display:inline-block; width: 18rem;">

View File

@@ -38,6 +38,12 @@
ckbSticky = new CheckBox();
dtpPublishDate = new DateTimePicker();
lblAuthor = new Label();
lblComments = new Label();
listBox1 = new ListBox();
btnViewComment = new Button();
btnEditComment = new Button();
btnDeleteComment = new Button();
btnCreateComment = new Button();
SuspendLayout();
//
// lblTitle
@@ -128,11 +134,75 @@
lblAuthor.TabIndex = 10;
lblAuthor.Text = "Created by: ";
//
// lblComments
//
lblComments.AutoSize = true;
lblComments.Location = new Point(12, 209);
lblComments.Name = "lblComments";
lblComments.Size = new Size(66, 15);
lblComments.TabIndex = 11;
lblComments.Text = "Comments";
//
// listBox1
//
listBox1.FormattingEnabled = true;
listBox1.ItemHeight = 15;
listBox1.Location = new Point(12, 227);
listBox1.Name = "listBox1";
listBox1.Size = new Size(399, 154);
listBox1.TabIndex = 12;
//
// btnViewComment
//
btnViewComment.Location = new Point(424, 271);
btnViewComment.Name = "btnViewComment";
btnViewComment.Size = new Size(75, 23);
btnViewComment.TabIndex = 13;
btnViewComment.Text = "View";
btnViewComment.UseVisualStyleBackColor = true;
btnViewComment.Click += btnViewComment_Click;
//
// btnEditComment
//
btnEditComment.Location = new Point(424, 300);
btnEditComment.Name = "btnEditComment";
btnEditComment.Size = new Size(75, 23);
btnEditComment.TabIndex = 14;
btnEditComment.Text = "Edit";
btnEditComment.UseVisualStyleBackColor = true;
btnEditComment.Click += btnEditComment_Click;
//
// btnDeleteComment
//
btnDeleteComment.Location = new Point(424, 329);
btnDeleteComment.Name = "btnDeleteComment";
btnDeleteComment.Size = new Size(75, 23);
btnDeleteComment.TabIndex = 15;
btnDeleteComment.Text = "Delete";
btnDeleteComment.UseVisualStyleBackColor = true;
btnDeleteComment.Click += btnDeleteComment_Click;
//
// btnCreateComment
//
btnCreateComment.Location = new Point(424, 358);
btnCreateComment.Name = "btnCreateComment";
btnCreateComment.Size = new Size(75, 23);
btnCreateComment.TabIndex = 16;
btnCreateComment.Text = "New";
btnCreateComment.UseVisualStyleBackColor = true;
btnCreateComment.Click += btnCreateComment_Click;
//
// AnnouncementForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(511, 216);
ClientSize = new Size(511, 400);
Controls.Add(btnCreateComment);
Controls.Add(btnDeleteComment);
Controls.Add(btnEditComment);
Controls.Add(btnViewComment);
Controls.Add(listBox1);
Controls.Add(lblComments);
Controls.Add(lblAuthor);
Controls.Add(dtpPublishDate);
Controls.Add(ckbSticky);
@@ -161,5 +231,11 @@
private CheckBox ckbSticky;
private DateTimePicker dtpPublishDate;
private Label lblAuthor;
private Label lblComments;
private ListBox listBox1;
private Button btnViewComment;
private Button btnEditComment;
private Button btnDeleteComment;
private Button btnCreateComment;
}
}

View File

@@ -16,17 +16,18 @@ namespace WinForms
{
Announcement announcement;
User currentUser;
public AnnouncementForm(Announcement? announcement, bool readOnly, User? currentUser)
public AnnouncementForm(Announcement? announcement, bool readOnly, User currentUser)
{
InitializeComponent();
this.announcement = announcement;
this.currentUser = currentUser;
dtpPublishDate.Enabled = false;
if (readOnly)
{
btnSave.Enabled = false;
tbTitle.Enabled = false;
tbDescription.Enabled = false;
dtpPublishDate.Enabled = false;
ckbImportant.Enabled = false;
ckbSticky.Enabled = false;
}
@@ -38,12 +39,19 @@ namespace WinForms
dtpPublishDate.Value = announcement.PublishDate;
ckbImportant.Checked = announcement.IsImportant;
ckbSticky.Checked = announcement.IsSticky;
RefreshComments();
}
else
{
btnCreateComment.Enabled = false;
btnDeleteComment.Enabled = false;
btnEditComment.Enabled = false;
btnViewComment.Enabled = false;
}
if (currentUser != null)
{
lblAuthor.Text = $"Created by: {currentUser.Name}";
}
}
private void btnSave_Click(object sender, EventArgs e)
@@ -61,9 +69,72 @@ namespace WinForms
}
else
{
announcementManager.UpdateAnnouncement(announcement.ID, tbTitle.Text, tbDescription.Text, currentUser, dtpPublishDate.Value, ckbImportant.Checked, ckbSticky.Checked);
announcementManager.UpdateAnnouncement(announcement.ID, tbTitle.Text, tbDescription.Text, ckbImportant.Checked, ckbSticky.Checked);
}
this.DialogResult = DialogResult.OK;
}
private void btnViewComment_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex == -1)
{
MessageBox.Show("Please select an item from the list");
}
else
{
CommentForm form = new CommentForm((Comment)listBox1.SelectedItem, true, currentUser);
form.ShowDialog();
RefreshComments();
}
}
private void btnEditComment_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex == -1)
{
MessageBox.Show("Please select an item from the list");
}
else
{
CommentForm form = new CommentForm((Comment)listBox1.SelectedItem, false, currentUser);
form.ShowDialog();
RefreshComments();
}
}
private void btnDeleteComment_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex == -1)
{
MessageBox.Show("Please select an item from the list");
}
else
{
Comment currentComment = (Comment)listBox1.SelectedItem;
if (MessageBox.Show($"Are you sure you want to delete\n{currentComment.Title}\nCreated at {currentComment.PublishDate.ToString("g")} by {currentComment.Author.Name}",
"Delete announcement", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
CommentManager commentManager = new CommentManager();
commentManager.DeleteCommentOnAnnouncement(currentComment.ID, announcement.ID);
}
RefreshComments();
}
}
private void btnCreateComment_Click(object sender, EventArgs e)
{
CommentForm form = new CommentForm(null, false, currentUser, true, announcement.ID);
form.ShowDialog();
RefreshComments();
}
private void RefreshComments()
{
listBox1.Items.Clear();
foreach (var item in announcement.Comments)
{
listBox1.Items.Add(item);
}
}
}
}

View File

@@ -0,0 +1,215 @@
namespace WinForms
{
partial class CommentForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
btnCreateComment = new Button();
btnDeleteComment = new Button();
btnEditComment = new Button();
btnViewComment = new Button();
listBox1 = new ListBox();
lblComments = new Label();
lblAuthor = new Label();
dtpPublishDate = new DateTimePicker();
btnSave = new Button();
lblPublishDate = new Label();
tbDescription = new TextBox();
lblDescription = new Label();
tbTitle = new TextBox();
lblTitle = new Label();
SuspendLayout();
//
// btnCreateComment
//
btnCreateComment.Location = new Point(424, 358);
btnCreateComment.Name = "btnCreateComment";
btnCreateComment.Size = new Size(75, 23);
btnCreateComment.TabIndex = 30;
btnCreateComment.Text = "New";
btnCreateComment.UseVisualStyleBackColor = true;
btnCreateComment.Click += btnCreateComment_Click;
//
// btnDeleteComment
//
btnDeleteComment.Location = new Point(424, 329);
btnDeleteComment.Name = "btnDeleteComment";
btnDeleteComment.Size = new Size(75, 23);
btnDeleteComment.TabIndex = 29;
btnDeleteComment.Text = "Delete";
btnDeleteComment.UseVisualStyleBackColor = true;
btnDeleteComment.Click += btnDeleteComment_Click;
//
// btnEditComment
//
btnEditComment.Location = new Point(424, 300);
btnEditComment.Name = "btnEditComment";
btnEditComment.Size = new Size(75, 23);
btnEditComment.TabIndex = 28;
btnEditComment.Text = "Edit";
btnEditComment.UseVisualStyleBackColor = true;
btnEditComment.Click += btnEditComment_Click;
//
// btnViewComment
//
btnViewComment.Location = new Point(424, 271);
btnViewComment.Name = "btnViewComment";
btnViewComment.Size = new Size(75, 23);
btnViewComment.TabIndex = 27;
btnViewComment.Text = "View";
btnViewComment.UseVisualStyleBackColor = true;
btnViewComment.Click += btnViewComment_Click;
//
// listBox1
//
listBox1.FormattingEnabled = true;
listBox1.ItemHeight = 15;
listBox1.Location = new Point(12, 227);
listBox1.Name = "listBox1";
listBox1.Size = new Size(399, 154);
listBox1.TabIndex = 26;
//
// lblComments
//
lblComments.AutoSize = true;
lblComments.Location = new Point(12, 209);
lblComments.Name = "lblComments";
lblComments.Size = new Size(66, 15);
lblComments.TabIndex = 25;
lblComments.Text = "Comments";
//
// lblAuthor
//
lblAuthor.AutoSize = true;
lblAuthor.Location = new Point(12, 184);
lblAuthor.Name = "lblAuthor";
lblAuthor.Size = new Size(70, 15);
lblAuthor.TabIndex = 24;
lblAuthor.Text = "Created by: ";
//
// dtpPublishDate
//
dtpPublishDate.Location = new Point(94, 153);
dtpPublishDate.Name = "dtpPublishDate";
dtpPublishDate.Size = new Size(200, 23);
dtpPublishDate.TabIndex = 23;
//
// btnSave
//
btnSave.Location = new Point(424, 180);
btnSave.Name = "btnSave";
btnSave.Size = new Size(75, 23);
btnSave.TabIndex = 22;
btnSave.Text = "Save changes";
btnSave.UseVisualStyleBackColor = true;
btnSave.Click += btnSave_Click;
//
// lblPublishDate
//
lblPublishDate.AutoSize = true;
lblPublishDate.Location = new Point(12, 159);
lblPublishDate.Name = "lblPublishDate";
lblPublishDate.Size = new Size(76, 15);
lblPublishDate.TabIndex = 21;
lblPublishDate.Text = "Publish Date:";
//
// tbDescription
//
tbDescription.Location = new Point(94, 35);
tbDescription.Multiline = true;
tbDescription.Name = "tbDescription";
tbDescription.Size = new Size(405, 112);
tbDescription.TabIndex = 20;
//
// lblDescription
//
lblDescription.AutoSize = true;
lblDescription.Location = new Point(12, 38);
lblDescription.Name = "lblDescription";
lblDescription.Size = new Size(70, 15);
lblDescription.TabIndex = 19;
lblDescription.Text = "Description:";
//
// tbTitle
//
tbTitle.Location = new Point(94, 6);
tbTitle.Name = "tbTitle";
tbTitle.Size = new Size(405, 23);
tbTitle.TabIndex = 18;
//
// lblTitle
//
lblTitle.AutoSize = true;
lblTitle.Location = new Point(12, 9);
lblTitle.Name = "lblTitle";
lblTitle.Size = new Size(32, 15);
lblTitle.TabIndex = 17;
lblTitle.Text = "Title:";
//
// CommentForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(517, 395);
Controls.Add(btnCreateComment);
Controls.Add(btnDeleteComment);
Controls.Add(btnEditComment);
Controls.Add(btnViewComment);
Controls.Add(listBox1);
Controls.Add(lblComments);
Controls.Add(lblAuthor);
Controls.Add(dtpPublishDate);
Controls.Add(btnSave);
Controls.Add(lblPublishDate);
Controls.Add(tbDescription);
Controls.Add(lblDescription);
Controls.Add(tbTitle);
Controls.Add(lblTitle);
Name = "CommentForm";
Text = "Comment";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button btnCreateComment;
private Button btnDeleteComment;
private Button btnEditComment;
private Button btnViewComment;
private ListBox listBox1;
private Label lblComments;
private Label lblAuthor;
private DateTimePicker dtpPublishDate;
private Button btnSave;
private Label lblPublishDate;
private TextBox tbDescription;
private Label lblDescription;
private TextBox tbTitle;
private Label lblTitle;
}
}

View File

@@ -0,0 +1,160 @@
using StudentHouseDashboard.Managers;
using StudentHouseDashboard.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinForms
{
public partial class CommentForm : Form
{
Comment? comment;
User currentUser;
bool announcementResponse;
int parentId;
public CommentForm(Comment? comment, bool readOnly, User currentUser)
{
InitializeComponent();
this.comment = comment;
this.currentUser = currentUser;
// restriction: no need to create events in the past
dtpPublishDate.Enabled = false;
if (comment != null)
{
tbTitle.Text = comment.Title;
lblAuthor.Text = $"Created by: {comment.Author.Name}";
tbDescription.Text = comment.Description;
dtpPublishDate.Value = comment.PublishDate;
RefreshComments();
}
else
{
btnCreateComment.Enabled = false;
btnDeleteComment.Enabled = false;
btnEditComment.Enabled = false;
btnViewComment.Enabled = false;
}
if (comment != null && currentUser != null)
{
if (currentUser.ID != comment.Author.ID)
{
// restriction: only edit personal comments
readOnly = true;
}
}
if (readOnly)
{
btnSave.Enabled = false;
tbTitle.Enabled = false;
tbDescription.Enabled = false;
}
if (currentUser != null)
{
lblAuthor.Text = $"Created by: {currentUser.Name}";
}
}
public CommentForm(Comment? comment, bool readOnly, User? currentUser, bool announcementResponse, int parentId) : this(comment, readOnly, currentUser)
{
this.announcementResponse = announcementResponse;
this.parentId = parentId;
}
private void btnSave_Click(object sender, EventArgs e)
{
CommentManager commentManager = new CommentManager();
if (string.IsNullOrEmpty(tbTitle.Text) || string.IsNullOrEmpty(tbDescription.Text))
{
MessageBox.Show("Please enter a title and comment text");
return;
}
if (this.comment == null)
{
if (announcementResponse)
{
commentManager.CreateCommentToAnnouncement(currentUser, tbDescription.Text, tbTitle.Text, dtpPublishDate.Value, parentId);
}
else
{
commentManager.CreateResponseToComment(currentUser, tbDescription.Text, tbTitle.Text, dtpPublishDate.Value, parentId);
}
}
else
{
commentManager.UpdateComment(comment.ID, tbDescription.Text);
}
}
private void btnViewComment_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex == -1)
{
MessageBox.Show("Please select an item from the list");
}
else
{
CommentForm form = new CommentForm((Comment)listBox1.SelectedItem, true, currentUser);
form.ShowDialog();
RefreshComments();
}
}
private void btnEditComment_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex == -1)
{
MessageBox.Show("Please select an item from the list");
}
else
{
CommentForm form = new CommentForm((Comment)listBox1.SelectedItem, false, currentUser);
form.ShowDialog();
RefreshComments();
}
}
private void btnDeleteComment_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex == -1)
{
MessageBox.Show("Please select an item from the list");
}
else
{
Comment currentResponse = (Comment)listBox1.SelectedItem;
if (MessageBox.Show($"Are you sure you want to delete\n{currentResponse.Title}\nCreated at {currentResponse.PublishDate.ToString("g")} by {currentResponse.Author.Name}",
"Delete announcement", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
CommentManager commentManager = new CommentManager();
commentManager.DeleteResponseOnComment(currentResponse.ID, comment.ID);
}
RefreshComments();
}
}
private void btnCreateComment_Click(object sender, EventArgs e)
{
CommentForm form = new CommentForm(null, false, currentUser, false, comment.ID);
form.ShowDialog();
RefreshComments();
}
private void RefreshComments()
{
listBox1.Items.Clear();
foreach (var item in comment.Responses)
{
listBox1.Items.Add(item);
}
}
}
}

View File

@@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -114,28 +114,49 @@ namespace WinForms
private void btnDeleteAnnouncement_Click(object sender, EventArgs e)
{
Announcement currentAnnouncement = (Announcement)lbAnnouncements.SelectedItem;
if (MessageBox.Show($"Are you sure you want to delete\n{currentAnnouncement.Title}\nCreated at {currentAnnouncement.PublishDate.ToString("g")} by {currentAnnouncement.Author.Name}",
"Delete announcement", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
if (lbAnnouncements.SelectedIndex == -1)
{
AnnouncementManager announcementManager = new AnnouncementManager();
announcementManager.DeleteAnnouncement(currentAnnouncement.ID);
MessageBox.Show("Please select an item from the list");
}
else
{
Announcement currentAnnouncement = (Announcement)lbAnnouncements.SelectedItem;
if (MessageBox.Show($"Are you sure you want to delete\n{currentAnnouncement.Title}\nCreated at {currentAnnouncement.PublishDate.ToString("g")} by {currentAnnouncement.Author.Name}",
"Delete announcement", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
AnnouncementManager announcementManager = new AnnouncementManager();
announcementManager.DeleteAnnouncement(currentAnnouncement.ID);
}
RefreshLists();
}
RefreshLists();
}
private void btnEditAnnouncement_Click(object sender, EventArgs e)
{
AnnouncementForm announcementForm = new AnnouncementForm((Announcement)lbAnnouncements.SelectedItem, false, null);
announcementForm.ShowDialog();
RefreshLists();
if (lbAnnouncements.SelectedIndex == -1)
{
MessageBox.Show("Please select an item from the list");
}
else
{
AnnouncementForm announcementForm = new AnnouncementForm((Announcement)lbAnnouncements.SelectedItem, false, user);
announcementForm.ShowDialog();
RefreshLists();
}
}
private void btnViewAnnouncement_Click(object sender, EventArgs e)
{
AnnouncementForm announcementForm = new AnnouncementForm((Announcement)lbAnnouncements.SelectedItem, true, null);
announcementForm.ShowDialog();
RefreshLists();
if (lbAnnouncements.SelectedIndex == -1)
{
MessageBox.Show("Please select an item from the list");
}
else
{
AnnouncementForm announcementForm = new AnnouncementForm((Announcement)lbAnnouncements.SelectedItem, true, user);
announcementForm.ShowDialog();
RefreshLists();
}
}
}
}