Events on desktop
This commit is contained in:
@@ -144,7 +144,7 @@ namespace Data
|
||||
var writer = cmd.ExecuteNonQuery();
|
||||
if (writer == -1)
|
||||
{
|
||||
throw new DatabaseOperationException("Database error: Complaint not created");
|
||||
throw new DatabaseOperationException("Database error: Complaint not updated");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
147
StudentHouseDashboard/Data/EventRepository.cs
Normal file
147
StudentHouseDashboard/Data/EventRepository.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
using Logic;
|
||||
using Logic.Exceptions;
|
||||
using Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
public class EventRepository : IEventRepository
|
||||
{
|
||||
public Event CreateEvent(string title, string description, User author, DateTime publishDate, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||
{
|
||||
string sql = "INSERT INTO Events (Author, Description, Title, PublishDate, StartDate, EndDate) VALUES (@author, @desc, @title, @date, @start, @end) " +
|
||||
"SELECT SCOPE_IDENTITY();";
|
||||
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("@start", startDate);
|
||||
cmd.Parameters.AddWithValue("@end", endDate);
|
||||
int newId = Convert.ToInt32(cmd.ExecuteScalar());
|
||||
if (newId == 0)
|
||||
{
|
||||
throw new DatabaseOperationException("Database error: Event not created");
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetEventById(newId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteEvent(int id)
|
||||
{
|
||||
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||
{
|
||||
string sql = "DELETE FROM Events WHERE Id = @id;";
|
||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
int writer = cmd.ExecuteNonQuery();
|
||||
if (writer != 1)
|
||||
{
|
||||
throw new DatabaseOperationException("Database error: Event not deleted");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Event> GetAllCurrentEvents()
|
||||
{
|
||||
List<Event> events = new List<Event>();
|
||||
UserRepository userRepository = new UserRepository();
|
||||
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||
{
|
||||
string sql = "SELECT * FROM Events WHERE StartDate >= CURRENT_TIMESTAMP;";
|
||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||
var reader = cmd.ExecuteReader();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
Event @event = new Event(Convert.ToInt32(reader["ID"]),
|
||||
userRepository.GetUserById(Convert.ToInt32(reader["Author"])),
|
||||
reader["Description"].ToString(), reader["Title"].ToString(),
|
||||
(DateTime)reader["PublishDate"], (DateTime)reader["StartDate"],
|
||||
(DateTime)reader["EndDate"]);
|
||||
// ID, Name, Password, Role
|
||||
events.Add(@event);
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
public List<Event> GetAllEvents()
|
||||
{
|
||||
List<Event> events = new List<Event>();
|
||||
UserRepository userRepository = new UserRepository();
|
||||
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||
{
|
||||
string sql = "SELECT * FROM Events;";
|
||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||
var reader = cmd.ExecuteReader();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
Event @event = new Event(Convert.ToInt32(reader["ID"]),
|
||||
userRepository.GetUserById(Convert.ToInt32(reader["Author"])),
|
||||
reader["Description"].ToString(), reader["Title"].ToString(),
|
||||
(DateTime)reader["PublishDate"], (DateTime)reader["StartDate"],
|
||||
(DateTime)reader["EndDate"]);
|
||||
// ID, Name, Password, Role
|
||||
events.Add(@event);
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
public Event GetEventById(int id)
|
||||
{
|
||||
UserRepository userRepository = new UserRepository();
|
||||
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||
{
|
||||
string sql = "SELECT * FROM Events WHERE ID = @id;";
|
||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||
cmd.Parameters.AddWithValue("id", id);
|
||||
var reader = cmd.ExecuteReader();
|
||||
reader.Read();
|
||||
Event @event = new Event(Convert.ToInt32(reader["ID"]),
|
||||
userRepository.GetUserById(Convert.ToInt32(reader["Author"])),
|
||||
reader["Description"].ToString(), reader["Title"].ToString(),
|
||||
(DateTime)reader["PublishDate"], (DateTime)reader["StartDate"],
|
||||
(DateTime)reader["EndDate"]);
|
||||
conn.Close();
|
||||
return @event;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateEvent(int id, string title, string description, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
using (SqlConnection conn = SqlConnectionHelper.CreateConnection())
|
||||
{
|
||||
string sql = "UPDATE Events " +
|
||||
"SET Description = @desc, Title = @title, StartDate = @start, EndDate = @end " +
|
||||
"WHERE ID = @id " +
|
||||
"SELECT SCOPE_IDENTITY();";
|
||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
cmd.Parameters.AddWithValue("@desc", description);
|
||||
cmd.Parameters.AddWithValue("@title", title);
|
||||
cmd.Parameters.AddWithValue("@status", startDate);
|
||||
cmd.Parameters.AddWithValue("@severity", endDate);
|
||||
var writer = cmd.ExecuteNonQuery();
|
||||
if (writer == -1)
|
||||
{
|
||||
throw new DatabaseOperationException("Database error: Event not updated");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
42
StudentHouseDashboard/Logic/EventManager.cs
Normal file
42
StudentHouseDashboard/Logic/EventManager.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Logic
|
||||
{
|
||||
public class EventManager
|
||||
{
|
||||
private IEventRepository eventRepository;
|
||||
public EventManager(IEventRepository eventRepository)
|
||||
{
|
||||
this.eventRepository = eventRepository;
|
||||
}
|
||||
public List<Event> GetAllEvents()
|
||||
{
|
||||
return eventRepository.GetAllEvents();
|
||||
}
|
||||
public List<Event> GetAllCurrentEvents()
|
||||
{
|
||||
return eventRepository.GetAllCurrentEvents();
|
||||
}
|
||||
public Event GetEventById(int id)
|
||||
{
|
||||
return eventRepository.GetEventById(id);
|
||||
}
|
||||
public Event CreateEvent(string title, string description, User author, DateTime publishDate, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
return eventRepository.CreateEvent(title, description, author, publishDate, startDate, endDate);
|
||||
}
|
||||
public void UpdateEvent(int id, string title, string description, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
eventRepository.UpdateEvent(id, title, description, startDate, endDate);
|
||||
}
|
||||
public void DeleteEvent(int id)
|
||||
{
|
||||
eventRepository.DeleteEvent(id);
|
||||
}
|
||||
}
|
||||
}
|
20
StudentHouseDashboard/Logic/IEventRepository.cs
Normal file
20
StudentHouseDashboard/Logic/IEventRepository.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Logic
|
||||
{
|
||||
public interface IEventRepository
|
||||
{
|
||||
public List<Event> GetAllEvents();
|
||||
public List<Event> GetAllCurrentEvents();
|
||||
public Event GetEventById(int id);
|
||||
public Event CreateEvent(string title, string description, User author, DateTime publishDate, DateTime startDate, DateTime endDate);
|
||||
public void UpdateEvent(int id, string title, string description, DateTime startDate, DateTime endDate);
|
||||
public void DeleteEvent(int id);
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,10 @@ namespace Models
|
||||
{
|
||||
public class Event : GenericMessage
|
||||
{
|
||||
public Event()
|
||||
{
|
||||
|
||||
}
|
||||
public Event(int id, User author, string description, string title, DateTime publishDate, DateTime startDate, DateTime endDate) : base(id, author, description, title, publishDate)
|
||||
{
|
||||
StartDate = startDate;
|
||||
@@ -22,5 +26,9 @@ namespace Models
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return $"({StartDate.ToString("g")} - {EndDate.ToString("g")}; {Author.Name}) {Title}";
|
||||
}
|
||||
}
|
||||
}
|
@@ -17,6 +17,7 @@
|
||||
{
|
||||
<a class="btn btn-primary" asp-page="Announcements">Announcements</a>
|
||||
<a class="btn btn-primary" asp-page="Complaints">Complaints</a>
|
||||
<a class="btn btn-primary" asp-page="Events">Events</a>
|
||||
}
|
||||
</div>
|
||||
|
||||
|
@@ -22,6 +22,7 @@ namespace WebApp
|
||||
builder.Services.AddScoped<ICommentRepository, CommentRepository>();
|
||||
builder.Services.AddScoped<IAnnouncementRepository, AnnouncementRepository>();
|
||||
builder.Services.AddScoped<IComplaintRepository, ComplaintRepository>();
|
||||
builder.Services.AddScoped<IEventRepository, EventRepository>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
@@ -1,4 +1,64 @@
|
||||
<root>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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">
|
||||
|
80
StudentHouseDashboard/WinForms/Dashboard.Designer.cs
generated
80
StudentHouseDashboard/WinForms/Dashboard.Designer.cs
generated
@@ -52,6 +52,12 @@
|
||||
lbComplaints = new ListBox();
|
||||
tpEvents = new TabPage();
|
||||
btnLogout = new Button();
|
||||
panel1 = new Panel();
|
||||
btnNewEvent = new Button();
|
||||
btnDeleteEvent = new Button();
|
||||
btnViewEvent = new Button();
|
||||
btnEditEvent = new Button();
|
||||
lbEvents = new ListBox();
|
||||
tabControl1.SuspendLayout();
|
||||
tpUsers.SuspendLayout();
|
||||
panelUserFunctions.SuspendLayout();
|
||||
@@ -59,6 +65,8 @@
|
||||
panelAnnouncementsFunctions.SuspendLayout();
|
||||
tpComplaints.SuspendLayout();
|
||||
panelComplaintFunctions.SuspendLayout();
|
||||
tpEvents.SuspendLayout();
|
||||
panel1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// lblUserStatus
|
||||
@@ -297,6 +305,8 @@
|
||||
//
|
||||
// tpEvents
|
||||
//
|
||||
tpEvents.Controls.Add(panel1);
|
||||
tpEvents.Controls.Add(lbEvents);
|
||||
tpEvents.Location = new Point(4, 24);
|
||||
tpEvents.Name = "tpEvents";
|
||||
tpEvents.Size = new Size(723, 340);
|
||||
@@ -314,6 +324,68 @@
|
||||
btnLogout.UseVisualStyleBackColor = true;
|
||||
btnLogout.Click += btnLogout_Click;
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
panel1.Controls.Add(btnNewEvent);
|
||||
panel1.Controls.Add(btnDeleteEvent);
|
||||
panel1.Controls.Add(btnViewEvent);
|
||||
panel1.Controls.Add(btnEditEvent);
|
||||
panel1.Dock = DockStyle.Bottom;
|
||||
panel1.Location = new Point(0, 301);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(723, 39);
|
||||
panel1.TabIndex = 8;
|
||||
//
|
||||
// btnNewEvent
|
||||
//
|
||||
btnNewEvent.Location = new Point(3, 3);
|
||||
btnNewEvent.Name = "btnNewEvent";
|
||||
btnNewEvent.Size = new Size(75, 23);
|
||||
btnNewEvent.TabIndex = 2;
|
||||
btnNewEvent.Text = "New";
|
||||
btnNewEvent.UseVisualStyleBackColor = true;
|
||||
btnNewEvent.Click += btnNewEvent_Click;
|
||||
//
|
||||
// btnDeleteEvent
|
||||
//
|
||||
btnDeleteEvent.Location = new Point(84, 3);
|
||||
btnDeleteEvent.Name = "btnDeleteEvent";
|
||||
btnDeleteEvent.Size = new Size(75, 23);
|
||||
btnDeleteEvent.TabIndex = 3;
|
||||
btnDeleteEvent.Text = "Delete";
|
||||
btnDeleteEvent.UseVisualStyleBackColor = true;
|
||||
btnDeleteEvent.Click += btnDeleteEvent_Click;
|
||||
//
|
||||
// btnViewEvent
|
||||
//
|
||||
btnViewEvent.Location = new Point(246, 3);
|
||||
btnViewEvent.Name = "btnViewEvent";
|
||||
btnViewEvent.Size = new Size(75, 23);
|
||||
btnViewEvent.TabIndex = 5;
|
||||
btnViewEvent.Text = "View";
|
||||
btnViewEvent.UseVisualStyleBackColor = true;
|
||||
btnViewEvent.Click += btnViewEvent_Click;
|
||||
//
|
||||
// btnEditEvent
|
||||
//
|
||||
btnEditEvent.Location = new Point(165, 3);
|
||||
btnEditEvent.Name = "btnEditEvent";
|
||||
btnEditEvent.Size = new Size(75, 23);
|
||||
btnEditEvent.TabIndex = 4;
|
||||
btnEditEvent.Text = "Edit";
|
||||
btnEditEvent.UseVisualStyleBackColor = true;
|
||||
btnEditEvent.Click += btnEditEvent_Click;
|
||||
//
|
||||
// lbEvents
|
||||
//
|
||||
lbEvents.Dock = DockStyle.Top;
|
||||
lbEvents.FormattingEnabled = true;
|
||||
lbEvents.ItemHeight = 15;
|
||||
lbEvents.Location = new Point(0, 0);
|
||||
lbEvents.Name = "lbEvents";
|
||||
lbEvents.Size = new Size(723, 304);
|
||||
lbEvents.TabIndex = 9;
|
||||
//
|
||||
// Dashboard
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
@@ -332,6 +404,8 @@
|
||||
panelAnnouncementsFunctions.ResumeLayout(false);
|
||||
tpComplaints.ResumeLayout(false);
|
||||
panelComplaintFunctions.ResumeLayout(false);
|
||||
tpEvents.ResumeLayout(false);
|
||||
panel1.ResumeLayout(false);
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
@@ -362,5 +436,11 @@
|
||||
private Button btnViewComplaint;
|
||||
private Button btnEditComplaint;
|
||||
private Button btnLogout;
|
||||
private Panel panel1;
|
||||
private Button btnNewEvent;
|
||||
private Button btnDeleteEvent;
|
||||
private Button btnViewEvent;
|
||||
private Button btnEditEvent;
|
||||
private ListBox lbEvents;
|
||||
}
|
||||
}
|
@@ -129,6 +129,12 @@ namespace WinForms
|
||||
{
|
||||
lbComplaints.Items.Add(complaint);
|
||||
}
|
||||
EventManager eventManager = new EventManager(new EventRepository());
|
||||
lbEvents.Items.Clear();
|
||||
foreach (Event @event in eventManager.GetAllEvents())
|
||||
{
|
||||
lbEvents.Items.Add(@event);
|
||||
}
|
||||
}
|
||||
|
||||
private void Dashboard_FormClosed(object sender, FormClosedEventArgs e)
|
||||
@@ -244,5 +250,59 @@ namespace WinForms
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnNewEvent_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventForm eventForm = new EventForm(null, false, user);
|
||||
eventForm.ShowDialog();
|
||||
RefreshLists();
|
||||
}
|
||||
|
||||
private void btnDeleteEvent_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (lbEvents.SelectedIndex == -1)
|
||||
{
|
||||
MessageBox.Show("Please select an item from the list");
|
||||
}
|
||||
else
|
||||
{
|
||||
Event currentEvent = (Event)lbEvents.SelectedItem;
|
||||
if (MessageBox.Show($"Are you sure you want to delete\n{currentEvent.Title}\nCreated at {currentEvent.PublishDate.ToString("g")} by {currentEvent.Author.Name}",
|
||||
"Delete announcement", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
EventManager eventManager = new EventManager(new EventRepository());
|
||||
eventManager.DeleteEvent(currentEvent.ID);
|
||||
}
|
||||
RefreshLists();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnEditEvent_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (lbEvents.SelectedIndex == -1)
|
||||
{
|
||||
MessageBox.Show("Please select an item from the list");
|
||||
}
|
||||
else
|
||||
{
|
||||
EventForm eventForm = new EventForm((Event)lbEvents.SelectedItem, false, user);
|
||||
eventForm.ShowDialog();
|
||||
RefreshLists();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnViewEvent_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (lbEvents.SelectedIndex == -1)
|
||||
{
|
||||
MessageBox.Show("Please select an item from the list");
|
||||
}
|
||||
else
|
||||
{
|
||||
EventForm eventForm = new EventForm((Event)lbEvents.SelectedItem, true, user);
|
||||
eventForm.ShowDialog();
|
||||
RefreshLists();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
189
StudentHouseDashboard/WinForms/EventForm.Designer.cs
generated
Normal file
189
StudentHouseDashboard/WinForms/EventForm.Designer.cs
generated
Normal file
@@ -0,0 +1,189 @@
|
||||
namespace WinForms
|
||||
{
|
||||
partial class EventForm
|
||||
{
|
||||
/// <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();
|
||||
dtpPublishDate = new DateTimePicker();
|
||||
lblAuthor = new Label();
|
||||
lblStart = new Label();
|
||||
dtpStartDate = new DateTimePicker();
|
||||
lblEnd = new Label();
|
||||
dtpEndDate = new DateTimePicker();
|
||||
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(75, 15);
|
||||
lblPublishDate.TabIndex = 4;
|
||||
lblPublishDate.Text = "Publish date:";
|
||||
//
|
||||
// btnSave
|
||||
//
|
||||
btnSave.Location = new Point(424, 212);
|
||||
btnSave.Name = "btnSave";
|
||||
btnSave.Size = new Size(75, 23);
|
||||
btnSave.TabIndex = 6;
|
||||
btnSave.Text = "Save changes";
|
||||
btnSave.UseVisualStyleBackColor = true;
|
||||
btnSave.Click += btnSave_Click;
|
||||
//
|
||||
// dtpPublishDate
|
||||
//
|
||||
dtpPublishDate.CustomFormat = "dd-MM-yyyy hh:mm";
|
||||
dtpPublishDate.Format = DateTimePickerFormat.Custom;
|
||||
dtpPublishDate.Location = new Point(94, 153);
|
||||
dtpPublishDate.Name = "dtpPublishDate";
|
||||
dtpPublishDate.Size = new Size(141, 23);
|
||||
dtpPublishDate.TabIndex = 9;
|
||||
//
|
||||
// lblAuthor
|
||||
//
|
||||
lblAuthor.AutoSize = true;
|
||||
lblAuthor.Location = new Point(241, 159);
|
||||
lblAuthor.Name = "lblAuthor";
|
||||
lblAuthor.Size = new Size(70, 15);
|
||||
lblAuthor.TabIndex = 10;
|
||||
lblAuthor.Text = "Created by: ";
|
||||
//
|
||||
// lblStart
|
||||
//
|
||||
lblStart.AutoSize = true;
|
||||
lblStart.Location = new Point(12, 188);
|
||||
lblStart.Name = "lblStart";
|
||||
lblStart.Size = new Size(60, 15);
|
||||
lblStart.TabIndex = 11;
|
||||
lblStart.Text = "Start date:";
|
||||
//
|
||||
// dtpStartDate
|
||||
//
|
||||
dtpStartDate.CustomFormat = "dd-MM-yyyy hh:mm";
|
||||
dtpStartDate.Format = DateTimePickerFormat.Custom;
|
||||
dtpStartDate.Location = new Point(94, 182);
|
||||
dtpStartDate.Name = "dtpStartDate";
|
||||
dtpStartDate.Size = new Size(141, 23);
|
||||
dtpStartDate.TabIndex = 12;
|
||||
//
|
||||
// lblEnd
|
||||
//
|
||||
lblEnd.AutoSize = true;
|
||||
lblEnd.Location = new Point(241, 188);
|
||||
lblEnd.Name = "lblEnd";
|
||||
lblEnd.Size = new Size(56, 15);
|
||||
lblEnd.TabIndex = 13;
|
||||
lblEnd.Text = "End date:";
|
||||
//
|
||||
// dtpEndDate
|
||||
//
|
||||
dtpEndDate.CustomFormat = "dd-MM-yyyy hh:mm";
|
||||
dtpEndDate.Format = DateTimePickerFormat.Custom;
|
||||
dtpEndDate.Location = new Point(303, 183);
|
||||
dtpEndDate.Name = "dtpEndDate";
|
||||
dtpEndDate.Size = new Size(141, 23);
|
||||
dtpEndDate.TabIndex = 14;
|
||||
//
|
||||
// EventForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(511, 246);
|
||||
Controls.Add(dtpEndDate);
|
||||
Controls.Add(lblEnd);
|
||||
Controls.Add(dtpStartDate);
|
||||
Controls.Add(lblStart);
|
||||
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 = "EventForm";
|
||||
Text = "Event";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label lblTitle;
|
||||
private TextBox tbTitle;
|
||||
private Label lblDescription;
|
||||
private TextBox tbDescription;
|
||||
private Label lblPublishDate;
|
||||
private Button btnSave;
|
||||
private DateTimePicker dtpPublishDate;
|
||||
private Label lblAuthor;
|
||||
private Label lblStart;
|
||||
private DateTimePicker dtpStartDate;
|
||||
private Label lblEnd;
|
||||
private DateTimePicker dtpEndDate;
|
||||
}
|
||||
}
|
69
StudentHouseDashboard/WinForms/EventForm.cs
Normal file
69
StudentHouseDashboard/WinForms/EventForm.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Data;
|
||||
using Logic;
|
||||
using 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 EventForm : Form
|
||||
{
|
||||
Event @event;
|
||||
User currentUser;
|
||||
public EventForm(Event? @event, bool readOnly, User currentUser)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.@event = @event;
|
||||
this.currentUser = currentUser;
|
||||
|
||||
dtpPublishDate.Enabled = false;
|
||||
if (readOnly)
|
||||
{
|
||||
btnSave.Enabled = false;
|
||||
tbTitle.Enabled = false;
|
||||
tbDescription.Enabled = false;
|
||||
dtpStartDate.Enabled = false;
|
||||
dtpEndDate.Enabled = false;
|
||||
}
|
||||
if (@event != null)
|
||||
{
|
||||
tbTitle.Text = @event.Title;
|
||||
lblAuthor.Text = $"Created by: {@event.Author.Name}";
|
||||
tbDescription.Text = @event.Description;
|
||||
dtpPublishDate.Value = @event.PublishDate;
|
||||
dtpStartDate.Value = @event.EndDate;
|
||||
}
|
||||
if (currentUser != null)
|
||||
{
|
||||
lblAuthor.Text = $"Created by: {currentUser.Name}";
|
||||
}
|
||||
}
|
||||
|
||||
private void btnSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventManager eventManager = new EventManager(new EventRepository());
|
||||
if (string.IsNullOrEmpty(tbTitle.Text))
|
||||
{
|
||||
MessageBox.Show("Please enter a title");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.@event == null)
|
||||
{
|
||||
eventManager.CreateEvent(tbTitle.Text, tbDescription.Text, currentUser, dtpPublishDate.Value, dtpStartDate.Value, dtpEndDate.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
eventManager.UpdateEvent(@event.ID, tbTitle.Text, tbDescription.Text, dtpStartDate.Value, dtpEndDate.Value);
|
||||
}
|
||||
this.DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
120
StudentHouseDashboard/WinForms/EventForm.resx
Normal file
120
StudentHouseDashboard/WinForms/EventForm.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
@@ -16,6 +16,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="EventForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Update="ComplaintForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 22 KiB |
Binary file not shown.
11
table.sql
11
table.sql
@@ -81,4 +81,15 @@ CREATE TABLE ComplaintsComments (
|
||||
ComplaintID INT FOREIGN KEY REFERENCES Complaints(ID) NOT NULL,
|
||||
CommentID INT FOREIGN KEY REFERENCES Comments(ID) NOT NULL
|
||||
)
|
||||
GO
|
||||
|
||||
CREATE TABLE Events (
|
||||
ID INT PRIMARY KEY IDENTITY NOT NULL,
|
||||
[Author] INT FOREIGN KEY REFERENCES Users(ID) NOT NULL,
|
||||
[Description] NVARCHAR(MAX),
|
||||
[Title] NVARCHAR(255) NOT NULL,
|
||||
[PublishDate] DATETIME NOT NULL,
|
||||
[StartDate] DATETIME NOT NULL,
|
||||
[EndDate] DATETIME NOT NULL
|
||||
)
|
||||
GO
|
Reference in New Issue
Block a user