Compare commits

...

5 Commits

Author SHA1 Message Date
funa4i
aa5c773d5a вроде все 2024-11-18 16:07:41 +04:00
funa4i
d87c72750b рефактор 2024-11-18 15:48:14 +04:00
funa4i
d7b991b7b2 слияние 2024-11-18 15:48:02 +04:00
funa4i
1cd02b7d2f labrefactor 2024-11-18 15:41:33 +04:00
funa4i
2cc365a2df refactor 2024-11-18 15:41:14 +04:00
7 changed files with 95 additions and 48 deletions

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.Entity.Enums
{
[Flags]
public enum Direction
{
None = 0,
PI = 1 << 0,
Ivt = 1 << 1,
Is = 1 << 2,
Ist = 1 << 3
}
}

View File

@ -1,4 +1,5 @@
using System; using StudentProgressRecord.Entity.Enums;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -12,12 +13,15 @@ namespace StudentProgressRecord.Entity
public string Name { get; set; } public string Name { get; set; }
public static Subject CreateEntity(long id, string name) public Direction direction { get; set; }
public static Subject CreateEntity(long id, string name, Direction direction)
{ {
return new Subject return new Subject
{ {
Id = id, Id = id,
Name = name Name = name,
direction = direction
}; };
} }
} }

View File

@ -32,6 +32,8 @@
textBoxSubject = new TextBox(); textBoxSubject = new TextBox();
buttonAply = new Button(); buttonAply = new Button();
buttonCancel = new Button(); buttonCancel = new Button();
checkedListBoxDir = new CheckedListBox();
label1 = new Label();
SuspendLayout(); SuspendLayout();
// //
// labelSubject // labelSubject
@ -52,7 +54,7 @@
// //
// buttonAply // buttonAply
// //
buttonAply.Location = new Point(13, 39); buttonAply.Location = new Point(12, 259);
buttonAply.Name = "buttonAply"; buttonAply.Name = "buttonAply";
buttonAply.Size = new Size(117, 29); buttonAply.Size = new Size(117, 29);
buttonAply.TabIndex = 2; buttonAply.TabIndex = 2;
@ -62,7 +64,7 @@
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Location = new Point(136, 39); buttonCancel.Location = new Point(135, 259);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(112, 29); buttonCancel.Size = new Size(112, 29);
buttonCancel.TabIndex = 3; buttonCancel.TabIndex = 3;
@ -70,11 +72,30 @@
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click; buttonCancel.Click += buttonCancel_Click;
// //
// checkedListBoxDir
//
checkedListBoxDir.FormattingEnabled = true;
checkedListBoxDir.Location = new Point(91, 39);
checkedListBoxDir.Name = "checkedListBoxDir";
checkedListBoxDir.Size = new Size(228, 158);
checkedListBoxDir.TabIndex = 4;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(12, 39);
label1.Name = "label1";
label1.Size = new Size(73, 20);
label1.TabIndex = 5;
label1.Text = "Предмет:";
//
// FormSubject // FormSubject
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(261, 77); ClientSize = new Size(412, 316);
Controls.Add(label1);
Controls.Add(checkedListBoxDir);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonAply); Controls.Add(buttonAply);
Controls.Add(textBoxSubject); Controls.Add(textBoxSubject);
@ -92,5 +113,7 @@
private TextBox textBoxSubject; private TextBox textBoxSubject;
private Button buttonAply; private Button buttonAply;
private Button buttonCancel; private Button buttonCancel;
private CheckedListBox checkedListBoxDir;
private Label label1;
} }
} }

View File

