Добавил каталог
This commit is contained in:
parent
09a8bc1857
commit
e825cc46c2
@ -29,6 +29,7 @@ namespace Lab3.Database.Repository.Implementations
|
||||
Id = Guid.NewGuid(),
|
||||
Name = f,
|
||||
}));
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ namespace Lab3.Extensions
|
||||
this IServiceCollection services)
|
||||
{
|
||||
services.AddScoped<MainForm>();
|
||||
services.AddScoped<CatalogForm>();
|
||||
|
||||
services.AddScoped<Func<Guid?, CreateForm>>(sp => (id
|
||||
=> new CreateForm(
|
||||
|
76
Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.Designer.cs
generated
Normal file
76
Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.Designer.cs
generated
Normal file
@ -0,0 +1,76 @@
|
||||
namespace Lab3.Forms
|
||||
{
|
||||
partial class CatalogForm
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
Catalog = new DataGridView();
|
||||
EducationForm = new DataGridViewTextBoxColumn();
|
||||
((System.ComponentModel.ISupportInitialize)Catalog).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// Catalog
|
||||
//
|
||||
Catalog.AllowUserToAddRows = false;
|
||||
Catalog.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
Catalog.Columns.AddRange(new DataGridViewColumn[] { EducationForm });
|
||||
Catalog.Dock = DockStyle.Fill;
|
||||
Catalog.Location = new Point(0, 0);
|
||||
Catalog.Name = "Catalog";
|
||||
Catalog.RowHeadersWidth = 51;
|
||||
Catalog.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
Catalog.Size = new Size(800, 450);
|
||||
Catalog.TabIndex = 0;
|
||||
Catalog.CellEndEdit += Catalog_CellEndEditAsync;
|
||||
Catalog.KeyDown += Catalog_KeyDownAsync;
|
||||
//
|
||||
// EducationForm
|
||||
//
|
||||
EducationForm.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
EducationForm.HeaderText = "Форма обучения";
|
||||
EducationForm.MinimumWidth = 6;
|
||||
EducationForm.Name = "EducationForm";
|
||||
//
|
||||
// CatalogForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(Catalog);
|
||||
Name = "CatalogForm";
|
||||
Text = "CatalogForm";
|
||||
Load += CatalogForm_LoadAsync;
|
||||
((System.ComponentModel.ISupportInitialize)Catalog).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView Catalog;
|
||||
private DataGridViewTextBoxColumn EducationForm;
|
||||
}
|
||||
}
|
97
Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs
Normal file
97
Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.cs
Normal file
@ -0,0 +1,97 @@
|
||||
using Lab3.Database.Repository.Interfaces;
|
||||
|
||||
namespace Lab3.Forms
|
||||
{
|
||||
public partial class CatalogForm : Form
|
||||
{
|
||||
private readonly IEducationFormRepository _repository;
|
||||
|
||||
public CatalogForm(IEducationFormRepository educationFormRepository)
|
||||
{
|
||||
_repository = educationFormRepository;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private async void CatalogForm_LoadAsync(object sender, EventArgs e)
|
||||
{
|
||||
Catalog.Rows.Clear();
|
||||
|
||||
var values = (await _repository.Get()).ToList();
|
||||
for (int i = 0; i < values.Count; i++)
|
||||
{
|
||||
Catalog.Rows.Add();
|
||||
Catalog.Rows[i].Cells[0].Value = values[i];
|
||||
}
|
||||
}
|
||||
|
||||
private async void Catalog_CellEndEditAsync(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private async Task LoadAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<string> values = new List<string>();
|
||||
|
||||
for (int i = 0; i < Catalog.Rows.Count; ++i)
|
||||
{
|
||||
string? val = (string?)Catalog.Rows[i].Cells[0].Value;
|
||||
if (string.IsNullOrEmpty(val))
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Неверные данные",
|
||||
"Ошибка",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
values.Add(val);
|
||||
}
|
||||
|
||||
await _repository.Update(values);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
ex.Message,
|
||||
"Ошибка",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async void Catalog_KeyDownAsync(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.Insert)
|
||||
{
|
||||
Catalog.Rows.Add();
|
||||
}
|
||||
|
||||
if (e.KeyCode == Keys.Delete && Catalog.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show(
|
||||
"Удалить?",
|
||||
"Удаление",
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
try
|
||||
{
|
||||
Catalog.Rows.RemoveAt(Catalog.SelectedRows[0].Index);
|
||||
await LoadAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
ex.Message,
|
||||
"Ошибка",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
123
Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.resx
Normal file
123
Cop.Borovkov.Var3/Lab3/Forms/CatalogForm.resx
Normal file
@ -0,0 +1,123 @@
|
||||
<?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>
|
||||
<metadata name="EducationForm.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
@ -28,16 +28,15 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
StudentsListBox = new ComponentsLibrary.ListBoxValues();
|
||||
StudentsListBox = new Cop.Borovkov.Var3.Components.CustomListBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// StudentsListBox
|
||||
//
|
||||
StudentsListBox.Dock = DockStyle.Fill;
|
||||
StudentsListBox.Location = new Point(0, 0);
|
||||
StudentsListBox.Margin = new Padding(3, 4, 3, 4);
|
||||
StudentsListBox.Name = "StudentsListBox";
|
||||
StudentsListBox.SelectedIndex = -1;
|
||||
StudentsListBox.Selected = "";
|
||||
StudentsListBox.Size = new Size(800, 450);
|
||||
StudentsListBox.TabIndex = 0;
|
||||
//
|
||||
@ -50,11 +49,12 @@
|
||||
Name = "MainForm";
|
||||
Text = "MainForm";
|
||||
Load += MainForm_LoadAsync;
|
||||
KeyDown += MainForm_KeyDown;
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComponentsLibrary.ListBoxValues StudentsListBox;
|
||||
private Cop.Borovkov.Var3.Components.CustomListBox StudentsListBox;
|
||||
}
|
||||
}
|
@ -8,20 +8,57 @@ namespace Lab3.Forms
|
||||
{
|
||||
private readonly IStudentRepository _studentRepository;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly Func<Guid?, CreateForm> _getCreateOrUpdateForm;
|
||||
|
||||
public MainForm(
|
||||
IStudentRepository repository,
|
||||
IMapper mapper)
|
||||
IMapper mapper,
|
||||
Func<Guid?, CreateForm> getCreateOrUpdateForm)
|
||||
{
|
||||
_studentRepository = repository;
|
||||
_studentRepository = repository;
|
||||
_mapper = mapper;
|
||||
|
||||
_getCreateOrUpdateForm = getCreateOrUpdateForm;
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private async void MainForm_LoadAsync(object sender, EventArgs e)
|
||||
{
|
||||
var students = _mapper.Map<List<StudentViewModel>>(await _studentRepository.GetAsync());
|
||||
StudentsListBox.FillListBox(students);
|
||||
StudentsListBox.FillValues(
|
||||
students.Select(s => string.Join(" ",
|
||||
[
|
||||
s.Id,
|
||||
s.Name,
|
||||
s.EducationForm,
|
||||
s.StartEducation.ToLongDateString(),
|
||||
s.SessionMarks,
|
||||
]
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
private void MainForm_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Modifiers != Keys.Control)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.A:
|
||||
_getCreateOrUpdateForm(null).Show(this);
|
||||
break;
|
||||
case Keys.U:
|
||||
_getCreateOrUpdateForm(
|
||||
Guid.Parse(StudentsListBox.Selected.Split()[0])
|
||||
).Show(this);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,7 @@ namespace Lab3.Models
|
||||
public record StudentViewModel : StudentDTO
|
||||
{
|
||||
public string SessionMarks => string.Join("; ", StudentSessions
|
||||
.Select(s => string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"сессия{}: {0:f2}",
|
||||
s.Number,
|
||||
s.Score)));
|
||||
.OrderBy(s => s.Number)
|
||||
.Select(s => $"сессия{s.Number:d}: {s.Score:n2}"));
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
using Lab3.Database.Extensions;
|
||||
using Lab3.Extensions;
|
||||
using Lab3.Forms;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@ -21,7 +20,7 @@ namespace Lab3
|
||||
|
||||
var app = CreateHostBuilder().Build();
|
||||
|
||||
Application.Run(app.Services.GetRequiredService<MainForm>());
|
||||
Application.Run(app.Services.GetRequiredService<CatalogForm>());
|
||||
}
|
||||
|
||||
static IHostBuilder CreateHostBuilder()
|
||||
|
Loading…
Reference in New Issue
Block a user