Переделанная схема, репозитории операции

This commit is contained in:
funa4i 2024-10-29 13:50:35 +04:00
parent c75709899e
commit 40ddc1509f
25 changed files with 154 additions and 575 deletions

View File

@ -1,28 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.Entity
{
public class Department
{
public long Id { get; set; }
public string DepartmentName { get; set; }
public long FacultyId { get; set; }
public static Department CreateEntity(long id, string DepartmentName, long facultyId)
{
return new Department
{
Id = id,
DepartmentName = DepartmentName,
FacultyId = facultyId
};
}
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.Entity.Enums
{
[Flags]
public enum Operations
{
None = 0,
Transfer = 1 << 0,
Enroll = 1 << 1,
Expel = 1 << 2,
}
}

View File

@ -1,25 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.Entity
{
public class Faculty
{
public long Id { get; set; }
public string FacultyName { get; set; }
public static Faculty CreateEntity(long id, string facultyName)
{
return new Faculty()
{
Id = id,
FacultyName = facultyName
};
}
}
}

View File

@ -1,28 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.Entity
{
public class Group
{
public long Id { get; set; }
public string GroupName { get; set; }
public long DepartmentId { get; set; }
public static Group CreateEntity(long id, string groupName, long departmentId)
{
return new Group
{
Id = id,
GroupName = groupName,
DepartmentId = departmentId
};
}
}
}

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.Entity
{
public class Marks
{
public long Id { get; set; }
public long StatementId { get; set; }
public long StudentId { get; set; }
public int Mark { get; set; }
public static Marks CreateElement(long id, long statementId, long studentId)
{
return new Marks
{
Id = id,
StatementId = statementId,
StudentId = studentId
};
}
}
}

View File

@ -9,26 +9,28 @@ namespace StudentProgressRecord.Entity
{ {
public class Statement public class Statement
{ {
public long Id { get; set; }
public long SubjectId { get; set; } public long SubjectId { get; set; }
public long TeacherId { get; set; } public long TeacherId { get; set; }
public long StudentId { get; set; }
public DateTime Date { get; set; } public DateTime Date { get; set; }
public int Mark { get; set; } public IEnumerable<Marks> Marks { get; private set; } = [];
public static Statement CreateEntity(long subjectId, long teacherId, long studentId, DateTime timeStamp, int mark) public static Statement CreateOperation(long id, long subjectId, long teacherId,
DateTime timeStamp, IEnumerable<Marks> marks)
{ {
return new Statement return new Statement
{ {
SubjectId = subjectId, Id = id,
SubjectId = subjectId,
TeacherId = teacherId, TeacherId = teacherId,
StudentId = studentId,
Date = timeStamp, Date = timeStamp,
Mark = mark }; Marks = marks
};
} }
} }
} }

View File

@ -17,17 +17,16 @@ namespace StudentProgressRecord.Entity
public bool Domitory { get; set; } public bool Domitory { get; set; }
public long GroupId { get; set; }
public static Student CreateEntity(long id, string fio, bool familyPos, bool domitory, long groupId) public static Student CreateEntity(long id, string fio, bool familyPos,
bool domitory)
{ {
return new Student return new Student
{ {
Id = id, Id = id,
Fio = fio, Fio = fio,
FamilyPos = familyPos, FamilyPos = familyPos,
Domitory = domitory, Domitory = domitory
GroupId = groupId
}; };
} }
} }

View File

@ -0,0 +1,32 @@
using StudentProgressRecord.Entity.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.Entity
{
public class StudentTransition
{
public long Id { get; set; }
public long StudentId { get; set; }
public Operations Operation { get; set; }
public DateTime timeStamp { get; set; }
public static StudentTransition CreateOperation(long id, long studentId, Operations operation, DateTime time)
{
return new StudentTransition
{
Id = id,
StudentId = studentId,
Operation = operation,
timeStamp = time
};
}
}
}

View File

@ -1,93 +0,0 @@
namespace StudentProgressRecord
{
partial class FormFaculty
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
labelFaculty = new Label();
textBoxFaculty = new TextBox();
buttonApply = new Button();
buttonCancel = new Button();
SuspendLayout();
//
// labelFaculty
//
labelFaculty.AutoSize = true;
labelFaculty.Location = new Point(12, 95);
labelFaculty.Name = "labelFaculty";
labelFaculty.Size = new Size(157, 20);
labelFaculty.TabIndex = 0;
labelFaculty.Text = "Название факультета";
//
// textBoxFaculty
//
textBoxFaculty.Location = new Point(175, 92);
textBoxFaculty.Name = "textBoxFaculty";
textBoxFaculty.Size = new Size(348, 27);
textBoxFaculty.TabIndex = 1;
//
// buttonApply
//
buttonApply.Location = new Point(85, 144);
buttonApply.Name = "buttonApply";
buttonApply.Size = new Size(180, 29);
buttonApply.TabIndex = 2;
buttonApply.Text = "Сохранить";
buttonApply.UseVisualStyleBackColor = true;
//
// buttonCancel
//
buttonCancel.Location = new Point(271, 144);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(180, 29);
buttonCancel.TabIndex = 3;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
//
// FormFaculty
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(535, 263);
Controls.Add(buttonCancel);
Controls.Add(buttonApply);
Controls.Add(textBoxFaculty);
Controls.Add(labelFaculty);
Name = "FormFaculty";
Text = "Факультет";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelFaculty;
private TextBox textBoxFaculty;
private Button buttonApply;
private Button buttonCancel;
}
}

