From e0e54cf87271940d976dfb2c3387a9c5dca87ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Wed, 5 Apr 2023 21:03:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20CRU?= =?UTF-8?q?D=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/WorkLogic.cs | 49 +++++-- .../SearchModels/WorkSearchModel.cs | 1 + .../ViewModels/WorkViewModel.cs | 2 + .../Implements/WorkStorage.cs | 87 ++++++++++++ .../Implements/WorkerStorage.cs | 25 +++- CarService/CarServiceDatabase/Models/Work.cs | 15 ++- .../FormAddWorkTest.Designer.cs | 127 ++++++++++++++++++ CarService/CarServiceView/FormAddWorkTest.cs | 33 +++++ .../CarServiceView/FormAddWorkTest.resx | 60 +++++++++ .../CarServiceView/FormWorkTest.Designer.cs | 108 +++++++++++++++ CarService/CarServiceView/FormWorkTest.cs | 47 +++++++ CarService/CarServiceView/FormWorkTest.resx | 63 +++++++++ CarService/CarServiceView/Program.cs | 5 +- 13 files changed, 599 insertions(+), 23 deletions(-) create mode 100644 CarService/CarServiceDatabase/Implements/WorkStorage.cs create mode 100644 CarService/CarServiceView/FormAddWorkTest.Designer.cs create mode 100644 CarService/CarServiceView/FormAddWorkTest.cs create mode 100644 CarService/CarServiceView/FormAddWorkTest.resx create mode 100644 CarService/CarServiceView/FormWorkTest.Designer.cs create mode 100644 CarService/CarServiceView/FormWorkTest.cs create mode 100644 CarService/CarServiceView/FormWorkTest.resx diff --git a/CarService/CarServiceBusinessLogic/BusinessLogics/WorkLogic.cs b/CarService/CarServiceBusinessLogic/BusinessLogics/WorkLogic.cs index f0eeca5..11d9c59 100644 --- a/CarService/CarServiceBusinessLogic/BusinessLogics/WorkLogic.cs +++ b/CarService/CarServiceBusinessLogic/BusinessLogics/WorkLogic.cs @@ -10,16 +10,16 @@ namespace CarServiceBusinessLogic.BusinessLogics public class WorkLogic : IWorkLogic { private readonly ILogger _logger; - private readonly IWorkStorage _customerStorage; + private readonly IWorkStorage _workStorage; public WorkLogic(ILogger logger, IWorkStorage customerStorage) { _logger = logger; - _customerStorage = customerStorage; + _workStorage = customerStorage; } public List? ReadList(WorkSearchModel? model) { _logger.LogInformation("ReadList. Id: {Id}", model?.Id); - var list = model == null ? _customerStorage.GetFullList() : _customerStorage.GetFilteredList(model); + var list = model == null ? _workStorage.GetFullList() : _workStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -35,7 +35,7 @@ namespace CarServiceBusinessLogic.BusinessLogics throw new ArgumentNullException(nameof(model)); } _logger.LogInformation("ReadElement. Id: {Id}", model.Id); - var element = _customerStorage.GetElement(model); + var element = _workStorage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement element not found"); @@ -47,7 +47,7 @@ namespace CarServiceBusinessLogic.BusinessLogics public bool Create(WorkBindingModel model) { CheckModel(model); - if (_customerStorage.Insert(model) == null) + if (_workStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; @@ -57,7 +57,7 @@ namespace CarServiceBusinessLogic.BusinessLogics public bool Update(WorkBindingModel model) { CheckModel(model); - if (_customerStorage.Update(model) == null) + if (_workStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; @@ -67,8 +67,8 @@ namespace CarServiceBusinessLogic.BusinessLogics public bool Delete(WorkBindingModel model) { CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_customerStorage.Delete(model) == null) + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_workStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; @@ -79,12 +79,43 @@ namespace CarServiceBusinessLogic.BusinessLogics { if (model == null) { - throw new ArgumentNullException(nameof(model)); + throw new ArgumentException(nameof(model)); } if (!withParams) { return; } + //Заполнено ли название? + if (string.IsNullOrEmpty(model.Name)) + { + _logger.LogWarning("Work name is empty"); + throw new ArgumentException("Не введено название"); + } + //Название уникально? + var existingWork = _workStorage.GetElement(new() { Name = model.Name }); + if (existingWork != null) + { + _logger.LogWarning("Work name is not unique"); + throw new ArgumentException("Работа с таким названием уже есть"); + } + //Название не больше 60 символов? + if (model.Name.Length > 60) + { + _logger.LogWarning("Work name's length > 60"); + throw new ArgumentException("Не введено название"); + } + //Цена больше 0? + if (model.Price <= 0) + { + _logger.LogWarning("Work Price is <= 0"); + throw new ArgumentException("Цена должна быть больше 0"); + } + //Длительность больше 0? + if (model.Duration <= 0) + { + _logger.LogWarning("Work Duration is <= 0"); + throw new ArgumentException("Длительность должна быть больше 0"); + } _logger.LogInformation("Work. Id: {Id}", model.Id); } } diff --git a/CarService/CarServiceContracts/SearchModels/WorkSearchModel.cs b/CarService/CarServiceContracts/SearchModels/WorkSearchModel.cs index ca3fe67..b88f0bd 100644 --- a/CarService/CarServiceContracts/SearchModels/WorkSearchModel.cs +++ b/CarService/CarServiceContracts/SearchModels/WorkSearchModel.cs @@ -3,5 +3,6 @@ public class WorkSearchModel { public int? Id { get; set; } + public string? Name { get; set; } } } diff --git a/CarService/CarServiceContracts/ViewModels/WorkViewModel.cs b/CarService/CarServiceContracts/ViewModels/WorkViewModel.cs index ad81912..27b2acd 100644 --- a/CarService/CarServiceContracts/ViewModels/WorkViewModel.cs +++ b/CarService/CarServiceContracts/ViewModels/WorkViewModel.cs @@ -13,5 +13,7 @@ namespace CarServiceContracts.ViewModels [DisplayName("Длительность")] public decimal Duration { get; set; } public int WorkerId { get; set; } + [DisplayName("Работник")] + public string WorkerName { get; set; } = string.Empty; } } diff --git a/CarService/CarServiceDatabase/Implements/WorkStorage.cs b/CarService/CarServiceDatabase/Implements/WorkStorage.cs new file mode 100644 index 0000000..7dee7aa --- /dev/null +++ b/CarService/CarServiceDatabase/Implements/WorkStorage.cs @@ -0,0 +1,87 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.SearchModels; +using CarServiceContracts.StorageContracts; +using CarServiceContracts.ViewModels; +using CarServiceDatabase.Models; +using Microsoft.EntityFrameworkCore; + +namespace CarServiceDatabase.Implements +{ + public class WorkStorage : IWorkStorage + { + public List GetFullList() + { + using var context = new CarServiceDbContext(); + return context.Works + .Include(x => x.Worker) + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(WorkSearchModel model) + { + using var context = new CarServiceDbContext(); + return context.Works + .Where(x => x.Id == model.Id) + .Include(x => x.Worker) + .Select(x => x.GetViewModel) + .ToList(); + } + public WorkViewModel? GetElement(WorkSearchModel model) + { + if (model == null) + { + return null; + } + using var context = new CarServiceDbContext(); + if (model.Id.HasValue)//сначала ищем по Id + { + return context.Works + .Include(x => x.Worker) + .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + if (!string.IsNullOrEmpty(model.Name))//затем по названию + { + return context.Works + .Include(x => x.Worker) + .FirstOrDefault(x => x.Name == model.Name)?.GetViewModel; + } + return null; + } + public WorkViewModel? Insert(WorkBindingModel model) + { + using var context = new CarServiceDbContext(); + var newWork = Work.Create(context, model); + if (newWork != null) + { + context.Works.Add(newWork); + context.SaveChanges(); + return newWork.GetViewModel; + } + return null; + } + public WorkViewModel? Update(WorkBindingModel model) + { + using var context = new CarServiceDbContext(); + var work = context.Works.FirstOrDefault(x => x.Id == model.Id); + if (work == null) + { + return null; + } + work.Update(context, model); + context.SaveChanges(); + return work.GetViewModel; + } + public WorkViewModel? Delete(WorkBindingModel model) + { + using var context = new CarServiceDbContext(); + var work = context.Works.FirstOrDefault(x => x.Id == model.Id); + if (work == null) + { + return null; + } + context.Works.Remove(work); + context.SaveChanges(); + return work.GetViewModel; + } + } +} \ No newline at end of file diff --git a/CarService/CarServiceDatabase/Implements/WorkerStorage.cs b/CarService/CarServiceDatabase/Implements/WorkerStorage.cs index c3f287b..d223a58 100644 --- a/CarService/CarServiceDatabase/Implements/WorkerStorage.cs +++ b/CarService/CarServiceDatabase/Implements/WorkerStorage.cs @@ -11,15 +11,24 @@ namespace CarServiceDatabase.Implements public List GetFullList() { using var context = new CarServiceDbContext(); - return context.Workers.Select(x => x.GetViewModel).ToList(); + return context.Workers + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(WorkerSearchModel model) { using var context = new CarServiceDbContext(); - return context.Workers.Select(x => x.GetViewModel).Where(x => x.Id == model.Id).ToList(); + return context.Workers + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); } public WorkerViewModel? GetElement(WorkerSearchModel model) { + if (model == null) + { + return null; + } using var context = new CarServiceDbContext(); if (model.Id.HasValue)//Сначала ищем по Id { @@ -27,11 +36,13 @@ namespace CarServiceDatabase.Implements } else if (!string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password))//Затем по логину (для проверки уникальности) { - return context.Workers.FirstOrDefault(x => x.Login == model.Login)?.GetViewModel; + return context.Workers + .FirstOrDefault(x => x.Login == model.Login)?.GetViewModel; } else if (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password))//Затем по логину и паролю (для входа) { - return context.Workers.FirstOrDefault(x => x.Login == model.Login && x.Password == model.Password)?.GetViewModel; + return context.Workers + .FirstOrDefault(x => x.Login == model.Login && x.Password == model.Password)?.GetViewModel; } return null; } @@ -50,7 +61,8 @@ namespace CarServiceDatabase.Implements public WorkerViewModel? Update(WorkerBindingModel model) { using var context = new CarServiceDbContext(); - var worker = context.Workers.FirstOrDefault(x => x.Id == model.Id); + var worker = context.Workers + .FirstOrDefault(x => x.Id == model.Id); if (worker == null) { return null; @@ -62,7 +74,8 @@ namespace CarServiceDatabase.Implements public WorkerViewModel? Delete(WorkerBindingModel model) { using var context = new CarServiceDbContext(); - var worker = context.Workers.FirstOrDefault(x => x.Id == model.Id); + var worker = context.Workers + .FirstOrDefault(x => x.Id == model.Id); if (worker == null) { return null; diff --git a/CarService/CarServiceDatabase/Models/Work.cs b/CarService/CarServiceDatabase/Models/Work.cs index 4bd8c70..a19958d 100644 --- a/CarService/CarServiceDatabase/Models/Work.cs +++ b/CarService/CarServiceDatabase/Models/Work.cs @@ -23,7 +23,7 @@ namespace CarServiceDatabase.Models [ForeignKey("WorkId")] public virtual List WorksInRequest { get; set; } = new(); public virtual Worker Worker { get; set; } = new(); - public static Work? Create(WorkBindingModel? model) + public static Work? Create(CarServiceDbContext context, WorkBindingModel? model) { if (model == null) { @@ -35,10 +35,10 @@ namespace CarServiceDatabase.Models Name = model.Name, Price = model.Price, Duration = model.Duration, - WorkerId = model.WorkerId + Worker = context.Workers.First(x => x.Id == model.WorkerId) }; } - public static Work Create(WorkViewModel model) + public static Work Create(CarServiceDbContext context, WorkViewModel model) { return new() { @@ -46,10 +46,10 @@ namespace CarServiceDatabase.Models Name = model.Name, Price = model.Price, Duration = model.Duration, - WorkerId = model.WorkerId + Worker = context.Workers.First(x => x.Id == model.WorkerId) }; } - public void Update(WorkBindingModel? model) + public void Update(CarServiceDbContext context, WorkBindingModel? model) { if (model == null) { @@ -59,7 +59,7 @@ namespace CarServiceDatabase.Models Name = model.Name; Price = model.Price; Duration = model.Duration; - WorkerId = model.WorkerId; + Worker = context.Workers.First(x => x.Id == model.WorkerId); } public WorkViewModel GetViewModel => new() { @@ -67,7 +67,8 @@ namespace CarServiceDatabase.Models Name = Name, Price = Price, Duration = Duration, - WorkerId = WorkerId + WorkerId = WorkerId, + WorkerName = Worker.Name + " " + Worker.Surname }; } } diff --git a/CarService/CarServiceView/FormAddWorkTest.Designer.cs b/CarService/CarServiceView/FormAddWorkTest.Designer.cs new file mode 100644 index 0000000..f110913 --- /dev/null +++ b/CarService/CarServiceView/FormAddWorkTest.Designer.cs @@ -0,0 +1,127 @@ +namespace CarServiceView +{ + partial class FormAddWorkTest + { + /// + /// 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.textBoxName = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxDuration = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(126, 16); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(100, 23); + this.textBoxName.TabIndex = 0; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(30, 19); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(90, 15); + this.label1.TabIndex = 1; + this.label1.Text = "Наименование"; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(126, 45); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(100, 23); + this.textBoxCost.TabIndex = 0; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(30, 48); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(67, 15); + this.label2.TabIndex = 1; + this.label2.Text = "Стоимость"; + // + // textBoxDuration + // + this.textBoxDuration.Location = new System.Drawing.Point(126, 74); + this.textBoxDuration.Name = "textBoxDuration"; + this.textBoxDuration.Size = new System.Drawing.Size(100, 23); + this.textBoxDuration.TabIndex = 0; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(30, 77); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(84, 15); + this.label3.TabIndex = 1; + this.label3.Text = "Длительность"; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(54, 135); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(75, 23); + this.buttonAdd.TabIndex = 2; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // FormAddWorkTest + // + 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.buttonAdd); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBoxDuration); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Name = "FormAddWorkTest"; + this.Text = "FormAddWorkTest"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxName; + private Label label1; + private TextBox textBoxCost; + private Label label2; + private TextBox textBoxDuration; + private Label label3; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/CarService/CarServiceView/FormAddWorkTest.cs b/CarService/CarServiceView/FormAddWorkTest.cs new file mode 100644 index 0000000..f6ae35d --- /dev/null +++ b/CarService/CarServiceView/FormAddWorkTest.cs @@ -0,0 +1,33 @@ +using CarServiceContracts.BusinessLogicsContracts; + +namespace CarServiceView +{ + public partial class FormAddWorkTest : Form + { + IWorkLogic _workLogic; + public FormAddWorkTest(IWorkLogic workLogic) + { + _workLogic = workLogic; + InitializeComponent(); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + try + { + + _workLogic.Create(new() + { + Name = textBoxName.Text, + Price = Convert.ToDecimal(textBoxCost.Text), + Duration = Convert.ToDecimal(textBoxDuration.Text), + WorkerId = 1 + }); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/CarService/CarServiceView/FormAddWorkTest.resx b/CarService/CarServiceView/FormAddWorkTest.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/CarService/CarServiceView/FormAddWorkTest.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/FormWorkTest.Designer.cs b/CarService/CarServiceView/FormWorkTest.Designer.cs new file mode 100644 index 0000000..4dbec64 --- /dev/null +++ b/CarService/CarServiceView/FormWorkTest.Designer.cs @@ -0,0 +1,108 @@ +namespace CarServiceView +{ + partial class FormWorkTest + { + /// + /// 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.dataGridView = new System.Windows.Forms.DataGridView(); + 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(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 27); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(798, 421); + this.dataGridView.TabIndex = 3; + // + // 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 = 4; + 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 = "Удалить"; + this.deleteToolStripMenuItem.Click += new System.EventHandler(this.deleteToolStripMenuItem_Click); + // + // FormWorkTest + // + 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 = "FormWorkTest"; + this.Text = "FormGridViewTest"; + this.Load += new System.EventHandler(this.FormWorkTest_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DataGridView dataGridView; + private MenuStrip menuStrip; + private ToolStripMenuItem addToolStripMenuItem; + private ToolStripMenuItem updateToolStripMenuItem; + private ToolStripMenuItem deleteToolStripMenuItem; + } +} \ No newline at end of file diff --git a/CarService/CarServiceView/FormWorkTest.cs b/CarService/CarServiceView/FormWorkTest.cs new file mode 100644 index 0000000..f6ccf9b --- /dev/null +++ b/CarService/CarServiceView/FormWorkTest.cs @@ -0,0 +1,47 @@ +using CarServiceContracts.BusinessLogicsContracts; +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 CarServiceView +{ + public partial class FormWorkTest : Form + { + IWorkLogic _workLogic; + public FormWorkTest(IWorkLogic workLogic) + { + _workLogic = workLogic; + InitializeComponent(); + } + private void FormWorkTest_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + var list = _workLogic.ReadList(null); + dataGridView.DataSource = list; + } + + private void addToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAddWorkTest)); + if (service is FormAddWorkTest form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void deleteToolStripMenuItem_Click(object sender, EventArgs e) + { + + } + } +} diff --git a/CarService/CarServiceView/FormWorkTest.resx b/CarService/CarServiceView/FormWorkTest.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/CarService/CarServiceView/FormWorkTest.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 54ddef3..fc8cc77 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) { @@ -43,8 +43,11 @@ namespace CarServiceView services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file