From 3f9b8298352699aa7570285095b392bbf724fd1c Mon Sep 17 00:00:00 2001 From: Yourdax Date: Sat, 25 May 2024 23:59:29 +0400 Subject: [PATCH] =?UTF-8?q?+=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BD=D0=B0=D0=BF=D0=B8=D1=82=D0=BA=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... 20240525195148_InitialCreate.Designer.cs} | 50 ++-- ...ate.cs => 20240525195148_InitialCreate.cs} | 54 ++--- .../DiningRoomDatabaseModelSnapshot.cs | 48 ++-- .../DiningRoomView/FormDrink.Designer.cs | 224 ++++++++++++++++++ DiningRoom/DiningRoomView/FormDrink.cs | 201 ++++++++++++++++ DiningRoom/DiningRoomView/FormDrink.resx | 120 ++++++++++ .../FormDrinkComponent.Designer.cs | 119 ++++++++++ .../DiningRoomView/FormDrinkComponent.cs | 72 ++++++ .../DiningRoomView/FormDrinkComponent.resx | 120 ++++++++++ .../DiningRoomView/FormMain.Designer.cs | 3 + DiningRoom/DiningRoomView/FormMain.cs | 30 ++- DiningRoom/DiningRoomView/Program.cs | 3 + 12 files changed, 955 insertions(+), 89 deletions(-) rename DiningRoom/DiningRoomDatabaseImplement/Migrations/{20240525184442_InitialCreate.Designer.cs => 20240525195148_InitialCreate.Designer.cs} (92%) rename DiningRoom/DiningRoomDatabaseImplement/Migrations/{20240525184442_InitialCreate.cs => 20240525195148_InitialCreate.cs} (89%) create mode 100644 DiningRoom/DiningRoomView/FormDrink.Designer.cs create mode 100644 DiningRoom/DiningRoomView/FormDrink.cs create mode 100644 DiningRoom/DiningRoomView/FormDrink.resx create mode 100644 DiningRoom/DiningRoomView/FormDrinkComponent.Designer.cs create mode 100644 DiningRoom/DiningRoomView/FormDrinkComponent.cs create mode 100644 DiningRoom/DiningRoomView/FormDrinkComponent.resx diff --git a/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525184442_InitialCreate.Designer.cs b/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525195148_InitialCreate.Designer.cs similarity index 92% rename from DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525184442_InitialCreate.Designer.cs rename to DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525195148_InitialCreate.Designer.cs index f518d2b..b9ca7a2 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525184442_InitialCreate.Designer.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525195148_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace DiningRoomDatabaseImplement.Migrations { [DbContext(typeof(DiningRoomDatabase))] - [Migration("20240525184442_InitialCreate")] + [Migration("20240525195148_InitialCreate")] partial class InitialCreate { /// @@ -20,7 +20,7 @@ namespace DiningRoomDatabaseImplement.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("DrinkVersion", "7.0.18") + .HasAnnotation("ProductVersion", "7.0.18") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -158,10 +158,10 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("DateCreate") .HasColumnType("timestamp without time zone"); - b.Property("DrinkId") + b.Property("ProductId") .HasColumnType("integer"); - b.Property("DrinkName") + b.Property("ProductName") .IsRequired() .HasColumnType("text"); @@ -176,14 +176,14 @@ namespace DiningRoomDatabaseImplement.Migrations b.HasKey("Id"); - b.HasIndex("DrinkId"); + b.HasIndex("ProductId"); b.HasIndex("UserId"); b.ToTable("Orders"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -194,7 +194,7 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("Cost") .HasColumnType("double precision"); - b.Property("DrinkName") + b.Property("ProductName") .IsRequired() .HasColumnType("text"); @@ -205,10 +205,10 @@ namespace DiningRoomDatabaseImplement.Migrations b.HasIndex("UserId"); - b.ToTable("Drinks"); + b.ToTable("Products"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.DrinkComponent", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.ProductComponent", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -222,16 +222,16 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("Count") .HasColumnType("integer"); - b.Property("DrinkId") + b.Property("ProductId") .HasColumnType("integer"); b.HasKey("Id"); b.HasIndex("ComponentId"); - b.HasIndex("DrinkId"); + b.HasIndex("ProductId"); - b.ToTable("DrinkComponents"); + b.ToTable("ProductComponents"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.User", b => @@ -316,9 +316,9 @@ namespace DiningRoomDatabaseImplement.Migrations modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Order", b => { - b.HasOne("DiningRoomDatabaseImplement.Models.Drink", "Drink") + b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product") .WithMany("Order") - .HasForeignKey("DrinkId") + .HasForeignKey("ProductId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -326,40 +326,40 @@ namespace DiningRoomDatabaseImplement.Migrations .WithMany("Orders") .HasForeignKey("UserId"); - b.Navigation("Drink"); + b.Navigation("Product"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => { b.HasOne("DiningRoomDatabaseImplement.Models.User", null) - .WithMany("Drinks") + .WithMany("Products") .HasForeignKey("UserId"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.DrinkComponent", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.ProductComponent", b => { b.HasOne("DiningRoomDatabaseImplement.Models.Component", "Component") - .WithMany("DrinkComponents") + .WithMany("ProductComponents") .HasForeignKey("ComponentId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("DiningRoomDatabaseImplement.Models.Drink", "Drink") + b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product") .WithMany("Components") - .HasForeignKey("DrinkId") + .HasForeignKey("ProductId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Component"); - b.Navigation("Drink"); + b.Navigation("Product"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Component", b => { b.Navigation("DrinkComponents"); - b.Navigation("DrinkComponents"); + b.Navigation("ProductComponents"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => @@ -367,7 +367,7 @@ namespace DiningRoomDatabaseImplement.Migrations b.Navigation("Components"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => { b.Navigation("Components"); @@ -384,7 +384,7 @@ namespace DiningRoomDatabaseImplement.Migrations b.Navigation("Orders"); - b.Navigation("Drinks"); + b.Navigation("Products"); }); #pragma warning restore 612, 618 } diff --git a/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525184442_InitialCreate.cs b/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525195148_InitialCreate.cs similarity index 89% rename from DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525184442_InitialCreate.cs rename to DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525195148_InitialCreate.cs index 8e75624..302ab4b 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525184442_InitialCreate.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240525195148_InitialCreate.cs @@ -89,20 +89,20 @@ namespace DiningRoomDatabaseImplement.Migrations }); migrationBuilder.CreateTable( - name: "Drinks", + name: "Products", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - DrinkName = table.Column(type: "text", nullable: false), + ProductName = table.Column(type: "text", nullable: false), Cost = table.Column(type: "double precision", nullable: false), UserId = table.Column(type: "integer", nullable: true) }, constraints: table => { - table.PrimaryKey("PK_Drinks", x => x.Id); + table.PrimaryKey("PK_Products", x => x.Id); table.ForeignKey( - name: "FK_Drinks_Users_UserId", + name: "FK_Products_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id"); @@ -165,8 +165,8 @@ namespace DiningRoomDatabaseImplement.Migrations { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - DrinkId = table.Column(type: "integer", nullable: false), - DrinkName = table.Column(type: "text", nullable: false), + ProductId = table.Column(type: "integer", nullable: false), + ProductName = table.Column(type: "text", nullable: false), Count = table.Column(type: "integer", nullable: false), Sum = table.Column(type: "double precision", nullable: false), Status = table.Column(type: "integer", nullable: false), @@ -177,9 +177,9 @@ namespace DiningRoomDatabaseImplement.Migrations { table.PrimaryKey("PK_Orders", x => x.Id); table.ForeignKey( - name: "FK_Orders_Drinks_DrinkId", - column: x => x.DrinkId, - principalTable: "Drinks", + name: "FK_Orders_Products_ProductId", + column: x => x.ProductId, + principalTable: "Products", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( @@ -190,28 +190,28 @@ namespace DiningRoomDatabaseImplement.Migrations }); migrationBuilder.CreateTable( - name: "DrinkComponents", + name: "ProductComponents", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - DrinkId = table.Column(type: "integer", nullable: false), + ProductId = table.Column(type: "integer", nullable: false), ComponentId = table.Column(type: "integer", nullable: false), Count = table.Column(type: "integer", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_DrinkComponents", x => x.Id); + table.PrimaryKey("PK_ProductComponents", x => x.Id); table.ForeignKey( - name: "FK_DrinkComponents_Components_ComponentId", + name: "FK_ProductComponents_Components_ComponentId", column: x => x.ComponentId, principalTable: "Components", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_DrinkComponents_Drinks_DrinkId", - column: x => x.DrinkId, - principalTable: "Drinks", + name: "FK_ProductComponents_Products_ProductId", + column: x => x.ProductId, + principalTable: "Products", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); @@ -247,9 +247,9 @@ namespace DiningRoomDatabaseImplement.Migrations column: "UserId"); migrationBuilder.CreateIndex( - name: "IX_Orders_DrinkId", + name: "IX_Orders_ProductId", table: "Orders", - column: "DrinkId"); + column: "ProductId"); migrationBuilder.CreateIndex( name: "IX_Orders_UserId", @@ -257,18 +257,18 @@ namespace DiningRoomDatabaseImplement.Migrations column: "UserId"); migrationBuilder.CreateIndex( - name: "IX_DrinkComponents_ComponentId", - table: "DrinkComponents", + name: "IX_ProductComponents_ComponentId", + table: "ProductComponents", column: "ComponentId"); migrationBuilder.CreateIndex( - name: "IX_DrinkComponents_DrinkId", - table: "DrinkComponents", - column: "DrinkId"); + name: "IX_ProductComponents_ProductId", + table: "ProductComponents", + column: "ProductId"); migrationBuilder.CreateIndex( - name: "IX_Drinks_UserId", - table: "Drinks", + name: "IX_Products_UserId", + table: "Products", column: "UserId"); } @@ -285,7 +285,7 @@ namespace DiningRoomDatabaseImplement.Migrations name: "Orders"); migrationBuilder.DropTable( - name: "DrinkComponents"); + name: "ProductComponents"); migrationBuilder.DropTable( name: "Cards"); @@ -297,7 +297,7 @@ namespace DiningRoomDatabaseImplement.Migrations name: "Components"); migrationBuilder.DropTable( - name: "Drinks"); + name: "Products"); migrationBuilder.DropTable( name: "Users"); diff --git a/DiningRoom/DiningRoomDatabaseImplement/Migrations/DiningRoomDatabaseModelSnapshot.cs b/DiningRoom/DiningRoomDatabaseImplement/Migrations/DiningRoomDatabaseModelSnapshot.cs index 10d4dd6..5f86f03 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Migrations/DiningRoomDatabaseModelSnapshot.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Migrations/DiningRoomDatabaseModelSnapshot.cs @@ -17,7 +17,7 @@ namespace DiningRoomDatabaseImplement.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("DrinkVersion", "7.0.18") + .HasAnnotation("ProductVersion", "7.0.18") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -155,10 +155,10 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("DateCreate") .HasColumnType("timestamp without time zone"); - b.Property("DrinkId") + b.Property("ProductId") .HasColumnType("integer"); - b.Property("DrinkName") + b.Property("ProductName") .IsRequired() .HasColumnType("text"); @@ -173,14 +173,14 @@ namespace DiningRoomDatabaseImplement.Migrations b.HasKey("Id"); - b.HasIndex("DrinkId"); + b.HasIndex("ProductId"); b.HasIndex("UserId"); b.ToTable("Orders"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -191,7 +191,7 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("Cost") .HasColumnType("double precision"); - b.Property("DrinkName") + b.Property("ProductName") .IsRequired() .HasColumnType("text"); @@ -202,10 +202,10 @@ namespace DiningRoomDatabaseImplement.Migrations b.HasIndex("UserId"); - b.ToTable("Drinks"); + b.ToTable("Products"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.DrinkComponent", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.ProductComponent", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -219,16 +219,16 @@ namespace DiningRoomDatabaseImplement.Migrations b.Property("Count") .HasColumnType("integer"); - b.Property("DrinkId") + b.Property("ProductId") .HasColumnType("integer"); b.HasKey("Id"); b.HasIndex("ComponentId"); - b.HasIndex("DrinkId"); + b.HasIndex("ProductId"); - b.ToTable("DrinkComponents"); + b.ToTable("ProductComponents"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.User", b => @@ -313,9 +313,9 @@ namespace DiningRoomDatabaseImplement.Migrations modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Order", b => { - b.HasOne("DiningRoomDatabaseImplement.Models.Drink", "Drink") + b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product") .WithMany("Order") - .HasForeignKey("DrinkId") + .HasForeignKey("ProductId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -323,40 +323,40 @@ namespace DiningRoomDatabaseImplement.Migrations .WithMany("Orders") .HasForeignKey("UserId"); - b.Navigation("Drink"); + b.Navigation("Product"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => { b.HasOne("DiningRoomDatabaseImplement.Models.User", null) - .WithMany("Drinks") + .WithMany("Products") .HasForeignKey("UserId"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.DrinkComponent", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.ProductComponent", b => { b.HasOne("DiningRoomDatabaseImplement.Models.Component", "Component") - .WithMany("DrinkComponents") + .WithMany("ProductComponents") .HasForeignKey("ComponentId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("DiningRoomDatabaseImplement.Models.Drink", "Drink") + b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product") .WithMany("Components") - .HasForeignKey("DrinkId") + .HasForeignKey("ProductId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.Navigation("Component"); - b.Navigation("Drink"); + b.Navigation("Product"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Component", b => { b.Navigation("DrinkComponents"); - b.Navigation("DrinkComponents"); + b.Navigation("ProductComponents"); }); modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => @@ -364,7 +364,7 @@ namespace DiningRoomDatabaseImplement.Migrations b.Navigation("Components"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Drink", b => + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => { b.Navigation("Components"); @@ -381,7 +381,7 @@ namespace DiningRoomDatabaseImplement.Migrations b.Navigation("Orders"); - b.Navigation("Drinks"); + b.Navigation("Products"); }); #pragma warning restore 612, 618 } diff --git a/DiningRoom/DiningRoomView/FormDrink.Designer.cs b/DiningRoom/DiningRoomView/FormDrink.Designer.cs new file mode 100644 index 0000000..9b605c0 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormDrink.Designer.cs @@ -0,0 +1,224 @@ +namespace DiningRoomView +{ + partial class FormDrink + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBox1 = new GroupBox(); + dataGridView = new DataGridView(); + ID = new DataGridViewTextBoxColumn(); + ComponentName = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + ButtonRef = new Button(); + ButtonDel = new Button(); + ButtonUpd = new Button(); + ButtonAdd = new Button(); + ButtonSave = new Button(); + ButtonCancel = new Button(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(12, 41); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(38, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Цена:"; + // + // textBoxName + // + textBoxName.Location = new Point(94, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(247, 23); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(94, 38); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(100, 23); + textBoxPrice.TabIndex = 3; + // + // groupBox1 + // + groupBox1.Controls.Add(dataGridView); + groupBox1.Controls.Add(ButtonRef); + groupBox1.Controls.Add(ButtonDel); + groupBox1.Controls.Add(ButtonUpd); + groupBox1.Controls.Add(ButtonAdd); + groupBox1.Location = new Point(12, 67); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(510, 338); + groupBox1.TabIndex = 4; + groupBox1.TabStop = false; + groupBox1.Text = "Компонент"; + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ButtonHighlight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ComponentName, Count }); + dataGridView.Location = new Point(0, 21); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(394, 311); + dataGridView.TabIndex = 5; + // + // ID + // + ID.HeaderText = "Id"; + ID.Name = "ID"; + ID.Visible = false; + ID.Width = 250; + // + // ComponentName + // + ComponentName.HeaderText = "Компоненте"; + ComponentName.Name = "ComponentName"; + ComponentName.Width = 250; + // + // Count + // + Count.HeaderText = "Количество"; + Count.Name = "Count"; + // + // ButtonRef + // + ButtonRef.Location = new Point(400, 169); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(106, 28); + ButtonRef.TabIndex = 4; + ButtonRef.Text = "Обновить"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; + // + // ButtonDel + // + ButtonDel.Location = new Point(400, 135); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(106, 28); + ButtonDel.TabIndex = 3; + ButtonDel.Text = "Удалить"; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; + // + // ButtonUpd + // + ButtonUpd.Location = new Point(400, 101); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(106, 28); + ButtonUpd.TabIndex = 2; + ButtonUpd.Text = "Изменить"; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // ButtonAdd + // + ButtonAdd.Location = new Point(400, 67); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(106, 28); + ButtonAdd.TabIndex = 1; + ButtonAdd.Text = "Добавить"; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // ButtonSave + // + ButtonSave.Location = new Point(354, 415); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(75, 23); + ButtonSave.TabIndex = 5; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(435, 415); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(75, 23); + ButtonCancel.TabIndex = 6; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // FormDrink + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(536, 450); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Controls.Add(groupBox1); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormDrink"; + Text = "Создание изделия"; + Load += FormDrink_Load; + groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private System.Windows.Forms.Label labelName; + private System.Windows.Forms.Label labelPrice; + private System.Windows.Forms.TextBox textBoxName; + private System.Windows.Forms.TextBox textBoxPrice; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Button ButtonRef; + private System.Windows.Forms.Button ButtonDel; + private System.Windows.Forms.Button ButtonUpd; + private System.Windows.Forms.Button ButtonAdd; + private System.Windows.Forms.Button ButtonSave; + private System.Windows.Forms.Button ButtonCancel; + private System.Windows.Forms.DataGridViewTextBoxColumn ID; + private System.Windows.Forms.DataGridViewTextBoxColumn ComponentName; + private System.Windows.Forms.DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormDrink.cs b/DiningRoom/DiningRoomView/FormDrink.cs new file mode 100644 index 0000000..b6b524e --- /dev/null +++ b/DiningRoom/DiningRoomView/FormDrink.cs @@ -0,0 +1,201 @@ +using DiningRoomContracts.BindingModels; +using DiningRoomContracts.BusinessLogicContracts; +using DiningRoomContracts.SearchModels; +using DiningRoomDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace DiningRoomView +{ + public partial class FormDrink : Form + { + private readonly ILogger _logger; + private readonly IDrinkLogic _logic; + private int? _id; + private Dictionary _drinkComponents; + public int Id { set { _id = value; } } + public FormDrink(ILogger logger, IDrinkLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _drinkComponents = new Dictionary(); + } + private void FormDrink_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new DrinkSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.DrinkName; + textBoxPrice.Text = view.Cost.ToString(); + _drinkComponents = view.DrinkComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_drinkComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _drinkComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDrinkComponent)); + if (service is FormDrinkComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + if (_drinkComponents.ContainsKey(form.Id)) + { + _drinkComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _drinkComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDrinkComponent)); + if (service is FormDrinkComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _drinkComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + _drinkComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: {ComponentName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value); _drinkComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_drinkComponents == null || _drinkComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new DrinkBindingModel + { + Id = _id ?? 0, + DrinkName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxPrice.Text), + DrinkComponents = _drinkComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _drinkComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/DiningRoom/DiningRoomView/FormDrink.resx b/DiningRoom/DiningRoomView/FormDrink.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormDrink.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormDrinkComponent.Designer.cs b/DiningRoom/DiningRoomView/FormDrinkComponent.Designer.cs new file mode 100644 index 0000000..c510395 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormDrinkComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace DiningRoomView +{ + partial class FormDrinkComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelComponent = new Label(); + labelCount = new Label(); + textBoxCount = new TextBox(); + comboBoxComponent = new ComboBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(12, 9); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(72, 15); + labelComponent.TabIndex = 0; + labelComponent.Text = "Компонент:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 37); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // textBoxCount + // + textBoxCount.Location = new Point(90, 34); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(235, 23); + textBoxCount.TabIndex = 3; + // + // comboBoxComponent + // + comboBoxComponent.BackColor = SystemColors.Window; + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(90, 6); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(235, 23); + comboBoxComponent.TabIndex = 4; + // + // buttonCancel + // + buttonCancel.Location = new Point(248, 63); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(167, 63); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // FormProductComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(337, 97); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(comboBoxComponent); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormProductComponent"; + Text = "Компонент"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private System.Windows.Forms.Label labelComponent; + private System.Windows.Forms.Label labelCount; + private System.Windows.Forms.TextBox textBoxCount; + private System.Windows.Forms.ComboBox comboBoxComponent; + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.Button buttonSave; + } +} \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormDrinkComponent.cs b/DiningRoom/DiningRoomView/FormDrinkComponent.cs new file mode 100644 index 0000000..12567e8 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormDrinkComponent.cs @@ -0,0 +1,72 @@ +using DiningRoomContracts.BusinessLogicContracts; +using DiningRoomContracts.ViewModels; +using DiningRoomDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace DiningRoomView +{ + public partial class FormDrinkComponent : Form + { + private readonly List? _list; + public int Id { get { return Convert.ToInt32(comboBoxComponent.SelectedValue); } set { comboBoxComponent.SelectedValue = value; } } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count { get { return Convert.ToInt32(textBoxCount.Text); } set { textBoxCount.Text = value.ToString(); } } + public FormDrinkComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/DiningRoom/DiningRoomView/FormDrinkComponent.resx b/DiningRoom/DiningRoomView/FormDrinkComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormDrinkComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormMain.Designer.cs b/DiningRoom/DiningRoomView/FormMain.Designer.cs index 7cfdf31..a0c4956 100644 --- a/DiningRoom/DiningRoomView/FormMain.Designer.cs +++ b/DiningRoom/DiningRoomView/FormMain.Designer.cs @@ -140,6 +140,7 @@ button4.TabIndex = 8; button4.Text = "Редактировать напиток"; button4.UseVisualStyleBackColor = true; + button4.Click += ButtonUpdDrink_Click; // // button2 // @@ -168,6 +169,7 @@ button6.TabIndex = 11; button6.Text = "Создать напиток"; button6.UseVisualStyleBackColor = true; + button6.Click += ButtonAddDrink_Click; // // button7 // @@ -177,6 +179,7 @@ button7.TabIndex = 12; button7.Text = "Удалить напиток"; button7.UseVisualStyleBackColor = true; + button7.Click += ButtonDelDrink_Click; // // FormMain // diff --git a/DiningRoom/DiningRoomView/FormMain.cs b/DiningRoom/DiningRoomView/FormMain.cs index fdbe260..edd637e 100644 --- a/DiningRoom/DiningRoomView/FormMain.cs +++ b/DiningRoom/DiningRoomView/FormMain.cs @@ -57,9 +57,12 @@ namespace DiningRoomView var list = _drinkLogic.ReadList(null); if (list != null) { - dataGridView2.DataSource = list; + dataGridView2.DataSource = list; + dataGridView2.Columns["Id"].Visible = false; + dataGridView2.Columns["DrinkComponents"].Visible = false; + dataGridView2.Columns["DrinkName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + } _logger.LogInformation("Загрузка напитков успешна"); } catch (Exception ex) @@ -109,7 +112,7 @@ namespace DiningRoomView if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление продукта"); + _logger.LogInformation("Удаление блюда"); try { if (!_productLogic.Delete(new ProductBindingModel { Id = id })) @@ -120,7 +123,7 @@ namespace DiningRoomView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления продукта"); + _logger.LogError(ex, "Ошибка удаления блюда"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -128,8 +131,8 @@ namespace DiningRoomView } private void ButtonAddDrink_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormProduct)); - if (service is FormProduct form) + var service = Program.ServiceProvider?.GetService(typeof(FormDrink)); + if (service is FormDrink form) { if (form.ShowDialog() == DialogResult.OK) { @@ -141,8 +144,8 @@ namespace DiningRoomView { if (dataGridView1.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormProduct)); - if (service is FormProduct form) + var service = Program.ServiceProvider?.GetService(typeof(FormDrink)); + if (service is FormDrink form) { form.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); if (form.ShowDialog() == DialogResult.OK) @@ -154,15 +157,15 @@ namespace DiningRoomView } private void ButtonDelDrink_Click(object sender, EventArgs e) { - if (dataGridView1.SelectedRows.Count == 1) + if (dataGridView2.SelectedRows.Count == 1) { if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление продукта"); + int id = Convert.ToInt32(dataGridView2.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление напитка"); try { - if (!_productLogic.Delete(new ProductBindingModel { Id = id })) + if (!_drinkLogic.Delete(new DrinkBindingModel { Id = id })) { throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); } @@ -170,12 +173,13 @@ namespace DiningRoomView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления продукта"); + _logger.LogError(ex, "Ошибка удаления напитка"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } + //private void ButtonCreateSale_Click(object sender, EventArgs e) //{ // var service = Program.ServiceProvider?.GetService(typeof(FormCreateSale)); diff --git a/DiningRoom/DiningRoomView/Program.cs b/DiningRoom/DiningRoomView/Program.cs index aad4ffd..4c8beda 100644 --- a/DiningRoom/DiningRoomView/Program.cs +++ b/DiningRoom/DiningRoomView/Program.cs @@ -52,6 +52,9 @@ namespace DiningRoomView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + }