diff --git a/ProjectSession/ProjectSession/Entities/AddMark.cs b/ProjectSession/ProjectSession/Entities/AddMark.cs new file mode 100644 index 0000000..9fc6137 --- /dev/null +++ b/ProjectSession/ProjectSession/Entities/AddMark.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectSession.Entities.Enums; + +namespace ProjectSession.Entities; + +public class AddMark +{ + public int Id { get; private set; } + public int StudentId { get; private set; } + public int GroupId { get; private set; } + public int DisciplineId { get; private set; } + public Mark? Mark { get; private set; } // Оставляем тип Mark + public DateTime Date { get; private set; } + + public static AddMark CreateOperation(int id, int studentId, int groupId, int disciplineId, Mark mark) + { + return new AddMark + { + Id = id, + StudentId = studentId, + GroupId = groupId, + DisciplineId = disciplineId, + Mark = mark, // Если `Mark` имеет значение по умолчанию, его можно обработать + Date = DateTime.Now + }; + } +} diff --git a/ProjectSession/ProjectSession/Entities/Discipline.cs b/ProjectSession/ProjectSession/Entities/Discipline.cs index c8f9b05..aa39a00 100644 --- a/ProjectSession/ProjectSession/Entities/Discipline.cs +++ b/ProjectSession/ProjectSession/Entities/Discipline.cs @@ -1,16 +1,28 @@ -namespace YourNamespace.Entities; +using Microsoft.VisualBasic.Devices; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectSession.Entities.Enums; + +namespace ProjectSession.Entities; public class Discipline { - public int Id { get; private set; } - public string Name { get; private set; } + public int ID { get; private set; } + public string Name { get; private set; } = string.Empty; + public string Description { get; private set; } = string.Empty; + public Course Courses { get; private set; } - public static Discipline CreateEntity(int id, string name) + public static Discipline Create(int id, string name, string description, Course courses) { return new Discipline { - Id = id, - Name = name ?? string.Empty + ID = id, + Name = name, + Description = description, + Courses = courses }; } -} \ No newline at end of file +} diff --git a/ProjectSession/ProjectSession/Entities/Enums/DisciplineType.cs b/ProjectSession/ProjectSession/Entities/Enums/Course.cs similarity index 53% rename from ProjectSession/ProjectSession/Entities/Enums/DisciplineType.cs rename to ProjectSession/ProjectSession/Entities/Enums/Course.cs index 2800e79..efd69ef 100644 --- a/ProjectSession/ProjectSession/Entities/Enums/DisciplineType.cs +++ b/ProjectSession/ProjectSession/Entities/Enums/Course.cs @@ -7,14 +7,11 @@ using System.Threading.Tasks; namespace ProjectSession.Entities.Enums; [Flags] -public enum DisciplineType +public enum Course { None = 0, - Mathematics = 1, - Physics = 2, - Chemistry = 4, - Biology = 8, - History = 16, - Literature = 32, - Programming = 64, + First = 1, // 1 курс + Second = 2, // 2 курс + Third = 4, // 3 курс + Fourth = 8 // 4 курс } diff --git a/ProjectSession/ProjectSession/Entities/Enums/GroupType.cs b/ProjectSession/ProjectSession/Entities/Enums/GroupType.cs new file mode 100644 index 0000000..945ea22 --- /dev/null +++ b/ProjectSession/ProjectSession/Entities/Enums/GroupType.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectSession.Entities.Enums; + +public enum GroupType +{ + Daytime, // Дневная + Evening, // Вечерняя + FullTimeDistance // Очно-заочная +} diff --git a/ProjectSession/ProjectSession/Entities/Enums/StudentStatus.cs b/ProjectSession/ProjectSession/Entities/Enums/Mark.cs similarity index 63% rename from ProjectSession/ProjectSession/Entities/Enums/StudentStatus.cs rename to ProjectSession/ProjectSession/Entities/Enums/Mark.cs index b102b0f..a27e0ee 100644 --- a/ProjectSession/ProjectSession/Entities/Enums/StudentStatus.cs +++ b/ProjectSession/ProjectSession/Entities/Enums/Mark.cs @@ -6,9 +6,12 @@ using System.Threading.Tasks; namespace ProjectSession.Entities.Enums; -public enum StudentStatus +public enum Mark { - Active, - Inactive, - Graduated + None, + One = 1, + Two = 2, + Three = 3, + Four = 4, + Five = 5 } diff --git a/ProjectSession/ProjectSession/Entities/Group.cs b/ProjectSession/ProjectSession/Entities/Group.cs new file mode 100644 index 0000000..d88b4c7 --- /dev/null +++ b/ProjectSession/ProjectSession/Entities/Group.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectSession.Entities.Enums; + +namespace ProjectSession.Entities; + +public class Group +{ + public int ID { get; private set; } + public string Name { get; private set; } = string.Empty; + public GroupType Type { get; private set; } + + public static Group Create(int id, string name, GroupType type) + { + return new Group + { + ID = id, + Name = name, + Type = type + }; + } +} diff --git a/ProjectSession/ProjectSession/Entities/Statament.cs b/ProjectSession/ProjectSession/Entities/Statament.cs deleted file mode 100644 index e9c8aca..0000000 --- a/ProjectSession/ProjectSession/Entities/Statament.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectSession.Entities; - -public class Statement -{ - public int Id { get; private set; } - public int StudentID { get; private set; } - public int TeacherID { get; private set; } - public int DisciplineID { get; private set; } - public int Estimation { get; private set; } - public DateTime Date { get; private set; } - - public static Statement CreateEntity(int id, int studentID, int teacherID, int disciplineID, int estimation, DateTime date) - { - return new Statement - { - Id = id, - StudentID = studentID, - TeacherID = teacherID, - DisciplineID = disciplineID, - Estimation = estimation, - Date = date - }; - } -} diff --git a/ProjectSession/ProjectSession/Entities/Student.cs b/ProjectSession/ProjectSession/Entities/Student.cs index 3ef164e..18a8367 100644 --- a/ProjectSession/ProjectSession/Entities/Student.cs +++ b/ProjectSession/ProjectSession/Entities/Student.cs @@ -8,19 +8,21 @@ namespace ProjectSession.Entities; public class Student { - public int Id { get; private set; } - public string Name { get; private set; } - public string FamilyStatus { get; private set; } - public bool Dormitory { get; private set; } + public int ID { get; private set; } + public string Surname { get; private set; } = string.Empty; + public string Name { get; private set; } = string.Empty; + public string MiddleName { get; private set; } = string.Empty; + public int GroupID { get; private set; } - public static Student CreateEntity(int id, string name, string familyStatus, bool dormitory, Enums.StudentStatus active) + public static Student Create(int id, string surname, string name, string middleName, int groupID) { return new Student { - Id = id, - Name = name ?? string.Empty, - FamilyStatus = familyStatus ?? string.Empty, - Dormitory = dormitory + ID = id, + Surname = surname, + Name = name, + MiddleName = middleName, + GroupID = groupID }; } } diff --git a/ProjectSession/ProjectSession/Entities/Student_Statament.cs b/ProjectSession/ProjectSession/Entities/Student_Statament.cs deleted file mode 100644 index e44b95d..0000000 --- a/ProjectSession/ProjectSession/Entities/Student_Statament.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectSession.Entities; - -public class Student_Statement -{ - public int Id { get; private set; } - public int StudentID { get; private set; } - public int StatementID { get; private set; } - - public static Student_Statement CreateEntity(int id, int studentID, int statementID) - { - return new Student_Statement - { - Id = id, - StudentID = studentID, - StatementID = statementID - }; - } -} diff --git a/ProjectSession/ProjectSession/Entities/Sumbission.cs b/ProjectSession/ProjectSession/Entities/Sumbission.cs deleted file mode 100644 index f0e9aac..0000000 --- a/ProjectSession/ProjectSession/Entities/Sumbission.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectSession.Entities; - -public class Sumbission -{ - public class Submission - { - public int Id { get; private set; } - public int DisciplineID { get; private set; } - public DateTime Date { get; private set; } - - public static Submission CreateEntity(int id, int disciplineID, DateTime date) - { - return new Submission - { - Id = id, - DisciplineID = disciplineID, - Date = date - }; - } - } -} diff --git a/ProjectSession/ProjectSession/Entities/Teacher.cs b/ProjectSession/ProjectSession/Entities/Teacher.cs index d6327e6..5d2aef9 100644 --- a/ProjectSession/ProjectSession/Entities/Teacher.cs +++ b/ProjectSession/ProjectSession/Entities/Teacher.cs @@ -8,15 +8,21 @@ namespace ProjectSession.Entities; public class Teacher { - public int Id { get; private set; } - public string Name { get; private set; } + public int ID { get; private set; } + public string Surname { get; private set; } = string.Empty; + public string Name { get; private set; } = string.Empty; + public string MiddleName { get; private set; } = string.Empty; + public int DisciplineID { get; private set; } - public static Teacher CreateEntity(int id, string name) + public static Teacher Create(int id, string surname, string name, string middleName, int disciplineID) { return new Teacher { - Id = id, - Name = name ?? string.Empty + ID = id, + Surname = surname, + Name = name, + MiddleName = middleName, + DisciplineID = disciplineID }; } -} \ No newline at end of file +} diff --git a/ProjectSession/ProjectSession/FormSessionResult.cs b/ProjectSession/ProjectSession/FormSessionResult.cs deleted file mode 100644 index 7b36605..0000000 --- a/ProjectSession/ProjectSession/FormSessionResult.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using System.Windows.Forms; -using Unity; - -namespace ProjectSession.Forms -{ - public partial class FormSessionResult : Form - { - private readonly IUnityContainer _container; - - public FormSessionResult(IUnityContainer container) - { - InitializeComponent(); - _container = container ?? throw new ArgumentNullException(nameof(container)); - this.StartPosition = FormStartPosition.CenterScreen; - } - - private void StudentsToolStripMenuItem_Click(object sender, EventArgs e) - { - try - { - _container.Resolve().ShowDialog(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void DisciplinesToolStripMenuItem_Click(object sender, EventArgs e) - { - try - { - _container.Resolve().ShowDialog(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void TeachersToolStripMenuItem_Click(object sender, EventArgs e) - { - try - { - _container.Resolve().ShowDialog(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void StatementsToolStripMenuItem_Click(object sender, EventArgs e) - { - try - { - _container.Resolve().ShowDialog(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void SubmissionsToolStripMenuItem_Click(object sender, EventArgs e) - { - try - { - _container.Resolve().ShowDialog(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/FormSessionResult.Designer.cs b/ProjectSession/ProjectSession/FormSessionResults.Designer.cs similarity index 79% rename from ProjectSession/ProjectSession/FormSessionResult.Designer.cs rename to ProjectSession/ProjectSession/FormSessionResults.Designer.cs index f2f35f8..7d1c78a 100644 --- a/ProjectSession/ProjectSession/FormSessionResult.Designer.cs +++ b/ProjectSession/ProjectSession/FormSessionResults.Designer.cs @@ -1,6 +1,6 @@ -namespace ProjectSession.Forms +namespace ProjectSession { - partial class FormSessionResult + partial class FormSessionResults { /// /// Required designer variable. @@ -31,11 +31,11 @@ menuStrip1 = new MenuStrip(); справочникиToolStripMenuItem = new ToolStripMenuItem(); StudentsToolStripMenuItem = new ToolStripMenuItem(); - DisciplinesToolStripMenuItem = new ToolStripMenuItem(); + GroupsToolStripMenuItem = new ToolStripMenuItem(); TeachersToolStripMenuItem = new ToolStripMenuItem(); + DisciplinesToolStripMenuItem = new ToolStripMenuItem(); опереToolStripMenuItem = new ToolStripMenuItem(); - StatementsToolStripMenuItem = new ToolStripMenuItem(); - SubmissionsToolStripMenuItem = new ToolStripMenuItem(); + AddMarksToolStripMenuItem = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -53,7 +53,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { StudentsToolStripMenuItem, DisciplinesToolStripMenuItem, TeachersToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { StudentsToolStripMenuItem, GroupsToolStripMenuItem, TeachersToolStripMenuItem, DisciplinesToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -65,12 +65,12 @@ StudentsToolStripMenuItem.Text = "Студенты"; StudentsToolStripMenuItem.Click += StudentsToolStripMenuItem_Click; // - // DisciplinesToolStripMenuItem + // GroupsToolStripMenuItem // - DisciplinesToolStripMenuItem.Name = "DisciplinesToolStripMenuItem"; - DisciplinesToolStripMenuItem.Size = new Size(201, 26); - DisciplinesToolStripMenuItem.Text = "Дисциплины"; - DisciplinesToolStripMenuItem.Click += DisciplinesToolStripMenuItem_Click; + GroupsToolStripMenuItem.Name = "GroupsToolStripMenuItem"; + GroupsToolStripMenuItem.Size = new Size(201, 26); + GroupsToolStripMenuItem.Text = "Группы"; + GroupsToolStripMenuItem.Click += GroupsToolStripMenuItem_Click; // // TeachersToolStripMenuItem // @@ -79,26 +79,26 @@ TeachersToolStripMenuItem.Text = "Преподаватели"; TeachersToolStripMenuItem.Click += TeachersToolStripMenuItem_Click; // + // DisciplinesToolStripMenuItem + // + DisciplinesToolStripMenuItem.Name = "DisciplinesToolStripMenuItem"; + DisciplinesToolStripMenuItem.Size = new Size(201, 26); + DisciplinesToolStripMenuItem.Text = "Дисциплины"; + DisciplinesToolStripMenuItem.Click += DisciplinesToolStripMenuItem_Click; + // // опереToolStripMenuItem // - опереToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { StatementsToolStripMenuItem, SubmissionsToolStripMenuItem }); + опереToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { AddMarksToolStripMenuItem }); опереToolStripMenuItem.Name = "опереToolStripMenuItem"; опереToolStripMenuItem.Size = new Size(95, 24); опереToolStripMenuItem.Text = "Операции"; // - // StatementsToolStripMenuItem + // AddMarksToolStripMenuItem // - StatementsToolStripMenuItem.Name = "StatementsToolStripMenuItem"; - StatementsToolStripMenuItem.Size = new Size(166, 26); - StatementsToolStripMenuItem.Text = "Заявления"; - StatementsToolStripMenuItem.Click += StatementsToolStripMenuItem_Click; - // - // SubmissionsToolStripMenuItem - // - SubmissionsToolStripMenuItem.Name = "SubmissionsToolStripMenuItem"; - SubmissionsToolStripMenuItem.Size = new Size(166, 26); - SubmissionsToolStripMenuItem.Text = "Сдачи"; - SubmissionsToolStripMenuItem.Click += SubmissionsToolStripMenuItem_Click; + AddMarksToolStripMenuItem.Name = "AddMarksToolStripMenuItem"; + AddMarksToolStripMenuItem.Size = new Size(233, 26); + AddMarksToolStripMenuItem.Text = "Добавление оценки"; + AddMarksToolStripMenuItem.Click += AddMarksToolStripMenuItem_Click; // // отчетыToolStripMenuItem // @@ -106,7 +106,7 @@ отчетыToolStripMenuItem.Size = new Size(73, 24); отчетыToolStripMenuItem.Text = "Отчеты"; // - // FormSessionResult + // FormSessionResults // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; @@ -116,9 +116,10 @@ Controls.Add(menuStrip1); MainMenuStrip = menuStrip1; Margin = new Padding(3, 4, 3, 4); - Name = "FormSessionResult"; + Name = "FormSessionResults"; StartPosition = FormStartPosition.CenterParent; - Text = "Результаты сессии"; + Text = "Ведомость"; + Load += FormSessionResults_Load; menuStrip1.ResumeLayout(false); menuStrip1.PerformLayout(); ResumeLayout(false); @@ -130,11 +131,11 @@ private MenuStrip menuStrip1; private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem StudentsToolStripMenuItem; - private ToolStripMenuItem DisciplinesToolStripMenuItem; + private ToolStripMenuItem GroupsToolStripMenuItem; private ToolStripMenuItem TeachersToolStripMenuItem; + private ToolStripMenuItem DisciplinesToolStripMenuItem; private ToolStripMenuItem опереToolStripMenuItem; private ToolStripMenuItem отчетыToolStripMenuItem; - private ToolStripMenuItem StatementsToolStripMenuItem; - private ToolStripMenuItem SubmissionsToolStripMenuItem; + private ToolStripMenuItem AddMarksToolStripMenuItem; } } \ No newline at end of file diff --git a/ProjectSession/ProjectSession/FormSessionResults.cs b/ProjectSession/ProjectSession/FormSessionResults.cs new file mode 100644 index 0000000..6d0718f --- /dev/null +++ b/ProjectSession/ProjectSession/FormSessionResults.cs @@ -0,0 +1,89 @@ +using ProjectSession.Forms; +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; +using Unity; + +namespace ProjectSession; + +public partial class FormSessionResults : Form +{ + private readonly IUnityContainer _container; + + public FormSessionResults(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + private void StudentsToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void GroupsToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void TeachersToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void DisciplinesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddMarksToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FormSessionResults_Load(object sender, EventArgs e) + { + + } +} diff --git a/ProjectSession/ProjectSession/FormSessionResult.resx b/ProjectSession/ProjectSession/FormSessionResults.resx similarity index 100% rename from ProjectSession/ProjectSession/FormSessionResult.resx rename to ProjectSession/ProjectSession/FormSessionResults.resx diff --git a/ProjectSession/ProjectSession/Forms/AddMarkForm.Designer.cs b/ProjectSession/ProjectSession/Forms/AddMarkForm.Designer.cs new file mode 100644 index 0000000..5464ed3 --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/AddMarkForm.Designer.cs @@ -0,0 +1,218 @@ +namespace ProjectSession.Forms +{ + partial class AddMarkForm + { + /// + /// 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() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + label5 = new Label(); + label6 = new Label(); + ButtonSave = new Button(); + ButtonCancel = new Button(); + comboBoxDiscipline = new ComboBox(); + comboBoxTeacher = new ComboBox(); + comboBoxStudent = new ComboBox(); + comboBoxGroup = new ComboBox(); + comboBoxMark = new ComboBox(); + dateTimePickerDate = new DateTimePicker(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(40, 42); + label1.Name = "label1"; + label1.Size = new Size(55, 15); + label1.TabIndex = 0; + label1.Text = "Предмет"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(40, 73); + label2.Name = "label2"; + label2.Size = new Size(91, 15); + label2.TabIndex = 1; + label2.Text = "Преподаватель"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(40, 105); + label3.Name = "label3"; + label3.Size = new Size(50, 15); + label3.TabIndex = 2; + label3.Text = "Студент"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(40, 137); + label4.Name = "label4"; + label4.Size = new Size(46, 15); + label4.TabIndex = 3; + label4.Text = "Группа"; + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(40, 195); + label5.Name = "label5"; + label5.Size = new Size(48, 15); + label5.TabIndex = 4; + label5.Text = "Оценка"; + // + // label6 + // + label6.AutoSize = true; + label6.Location = new Point(40, 233); + label6.Name = "label6"; + label6.Size = new Size(32, 15); + label6.TabIndex = 5; + label6.Text = "Дата"; + // + // ButtonSave + // + ButtonSave.Location = new Point(61, 284); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(96, 23); + ButtonSave.TabIndex = 10; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(234, 284); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(96, 23); + ButtonCancel.TabIndex = 11; + ButtonCancel.Text = "Отменить"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // comboBoxDiscipline + // + comboBoxDiscipline.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxDiscipline.FormattingEnabled = true; + comboBoxDiscipline.Location = new Point(186, 39); + comboBoxDiscipline.Name = "comboBoxDiscipline"; + comboBoxDiscipline.Size = new Size(175, 23); + comboBoxDiscipline.TabIndex = 12; + // + // comboBoxTeacher + // + comboBoxTeacher.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxTeacher.FormattingEnabled = true; + comboBoxTeacher.Location = new Point(186, 70); + comboBoxTeacher.Name = "comboBoxTeacher"; + comboBoxTeacher.Size = new Size(175, 23); + comboBoxTeacher.TabIndex = 13; + // + // comboBoxStudent + // + comboBoxStudent.BackColor = Color.White; + comboBoxStudent.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStudent.FormattingEnabled = true; + comboBoxStudent.Location = new Point(186, 102); + comboBoxStudent.Name = "comboBoxStudent"; + comboBoxStudent.Size = new Size(175, 23); + comboBoxStudent.TabIndex = 14; + // + // comboBoxGroup + // + comboBoxGroup.BackColor = Color.White; + comboBoxGroup.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxGroup.FormattingEnabled = true; + comboBoxGroup.Location = new Point(186, 134); + comboBoxGroup.Name = "comboBoxGroup"; + comboBoxGroup.Size = new Size(175, 23); + comboBoxGroup.TabIndex = 15; + // + // comboBoxMark + // + comboBoxMark.BackColor = Color.White; + comboBoxMark.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxMark.FormattingEnabled = true; + comboBoxMark.Location = new Point(186, 192); + comboBoxMark.Name = "comboBoxMark"; + comboBoxMark.Size = new Size(175, 23); + comboBoxMark.TabIndex = 16; + // + // dateTimePickerDate + // + dateTimePickerDate.Location = new Point(186, 227); + dateTimePickerDate.Name = "dateTimePickerDate"; + dateTimePickerDate.Size = new Size(175, 23); + dateTimePickerDate.TabIndex = 17; + // + // AddMarkForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(407, 342); + Controls.Add(dateTimePickerDate); + Controls.Add(comboBoxMark); + Controls.Add(comboBoxGroup); + Controls.Add(comboBoxStudent); + Controls.Add(comboBoxTeacher); + Controls.Add(comboBoxDiscipline); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Controls.Add(label6); + Controls.Add(label5); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "AddMarkForm"; + Text = "Добавить оценку"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private Label label5; + private Label label6; + private Button ButtonSave; + private Button ButtonCancel; + private ComboBox comboBoxDiscipline; + private ComboBox comboBoxTeacher; + private ComboBox comboBoxStudent; + private ComboBox comboBoxGroup; + private ComboBox comboBoxMark; + private DateTimePicker dateTimePickerDate; + } +} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/AddMarkForm.cs b/ProjectSession/ProjectSession/Forms/AddMarkForm.cs new file mode 100644 index 0000000..0bc02ef --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/AddMarkForm.cs @@ -0,0 +1,85 @@ +using ProjectSession.Entities.Enums; +using ProjectSession.Entities; +using ProjectSession.Repositories; +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 ProjectSession.Forms; + +public partial class AddMarkForm : Form +{ + private readonly IAddMarkRepository _addMarkRepository; + private readonly IStudentRepository _studentRepository; + private readonly IGroupRepository _groupRepository; + private readonly ITeacherRepository _teacherRepository; + private readonly IDisciplineRepository _disciplineRepository; + + public AddMarkForm(IAddMarkRepository addMarkRepository, IStudentRepository studentRepository, IGroupRepository groupRepository, ITeacherRepository teacherRepository, IDisciplineRepository disciplineRepository) + { + InitializeComponent(); + + _addMarkRepository = addMarkRepository ?? throw new ArgumentNullException(nameof(addMarkRepository)); + _studentRepository = studentRepository ?? throw new ArgumentNullException(nameof(studentRepository)); + _groupRepository = groupRepository ?? throw new ArgumentNullException(nameof(groupRepository)); + _teacherRepository = teacherRepository ?? throw new ArgumentNullException(nameof(teacherRepository)); + _disciplineRepository = disciplineRepository ?? throw new ArgumentNullException(nameof(disciplineRepository)); + + + comboBoxStudent.DataSource = _studentRepository.GetAllStudents(); + comboBoxStudent.DisplayMember = "Name"; + comboBoxStudent.ValueMember = "Id"; + + comboBoxGroup.DataSource = _groupRepository.GetAllGroups(); + comboBoxGroup.DisplayMember = "Name"; + comboBoxGroup.ValueMember = "Id"; + + comboBoxTeacher.DataSource = _teacherRepository.GetAllTeachers(); + comboBoxTeacher.DisplayMember = "Name"; + comboBoxTeacher.ValueMember = "Id"; + + comboBoxDiscipline.DataSource = _disciplineRepository.GetAllDisciplines(); + comboBoxDiscipline.DisplayMember = "Name"; + comboBoxDiscipline.ValueMember = "Id"; + + comboBoxMark.DataSource = Enum.GetValues(typeof(Mark)); + + + dateTimePickerDate.Enabled = false; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxStudent.SelectedIndex < 0 || + comboBoxGroup.SelectedIndex < 0 || + comboBoxTeacher.SelectedIndex < 0 || + comboBoxDiscipline.SelectedIndex < 0 || + comboBoxMark.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля"); + } + + _addMarkRepository.CreateMark(AddMark.CreateOperation(0, + (int)comboBoxStudent.SelectedValue!, + (int)comboBoxGroup.SelectedValue!, + (int)comboBoxDiscipline.SelectedValue!, + (Mark)comboBoxMark.SelectedItem!)); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); +} diff --git a/ProjectSession/ProjectSession/Forms/FormDiscipline.resx b/ProjectSession/ProjectSession/Forms/AddMarkForm.resx similarity index 100% rename from ProjectSession/ProjectSession/Forms/FormDiscipline.resx rename to ProjectSession/ProjectSession/Forms/AddMarkForm.resx diff --git a/ProjectSession/ProjectSession/Forms/AddMarkListForm.Designer.cs b/ProjectSession/ProjectSession/Forms/AddMarkListForm.Designer.cs new file mode 100644 index 0000000..2e51b60 --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/AddMarkListForm.Designer.cs @@ -0,0 +1,102 @@ +namespace ProjectSession.Forms +{ + partial class AddMarkListForm + { + /// + /// 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() + { + panel1 = new Panel(); + ButtonAdd = new Button(); + dataGridViewData = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(ButtonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(916, 0); + panel1.Margin = new Padding(3, 4, 3, 4); + panel1.Name = "panel1"; + panel1.Size = new Size(180, 599); + panel1.TabIndex = 0; + // + // ButtonAdd + // + ButtonAdd.BackgroundImage = Properties.Resources.add_icon; + ButtonAdd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonAdd.Location = new Point(18, 186); + ButtonAdd.Margin = new Padding(3, 4, 3, 4); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(150, 150); + ButtonAdd.TabIndex = 3; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.Margin = new Padding(3, 4, 3, 4); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.RowHeadersWidth = 51; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(916, 599); + dataGridViewData.TabIndex = 4; + // + // AddMarkListForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1096, 599); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Margin = new Padding(3, 4, 3, 4); + Name = "AddMarkListForm"; + Text = "Добавление оценок"; + Load += AddMarkListForm_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button ButtonAdd; + private DataGridView dataGridViewData; + } +} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/AddMarkListForm.cs b/ProjectSession/ProjectSession/Forms/AddMarkListForm.cs new file mode 100644 index 0000000..ec7d204 --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/AddMarkListForm.cs @@ -0,0 +1,54 @@ +using ProjectSession.Repositories; +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; +using Unity; + +namespace ProjectSession.Forms; + +public partial class AddMarkListForm : Form +{ + private readonly IUnityContainer _container; + private readonly IAddMarkRepository _addMarkRepository; + + public AddMarkListForm(IUnityContainer container, IAddMarkRepository addMarkRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _addMarkRepository = addMarkRepository ?? throw new ArgumentNullException(nameof(addMarkRepository)); + } + + private void AddMarkListForm_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewData.DataSource = _addMarkRepository.GetAllMarks(); + +} diff --git a/ProjectSession/ProjectSession/Forms/FormStatementEdit.resx b/ProjectSession/ProjectSession/Forms/AddMarkListForm.resx similarity index 100% rename from ProjectSession/ProjectSession/Forms/FormStatementEdit.resx rename to ProjectSession/ProjectSession/Forms/AddMarkListForm.resx diff --git a/ProjectSession/ProjectSession/Forms/DisciplineForm.Designer.cs b/ProjectSession/ProjectSession/Forms/DisciplineForm.Designer.cs new file mode 100644 index 0000000..e7a478d --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/DisciplineForm.Designer.cs @@ -0,0 +1,141 @@ +namespace ProjectSession.Forms +{ + partial class DisciplineForm + { + /// + /// 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() + { + labelName = new Label(); + labelDescription = new Label(); + labelDisciplineType = new Label(); + textBoxName = new TextBox(); + textBoxDescription = new TextBox(); + checkedListBoxCourse = new CheckedListBox(); + ButtonSave = new Button(); + ButtonCancel = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(41, 36); + labelName.Name = "labelName"; + labelName.Size = new Size(59, 15); + labelName.TabIndex = 0; + labelName.Text = "Название"; + // + // labelDescription + // + labelDescription.AutoSize = true; + labelDescription.Location = new Point(41, 74); + labelDescription.Name = "labelDescription"; + labelDescription.Size = new Size(62, 15); + labelDescription.TabIndex = 1; + labelDescription.Text = "Описание"; + // + // labelDisciplineType + // + labelDisciplineType.AutoSize = true; + labelDisciplineType.Location = new Point(41, 174); + labelDisciplineType.Name = "labelDisciplineType"; + labelDisciplineType.Size = new Size(78, 15); + labelDisciplineType.TabIndex = 2; + labelDisciplineType.Text = "Выбор курса"; + // + // textBoxName + // + textBoxName.Location = new Point(147, 33); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(184, 23); + textBoxName.TabIndex = 3; + // + // textBoxDescription + // + textBoxDescription.Location = new Point(147, 71); + textBoxDescription.Multiline = true; + textBoxDescription.Name = "textBoxDescription"; + textBoxDescription.Size = new Size(184, 85); + textBoxDescription.TabIndex = 4; + // + // checkedListBoxCourse + // + checkedListBoxCourse.FormattingEnabled = true; + checkedListBoxCourse.Location = new Point(147, 174); + checkedListBoxCourse.Name = "checkedListBoxCourse"; + checkedListBoxCourse.Size = new Size(184, 94); + checkedListBoxCourse.TabIndex = 5; + // + // ButtonSave + // + ButtonSave.Location = new Point(54, 298); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(96, 23); + ButtonSave.TabIndex = 10; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(210, 298); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(96, 23); + ButtonCancel.TabIndex = 11; + ButtonCancel.Text = "Отменить"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // DisciplineForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(372, 347); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Controls.Add(checkedListBoxCourse); + Controls.Add(textBoxDescription); + Controls.Add(textBoxName); + Controls.Add(labelDisciplineType); + Controls.Add(labelDescription); + Controls.Add(labelName); + Name = "DisciplineForm"; + Text = "Дисциплина"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelDescription; + private Label labelDisciplineType; + private TextBox textBoxName; + private TextBox textBoxDescription; + private CheckedListBox checkedListBoxCourse; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/DisciplineForm.cs b/ProjectSession/ProjectSession/Forms/DisciplineForm.cs new file mode 100644 index 0000000..5b0d72d --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/DisciplineForm.cs @@ -0,0 +1,102 @@ +using ProjectSession.Entities.Enums; +using ProjectSession.Entities; +using ProjectSession.Repositories; +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 ProjectSession.Forms; + +public partial class DisciplineForm : Form +{ + private readonly IDisciplineRepository _disciplineRepository; + private int? _disciplineId; + + public int Id + { + set + { + try + { + var discipline = _disciplineRepository.GetDisciplineById(value); + if (discipline == null) + { + throw new InvalidDataException(nameof(discipline)); + } + foreach (Course elem in Enum.GetValues(typeof(Course))) + { + if ((elem & discipline.Courses) != 0) + { + checkedListBoxCourse.SetItemChecked(checkedListBoxCourse.Items.IndexOf(elem), true); + } + } + textBoxName.Text = discipline.Name; + textBoxDescription.Text = discipline.Description; + _disciplineId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public DisciplineForm(IDisciplineRepository disciplineRepository) + { + InitializeComponent(); + + _disciplineRepository = disciplineRepository ?? throw new ArgumentNullException(nameof(disciplineRepository)); + + foreach (var elem in Enum.GetValues(typeof(Course))) + { + checkedListBoxCourse.Items.Add(elem); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxName.Text) || + string.IsNullOrWhiteSpace(textBoxDescription.Text) || + checkedListBoxCourse.CheckedItems.Count == 0) + { + throw new Exception("Имеются незаполненные поля"); + } + + if (_disciplineId.HasValue) + { + _disciplineRepository.UpdateDiscipline(CreateDiscipline(_disciplineId.Value)); + } + else + { + _disciplineRepository.AddDiscipline(CreateDiscipline(0)); + } + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Discipline CreateDiscipline(int id) + { + Course course = Course.None; + foreach (var elem in checkedListBoxCourse.CheckedItems) + { + course |= (Course)elem; + } + return Discipline.Create(id, textBoxName.Text, textBoxDescription.Text, course); + } +} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormDisciplineEdit.resx b/ProjectSession/ProjectSession/Forms/DisciplineForm.resx similarity index 100% rename from ProjectSession/ProjectSession/Forms/FormDisciplineEdit.resx rename to ProjectSession/ProjectSession/Forms/DisciplineForm.resx diff --git a/ProjectSession/ProjectSession/Forms/DisciplineListForm.Designer.cs b/ProjectSession/ProjectSession/Forms/DisciplineListForm.Designer.cs new file mode 100644 index 0000000..6bd6715 --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/DisciplineListForm.Designer.cs @@ -0,0 +1,132 @@ +namespace ProjectSession.Forms +{ + partial class DisciplineListForm + { + /// + /// 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() + { + panel1 = new Panel(); + ButtonDel = new Button(); + ButtonUpd = new Button(); + ButtonAdd = new Button(); + dataGridViewDisciplines = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewDisciplines).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(ButtonDel); + panel1.Controls.Add(ButtonUpd); + panel1.Controls.Add(ButtonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(887, 0); + panel1.Margin = new Padding(3, 4, 3, 4); + panel1.Name = "panel1"; + panel1.Size = new Size(180, 572); + panel1.TabIndex = 0; + // + // ButtonDel + // + ButtonDel.BackgroundImage = Properties.Resources.delete_icon; + ButtonDel.BackgroundImageLayout = ImageLayout.Stretch; + ButtonDel.Location = new Point(18, 171); + ButtonDel.Margin = new Padding(3, 4, 3, 4); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(150, 150); + ButtonDel.TabIndex = 4; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; + // + // ButtonUpd + // + ButtonUpd.BackgroundImage = Properties.Resources.edit_icon; + ButtonUpd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonUpd.Location = new Point(16, 329); + ButtonUpd.Margin = new Padding(3, 4, 3, 4); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(150, 150); + ButtonUpd.TabIndex = 3; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // ButtonAdd + // + ButtonAdd.BackgroundImage = Properties.Resources.add_icon; + ButtonAdd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonAdd.Location = new Point(16, 13); + ButtonAdd.Margin = new Padding(3, 4, 3, 4); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(150, 150); + ButtonAdd.TabIndex = 2; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // dataGridViewDisciplines + // + dataGridViewDisciplines.AllowUserToAddRows = false; + dataGridViewDisciplines.AllowUserToDeleteRows = false; + dataGridViewDisciplines.AllowUserToResizeColumns = false; + dataGridViewDisciplines.AllowUserToResizeRows = false; + dataGridViewDisciplines.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewDisciplines.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewDisciplines.Dock = DockStyle.Fill; + dataGridViewDisciplines.Location = new Point(0, 0); + dataGridViewDisciplines.Margin = new Padding(3, 4, 3, 4); + dataGridViewDisciplines.MultiSelect = false; + dataGridViewDisciplines.Name = "dataGridViewDisciplines"; + dataGridViewDisciplines.ReadOnly = true; + dataGridViewDisciplines.RowHeadersVisible = false; + dataGridViewDisciplines.RowHeadersWidth = 51; + dataGridViewDisciplines.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewDisciplines.Size = new Size(887, 572); + dataGridViewDisciplines.TabIndex = 3; + // + // DisciplineListForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1067, 572); + Controls.Add(dataGridViewDisciplines); + Controls.Add(panel1); + Margin = new Padding(3, 4, 3, 4); + Name = "DisciplineListForm"; + Text = "Дисциплины"; + Load += DisciplineListForm_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewDisciplines).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button ButtonAdd; + private Button ButtonUpd; + private Button ButtonDel; + private DataGridView dataGridViewDisciplines; + } +} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/DisciplineListForm.cs b/ProjectSession/ProjectSession/Forms/DisciplineListForm.cs new file mode 100644 index 0000000..3999186 --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/DisciplineListForm.cs @@ -0,0 +1,107 @@ +using ProjectSession.Repositories; +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; +using Unity; + +namespace ProjectSession.Forms; + +public partial class DisciplineListForm : Form +{ + + private readonly IUnityContainer _container; + private readonly IDisciplineRepository _disciplineRepository; + + public DisciplineListForm(IUnityContainer container, IDisciplineRepository disciplineRepository) + { + InitializeComponent(); + + _container = container ?? throw new ArgumentNullException(nameof(container)); + _disciplineRepository = disciplineRepository ?? throw new ArgumentNullException(nameof(disciplineRepository)); + } + + private void DisciplineListForm_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _disciplineRepository.DeleteDiscipline(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewDisciplines.DataSource = _disciplineRepository.GetAllDisciplines(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewDisciplines.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridViewDisciplines.SelectedRows[0].Cells["ID"].Value); + return true; + } +} diff --git a/ProjectSession/ProjectSession/Forms/FormStudent.resx b/ProjectSession/ProjectSession/Forms/DisciplineListForm.resx similarity index 100% rename from ProjectSession/ProjectSession/Forms/FormStudent.resx rename to ProjectSession/ProjectSession/Forms/DisciplineListForm.resx diff --git a/ProjectSession/ProjectSession/Forms/FormDiscipline.Designer.cs b/ProjectSession/ProjectSession/Forms/FormDiscipline.Designer.cs deleted file mode 100644 index 558f6fd..0000000 --- a/ProjectSession/ProjectSession/Forms/FormDiscipline.Designer.cs +++ /dev/null @@ -1,128 +0,0 @@ -namespace ProjectSession.Forms -{ - partial class FormDiscipline - { - /// - /// 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() - { - dataGridViewDisciplines = new DataGridView(); - buttonAdd = new Button(); - buttonEdit = new Button(); - buttonDelete = new Button(); - panelButtons = new Panel(); - ((System.ComponentModel.ISupportInitialize)dataGridViewDisciplines).BeginInit(); - panelButtons.SuspendLayout(); - SuspendLayout(); - // - // dataGridViewDisciplines - // - dataGridViewDisciplines.AllowUserToAddRows = false; - dataGridViewDisciplines.AllowUserToDeleteRows = false; - dataGridViewDisciplines.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridViewDisciplines.Dock = DockStyle.Fill; - dataGridViewDisciplines.Location = new Point(0, 0); - dataGridViewDisciplines.Margin = new Padding(3, 4, 3, 4); - dataGridViewDisciplines.Name = "dataGridViewDisciplines"; - dataGridViewDisciplines.ReadOnly = true; - dataGridViewDisciplines.RowHeadersVisible = false; - dataGridViewDisciplines.RowHeadersWidth = 51; - dataGridViewDisciplines.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridViewDisciplines.Size = new Size(732, 533); - dataGridViewDisciplines.TabIndex = 0; - // - // buttonAdd - // - buttonAdd.BackgroundImage = Properties.Resources.add_icon; - buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; - buttonAdd.Location = new Point(44, 13); - buttonAdd.Margin = new Padding(3, 4, 3, 4); - buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(100, 100); - buttonAdd.TabIndex = 1; - buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += buttonAdd_Click; - // - // buttonEdit - // - buttonEdit.BackgroundImage = Properties.Resources.edit_icon; - buttonEdit.BackgroundImageLayout = ImageLayout.Stretch; - buttonEdit.Location = new Point(44, 229); - buttonEdit.Margin = new Padding(3, 4, 3, 4); - buttonEdit.Name = "buttonEdit"; - buttonEdit.Size = new Size(100, 100); - buttonEdit.TabIndex = 2; - buttonEdit.UseVisualStyleBackColor = true; - buttonEdit.Click += buttonEdit_Click; - // - // buttonDelete - // - buttonDelete.BackgroundImage = Properties.Resources.delete_icon; - buttonDelete.BackgroundImageLayout = ImageLayout.Stretch; - buttonDelete.Location = new Point(44, 121); - buttonDelete.Margin = new Padding(3, 4, 3, 4); - buttonDelete.Name = "buttonDelete"; - buttonDelete.Size = new Size(100, 100); - buttonDelete.TabIndex = 3; - buttonDelete.UseVisualStyleBackColor = true; - buttonDelete.Click += buttonDelete_Click; - // - // panelButtons - // - panelButtons.Controls.Add(buttonDelete); - panelButtons.Controls.Add(buttonEdit); - panelButtons.Controls.Add(buttonAdd); - panelButtons.Dock = DockStyle.Right; - panelButtons.Location = new Point(732, 0); - panelButtons.Margin = new Padding(3, 4, 3, 4); - panelButtons.Name = "panelButtons"; - panelButtons.Size = new Size(182, 533); - panelButtons.TabIndex = 4; - // - // FormDiscipline - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(914, 533); - Controls.Add(dataGridViewDisciplines); - Controls.Add(panelButtons); - Margin = new Padding(3, 4, 3, 4); - Name = "FormDiscipline"; - Text = "Дисциплины"; - Load += FormDiscipline_Load; - ((System.ComponentModel.ISupportInitialize)dataGridViewDisciplines).EndInit(); - panelButtons.ResumeLayout(false); - ResumeLayout(false); - } - - #endregion - - private DataGridView dataGridViewDisciplines; - private Button buttonAdd; - private Button buttonEdit; - private Button buttonDelete; - private Panel panelButtons; - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormDiscipline.cs b/ProjectSession/ProjectSession/Forms/FormDiscipline.cs deleted file mode 100644 index c2e03cf..0000000 --- a/ProjectSession/ProjectSession/Forms/FormDiscipline.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Windows.Forms; -using Unity; -using ProjectSession.Entities; -using ProjectSession.Repositories; - -namespace ProjectSession.Forms -{ - public partial class FormDiscipline : Form - { - private readonly IUnityContainer _container; - private readonly IDisciplineRepository _disciplineRepository; - - public FormDiscipline(IUnityContainer container, IDisciplineRepository disciplineRepository) - { - InitializeComponent(); - _container = container ?? throw new ArgumentNullException(nameof(container)); - _disciplineRepository = disciplineRepository ?? throw new ArgumentNullException(nameof(disciplineRepository)); - } - - private void FormDiscipline_Load(object sender, EventArgs e) - { - try - { - LoadDisciplines(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void LoadDisciplines() - { - dataGridViewDisciplines.DataSource = _disciplineRepository.ReadDisciplines(); - } - - private void buttonAdd_Click(object sender, EventArgs e) - { - try - { - var form = _container.Resolve(); - form.ShowDialog(); - LoadDisciplines(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void buttonEdit_Click(object sender, EventArgs e) - { - if (!TryGetSelectedDisciplineId(out var disciplineId)) - { - return; - } - - try - { - var form = _container.Resolve(); - form.DisciplineId = disciplineId; - form.ShowDialog(); - LoadDisciplines(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при редактировании", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void buttonDelete_Click(object sender, EventArgs e) - { - if (!TryGetSelectedDisciplineId(out var disciplineId)) - { - return; - } - - if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) - { - return; - } - - try - { - _disciplineRepository.DeleteDiscipline(disciplineId); - LoadDisciplines(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private bool TryGetSelectedDisciplineId(out int disciplineId) - { - disciplineId = 0; - - if (dataGridViewDisciplines.SelectedRows.Count < 1) - { - MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - - disciplineId = Convert.ToInt32(dataGridViewDisciplines.SelectedRows[0].Cells["Id"].Value); - return true; - } - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormDisciplineEdit.Designer.cs b/ProjectSession/ProjectSession/Forms/FormDisciplineEdit.Designer.cs deleted file mode 100644 index f8e071a..0000000 --- a/ProjectSession/ProjectSession/Forms/FormDisciplineEdit.Designer.cs +++ /dev/null @@ -1,95 +0,0 @@ -namespace ProjectSession.Forms -{ - partial class FormDisciplineEdit - { - /// - /// 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() - { - labelName = new Label(); - textBoxName = new TextBox(); - buttonSave = new Button(); - buttonCancel = new Button(); - SuspendLayout(); - // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(12, 20); - labelName.Name = "labelName"; - labelName.Size = new Size(62, 15); - labelName.TabIndex = 0; - labelName.Text = "Название:"; - // - // textBoxName - // - textBoxName.Location = new Point(12, 38); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(200, 23); - textBoxName.TabIndex = 1; - // - // buttonSave - // - buttonSave.Location = new Point(12, 70); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(75, 23); - buttonSave.TabIndex = 2; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += buttonSave_Click; - // - // buttonCancel - // - buttonCancel.Location = new Point(93, 70); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(75, 23); - buttonCancel.TabIndex = 3; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += buttonCancel_Click; - // - // FormDisciplineEdit - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(224, 105); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(textBoxName); - Controls.Add(labelName); - Name = "FormDisciplineEdit"; - Text = "Редактирование дисциплины"; - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private Label labelName; - private TextBox textBoxName; - private Button buttonSave; - private Button buttonCancel; - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormDisciplineEdit.cs b/ProjectSession/ProjectSession/Forms/FormDisciplineEdit.cs deleted file mode 100644 index 13676d2..0000000 --- a/ProjectSession/ProjectSession/Forms/FormDisciplineEdit.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Windows.Forms; -using ProjectSession.Entities; -using ProjectSession.Repositories; -using YourNamespace.Entities; - -namespace ProjectSession.Forms -{ - public partial class FormDisciplineEdit : Form - { - private readonly IDisciplineRepository _disciplineRepository; - private int? _disciplineId; - - public int? DisciplineId - { - get => _disciplineId; - set - { - _disciplineId = value; - if (_disciplineId.HasValue) - { - var discipline = _disciplineRepository.ReadDisciplineById(_disciplineId.Value); - textBoxName.Text = discipline.Name; - } - } - } - - public FormDisciplineEdit(IDisciplineRepository disciplineRepository) - { - InitializeComponent(); - _disciplineRepository = disciplineRepository ?? throw new ArgumentNullException(nameof(disciplineRepository)); - } - - private void buttonSave_Click(object sender, EventArgs e) - { - try - { - if (string.IsNullOrWhiteSpace(textBoxName.Text)) - { - throw new Exception("Имеются незаполненные поля"); - } - - var discipline = Discipline.CreateEntity( - _disciplineId ?? 0, - textBoxName.Text - ); - - if (_disciplineId.HasValue) - { - _disciplineRepository.UpdateDiscipline(discipline); - } - else - { - _disciplineRepository.CreateDiscipline(discipline); - } - - Close(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void buttonCancel_Click(object sender, EventArgs e) - { - Close(); - } - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormStatement.Designer.cs b/ProjectSession/ProjectSession/Forms/FormStatement.Designer.cs deleted file mode 100644 index 7eaa415..0000000 --- a/ProjectSession/ProjectSession/Forms/FormStatement.Designer.cs +++ /dev/null @@ -1,121 +0,0 @@ -namespace ProjectSession.Forms -{ - partial class FormStatement - { - /// - /// 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() - { - dataGridViewStatements = new DataGridView(); - buttonAdd = new Button(); - buttonEdit = new Button(); - buttonDelete = new Button(); - panelButtons = new Panel(); - panelButtons.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridViewStatements).BeginInit(); - SuspendLayout(); - // - // dataGridViewStatements - // - dataGridViewStatements.AllowUserToAddRows = false; - dataGridViewStatements.AllowUserToDeleteRows = false; - dataGridViewStatements.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridViewStatements.Dock = DockStyle.Fill; - dataGridViewStatements.Location = new Point(0, 0); - dataGridViewStatements.Name = "dataGridViewStatements"; - dataGridViewStatements.ReadOnly = true; - dataGridViewStatements.RowHeadersVisible = false; - dataGridViewStatements.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridViewStatements.Size = new Size(718, 400); - dataGridViewStatements.TabIndex = 0; - // - // buttonAdd - // - buttonAdd.BackgroundImage = Properties.Resources.add_icon; - buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; - buttonAdd.Location = new Point(44, 13); - buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(100, 100); - buttonAdd.TabIndex = 1; - buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += buttonAdd_Click; - // - // buttonEdit - // - buttonEdit.BackgroundImage = Properties.Resources.edit_icon; - buttonEdit.BackgroundImageLayout = ImageLayout.Stretch; - buttonEdit.Location = new Point(44, 229); - buttonEdit.Name = "buttonEdit"; - buttonEdit.Size = new Size(100, 100); - buttonEdit.TabIndex = 2; - buttonEdit.UseVisualStyleBackColor = true; - buttonEdit.Click += buttonEdit_Click; - // - // buttonDelete - // - buttonDelete.BackgroundImage = Properties.Resources.delete_icon; - buttonDelete.BackgroundImageLayout = ImageLayout.Stretch; - buttonDelete.Location = new Point(44, 121); - buttonDelete.Name = "buttonDelete"; - buttonDelete.Size = new Size(100, 100); - buttonDelete.TabIndex = 3; - buttonDelete.UseVisualStyleBackColor = true; - buttonDelete.Click += buttonDelete_Click; - // - // panelButtons - // - panelButtons.Controls.Add(buttonDelete); - panelButtons.Controls.Add(buttonEdit); - panelButtons.Controls.Add(buttonAdd); - panelButtons.Dock = DockStyle.Right; - panelButtons.Location = new Point(718, 0); - panelButtons.Name = "panelButtons"; - panelButtons.Size = new Size(182, 400); - panelButtons.TabIndex = 4; - // - // FormStatement - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(900, 400); - Controls.Add(dataGridViewStatements); - Controls.Add(panelButtons); - Name = "FormStatement"; - Text = "Заявления"; - Load += FormStatement_Load; - ((System.ComponentModel.ISupportInitialize)dataGridViewStatements).EndInit(); - panelButtons.ResumeLayout(false); - ResumeLayout(false); - } - - #endregion - - private DataGridView dataGridViewStatements; - private Button buttonAdd; - private Button buttonEdit; - private Button buttonDelete; - private Panel panelButtons; - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormStatement.cs b/ProjectSession/ProjectSession/Forms/FormStatement.cs deleted file mode 100644 index e738a01..0000000 --- a/ProjectSession/ProjectSession/Forms/FormStatement.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Windows.Forms; -using Unity; -using ProjectSession.Entities; -using ProjectSession.Repositories; - -namespace ProjectSession.Forms -{ - public partial class FormStatement : Form - { - private readonly IUnityContainer _container; - private readonly IStatementRepository _statementRepository; - - public FormStatement(IUnityContainer container, IStatementRepository statementRepository) - { - InitializeComponent(); - _container = container ?? throw new ArgumentNullException(nameof(container)); - _statementRepository = statementRepository ?? throw new ArgumentNullException(nameof(statementRepository)); - } - - private void FormStatement_Load(object sender, EventArgs e) - { - try - { - LoadStatements(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void LoadStatements() - { - dataGridViewStatements.DataSource = _statementRepository.ReadStatements(); - } - - private void buttonAdd_Click(object sender, EventArgs e) - { - try - { - var form = _container.Resolve(); - form.ShowDialog(); - LoadStatements(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void buttonEdit_Click(object sender, EventArgs e) - { - if (!TryGetSelectedStatementId(out var statementId)) - { - return; - } - - try - { - var form = _container.Resolve(); - form.StatementId = statementId; - form.ShowDialog(); - LoadStatements(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при редактировании", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void buttonDelete_Click(object sender, EventArgs e) - { - if (!TryGetSelectedStatementId(out var statementId)) - { - return; - } - - if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) - { - return; - } - - try - { - _statementRepository.DeleteStatement(statementId); - LoadStatements(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private bool TryGetSelectedStatementId(out int statementId) - { - statementId = 0; - - if (dataGridViewStatements.SelectedRows.Count < 1) - { - MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - - statementId = Convert.ToInt32(dataGridViewStatements.SelectedRows[0].Cells["Id"].Value); - return true; - } - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormStatementEdit.Designer.cs b/ProjectSession/ProjectSession/Forms/FormStatementEdit.Designer.cs deleted file mode 100644 index 12ad8a5..0000000 --- a/ProjectSession/ProjectSession/Forms/FormStatementEdit.Designer.cs +++ /dev/null @@ -1,191 +0,0 @@ -namespace ProjectSession.Forms -{ - partial class FormStatementEdit - { - /// - /// 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() - { - labelStudentID = new Label(); - textBoxStudentID = new TextBox(); - labelTeacherID = new Label(); - textBoxTeacherID = new TextBox(); - labelDisciplineID = new Label(); - textBoxDisciplineID = new TextBox(); - labelEstimation = new Label(); - textBoxEstimation = new TextBox(); - labelDate = new Label(); - dateTimePickerDate = new DateTimePicker(); - buttonSave = new Button(); - buttonCancel = new Button(); - SuspendLayout(); - // - // labelStudentID - // - labelStudentID.AutoSize = true; - labelStudentID.Location = new Point(14, 27); - labelStudentID.Name = "labelStudentID"; - labelStudentID.Size = new Size(65, 20); - labelStudentID.TabIndex = 0; - labelStudentID.Text = "Студент:"; - // - // textBoxStudentID - // - textBoxStudentID.Location = new Point(14, 51); - textBoxStudentID.Margin = new Padding(3, 4, 3, 4); - textBoxStudentID.Name = "textBoxStudentID"; - textBoxStudentID.Size = new Size(228, 27); - textBoxStudentID.TabIndex = 1; - // - // labelTeacherID - // - labelTeacherID.AutoSize = true; - labelTeacherID.Location = new Point(14, 93); - labelTeacherID.Name = "labelTeacherID"; - labelTeacherID.Size = new Size(121, 20); - labelTeacherID.TabIndex = 2; - labelTeacherID.Text = "Преподователь:"; - // - // textBoxTeacherID - // - textBoxTeacherID.Location = new Point(14, 117); - textBoxTeacherID.Margin = new Padding(3, 4, 3, 4); - textBoxTeacherID.Name = "textBoxTeacherID"; - textBoxTeacherID.Size = new Size(228, 27); - textBoxTeacherID.TabIndex = 3; - // - // labelDisciplineID - // - labelDisciplineID.AutoSize = true; - labelDisciplineID.Location = new Point(14, 160); - labelDisciplineID.Name = "labelDisciplineID"; - labelDisciplineID.Size = new Size(73, 20); - labelDisciplineID.TabIndex = 4; - labelDisciplineID.Text = "Предмет:"; - // - // textBoxDisciplineID - // - textBoxDisciplineID.Location = new Point(14, 184); - textBoxDisciplineID.Margin = new Padding(3, 4, 3, 4); - textBoxDisciplineID.Name = "textBoxDisciplineID"; - textBoxDisciplineID.Size = new Size(228, 27); - textBoxDisciplineID.TabIndex = 5; - // - // labelEstimation - // - labelEstimation.AutoSize = true; - labelEstimation.Location = new Point(14, 227); - labelEstimation.Name = "labelEstimation"; - labelEstimation.Size = new Size(64, 20); - labelEstimation.TabIndex = 6; - labelEstimation.Text = "Оценка:"; - // - // textBoxEstimation - // - textBoxEstimation.Location = new Point(14, 251); - textBoxEstimation.Margin = new Padding(3, 4, 3, 4); - textBoxEstimation.Name = "textBoxEstimation"; - textBoxEstimation.Size = new Size(228, 27); - textBoxEstimation.TabIndex = 7; - // - // labelDate - // - labelDate.AutoSize = true; - labelDate.Location = new Point(14, 293); - labelDate.Name = "labelDate"; - labelDate.Size = new Size(44, 20); - labelDate.TabIndex = 8; - labelDate.Text = "Дата:"; - // - // dateTimePickerDate - // - dateTimePickerDate.Location = new Point(14, 317); - dateTimePickerDate.Margin = new Padding(3, 4, 3, 4); - dateTimePickerDate.Name = "dateTimePickerDate"; - dateTimePickerDate.Size = new Size(228, 27); - dateTimePickerDate.TabIndex = 9; - // - // buttonSave - // - buttonSave.Location = new Point(14, 360); - buttonSave.Margin = new Padding(3, 4, 3, 4); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(86, 31); - buttonSave.TabIndex = 10; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += buttonSave_Click; - // - // buttonCancel - // - buttonCancel.Location = new Point(106, 360); - buttonCancel.Margin = new Padding(3, 4, 3, 4); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(86, 31); - buttonCancel.TabIndex = 11; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += buttonCancel_Click; - // - // FormStatementEdit - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(256, 407); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(dateTimePickerDate); - Controls.Add(labelDate); - Controls.Add(textBoxEstimation); - Controls.Add(labelEstimation); - Controls.Add(textBoxDisciplineID); - Controls.Add(labelDisciplineID); - Controls.Add(textBoxTeacherID); - Controls.Add(labelTeacherID); - Controls.Add(textBoxStudentID); - Controls.Add(labelStudentID); - Margin = new Padding(3, 4, 3, 4); - Name = "FormStatementEdit"; - Text = "Редактирование заявления"; - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private Label labelStudentID; - private TextBox textBoxStudentID; - private Label labelTeacherID; - private TextBox textBoxTeacherID; - private Label labelDisciplineID; - private TextBox textBoxDisciplineID; - private Label labelEstimation; - private TextBox textBoxEstimation; - private Label labelDate; - private DateTimePicker dateTimePickerDate; - private Button buttonSave; - private Button buttonCancel; - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormStatementEdit.cs b/ProjectSession/ProjectSession/Forms/FormStatementEdit.cs deleted file mode 100644 index 370af65..0000000 --- a/ProjectSession/ProjectSession/Forms/FormStatementEdit.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Windows.Forms; -using ProjectSession.Entities; -using ProjectSession.Repositories; - -namespace ProjectSession.Forms -{ - public partial class FormStatementEdit : Form - { - private readonly IStatementRepository _statementRepository; - private int? _statementId; - - public int? StatementId - { - get => _statementId; - set - { - _statementId = value; - if (_statementId.HasValue) - { - var statement = _statementRepository.ReadStatementById(_statementId.Value); - textBoxStudentID.Text = statement.StudentID.ToString(); - textBoxTeacherID.Text = statement.TeacherID.ToString(); - textBoxDisciplineID.Text = statement.DisciplineID.ToString(); - textBoxEstimation.Text = statement.Estimation.ToString(); - dateTimePickerDate.Value = statement.Date; - } - } - } - - public FormStatementEdit(IStatementRepository statementRepository) - { - InitializeComponent(); - _statementRepository = statementRepository ?? throw new ArgumentNullException(nameof(statementRepository)); - } - - private void buttonSave_Click(object sender, EventArgs e) - { - try - { - if (string.IsNullOrWhiteSpace(textBoxStudentID.Text) || - string.IsNullOrWhiteSpace(textBoxTeacherID.Text) || - string.IsNullOrWhiteSpace(textBoxDisciplineID.Text) || - string.IsNullOrWhiteSpace(textBoxEstimation.Text)) - { - throw new Exception("Имеются незаполненные поля"); - } - - var statement = Statement.CreateEntity( - _statementId ?? 0, - int.Parse(textBoxStudentID.Text), - int.Parse(textBoxTeacherID.Text), - int.Parse(textBoxDisciplineID.Text), - int.Parse(textBoxEstimation.Text), - dateTimePickerDate.Value - ); - - if (_statementId.HasValue) - { - _statementRepository.UpdateStatement(statement); - } - else - { - _statementRepository.CreateStatement(statement); - } - - Close(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void buttonCancel_Click(object sender, EventArgs e) - { - Close(); - } - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormStudent.Designer.cs b/ProjectSession/ProjectSession/Forms/FormStudent.Designer.cs deleted file mode 100644 index b36576c..0000000 --- a/ProjectSession/ProjectSession/Forms/FormStudent.Designer.cs +++ /dev/null @@ -1,128 +0,0 @@ -namespace ProjectSession.Forms -{ - partial class FormStudent - { - /// - /// 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() - { - dataGridViewStudents = new DataGridView(); - buttonAdd = new Button(); - buttonEdit = new Button(); - buttonDelete = new Button(); - panelButtons = new Panel(); - ((System.ComponentModel.ISupportInitialize)dataGridViewStudents).BeginInit(); - panelButtons.SuspendLayout(); - SuspendLayout(); - // - // dataGridViewStudents - // - dataGridViewStudents.AllowUserToAddRows = false; - dataGridViewStudents.AllowUserToDeleteRows = false; - dataGridViewStudents.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridViewStudents.Dock = DockStyle.Fill; - dataGridViewStudents.Location = new Point(0, 0); - dataGridViewStudents.Margin = new Padding(3, 4, 3, 4); - dataGridViewStudents.Name = "dataGridViewStudents"; - dataGridViewStudents.ReadOnly = true; - dataGridViewStudents.RowHeadersVisible = false; - dataGridViewStudents.RowHeadersWidth = 51; - dataGridViewStudents.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridViewStudents.Size = new Size(732, 533); - dataGridViewStudents.TabIndex = 0; - // - // buttonAdd - // - buttonAdd.BackgroundImage = Properties.Resources.add_icon; - buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; - buttonAdd.Location = new Point(44, 13); - buttonAdd.Margin = new Padding(3, 4, 3, 4); - buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(100, 100); - buttonAdd.TabIndex = 1; - buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += buttonAdd_Click; - // - // buttonEdit - // - buttonEdit.BackgroundImage = Properties.Resources.edit_icon; - buttonEdit.BackgroundImageLayout = ImageLayout.Stretch; - buttonEdit.Location = new Point(44, 229); - buttonEdit.Margin = new Padding(3, 4, 3, 4); - buttonEdit.Name = "buttonEdit"; - buttonEdit.Size = new Size(100, 100); - buttonEdit.TabIndex = 2; - buttonEdit.UseVisualStyleBackColor = true; - buttonEdit.Click += buttonEdit_Click; - // - // buttonDelete - // - buttonDelete.BackgroundImage = Properties.Resources.delete_icon; - buttonDelete.BackgroundImageLayout = ImageLayout.Stretch; - buttonDelete.Location = new Point(44, 121); - buttonDelete.Margin = new Padding(3, 4, 3, 4); - buttonDelete.Name = "buttonDelete"; - buttonDelete.Size = new Size(100, 100); - buttonDelete.TabIndex = 3; - buttonDelete.UseVisualStyleBackColor = true; - buttonDelete.Click += buttonDelete_Click; - // - // panelButtons - // - panelButtons.Controls.Add(buttonDelete); - panelButtons.Controls.Add(buttonEdit); - panelButtons.Controls.Add(buttonAdd); - panelButtons.Dock = DockStyle.Right; - panelButtons.Location = new Point(732, 0); - panelButtons.Margin = new Padding(3, 4, 3, 4); - panelButtons.Name = "panelButtons"; - panelButtons.Size = new Size(182, 533); - panelButtons.TabIndex = 4; - // - // FormStudent - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(914, 533); - Controls.Add(dataGridViewStudents); - Controls.Add(panelButtons); - Margin = new Padding(3, 4, 3, 4); - Name = "FormStudent"; - Text = "Студенты"; - Load += FormStudent_Load; - ((System.ComponentModel.ISupportInitialize)dataGridViewStudents).EndInit(); - panelButtons.ResumeLayout(false); - ResumeLayout(false); - } - - #endregion - - private DataGridView dataGridViewStudents; - private Button buttonAdd; - private Button buttonEdit; - private Button buttonDelete; - private Panel panelButtons; - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormStudent.cs b/ProjectSession/ProjectSession/Forms/FormStudent.cs deleted file mode 100644 index 5f17484..0000000 --- a/ProjectSession/ProjectSession/Forms/FormStudent.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Windows.Forms; -using Unity; -using ProjectSession.Entities; -using ProjectSession.Repositories; - -namespace ProjectSession.Forms -{ - public partial class FormStudent : Form - { - private readonly IUnityContainer _container; - private readonly IStudentRepository _studentRepository; - - public FormStudent(IUnityContainer container, IStudentRepository studentRepository) - { - InitializeComponent(); - _container = container ?? throw new ArgumentNullException(nameof(container)); - _studentRepository = studentRepository ?? throw new ArgumentNullException(nameof(studentRepository)); - } - - private void FormStudent_Load(object sender, EventArgs e) - { - try - { - LoadStudents(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void LoadStudents() - { - dataGridViewStudents.DataSource = _studentRepository.ReadStudents(); - } - - private void buttonAdd_Click(object sender, EventArgs e) - { - try - { - var form = _container.Resolve(); - form.ShowDialog(); - LoadStudents(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void buttonEdit_Click(object sender, EventArgs e) - { - if (!TryGetSelectedStudentId(out var studentId)) - { - return; - } - - try - { - var form = _container.Resolve(); - form.StudentId = studentId; - form.ShowDialog(); - LoadStudents(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при редактировании", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void buttonDelete_Click(object sender, EventArgs e) - { - if (!TryGetSelectedStudentId(out var studentId)) - { - return; - } - - if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) - { - return; - } - - try - { - _studentRepository.DeleteStudent(studentId); - LoadStudents(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private bool TryGetSelectedStudentId(out int studentId) - { - studentId = 0; - - if (dataGridViewStudents.SelectedRows.Count < 1) - { - MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - - studentId = Convert.ToInt32(dataGridViewStudents.SelectedRows[0].Cells["Id"].Value); - return true; - } - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormStudentEdit.Designer.cs b/ProjectSession/ProjectSession/Forms/FormStudentEdit.Designer.cs deleted file mode 100644 index d4a6366..0000000 --- a/ProjectSession/ProjectSession/Forms/FormStudentEdit.Designer.cs +++ /dev/null @@ -1,136 +0,0 @@ -namespace ProjectSession.Forms -{ - partial class FormStudentEdit - { - /// - /// 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() - { - labelName = new Label(); - textBoxName = new TextBox(); - labelFamilyStatus = new Label(); - textBoxFamilyStatus = new TextBox(); - checkBoxDormitory = new CheckBox(); - buttonSave = new Button(); - buttonCancel = new Button(); - SuspendLayout(); - // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(14, 27); - labelName.Name = "labelName"; - labelName.Size = new Size(45, 20); - labelName.TabIndex = 0; - labelName.Text = "ФИО:"; - // - // textBoxName - // - textBoxName.Location = new Point(14, 51); - textBoxName.Margin = new Padding(3, 4, 3, 4); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(228, 27); - textBoxName.TabIndex = 1; - // - // labelFamilyStatus - // - labelFamilyStatus.AutoSize = true; - labelFamilyStatus.Location = new Point(14, 93); - labelFamilyStatus.Name = "labelFamilyStatus"; - labelFamilyStatus.Size = new Size(131, 20); - labelFamilyStatus.TabIndex = 2; - labelFamilyStatus.Text = "Семейный статус:"; - // - // textBoxFamilyStatus - // - textBoxFamilyStatus.Location = new Point(14, 117); - textBoxFamilyStatus.Margin = new Padding(3, 4, 3, 4); - textBoxFamilyStatus.Name = "textBoxFamilyStatus"; - textBoxFamilyStatus.Size = new Size(228, 27); - textBoxFamilyStatus.TabIndex = 3; - // - // checkBoxDormitory - // - checkBoxDormitory.AutoSize = true; - checkBoxDormitory.Location = new Point(14, 160); - checkBoxDormitory.Margin = new Padding(3, 4, 3, 4); - checkBoxDormitory.Name = "checkBoxDormitory"; - checkBoxDormitory.Size = new Size(208, 24); - checkBoxDormitory.TabIndex = 4; - checkBoxDormitory.Text = "Проживает в общежитии"; - checkBoxDormitory.UseVisualStyleBackColor = true; - // - // buttonSave - // - buttonSave.Location = new Point(14, 200); - buttonSave.Margin = new Padding(3, 4, 3, 4); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(86, 31); - buttonSave.TabIndex = 5; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += buttonSave_Click; - // - // buttonCancel - // - buttonCancel.Location = new Point(106, 200); - buttonCancel.Margin = new Padding(3, 4, 3, 4); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(86, 31); - buttonCancel.TabIndex = 6; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += buttonCancel_Click; - // - // FormStudentEdit - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(256, 247); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(checkBoxDormitory); - Controls.Add(textBoxFamilyStatus); - Controls.Add(labelFamilyStatus); - Controls.Add(textBoxName); - Controls.Add(labelName); - Margin = new Padding(3, 4, 3, 4); - Name = "FormStudentEdit"; - Text = "Редактирование студента"; - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private Label labelName; - private TextBox textBoxName; - private Label labelFamilyStatus; - private TextBox textBoxFamilyStatus; - private CheckBox checkBoxDormitory; - private Button buttonSave; - private Button buttonCancel; - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormStudentEdit.cs b/ProjectSession/ProjectSession/Forms/FormStudentEdit.cs deleted file mode 100644 index 238ccc5..0000000 --- a/ProjectSession/ProjectSession/Forms/FormStudentEdit.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using System.Windows.Forms; -using ProjectSession.Entities; -using ProjectSession.Repositories; - -namespace ProjectSession.Forms -{ - public partial class FormStudentEdit : Form - { - private readonly IStudentRepository _studentRepository; - private int? _studentId; - - public int? StudentId - { - get => _studentId; - set - { - _studentId = value; - if (_studentId.HasValue) - { - var student = _studentRepository.ReadStudentById(_studentId.Value); - textBoxName.Text = student.Name; - textBoxFamilyStatus.Text = student.FamilyStatus; - checkBoxDormitory.Checked = student.Dormitory; - } - } - } - - public FormStudentEdit(IStudentRepository studentRepository) - { - InitializeComponent(); - _studentRepository = studentRepository ?? throw new ArgumentNullException(nameof(studentRepository)); - } - - private void buttonSave_Click(object sender, EventArgs e) - { - try - { - if (string.IsNullOrWhiteSpace(textBoxName.Text) || string.IsNullOrWhiteSpace(textBoxFamilyStatus.Text)) - { - throw new Exception("Имеются незаполненные поля"); - } - - var student = Student.CreateEntity( - _studentId ?? 0, - textBoxName.Text, - textBoxFamilyStatus.Text, - checkBoxDormitory.Checked, - Entities.Enums.StudentStatus.Active - ); - - if (_studentId.HasValue) - { - _studentRepository.UpdateStudent(student); - } - else - { - _studentRepository.CreateStudent(student); - } - - Close(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void buttonCancel_Click(object sender, EventArgs e) - { - Close(); - } - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormSubmission.Designer.cs b/ProjectSession/ProjectSession/Forms/FormSubmission.Designer.cs deleted file mode 100644 index 604039b..0000000 --- a/ProjectSession/ProjectSession/Forms/FormSubmission.Designer.cs +++ /dev/null @@ -1,128 +0,0 @@ -namespace ProjectSession.Forms -{ - partial class FormSubmission - { - /// - /// 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() - { - dataGridViewSubmissions = new DataGridView(); - buttonAdd = new Button(); - buttonEdit = new Button(); - buttonDelete = new Button(); - panelButtons = new Panel(); - ((System.ComponentModel.ISupportInitialize)dataGridViewSubmissions).BeginInit(); - panelButtons.SuspendLayout(); - SuspendLayout(); - // - // dataGridViewSubmissions - // - dataGridViewSubmissions.AllowUserToAddRows = false; - dataGridViewSubmissions.AllowUserToDeleteRows = false; - dataGridViewSubmissions.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridViewSubmissions.Dock = DockStyle.Fill; - dataGridViewSubmissions.Location = new Point(0, 0); - dataGridViewSubmissions.Margin = new Padding(3, 4, 3, 4); - dataGridViewSubmissions.Name = "dataGridViewSubmissions"; - dataGridViewSubmissions.ReadOnly = true; - dataGridViewSubmissions.RowHeadersVisible = false; - dataGridViewSubmissions.RowHeadersWidth = 51; - dataGridViewSubmissions.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridViewSubmissions.Size = new Size(732, 533); - dataGridViewSubmissions.TabIndex = 0; - // - // buttonAdd - // - buttonAdd.BackgroundImage = Properties.Resources.add_icon; - buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; - buttonAdd.Location = new Point(44, 13); - buttonAdd.Margin = new Padding(3, 4, 3, 4); - buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(100, 100); - buttonAdd.TabIndex = 1; - buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += buttonAdd_Click; - // - // buttonEdit - // - buttonEdit.BackgroundImage = Properties.Resources.edit_icon; - buttonEdit.BackgroundImageLayout = ImageLayout.Stretch; - buttonEdit.Location = new Point(44, 229); - buttonEdit.Margin = new Padding(3, 4, 3, 4); - buttonEdit.Name = "buttonEdit"; - buttonEdit.Size = new Size(100, 100); - buttonEdit.TabIndex = 2; - buttonEdit.UseVisualStyleBackColor = true; - buttonEdit.Click += buttonEdit_Click; - // - // buttonDelete - // - buttonDelete.BackgroundImage = Properties.Resources.delete_icon; - buttonDelete.BackgroundImageLayout = ImageLayout.Stretch; - buttonDelete.Location = new Point(44, 121); - buttonDelete.Margin = new Padding(3, 4, 3, 4); - buttonDelete.Name = "buttonDelete"; - buttonDelete.Size = new Size(100, 100); - buttonDelete.TabIndex = 3; - buttonDelete.UseVisualStyleBackColor = true; - buttonDelete.Click += buttonDelete_Click; - // - // panelButtons - // - panelButtons.Controls.Add(buttonDelete); - panelButtons.Controls.Add(buttonEdit); - panelButtons.Controls.Add(buttonAdd); - panelButtons.Dock = DockStyle.Right; - panelButtons.Location = new Point(732, 0); - panelButtons.Margin = new Padding(3, 4, 3, 4); - panelButtons.Name = "panelButtons"; - panelButtons.Size = new Size(182, 533); - panelButtons.TabIndex = 4; - // - // FormSubmission - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(914, 533); - Controls.Add(dataGridViewSubmissions); - Controls.Add(panelButtons); - Margin = new Padding(3, 4, 3, 4); - Name = "FormSubmission"; - Text = "Подачи"; - Load += FormSubmission_Load; - ((System.ComponentModel.ISupportInitialize)dataGridViewSubmissions).EndInit(); - panelButtons.ResumeLayout(false); - ResumeLayout(false); - } - - #endregion - - private DataGridView dataGridViewSubmissions; - private Button buttonAdd; - private Button buttonEdit; - private Button buttonDelete; - private Panel panelButtons; - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormSubmission.cs b/ProjectSession/ProjectSession/Forms/FormSubmission.cs deleted file mode 100644 index c783fe0..0000000 --- a/ProjectSession/ProjectSession/Forms/FormSubmission.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Windows.Forms; -using Unity; -using ProjectSession.Entities; -using ProjectSession.Repositories; - -namespace ProjectSession.Forms -{ - public partial class FormSubmission : Form - { - private readonly IUnityContainer _container; - private readonly ISubmissionRepository _submissionRepository; - - public FormSubmission(IUnityContainer container, ISubmissionRepository submissionRepository) - { - InitializeComponent(); - _container = container ?? throw new ArgumentNullException(nameof(container)); - _submissionRepository = submissionRepository ?? throw new ArgumentNullException(nameof(submissionRepository)); - } - - private void FormSubmission_Load(object sender, EventArgs e) - { - try - { - LoadSubmissions(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void LoadSubmissions() - { - dataGridViewSubmissions.DataSource = _submissionRepository.ReadSubmissions(); - } - - private void buttonAdd_Click(object sender, EventArgs e) - { - try - { - var form = _container.Resolve(); - form.ShowDialog(); - LoadSubmissions(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void buttonEdit_Click(object sender, EventArgs e) - { - if (!TryGetSelectedSubmissionId(out var submissionId)) - { - return; - } - - try - { - var form = _container.Resolve(); - form.SubmissionId = submissionId; - form.ShowDialog(); - LoadSubmissions(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при редактировании", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void buttonDelete_Click(object sender, EventArgs e) - { - if (!TryGetSelectedSubmissionId(out var submissionId)) - { - return; - } - - if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) - { - return; - } - - try - { - _submissionRepository.DeleteSubmission(submissionId); - LoadSubmissions(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private bool TryGetSelectedSubmissionId(out int submissionId) - { - submissionId = 0; - - if (dataGridViewSubmissions.SelectedRows.Count < 1) - { - MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - - submissionId = Convert.ToInt32(dataGridViewSubmissions.SelectedRows[0].Cells["Id"].Value); - return true; - } - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormSubmissionEdit.Designer.cs b/ProjectSession/ProjectSession/Forms/FormSubmissionEdit.Designer.cs deleted file mode 100644 index 51c1f32..0000000 --- a/ProjectSession/ProjectSession/Forms/FormSubmissionEdit.Designer.cs +++ /dev/null @@ -1,123 +0,0 @@ -namespace ProjectSession.Forms -{ - partial class FormSubmissionEdit - { - /// - /// 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() - { - labelDisciplineID = new Label(); - textBoxDisciplineID = new TextBox(); - labelDate = new Label(); - dateTimePickerDate = new DateTimePicker(); - buttonSave = new Button(); - buttonCancel = new Button(); - SuspendLayout(); - // - // labelDisciplineID - // - labelDisciplineID.AutoSize = true; - labelDisciplineID.Location = new Point(14, 27); - labelDisciplineID.Name = "labelDisciplineID"; - labelDisciplineID.Size = new Size(73, 20); - labelDisciplineID.TabIndex = 0; - labelDisciplineID.Text = "Предмет:"; - labelDisciplineID.Click += labelDisciplineID_Click; - // - // textBoxDisciplineID - // - textBoxDisciplineID.Location = new Point(14, 51); - textBoxDisciplineID.Margin = new Padding(3, 4, 3, 4); - textBoxDisciplineID.Name = "textBoxDisciplineID"; - textBoxDisciplineID.Size = new Size(228, 27); - textBoxDisciplineID.TabIndex = 1; - // - // labelDate - // - labelDate.AutoSize = true; - labelDate.Location = new Point(14, 93); - labelDate.Name = "labelDate"; - labelDate.Size = new Size(44, 20); - labelDate.TabIndex = 2; - labelDate.Text = "Дата:"; - // - // dateTimePickerDate - // - dateTimePickerDate.Location = new Point(14, 117); - dateTimePickerDate.Margin = new Padding(3, 4, 3, 4); - dateTimePickerDate.Name = "dateTimePickerDate"; - dateTimePickerDate.Size = new Size(228, 27); - dateTimePickerDate.TabIndex = 3; - // - // buttonSave - // - buttonSave.Location = new Point(14, 160); - buttonSave.Margin = new Padding(3, 4, 3, 4); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(86, 31); - buttonSave.TabIndex = 4; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += buttonSave_Click; - // - // buttonCancel - // - buttonCancel.Location = new Point(106, 160); - buttonCancel.Margin = new Padding(3, 4, 3, 4); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(86, 31); - buttonCancel.TabIndex = 5; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += buttonCancel_Click; - // - // FormSubmissionEdit - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(255, 202); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(dateTimePickerDate); - Controls.Add(labelDate); - Controls.Add(textBoxDisciplineID); - Controls.Add(labelDisciplineID); - Margin = new Padding(3, 4, 3, 4); - Name = "FormSubmissionEdit"; - Text = "Редактирование сдачи"; - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private Label labelDisciplineID; - private TextBox textBoxDisciplineID; - private Label labelDate; - private DateTimePicker dateTimePickerDate; - private Button buttonSave; - private Button buttonCancel; - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormSubmissionEdit.cs b/ProjectSession/ProjectSession/Forms/FormSubmissionEdit.cs deleted file mode 100644 index b8b2bed..0000000 --- a/ProjectSession/ProjectSession/Forms/FormSubmissionEdit.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.Windows.Forms; -using ProjectSession.Entities; -using ProjectSession.Repositories; -using static ProjectSession.Entities.Sumbission; - -namespace ProjectSession.Forms -{ - public partial class FormSubmissionEdit : Form - { - private readonly ISubmissionRepository _submissionRepository; - private int? _submissionId; - - public int? SubmissionId - { - get => _submissionId; - set - { - _submissionId = value; - if (_submissionId.HasValue) - { - var submission = _submissionRepository.ReadSubmissionById(_submissionId.Value); - textBoxDisciplineID.Text = submission.DisciplineID.ToString(); - dateTimePickerDate.Value = submission.Date; - } - } - } - - public FormSubmissionEdit(ISubmissionRepository submissionRepository) - { - InitializeComponent(); - _submissionRepository = submissionRepository ?? throw new ArgumentNullException(nameof(submissionRepository)); - } - - private void buttonSave_Click(object sender, EventArgs e) - { - try - { - if (string.IsNullOrWhiteSpace(textBoxDisciplineID.Text)) - { - throw new Exception("Имеются незаполненные поля"); - } - - var submission = Submission.CreateEntity( - _submissionId ?? 0, - int.Parse(textBoxDisciplineID.Text), - dateTimePickerDate.Value - ); - - if (_submissionId.HasValue) - { - _submissionRepository.UpdateSubmission(submission); - } - else - { - _submissionRepository.CreateSubmission(submission); - } - - Close(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void buttonCancel_Click(object sender, EventArgs e) - { - Close(); - } - - private void labelDisciplineID_Click(object sender, EventArgs e) - { - - } - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormTeacher.Designer.cs b/ProjectSession/ProjectSession/Forms/FormTeacher.Designer.cs deleted file mode 100644 index 002f2f0..0000000 --- a/ProjectSession/ProjectSession/Forms/FormTeacher.Designer.cs +++ /dev/null @@ -1,128 +0,0 @@ -namespace ProjectSession.Forms -{ - partial class FormTeacher - { - /// - /// 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() - { - dataGridViewTeachers = new DataGridView(); - buttonAdd = new Button(); - buttonEdit = new Button(); - buttonDelete = new Button(); - panelButtons = new Panel(); - ((System.ComponentModel.ISupportInitialize)dataGridViewTeachers).BeginInit(); - panelButtons.SuspendLayout(); - SuspendLayout(); - // - // dataGridViewTeachers - // - dataGridViewTeachers.AllowUserToAddRows = false; - dataGridViewTeachers.AllowUserToDeleteRows = false; - dataGridViewTeachers.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridViewTeachers.Dock = DockStyle.Fill; - dataGridViewTeachers.Location = new Point(0, 0); - dataGridViewTeachers.Margin = new Padding(3, 4, 3, 4); - dataGridViewTeachers.Name = "dataGridViewTeachers"; - dataGridViewTeachers.ReadOnly = true; - dataGridViewTeachers.RowHeadersVisible = false; - dataGridViewTeachers.RowHeadersWidth = 51; - dataGridViewTeachers.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridViewTeachers.Size = new Size(732, 533); - dataGridViewTeachers.TabIndex = 0; - // - // buttonAdd - // - buttonAdd.BackgroundImage = Properties.Resources.add_icon; - buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; - buttonAdd.Location = new Point(44, 13); - buttonAdd.Margin = new Padding(3, 4, 3, 4); - buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(100, 100); - buttonAdd.TabIndex = 1; - buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += buttonAdd_Click; - // - // buttonEdit - // - buttonEdit.BackgroundImage = Properties.Resources.edit_icon; - buttonEdit.BackgroundImageLayout = ImageLayout.Stretch; - buttonEdit.Location = new Point(44, 229); - buttonEdit.Margin = new Padding(3, 4, 3, 4); - buttonEdit.Name = "buttonEdit"; - buttonEdit.Size = new Size(100, 100); - buttonEdit.TabIndex = 2; - buttonEdit.UseVisualStyleBackColor = true; - buttonEdit.Click += buttonEdit_Click; - // - // buttonDelete - // - buttonDelete.BackgroundImage = Properties.Resources.delete_icon; - buttonDelete.BackgroundImageLayout = ImageLayout.Stretch; - buttonDelete.Location = new Point(44, 121); - buttonDelete.Margin = new Padding(3, 4, 3, 4); - buttonDelete.Name = "buttonDelete"; - buttonDelete.Size = new Size(100, 100); - buttonDelete.TabIndex = 3; - buttonDelete.UseVisualStyleBackColor = true; - buttonDelete.Click += buttonDelete_Click; - // - // panelButtons - // - panelButtons.Controls.Add(buttonDelete); - panelButtons.Controls.Add(buttonEdit); - panelButtons.Controls.Add(buttonAdd); - panelButtons.Dock = DockStyle.Right; - panelButtons.Location = new Point(732, 0); - panelButtons.Margin = new Padding(3, 4, 3, 4); - panelButtons.Name = "panelButtons"; - panelButtons.Size = new Size(182, 533); - panelButtons.TabIndex = 4; - // - // FormTeacher - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(914, 533); - Controls.Add(dataGridViewTeachers); - Controls.Add(panelButtons); - Margin = new Padding(3, 4, 3, 4); - Name = "FormTeacher"; - Text = "Преподаватели"; - Load += FormTeacher_Load; - ((System.ComponentModel.ISupportInitialize)dataGridViewTeachers).EndInit(); - panelButtons.ResumeLayout(false); - ResumeLayout(false); - } - - #endregion - - private DataGridView dataGridViewTeachers; - private Button buttonAdd; - private Button buttonEdit; - private Button buttonDelete; - private Panel panelButtons; - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormTeacher.cs b/ProjectSession/ProjectSession/Forms/FormTeacher.cs deleted file mode 100644 index 0eb06cb..0000000 --- a/ProjectSession/ProjectSession/Forms/FormTeacher.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Windows.Forms; -using Unity; -using ProjectSession.Entities; -using ProjectSession.Repositories; - -namespace ProjectSession.Forms -{ - public partial class FormTeacher : Form - { - private readonly IUnityContainer _container; - private readonly ITeacherRepository _teacherRepository; - - public FormTeacher(IUnityContainer container, ITeacherRepository teacherRepository) - { - InitializeComponent(); - _container = container ?? throw new ArgumentNullException(nameof(container)); - _teacherRepository = teacherRepository ?? throw new ArgumentNullException(nameof(teacherRepository)); - } - - private void FormTeacher_Load(object sender, EventArgs e) - { - try - { - LoadTeachers(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void LoadTeachers() - { - dataGridViewTeachers.DataSource = _teacherRepository.ReadTeachers(); - } - - private void buttonAdd_Click(object sender, EventArgs e) - { - try - { - var form = _container.Resolve(); - form.ShowDialog(); - LoadTeachers(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void buttonEdit_Click(object sender, EventArgs e) - { - if (!TryGetSelectedTeacherId(out var teacherId)) - { - return; - } - - try - { - var form = _container.Resolve(); - form.TeacherId = teacherId; - form.ShowDialog(); - LoadTeachers(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при редактировании", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void buttonDelete_Click(object sender, EventArgs e) - { - if (!TryGetSelectedTeacherId(out var teacherId)) - { - return; - } - - if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) - { - return; - } - - try - { - _teacherRepository.DeleteTeacher(teacherId); - LoadTeachers(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private bool TryGetSelectedTeacherId(out int teacherId) - { - teacherId = 0; - - if (dataGridViewTeachers.SelectedRows.Count < 1) - { - MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - - teacherId = Convert.ToInt32(dataGridViewTeachers.SelectedRows[0].Cells["Id"].Value); - return true; - } - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormTeacherEdit.Designer.cs b/ProjectSession/ProjectSession/Forms/FormTeacherEdit.Designer.cs deleted file mode 100644 index 8cc8968..0000000 --- a/ProjectSession/ProjectSession/Forms/FormTeacherEdit.Designer.cs +++ /dev/null @@ -1,99 +0,0 @@ -namespace ProjectSession.Forms -{ - partial class FormTeacherEdit - { - /// - /// 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() - { - labelName = new Label(); - textBoxName = new TextBox(); - buttonSave = new Button(); - buttonCancel = new Button(); - SuspendLayout(); - // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(14, 27); - labelName.Name = "labelName"; - labelName.Size = new Size(45, 20); - labelName.TabIndex = 0; - labelName.Text = "ФИО:"; - // - // textBoxName - // - textBoxName.Location = new Point(14, 51); - textBoxName.Margin = new Padding(3, 4, 3, 4); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(228, 27); - textBoxName.TabIndex = 1; - // - // buttonSave - // - buttonSave.Location = new Point(14, 93); - buttonSave.Margin = new Padding(3, 4, 3, 4); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(86, 31); - buttonSave.TabIndex = 2; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += buttonSave_Click; - // - // buttonCancel - // - buttonCancel.Location = new Point(106, 93); - buttonCancel.Margin = new Padding(3, 4, 3, 4); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(86, 31); - buttonCancel.TabIndex = 3; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += buttonCancel_Click; - // - // FormTeacherEdit - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(256, 140); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(textBoxName); - Controls.Add(labelName); - Margin = new Padding(3, 4, 3, 4); - Name = "FormTeacherEdit"; - Text = "Редактирование преподавателя"; - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private Label labelName; - private TextBox textBoxName; - private Button buttonSave; - private Button buttonCancel; - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormTeacherEdit.cs b/ProjectSession/ProjectSession/Forms/FormTeacherEdit.cs deleted file mode 100644 index f9c74ee..0000000 --- a/ProjectSession/ProjectSession/Forms/FormTeacherEdit.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Windows.Forms; -using ProjectSession.Entities; -using ProjectSession.Repositories; - -namespace ProjectSession.Forms -{ - public partial class FormTeacherEdit : Form - { - private readonly ITeacherRepository _teacherRepository; - private int? _teacherId; - - public int? TeacherId - { - get => _teacherId; - set - { - _teacherId = value; - if (_teacherId.HasValue) - { - var teacher = _teacherRepository.ReadTeacherById(_teacherId.Value); - textBoxName.Text = teacher.Name; - } - } - } - - public FormTeacherEdit(ITeacherRepository teacherRepository) - { - InitializeComponent(); - _teacherRepository = teacherRepository ?? throw new ArgumentNullException(nameof(teacherRepository)); - } - - private void buttonSave_Click(object sender, EventArgs e) - { - try - { - if (string.IsNullOrWhiteSpace(textBoxName.Text)) - { - throw new Exception("Имеются незаполненные поля"); - } - - var teacher = Teacher.CreateEntity( - _teacherId ?? 0, - textBoxName.Text - ); - - if (_teacherId.HasValue) - { - _teacherRepository.UpdateTeacher(teacher); - } - else - { - _teacherRepository.CreateTeacher(teacher); - } - - Close(); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void buttonCancel_Click(object sender, EventArgs e) - { - Close(); - } - } -} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/GroupForm.Designer.cs b/ProjectSession/ProjectSession/Forms/GroupForm.Designer.cs new file mode 100644 index 0000000..934fa5e --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/GroupForm.Designer.cs @@ -0,0 +1,119 @@ +namespace ProjectSession.Forms +{ + partial class GroupForm + { + /// + /// 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() + { + label1 = new Label(); + label2 = new Label(); + ButtonSave = new Button(); + ButtonCancel = new Button(); + textBoxName = new TextBox(); + comboBoxType = new ComboBox(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(38, 38); + label1.Name = "label1"; + label1.Size = new Size(46, 15); + label1.TabIndex = 0; + label1.Text = "Группа"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(38, 68); + label2.Name = "label2"; + label2.Size = new Size(83, 15); + label2.TabIndex = 1; + label2.Text = "Тип обучения"; + // + // ButtonSave + // + ButtonSave.Location = new Point(53, 108); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(96, 23); + ButtonSave.TabIndex = 9; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(206, 108); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(96, 23); + ButtonCancel.TabIndex = 10; + ButtonCancel.Text = "Отменить"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // textBoxName + // + textBoxName.Location = new Point(154, 36); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(159, 23); + textBoxName.TabIndex = 11; + // + // comboBoxType + // + comboBoxType.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxType.FormattingEnabled = true; + comboBoxType.Location = new Point(155, 65); + comboBoxType.Name = "comboBoxType"; + comboBoxType.Size = new Size(159, 23); + comboBoxType.TabIndex = 12; + // + // GroupForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(360, 157); + Controls.Add(comboBoxType); + Controls.Add(textBoxName); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Controls.Add(label2); + Controls.Add(label1); + Name = "GroupForm"; + Text = "Группа"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Button ButtonSave; + private Button ButtonCancel; + private TextBox textBoxName; + private ComboBox comboBoxType; + } +} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/GroupForm.cs b/ProjectSession/ProjectSession/Forms/GroupForm.cs new file mode 100644 index 0000000..36fb6e7 --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/GroupForm.cs @@ -0,0 +1,84 @@ +using ProjectSession.Entities.Enums; +using ProjectSession.Entities; +using ProjectSession.Repositories; +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 ProjectSession.Forms; + +public partial class GroupForm : Form +{ + private readonly IGroupRepository _groupRepository; + private int? _groupId; + + public int Id + { + set + { + try + { + var group = _groupRepository.GetGroupById(value); + if (group == null) + { + throw new InvalidDataException(nameof(group)); + } + textBoxName.Text = group.Name; + comboBoxType.SelectedItem = group.Type; + _groupId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public GroupForm(IGroupRepository groupRepository) + { + InitializeComponent(); + _groupRepository = groupRepository ?? + throw new ArgumentNullException(nameof(groupRepository)); + + comboBoxType.DataSource = Enum.GetValues(typeof(GroupType)); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxName.Text) || comboBoxType.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля"); + } + + if (_groupId.HasValue) + { + _groupRepository.UpdateGroup(CreateGroup(_groupId.Value)); + } + else + { + _groupRepository.AddGroup(CreateGroup(0)); + } + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Group CreateGroup(int id) => Group. + Create(id, textBoxName.Text, + (GroupType)comboBoxType.SelectedItem!); +} diff --git a/ProjectSession/ProjectSession/Forms/FormStatement.resx b/ProjectSession/ProjectSession/Forms/GroupForm.resx similarity index 100% rename from ProjectSession/ProjectSession/Forms/FormStatement.resx rename to ProjectSession/ProjectSession/Forms/GroupForm.resx diff --git a/ProjectSession/ProjectSession/Forms/GroupsListForm.Designer.cs b/ProjectSession/ProjectSession/Forms/GroupsListForm.Designer.cs new file mode 100644 index 0000000..192ae92 --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/GroupsListForm.Designer.cs @@ -0,0 +1,132 @@ +namespace ProjectSession.Forms +{ + partial class GroupsListForm + { + /// + /// 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() + { + panel1 = new Panel(); + ButtonDel = new Button(); + ButtonUpd = new Button(); + ButtonAdd = new Button(); + dataGridViewGroups = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewGroups).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(ButtonDel); + panel1.Controls.Add(ButtonUpd); + panel1.Controls.Add(ButtonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(909, 0); + panel1.Margin = new Padding(3, 4, 3, 4); + panel1.Name = "panel1"; + panel1.Size = new Size(180, 585); + panel1.TabIndex = 0; + // + // ButtonDel + // + ButtonDel.BackgroundImage = Properties.Resources.delete_icon; + ButtonDel.BackgroundImageLayout = ImageLayout.Stretch; + ButtonDel.Location = new Point(18, 171); + ButtonDel.Margin = new Padding(3, 4, 3, 4); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(150, 150); + ButtonDel.TabIndex = 3; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; + // + // ButtonUpd + // + ButtonUpd.BackgroundImage = Properties.Resources.edit_icon; + ButtonUpd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonUpd.Location = new Point(18, 329); + ButtonUpd.Margin = new Padding(3, 4, 3, 4); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(150, 150); + ButtonUpd.TabIndex = 2; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // ButtonAdd + // + ButtonAdd.BackgroundImage = Properties.Resources.add_icon; + ButtonAdd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonAdd.Location = new Point(18, 13); + ButtonAdd.Margin = new Padding(3, 4, 3, 4); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(150, 150); + ButtonAdd.TabIndex = 1; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // dataGridViewGroups + // + dataGridViewGroups.AllowUserToAddRows = false; + dataGridViewGroups.AllowUserToDeleteRows = false; + dataGridViewGroups.AllowUserToResizeColumns = false; + dataGridViewGroups.AllowUserToResizeRows = false; + dataGridViewGroups.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewGroups.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewGroups.Dock = DockStyle.Fill; + dataGridViewGroups.Location = new Point(0, 0); + dataGridViewGroups.Margin = new Padding(3, 4, 3, 4); + dataGridViewGroups.MultiSelect = false; + dataGridViewGroups.Name = "dataGridViewGroups"; + dataGridViewGroups.ReadOnly = true; + dataGridViewGroups.RowHeadersVisible = false; + dataGridViewGroups.RowHeadersWidth = 51; + dataGridViewGroups.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewGroups.Size = new Size(909, 585); + dataGridViewGroups.TabIndex = 2; + // + // GroupsListForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1089, 585); + Controls.Add(dataGridViewGroups); + Controls.Add(panel1); + Margin = new Padding(3, 4, 3, 4); + Name = "GroupsListForm"; + Text = "Группы"; + Load += GroupList_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewGroups).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button ButtonAdd; + private Button ButtonUpd; + private Button ButtonDel; + private DataGridView dataGridViewGroups; + } +} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/GroupsListForm.cs b/ProjectSession/ProjectSession/Forms/GroupsListForm.cs new file mode 100644 index 0000000..84b503d --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/GroupsListForm.cs @@ -0,0 +1,107 @@ +using ProjectSession.Repositories; +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; +using Unity; + +namespace ProjectSession.Forms; + +public partial class GroupsListForm : Form +{ + + private readonly IUnityContainer _container; + private readonly IGroupRepository _groupRepository; + + public GroupsListForm(IUnityContainer container, IGroupRepository groupRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _groupRepository = groupRepository ?? throw new ArgumentNullException(nameof(groupRepository)); + } + + private void GroupList_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _groupRepository.DeleteGroup(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewGroups.DataSource = _groupRepository.GetAllGroups(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewGroups.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridViewGroups.SelectedRows[0].Cells["ID"].Value); + return true; + } +} diff --git a/ProjectSession/ProjectSession/Forms/FormStudentEdit.resx b/ProjectSession/ProjectSession/Forms/GroupsListForm.resx similarity index 100% rename from ProjectSession/ProjectSession/Forms/FormStudentEdit.resx rename to ProjectSession/ProjectSession/Forms/GroupsListForm.resx diff --git a/ProjectSession/ProjectSession/Forms/StudentForm.Designer.cs b/ProjectSession/ProjectSession/Forms/StudentForm.Designer.cs new file mode 100644 index 0000000..176384a --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/StudentForm.Designer.cs @@ -0,0 +1,163 @@ +namespace ProjectSession.Forms +{ + partial class StudentForm + { + /// + /// 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() + { + lblSurname = new Label(); + lblName = new Label(); + lblMiddleName = new Label(); + lblGroup = new Label(); + textBoxSurname = new TextBox(); + textBoxName = new TextBox(); + textBoxMiddleName = new TextBox(); + ButtonSave = new Button(); + ButtonCancel = new Button(); + comboBoxGroup = new ComboBox(); + SuspendLayout(); + // + // lblSurname + // + lblSurname.AutoSize = true; + lblSurname.Location = new Point(38, 39); + lblSurname.Name = "lblSurname"; + lblSurname.Size = new Size(61, 15); + lblSurname.TabIndex = 0; + lblSurname.Text = "Фамилия "; + // + // lblName + // + lblName.AutoSize = true; + lblName.Location = new Point(38, 69); + lblName.Name = "lblName"; + lblName.Size = new Size(31, 15); + lblName.TabIndex = 1; + lblName.Text = "Имя"; + // + // lblMiddleName + // + lblMiddleName.AutoSize = true; + lblMiddleName.Location = new Point(38, 98); + lblMiddleName.Name = "lblMiddleName"; + lblMiddleName.Size = new Size(58, 15); + lblMiddleName.TabIndex = 2; + lblMiddleName.Text = "Отчество"; + // + // lblGroup + // + lblGroup.AutoSize = true; + lblGroup.Location = new Point(38, 127); + lblGroup.Name = "lblGroup"; + lblGroup.Size = new Size(46, 15); + lblGroup.TabIndex = 3; + lblGroup.Text = "Группа"; + // + // textBoxSurname + // + textBoxSurname.Location = new Point(149, 36); + textBoxSurname.Name = "textBoxSurname"; + textBoxSurname.Size = new Size(141, 23); + textBoxSurname.TabIndex = 4; + // + // textBoxName + // + textBoxName.Location = new Point(149, 66); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(141, 23); + textBoxName.TabIndex = 5; + // + // textBoxMiddleName + // + textBoxMiddleName.Location = new Point(149, 95); + textBoxMiddleName.Name = "textBoxMiddleName"; + textBoxMiddleName.Size = new Size(141, 23); + textBoxMiddleName.TabIndex = 6; + // + // ButtonSave + // + ButtonSave.Location = new Point(49, 176); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(96, 23); + ButtonSave.TabIndex = 8; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(183, 176); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(96, 23); + ButtonCancel.TabIndex = 9; + ButtonCancel.Text = "Отменить"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // comboBoxGroup + // + comboBoxGroup.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxGroup.FormattingEnabled = true; + comboBoxGroup.Location = new Point(149, 124); + comboBoxGroup.Name = "comboBoxGroup"; + comboBoxGroup.Size = new Size(141, 23); + comboBoxGroup.TabIndex = 10; + // + // StudentForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(331, 224); + Controls.Add(comboBoxGroup); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Controls.Add(textBoxMiddleName); + Controls.Add(textBoxName); + Controls.Add(textBoxSurname); + Controls.Add(lblGroup); + Controls.Add(lblMiddleName); + Controls.Add(lblName); + Controls.Add(lblSurname); + Name = "StudentForm"; + Text = "StudentForm"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label lblSurname; + private Label lblName; + private Label lblMiddleName; + private Label lblGroup; + private TextBox textBoxSurname; + private TextBox textBoxName; + private TextBox textBoxMiddleName; + private Button ButtonSave; + private Button ButtonCancel; + private ComboBox comboBoxGroup; + } +} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/StudentForm.cs b/ProjectSession/ProjectSession/Forms/StudentForm.cs new file mode 100644 index 0000000..3499810 --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/StudentForm.cs @@ -0,0 +1,90 @@ +using ProjectSession.Entities; +using ProjectSession.Repositories; +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 ProjectSession.Forms; + +public partial class StudentForm : Form +{ + private readonly IStudentRepository _studentRepository; + private int? _studentId; + + public int Id + { + set + { + try + { + var student = _studentRepository.GetStudentById(value); + if (student == null) + { + throw new InvalidDataException(nameof(student)); + } + textBoxSurname.Text = student.Surname; + textBoxName.Text = student.Name; + textBoxMiddleName.Text = student.MiddleName; + comboBoxGroup.SelectedValue = student.GroupID; + _studentId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public StudentForm(IStudentRepository studentRepository) + { + InitializeComponent(); + _studentRepository = studentRepository ?? + throw new ArgumentNullException(nameof(studentRepository)); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxSurname.Text) || + string.IsNullOrWhiteSpace(textBoxName.Text) || + string.IsNullOrWhiteSpace(textBoxMiddleName.Text) || + comboBoxGroup.SelectedItem == null) + { + throw new Exception("Имеются незаполненные поля"); + } + + if (_studentId.HasValue) + { + _studentRepository.UpdateStudent(CreateStudent(_studentId.Value)); + } + else + { + _studentRepository.AddStudent(CreateStudent(0)); + } + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Student CreateStudent(int id) => Student.Create( + id, + textBoxSurname.Text, + textBoxName.Text, + textBoxMiddleName.Text, + (int)comboBoxGroup.SelectedValue!); +} diff --git a/ProjectSession/ProjectSession/Forms/FormSubmission.resx b/ProjectSession/ProjectSession/Forms/StudentForm.resx similarity index 100% rename from ProjectSession/ProjectSession/Forms/FormSubmission.resx rename to ProjectSession/ProjectSession/Forms/StudentForm.resx diff --git a/ProjectSession/ProjectSession/Forms/StudentsList.Designer.cs b/ProjectSession/ProjectSession/Forms/StudentsList.Designer.cs new file mode 100644 index 0000000..782d5f4 --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/StudentsList.Designer.cs @@ -0,0 +1,133 @@ +namespace ProjectSession.Forms +{ + partial class StudentsList + { + /// + /// 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() + { + panel1 = new Panel(); + ButtonDel = new Button(); + ButtonUpd = new Button(); + ButtonAdd = new Button(); + dataGridViewStudents = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewStudents).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(ButtonDel); + panel1.Controls.Add(ButtonUpd); + panel1.Controls.Add(ButtonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(924, 0); + panel1.Margin = new Padding(3, 4, 3, 4); + panel1.Name = "panel1"; + panel1.Size = new Size(180, 603); + panel1.TabIndex = 0; + // + // ButtonDel + // + ButtonDel.BackgroundImage = Properties.Resources.delete_icon; + ButtonDel.BackgroundImageLayout = ImageLayout.Stretch; + ButtonDel.Location = new Point(15, 171); + ButtonDel.Margin = new Padding(3, 4, 3, 4); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(150, 150); + ButtonDel.TabIndex = 2; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; + // + // ButtonUpd + // + ButtonUpd.BackgroundImage = Properties.Resources.edit_icon; + ButtonUpd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonUpd.Location = new Point(15, 329); + ButtonUpd.Margin = new Padding(3, 4, 3, 4); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(150, 150); + ButtonUpd.TabIndex = 1; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // ButtonAdd + // + ButtonAdd.BackgroundImage = Properties.Resources.add_icon; + ButtonAdd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonAdd.Location = new Point(15, 13); + ButtonAdd.Margin = new Padding(3, 4, 3, 4); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(150, 150); + ButtonAdd.TabIndex = 0; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // dataGridViewStudents + // + dataGridViewStudents.AllowUserToAddRows = false; + dataGridViewStudents.AllowUserToDeleteRows = false; + dataGridViewStudents.AllowUserToResizeColumns = false; + dataGridViewStudents.AllowUserToResizeRows = false; + dataGridViewStudents.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewStudents.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewStudents.Dock = DockStyle.Fill; + dataGridViewStudents.Location = new Point(0, 0); + dataGridViewStudents.Margin = new Padding(3, 4, 3, 4); + dataGridViewStudents.MultiSelect = false; + dataGridViewStudents.Name = "dataGridViewStudents"; + dataGridViewStudents.ReadOnly = true; + dataGridViewStudents.RowHeadersVisible = false; + dataGridViewStudents.RowHeadersWidth = 51; + dataGridViewStudents.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewStudents.Size = new Size(924, 603); + dataGridViewStudents.TabIndex = 1; + // + // StudentsList + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1104, 603); + Controls.Add(dataGridViewStudents); + Controls.Add(panel1); + Margin = new Padding(3, 4, 3, 4); + Name = "StudentsList"; + StartPosition = FormStartPosition.CenterParent; + Text = "Студенты"; + Load += StudentsList_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewStudents).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button ButtonDel; + private Button ButtonUpd; + private Button ButtonAdd; + private DataGridView dataGridViewStudents; + } +} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/StudentsList.cs b/ProjectSession/ProjectSession/Forms/StudentsList.cs new file mode 100644 index 0000000..f330fe6 --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/StudentsList.cs @@ -0,0 +1,108 @@ +using ProjectSession.Repositories; +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; +using Unity; + +namespace ProjectSession.Forms; + +public partial class StudentsList : Form +{ + private readonly IUnityContainer _container; + private readonly IStudentRepository _studentRepository; + + public StudentsList(IUnityContainer container, IStudentRepository studentRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _studentRepository = studentRepository ?? throw new ArgumentNullException(nameof(studentRepository)); + } + + + private void StudentsList_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _studentRepository.DeleteStudent(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewStudents.DataSource = _studentRepository.GetAllStudents(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewStudents.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridViewStudents.SelectedRows[0].Cells["ID"].Value); + return true; + } +} diff --git a/ProjectSession/ProjectSession/Forms/FormSubmissionEdit.resx b/ProjectSession/ProjectSession/Forms/StudentsList.resx similarity index 100% rename from ProjectSession/ProjectSession/Forms/FormSubmissionEdit.resx rename to ProjectSession/ProjectSession/Forms/StudentsList.resx diff --git a/ProjectSession/ProjectSession/Forms/TeacherForm.Designer.cs b/ProjectSession/ProjectSession/Forms/TeacherForm.Designer.cs new file mode 100644 index 0000000..744b604 --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/TeacherForm.Designer.cs @@ -0,0 +1,161 @@ +namespace ProjectSession.Forms +{ + partial class TeacherForm + { + /// + /// 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() + { + ButtonSave = new Button(); + ButtonCancel = new Button(); + labelSurname = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + textBoxSurname = new TextBox(); + textBoxName = new TextBox(); + textBoxMiddleName = new TextBox(); + comboBoxDiscipline = new ComboBox(); + SuspendLayout(); + // + // ButtonSave + // + ButtonSave.Location = new Point(75, 195); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(96, 23); + ButtonSave.TabIndex = 9; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(223, 195); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(96, 23); + ButtonCancel.TabIndex = 10; + ButtonCancel.Text = "Отменить"; + ButtonCancel.UseVisualStyleBackColor = true; + // + // labelSurname + // + labelSurname.AutoSize = true; + labelSurname.Location = new Point(56, 55); + labelSurname.Name = "labelSurname"; + labelSurname.Size = new Size(58, 15); + labelSurname.TabIndex = 11; + labelSurname.Text = "Фамилия"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(56, 86); + label2.Name = "label2"; + label2.Size = new Size(31, 15); + label2.TabIndex = 12; + label2.Text = "Имя"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(56, 115); + label3.Name = "label3"; + label3.Size = new Size(58, 15); + label3.TabIndex = 13; + label3.Text = "Отчество"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(56, 144); + label4.Name = "label4"; + label4.Size = new Size(76, 15); + label4.TabIndex = 14; + label4.Text = "Дисциплина"; + // + // textBoxSurname + // + textBoxSurname.Location = new Point(200, 52); + textBoxSurname.Name = "textBoxSurname"; + textBoxSurname.Size = new Size(145, 23); + textBoxSurname.TabIndex = 15; + // + // textBoxName + // + textBoxName.Location = new Point(200, 83); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(145, 23); + textBoxName.TabIndex = 16; + // + // textBoxMiddleName + // + textBoxMiddleName.Location = new Point(200, 112); + textBoxMiddleName.Name = "textBoxMiddleName"; + textBoxMiddleName.Size = new Size(145, 23); + textBoxMiddleName.TabIndex = 17; + // + // comboBoxDiscipline + // + comboBoxDiscipline.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxDiscipline.FormattingEnabled = true; + comboBoxDiscipline.Location = new Point(200, 141); + comboBoxDiscipline.Name = "comboBoxDiscipline"; + comboBoxDiscipline.Size = new Size(145, 23); + comboBoxDiscipline.TabIndex = 18; + // + // TeacherForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(388, 249); + Controls.Add(comboBoxDiscipline); + Controls.Add(textBoxMiddleName); + Controls.Add(textBoxName); + Controls.Add(textBoxSurname); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(labelSurname); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Name = "TeacherForm"; + Text = "Преподаватель"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button ButtonSave; + private Button ButtonCancel; + private Label labelSurname; + private Label label2; + private Label label3; + private Label label4; + private TextBox textBoxSurname; + private TextBox textBoxName; + private TextBox textBoxMiddleName; + private ComboBox comboBoxDiscipline; + } +} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/TeacherForm.cs b/ProjectSession/ProjectSession/Forms/TeacherForm.cs new file mode 100644 index 0000000..499e0eb --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/TeacherForm.cs @@ -0,0 +1,88 @@ +using ProjectSession.Entities; +using ProjectSession.Repositories; +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 ProjectSession.Forms; + +public partial class TeacherForm : Form +{ + + private readonly ITeacherRepository _teacherRepository; + private int? _teacherId; + + public int Id + { + set + { + try + { + var teacher = _teacherRepository.GetTeacherById(value); + if (teacher == null) + { + throw new InvalidDataException(nameof(teacher)); + } + textBoxSurname.Text = teacher.Surname; + textBoxName.Text = teacher.Name; + textBoxMiddleName.Text = teacher.MiddleName; + comboBoxDiscipline.SelectedValue = teacher.DisciplineID; + _teacherId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public TeacherForm(ITeacherRepository teacherRepository) + { + InitializeComponent(); + _teacherRepository = teacherRepository ?? throw new ArgumentNullException(nameof(teacherRepository)); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxSurname.Text) || + string.IsNullOrWhiteSpace(textBoxName.Text) || + string.IsNullOrWhiteSpace(textBoxMiddleName.Text)) + { + throw new Exception("Имеются незаполненные поля"); + } + + if (_teacherId.HasValue) + { + _teacherRepository.UpdateTeacher(CreateTeacher(_teacherId.Value)); + } + else + { + _teacherRepository.AddTeacher(CreateTeacher(0)); + } + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Teacher CreateTeacher(int id) => Teacher.Create( + id, + textBoxSurname.Text, + textBoxName.Text, + textBoxMiddleName.Text, + (int)comboBoxDiscipline.SelectedValue!); +} diff --git a/ProjectSession/ProjectSession/Forms/FormTeacher.resx b/ProjectSession/ProjectSession/Forms/TeacherForm.resx similarity index 100% rename from ProjectSession/ProjectSession/Forms/FormTeacher.resx rename to ProjectSession/ProjectSession/Forms/TeacherForm.resx diff --git a/ProjectSession/ProjectSession/Forms/TeachersList.Designer.cs b/ProjectSession/ProjectSession/Forms/TeachersList.Designer.cs new file mode 100644 index 0000000..12bddbb --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/TeachersList.Designer.cs @@ -0,0 +1,132 @@ +namespace ProjectSession.Forms +{ + partial class TeachersList + { + /// + /// 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() + { + panel1 = new Panel(); + ButtonDel = new Button(); + ButtonUpd = new Button(); + ButtonAdd = new Button(); + dataGridViewTeachers = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewTeachers).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(ButtonDel); + panel1.Controls.Add(ButtonUpd); + panel1.Controls.Add(ButtonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(918, 0); + panel1.Margin = new Padding(3, 4, 3, 4); + panel1.Name = "panel1"; + panel1.Size = new Size(180, 575); + panel1.TabIndex = 0; + // + // ButtonDel + // + ButtonDel.BackgroundImage = Properties.Resources.delete_icon; + ButtonDel.BackgroundImageLayout = ImageLayout.Stretch; + ButtonDel.Location = new Point(16, 171); + ButtonDel.Margin = new Padding(3, 4, 3, 4); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(150, 150); + ButtonDel.TabIndex = 4; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; + // + // ButtonUpd + // + ButtonUpd.BackgroundImage = Properties.Resources.edit_icon; + ButtonUpd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonUpd.Location = new Point(16, 329); + ButtonUpd.Margin = new Padding(3, 4, 3, 4); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(150, 150); + ButtonUpd.TabIndex = 3; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // ButtonAdd + // + ButtonAdd.BackgroundImage = Properties.Resources.add_icon; + ButtonAdd.BackgroundImageLayout = ImageLayout.Stretch; + ButtonAdd.Location = new Point(16, 13); + ButtonAdd.Margin = new Padding(3, 4, 3, 4); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(150, 150); + ButtonAdd.TabIndex = 2; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // dataGridViewTeachers + // + dataGridViewTeachers.AllowUserToAddRows = false; + dataGridViewTeachers.AllowUserToDeleteRows = false; + dataGridViewTeachers.AllowUserToResizeColumns = false; + dataGridViewTeachers.AllowUserToResizeRows = false; + dataGridViewTeachers.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewTeachers.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewTeachers.Dock = DockStyle.Fill; + dataGridViewTeachers.Location = new Point(0, 0); + dataGridViewTeachers.Margin = new Padding(3, 4, 3, 4); + dataGridViewTeachers.MultiSelect = false; + dataGridViewTeachers.Name = "dataGridViewTeachers"; + dataGridViewTeachers.ReadOnly = true; + dataGridViewTeachers.RowHeadersVisible = false; + dataGridViewTeachers.RowHeadersWidth = 51; + dataGridViewTeachers.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewTeachers.Size = new Size(918, 575); + dataGridViewTeachers.TabIndex = 3; + // + // TeachersList + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1098, 575); + Controls.Add(dataGridViewTeachers); + Controls.Add(panel1); + Margin = new Padding(3, 4, 3, 4); + Name = "TeachersList"; + Text = "Преподаватели"; + Load += TeachersList_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewTeachers).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button ButtonAdd; + private Button ButtonUpd; + private Button ButtonDel; + private DataGridView dataGridViewTeachers; + } +} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/TeachersList.cs b/ProjectSession/ProjectSession/Forms/TeachersList.cs new file mode 100644 index 0000000..ea4ca2f --- /dev/null +++ b/ProjectSession/ProjectSession/Forms/TeachersList.cs @@ -0,0 +1,106 @@ +using ProjectSession.Repositories; +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; +using Unity; + +namespace ProjectSession.Forms; + +public partial class TeachersList : Form +{ + private readonly IUnityContainer _container; + private readonly ITeacherRepository _teacherRepository; + + public TeachersList(IUnityContainer container, ITeacherRepository teacherRepository) + { + InitializeComponent(); + + _container = container ?? throw new ArgumentNullException(nameof(container)); + _teacherRepository = teacherRepository ?? throw new ArgumentNullException(nameof(teacherRepository)); + } + + private void TeachersList_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _teacherRepository.DeleteTeacher(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewTeachers.DataSource = _teacherRepository.GetAllTeachers(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewTeachers.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridViewTeachers.SelectedRows[0].Cells["ID"].Value); + return true; + } +} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Forms/FormTeacherEdit.resx b/ProjectSession/ProjectSession/Forms/TeachersList.resx similarity index 100% rename from ProjectSession/ProjectSession/Forms/FormTeacherEdit.resx rename to ProjectSession/ProjectSession/Forms/TeachersList.resx diff --git a/ProjectSession/ProjectSession/Program.cs b/ProjectSession/ProjectSession/Program.cs index f7b973b..6ab25c5 100644 --- a/ProjectSession/ProjectSession/Program.cs +++ b/ProjectSession/ProjectSession/Program.cs @@ -1,34 +1,35 @@ -using ProjectSession.Repositories.Implementations; +using ProjectSession.Repositories.Implementations; using ProjectSession.Repositories; using Unity.Lifetime; using Unity; -using ProjectSession.Forms; +using System.ComponentModel; namespace ProjectSession { internal static class Program { /// - /// The main entry point for the application. + /// 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(CreateContainer().Resolve()); + Application.Run(CreateContainer().Resolve()); } private static IUnityContainer CreateContainer() { var container = new UnityContainer(); - // + // Ðåãèñòðàöèÿ ðåïîçèòîðèåâ container.RegisterType(new TransientLifetimeManager()); - container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); - container.RegisterType(new TransientLifetimeManager()); - container.RegisterType(new TransientLifetimeManager()); - container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); return container; } diff --git a/ProjectSession/ProjectSession/Properties/Resources.resx b/ProjectSession/ProjectSession/Properties/Resources.resx index 7f3afb7..0084d13 100644 --- a/ProjectSession/ProjectSession/Properties/Resources.resx +++ b/ProjectSession/ProjectSession/Properties/Resources.resx @@ -121,13 +121,13 @@ ..\Resources\1.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\delete_icon.jpeg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Resources\add_icon.jpeg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\edit_icon.jpeg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\delete_icon.jpeg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Repositories/IAddMarkRepository.cs b/ProjectSession/ProjectSession/Repositories/IAddMarkRepository.cs new file mode 100644 index 0000000..98d4172 --- /dev/null +++ b/ProjectSession/ProjectSession/Repositories/IAddMarkRepository.cs @@ -0,0 +1,17 @@ +using ProjectSession.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectSession.Repositories; + +public interface IAddMarkRepository +{ + void CreateMark(AddMark addMark); + void UpdateMark(AddMark addMark); + void DeleteMark(int id); + AddMark GetMarkById(int id); + IEnumerable GetAllMarks(); +} diff --git a/ProjectSession/ProjectSession/Repositories/IDisciplineRepository.cs b/ProjectSession/ProjectSession/Repositories/IDisciplineRepository.cs index f0fe883..9c57e07 100644 --- a/ProjectSession/ProjectSession/Repositories/IDisciplineRepository.cs +++ b/ProjectSession/ProjectSession/Repositories/IDisciplineRepository.cs @@ -4,15 +4,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using YourNamespace.Entities; namespace ProjectSession.Repositories; public interface IDisciplineRepository { - IEnumerable ReadDisciplines(); - Discipline ReadDisciplineById(int id); - void CreateDiscipline(Discipline discipline); + IEnumerable GetAllDisciplines(); + Discipline GetDisciplineById(int id); + void AddDiscipline(Discipline discipline); void UpdateDiscipline(Discipline discipline); void DeleteDiscipline(int id); -} \ No newline at end of file +} diff --git a/ProjectSession/ProjectSession/Repositories/IGroupRepository.cs b/ProjectSession/ProjectSession/Repositories/IGroupRepository.cs new file mode 100644 index 0000000..b3af550 --- /dev/null +++ b/ProjectSession/ProjectSession/Repositories/IGroupRepository.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectSession.Entities; + +namespace ProjectSession.Repositories; + +public interface IGroupRepository +{ + IEnumerable GetAllGroups(); + Group GetGroupById(int id); + void AddGroup(Group group); + void UpdateGroup(Group group); + void DeleteGroup(int id); +} diff --git a/ProjectSession/ProjectSession/Repositories/IStatamentRepository.cs b/ProjectSession/ProjectSession/Repositories/IStatamentRepository.cs deleted file mode 100644 index a3f5e5d..0000000 --- a/ProjectSession/ProjectSession/Repositories/IStatamentRepository.cs +++ /dev/null @@ -1,17 +0,0 @@ -using ProjectSession.Entities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectSession.Repositories; - -public interface IStatementRepository -{ - IEnumerable ReadStatements(); - Statement ReadStatementById(int id); - void CreateStatement(Statement statement); - void UpdateStatement(Statement statement); - void DeleteStatement(int id); -} diff --git a/ProjectSession/ProjectSession/Repositories/IStudentRepository.cs b/ProjectSession/ProjectSession/Repositories/IStudentRepository.cs index 60b7020..3d602d0 100644 --- a/ProjectSession/ProjectSession/Repositories/IStudentRepository.cs +++ b/ProjectSession/ProjectSession/Repositories/IStudentRepository.cs @@ -9,9 +9,9 @@ namespace ProjectSession.Repositories; public interface IStudentRepository { - IEnumerable ReadStudents(); - Student ReadStudentById(int id); - void CreateStudent(Student student); + IEnumerable GetAllStudents(); + Student GetStudentById(int id); + void AddStudent(Student student); void UpdateStudent(Student student); void DeleteStudent(int id); -} \ No newline at end of file +} diff --git a/ProjectSession/ProjectSession/Repositories/IStudent_StatementRepository.cs b/ProjectSession/ProjectSession/Repositories/IStudent_StatementRepository.cs deleted file mode 100644 index 6ff39cd..0000000 --- a/ProjectSession/ProjectSession/Repositories/IStudent_StatementRepository.cs +++ /dev/null @@ -1,17 +0,0 @@ -using ProjectSession.Entities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectSession.Repositories; - -public interface IStudent_StatementRepository -{ - IEnumerable ReadStudent_Statements(); - Student_Statement ReadStudent_StatementById(int id); - void CreateStudent_Statement(Student_Statement student_Statement); - void UpdateStudent_Statement(Student_Statement student_Statement); - void DeleteStudent_Statement(int id); -} diff --git a/ProjectSession/ProjectSession/Repositories/ISubmissionRepository.cs b/ProjectSession/ProjectSession/Repositories/ISubmissionRepository.cs deleted file mode 100644 index 98290dc..0000000 --- a/ProjectSession/ProjectSession/Repositories/ISubmissionRepository.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static ProjectSession.Entities.Sumbission; - -namespace ProjectSession.Repositories; - -public interface ISubmissionRepository -{ - IEnumerable ReadSubmissions(); - Submission ReadSubmissionById(int id); - void CreateSubmission(Submission submission); - void UpdateSubmission(Submission submission); - void DeleteSubmission(int id); -} diff --git a/ProjectSession/ProjectSession/Repositories/ITeacherRepository.cs b/ProjectSession/ProjectSession/Repositories/ITeacherRepository.cs index 361ecdc..b931a0e 100644 --- a/ProjectSession/ProjectSession/Repositories/ITeacherRepository.cs +++ b/ProjectSession/ProjectSession/Repositories/ITeacherRepository.cs @@ -9,9 +9,9 @@ namespace ProjectSession.Repositories; public interface ITeacherRepository { - IEnumerable ReadTeachers(); - Teacher ReadTeacherById(int id); - void CreateTeacher(Teacher teacher); + IEnumerable GetAllTeachers(); + Teacher GetTeacherById(int id); + void AddTeacher(Teacher teacher); void UpdateTeacher(Teacher teacher); void DeleteTeacher(int id); } diff --git a/ProjectSession/ProjectSession/Repositories/Implementations/AddMarkRepository.cs b/ProjectSession/ProjectSession/Repositories/Implementations/AddMarkRepository.cs new file mode 100644 index 0000000..fd4b7ca --- /dev/null +++ b/ProjectSession/ProjectSession/Repositories/Implementations/AddMarkRepository.cs @@ -0,0 +1,38 @@ +using ProjectSession.Entities.Enums; +using ProjectSession.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectSession.Repositories.Implementations; +public class AddMarkRepository : IAddMarkRepository +{ + public void CreateMark(AddMark addMark) + { + // Заглушка + } + + public void UpdateMark(AddMark addMark) + { + // Заглушка + } + + public void DeleteMark(int id) + { + // Заглушка + } + + public AddMark GetMarkById(int id) + { + // Возвращаем объект с фиктивными данными, убедившись, что Mark.One существует + return AddMark.CreateOperation(0, 0, 0, 0, Mark.One); // Убедитесь, что Mark.One определен + } + + public IEnumerable GetAllMarks() + { + // Заглушка + return new List(); + } +} \ No newline at end of file diff --git a/ProjectSession/ProjectSession/Repositories/Implementations/DisciplineRepository.cs b/ProjectSession/ProjectSession/Repositories/Implementations/DisciplineRepository.cs index e87fe74..5ac1a79 100644 --- a/ProjectSession/ProjectSession/Repositories/Implementations/DisciplineRepository.cs +++ b/ProjectSession/ProjectSession/Repositories/Implementations/DisciplineRepository.cs @@ -1,17 +1,37 @@ -using System; +using ProjectSession.Entities.Enums; +using ProjectSession.Entities; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using YourNamespace.Entities; namespace ProjectSession.Repositories.Implementations; public class DisciplineRepository : IDisciplineRepository { - public void CreateDiscipline(Discipline discipline) { } - public void DeleteDiscipline(int id) { } - public Discipline ReadDisciplineById(int id) => Discipline.CreateEntity(0, string.Empty); - public IEnumerable ReadDisciplines() { return new List(); } - public void UpdateDiscipline(Discipline discipline) { } -} \ No newline at end of file + public void AddDiscipline(Discipline discipline) + { + // Заглушка + } + + public void DeleteDiscipline(int id) + { + // Заглушка + } + + public IEnumerable GetAllDisciplines() + { + return new List(); + } + + public Discipline GetDisciplineById(int id) + { + return Discipline.Create(0, string.Empty, string.Empty, Course.None); + } + + public void UpdateDiscipline(Discipline discipline) + { + // Заглушка + } +} diff --git a/ProjectSession/ProjectSession/Repositories/Implementations/GroupRepository.cs b/ProjectSession/ProjectSession/Repositories/Implementations/GroupRepository.cs new file mode 100644 index 0000000..83d055a --- /dev/null +++ b/ProjectSession/ProjectSession/Repositories/Implementations/GroupRepository.cs @@ -0,0 +1,37 @@ +using ProjectSession.Entities; +using ProjectSession.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectSession.Repositories.Implementations; + +public class GroupRepository : IGroupRepository +{ + public void AddGroup(Group group) + { + // Заглушка + } + + public void DeleteGroup(int id) + { + // Заглушка + } + + public IEnumerable GetAllGroups() + { + return new List(); + } + + public Group GetGroupById(int id) + { + return Group.Create(0, string.Empty, GroupType.Daytime); + } + + public void UpdateGroup(Group group) + { + // Заглушка + } +} diff --git a/ProjectSession/ProjectSession/Repositories/Implementations/StatementRepository.cs b/ProjectSession/ProjectSession/Repositories/Implementations/StatementRepository.cs deleted file mode 100644 index 3ec47a5..0000000 --- a/ProjectSession/ProjectSession/Repositories/Implementations/StatementRepository.cs +++ /dev/null @@ -1,17 +0,0 @@ -using ProjectSession.Entities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectSession.Repositories.Implementations; - -public class StatementRepository : IStatementRepository -{ - public void CreateStatement(Statement statement) { } - public void DeleteStatement(int id) { } - public Statement ReadStatementById(int id) { return Statement.CreateEntity(0, 0, 0, 0, 0, DateTime.Now); } - public IEnumerable ReadStatements() { return new List(); } - public void UpdateStatement(Statement statement) { } -} diff --git a/ProjectSession/ProjectSession/Repositories/Implementations/StudentRepository.cs b/ProjectSession/ProjectSession/Repositories/Implementations/StudentRepository.cs index 9283d5c..d9023c9 100644 --- a/ProjectSession/ProjectSession/Repositories/Implementations/StudentRepository.cs +++ b/ProjectSession/ProjectSession/Repositories/Implementations/StudentRepository.cs @@ -1,5 +1,4 @@ -using ProjectSession.Entities; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -7,11 +6,33 @@ using System.Threading.Tasks; namespace ProjectSession.Repositories.Implementations; +using ProjectSession.Entities; +using System.Collections.Generic; + public class StudentRepository : IStudentRepository { - public void CreateStudent(Student student) { } - public void DeleteStudent(int id) { } - public Student ReadStudentById(int id) { return Student.CreateEntity(0, string.Empty, string.Empty, false, Entities.Enums.StudentStatus.Active); } - public IEnumerable ReadStudents() { return new List(); } - public void UpdateStudent(Student student) { } + public void AddStudent(Student student) + { + // Заглушка + } + + public void DeleteStudent(int id) + { + // Заглушка + } + + public IEnumerable GetAllStudents() + { + return new List(); + } + + public Student GetStudentById(int id) + { + return Student.Create(0, string.Empty, string.Empty, string.Empty, 0); + } + + public void UpdateStudent(Student student) + { + // Заглушка + } } diff --git a/ProjectSession/ProjectSession/Repositories/Implementations/Student_StatementRepository.cs b/ProjectSession/ProjectSession/Repositories/Implementations/Student_StatementRepository.cs deleted file mode 100644 index d157636..0000000 --- a/ProjectSession/ProjectSession/Repositories/Implementations/Student_StatementRepository.cs +++ /dev/null @@ -1,17 +0,0 @@ -using ProjectSession.Entities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectSession.Repositories.Implementations; - -public class Student_StatementRepository : IStudent_StatementRepository -{ - public void CreateStudent_Statement(Student_Statement student_Statement) { } - public void DeleteStudent_Statement(int id) { } - public Student_Statement ReadStudent_StatementById(int id) { return Student_Statement.CreateEntity(0, 0, 0); } - public IEnumerable ReadStudent_Statements() { return new List(); } - public void UpdateStudent_Statement(Student_Statement student_Statement) { } -} diff --git a/ProjectSession/ProjectSession/Repositories/Implementations/SubmissionRepository.cs b/ProjectSession/ProjectSession/Repositories/Implementations/SubmissionRepository.cs deleted file mode 100644 index 1ff6b6a..0000000 --- a/ProjectSession/ProjectSession/Repositories/Implementations/SubmissionRepository.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static ProjectSession.Entities.Sumbission; - -namespace ProjectSession.Repositories.Implementations; - -public class SubmissionRepository : ISubmissionRepository -{ - public void CreateSubmission(Submission submission) { } - public void DeleteSubmission(int id) { } - public Submission ReadSubmissionById(int id) { return Submission.CreateEntity(0, 0, DateTime.Now); } - public IEnumerable ReadSubmissions() { return new List(); } - public void UpdateSubmission(Submission submission) { } -} diff --git a/ProjectSession/ProjectSession/Repositories/Implementations/TeacherRepository.cs b/ProjectSession/ProjectSession/Repositories/Implementations/TeacherRepository.cs index ebf6ecb..a5f17b3 100644 --- a/ProjectSession/ProjectSession/Repositories/Implementations/TeacherRepository.cs +++ b/ProjectSession/ProjectSession/Repositories/Implementations/TeacherRepository.cs @@ -1,5 +1,4 @@ -using ProjectSession.Entities; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -7,11 +6,33 @@ using System.Threading.Tasks; namespace ProjectSession.Repositories.Implementations; +using ProjectSession.Entities; +using System.Collections.Generic; + public class TeacherRepository : ITeacherRepository { - public void CreateTeacher(Teacher teacher) { } - public void DeleteTeacher(int id) { } - public Teacher ReadTeacherById(int id) { return Teacher.CreateEntity(0, string.Empty); } - public IEnumerable ReadTeachers() { return new List(); } - public void UpdateTeacher(Teacher teacher) { } + public void AddTeacher(Teacher teacher) + { + // Заглушка + } + + public void DeleteTeacher(int id) + { + // Заглушка + } + + public IEnumerable GetAllTeachers() + { + return new List(); + } + + public Teacher GetTeacherById(int id) + { + return Teacher.Create(0, string.Empty, string.Empty, string.Empty, 0); + } + + public void UpdateTeacher(Teacher teacher) + { + // Заглушка + } }