Basic announcements added
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
using System;
|
using StudentHouseDashboard.Models;
|
||||||
|
using StudentHouseDashboard.Repositories;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -8,5 +11,30 @@ namespace StudentHouseDashboard.Managers
|
|||||||
{
|
{
|
||||||
public class AnnouncementManager
|
public class AnnouncementManager
|
||||||
{
|
{
|
||||||
|
private AnnouncementRepository announcementRepository;
|
||||||
|
public AnnouncementManager()
|
||||||
|
{
|
||||||
|
announcementRepository = new AnnouncementRepository();
|
||||||
|
}
|
||||||
|
public List<Announcement> GetAllAnnouncements()
|
||||||
|
{
|
||||||
|
return announcementRepository.GetAllAnnouncements();
|
||||||
|
}
|
||||||
|
public List<Announcement> GetAnnouncementsByPage(int? p, int? c)
|
||||||
|
{
|
||||||
|
return announcementRepository.GetAnnouncementsByPage(p, c);
|
||||||
|
}
|
||||||
|
public bool CreateAnnouncement(string title, string description, User author, DateTime publishDate, bool isImportant, bool isSticky)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
return announcementRepository.UpdateAnnouncement(id, title, description, author, publishDate, isImportant, isSticky);
|
||||||
|
}
|
||||||
|
public bool DeleteAnnouncement(int id)
|
||||||
|
{
|
||||||
|
return announcementRepository.DeleteAnnouncement(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -37,5 +37,9 @@ namespace StudentHouseDashboard.Models
|
|||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{Title} ({PublishDate.ToString("g")} - {Author.Name})";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -11,27 +11,12 @@ namespace StudentHouseDashboard.Repositories
|
|||||||
{
|
{
|
||||||
public class AnnouncementRepository
|
public class AnnouncementRepository
|
||||||
{
|
{
|
||||||
private string connectionString = "Server=mssqlstud.fhict.local;Database=dbi509645;User Id=dbi509645;Password=sNPNBm*BX!6z8RM;";
|
|
||||||
public AnnouncementRepository() { }
|
public AnnouncementRepository() { }
|
||||||
private SqlConnection CreateConnection()
|
|
||||||
{
|
|
||||||
SqlConnection connection = new SqlConnection(connectionString);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.Open();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Database connection error. Are you connected to the VDI VPN?");
|
|
||||||
}
|
|
||||||
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
public List<Announcement> GetAllAnnouncements()
|
public List<Announcement> GetAllAnnouncements()
|
||||||
{
|
{
|
||||||
List<Announcement> announcements = new List<Announcement>();
|
List<Announcement> announcements = new List<Announcement>();
|
||||||
UserManager userManager = new UserManager();
|
UserManager userManager = new UserManager();
|
||||||
using (SqlConnection conn = CreateConnection())
|
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||||
{
|
{
|
||||||
string sql = "SELECT * FROM Announcements;";
|
string sql = "SELECT * FROM Announcements;";
|
||||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||||
@@ -62,7 +47,7 @@ namespace StudentHouseDashboard.Repositories
|
|||||||
{
|
{
|
||||||
p = 0;
|
p = 0;
|
||||||
}
|
}
|
||||||
using (SqlConnection conn = CreateConnection())
|
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||||
{
|
{
|
||||||
string sql = "SELECT * FROM Announcements ORDER BY ID OFFSET @start ROWS FETCH NEXT @count ROWS ONLY;";
|
string sql = "SELECT * FROM Announcements ORDER BY ID OFFSET @start ROWS FETCH NEXT @count ROWS ONLY;";
|
||||||
SqlCommand sqlCommand = new SqlCommand(sql, conn);
|
SqlCommand sqlCommand = new SqlCommand(sql, conn);
|
||||||
@@ -81,5 +66,66 @@ namespace StudentHouseDashboard.Repositories
|
|||||||
}
|
}
|
||||||
return announcements;
|
return announcements;
|
||||||
}
|
}
|
||||||
|
public bool CreateAnnouncement(string title, string description, User author, DateTime publishDate, bool isImportant, bool isSticky)
|
||||||
|
{
|
||||||
|
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "INSERT INTO Announcements (Author, Description, Title, PublishDate, IsImportant, IsSticky) VALUES (@author, @desc, @title, @date, @important, @sticky);";
|
||||||
|
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);
|
||||||
|
int writer = cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
if (writer == 1)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public bool UpdateAnnouncement(int id, string title, string description, User author, DateTime publishDate, 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 " +
|
||||||
|
"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);
|
||||||
|
int writer = cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
if (writer == 1)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public bool DeleteAnnouncement(int id)
|
||||||
|
{
|
||||||
|
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||||
|
{
|
||||||
|
string sql = "DELETE FROM Announcements WHERE Id = @id;";
|
||||||
|
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||||
|
cmd.Parameters.AddWithValue("@id", id);
|
||||||
|
int writer = cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
if (writer == 1)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StudentHouseDashboard.Repositories
|
||||||
|
{
|
||||||
|
public static class SqlConnectionHelper
|
||||||
|
{
|
||||||
|
private static string connectionString = "Server=mssqlstud.fhict.local;Database=dbi509645;User Id=dbi509645;Password=sNPNBm*BX!6z8RM;";
|
||||||
|
public static SqlConnection CreateConnection()
|
||||||
|
{
|
||||||
|
SqlConnection connection = new SqlConnection(connectionString);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
connection.Open();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Database connection error. Are you connected to the VDI VPN?");
|
||||||
|
}
|
||||||
|
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -12,28 +12,12 @@ namespace StudentHouseDashboard.Repositories
|
|||||||
{
|
{
|
||||||
public class UserRepository
|
public class UserRepository
|
||||||
{
|
{
|
||||||
private string connectionString = "Server=mssqlstud.fhict.local;Database=dbi509645;User Id=dbi509645;Password=sNPNBm*BX!6z8RM;";
|
|
||||||
|
|
||||||
public UserRepository() { }
|
public UserRepository() { }
|
||||||
private SqlConnection CreateConnection()
|
|
||||||
{
|
|
||||||
SqlConnection connection = new SqlConnection(connectionString);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.Open();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Database connection error. Are you connected to the VDI VPN?");
|
|
||||||
}
|
|
||||||
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
public List<User> GetAllUsers()
|
public List<User> GetAllUsers()
|
||||||
{
|
{
|
||||||
var users = new List<User>();
|
var users = new List<User>();
|
||||||
|
|
||||||
using (SqlConnection conn = CreateConnection())
|
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||||
{
|
{
|
||||||
string sql = "SELECT * FROM Users;";
|
string sql = "SELECT * FROM Users;";
|
||||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||||
@@ -54,7 +38,7 @@ namespace StudentHouseDashboard.Repositories
|
|||||||
}
|
}
|
||||||
public User GetUserById(int id)
|
public User GetUserById(int id)
|
||||||
{
|
{
|
||||||
using (SqlConnection conn = CreateConnection())
|
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||||
{
|
{
|
||||||
string sql = "SELECT * FROM Users WHERE ID = @id;";
|
string sql = "SELECT * FROM Users WHERE ID = @id;";
|
||||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||||
@@ -81,7 +65,7 @@ namespace StudentHouseDashboard.Repositories
|
|||||||
{
|
{
|
||||||
p = 0;
|
p = 0;
|
||||||
}
|
}
|
||||||
using (SqlConnection conn = CreateConnection())
|
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||||
{
|
{
|
||||||
string sql = "SELECT * FROM Users ORDER BY ID OFFSET @start ROWS FETCH NEXT @count ROWS ONLY;";
|
string sql = "SELECT * FROM Users ORDER BY ID OFFSET @start ROWS FETCH NEXT @count ROWS ONLY;";
|
||||||
SqlCommand sqlCommand = new SqlCommand(sql, conn);
|
SqlCommand sqlCommand = new SqlCommand(sql, conn);
|
||||||
@@ -99,7 +83,7 @@ namespace StudentHouseDashboard.Repositories
|
|||||||
}
|
}
|
||||||
public bool CreateUser(string name, string password, UserRole role)
|
public bool CreateUser(string name, string password, UserRole role)
|
||||||
{
|
{
|
||||||
using (SqlConnection conn = CreateConnection())
|
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||||
{
|
{
|
||||||
string sql = "INSERT INTO Users (Name, Password, Role) VALUES (@name, @pass, @role);";
|
string sql = "INSERT INTO Users (Name, Password, Role) VALUES (@name, @pass, @role);";
|
||||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||||
@@ -117,7 +101,7 @@ namespace StudentHouseDashboard.Repositories
|
|||||||
}
|
}
|
||||||
public bool UpdateUser(int id, string name, string password, UserRole role)
|
public bool UpdateUser(int id, string name, string password, UserRole role)
|
||||||
{
|
{
|
||||||
using (SqlConnection conn = CreateConnection())
|
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||||
{
|
{
|
||||||
string sql = "UPDATE Users " +
|
string sql = "UPDATE Users " +
|
||||||
"SET Name = @name, Password = @pass, Role = @role " +
|
"SET Name = @name, Password = @pass, Role = @role " +
|
||||||
@@ -138,7 +122,7 @@ namespace StudentHouseDashboard.Repositories
|
|||||||
}
|
}
|
||||||
public bool DisableUser(int id)
|
public bool DisableUser(int id)
|
||||||
{
|
{
|
||||||
using (SqlConnection conn = CreateConnection())
|
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||||
{
|
{
|
||||||
string sql = "UPDATE Users " +
|
string sql = "UPDATE Users " +
|
||||||
"SET Name = 'Deleted User @id', Password = '0'" +
|
"SET Name = 'Deleted User @id', Password = '0'" +
|
||||||
@@ -154,6 +138,5 @@ namespace StudentHouseDashboard.Repositories
|
|||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,21 +2,27 @@
|
|||||||
@using StudentHouseDashboard.Models;
|
@using StudentHouseDashboard.Models;
|
||||||
@model WebApp.Pages.AnnouncementModel
|
@model WebApp.Pages.AnnouncementModel
|
||||||
@{
|
@{
|
||||||
User user = (User)ViewData["user"];
|
Announcement announcement = (Announcement)ViewData["announcement"];
|
||||||
ViewData["Title"] = $"User {user.Name}";
|
ViewData["Title"] = $"{announcement.Title}";
|
||||||
}
|
}
|
||||||
<h1>@user.Name</h1>
|
<h1>@announcement.Title</h1>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<p>Name: </p>
|
<p>Title: </p>
|
||||||
<p>Password: </p>
|
<p>Author: </p>
|
||||||
<p>Role: </p>
|
<p>Description: </p>
|
||||||
|
<p>Date: </p>
|
||||||
|
<p>Important: </p>
|
||||||
|
<p>Pinned: </p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<p>@user.Name</p>
|
<p>@announcement.Title</p>
|
||||||
<p>@user.Password</p>
|
<p>@announcement.Author.Name</p>
|
||||||
<p>@user.Role.ToString()</p>
|
<p>@announcement.Description</p>
|
||||||
|
<p>@announcement.PublishDate.ToString("g")</p>
|
||||||
|
<p>@announcement.IsImportant.ToString()</p>
|
||||||
|
<p>@announcement.IsSticky.ToString()</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
using StudentHouseDashboard.Managers;
|
using StudentHouseDashboard.Managers;
|
||||||
|
using StudentHouseDashboard.Models;
|
||||||
|
|
||||||
namespace WebApp.Pages
|
namespace WebApp.Pages
|
||||||
{
|
{
|
||||||
@@ -10,8 +11,8 @@ namespace WebApp.Pages
|
|||||||
{
|
{
|
||||||
public void OnGet(int id)
|
public void OnGet(int id)
|
||||||
{
|
{
|
||||||
UserManager userManager = new UserManager();
|
AnnouncementManager announcementManager = new AnnouncementManager();
|
||||||
ViewData.Add("user", userManager.GetUserById(id));
|
ViewData.Add("announcement", announcementManager.GetAllAnnouncements().Where(x => x.ID == id).First());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,20 +1,25 @@
|
|||||||
@page
|
@page
|
||||||
@using StudentHouseDashboard.Models;
|
@using StudentHouseDashboard.Models;
|
||||||
|
@using System.Security.Claims;
|
||||||
@model WebApp.Pages.AnnouncementsModel
|
@model WebApp.Pages.AnnouncementsModel
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Announcements";
|
ViewData["Title"] = "Announcements";
|
||||||
List<User> users = (List<User>)ViewData["users"];
|
List<Announcement> announcements = (List<Announcement>)ViewData["announcements"];
|
||||||
int currentPage = @Convert.ToInt32(ViewData["page"]);
|
int currentPage = @Convert.ToInt32(ViewData["page"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@foreach (User user in users)
|
@foreach (Announcement announcement in announcements)
|
||||||
{
|
{
|
||||||
<div class="card" style="display:inline-block; width: 18rem;">
|
<div class="card" style="display:inline-block; width: 18rem;">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">@user.Role.ToString()</h5>
|
<h5 class="card-title">@announcement.Title</h5>
|
||||||
<h6 class="card-subtitle mb-2 text-muted">@user.Name</h6>
|
<h6 class="card-subtitle mb-2 text-muted">@announcement.Author.Name</h6>
|
||||||
<p class="card-text">@user.Password</p>
|
<p class="card-text">@announcement.Description</p>
|
||||||
<a href="./Announcement?id=@user.ID" class="btn btn-primary">More details</a>
|
<a href="./Announcement?id=@announcement.ID" class="btn btn-primary">More details</a>
|
||||||
|
@if (User.FindFirst(ClaimTypes.Role).Value == "ADMIN")
|
||||||
|
{
|
||||||
|
@: <a href="./Announcement?id=@announcement.ID" class="btn btn-outline-danger btn-sm">Delete</a>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@@ -37,7 +42,7 @@
|
|||||||
@: <li class="page-item"><a class="page-link" href="./Announcements?p=@(currentPage - 1)">@(currentPage - 1)</a></li>
|
@: <li class="page-item"><a class="page-link" href="./Announcements?p=@(currentPage - 1)">@(currentPage - 1)</a></li>
|
||||||
}
|
}
|
||||||
<li class="page-item"><a class="page-link">@currentPage</a></li>
|
<li class="page-item"><a class="page-link">@currentPage</a></li>
|
||||||
@if (users.Count == 0)
|
@if (announcements.Count == 0)
|
||||||
{
|
{
|
||||||
@: <li class="page-item disabled">
|
@: <li class="page-item disabled">
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,8 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
using StudentHouseDashboard.Managers;
|
using StudentHouseDashboard.Managers;
|
||||||
|
using StudentHouseDashboard.Models;
|
||||||
|
using System.Security.Claims;
|
||||||
|
|
||||||
namespace WebApp.Pages
|
namespace WebApp.Pages
|
||||||
{
|
{
|
||||||
@@ -9,17 +11,16 @@ namespace WebApp.Pages
|
|||||||
public class AnnouncementsModel : PageModel
|
public class AnnouncementsModel : PageModel
|
||||||
{
|
{
|
||||||
public AnnouncementManager AnnouncementManager { get; set; }
|
public AnnouncementManager AnnouncementManager { get; set; }
|
||||||
public UserManager UserManager { get; set; }
|
|
||||||
public void OnGet(int? p, int? c)
|
public void OnGet(int? p, int? c)
|
||||||
{
|
{
|
||||||
UserManager = new UserManager();
|
AnnouncementManager = new AnnouncementManager();
|
||||||
if (p == null || p < 1)
|
if (p == null || p < 1)
|
||||||
{
|
{
|
||||||
p = 1;
|
p = 1;
|
||||||
}
|
}
|
||||||
ViewData.Add("users", UserManager.GetUsersByPage(p - 1, c));
|
ViewData.Add("announcements", AnnouncementManager.GetAnnouncementsByPage(p - 1, c));
|
||||||
ViewData.Add("page", p);
|
ViewData.Add("page", p);
|
||||||
ViewData.Add("allCount", UserManager.GetAllUsers().Count());
|
ViewData.Add("allCount", AnnouncementManager.GetAllAnnouncements().Count());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
165
StudentHouseDashboard/WinForms/AnnouncementForm.Designer.cs
generated
Normal file
165
StudentHouseDashboard/WinForms/AnnouncementForm.Designer.cs
generated
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
namespace WinForms
|
||||||
|
{
|
||||||
|
partial class AnnouncementForm
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
lblTitle = new Label();
|
||||||
|
tbTitle = new TextBox();
|
||||||
|
lblDescription = new Label();
|
||||||
|
tbDescription = new TextBox();
|
||||||
|
lblPublishDate = new Label();
|
||||||
|
btnSave = new Button();
|
||||||
|
ckbImportant = new CheckBox();
|
||||||
|
ckbSticky = new CheckBox();
|
||||||
|
dtpPublishDate = new DateTimePicker();
|
||||||
|
lblAuthor = new Label();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// lblTitle
|
||||||
|
//
|
||||||
|
lblTitle.AutoSize = true;
|
||||||
|
lblTitle.Location = new Point(12, 9);
|
||||||
|
lblTitle.Name = "lblTitle";
|
||||||
|
lblTitle.Size = new Size(32, 15);
|
||||||
|
lblTitle.TabIndex = 0;
|
||||||
|
lblTitle.Text = "Title:";
|
||||||
|
//
|
||||||
|
// tbTitle
|
||||||
|
//
|
||||||
|
tbTitle.Location = new Point(94, 6);
|
||||||
|
tbTitle.Name = "tbTitle";
|
||||||
|
tbTitle.Size = new Size(405, 23);
|
||||||
|
tbTitle.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// lblDescription
|
||||||
|
//
|
||||||
|
lblDescription.AutoSize = true;
|
||||||
|
lblDescription.Location = new Point(12, 38);
|
||||||
|
lblDescription.Name = "lblDescription";
|
||||||
|
lblDescription.Size = new Size(70, 15);
|
||||||
|
lblDescription.TabIndex = 2;
|
||||||
|
lblDescription.Text = "Description:";
|
||||||
|
//
|
||||||
|
// tbDescription
|
||||||
|
//
|
||||||
|
tbDescription.Location = new Point(94, 35);
|
||||||
|
tbDescription.Multiline = true;
|
||||||
|
tbDescription.Name = "tbDescription";
|
||||||
|
tbDescription.Size = new Size(405, 112);
|
||||||
|
tbDescription.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// lblPublishDate
|
||||||
|
//
|
||||||
|
lblPublishDate.AutoSize = true;
|
||||||
|
lblPublishDate.Location = new Point(12, 159);
|
||||||
|
lblPublishDate.Name = "lblPublishDate";
|
||||||
|
lblPublishDate.Size = new Size(76, 15);
|
||||||
|
lblPublishDate.TabIndex = 4;
|
||||||
|
lblPublishDate.Text = "Publish Date:";
|
||||||
|
//
|
||||||
|
// btnSave
|
||||||
|
//
|
||||||
|
btnSave.Location = new Point(424, 180);
|
||||||
|
btnSave.Name = "btnSave";
|
||||||
|
btnSave.Size = new Size(75, 23);
|
||||||
|
btnSave.TabIndex = 6;
|
||||||
|
btnSave.Text = "Save changes";
|
||||||
|
btnSave.UseVisualStyleBackColor = true;
|
||||||
|
btnSave.Click += btnSave_Click;
|
||||||
|
//
|
||||||
|
// ckbImportant
|
||||||
|
//
|
||||||
|
ckbImportant.AutoSize = true;
|
||||||
|
ckbImportant.Location = new Point(300, 155);
|
||||||
|
ckbImportant.Name = "ckbImportant";
|
||||||
|
ckbImportant.Size = new Size(79, 19);
|
||||||
|
ckbImportant.TabIndex = 7;
|
||||||
|
ckbImportant.Text = "Important";
|
||||||
|
ckbImportant.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// ckbSticky
|
||||||
|
//
|
||||||
|
ckbSticky.AutoSize = true;
|
||||||
|
ckbSticky.Location = new Point(385, 155);
|
||||||
|
ckbSticky.Name = "ckbSticky";
|
||||||
|
ckbSticky.Size = new Size(78, 19);
|
||||||
|
ckbSticky.TabIndex = 8;
|
||||||
|
ckbSticky.Text = "Pin to top";
|
||||||
|
ckbSticky.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// dtpPublishDate
|
||||||
|
//
|
||||||
|
dtpPublishDate.Location = new Point(94, 153);
|
||||||
|
dtpPublishDate.Name = "dtpPublishDate";
|
||||||
|
dtpPublishDate.Size = new Size(200, 23);
|
||||||
|
dtpPublishDate.TabIndex = 9;
|
||||||
|
//
|
||||||
|
// lblAuthor
|
||||||
|
//
|
||||||
|
lblAuthor.AutoSize = true;
|
||||||
|
lblAuthor.Location = new Point(12, 184);
|
||||||
|
lblAuthor.Name = "lblAuthor";
|
||||||
|
lblAuthor.Size = new Size(70, 15);
|
||||||
|
lblAuthor.TabIndex = 10;
|
||||||
|
lblAuthor.Text = "Created by: ";
|
||||||
|
//
|
||||||
|
// AnnouncementForm
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(511, 216);
|
||||||
|
Controls.Add(lblAuthor);
|
||||||
|
Controls.Add(dtpPublishDate);
|
||||||
|
Controls.Add(ckbSticky);
|
||||||
|
Controls.Add(ckbImportant);
|
||||||
|
Controls.Add(btnSave);
|
||||||
|
Controls.Add(lblPublishDate);
|
||||||
|
Controls.Add(tbDescription);
|
||||||
|
Controls.Add(lblDescription);
|
||||||
|
Controls.Add(tbTitle);
|
||||||
|
Controls.Add(lblTitle);
|
||||||
|
Name = "AnnouncementForm";
|
||||||
|
Text = "Announcement";
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label lblTitle;
|
||||||
|
private TextBox tbTitle;
|
||||||
|
private Label lblDescription;
|
||||||
|
private TextBox tbDescription;
|
||||||
|
private Label lblPublishDate;
|
||||||
|
private Button btnSave;
|
||||||
|
private CheckBox ckbImportant;
|
||||||
|
private CheckBox ckbSticky;
|
||||||
|
private DateTimePicker dtpPublishDate;
|
||||||
|
private Label lblAuthor;
|
||||||
|
}
|
||||||
|
}
|
69
StudentHouseDashboard/WinForms/AnnouncementForm.cs
Normal file
69
StudentHouseDashboard/WinForms/AnnouncementForm.cs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
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 AnnouncementForm : Form
|
||||||
|
{
|
||||||
|
Announcement announcement;
|
||||||
|
User currentUser;
|
||||||
|
public AnnouncementForm(Announcement? announcement, bool readOnly, User? currentUser)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
this.announcement = announcement;
|
||||||
|
this.currentUser = currentUser;
|
||||||
|
if (readOnly)
|
||||||
|
{
|
||||||
|
btnSave.Enabled = false;
|
||||||
|
tbTitle.Enabled = false;
|
||||||
|
tbDescription.Enabled = false;
|
||||||
|
dtpPublishDate.Enabled = false;
|
||||||
|
ckbImportant.Enabled = false;
|
||||||
|
ckbSticky.Enabled = false;
|
||||||
|
}
|
||||||
|
if (announcement != null)
|
||||||
|
{
|
||||||
|
tbTitle.Text = announcement.Title;
|
||||||
|
lblAuthor.Text = $"Created by: {announcement.Author.Name}";
|
||||||
|
tbDescription.Text = announcement.Description;
|
||||||
|
dtpPublishDate.Value = announcement.PublishDate;
|
||||||
|
ckbImportant.Checked = announcement.IsImportant;
|
||||||
|
ckbSticky.Checked = announcement.IsSticky;
|
||||||
|
}
|
||||||
|
if (currentUser != null)
|
||||||
|
{
|
||||||
|
lblAuthor.Text = $"Created by: {currentUser.Name}";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
AnnouncementManager announcementManager = new AnnouncementManager();
|
||||||
|
if (string.IsNullOrEmpty(tbTitle.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Please enter a title");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.announcement == null)
|
||||||
|
{
|
||||||
|
announcementManager.CreateAnnouncement(tbTitle.Text, tbDescription.Text, currentUser, dtpPublishDate.Value, ckbImportant.Checked, ckbSticky.Checked);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
announcementManager.UpdateAnnouncement(announcement.ID, tbTitle.Text, tbDescription.Text, currentUser, dtpPublishDate.Value, ckbImportant.Checked, ckbSticky.Checked);
|
||||||
|
}
|
||||||
|
this.DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
StudentHouseDashboard/WinForms/AnnouncementForm.resx
Normal file
60
StudentHouseDashboard/WinForms/AnnouncementForm.resx
Normal 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>
|
172
StudentHouseDashboard/WinForms/Dashboard.Designer.cs
generated
172
StudentHouseDashboard/WinForms/Dashboard.Designer.cs
generated
@@ -34,80 +34,208 @@
|
|||||||
btnDeleteUser = new Button();
|
btnDeleteUser = new Button();
|
||||||
btnUpdateUser = new Button();
|
btnUpdateUser = new Button();
|
||||||
btnViewUser = new Button();
|
btnViewUser = new Button();
|
||||||
|
tabControl1 = new TabControl();
|
||||||
|
tpUsers = new TabPage();
|
||||||
|
panelUserFunctions = new Panel();
|
||||||
|
tpAnnouncements = new TabPage();
|
||||||
|
lbAnnouncements = new ListBox();
|
||||||
|
panel1 = new Panel();
|
||||||
|
btnNewAnnouncement = new Button();
|
||||||
|
btnDeleteAnnouncement = new Button();
|
||||||
|
btnViewAnnouncement = new Button();
|
||||||
|
btnEditAnnouncement = new Button();
|
||||||
|
tabControl1.SuspendLayout();
|
||||||
|
tpUsers.SuspendLayout();
|
||||||
|
panelUserFunctions.SuspendLayout();
|
||||||
|
tpAnnouncements.SuspendLayout();
|
||||||
|
panel1.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// lblUserStatus
|
// lblUserStatus
|
||||||
//
|
//
|
||||||
|
lblUserStatus.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
lblUserStatus.AutoSize = true;
|
lblUserStatus.AutoSize = true;
|
||||||
lblUserStatus.Location = new Point(13, 18);
|
lblUserStatus.Location = new Point(396, 4);
|
||||||
lblUserStatus.Name = "lblUserStatus";
|
lblUserStatus.Name = "lblUserStatus";
|
||||||
lblUserStatus.Size = new Size(80, 15);
|
lblUserStatus.Size = new Size(80, 15);
|
||||||
lblUserStatus.TabIndex = 0;
|
lblUserStatus.TabIndex = 0;
|
||||||
lblUserStatus.Text = "Logged in as: ";
|
lblUserStatus.Text = "Logged in as: ";
|
||||||
|
lblUserStatus.TextAlign = ContentAlignment.TopRight;
|
||||||
//
|
//
|
||||||
// lbUsers
|
// lbUsers
|
||||||
//
|
//
|
||||||
|
lbUsers.Dock = DockStyle.Fill;
|
||||||
lbUsers.FormattingEnabled = true;
|
lbUsers.FormattingEnabled = true;
|
||||||
lbUsers.ItemHeight = 15;
|
lbUsers.ItemHeight = 15;
|
||||||
lbUsers.Location = new Point(13, 86);
|
lbUsers.Location = new Point(3, 3);
|
||||||
lbUsers.Name = "lbUsers";
|
lbUsers.Name = "lbUsers";
|
||||||
lbUsers.Size = new Size(318, 154);
|
lbUsers.Size = new Size(717, 334);
|
||||||
lbUsers.TabIndex = 1;
|
lbUsers.TabIndex = 1;
|
||||||
//
|
//
|
||||||
// btnCreateUser
|
// btnCreateUser
|
||||||
//
|
//
|
||||||
btnCreateUser.Location = new Point(13, 257);
|
btnCreateUser.Location = new Point(3, 3);
|
||||||
btnCreateUser.Name = "btnCreateUser";
|
btnCreateUser.Name = "btnCreateUser";
|
||||||
btnCreateUser.Size = new Size(75, 23);
|
btnCreateUser.Size = new Size(75, 23);
|
||||||
btnCreateUser.TabIndex = 2;
|
btnCreateUser.TabIndex = 2;
|
||||||
btnCreateUser.Text = "New User";
|
btnCreateUser.Text = "New";
|
||||||
btnCreateUser.UseVisualStyleBackColor = true;
|
btnCreateUser.UseVisualStyleBackColor = true;
|
||||||
btnCreateUser.Click += btnCreateUser_Click;
|
btnCreateUser.Click += btnCreateUser_Click;
|
||||||
//
|
//
|
||||||
// btnDeleteUser
|
// btnDeleteUser
|
||||||
//
|
//
|
||||||
btnDeleteUser.Location = new Point(94, 257);
|
btnDeleteUser.Location = new Point(84, 3);
|
||||||
btnDeleteUser.Name = "btnDeleteUser";
|
btnDeleteUser.Name = "btnDeleteUser";
|
||||||
btnDeleteUser.Size = new Size(75, 23);
|
btnDeleteUser.Size = new Size(75, 23);
|
||||||
btnDeleteUser.TabIndex = 3;
|
btnDeleteUser.TabIndex = 3;
|
||||||
btnDeleteUser.Text = "Delete User";
|
btnDeleteUser.Text = "Delete";
|
||||||
btnDeleteUser.UseVisualStyleBackColor = true;
|
btnDeleteUser.UseVisualStyleBackColor = true;
|
||||||
btnDeleteUser.Click += btnDeleteUser_Click;
|
btnDeleteUser.Click += btnDeleteUser_Click;
|
||||||
//
|
//
|
||||||
// btnUpdateUser
|
// btnUpdateUser
|
||||||
//
|
//
|
||||||
btnUpdateUser.Location = new Point(175, 257);
|
btnUpdateUser.Location = new Point(165, 3);
|
||||||
btnUpdateUser.Name = "btnUpdateUser";
|
btnUpdateUser.Name = "btnUpdateUser";
|
||||||
btnUpdateUser.Size = new Size(75, 23);
|
btnUpdateUser.Size = new Size(75, 23);
|
||||||
btnUpdateUser.TabIndex = 4;
|
btnUpdateUser.TabIndex = 4;
|
||||||
btnUpdateUser.Text = "Edit User";
|
btnUpdateUser.Text = "Edit";
|
||||||
btnUpdateUser.UseVisualStyleBackColor = true;
|
btnUpdateUser.UseVisualStyleBackColor = true;
|
||||||
btnUpdateUser.Click += btnUpdateUser_Click;
|
btnUpdateUser.Click += btnUpdateUser_Click;
|
||||||
//
|
//
|
||||||
// btnViewUser
|
// btnViewUser
|
||||||
//
|
//
|
||||||
btnViewUser.Location = new Point(256, 257);
|
btnViewUser.Location = new Point(246, 3);
|
||||||
btnViewUser.Name = "btnViewUser";
|
btnViewUser.Name = "btnViewUser";
|
||||||
btnViewUser.Size = new Size(75, 23);
|
btnViewUser.Size = new Size(75, 23);
|
||||||
btnViewUser.TabIndex = 5;
|
btnViewUser.TabIndex = 5;
|
||||||
btnViewUser.Text = "View User";
|
btnViewUser.Text = "View";
|
||||||
btnViewUser.UseVisualStyleBackColor = true;
|
btnViewUser.UseVisualStyleBackColor = true;
|
||||||
btnViewUser.Click += btnViewUser_Click;
|
btnViewUser.Click += btnViewUser_Click;
|
||||||
//
|
//
|
||||||
|
// tabControl1
|
||||||
|
//
|
||||||
|
tabControl1.Controls.Add(tpUsers);
|
||||||
|
tabControl1.Controls.Add(tpAnnouncements);
|
||||||
|
tabControl1.Dock = DockStyle.Fill;
|
||||||
|
tabControl1.Location = new Point(0, 0);
|
||||||
|
tabControl1.Name = "tabControl1";
|
||||||
|
tabControl1.SelectedIndex = 0;
|
||||||
|
tabControl1.Size = new Size(731, 368);
|
||||||
|
tabControl1.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// tpUsers
|
||||||
|
//
|
||||||
|
tpUsers.Controls.Add(panelUserFunctions);
|
||||||
|
tpUsers.Controls.Add(lbUsers);
|
||||||
|
tpUsers.Location = new Point(4, 24);
|
||||||
|
tpUsers.Name = "tpUsers";
|
||||||
|
tpUsers.Padding = new Padding(3);
|
||||||
|
tpUsers.Size = new Size(723, 340);
|
||||||
|
tpUsers.TabIndex = 0;
|
||||||
|
tpUsers.Text = "Users";
|
||||||
|
tpUsers.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// panelUserFunctions
|
||||||
|
//
|
||||||
|
panelUserFunctions.Controls.Add(btnCreateUser);
|
||||||
|
panelUserFunctions.Controls.Add(btnDeleteUser);
|
||||||
|
panelUserFunctions.Controls.Add(btnViewUser);
|
||||||
|
panelUserFunctions.Controls.Add(btnUpdateUser);
|
||||||
|
panelUserFunctions.Dock = DockStyle.Bottom;
|
||||||
|
panelUserFunctions.Location = new Point(3, 298);
|
||||||
|
panelUserFunctions.Name = "panelUserFunctions";
|
||||||
|
panelUserFunctions.Size = new Size(717, 39);
|
||||||
|
panelUserFunctions.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// tpAnnouncements
|
||||||
|
//
|
||||||
|
tpAnnouncements.Controls.Add(panel1);
|
||||||
|
tpAnnouncements.Controls.Add(lbAnnouncements);
|
||||||
|
tpAnnouncements.Location = new Point(4, 24);
|
||||||
|
tpAnnouncements.Name = "tpAnnouncements";
|
||||||
|
tpAnnouncements.Padding = new Padding(3);
|
||||||
|
tpAnnouncements.Size = new Size(723, 340);
|
||||||
|
tpAnnouncements.TabIndex = 1;
|
||||||
|
tpAnnouncements.Text = "Announcements";
|
||||||
|
tpAnnouncements.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// lbAnnouncements
|
||||||
|
//
|
||||||
|
lbAnnouncements.Dock = DockStyle.Fill;
|
||||||
|
lbAnnouncements.FormattingEnabled = true;
|
||||||
|
lbAnnouncements.ItemHeight = 15;
|
||||||
|
lbAnnouncements.Location = new Point(3, 3);
|
||||||
|
lbAnnouncements.Name = "lbAnnouncements";
|
||||||
|
lbAnnouncements.Size = new Size(717, 334);
|
||||||
|
lbAnnouncements.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// panel1
|
||||||
|
//
|
||||||
|
panel1.Controls.Add(btnNewAnnouncement);
|
||||||
|
panel1.Controls.Add(btnDeleteAnnouncement);
|
||||||
|
panel1.Controls.Add(btnViewAnnouncement);
|
||||||
|
panel1.Controls.Add(btnEditAnnouncement);
|
||||||
|
panel1.Dock = DockStyle.Bottom;
|
||||||
|
panel1.Location = new Point(3, 298);
|
||||||
|
panel1.Name = "panel1";
|
||||||
|
panel1.Size = new Size(717, 39);
|
||||||
|
panel1.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// btnNewAnnouncement
|
||||||
|
//
|
||||||
|
btnNewAnnouncement.Location = new Point(3, 3);
|
||||||
|
btnNewAnnouncement.Name = "btnNewAnnouncement";
|
||||||
|
btnNewAnnouncement.Size = new Size(75, 23);
|
||||||
|
btnNewAnnouncement.TabIndex = 2;
|
||||||
|
btnNewAnnouncement.Text = "New";
|
||||||
|
btnNewAnnouncement.UseVisualStyleBackColor = true;
|
||||||
|
btnNewAnnouncement.Click += btnNewAnnouncement_Click;
|
||||||
|
//
|
||||||
|
// btnDeleteAnnouncement
|
||||||
|
//
|
||||||
|
btnDeleteAnnouncement.Location = new Point(84, 3);
|
||||||
|
btnDeleteAnnouncement.Name = "btnDeleteAnnouncement";
|
||||||
|
btnDeleteAnnouncement.Size = new Size(75, 23);
|
||||||
|
btnDeleteAnnouncement.TabIndex = 3;
|
||||||
|
btnDeleteAnnouncement.Text = "Delete";
|
||||||
|
btnDeleteAnnouncement.UseVisualStyleBackColor = true;
|
||||||
|
btnDeleteAnnouncement.Click += btnDeleteAnnouncement_Click;
|
||||||
|
//
|
||||||
|
// btnViewAnnouncement
|
||||||
|
//
|
||||||
|
btnViewAnnouncement.Location = new Point(246, 3);
|
||||||
|
btnViewAnnouncement.Name = "btnViewAnnouncement";
|
||||||
|
btnViewAnnouncement.Size = new Size(75, 23);
|
||||||
|
btnViewAnnouncement.TabIndex = 5;
|
||||||
|
btnViewAnnouncement.Text = "View";
|
||||||
|
btnViewAnnouncement.UseVisualStyleBackColor = true;
|
||||||
|
btnViewAnnouncement.Click += btnViewAnnouncement_Click;
|
||||||
|
//
|
||||||
|
// btnEditAnnouncement
|
||||||
|
//
|
||||||
|
btnEditAnnouncement.Location = new Point(165, 3);
|
||||||
|
btnEditAnnouncement.Name = "btnEditAnnouncement";
|
||||||
|
btnEditAnnouncement.Size = new Size(75, 23);
|
||||||
|
btnEditAnnouncement.TabIndex = 4;
|
||||||
|
btnEditAnnouncement.Text = "Edit";
|
||||||
|
btnEditAnnouncement.UseVisualStyleBackColor = true;
|
||||||
|
btnEditAnnouncement.Click += btnEditAnnouncement_Click;
|
||||||
|
//
|
||||||
// Dashboard
|
// Dashboard
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(359, 302);
|
ClientSize = new Size(731, 368);
|
||||||
Controls.Add(btnViewUser);
|
|
||||||
Controls.Add(btnUpdateUser);
|
|
||||||
Controls.Add(btnDeleteUser);
|
|
||||||
Controls.Add(btnCreateUser);
|
|
||||||
Controls.Add(lbUsers);
|
|
||||||
Controls.Add(lblUserStatus);
|
Controls.Add(lblUserStatus);
|
||||||
|
Controls.Add(tabControl1);
|
||||||
Name = "Dashboard";
|
Name = "Dashboard";
|
||||||
Text = "Dashboard";
|
Text = "Dashboard";
|
||||||
FormClosed += Dashboard_FormClosed;
|
FormClosed += Dashboard_FormClosed;
|
||||||
|
tabControl1.ResumeLayout(false);
|
||||||
|
tpUsers.ResumeLayout(false);
|
||||||
|
panelUserFunctions.ResumeLayout(false);
|
||||||
|
tpAnnouncements.ResumeLayout(false);
|
||||||
|
panel1.ResumeLayout(false);
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
}
|
}
|
||||||
@@ -120,5 +248,15 @@
|
|||||||
private Button btnDeleteUser;
|
private Button btnDeleteUser;
|
||||||
private Button btnUpdateUser;
|
private Button btnUpdateUser;
|
||||||
private Button btnViewUser;
|
private Button btnViewUser;
|
||||||
|
private TabControl tabControl1;
|
||||||
|
private TabPage tpUsers;
|
||||||
|
private TabPage tpAnnouncements;
|
||||||
|
private Panel panelUserFunctions;
|
||||||
|
private Panel panel1;
|
||||||
|
private Button btnNewAnnouncement;
|
||||||
|
private Button btnDeleteAnnouncement;
|
||||||
|
private Button btnViewAnnouncement;
|
||||||
|
private Button btnEditAnnouncement;
|
||||||
|
private ListBox lbAnnouncements;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -15,9 +15,11 @@ namespace WinForms
|
|||||||
public partial class Dashboard : Form
|
public partial class Dashboard : Form
|
||||||
{
|
{
|
||||||
Login loginForm;
|
Login loginForm;
|
||||||
|
User user;
|
||||||
public Dashboard(Login loginForm, User user)
|
public Dashboard(Login loginForm, User user)
|
||||||
{
|
{
|
||||||
this.loginForm = loginForm;
|
this.loginForm = loginForm;
|
||||||
|
this.user = user;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
lblUserStatus.Text = $"Logged in as: {user.Role} {user.Name}";
|
lblUserStatus.Text = $"Logged in as: {user.Role} {user.Name}";
|
||||||
if (user.Role == UserRole.MANAGER)
|
if (user.Role == UserRole.MANAGER)
|
||||||
@@ -25,18 +27,27 @@ namespace WinForms
|
|||||||
btnCreateUser.Enabled = false;
|
btnCreateUser.Enabled = false;
|
||||||
btnDeleteUser.Enabled = false;
|
btnDeleteUser.Enabled = false;
|
||||||
btnUpdateUser.Enabled = true;
|
btnUpdateUser.Enabled = true;
|
||||||
|
btnNewAnnouncement.Enabled = false;
|
||||||
|
btnDeleteAnnouncement.Enabled = false;
|
||||||
|
btnEditAnnouncement.Enabled = true;
|
||||||
}
|
}
|
||||||
else if (user.Role == UserRole.ADMIN)
|
else if (user.Role == UserRole.ADMIN)
|
||||||
{
|
{
|
||||||
btnCreateUser.Enabled = true;
|
btnCreateUser.Enabled = true;
|
||||||
btnDeleteUser.Enabled = true;
|
btnDeleteUser.Enabled = true;
|
||||||
btnUpdateUser.Enabled = true;
|
btnUpdateUser.Enabled = true;
|
||||||
|
btnNewAnnouncement.Enabled = true;
|
||||||
|
btnDeleteAnnouncement.Enabled = true;
|
||||||
|
btnEditAnnouncement.Enabled = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
btnCreateUser.Enabled = false;
|
btnCreateUser.Enabled = false;
|
||||||
btnDeleteUser.Enabled = false;
|
btnDeleteUser.Enabled = false;
|
||||||
btnUpdateUser.Enabled = false;
|
btnUpdateUser.Enabled = false;
|
||||||
|
btnNewAnnouncement.Enabled = false;
|
||||||
|
btnDeleteAnnouncement.Enabled = false;
|
||||||
|
btnEditAnnouncement.Enabled = false;
|
||||||
}
|
}
|
||||||
RefreshLists();
|
RefreshLists();
|
||||||
}
|
}
|
||||||
@@ -81,11 +92,50 @@ namespace WinForms
|
|||||||
{
|
{
|
||||||
lbUsers.Items.Add(_user);
|
lbUsers.Items.Add(_user);
|
||||||
}
|
}
|
||||||
|
AnnouncementManager announcementManager = new AnnouncementManager();
|
||||||
|
lbAnnouncements.Items.Clear();
|
||||||
|
foreach (Announcement announcement in announcementManager.GetAllAnnouncements())
|
||||||
|
{
|
||||||
|
lbAnnouncements.Items.Add(announcement);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Dashboard_FormClosed(object sender, FormClosedEventArgs e)
|
private void Dashboard_FormClosed(object sender, FormClosedEventArgs e)
|
||||||
{
|
{
|
||||||
loginForm.Show();
|
loginForm.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void btnNewAnnouncement_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
AnnouncementForm announcementForm = new AnnouncementForm(null, false, user);
|
||||||
|
announcementForm.ShowDialog();
|
||||||
|
RefreshLists();
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
AnnouncementManager announcementManager = new AnnouncementManager();
|
||||||
|
announcementManager.DeleteAnnouncement(currentAnnouncement.ID);
|
||||||
|
}
|
||||||
|
RefreshLists();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnEditAnnouncement_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
AnnouncementForm announcementForm = new AnnouncementForm((Announcement)lbAnnouncements.SelectedItem, false, null);
|
||||||
|
announcementForm.ShowDialog();
|
||||||
|
RefreshLists();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnViewAnnouncement_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
AnnouncementForm announcementForm = new AnnouncementForm((Announcement)lbAnnouncements.SelectedItem, true, null);
|
||||||
|
announcementForm.ShowDialog();
|
||||||
|
RefreshLists();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,4 +12,10 @@
|
|||||||
<ProjectReference Include="..\HouseData\StudentHouseDashboard.csproj" />
|
<ProjectReference Include="..\HouseData\StudentHouseDashboard.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="AnnouncementForm.cs">
|
||||||
|
<SubType>Form</SubType>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
BIN
docs/dbdiagram.png
Normal file
BIN
docs/dbdiagram.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
Reference in New Issue
Block a user