From 31a881056da047f5d42160b77ae807304936d9db Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Wed, 27 Mar 2024 16:18:02 +0400 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D1=81?= =?UTF-8?q?=20=D0=B1=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ExamTimetable/ExamTimetable.sln | 25 ++ .../ExamTimetable/ExamTimetable_Forms.csproj | 11 + ExamTimetable/ExamTimetable/Form1.Designer.cs | 39 ++ ExamTimetable/ExamTimetable/Form1.cs | 10 + ExamTimetable/ExamTimetable/Form1.resx | 120 +++++++ ExamTimetable/ExamTimetable/Program.cs | 17 + .../ExamTimetable_Database/Abstractions.cs | 46 +++ .../ExamTimetable_Database/Entity_models.cs | 39 ++ .../ExamTimetable_Database.csproj | 9 + .../ExamTimetable_Database/Implementation.cs | 333 ++++++++++++++++++ 10 files changed, 649 insertions(+) create mode 100644 ExamTimetable/ExamTimetable.sln create mode 100644 ExamTimetable/ExamTimetable/ExamTimetable_Forms.csproj create mode 100644 ExamTimetable/ExamTimetable/Form1.Designer.cs create mode 100644 ExamTimetable/ExamTimetable/Form1.cs create mode 100644 ExamTimetable/ExamTimetable/Form1.resx create mode 100644 ExamTimetable/ExamTimetable/Program.cs create mode 100644 ExamTimetable/ExamTimetable_Database/Abstractions.cs create mode 100644 ExamTimetable/ExamTimetable_Database/Entity_models.cs create mode 100644 ExamTimetable/ExamTimetable_Database/ExamTimetable_Database.csproj create mode 100644 ExamTimetable/ExamTimetable_Database/Implementation.cs diff --git a/ExamTimetable/ExamTimetable.sln b/ExamTimetable/ExamTimetable.sln new file mode 100644 index 0000000..c14d4b0 --- /dev/null +++ b/ExamTimetable/ExamTimetable.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33122.133 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExamTimetable", "ExamTimetable\ExamTimetable.csproj", "{073BFD8D-BE81-4F92-963C-F36385B2337C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {073BFD8D-BE81-4F92-963C-F36385B2337C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {073BFD8D-BE81-4F92-963C-F36385B2337C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {073BFD8D-BE81-4F92-963C-F36385B2337C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {073BFD8D-BE81-4F92-963C-F36385B2337C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F3EC9A9E-1007-43F2-BC85-C78B6E031DC8} + EndGlobalSection +EndGlobal diff --git a/ExamTimetable/ExamTimetable/ExamTimetable_Forms.csproj b/ExamTimetable/ExamTimetable/ExamTimetable_Forms.csproj new file mode 100644 index 0000000..b57c89e --- /dev/null +++ b/ExamTimetable/ExamTimetable/ExamTimetable_Forms.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/ExamTimetable/ExamTimetable/Form1.Designer.cs b/ExamTimetable/ExamTimetable/Form1.Designer.cs new file mode 100644 index 0000000..70bdbb5 --- /dev/null +++ b/ExamTimetable/ExamTimetable/Form1.Designer.cs @@ -0,0 +1,39 @@ +namespace ExamTimetable +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "Form1"; + } + + #endregion + } +} \ No newline at end of file diff --git a/ExamTimetable/ExamTimetable/Form1.cs b/ExamTimetable/ExamTimetable/Form1.cs new file mode 100644 index 0000000..8ef3ff4 --- /dev/null +++ b/ExamTimetable/ExamTimetable/Form1.cs @@ -0,0 +1,10 @@ +namespace ExamTimetable +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/ExamTimetable/ExamTimetable/Form1.resx b/ExamTimetable/ExamTimetable/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ExamTimetable/ExamTimetable/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ExamTimetable/ExamTimetable/Program.cs b/ExamTimetable/ExamTimetable/Program.cs new file mode 100644 index 0000000..8be64be --- /dev/null +++ b/ExamTimetable/ExamTimetable/Program.cs @@ -0,0 +1,17 @@ +namespace ExamTimetable +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file diff --git a/ExamTimetable/ExamTimetable_Database/Abstractions.cs b/ExamTimetable/ExamTimetable_Database/Abstractions.cs new file mode 100644 index 0000000..5aa1e7e --- /dev/null +++ b/ExamTimetable/ExamTimetable_Database/Abstractions.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ExamTimetable_Database +{ + public abstract class Abstractions + { + //university + public abstract void AddUniversity(University university); + public abstract List GetUniversities(); + public abstract University GetUniversityById(int id); + public abstract void UpdateUniversity(University university); + public abstract void DeleteUniversity(int id); + + //Faculty + public abstract void AddFaculty(Faculty faculty); + public abstract List GetFaculties(); + public abstract Faculty GetFacultyById(int id); + public abstract void UpdateFaculty(Faculty faculty); + public abstract void DeleteFaculty(int id); + + //Specialization + public abstract void AddSpecialization(Specialization specialization); + public abstract List GetSpecializations(); + public abstract Specialization GetSpecializationById(int id); + public abstract void UpdateSpecialization(Specialization specialization); + public abstract void DeleteSpecialization(int id); + + //Comission + public abstract void AddComission(Comission comission); + public abstract List GetComissions(); + public abstract Comission GetComissionById(int id); + public abstract void UpdateComission(Comission comission); + public abstract void DeleteComission(int id); + + //Exam + public abstract void AddExam(Exam exam); + public abstract List GetExams(); + public abstract Exam GetExamById(int id); + public abstract void UpdateExam(Exam exam); + public abstract void DeleteExam(int id); + } +} diff --git a/ExamTimetable/ExamTimetable_Database/Entity_models.cs b/ExamTimetable/ExamTimetable_Database/Entity_models.cs new file mode 100644 index 0000000..4ae6b44 --- /dev/null +++ b/ExamTimetable/ExamTimetable_Database/Entity_models.cs @@ -0,0 +1,39 @@ + +namespace ExamTimetable_Database +{ + public class University + { + public int univer_id { get; set; } + public string univer_name { get; set; } + public string univer_adress { get; set; } + public string phone_number { get; set; } + public string email_addr { get; set; } + } + public class Faculty + { + public int faculty_id { get; set; } + public string faculty_name { get; set; } + public int uni_id { get; set; } + } + public class Specialization + { + public int spec_id { get; set; } + public string spec_name { get; set; } + public int fuc_id { get; set; } + } + public class Comission + { + public int comm_id { get; set; } + public string teaching_stuff { get; set; } + public int fu_id { get; set; } + } + public class Exam + { + public int exam_id { get; set; } + public DateTime exam_date{ get; set; } + public string exam_place { get; set; } + public string exam_subject { get; set; } + public int com_id { get; set; } + public DateTime exam_time { get; set; } + } +} diff --git a/ExamTimetable/ExamTimetable_Database/ExamTimetable_Database.csproj b/ExamTimetable/ExamTimetable_Database/ExamTimetable_Database.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/ExamTimetable/ExamTimetable_Database/ExamTimetable_Database.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/ExamTimetable/ExamTimetable_Database/Implementation.cs b/ExamTimetable/ExamTimetable_Database/Implementation.cs new file mode 100644 index 0000000..809dadf --- /dev/null +++ b/ExamTimetable/ExamTimetable_Database/Implementation.cs @@ -0,0 +1,333 @@ +using Npgsql; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.ConstrainedExecution; +using System.Text; +using System.Threading.Tasks; + +namespace ExamTimetable_Database +{ + public class Implementation : Abstractions + { + private NpgsqlConnection GetConnection() + { + return new NpgsqlConnection("Host=127.0.0.1;Port=5555;Username=anna;Database=subd_anna;"); + } + //university + public override void AddUniversity(University university) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"INSERT INTO university (univer_id, univer_name, univer_adress, phone_number, email_addr) VALUES (@univer_id, @univer_name ,@univer_adress, @phone_number, @email_addr)", conn); + cmd.Parameters.AddWithValue("@univer_id", university.univer_id); + cmd.Parameters.AddWithValue("@univer_name", university.univer_name); + cmd.Parameters.AddWithValue("@univer_adress", university.univer_adress); + cmd.Parameters.AddWithValue("@phone_number", university.phone_number); + cmd.Parameters.AddWithValue("@email_addr", university.email_addr); + cmd.ExecuteNonQuery(); + } + public override List GetUniversities() + { + var universities = new List(); + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand("SELECT * FROM university", conn); + using var reader = cmd.ExecuteReader(); + while (reader.Read()) + { + universities.Add(new University + { + univer_id = reader.GetInt32(0), + univer_name = reader.GetString(1), + univer_adress = reader.GetString(2), + phone_number = reader.GetString(3), + email_addr = reader.GetString(4) + }); + } + return universities; + } + public override University GetUniversityById(int id) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"SELECT * FROM university WHERE univer_id = {id}", conn); + using var reader = cmd.ExecuteReader(); + if (reader.Read()) + { + return new University + { + univer_id = reader.GetInt32(0), + univer_name = reader.GetString(1), + univer_adress = reader.GetString(2), + phone_number = reader.GetString(3), + email_addr = reader.GetString(4) + }; + } + return null; + } + public override void UpdateUniversity(University university) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"UPDATE university SET univer_name = {university.univer_name}, univer_adress = {university.univer_adress}, phone_number = {university.phone_number}, email_addr = {university.email_addr} WHERE univer_id = {university.univer_id}", conn); + cmd.ExecuteNonQuery(); + } + public override void DeleteUniversity(int id) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"DELETE FROM university WHERE univer_id = {id}", conn); + cmd.ExecuteNonQuery(); + } + //Faculty + public override void AddFaculty(Faculty faculty) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"INSERT INTO faculty (faculty_id, faculty_name, uni_id) VALUES (@faculty_id, @faculty_name, @uni_id)", conn); + cmd.Parameters.AddWithValue("@faculty_id", faculty.faculty_id); + cmd.Parameters.AddWithValue("@faculty_name", faculty.faculty_name); + cmd.Parameters.AddWithValue("@uni_id", faculty.uni_id); + cmd.ExecuteNonQuery(); + } + public override List GetFaculties() + { + var faculties = new List(); + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand("SELECT * FROM faculty", conn); + using var reader = cmd.ExecuteReader(); + while (reader.Read()) + { + faculties.Add(new Faculty + { + faculty_id = reader.GetInt32(0), + faculty_name = reader.GetString(1), + uni_id = reader.GetInt32(2) + }); + } + return faculties; + } + public override Faculty GetFacultyById(int id) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"SELECT * FROM faculty WHERE faculty_id = {id}", conn); + using var reader = cmd.ExecuteReader(); + if (reader.Read()) + { + return new Faculty + { + faculty_id = reader.GetInt32(0), + faculty_name = reader.GetString(1), + uni_id = reader.GetInt32(2) + }; + } + return null; + } + public override void UpdateFaculty(Faculty faculty) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"UPDATE faculty SET faculty_name = {faculty.faculty_name}, uni_id = {faculty.uni_id} WHERE faculty_id = {faculty.faculty_id}", conn); + cmd.ExecuteNonQuery(); + } + public override void DeleteFaculty(int id) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"DELETE FROM faculty WHERE faculty_id = {id}", conn); + cmd.ExecuteNonQuery(); + } + //Specialization + public override void AddSpecialization(Specialization specialization) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"INSERT INTO specialization (spec_id, spec_name, fuc_id) VALUES (@spec_id, @spec_name, @fuc_id)", conn); + cmd.Parameters.AddWithValue("@spec_id", specialization.spec_id); + cmd.Parameters.AddWithValue("@spec_name", specialization.spec_name); + cmd.Parameters.AddWithValue("@fuc_id", specialization.fuc_id); + cmd.ExecuteNonQuery(); + } + public override List GetSpecializations() + { + var specializations = new List(); + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand("SELECT * FROM specialization", conn); + using var reader = cmd.ExecuteReader(); + while (reader.Read()) + { + specializations.Add(new Specialization + { + spec_id = reader.GetInt32(0), + spec_name = reader.GetString(1), + fuc_id = reader.GetInt32(2) + }); + } + return specializations; + } + public override Specialization GetSpecializationById(int id) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"SELECT * FROM specialization WHERE spec_id = {id}", conn); + using var reader = cmd.ExecuteReader(); + if (reader.Read()) + { + return new Specialization + { + spec_id = reader.GetInt32(0), + spec_name = reader.GetString(1), + fuc_id = reader.GetInt32(2) + }; + } + return null; + } + public override void UpdateSpecialization(Specialization specialization) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"UPDATE specialization SET spec_name = {specialization.spec_name}, fuc_id = {specialization.fuc_id} WHERE spec_id = {specialization.spec_id}", conn); + cmd.ExecuteNonQuery(); + } + public override void DeleteSpecialization(int id) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"DELETE FROM specialization WHERE spec_id = {id}", conn); + cmd.ExecuteNonQuery(); + } + //Comission + public override void AddComission(Comission comission) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"INSERT INTO comission (comm_id, teaching_stuff, fu_id) VALUES (@comm_id, @teaching_stuff, @fu_id)", conn); + cmd.Parameters.AddWithValue("@comm_id", comission.comm_id); + cmd.Parameters.AddWithValue("@teaching_stuff", comission.teaching_stuff); + cmd.Parameters.AddWithValue("@fu_id", comission.fu_id); + cmd.ExecuteNonQuery(); + } + public override List GetComissions() + { + var comissions = new List(); + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand("SELECT * FROM comission", conn); + using var reader = cmd.ExecuteReader(); + while (reader.Read()) + { + comissions.Add(new Comission + { + comm_id = reader.GetInt32(0), + teaching_stuff = reader.GetString(1), + fu_id = reader.GetInt32(2) + }); + } + return comissions; + } + public override Comission GetComissionById(int id) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"SELECT * FROM comission WHERE comm_id = {id}", conn); + using var reader = cmd.ExecuteReader(); + if (reader.Read()) + { + return new Comission + { + comm_id = reader.GetInt32(0), + teaching_stuff = reader.GetString(1), + fu_id = reader.GetInt32(2) + }; + } + return null; + } + public override void UpdateComission(Comission comission) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"UPDATE comission SET teaching_stuff = {comission.teaching_stuff}, fu_id = {comission.fu_id} WHERE comm_id = {comission.comm_id}", conn); + cmd.ExecuteNonQuery(); + } + public override void DeleteComission(int id) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"DELETE FROM comission WHERE comm_id = {id}", conn); + cmd.ExecuteNonQuery(); + } + //Exam + public override void AddExam(Exam exam) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"INSERT INTO exam (exam_id, exam_date, exam_place, exam_subject, com_id, exam_time) VALUES (@exam_id, @exam_date, @exam_place, @exam_subject, @com_id, @exam_time)", conn); + cmd.Parameters.AddWithValue("@exam_id", exam.exam_id); + cmd.Parameters.AddWithValue("@exam_date", exam.exam_date); + cmd.Parameters.AddWithValue("@exam_place", exam.exam_place); + cmd.Parameters.AddWithValue("@exam_subject", exam.exam_subject); + cmd.Parameters.AddWithValue("@com_id", exam.com_id); + cmd.Parameters.AddWithValue("@exam_time", exam.exam_time); + cmd.ExecuteNonQuery(); + } + public override List GetExams() + { + var exams = new List(); + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand("SELECT * FROM exam", conn); + using var reader = cmd.ExecuteReader(); + while (reader.Read()) + { + exams.Add(new Exam + { + exam_id = reader.GetInt32(0), + exam_date = reader.GetDateTime(1), + exam_place = reader.GetString(2), + exam_subject = reader.GetString(3), + com_id = reader.GetInt32(4), + exam_time = reader.GetDateTime(5) + }); + } + return exams; + } + public override Exam GetExamById(int id) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"SELECT * FROM exam WHERE exam_id = {id}", conn); + using var reader = cmd.ExecuteReader(); + if (reader.Read()) + { + return new Exam + { + exam_id = reader.GetInt32(0), + exam_date = reader.GetDateTime(1), + exam_place = reader.GetString(2), + exam_subject = reader.GetString(3), + com_id = reader.GetInt32(4), + exam_time = reader.GetDateTime(5) + }; + } + return null; + } + public override void UpdateExam(Exam exam) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"UPDATE exam SET exam_date = {exam.exam_date}, exam_place = {exam.exam_place}, exam_subject = {exam.exam_subject}, com_id = {exam.com_id}, exam_time= {exam.exam_time} WHERE exam_id = {exam.exam_id}", conn); + cmd.ExecuteNonQuery(); + } + public override void DeleteExam(int id) + { + using var conn = GetConnection(); + conn.Open(); + using var cmd = new NpgsqlCommand($"DELETE FROM exam WHERE exam_id = {id}", conn); + cmd.ExecuteNonQuery(); + } + } +}