This commit is contained in:
Данила Селяев 2025-02-21 16:05:46 +04:00
parent fca5f52c57
commit 01fd280859
8 changed files with 230 additions and 124 deletions

View File

@ -63,8 +63,10 @@ namespace FoodOrderDatabaseImplement.Implements
return null;
}
using var context = new FoodOrdersDataBase();
context.Clients.Add(newClient);
context.SaveChanges();
return newClient.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)

View File

@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace FoodOrderDatabaseImplement.Migrations
{
[DbContext(typeof(FoodOrdersDataBase))]
[Migration("20231122135912_Init")]
partial class Init
[Migration("20250217133549_InitMigration")]
partial class InitMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -37,7 +37,7 @@ namespace FoodOrderDatabaseImplement.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<string>("Login")
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");

View File

@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace FoodOrderDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class Init : Migration
public partial class InitMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
@ -19,7 +19,7 @@ namespace FoodOrderDatabaseImplement.Migrations
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientFIO = table.Column<string>(type: "text", nullable: false),
Login = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>

View File

@ -34,7 +34,7 @@ namespace FoodOrderDatabaseImplement.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<string>("Login")
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");

View File

@ -28,106 +28,126 @@
/// </summary>
private void InitializeComponent()
{
this.WorkNameLabel = new System.Windows.Forms.Label();
this.CountLabel = new System.Windows.Forms.Label();
this.SumLabel = new System.Windows.Forms.Label();
this.FoodComboBox = new System.Windows.Forms.ComboBox();
this.CountTextBox = new System.Windows.Forms.TextBox();
this.SumTextBox = new System.Windows.Forms.TextBox();
this.SaveButton = new System.Windows.Forms.Button();
this.ButtonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
WorkNameLabel = new Label();
CountLabel = new Label();
SumLabel = new Label();
FoodComboBox = new ComboBox();
CountTextBox = new TextBox();
SumTextBox = new TextBox();
SaveButton = new Button();
ButtonCancel = new Button();
comboBox4 = new ComboBox();
label1 = new Label();
SuspendLayout();
//
// WorkNameLabel
//
this.WorkNameLabel.AutoSize = true;
this.WorkNameLabel.Location = new System.Drawing.Point(25, 15);
this.WorkNameLabel.Name = "WorkNameLabel";
this.WorkNameLabel.Size = new System.Drawing.Size(59, 15);
this.WorkNameLabel.TabIndex = 0;
this.WorkNameLabel.Text = "Изделие: ";
WorkNameLabel.AutoSize = true;
WorkNameLabel.Location = new Point(25, 15);
WorkNameLabel.Name = "WorkNameLabel";
WorkNameLabel.Size = new Size(59, 15);
WorkNameLabel.TabIndex = 0;
WorkNameLabel.Text = "Изделие: ";
//
// CountLabel
//
this.CountLabel.AutoSize = true;
this.CountLabel.Location = new System.Drawing.Point(25, 44);
this.CountLabel.Name = "CountLabel";
this.CountLabel.Size = new System.Drawing.Size(78, 15);
this.CountLabel.TabIndex = 1;
this.CountLabel.Text = "Количество: ";
CountLabel.AutoSize = true;
CountLabel.Location = new Point(25, 44);
CountLabel.Name = "CountLabel";
CountLabel.Size = new Size(78, 15);
CountLabel.TabIndex = 1;
CountLabel.Text = "Количество: ";
//
// SumLabel
//
this.SumLabel.AutoSize = true;
this.SumLabel.Location = new System.Drawing.Point(25, 76);
this.SumLabel.Name = "SumLabel";
this.SumLabel.Size = new System.Drawing.Size(51, 15);
this.SumLabel.TabIndex = 2;
this.SumLabel.Text = "Сумма: ";
SumLabel.AutoSize = true;
SumLabel.Location = new Point(25, 76);
SumLabel.Name = "SumLabel";
SumLabel.Size = new Size(51, 15);
SumLabel.TabIndex = 2;
SumLabel.Text = "Сумма: ";
//
// FoodComboBox
//
this.FoodComboBox.FormattingEnabled = true;
this.FoodComboBox.Location = new System.Drawing.Point(111, 15);
this.FoodComboBox.Name = "FoodComboBox";
this.FoodComboBox.Size = new System.Drawing.Size(214, 23);
this.FoodComboBox.TabIndex = 4;
this.FoodComboBox.SelectedIndexChanged += new System.EventHandler(this.FoodComboBox_SelectedIndexChanged);
FoodComboBox.FormattingEnabled = true;
FoodComboBox.Location = new Point(111, 15);
FoodComboBox.Name = "FoodComboBox";
FoodComboBox.Size = new Size(214, 23);
FoodComboBox.TabIndex = 4;
FoodComboBox.SelectedIndexChanged += FoodComboBox_SelectedIndexChanged;
//
// CountTextBox
//
this.CountTextBox.Location = new System.Drawing.Point(111, 44);
this.CountTextBox.Name = "CountTextBox";
this.CountTextBox.Size = new System.Drawing.Size(214, 23);
this.CountTextBox.TabIndex = 5;
this.CountTextBox.TextChanged += new System.EventHandler(this.CountTextBox_TextChanged);
CountTextBox.Location = new Point(111, 44);
CountTextBox.Name = "CountTextBox";
CountTextBox.Size = new Size(214, 23);
CountTextBox.TabIndex = 5;
CountTextBox.TextChanged += CountTextBox_TextChanged;
//
// SumTextBox
//
this.SumTextBox.Enabled = false;
this.SumTextBox.Location = new System.Drawing.Point(111, 73);
this.SumTextBox.Name = "SumTextBox";
this.SumTextBox.Size = new System.Drawing.Size(214, 23);
this.SumTextBox.TabIndex = 6;
SumTextBox.Enabled = false;
SumTextBox.Location = new Point(111, 73);
SumTextBox.Name = "SumTextBox";
SumTextBox.Size = new Size(214, 23);
SumTextBox.TabIndex = 6;
//
// SaveButton
//
this.SaveButton.Location = new System.Drawing.Point(111, 115);
this.SaveButton.Name = "SaveButton";
this.SaveButton.Size = new System.Drawing.Size(95, 23);
this.SaveButton.TabIndex = 7;
this.SaveButton.Text = "Сохранить";
this.SaveButton.UseVisualStyleBackColor = true;
this.SaveButton.MouseClick += new System.Windows.Forms.MouseEventHandler(this.SaveButton_Click);
SaveButton.Location = new Point(111, 178);
SaveButton.Name = "SaveButton";
SaveButton.Size = new Size(95, 23);
SaveButton.TabIndex = 7;
SaveButton.Text = "Сохранить";
SaveButton.UseVisualStyleBackColor = true;
SaveButton.MouseClick += SaveButton_Click;
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(230, 115);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(95, 23);
this.ButtonCancel.TabIndex = 8;
this.ButtonCancel.Text = "Отменить";
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ButtonCancel_Click);
ButtonCancel.Location = new Point(230, 178);
ButtonCancel.Name = "ButtonCancel";
ButtonCancel.Size = new Size(95, 23);
ButtonCancel.TabIndex = 8;
ButtonCancel.Text = "Отменить";
ButtonCancel.UseVisualStyleBackColor = true;
ButtonCancel.MouseClick += ButtonCancel_Click;
//
// comboBox4
//
comboBox4.FormattingEnabled = true;
comboBox4.Location = new Point(111, 102);
comboBox4.Name = "comboBox4";
comboBox4.Size = new Size(214, 23);
comboBox4.TabIndex = 10;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(25, 102);
label1.Name = "label1";
label1.Size = new Size(52, 15);
label1.TabIndex = 9;
label1.Text = "Клиент: ";
//
// FormCreateOrder
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(350, 146);
this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.SaveButton);
this.Controls.Add(this.SumTextBox);
this.Controls.Add(this.CountTextBox);
this.Controls.Add(this.FoodComboBox);
this.Controls.Add(this.SumLabel);
this.Controls.Add(this.CountLabel);
this.Controls.Add(this.WorkNameLabel);
this.Name = "FormCreateOrder";
this.Text = "Заказ";
this.ResumeLayout(false);
this.PerformLayout();
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(346, 213);
Controls.Add(comboBox4);
Controls.Add(label1);
Controls.Add(ButtonCancel);
Controls.Add(SaveButton);
Controls.Add(SumTextBox);
Controls.Add(CountTextBox);
Controls.Add(FoodComboBox);
Controls.Add(SumLabel);
Controls.Add(CountLabel);
Controls.Add(WorkNameLabel);
Name = "FormCreateOrder";
Text = "Заказ";
ResumeLayout(false);
PerformLayout();
}
#endregion
@ -140,5 +160,7 @@
private TextBox SumTextBox;
private Button SaveButton;
private Button ButtonCancel;
private ComboBox comboBox4;
private Label label1;
}
}

