This commit is contained in:
danila 2025-01-30 17:34:37 +04:00
parent ac8ab62ae9
commit 0689ebe5b9
16 changed files with 51 additions and 79 deletions

View File

@ -9,7 +9,7 @@ namespace ShoeStore.Entities;
public class ShoesReplenishment
{
public int Id { get; private set; }
public int FactoryId { get; private set; }
public int FactorysId { get; private set; }
public DateTime DateReceipt { get; private set; }
public IEnumerable<ShoesShoesReplenishment> ShoesShoesReplenishments
{
@ -22,7 +22,7 @@ public class ShoesReplenishment
return new ShoesReplenishment
{
Id = id,
FactoryId = factoryId,
FactorysId = factoryId,
DateReceipt = DateTime.Now,
ShoesShoesReplenishments = shoesShoesReplenishments
};

View File

@ -9,17 +9,15 @@ namespace ShoeStore.Entities;
public class Store
{
public int Id { get; private set; }
public string StoreType { get; private set; } = string.Empty;
public string StoreName { get; private set; } = string.Empty;
public int Employees { get; private set; }
public double Visitors { get; private set; }
public static Store CreateEntity(int id, string storeType, string
public static Store CreateEntity(int id, string
storeName, int employees, double visitors)
{
return new Store
{
Id = id,
StoreType = storeType ?? string.Empty,
StoreName = storeName ?? string.Empty,
Employees = employees,
Visitors = visitors

View File

@ -57,6 +57,7 @@
ButtonDel.Size = new Size(85, 78);
ButtonDel.TabIndex = 2;
ButtonDel.UseVisualStyleBackColor = true;
ButtonDel.Click += ButtonDel_Click;
//
// ButtonUpd
//
@ -67,6 +68,7 @@
ButtonUpd.Size = new Size(85, 77);
ButtonUpd.TabIndex = 1;
ButtonUpd.UseVisualStyleBackColor = true;
ButtonUpd.Click += ButtonUpd_Click;
//
// ButtonAdd
//

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
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

View File

@ -32,10 +32,10 @@
comboBoxFactory = new ComboBox();
groupBox1 = new GroupBox();
dataGridViewShoess = new DataGridView();
ColumnShoes = new DataGridViewComboBoxColumn();
Column2 = new DataGridViewTextBoxColumn();
ButtonSave = new Button();
ButtonCancel = new Button();
ColumnShoes = new DataGridViewComboBoxColumn();
ColumnCount = new DataGridViewTextBoxColumn();
groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewShoess).BeginInit();
SuspendLayout();
@ -74,7 +74,7 @@
dataGridViewShoess.AllowUserToResizeColumns = false;
dataGridViewShoess.AllowUserToResizeRows = false;
dataGridViewShoess.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewShoess.Columns.AddRange(new DataGridViewColumn[] { ColumnShoes, Column2 });
dataGridViewShoess.Columns.AddRange(new DataGridViewColumn[] { ColumnShoes, ColumnCount });
dataGridViewShoess.Dock = DockStyle.Fill;
dataGridViewShoess.Location = new Point(3, 19);
dataGridViewShoess.MultiSelect = false;
@ -85,18 +85,6 @@
dataGridViewShoess.TabIndex = 8;
dataGridViewShoess.CellContentClick += dataGridViewShoess_CellContentClick;
//
// ColumnShoes
//
ColumnShoes.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
ColumnShoes.HeaderText = "Обувь";
ColumnShoes.Name = "ColumnShoes";
//
// Column2
//
Column2.HeaderText = "Количество";
Column2.Name = "Column2";
Column2.Width = 114;
//
// ButtonSave
//
ButtonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
@ -119,6 +107,18 @@
ButtonCancel.UseVisualStyleBackColor = true;
ButtonCancel.Click += ButtonCancel_Click;
//
// ColumnShoes
//
ColumnShoes.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
ColumnShoes.HeaderText = "Обувь";
ColumnShoes.Name = "ColumnShoes";
//
// ColumnCount
//
ColumnCount.HeaderText = "Количество";
ColumnCount.Name = "ColumnCount";
ColumnCount.Width = 114;
//
// FormShoesReplenishment
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -147,6 +147,6 @@
private Button ButtonSave;
private Button ButtonCancel;
private DataGridViewComboBoxColumn ColumnShoes;
private DataGridViewTextBoxColumn Column2;
private DataGridViewTextBoxColumn ColumnCount;
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
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
@ -117,7 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="Column2.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -28,8 +28,6 @@
/// </summary>
private void InitializeComponent()
{
textBoxStoreType = new TextBox();
label1 = new Label();
label2 = new Label();
textBoxStoreName = new TextBox();
label3 = new Label();
@ -43,26 +41,10 @@
((System.ComponentModel.ISupportInitialize)numericUpDownVisitors).BeginInit();
SuspendLayout();
//
// textBoxStoreType
//
textBoxStoreType.Location = new Point(161, 47);
textBoxStoreType.Name = "textBoxStoreType";
textBoxStoreType.Size = new Size(178, 23);
textBoxStoreType.TabIndex = 0;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(39, 50);
label1.Name = "label1";
label1.Size = new Size(84, 15);
label1.TabIndex = 1;
label1.Text = "Тип магазина:";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(39, 94);
label2.Location = new Point(39, 61);
label2.Name = "label2";
label2.Size = new Size(116, 15);
label2.TabIndex = 2;
@ -70,7 +52,7 @@
//
// textBoxStoreName
//
textBoxStoreName.Location = new Point(161, 91);
textBoxStoreName.Location = new Point(161, 58);
textBoxStoreName.Name = "textBoxStoreName";
textBoxStoreName.Size = new Size(178, 23);
textBoxStoreName.TabIndex = 3;
@ -153,8 +135,6 @@
Controls.Add(label3);
Controls.Add(textBoxStoreName);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(textBoxStoreType);
Name = "FormStore";
StartPosition = FormStartPosition.CenterParent;
Text = "Магазин";
@ -166,9 +146,6 @@
}
#endregion
private TextBox textBoxStoreType;
private Label label1;
private Label label2;
private TextBox textBoxStoreName;
private Label label3;

View File

@ -28,7 +28,6 @@ public partial class FormStore : Form
throw new InvalidDataException(nameof(store));
}
textBoxStoreType.Text = store.StoreType;
textBoxStoreName.Text = store.StoreName;
numericUpDownEmployees.Value = store.Employees;
numericUpDownVisitors.Value = (decimal)store.Visitors;
@ -51,9 +50,7 @@ public partial class FormStore : Form
{
try
{
if (string.IsNullOrWhiteSpace(textBoxStoreType.Text)
||
string.IsNullOrWhiteSpace(textBoxStoreName.Text))
if (string.IsNullOrWhiteSpace(textBoxStoreName.Text))
{
throw new Exception("Имеются незаполненные поля");
}
@ -75,7 +72,6 @@ public partial class FormStore : Form
}
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private Store CreateStore(int id) => Store.CreateEntity(id,
textBoxStoreType.Text,
textBoxStoreName.Text,
Convert.ToInt32(numericUpDownEmployees.Value),
Convert.ToDouble(numericUpDownVisitors.Value));
@ -84,6 +80,4 @@ public partial class FormStore : Form
{
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
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

View File

@ -58,6 +58,7 @@
ButtonDel.Size = new Size(85, 78);
ButtonDel.TabIndex = 2;
ButtonDel.UseVisualStyleBackColor = true;
ButtonDel.Click += ButtonDel_Click;
//
// ButtonUpd
//
@ -68,6 +69,7 @@
ButtonUpd.Size = new Size(85, 77);
ButtonUpd.TabIndex = 1;
ButtonUpd.UseVisualStyleBackColor = true;
ButtonUpd.Click += ButtonUpd_Click;
//
// ButtonAdd
//

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
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

View File

@ -8,6 +8,6 @@ namespace ShoeStore.Repositories.Implementations;
internal class ConnectionString : IConnectionString
{
string IConnectionString.ConnectionString => "Server=localhost;Port=5432;Database=Shoe_store;User Id=postgres;Password=326452ND;";
string IConnectionString.ConnectionString => "Server=localhost;Port=5432;Database=postgres;Username=postgres;Password=326452ND;";
}

View File

@ -59,7 +59,7 @@ UPDATE Factorys
SET
FactoryName=@FactoryName,
Manufacturer=@Manufacturer
WHERE [Id]=@Id";
WHERE Id=@Id";
connection.Execute(queryUpdate, factory);
}
catch (Exception ex)

View File

@ -35,13 +35,13 @@ internal class ShoesReplenishmentRepository : IShoesReplenishmentRepository
connection.Open();
using var transaction = connection.BeginTransaction();
var queryInsert = @"
INSERT INTO ShoesReplenishments (FactorysId, DateReceipt)
VALUES (@FactorysId, @DateReceipt);
INSERT INTO ShoesReplenishments (factorysid, DateReceipt)
VALUES (@factorysid, @DateReceipt);
SELECT MAX(Id) FROM ShoesReplenishments";
var shoesReplenishmentId =
connection.QueryFirst<int>(queryInsert, shoesReplenishment, transaction);
var querySubInsert = @"
INSERT INTO ShoesShoesReplenishments (ShoesReplenishmentId, ShoesId, Count)
INSERT INTO ShoesShoesReplenishments (shoesreplenishmentsid, ShoesId, Count)
VALUES (@ShoesReplenishmentId,@ShoesId, @Count)";
foreach (var elem in shoesReplenishment.ShoesShoesReplenishments)
{

View File

@ -34,7 +34,7 @@ internal class ShoesRepository : IShoesRepository
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO Shoess (ShoesType, Name, Description)
INSERT INTO Shoes (ShoesType, Name, Description)
VALUES (@ShoesType, @Name, @Description)";
connection.Execute(queryInsert, shoes);
}
@ -54,7 +54,7 @@ VALUES (@ShoesType, @Name, @Description)";
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE Shoess
UPDATE Shoes
SET
ShoesType=@ShoesType,
Name=@Name,
@ -77,7 +77,7 @@ WHERE Id=@Id";
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Shoess
DELETE FROM Shoes
WHERE Id=@id";
connection.Execute(queryDelete, new { id });
}
@ -96,7 +96,7 @@ WHERE Id=@id";
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM Shoess
SELECT * FROM Shoes
WHERE Id=@id";
var shoes = connection.QueryFirst<Shoes>(querySelect, new
{
@ -119,7 +119,7 @@ WHERE Id=@id";
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Shoess";
var querySelect = "SELECT * FROM Shoes";
var shoess = connection.Query<Shoes>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(shoess));

View File

@ -33,8 +33,8 @@ internal class StoreRepository : IStoreRepository
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO Stores (StoreType, StoreName, Employees, Visitors)
VALUES (@StoreType, @StoreName, @Employees, @Visitors)";
INSERT INTO Stores (StoreName, Employees, Visitors)
VALUES (@StoreName, @Employees, @Visitors)";
connection.Execute(queryInsert, store);
}
catch (Exception ex)
@ -52,9 +52,8 @@ VALUES (@StoreType, @StoreName, @Employees, @Visitors)";
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE Store
UPDATE Stores
SET
StoreType=@StoreType,
StoreName=@StoreName,
Employees=@Employees,
Visitors=@Visitors
@ -77,7 +76,7 @@ WHERE Id=@Id";
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Store
DELETE FROM Stores
WHERE Id=@id";
connection.Execute(queryDelete, new { id });
}
@ -97,8 +96,8 @@ WHERE Id=@id";
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM Store
WHERE [Id]=@id";
SELECT * FROM Stores
WHERE Id=@id";
var store = connection.QueryFirst<Store>(querySelect, new
{
id