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; return null;
} }
using var context = new FoodOrdersDataBase(); using var context = new FoodOrdersDataBase();
context.Clients.Add(newClient); context.Clients.Add(newClient);
context.SaveChanges(); context.SaveChanges();
return newClient.GetViewModel; return newClient.GetViewModel;
} }
public ClientViewModel? Update(ClientBindingModel model) public ClientViewModel? Update(ClientBindingModel model)

View File

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

View File

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

View File

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

View File

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

View File

@ -8,6 +8,7 @@ using System.ComponentModel;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@ -19,13 +20,16 @@ namespace FoodOrdersView
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IFoodLogic _logicW; private readonly IFoodLogic _logicW;
private readonly IOrderLogic _logicO; 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(); InitializeComponent();
_logger = logger; _logger = logger;
_logicW = logicF; _logicW = logicF;
_logicO = logicO; _logicO = logicO;
_logicC = logicC;
LoadData(); LoadData();
} }
@ -54,6 +58,23 @@ namespace FoodOrdersView
{ {
_logger.LogError(ex, "Ошибка загрузки списка изделий"); _logger.LogError(ex, "Ошибка загрузки списка изделий");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); 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), FoodId = Convert.ToInt32(FoodComboBox.SelectedValue),
FoodName = FoodComboBox.Text, FoodName = FoodComboBox.Text,
ClientId = 0, ClientId = Convert.ToInt32(comboBox4.SelectedValue),
ClientName = "Admin", ClientName = comboBox4.Text,
Count = Convert.ToInt32(CountTextBox.Text), Count = Convert.ToInt32(CountTextBox.Text),
Sum = Convert.ToDouble(SumTextBox.Text) Sum = Convert.ToDouble(SumTextBox.Text)
}) ; }) ;
Console.Write(Convert.ToInt32(comboBox4.SelectedValue));
if (!operationResult) 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: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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">

View File

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