@ -1,4 +1,6 @@
using StudentProgressRecord.Entity; using Microsoft.VisualBasic.FileIO;
using StudentProgressRecord.Entity;
using StudentProgressRecord.Entity.Enums;
using StudentProgressRecord.Repositories; using StudentProgressRecord.Repositories;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -31,6 +33,13 @@ namespace StudentProgressRecord
} }
textBoxSubject.Text = subject.Name; textBoxSubject.Text = subject.Name;
_subjectId = value; _subjectId = value;
foreach (Direction elem in Enum.GetValues(typeof(Direction)))
{
if ((elem & subject.direction) != 0)
{
checkedListBoxDir.SetItemChecked(checkedListBoxDir.Items.IndexOf(elem), true);
}
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -43,6 +52,10 @@ namespace StudentProgressRecord
{ {
InitializeComponent(); InitializeComponent();
_subjectRepository = subjectRepository ?? throw new ArgumentNullException(nameof(subjectRepository)); _subjectRepository = subjectRepository ?? throw new ArgumentNullException(nameof(subjectRepository));
foreach (var elem in Enum.GetValues(typeof(Direction)))
{
checkedListBoxDir.Items.Add(elem);
}
} }
private void buttonAply_Click(object sender, EventArgs e) private void buttonAply_Click(object sender, EventArgs e)
@ -50,7 +63,7 @@ namespace StudentProgressRecord
try try
{ {
if (string.IsNullOrWhiteSpace(textBoxSubject.Text) || if (string.IsNullOrWhiteSpace(textBoxSubject.Text) ||
string.IsNullOrWhiteSpace(textBoxSubject.Text)) checkedListBoxDir.CheckedItems.Count == 0)
{ {
throw new Exception("Имя не может быть пустым"); throw new Exception("Имя не может быть пустым");
} }
@ -77,7 +90,14 @@ namespace StudentProgressRecord
{ {
Close(); Close();
} }
private Subject CreateSubject(long id) => Subject.CreateEntity(id, textBoxSubject.Text); private Subject CreateSubject(long id)
{
Direction direction = Direction.None;
foreach (var elem in checkedListBoxDir.CheckedItems)
{
direction |= (Direction)elem;
}
return Subject.CreateEntity(id, textBoxSubject.Text, direction);
}
} }
} }

View File

@ -34,9 +34,9 @@
StudentToolStripMenuItem = new ToolStripMenuItem(); StudentToolStripMenuItem = new ToolStripMenuItem();
TeacherToolStripMenuItem = new ToolStripMenuItem(); TeacherToolStripMenuItem = new ToolStripMenuItem();
SubjectToolStripMenuItem = new ToolStripMenuItem(); SubjectToolStripMenuItem = new ToolStripMenuItem();
StatementToolStripMenuItem = new ToolStripMenuItem();
OperationToolStripMenuItem = new ToolStripMenuItem(); OperationToolStripMenuItem = new ToolStripMenuItem();
TransientToolStripMenuItem = new ToolStripMenuItem(); TransientToolStripMenuItem = new ToolStripMenuItem();
StatementToolStripMenuItem = new ToolStripMenuItem();
ReportToolStripMenuItem = new ToolStripMenuItem(); ReportToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.SuspendLayout(); menuStrip1.SuspendLayout();
SuspendLayout(); SuspendLayout();
@ -53,7 +53,7 @@
// //
// HandbookToolStripMenuItem // HandbookToolStripMenuItem
// //
HandbookToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { StudentToolStripMenuItem, TeacherToolStripMenuItem, SubjectToolStripMenuItem, StatementToolStripMenuItem }); HandbookToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { StudentToolStripMenuItem, TeacherToolStripMenuItem, SubjectToolStripMenuItem });
HandbookToolStripMenuItem.Name = "HandbookToolStripMenuItem"; HandbookToolStripMenuItem.Name = "HandbookToolStripMenuItem";
HandbookToolStripMenuItem.Size = new Size(117, 24); HandbookToolStripMenuItem.Size = new Size(117, 24);
HandbookToolStripMenuItem.Text = "Справочники"; HandbookToolStripMenuItem.Text = "Справочники";
@ -79,16 +79,9 @@
SubjectToolStripMenuItem.Text = "Предметы"; SubjectToolStripMenuItem.Text = "Предметы";
SubjectToolStripMenuItem.Click += SubjectToolStripMenuItem_Click; SubjectToolStripMenuItem.Click += SubjectToolStripMenuItem_Click;
// //
// StatementToolStripMenuItem
//
StatementToolStripMenuItem.Name = "StatementToolStripMenuItem";
StatementToolStripMenuItem.Size = new Size(201, 26);
StatementToolStripMenuItem.Text = "Ведомость";
StatementToolStripMenuItem.Click += StatementToolStripMenuItem_Click;
//
// OperationToolStripMenuItem // OperationToolStripMenuItem
// //
OperationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { TransientToolStripMenuItem }); OperationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { TransientToolStripMenuItem, StatementToolStripMenuItem });
OperationToolStripMenuItem.Name = "OperationToolStripMenuItem"; OperationToolStripMenuItem.Name = "OperationToolStripMenuItem";
OperationToolStripMenuItem.Size = new Size(95, 24); OperationToolStripMenuItem.Size = new Size(95, 24);
OperationToolStripMenuItem.Text = "Операции"; OperationToolStripMenuItem.Text = "Операции";
@ -98,7 +91,14 @@
TransientToolStripMenuItem.Name = "TransientToolStripMenuItem"; TransientToolStripMenuItem.Name = "TransientToolStripMenuItem";
TransientToolStripMenuItem.Size = new Size(224, 26); TransientToolStripMenuItem.Size = new Size(224, 26);
TransientToolStripMenuItem.Text = "Перемещения"; TransientToolStripMenuItem.Text = "Перемещения";
TransientToolStripMenuItem.Click += this.TransientToolStripMenuItem_Click_1; TransientToolStripMenuItem.Click += TransientToolStripMenuItem_Click_1;
//
// StatementToolStripMenuItem
//
StatementToolStripMenuItem.Name = "StatementToolStripMenuItem";
StatementToolStripMenuItem.Size = new Size(224, 26);
StatementToolStripMenuItem.Text = "Ведомость";
StatementToolStripMenuItem.Click += StatementToolStripMenuItem_Click;
// //
// ReportToolStripMenuItem // ReportToolStripMenuItem
// //
@ -131,7 +131,7 @@
private ToolStripMenuItem StudentToolStripMenuItem; private ToolStripMenuItem StudentToolStripMenuItem;
private ToolStripMenuItem TeacherToolStripMenuItem; private ToolStripMenuItem TeacherToolStripMenuItem;
private ToolStripMenuItem SubjectToolStripMenuItem; private ToolStripMenuItem SubjectToolStripMenuItem;
private ToolStripMenuItem StatementToolStripMenuItem;
private ToolStripMenuItem TransientToolStripMenuItem; private ToolStripMenuItem TransientToolStripMenuItem;
private ToolStripMenuItem StatementToolStripMenuItem;
} }
} }

