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.Linq;
using System.Text;
@ -12,12 +13,15 @@ namespace StudentProgressRecord.Entity
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
{
Id = id,
Name = name
Name = name,
direction = direction
};
}
}

View File

@ -32,6 +32,8 @@
textBoxSubject = new TextBox();
buttonAply = new Button();
buttonCancel = new Button();
checkedListBoxDir = new CheckedListBox();
label1 = new Label();
SuspendLayout();
//
// labelSubject
@ -52,7 +54,7 @@
//
// buttonAply
//
buttonAply.Location = new Point(13, 39);
buttonAply.Location = new Point(12, 259);
buttonAply.Name = "buttonAply";
buttonAply.Size = new Size(117, 29);
buttonAply.TabIndex = 2;
@ -62,7 +64,7 @@
//
// buttonCancel
//
buttonCancel.Location = new Point(136, 39);
buttonCancel.Location = new Point(135, 259);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(112, 29);
buttonCancel.TabIndex = 3;
@ -70,11 +72,30 @@
buttonCancel.UseVisualStyleBackColor = true;
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
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(261, 77);
ClientSize = new Size(412, 316);
Controls.Add(label1);
Controls.Add(checkedListBoxDir);
Controls.Add(buttonCancel);
Controls.Add(buttonAply);
Controls.Add(textBoxSubject);
@ -92,5 +113,7 @@
private TextBox textBoxSubject;
private Button buttonAply;
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 System;
using System.Collections.Generic;
@ -31,6 +33,13 @@ namespace StudentProgressRecord
}
textBoxSubject.Text = subject.Name;
_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)
{
@ -43,6 +52,10 @@ namespace StudentProgressRecord
{
InitializeComponent();
_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)
@ -50,7 +63,7 @@ namespace StudentProgressRecord
try
{
if (string.IsNullOrWhiteSpace(textBoxSubject.Text) ||
string.IsNullOrWhiteSpace(textBoxSubject.Text))
checkedListBoxDir.CheckedItems.Count == 0)
{
throw new Exception("Имя не может быть пустым");
}
@ -77,7 +90,14 @@ namespace StudentProgressRecord
{
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();
TeacherToolStripMenuItem = new ToolStripMenuItem();
SubjectToolStripMenuItem = new ToolStripMenuItem();
StatementToolStripMenuItem = new ToolStripMenuItem();
OperationToolStripMenuItem = new ToolStripMenuItem();
TransientToolStripMenuItem = new ToolStripMenuItem();
StatementToolStripMenuItem = new ToolStripMenuItem();
ReportToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.SuspendLayout();
SuspendLayout();
@ -53,7 +53,7 @@
//
// HandbookToolStripMenuItem
//
HandbookToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { StudentToolStripMenuItem, TeacherToolStripMenuItem, SubjectToolStripMenuItem, StatementToolStripMenuItem });
HandbookToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { StudentToolStripMenuItem, TeacherToolStripMenuItem, SubjectToolStripMenuItem });
HandbookToolStripMenuItem.Name = "HandbookToolStripMenuItem";
HandbookToolStripMenuItem.Size = new Size(117, 24);
HandbookToolStripMenuItem.Text = "Справочники";
@ -79,16 +79,9 @@
SubjectToolStripMenuItem.Text = "Предметы";
SubjectToolStripMenuItem.Click += SubjectToolStripMenuItem_Click;
//
// StatementToolStripMenuItem
//
StatementToolStripMenuItem.Name = "StatementToolStripMenuItem";
StatementToolStripMenuItem.Size = new Size(201, 26);
StatementToolStripMenuItem.Text = "Ведомость";
StatementToolStripMenuItem.Click += StatementToolStripMenuItem_Click;
//
// OperationToolStripMenuItem
//
OperationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { TransientToolStripMenuItem });
OperationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { TransientToolStripMenuItem, StatementToolStripMenuItem });
OperationToolStripMenuItem.Name = "OperationToolStripMenuItem";
OperationToolStripMenuItem.Size = new Size(95, 24);
OperationToolStripMenuItem.Text = "Операции";
@ -98,7 +91,14 @@
TransientToolStripMenuItem.Name = "TransientToolStripMenuItem";
TransientToolStripMenuItem.Size = new Size(224, 26);
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
//
@ -131,7 +131,7 @@
private ToolStripMenuItem StudentToolStripMenuItem;
private ToolStripMenuItem TeacherToolStripMenuItem;
private ToolStripMenuItem SubjectToolStripMenuItem;
private ToolStripMenuItem StatementToolStripMenuItem;
private ToolStripMenuItem TransientToolStripMenuItem;
private ToolStripMenuItem StatementToolStripMenuItem;
}
}

View File

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

View File

@ -3,13 +3,10 @@ using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using StudentProgressRecord.Entity;
using StudentProgressRecord.Entity.Enums;
using StudentProgressRecord.IRepositories;
using StudentProgressRecord.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.RepositoryImp
{
@ -32,8 +29,8 @@ namespace StudentProgressRecord.RepositoryImp
{
using var connection = new NpgsqlConnection(_connectionString.GetConnectionString());
var query = @"
INSERT INTO Subject (Name)
VALUES (@Name)";
INSERT INTO Subject (direction, Name)
VALUES (@direction ,@Name)";
connection.Execute(query, subject);
}
catch (Exception ex)
@ -64,24 +61,7 @@ namespace StudentProgressRecord.RepositoryImp
public Subject ReadSubjectById(long id)
{
_logger.LogInformation("Получение объекта по идентификатору");
_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;
}
return Subject.CreateEntity(0, string.Empty, Direction.None);
}
public IEnumerable<Subject> ReadSubjects()