View File

@ -8,6 +8,7 @@ using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
@ -19,13 +20,16 @@ namespace FoodOrdersView
private readonly ILogger _logger;
private readonly IFoodLogic _logicW;
private readonly IOrderLogic _logicO;
private readonly IClientLogic _logicC;
public FormCreateOrder(ILogger<FormCreateOrder> logger, IFoodLogic logicF, IOrderLogic logicO)
public FormCreateOrder(ILogger<FormCreateOrder> logger, IFoodLogic logicF, IOrderLogic logicO, IClientLogic logicC)
{
InitializeComponent();
_logger = logger;
_logicW = logicF;
_logicO = logicO;
_logicC = logicC;
LoadData();
}
@ -54,6 +58,23 @@ namespace FoodOrdersView
{
_logger.LogError(ex, "Ошибка загрузки списка изделий");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
try
{
var list = _logicC.ReadList(null);
if (list != null)
{
comboBox4.DisplayMember = "ClientFIO";
comboBox4.ValueMember = "Id";
comboBox4.DataSource = list;
comboBox4.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка пользователей");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
@ -114,11 +135,12 @@ namespace FoodOrdersView
{
FoodId = Convert.ToInt32(FoodComboBox.SelectedValue),
FoodName = FoodComboBox.Text,
ClientId = 0,
ClientName = "Admin",
ClientId = Convert.ToInt32(comboBox4.SelectedValue),
ClientName = comboBox4.Text,
Count = Convert.ToInt32(CountTextBox.Text),
Sum = Convert.ToDouble(SumTextBox.Text)
}) ;
Console.Write(Convert.ToInt32(comboBox4.SelectedValue));
if (!operationResult)
{

View File

@ -1,4 +1,64 @@
<root>
<?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">

View File

@ -36,7 +36,7 @@ namespace FoodOrdersView
{
dataGridView1.DataSource = list;
dataGridView1.Columns["FoodId"].Visible = false;
dataGridView1.Columns["ClientId"].Visible = false;
dataGridView1.Columns["ClientId"].Visible = true;
}
_logger.LogInformation("Загрузка заказов");