View File

@ -86,5 +86,7 @@ namespace StudentProgressRecord
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
} }
} }

View File

@ -3,13 +3,10 @@ using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Npgsql; using Npgsql;
using StudentProgressRecord.Entity; using StudentProgressRecord.Entity;
using StudentProgressRecord.Entity.Enums;
using StudentProgressRecord.IRepositories; using StudentProgressRecord.IRepositories;
using StudentProgressRecord.Repositories; using StudentProgressRecord.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.RepositoryImp namespace StudentProgressRecord.RepositoryImp
{ {
@ -32,8 +29,8 @@ namespace StudentProgressRecord.RepositoryImp
{ {
using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); using var connection = new NpgsqlConnection(_connectionString.GetConnectionString());
var query = @" var query = @"
INSERT INTO Subject (Name) INSERT INTO Subject (direction, Name)
VALUES (@Name)"; VALUES (@direction ,@Name)";
connection.Execute(query, subject); connection.Execute(query, subject);
} }
catch (Exception ex) catch (Exception ex)
@ -64,24 +61,7 @@ namespace StudentProgressRecord.RepositoryImp
public Subject ReadSubjectById(long id) public Subject ReadSubjectById(long id)
{ {
_logger.LogInformation("Получение объекта по идентификатору"); return Subject.CreateEntity(0, string.Empty, Direction.None);
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.GetConnectionString());
var querySelect = @"
SELECT * FROM Subject
WHERE Id=@id";
var obj = connection.QueryFirst<Subject>(querySelect, new { id });
_logger.LogDebug("Найденный объект: {json}",
JsonConvert.SerializeObject(obj));
return obj;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
} }
public IEnumerable<Subject> ReadSubjects() public IEnumerable<Subject> ReadSubjects()