From 707916b227937131e18c506fdd3ee201999d4880 Mon Sep 17 00:00:00 2001 From: the Date: Fri, 7 Apr 2023 13:54:25 +0400 Subject: [PATCH] Seems to wok --- .../Controllers/HomeController.cs | 14 +- .../ViewModels/OrderViewModel.cs | 6 + .../Implements/OrderStorage.cs | 10 +- ...20230407090923_clientmigration.Designer.cs | 218 ++++++++++++++++++ .../20230407090923_clientmigration.cs | 68 ++++++ .../ComputerShopDatabaseModelSnapshot.cs | 43 ++++ ComputerShopDatabaseImplement/Models/Order.cs | 36 ++- ComputersShop/FormClients.Designer.cs | 92 ++++++++ ComputersShop/FormClients.cs | 85 +++++++ ComputersShop/FormClients.resx | 60 +++++ ComputersShop/FormCreateOrder.Designer.cs | 30 ++- ComputersShop/FormCreateOrder.cs | 29 ++- ComputersShop/FormMain.Designer.cs | 16 +- ComputersShop/FormMain.cs | 10 + ComputersShop/Program.cs | 4 + 15 files changed, 696 insertions(+), 25 deletions(-) create mode 100644 ComputerShopDatabaseImplement/Migrations/20230407090923_clientmigration.Designer.cs create mode 100644 ComputerShopDatabaseImplement/Migrations/20230407090923_clientmigration.cs create mode 100644 ComputersShop/FormClients.Designer.cs create mode 100644 ComputersShop/FormClients.cs create mode 100644 ComputersShop/FormClients.resx diff --git a/ComputerShopClientApp/Controllers/HomeController.cs b/ComputerShopClientApp/Controllers/HomeController.cs index a00cb16..5d9e990 100644 --- a/ComputerShopClientApp/Controllers/HomeController.cs +++ b/ComputerShopClientApp/Controllers/HomeController.cs @@ -112,12 +112,12 @@ namespace ComputerShopClientApp.Controllers [HttpGet] public IActionResult Create() { - ViewBag.Products = APIClient.GetRequest>("api/main/getproductlist"); + ViewBag.Computers = APIClient.GetRequest>("api/main/getproductlist"); return View(); } [HttpPost] - public void Create(int product, int count) + public void Create(int computer, int count) { if (APIClient.Client == null) { @@ -130,18 +130,18 @@ namespace ComputerShopClientApp.Controllers APIClient.PostRequest("api/main/createorder", new OrderBindingModel { ClientId = APIClient.Client.Id, - ComputerId = product, + ComputerId = computer, Count = count, - Sum = Calc(count, product) + Sum = Calc(count, computer) }); Response.Redirect("Index"); } [HttpPost] - public double Calc(int count, int product) + public double Calc(int count, int computer) { - var prod = APIClient.GetRequest($"api/main/getproduct?productId={product}"); - return count * (prod?.Price ?? 1); + var comp = APIClient.GetRequest($"api/main/getproduct?productId={computer}"); + return count * (comp?.Price ?? 1); } } } \ No newline at end of file diff --git a/ComputerShopContracts/ViewModels/OrderViewModel.cs b/ComputerShopContracts/ViewModels/OrderViewModel.cs index bd75392..63a8bcd 100644 --- a/ComputerShopContracts/ViewModels/OrderViewModel.cs +++ b/ComputerShopContracts/ViewModels/OrderViewModel.cs @@ -17,6 +17,12 @@ namespace ComputerShopContracts.ViewModels public int Id { get; set; } [DisplayName("Компьютер")] public string ComputerName { get; set; } = string.Empty; + + public int ClientId { get; set; } + + [DisplayName("ФИО клиента")] + public string ClientFIO { get; set; } = string.Empty; + [DisplayName("Количество")] public int Count { get; set; } [DisplayName("Сумма")] diff --git a/ComputerShopDatabaseImplement/Implements/OrderStorage.cs b/ComputerShopDatabaseImplement/Implements/OrderStorage.cs index cbaf643..e2af06d 100644 --- a/ComputerShopDatabaseImplement/Implements/OrderStorage.cs +++ b/ComputerShopDatabaseImplement/Implements/OrderStorage.cs @@ -26,11 +26,19 @@ namespace ComputerShopDatabaseImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) { return new(); } using var context = new ComputerShopDatabase(); + if (model.ClientId.HasValue) + { + return context.Orders + .Include(x => x.Client) + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } return context.Orders .Include(x => x.Computer) .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) diff --git a/ComputerShopDatabaseImplement/Migrations/20230407090923_clientmigration.Designer.cs b/ComputerShopDatabaseImplement/Migrations/20230407090923_clientmigration.Designer.cs new file mode 100644 index 0000000..627893a --- /dev/null +++ b/ComputerShopDatabaseImplement/Migrations/20230407090923_clientmigration.Designer.cs @@ -0,0 +1,218 @@ +// +using System; +using ComputerShopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ComputerShopDatabaseImplement.Migrations +{ + [DbContext(typeof(ComputerShopDatabase))] + [Migration("20230407090923_clientmigration")] + partial class clientmigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Computer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComputerName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Computers"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ComputerComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("ComputerId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ComputerId"); + + b.ToTable("ComputerComponents"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("ComputerId") + .HasColumnType("int"); + + b.Property("ComputerName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ComputerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ComputerComponent", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component") + .WithMany("ComputerComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Computer", "Computer") + .WithMany("Components") + .HasForeignKey("ComputerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Computer"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Computer", "Computer") + .WithMany("Orders") + .HasForeignKey("ComputerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Computer"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => + { + b.Navigation("ComputerComponents"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Computer", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ComputerShopDatabaseImplement/Migrations/20230407090923_clientmigration.cs b/ComputerShopDatabaseImplement/Migrations/20230407090923_clientmigration.cs new file mode 100644 index 0000000..190f823 --- /dev/null +++ b/ComputerShopDatabaseImplement/Migrations/20230407090923_clientmigration.cs @@ -0,0 +1,68 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ComputerShopDatabaseImplement.Migrations +{ + /// + public partial class clientmigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ClientId", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ClientId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ClientId", + table: "Orders"); + } + } +} diff --git a/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs b/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs index 5cbeec7..3de14ac 100644 --- a/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs +++ b/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs @@ -22,6 +22,31 @@ namespace ComputerShopDatabaseImplement.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => { b.Property("Id") @@ -96,6 +121,9 @@ namespace ComputerShopDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("ClientId") + .HasColumnType("int"); + b.Property("ComputerId") .HasColumnType("int"); @@ -120,6 +148,8 @@ namespace ComputerShopDatabaseImplement.Migrations b.HasKey("Id"); + b.HasIndex("ClientId"); + b.HasIndex("ComputerId"); b.ToTable("Orders"); @@ -146,15 +176,28 @@ namespace ComputerShopDatabaseImplement.Migrations modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => { + b.HasOne("ComputerShopDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.HasOne("ComputerShopDatabaseImplement.Models.Computer", "Computer") .WithMany("Orders") .HasForeignKey("ComputerId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.Navigation("Client"); + b.Navigation("Computer"); }); + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => { b.Navigation("ComputerComponents"); diff --git a/ComputerShopDatabaseImplement/Models/Order.cs b/ComputerShopDatabaseImplement/Models/Order.cs index 429d42c..173f41e 100644 --- a/ComputerShopDatabaseImplement/Models/Order.cs +++ b/ComputerShopDatabaseImplement/Models/Order.cs @@ -10,6 +10,8 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using ComputerShopDataModels.Enums; using System.Reflection.Metadata; +using DocumentFormat.OpenXml.InkML; +using DocumentFormat.OpenXml.Office2010.Word; namespace ComputerShopDatabaseImplement.Models { @@ -20,6 +22,8 @@ namespace ComputerShopDatabaseImplement.Models [Required] public int ComputerId { get; private set; } [Required] + public int ClientId { get; private set; } + [Required] public int Count { get; private set; } [Required] public double Sum { get; private set; } @@ -31,6 +35,8 @@ namespace ComputerShopDatabaseImplement.Models public DateTime? DateImplement { get; private set; } public virtual Computer Computer { get; set; } + public virtual Client Client { get; set; } + public static Order? Create(OrderBindingModel? model) { if (model == null) @@ -41,6 +47,7 @@ namespace ComputerShopDatabaseImplement.Models { ComputerId = model.ComputerId, ComputerName = model.ComputerName, + ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -60,17 +67,26 @@ namespace ComputerShopDatabaseImplement.Models DateImplement = model.DateImplement; } - public OrderViewModel GetViewModel => new() + public OrderViewModel GetViewModel { - ComputerId = ComputerId, - Count = Count, - Sum = Sum, - DateCreate = DateCreate, - DateImplement = DateImplement, - Id = Id, - Status = Status, - ComputerName = ComputerName - }; + get + { + var context = new ComputerShopDatabase(); + return new() + { + ComputerId = ComputerId, + ClientId = ClientId, + Count = Count, + Sum = Sum, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + Status = Status, + ComputerName = context.Computers.FirstOrDefault(x => x.Id == ComputerId)?.ComputerName ?? string.Empty, + ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty + }; + } + } } } diff --git a/ComputersShop/FormClients.Designer.cs b/ComputersShop/FormClients.Designer.cs new file mode 100644 index 0000000..7154995 --- /dev/null +++ b/ComputersShop/FormClients.Designer.cs @@ -0,0 +1,92 @@ +namespace ComputersShop +{ + partial class FormClients + { + /// + /// 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() + { + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(553, 11); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(82, 22); + this.buttonUpdate.TabIndex = 5; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(553, 37); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(82, 26); + this.buttonDelete.TabIndex = 4; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 11); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(534, 287); + this.dataGridView.TabIndex = 3; + // + // FormClients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(645, 308); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.dataGridView); + this.Name = "FormClients"; + this.Text = "FormClients"; + this.Click += new System.EventHandler(this.FormClients_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonUpdate; + private Button buttonDelete; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ComputersShop/FormClients.cs b/ComputersShop/FormClients.cs new file mode 100644 index 0000000..356bba9 --- /dev/null +++ b/ComputersShop/FormClients.cs @@ -0,0 +1,85 @@ +using ComputerShopContracts.BindingModels; +using ComputerShopContracts.BusinessLogicsContracts; +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 ComputersShop +{ + public partial class FormClients : Form + { + private readonly ILogger _logger; + private readonly IClientLogic _logic; + public FormClients(ILogger logger, IClientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormClients_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить клиента?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление клиента"); + try + { + if (!_logic.Delete(new ClientBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении клиента. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления клиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/ComputersShop/FormClients.resx b/ComputersShop/FormClients.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ComputersShop/FormClients.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/ComputersShop/FormCreateOrder.Designer.cs b/ComputersShop/FormCreateOrder.Designer.cs index e19d281..002b126 100644 --- a/ComputersShop/FormCreateOrder.Designer.cs +++ b/ComputersShop/FormCreateOrder.Designer.cs @@ -36,6 +36,8 @@ this.textBoxSum = new System.Windows.Forms.TextBox(); this.buttonCancel = new System.Windows.Forms.Button(); this.buttonSave = new System.Windows.Forms.Button(); + this.comboBoxClient = new System.Windows.Forms.ComboBox(); + this.labelClient = new System.Windows.Forms.Label(); this.SuspendLayout(); // // labelComputerName @@ -91,7 +93,7 @@ // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(274, 137); + this.buttonCancel.Location = new System.Drawing.Point(276, 184); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(75, 23); this.buttonCancel.TabIndex = 6; @@ -101,7 +103,7 @@ // // buttonSave // - this.buttonSave.Location = new System.Drawing.Point(193, 137); + this.buttonSave.Location = new System.Drawing.Point(195, 184); this.buttonSave.Name = "buttonSave"; this.buttonSave.Size = new System.Drawing.Size(75, 23); this.buttonSave.TabIndex = 7; @@ -109,11 +111,31 @@ this.buttonSave.UseVisualStyleBackColor = true; this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // + // comboBoxClient + // + this.comboBoxClient.FormattingEnabled = true; + this.comboBoxClient.Location = new System.Drawing.Point(105, 146); + this.comboBoxClient.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxClient.Name = "comboBoxClient"; + this.comboBoxClient.Size = new System.Drawing.Size(249, 23); + this.comboBoxClient.TabIndex = 11; + // + // labelClient + // + this.labelClient.AutoSize = true; + this.labelClient.Location = new System.Drawing.Point(24, 146); + this.labelClient.Name = "labelClient"; + this.labelClient.Size = new System.Drawing.Size(49, 15); + this.labelClient.TabIndex = 10; + this.labelClient.Text = "Клиент:"; + // // FormCreateOrder // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(361, 168); + this.ClientSize = new System.Drawing.Size(367, 223); + this.Controls.Add(this.comboBoxClient); + this.Controls.Add(this.labelClient); this.Controls.Add(this.buttonSave); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.textBoxSum); @@ -140,5 +162,7 @@ private TextBox textBoxSum; private Button buttonCancel; private Button buttonSave; + private ComboBox comboBoxClient; + private Label labelClient; } } \ No newline at end of file diff --git a/ComputersShop/FormCreateOrder.cs b/ComputersShop/FormCreateOrder.cs index 2e6bb32..7527c9c 100644 --- a/ComputersShop/FormCreateOrder.cs +++ b/ComputersShop/FormCreateOrder.cs @@ -19,12 +19,14 @@ namespace ComputersShop private readonly ILogger _logger; private readonly IComputerLogic _logicC; private readonly IOrderLogic _logicO; - public FormCreateOrder(ILogger logger, IComputerLogic logicC, IOrderLogic logicO) + private readonly IClientLogic _logicCl; + public FormCreateOrder(ILogger logger, IComputerLogic logicC, IOrderLogic logicO, IClientLogic logicCl) { InitializeComponent(); _logger = logger; _logicC = logicC; _logicO = logicO; + _logicCl = logicCl; } private void FormCreateOrder_Load(object sender, EventArgs e) { @@ -46,6 +48,25 @@ namespace ComputersShop _logger.LogError(ex, "Ошибка загрузки списка компьютеров"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } + + _logger.LogInformation("Загрузка клиентов для заказа"); + try + { + var list = _logicCl.ReadList(null); + if (list != null) + { + comboBoxClient.DisplayMember = "ClientFIO"; + comboBoxClient.ValueMember = "Id"; + comboBoxClient.DataSource = list; + comboBoxClient.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void CalcSum() { @@ -89,6 +110,11 @@ namespace ComputersShop MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (comboBoxClient.SelectedValue == null) + { + MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } _logger.LogInformation("Создание заказа"); try { @@ -96,6 +122,7 @@ namespace ComputersShop { ComputerId = Convert.ToInt32(comboBoxComputer.SelectedValue), ComputerName = comboBoxComputer.Text, + ClientId = Convert.ToInt32(comboBoxClient.SelectedValue), Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/ComputersShop/FormMain.Designer.cs b/ComputersShop/FormMain.Designer.cs index 69c4149..c9635a5 100644 --- a/ComputersShop/FormMain.Designer.cs +++ b/ComputersShop/FormMain.Designer.cs @@ -42,6 +42,7 @@ this.ButtonOrderReady = new System.Windows.Forms.Button(); this.ButtonIssuedOrder = new System.Windows.Forms.Button(); this.ButtonRef = new System.Windows.Forms.Button(); + this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -61,7 +62,8 @@ // this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компьютерыToolStripMenuItem, - this.компонентыToolStripMenuItem}); + this.компонентыToolStripMenuItem, + this.клиентыToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -69,14 +71,14 @@ // компьютерыToolStripMenuItem // this.компьютерыToolStripMenuItem.Name = "компьютерыToolStripMenuItem"; - this.компьютерыToolStripMenuItem.Size = new System.Drawing.Size(147, 22); + this.компьютерыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.компьютерыToolStripMenuItem.Text = "Компьютеры"; this.компьютерыToolStripMenuItem.Click += new System.EventHandler(this.КомпьютерыToolStripMenuItem_Click); // // компонентыToolStripMenuItem // this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(147, 22); + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.компонентыToolStripMenuItem.Text = "Компоненты"; this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // @@ -170,6 +172,13 @@ this.ButtonRef.UseVisualStyleBackColor = true; this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); // + // клиентыToolStripMenuItem + // + this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.клиентыToolStripMenuItem.Text = "Клиенты"; + this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -210,5 +219,6 @@ private ToolStripMenuItem списокКомпонентовToolStripMenuItem; private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; + private ToolStripMenuItem клиентыToolStripMenuItem; } } \ No newline at end of file diff --git a/ComputersShop/FormMain.cs b/ComputersShop/FormMain.cs index 542db85..ff3ee2d 100644 --- a/ComputersShop/FormMain.cs +++ b/ComputersShop/FormMain.cs @@ -41,6 +41,7 @@ namespace ComputersShop { dataGridView.DataSource = list; dataGridView.Columns["ComputerId"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); } @@ -205,5 +206,14 @@ namespace ComputersShop form.ShowDialog(); } } + + private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + if (service is FormClients form) + { + form.ShowDialog(); + } + } } } diff --git a/ComputersShop/Program.cs b/ComputersShop/Program.cs index c747e81..ccc0d28 100644 --- a/ComputersShop/Program.cs +++ b/ComputersShop/Program.cs @@ -38,16 +38,20 @@ namespace ComputersShop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient();