Pibd-22_Lyakhov_T_I_Lab2_Simple #3
18
StudentProgressRecord/Entity/Enums/Direction.cs
Normal file
18
StudentProgressRecord/Entity/Enums/Direction.cs
Normal 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
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using StudentProgressRecord.Entity.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -12,7 +13,9 @@ 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
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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)
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -86,5 +86,7 @@ namespace StudentProgressRecord
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using StudentProgressRecord.Entity;
|
||||
using StudentProgressRecord.IRepositories;
|
||||
using StudentProgressRecord.Entity.Enums;
|
||||
using StudentProgressRecord.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -64,24 +64,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);
|
||||
}
|
||||
|
||||
public IEnumerable<Subject> ReadSubjects()
|
||||
|
Loading…
Reference in New Issue
Block a user