diff --git a/CarService/CarServiceContracts/ViewModels/ItemForRepairViewModel.cs b/CarService/CarServiceContracts/ViewModels/ItemForRepairViewModel.cs index 3cb4931..f318e08 100644 --- a/CarService/CarServiceContracts/ViewModels/ItemForRepairViewModel.cs +++ b/CarService/CarServiceContracts/ViewModels/ItemForRepairViewModel.cs @@ -9,6 +9,9 @@ namespace CarServiceContracts.ViewModels [DisplayName("Количество")] public int Count { get; set; } public int ItemId { get; set; } + [DisplayName("Номер заявки")] public int RepairRequestId { get; set; } + [DisplayName("Статья затрат")] + public string ItemName { get; set; } = string.Empty; } } diff --git a/CarService/CarServiceDatabase/Implements/ItemForRepairStorage.cs b/CarService/CarServiceDatabase/Implements/ItemForRepairStorage.cs new file mode 100644 index 0000000..bef70f1 --- /dev/null +++ b/CarService/CarServiceDatabase/Implements/ItemForRepairStorage.cs @@ -0,0 +1,81 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.SearchModels; +using CarServiceContracts.StorageContracts; +using CarServiceContracts.ViewModels; +using CarServiceDatabase.Models; +using Microsoft.EntityFrameworkCore; + +namespace CarServiceDatabase.Implements +{ + public class ItemForRepairStorage : IItemForRepairStorage + { + public List GetFullList() + { + using var context = new CarServiceDbContext(); + return context.ItemsForRepair + .Include(x => x.Item) + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ItemForRepairSearchModel model) + { + using var context = new CarServiceDbContext(); + return context.ItemsForRepair + .Where(x => x.Id == model.Id) + .Include(x => x.Item) + .Select(x => x.GetViewModel) + .ToList(); + } + public ItemForRepairViewModel? GetElement(ItemForRepairSearchModel model) + { + if (model == null) + { + return null; + } + using var context = new CarServiceDbContext(); + if (model.Id.HasValue) + { + return context.ItemsForRepair + .Include(x => x.Item) + .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + return null; + } + public ItemForRepairViewModel? Insert(ItemForRepairBindingModel model) + { + using var context = new CarServiceDbContext(); + var newItemForRepair = ItemForRepair.Create(context, model); + if (newItemForRepair != null) + { + context.ItemsForRepair.Add(newItemForRepair); + context.SaveChanges(); + return newItemForRepair.GetViewModel; + } + return null; + } + public ItemForRepairViewModel? Update(ItemForRepairBindingModel model) + { + using var context = new CarServiceDbContext(); + var itemForRepair = context.ItemsForRepair.FirstOrDefault(x => x.Id == model.Id); + if (itemForRepair == null) + { + return null; + } + itemForRepair.Update(context, model); + context.SaveChanges(); + return itemForRepair.GetViewModel; + } + public ItemForRepairViewModel? Delete(ItemForRepairBindingModel model) + { + using var context = new CarServiceDbContext(); + var itemForRepair = context.ItemsForRepair.FirstOrDefault(x => x.Id == model.Id); + if (itemForRepair == null) + { + return null; + } + context.ItemsForRepair.Remove(itemForRepair); + context.SaveChanges(); + return itemForRepair.GetViewModel; + } + } +} diff --git a/CarService/CarServiceDatabase/Implements/RepairRequestStorage.cs b/CarService/CarServiceDatabase/Implements/RepairRequestStorage.cs new file mode 100644 index 0000000..5a26d9a --- /dev/null +++ b/CarService/CarServiceDatabase/Implements/RepairRequestStorage.cs @@ -0,0 +1,78 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.SearchModels; +using CarServiceContracts.StorageContracts; +using CarServiceContracts.ViewModels; +using CarServiceDatabase.Models; +using Microsoft.EntityFrameworkCore; + +namespace CarServiceDatabase.Implements +{ + public class RepairRequestStorage : IRepairRequestStorage + { + public List GetFullList() + { + using var context = new CarServiceDbContext(); + return context.RepairRequests + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(RepairRequestSearchModel model) + { + using var context = new CarServiceDbContext(); + return context.RepairRequests + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + public RepairRequestViewModel? GetElement(RepairRequestSearchModel model) + { + if (model == null) + { + return null; + } + using var context = new CarServiceDbContext(); + if (model.Id.HasValue) + { + return context.RepairRequests + .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + return null; + } + public RepairRequestViewModel? Insert(RepairRequestBindingModel model) + { + using var context = new CarServiceDbContext(); + var newRepairRequest = RepairRequest.Create(model); + if (newRepairRequest != null) + { + context.RepairRequests.Add(newRepairRequest); + context.SaveChanges(); + return newRepairRequest.GetViewModel; + } + return null; + } + public RepairRequestViewModel? Update(RepairRequestBindingModel model) + { + using var context = new CarServiceDbContext(); + var repairRequest = context.RepairRequests.FirstOrDefault(x => x.Id == model.Id); + if (repairRequest == null) + { + return null; + } + repairRequest.Update(model); + context.SaveChanges(); + return repairRequest.GetViewModel; + } + public RepairRequestViewModel? Delete(RepairRequestBindingModel model) + { + using var context = new CarServiceDbContext(); + var repairRequest = context.RepairRequests.FirstOrDefault(x => x.Id == model.Id); + if (repairRequest == null) + { + return null; + } + context.RepairRequests.Remove(repairRequest); + context.SaveChanges(); + return repairRequest.GetViewModel; + } + } +} diff --git a/CarService/CarServiceDatabase/Migrations/20230405185109_DateFixMigration.Designer.cs b/CarService/CarServiceDatabase/Migrations/20230405185109_DateFixMigration.Designer.cs new file mode 100644 index 0000000..018d774 --- /dev/null +++ b/CarService/CarServiceDatabase/Migrations/20230405185109_DateFixMigration.Designer.cs @@ -0,0 +1,404 @@ +// +using System; +using CarServiceDatabase; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CarServiceDatabase.Migrations +{ + [DbContext(typeof(CarServiceDbContext))] + [Migration("20230405185109_DateFixMigration")] + partial class DateFixMigration + { + /// + 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("CarServiceDatabase.Models.Customer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Customers"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Item", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal (10,2)"); + + b.Property("WorkerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WorkerId"); + + b.ToTable("Items"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.ItemForRepair", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ItemId") + .HasColumnType("int"); + + b.Property("RepairRequestId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ItemId"); + + b.HasIndex("RepairRequestId"); + + b.ToTable("ItemsForRepair"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.RepairRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DateCreated") + .HasColumnType("date"); + + b.Property("VehicleId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("VehicleId"); + + b.ToTable("RepairRequests"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Vehicle", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CustomerId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Plate") + .HasColumnType("nvarchar(max)"); + + b.Property("VIN") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.ToTable("Vehicles"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Work", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Duration") + .HasColumnType("decimal (3,1)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal (10,2)"); + + b.Property("WorkerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WorkerId"); + + b.ToTable("Works"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.WorkInRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("decimal (10,2)"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("RepairRequestId") + .HasColumnType("int"); + + b.Property("WorkId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("RepairRequestId"); + + b.HasIndex("WorkId"); + + b.ToTable("WorksInRequest"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.WorkPayment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DatePayment") + .HasColumnType("date"); + + b.Property("Sum") + .HasColumnType("decimal (10,2)"); + + b.Property("WorkInRequestId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WorkInRequestId"); + + b.ToTable("WorkPayments"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Worker", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Workers"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Item", b => + { + b.HasOne("CarServiceDatabase.Models.Worker", "Worker") + .WithMany("Items") + .HasForeignKey("WorkerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Worker"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.ItemForRepair", b => + { + b.HasOne("CarServiceDatabase.Models.Item", "Item") + .WithMany("ItemsForRepair") + .HasForeignKey("ItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarServiceDatabase.Models.RepairRequest", "RepairRequest") + .WithMany("ItemsForRepair") + .HasForeignKey("RepairRequestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Item"); + + b.Navigation("RepairRequest"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.RepairRequest", b => + { + b.HasOne("CarServiceDatabase.Models.Vehicle", "Vehicle") + .WithMany("RepairRequests") + .HasForeignKey("VehicleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Vehicle"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Vehicle", b => + { + b.HasOne("CarServiceDatabase.Models.Customer", "Customer") + .WithMany("Vehicles") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Customer"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Work", b => + { + b.HasOne("CarServiceDatabase.Models.Worker", "Worker") + .WithMany("Works") + .HasForeignKey("WorkerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Worker"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.WorkInRequest", b => + { + b.HasOne("CarServiceDatabase.Models.RepairRequest", "RepairRequest") + .WithMany("WorksInRequest") + .HasForeignKey("RepairRequestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarServiceDatabase.Models.Work", "Work") + .WithMany("WorksInRequest") + .HasForeignKey("WorkId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("RepairRequest"); + + b.Navigation("Work"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.WorkPayment", b => + { + b.HasOne("CarServiceDatabase.Models.WorkInRequest", "WorkInRequest") + .WithMany("WorkPayments") + .HasForeignKey("WorkInRequestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("WorkInRequest"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Customer", b => + { + b.Navigation("Vehicles"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Item", b => + { + b.Navigation("ItemsForRepair"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.RepairRequest", b => + { + b.Navigation("ItemsForRepair"); + + b.Navigation("WorksInRequest"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Vehicle", b => + { + b.Navigation("RepairRequests"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Work", b => + { + b.Navigation("WorksInRequest"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.WorkInRequest", b => + { + b.Navigation("WorkPayments"); + }); + + modelBuilder.Entity("CarServiceDatabase.Models.Worker", b => + { + b.Navigation("Items"); + + b.Navigation("Works"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CarService/CarServiceDatabase/Migrations/20230405185109_DateFixMigration.cs b/CarService/CarServiceDatabase/Migrations/20230405185109_DateFixMigration.cs new file mode 100644 index 0000000..bee46e9 --- /dev/null +++ b/CarService/CarServiceDatabase/Migrations/20230405185109_DateFixMigration.cs @@ -0,0 +1,51 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CarServiceDatabase.Migrations +{ + /// + public partial class DateFixMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "DatePayment", + table: "WorkPayments", + type: "date", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "datetime2"); + + migrationBuilder.AlterColumn( + name: "DateCreated", + table: "RepairRequests", + type: "date", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "datetime2"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "DatePayment", + table: "WorkPayments", + type: "datetime2", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "date"); + + migrationBuilder.AlterColumn( + name: "DateCreated", + table: "RepairRequests", + type: "datetime2", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "date"); + } + } +} diff --git a/CarService/CarServiceDatabase/Migrations/CarServiceDbContextModelSnapshot.cs b/CarService/CarServiceDatabase/Migrations/CarServiceDbContextModelSnapshot.cs index 3dcb2d0..97b1d1c 100644 --- a/CarService/CarServiceDatabase/Migrations/CarServiceDbContextModelSnapshot.cs +++ b/CarService/CarServiceDatabase/Migrations/CarServiceDbContextModelSnapshot.cs @@ -114,7 +114,7 @@ namespace CarServiceDatabase.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("DateCreated") - .HasColumnType("datetime2"); + .HasColumnType("date"); b.Property("VehicleId") .HasColumnType("int"); @@ -220,7 +220,7 @@ namespace CarServiceDatabase.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("DatePayment") - .HasColumnType("datetime2"); + .HasColumnType("date"); b.Property("Sum") .HasColumnType("decimal (10,2)"); diff --git a/CarService/CarServiceDatabase/Models/ItemForRepair.cs b/CarService/CarServiceDatabase/Models/ItemForRepair.cs index f4b0417..ca7f44f 100644 --- a/CarService/CarServiceDatabase/Models/ItemForRepair.cs +++ b/CarService/CarServiceDatabase/Models/ItemForRepair.cs @@ -16,7 +16,7 @@ namespace CarServiceDatabase.Models public int RepairRequestId { get; private set; } public virtual Item Item { get; set; } = new(); public virtual RepairRequest RepairRequest { get; set; } = new(); - public static ItemForRepair? Create(ItemForRepairBindingModel? model) + public static ItemForRepair? Create(CarServiceDbContext context, ItemForRepairBindingModel? model) { if (model == null) { @@ -26,21 +26,21 @@ namespace CarServiceDatabase.Models { Id = model.Id, Count = model.Count, - ItemId = model.ItemId, - RepairRequestId = model.RepairRequestId + Item = context.Items.First(x => x.Id == model.ItemId), + RepairRequest = context.RepairRequests.First(x => x.Id == model.RepairRequestId) }; } - public static ItemForRepair Create(ItemForRepairViewModel model) + public static ItemForRepair Create(CarServiceDbContext context, ItemForRepairViewModel model) { return new() { Id = model.Id, Count = model.Count, - ItemId = model.ItemId, - RepairRequestId = model.RepairRequestId + Item = context.Items.First(x => x.Id == model.ItemId), + RepairRequest = context.RepairRequests.First(x => x.Id == model.RepairRequestId) }; } - public void Update(ItemForRepairBindingModel? model) + public void Update(CarServiceDbContext context, ItemForRepairBindingModel? model) { if (model == null) { @@ -56,7 +56,8 @@ namespace CarServiceDatabase.Models Id = Id, Count = Count, ItemId = ItemId, - RepairRequestId = RepairRequestId + RepairRequestId = RepairRequestId, + ItemName = Item.Name }; } } diff --git a/CarService/CarServiceDatabase/Models/RepairRequest.cs b/CarService/CarServiceDatabase/Models/RepairRequest.cs index d0e68b7..4f47592 100644 --- a/CarService/CarServiceDatabase/Models/RepairRequest.cs +++ b/CarService/CarServiceDatabase/Models/RepairRequest.cs @@ -9,7 +9,7 @@ namespace CarServiceDatabase.Models public class RepairRequest : IRepairRequestModel { public int Id { get; private set; } - [Required] + [Required, Column(TypeName = "date")] public DateTime DateCreated { get; private set; } = DateTime.Now; [Required] public int VehicleId { get; private set; } diff --git a/CarService/CarServiceDatabase/Models/WorkPayment.cs b/CarService/CarServiceDatabase/Models/WorkPayment.cs index 1d0ee23..cdde6c1 100644 --- a/CarService/CarServiceDatabase/Models/WorkPayment.cs +++ b/CarService/CarServiceDatabase/Models/WorkPayment.cs @@ -10,7 +10,7 @@ namespace CarServiceDatabase.Models public class WorkPayment : IWorkPaymentModel { public int Id { get; private set; } - [Required] + [Required, Column(TypeName = "date")] public DateTime DatePayment { get; private set; } = DateTime.Now; [Required, Column(TypeName = "decimal (10,2)")] public decimal Sum { get; private set; } diff --git a/CarService/CarServiceView/FormAddItemForRepairTest.Designer.cs b/CarService/CarServiceView/FormAddItemForRepairTest.Designer.cs new file mode 100644 index 0000000..04ac54f --- /dev/null +++ b/CarService/CarServiceView/FormAddItemForRepairTest.Designer.cs @@ -0,0 +1,132 @@ +namespace CarServiceView +{ + partial class FormAddItemForRepairTest + { + /// + /// 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.buttonAdd = new System.Windows.Forms.Button(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.comboBoxRepairRequest = new System.Windows.Forms.ComboBox(); + this.comboBoxItem = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(36, 125); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(75, 23); + this.buttonAdd.TabIndex = 9; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 67); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(72, 15); + this.label3.TabIndex = 6; + this.label3.Text = "Количество"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 38); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(80, 15); + this.label2.TabIndex = 7; + this.label2.Text = "Статья затрат"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(44, 15); + this.label1.TabIndex = 8; + this.label1.Text = "Заявка"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(110, 64); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(100, 23); + this.textBoxCount.TabIndex = 3; + // + // comboBoxRepairRequest + // + this.comboBoxRepairRequest.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxRepairRequest.FormattingEnabled = true; + this.comboBoxRepairRequest.Location = new System.Drawing.Point(110, 12); + this.comboBoxRepairRequest.Name = "comboBoxRepairRequest"; + this.comboBoxRepairRequest.Size = new System.Drawing.Size(121, 23); + this.comboBoxRepairRequest.TabIndex = 10; + // + // comboBoxItem + // + this.comboBoxItem.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxItem.FormattingEnabled = true; + this.comboBoxItem.Location = new System.Drawing.Point(110, 38); + this.comboBoxItem.Name = "comboBoxItem"; + this.comboBoxItem.Size = new System.Drawing.Size(121, 23); + this.comboBoxItem.TabIndex = 10; + // + // FormAddItemForRepairTest + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.comboBoxItem); + this.Controls.Add(this.comboBoxRepairRequest); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBoxCount); + this.Name = "FormAddItemForRepairTest"; + this.Text = "FormAddItemForRepairTest"; + this.Load += new System.EventHandler(this.FormAddItemForRepairTest_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonAdd; + private Label label3; + private Label label2; + private Label label1; + private TextBox textBoxCount; + private ComboBox comboBoxRepairRequest; + private ComboBox comboBoxItem; + } +} \ No newline at end of file diff --git a/CarService/CarServiceView/FormAddItemForRepairTest.cs b/CarService/CarServiceView/FormAddItemForRepairTest.cs new file mode 100644 index 0000000..6f93abc --- /dev/null +++ b/CarService/CarServiceView/FormAddItemForRepairTest.cs @@ -0,0 +1,54 @@ +using CarServiceContracts.BusinessLogicsContracts; + +namespace CarServiceView +{ + public partial class FormAddItemForRepairTest : Form + { + IItemLogic _itemLogic; + IRepairRequestLogic _repairRequestLogic; + IItemForRepairLogic _itemForRepairLogic; + public FormAddItemForRepairTest(IItemLogic itemLogic, IRepairRequestLogic repairRequestLogic, IItemForRepairLogic itemForRepairLogic) + { + _itemLogic = itemLogic; + _repairRequestLogic = repairRequestLogic; + _itemForRepairLogic = itemForRepairLogic; + InitializeComponent(); + } + + private void FormAddItemForRepairTest_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + //загружаем заказы + var listRR = _repairRequestLogic.ReadList(null); + if (listRR != null) + { + comboBoxRepairRequest.DisplayMember = "Id"; + comboBoxRepairRequest.ValueMember = "Id"; + comboBoxRepairRequest.DataSource = listRR; + comboBoxRepairRequest.SelectedItem = null; + } + //загружаем статьи затрат + var listI = _itemLogic.ReadList(null); + if (listI != null) + { + comboBoxItem.DisplayMember = "Name"; + comboBoxItem.ValueMember = "Id"; + comboBoxItem.DataSource = listI; + comboBoxItem.SelectedItem = null; + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + _itemForRepairLogic.Create(new() + { + Count = Convert.ToInt32(textBoxCount.Text), + ItemId = Convert.ToInt32(comboBoxItem.SelectedValue), + RepairRequestId = Convert.ToInt32(comboBoxRepairRequest.SelectedValue) + }); + } + } +} diff --git a/CarService/CarServiceView/FormAddItemForRepairTest.resx b/CarService/CarServiceView/FormAddItemForRepairTest.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/CarService/CarServiceView/FormAddItemForRepairTest.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/CarService/CarServiceView/FormItemForRepairTest.Designer.cs b/CarService/CarServiceView/FormItemForRepairTest.Designer.cs new file mode 100644 index 0000000..f6924a1 --- /dev/null +++ b/CarService/CarServiceView/FormItemForRepairTest.Designer.cs @@ -0,0 +1,107 @@ +namespace CarServiceView +{ + partial class FormItemForRepairTest + { + /// + /// 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.menuStrip = new System.Windows.Forms.MenuStrip(); + this.addToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.updateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip + // + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.addToolStripMenuItem, + this.updateToolStripMenuItem, + this.deleteToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(800, 24); + this.menuStrip.TabIndex = 6; + this.menuStrip.Text = "menuStrip1"; + // + // addToolStripMenuItem + // + this.addToolStripMenuItem.Name = "addToolStripMenuItem"; + this.addToolStripMenuItem.Size = new System.Drawing.Size(71, 20); + this.addToolStripMenuItem.Text = "Добавить"; + this.addToolStripMenuItem.Click += new System.EventHandler(this.addToolStripMenuItem_Click); + // + // updateToolStripMenuItem + // + this.updateToolStripMenuItem.Name = "updateToolStripMenuItem"; + this.updateToolStripMenuItem.Size = new System.Drawing.Size(73, 20); + this.updateToolStripMenuItem.Text = "Изменить"; + // + // deleteToolStripMenuItem + // + this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem"; + this.deleteToolStripMenuItem.Size = new System.Drawing.Size(63, 20); + this.deleteToolStripMenuItem.Text = "Удалить"; + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 28); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(798, 421); + this.dataGridView.TabIndex = 5; + // + // FormItemForRepairTest + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.menuStrip); + this.Controls.Add(this.dataGridView); + this.Name = "FormItemForRepairTest"; + this.Text = "FormItemForRepairTest"; + this.Load += new System.EventHandler(this.FormWorkInRequestTest_Load); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem addToolStripMenuItem; + private ToolStripMenuItem updateToolStripMenuItem; + private ToolStripMenuItem deleteToolStripMenuItem; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/CarService/CarServiceView/FormItemForRepairTest.cs b/CarService/CarServiceView/FormItemForRepairTest.cs new file mode 100644 index 0000000..468ed6e --- /dev/null +++ b/CarService/CarServiceView/FormItemForRepairTest.cs @@ -0,0 +1,37 @@ +using CarServiceBusinessLogic.BusinessLogics; +using CarServiceContracts.BusinessLogicsContracts; + +namespace CarServiceView +{ + public partial class FormItemForRepairTest : Form + { + IItemForRepairLogic _itemForRepairLogic; + public FormItemForRepairTest(IItemForRepairLogic itemForRepairLogic) + { + _itemForRepairLogic = itemForRepairLogic; + InitializeComponent(); + } + + private void FormWorkInRequestTest_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + var list = _itemForRepairLogic.ReadList(null); + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ItemId"].Visible = false; + } + + private void addToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAddItemForRepairTest)); + if (service is FormAddItemForRepairTest form) + { + form.ShowDialog(); + LoadData(); + } + } + } +} diff --git a/CarService/CarServiceView/FormItemForRepairTest.resx b/CarService/CarServiceView/FormItemForRepairTest.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/CarService/CarServiceView/FormItemForRepairTest.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/CarService/CarServiceView/Program.cs b/CarService/CarServiceView/Program.cs index 57127c3..a944472 100644 --- a/CarService/CarServiceView/Program.cs +++ b/CarService/CarServiceView/Program.cs @@ -19,7 +19,7 @@ namespace CarServiceView var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(_serviceProvider.GetRequiredService()); } private static void ConfigureServices(ServiceCollection services) { @@ -41,12 +41,16 @@ namespace CarServiceView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file