Compare commits

..

No commits in common. "aa5c773d5a7bab4d8c255622c4e457ccc47d6876" and "d5889f7b3e3c1d7961a003167e9f85342ee78280" have entirely different histories.

7 changed files with 48 additions and 95 deletions

View File

@ -1,18 +0,0 @@
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,5 +1,4 @@
using StudentProgressRecord.Entity.Enums; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -13,15 +12,12 @@ namespace StudentProgressRecord.Entity
public string Name { get; set; } public string Name { get; set; }
public Direction direction { get; set; } public static Subject CreateEntity(long id, string name)
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,8 +32,6 @@
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
@ -54,7 +52,7 @@
// //
// buttonAply // buttonAply
// //
buttonAply.Location = new Point(12, 259); buttonAply.Location = new Point(13, 39);
buttonAply.Name = "buttonAply"; buttonAply.Name = "buttonAply";
buttonAply.Size = new Size(117, 29); buttonAply.Size = new Size(117, 29);
buttonAply.TabIndex = 2; buttonAply.TabIndex = 2;
@ -64,7 +62,7 @@
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Location = new Point(135, 259); buttonCancel.Location = new Point(136, 39);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(112, 29); buttonCancel.Size = new Size(112, 29);
buttonCancel.TabIndex = 3; buttonCancel.TabIndex = 3;
@ -72,30 +70,11 @@
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(412, 316); ClientSize = new Size(261, 77);
Controls.Add(label1);
Controls.Add(checkedListBoxDir);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonAply); Controls.Add(buttonAply);
Controls.Add(textBoxSubject); Controls.Add(textBoxSubject);
@ -113,7 +92,5 @@
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,6 +1,4 @@
using Microsoft.VisualBasic.FileIO; using StudentProgressRecord.Entity;
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;
@ -33,13 +31,6 @@ 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)
{ {
@ -52,18 +43,14 @@ 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)
{ {
try try
{ {
if (string.IsNullOrWhiteSpace(textBoxSubject.Text) || if (string.IsNullOrWhiteSpace(textBoxSubject.Text) ||
checkedListBoxDir.CheckedItems.Count == 0) string.IsNullOrWhiteSpace(textBoxSubject.Text))
{ {
throw new Exception("Имя не может быть пустым"); throw new Exception("Имя не может быть пустым");
} }
@ -90,14 +77,7 @@ namespace StudentProgressRecord
{ {
Close(); Close();
} }
private Subject CreateSubject(long id) private Subject CreateSubject(long id) => Subject.CreateEntity(id, textBoxSubject.Text);
{
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 }); HandbookToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { StudentToolStripMenuItem, TeacherToolStripMenuItem, SubjectToolStripMenuItem, StatementToolStripMenuItem });
HandbookToolStripMenuItem.Name = "HandbookToolStripMenuItem"; HandbookToolStripMenuItem.Name = "HandbookToolStripMenuItem";
HandbookToolStripMenuItem.Size = new Size(117, 24); HandbookToolStripMenuItem.Size = new Size(117, 24);
HandbookToolStripMenuItem.Text = "Справочники"; HandbookToolStripMenuItem.Text = "Справочники";
@ -79,9 +79,16 @@
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, StatementToolStripMenuItem }); OperationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { TransientToolStripMenuItem });
OperationToolStripMenuItem.Name = "OperationToolStripMenuItem"; OperationToolStripMenuItem.Name = "OperationToolStripMenuItem";
OperationToolStripMenuItem.Size = new Size(95, 24); OperationToolStripMenuItem.Size = new Size(95, 24);
OperationToolStripMenuItem.Text = "Операции"; OperationToolStripMenuItem.Text = "Операции";
@ -91,14 +98,7 @@
TransientToolStripMenuItem.Name = "TransientToolStripMenuItem"; TransientToolStripMenuItem.Name = "TransientToolStripMenuItem";
TransientToolStripMenuItem.Size = new Size(224, 26); TransientToolStripMenuItem.Size = new Size(224, 26);
TransientToolStripMenuItem.Text = "Перемещения"; TransientToolStripMenuItem.Text = "Перемещения";
TransientToolStripMenuItem.Click += TransientToolStripMenuItem_Click_1; TransientToolStripMenuItem.Click += this.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 TransientToolStripMenuItem;
private ToolStripMenuItem StatementToolStripMenuItem; private ToolStripMenuItem StatementToolStripMenuItem;
private ToolStripMenuItem TransientToolStripMenuItem;
} }
} }

View File

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

View File

@ -3,10 +3,13 @@ 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
{ {
@ -29,8 +32,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 (direction, Name) INSERT INTO Subject (Name)
VALUES (@direction ,@Name)"; VALUES (@Name)";
connection.Execute(query, subject); connection.Execute(query, subject);
} }
catch (Exception ex) catch (Exception ex)
@ -61,7 +64,24 @@ namespace StudentProgressRecord.RepositoryImp
public Subject ReadSubjectById(long id) public Subject ReadSubjectById(long id)
{ {
return Subject.CreateEntity(0, string.Empty, Direction.None); _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;
}
} }
public IEnumerable<Subject> ReadSubjects() public IEnumerable<Subject> ReadSubjects()