View File

@ -1,74 +0,0 @@
using StudentProgressRecord.Entity;
using StudentProgressRecord.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 StudentProgressRecord
{
public partial class FormFaculty : Form
{
private readonly IFacultyRepository _facultyRepository;
private int? _facultyId;
public int Id
{
set
{
try
{
var faculty =
_facultyRepository.ReadFacultyById(value);
if (faculty == null)
{
throw new InvalidDataException(nameof(faculty));
}
textBoxFaculty.Text = faculty.FacultyName;
_facultyId = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при полученииданных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
public FormFaculty(IFacultyRepository facultyRepository)
{
InitializeComponent();
_facultyRepository = facultyRepository ?? throw new ArgumentNullException(nameof(facultyRepository));
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(textBoxFaculty.Text))
{
throw new Exception("Название факультета не может быть пустым");
}
if (_facultyId.HasValue)
{
_facultyRepository.UpdateFaculty(CreateFaculty(_facultyId.Value));
}
else
{
_facultyRepository.CreateFaculty(CreateFaculty(0));
}
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private Faculty CreateFaculty(int id) => Faculty.CreateEntity(id, textBoxFaculty.Text);
}
}

View File

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,20 +0,0 @@
using StudentProgressRecord.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.Repositories
{
public interface IDepartmentRepository
{
IEnumerable<Department> ReadDepartments(long? facultyId=null);
Department ReadDepartmentById(long id);
void CreateDepartment(Department department);
void UpdateDepartment(Department department);
void DeleteDepartment(long id);
}
}

View File

@ -1,19 +0,0 @@
using StudentProgressRecord.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.Repositories
{
public interface IFacultyRepository
{
IEnumerable<Faculty> ReadFaculties();
Faculty ReadFacultyById(long id);
void CreateFaculty(Faculty faculty);
void UpdateFaculty(Faculty faculty);
void DeleteFaculty(long id);
}
}

View File

@ -1,19 +0,0 @@
using StudentProgressRecord.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.Repositories
{
public interface IGroupRepository
{
IEnumerable<Group> ReadGroups(long? departmentId=null);
Group ReadGroupById(long id);
void CreateGroup(Group group);
void UpdateGroup(Group group);
void DeleteGroup(long id);
}
}

View File

@ -4,10 +4,9 @@ namespace StudentProgressRecord.Repositories
{ {
public interface IStatementRepository public interface IStatementRepository
{ {
IEnumerable<Statement> ReadStatements(long? subjectId, long? teacherId, long? studentId, DateTime? dateTo=null, int? mark=null); IEnumerable<Statement> ReadStatements(long? subjectId = null, long? teacherId = null, DateTime? dateFrom = null, DateTime? dateTo=null);
Statement ReadStatementById(long id);
void CreateStatement(Statement statement); void CreateStatement(Statement statement);
void UpdateStatement(Statement statement);
void DeleteStatement(long id); void DeleteStatement(long id);
} }
} }

View File

@ -9,7 +9,7 @@ namespace StudentProgressRecord.Repositories
{ {
public interface IStudentRepository public interface IStudentRepository
{ {
IEnumerable<Student> ReadStudents(long? groupId = null, bool? familyPos=null, bool? domitory=null); IEnumerable<Student> ReadStudents(bool? familyPos=null, bool? domitory=null);
Student ReadStudentById(long id); Student ReadStudentById(long id);
void CreateStudent(Student student); void CreateStudent(Student student);
void UpdateStudent(Student student); void UpdateStudent(Student student);

View File

@ -0,0 +1,18 @@
using StudentProgressRecord.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.IRepositories
{
public interface IStudentTransitionRepository
{
IEnumerable<StudentTransition> ReadStudentTransitions(long? groupId = null, bool? familyPos = null, bool? domitory = null);
StudentTransition ReadStudentTransitionById(long id);
void CreateStudentTransition(StudentTransition studentTransition);
void DeleteStudentTransition(long id);
}
}

View File

@ -1,38 +0,0 @@
using StudentProgressRecord.Entity;
using StudentProgressRecord.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.RepositoryImp
{
public class DepartmentRepository : IDepartmentRepository
{
public void CreateDepartment(Department department)
{
}
public void DeleteDepartment(long id)
{
}
public Department ReadDepartmentById(long id)
{
return Department.CreateDepartment(0, string.Empty, 0);
}
public IEnumerable<Department> ReadDepartments(long? facultyId = null)
{
return [];
}
public void UpdateDepartment(Department department)
{
}
}
}

View File

@ -1,38 +0,0 @@
using StudentProgressRecord.Entity;
using StudentProgressRecord.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.RepositoryImp
{
public class FacultyRepository : IFacultyRepository
{
public void CreateFaculty(Faculty faculty)
{
}
public void DeleteFaculty(long id)
{
}
public IEnumerable<Faculty> ReadFaculties()
{
return [];
}
public Faculty ReadFacultyById(long id)
{
return Faculty.CreateFaculty(0, string.Empty);
}
public void UpdateFaculty(Faculty faculty)
{
}
}
}

View File

@ -1,37 +0,0 @@
using StudentProgressRecord.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.Repositories
{
public class GroupRepository : IGroupRepository
{
public void CreateGroup(Group group)
{
}
public void DeleteGroup(long id)
{
}
public Group ReadGroupById(long id)
{
return Group.CreateGroup(0, string.Empty, 0);
}
public IEnumerable<Group> ReadGroups(long? departmentId = null)
{
return [];
}
public void UpdateGroup(Group group)
{
}
}
}

View File

@ -12,27 +12,18 @@ namespace StudentProgressRecord.RepositoryImp
{ {
public void CreateStatement(Statement statement) public void CreateStatement(Statement statement)
{ {
} }
public void DeleteStatement(long id) public void DeleteStatement(long id)
{ {
} }
public Statement ReadStatementById(long id) public IEnumerable<Statement> ReadStatements(long? subjectId = null, long? teacherId = null,
{ DateTime? dateFrom = null, DateTime? dateTo = null)
return Statement.CreateStatement(0, 0, 0, DateTime.Now, 0);
}
public IEnumerable<Statement> ReadStatements(long? subjectId, long? teacherId, long? studentId, DateTime? dateTo = null, int? mark = null)
{ {
return []; return [];
} }
public void UpdateStatement(Statement statement)
{
}
} }
} }

View File

@ -12,7 +12,7 @@ namespace StudentProgressRecord.RepositoryImp
{ {
public void CreateStudent(Student student) public void CreateStudent(Student student)
{ {
} }
public void DeleteStudent(long id) public void DeleteStudent(long id)
@ -22,17 +22,17 @@ namespace StudentProgressRecord.RepositoryImp
public Student ReadStudentById(long id) public Student ReadStudentById(long id)
{ {
return Student.CreateStudent(0, string.Empty, false, false, 0); return Student.CreateEntity(0, string.Empty, false , false);
} }
public IEnumerable<Student> ReadStudents(long? groupId = null, bool? familyPos = null, bool? domitory = null) public IEnumerable<Student> ReadStudents(bool? familyPos = null, bool? domitory = null)
{ {
return []; return [];
} }
public void UpdateStudent(Student student) public void UpdateStudent(Student student)
{ {
} }
} }
} }

View File

@ -0,0 +1,28 @@
using StudentProgressRecord.Entity;
using StudentProgressRecord.IRepositories;
using StudentProgressRecord.Entity.Enums;
namespace StudentProgressRecord.RepositoryImp
{
public class StudentTransitionRepository : IStudentTransitionRepository
{
public void CreateStudentTransition(StudentTransition studentTransition)
{
throw new NotImplementedException();
}
public void DeleteStudentTransition(long id)
{
throw new NotImplementedException();
}
public StudentTransition ReadStudentTransitionById(long id)
{
return StudentTransition.CreateOperation(0, 0, Operations.None, DateTime.Now);
}
public IEnumerable<StudentTransition> ReadStudentTransitions(long? groupId = null, bool? familyPos = null, bool? domitory = null)
{
throw new NotImplementedException();
}
}
}

View File

@ -22,7 +22,7 @@ namespace StudentProgressRecord.RepositoryImp
public Subject ReadSubjectById(long id) public Subject ReadSubjectById(long id)
{ {
return Subject.CreateSubject(0, string.Empty); return Subject.CreateEntity(0, string.Empty);
} }
public IEnumerable<Subject> ReadSubjects() public IEnumerable<Subject> ReadSubjects()

View File

@ -22,7 +22,7 @@ namespace StudentProgressRecord.RepositoryImp
public Teacher ReadTeacherById(long id) public Teacher ReadTeacherById(long id)
{ {
return Teacher.CreateTeacher(0, string.Empty, 0); return Teacher.CreateEntity(0, string.Empty, 0);
} }
public IEnumerable<Teacher> ReadTeachers(long? departmentID = null) public IEnumerable<Teacher> ReadTeachers(long? departmentID = null)