From 2dfdf5d21d49b67bb5d836861c700f0b9492676a Mon Sep 17 00:00:00 2001 From: dasha Date: Wed, 29 Mar 2023 20:00:53 +0400 Subject: [PATCH] ? --- .../BeautySaloonBusinessLogic/OrderLogic.cs | 24 ++ .../BindingModels/OrderBindingModel.cs | 2 +- .../BusinessLogicsContracts/IOrderLogic.cs | 2 + .../StoragesContracts/IOrderStorage.cs | 1 + .../ViewModels/EmployeeViewModel.cs | 2 + .../ViewModels/OrderViewModel.cs | 2 +- .../ViewModels/ServiceViewModel.cs | 2 +- .../BeautySaloonDataModels/IOrderModel.cs | 2 +- .../BeautySaloonDatabaseImplement/Employee.cs | 3 +- .../Implements/ClientStorage.cs | 4 +- .../Implements/EmployeeStorage.cs | 34 ++- .../Implements/OrderStorage.cs | 30 +- .../Implements/PositionStorage.cs | 4 +- .../Implements/ServiceStorage.cs | 4 +- .../BeautySaloonDatabaseImplement/Order.cs | 72 ++++- .../BeautySaloonView/FormClient.Designer.cs | 166 +++++++++++ BeautySaloon/BeautySaloonView/FormClient.cs | 92 ++++++ BeautySaloon/BeautySaloonView/FormClient.resx | 60 ++++ .../FormClientOrders.Designer.cs | 108 +++++++ .../BeautySaloonView/FormClientOrders.cs | 77 +++++ .../BeautySaloonView/FormClientOrders.resx | 60 ++++ .../BeautySaloonView/FormClients.Designer.cs | 136 +++++++++ BeautySaloon/BeautySaloonView/FormClients.cs | 109 +++++++ .../BeautySaloonView/FormClients.resx | 60 ++++ .../FormCreateOrder.Designer.cs | 275 ++++++++++++++++++ .../BeautySaloonView/FormCreateOrder.cs | 221 ++++++++++++++ .../BeautySaloonView/FormCreateOrder.resx | 72 +++++ .../BeautySaloonView/FormEmployee.Designer.cs | 189 ++++++++++++ BeautySaloon/BeautySaloonView/FormEmployee.cs | 127 ++++++++ .../BeautySaloonView/FormEmployee.resx | 60 ++++ .../FormEmployees.Designer.cs | 122 ++++++++ .../BeautySaloonView/FormEmployees.cs | 93 ++++++ .../BeautySaloonView/FormEmployees.resx | 60 ++++ .../BeautySaloonView/FormMain.Designer.cs | 30 +- BeautySaloon/BeautySaloonView/FormMain.cs | 68 ++++- .../FormOrderServices.Designer.cs | 149 ++++++++++ .../BeautySaloonView/FormOrderServices.cs | 99 +++++++ .../BeautySaloonView/FormOrderServices.resx | 60 ++++ .../BeautySaloonView/FormPosition.Designer.cs | 99 +++++++ BeautySaloon/BeautySaloonView/FormPosition.cs | 75 +++++ .../BeautySaloonView/FormPosition.resx | 60 ++++ .../FormPositions.Designer.cs | 122 ++++++++ .../BeautySaloonView/FormPositions.cs | 92 ++++++ .../BeautySaloonView/FormPositions.resx | 60 ++++ .../BeautySaloonView/FormService.Designer.cs | 124 ++++++++ BeautySaloon/BeautySaloonView/FormService.cs | 81 ++++++ .../BeautySaloonView/FormService.resx | 60 ++++ .../BeautySaloonView/FormServices.Designer.cs | 122 ++++++++ BeautySaloon/BeautySaloonView/FormServices.cs | 91 ++++++ .../BeautySaloonView/FormServices.resx | 60 ++++ BeautySaloon/BeautySaloonView/Program.cs | 20 +- 51 files changed, 3695 insertions(+), 52 deletions(-) create mode 100644 BeautySaloon/BeautySaloonView/FormClient.Designer.cs create mode 100644 BeautySaloon/BeautySaloonView/FormClient.cs create mode 100644 BeautySaloon/BeautySaloonView/FormClient.resx create mode 100644 BeautySaloon/BeautySaloonView/FormClientOrders.Designer.cs create mode 100644 BeautySaloon/BeautySaloonView/FormClientOrders.cs create mode 100644 BeautySaloon/BeautySaloonView/FormClientOrders.resx create mode 100644 BeautySaloon/BeautySaloonView/FormClients.Designer.cs create mode 100644 BeautySaloon/BeautySaloonView/FormClients.cs create mode 100644 BeautySaloon/BeautySaloonView/FormClients.resx create mode 100644 BeautySaloon/BeautySaloonView/FormCreateOrder.Designer.cs create mode 100644 BeautySaloon/BeautySaloonView/FormCreateOrder.cs create mode 100644 BeautySaloon/BeautySaloonView/FormCreateOrder.resx create mode 100644 BeautySaloon/BeautySaloonView/FormEmployee.Designer.cs create mode 100644 BeautySaloon/BeautySaloonView/FormEmployee.cs create mode 100644 BeautySaloon/BeautySaloonView/FormEmployee.resx create mode 100644 BeautySaloon/BeautySaloonView/FormEmployees.Designer.cs create mode 100644 BeautySaloon/BeautySaloonView/FormEmployees.cs create mode 100644 BeautySaloon/BeautySaloonView/FormEmployees.resx create mode 100644 BeautySaloon/BeautySaloonView/FormOrderServices.Designer.cs create mode 100644 BeautySaloon/BeautySaloonView/FormOrderServices.cs create mode 100644 BeautySaloon/BeautySaloonView/FormOrderServices.resx create mode 100644 BeautySaloon/BeautySaloonView/FormPosition.Designer.cs create mode 100644 BeautySaloon/BeautySaloonView/FormPosition.cs create mode 100644 BeautySaloon/BeautySaloonView/FormPosition.resx create mode 100644 BeautySaloon/BeautySaloonView/FormPositions.Designer.cs create mode 100644 BeautySaloon/BeautySaloonView/FormPositions.cs create mode 100644 BeautySaloon/BeautySaloonView/FormPositions.resx create mode 100644 BeautySaloon/BeautySaloonView/FormService.Designer.cs create mode 100644 BeautySaloon/BeautySaloonView/FormService.cs create mode 100644 BeautySaloon/BeautySaloonView/FormService.resx create mode 100644 BeautySaloon/BeautySaloonView/FormServices.Designer.cs create mode 100644 BeautySaloon/BeautySaloonView/FormServices.cs create mode 100644 BeautySaloon/BeautySaloonView/FormServices.resx diff --git a/BeautySaloon/BeautySaloonBusinessLogic/OrderLogic.cs b/BeautySaloon/BeautySaloonBusinessLogic/OrderLogic.cs index e7a40cc..b14bdf8 100644 --- a/BeautySaloon/BeautySaloonBusinessLogic/OrderLogic.cs +++ b/BeautySaloon/BeautySaloonBusinessLogic/OrderLogic.cs @@ -23,6 +23,20 @@ namespace BeautySaloonBusinessLogic return true; } + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var element = _orderStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + public List? ReadList(OrderSearchModel? model) { var list = model == null ? _orderStorage.GetFullList() : @@ -34,6 +48,16 @@ namespace BeautySaloonBusinessLogic return list; } + public bool Update(OrderBindingModel model) + { + CheckModel(model); + if (_orderStorage.Update(model) == null) + { + return false; + } + return true; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) diff --git a/BeautySaloon/BeautySaloonContracts/BindingModels/OrderBindingModel.cs b/BeautySaloon/BeautySaloonContracts/BindingModels/OrderBindingModel.cs index 5b637a7..b2c7968 100644 --- a/BeautySaloon/BeautySaloonContracts/BindingModels/OrderBindingModel.cs +++ b/BeautySaloon/BeautySaloonContracts/BindingModels/OrderBindingModel.cs @@ -10,7 +10,7 @@ namespace BeautySaloonContracts.BindingModels public int ClientId { get; set; } public int EmployeeId { get; set; } - public Dictionary OrderServices + public Dictionary OrderServices { get; set; diff --git a/BeautySaloon/BeautySaloonContracts/BusinessLogicsContracts/IOrderLogic.cs b/BeautySaloon/BeautySaloonContracts/BusinessLogicsContracts/IOrderLogic.cs index afe1e2f..aaa9288 100644 --- a/BeautySaloon/BeautySaloonContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/BeautySaloon/BeautySaloonContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -7,6 +7,8 @@ namespace BeautySaloonContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); bool CreateOrder(OrderBindingModel model); + bool Update(OrderBindingModel model); } } diff --git a/BeautySaloon/BeautySaloonContracts/StoragesContracts/IOrderStorage.cs b/BeautySaloon/BeautySaloonContracts/StoragesContracts/IOrderStorage.cs index 55c8981..62d474c 100644 --- a/BeautySaloon/BeautySaloonContracts/StoragesContracts/IOrderStorage.cs +++ b/BeautySaloon/BeautySaloonContracts/StoragesContracts/IOrderStorage.cs @@ -10,6 +10,7 @@ namespace BeautySaloonContracts.StoragesContracts List GetFilteredList(OrderSearchModel model); OrderViewModel? GetElement(OrderSearchModel model); OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); OrderViewModel? Delete(OrderBindingModel model); } } diff --git a/BeautySaloon/BeautySaloonContracts/ViewModels/EmployeeViewModel.cs b/BeautySaloon/BeautySaloonContracts/ViewModels/EmployeeViewModel.cs index df015e6..943ecd6 100644 --- a/BeautySaloon/BeautySaloonContracts/ViewModels/EmployeeViewModel.cs +++ b/BeautySaloon/BeautySaloonContracts/ViewModels/EmployeeViewModel.cs @@ -15,6 +15,8 @@ namespace BeautySaloonContracts.ViewModels public string Surname { get; set; } = string.Empty; [DisplayName("Отчество")] public string Patronymic { get; set; } = string.Empty; + [DisplayName("ФИО")] + public string FIO { get; set; } = string.Empty; [DisplayName("Телефон")] public string Phone { get; set; } = string.Empty; } diff --git a/BeautySaloon/BeautySaloonContracts/ViewModels/OrderViewModel.cs b/BeautySaloon/BeautySaloonContracts/ViewModels/OrderViewModel.cs index 9222628..29ed5c0 100644 --- a/BeautySaloon/BeautySaloonContracts/ViewModels/OrderViewModel.cs +++ b/BeautySaloon/BeautySaloonContracts/ViewModels/OrderViewModel.cs @@ -21,7 +21,7 @@ namespace BeautySaloonContracts.ViewModels public string EmployeeName { get; set; } = string.Empty; [DisplayName("Номер продавца")] public string EmployeePhone { get; set; } = string.Empty; - public Dictionary OrderServices + public Dictionary OrderServices { get; set; diff --git a/BeautySaloon/BeautySaloonContracts/ViewModels/ServiceViewModel.cs b/BeautySaloon/BeautySaloonContracts/ViewModels/ServiceViewModel.cs index 35b9dd0..b32f9d5 100644 --- a/BeautySaloon/BeautySaloonContracts/ViewModels/ServiceViewModel.cs +++ b/BeautySaloon/BeautySaloonContracts/ViewModels/ServiceViewModel.cs @@ -9,6 +9,6 @@ namespace BeautySaloonContracts.ViewModels [DisplayName("Услуга")] public string Name { get; set; } = string.Empty; [DisplayName("Цена")] - public double Price { get; set; } + public decimal Price { get; set; } } } diff --git a/BeautySaloon/BeautySaloonDataModels/IOrderModel.cs b/BeautySaloon/BeautySaloonDataModels/IOrderModel.cs index 9310644..a40f8b5 100644 --- a/BeautySaloon/BeautySaloonDataModels/IOrderModel.cs +++ b/BeautySaloon/BeautySaloonDataModels/IOrderModel.cs @@ -7,6 +7,6 @@ decimal Sum { get; } int ClientId { get; } int EmployeeId { get; } - Dictionary OrderServices { get; } + Dictionary OrderServices { get; } } } diff --git a/BeautySaloon/BeautySaloonDatabaseImplement/Employee.cs b/BeautySaloon/BeautySaloonDatabaseImplement/Employee.cs index 6ce0500..30ba644 100644 --- a/BeautySaloon/BeautySaloonDatabaseImplement/Employee.cs +++ b/BeautySaloon/BeautySaloonDatabaseImplement/Employee.cs @@ -41,7 +41,7 @@ public partial class Employee : IEmployeeModel public virtual ICollection Orders { get; } = new List(); - public virtual Position Position { get; set; } = null!; + public virtual Position Position { get; set; } public virtual ICollection ServiceOrders { get; } = new List(); @@ -84,5 +84,6 @@ public partial class Employee : IEmployeeModel Phone = Phone, PositionId = PositionId, PositionName = Position.Name, + FIO = Name + ' ' + Surname + ' ' + Patronymic, }; } diff --git a/BeautySaloon/BeautySaloonDatabaseImplement/Implements/ClientStorage.cs b/BeautySaloon/BeautySaloonDatabaseImplement/Implements/ClientStorage.cs index 7a56379..3580468 100644 --- a/BeautySaloon/BeautySaloonDatabaseImplement/Implements/ClientStorage.cs +++ b/BeautySaloon/BeautySaloonDatabaseImplement/Implements/ClientStorage.cs @@ -58,12 +58,14 @@ namespace BeautySaloonDatabaseImplement.Implements public ClientViewModel? Insert(ClientBindingModel model) { + using var context = new NewdbContext(); + model.Id = context.Clients + .Count() > 0 ? context.Clients.Max(x => x.Id) + 1 : 1; var newClient = Client.Create(model); if (newClient == null) { return null; } - using var context = new NewdbContext(); context.Clients.Add(newClient); context.SaveChanges(); return newClient.GetViewModel; diff --git a/BeautySaloon/BeautySaloonDatabaseImplement/Implements/EmployeeStorage.cs b/BeautySaloon/BeautySaloonDatabaseImplement/Implements/EmployeeStorage.cs index c93f990..0442396 100644 --- a/BeautySaloon/BeautySaloonDatabaseImplement/Implements/EmployeeStorage.cs +++ b/BeautySaloon/BeautySaloonDatabaseImplement/Implements/EmployeeStorage.cs @@ -2,6 +2,7 @@ using BeautySaloonContracts.SearchModels; using BeautySaloonContracts.StoragesContracts; using BeautySaloonContracts.ViewModels; +using Microsoft.EntityFrameworkCore; namespace BeautySaloonDatabaseImplement.Implements { @@ -11,6 +12,7 @@ namespace BeautySaloonDatabaseImplement.Implements { using var context = new NewdbContext(); var element = context.Employees + .Include(x => x.Position) .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { @@ -26,10 +28,12 @@ namespace BeautySaloonDatabaseImplement.Implements using var context = new NewdbContext(); if (model.Id.HasValue) return context.Employees + .Include(x => x.Position) .FirstOrDefault(x => x.Id == model.Id)? .GetViewModel; if (!string.IsNullOrEmpty(model.Phone)) return context.Employees + .Include(x => x.Position) .FirstOrDefault(x => x.Phone.Equals(model.Phone))? .GetViewModel; return null; @@ -37,12 +41,19 @@ namespace BeautySaloonDatabaseImplement.Implements public List GetFilteredList(EmployeeSearchModel model) { - if (string.IsNullOrEmpty(model.Surname)) + using var context = new NewdbContext(); + if (string.IsNullOrEmpty(model.Surname) && !model.Id.HasValue) { return new(); } - using var context = new NewdbContext(); + if (model.Id.HasValue) + return context.Employees + .Include(x => x.Position) + .Where(x => x.Id.Equals(model.Id)) + .Select(x => x.GetViewModel) + .ToList(); return context.Employees + .Include(x => x.Position) .Where(x => x.Surname.Contains(model.Surname)) .Select(x => x.GetViewModel) .ToList(); @@ -52,27 +63,33 @@ namespace BeautySaloonDatabaseImplement.Implements { using var context = new NewdbContext(); return context.Employees - .Select(x => x.GetViewModel) - .ToList(); + .Include(x => x.Position) + .Select(x => x.GetViewModel) + .ToList(); } public EmployeeViewModel? Insert(EmployeeBindingModel model) { + using var context = new NewdbContext(); + model.Id = context.Employees.Count() > 0 ? context.Employees.Max(x => x.Id) + 1 : 1; var newEmployee = Employee.Create(model); if (newEmployee == null) { return null; } - using var context = new NewdbContext(); context.Employees.Add(newEmployee); context.SaveChanges(); - return newEmployee.GetViewModel; + return context.Employees + .Include(x => x.Position) + .FirstOrDefault(x => x.Id == newEmployee.Id)? + .GetViewModel; } public EmployeeViewModel? Update(EmployeeBindingModel model) { using var context = new NewdbContext(); var client = context.Employees + .Include(x => x.Position) .FirstOrDefault(x => x.Id == model.Id); if (client == null) { @@ -80,7 +97,10 @@ namespace BeautySaloonDatabaseImplement.Implements } client.Update(model); context.SaveChanges(); - return client.GetViewModel; + return context.Employees + .Include(x => x.Position) + .FirstOrDefault(x => x.Id == client.Id)? + .GetViewModel; } } } diff --git a/BeautySaloon/BeautySaloonDatabaseImplement/Implements/OrderStorage.cs b/BeautySaloon/BeautySaloonDatabaseImplement/Implements/OrderStorage.cs index 81c21f0..3cc04b2 100644 --- a/BeautySaloon/BeautySaloonDatabaseImplement/Implements/OrderStorage.cs +++ b/BeautySaloon/BeautySaloonDatabaseImplement/Implements/OrderStorage.cs @@ -62,15 +62,41 @@ namespace BeautySaloonDatabaseImplement.Implements public OrderViewModel? Insert(OrderBindingModel model) { - var newOrder = Order.Create(model); + using var context = new NewdbContext(); + model.Id = context.Orders + .Count() > 0 ? context.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(context, model); if (newOrder == null) { return null; } - using var context = new NewdbContext(); context.Orders.Add(newOrder); context.SaveChanges(); return newOrder.GetViewModel; } + + public OrderViewModel? Update(OrderBindingModel model) + { + using var context = new NewdbContext(); + using var transaction = context.Database.BeginTransaction(); + try + { + var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + context.SaveChanges(); + order.UpdateServices(context, model); + transaction.Commit(); + return order.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } } } diff --git a/BeautySaloon/BeautySaloonDatabaseImplement/Implements/PositionStorage.cs b/BeautySaloon/BeautySaloonDatabaseImplement/Implements/PositionStorage.cs index 7826beb..e326b6e 100644 --- a/BeautySaloon/BeautySaloonDatabaseImplement/Implements/PositionStorage.cs +++ b/BeautySaloon/BeautySaloonDatabaseImplement/Implements/PositionStorage.cs @@ -58,12 +58,14 @@ namespace BeautySaloonDatabaseImplement.Implements public PositionViewModel? Insert(PositionBindingModel model) { + using var context = new NewdbContext(); + model.Id = context.Positions + .Count() > 0 ? context.Positions.Max(x => x.Id) + 1 : 1; var newPosition = Position.Create(model); if (newPosition == null) { return null; } - using var context = new NewdbContext(); context.Positions.Add(newPosition); context.SaveChanges(); return newPosition.GetViewModel; diff --git a/BeautySaloon/BeautySaloonDatabaseImplement/Implements/ServiceStorage.cs b/BeautySaloon/BeautySaloonDatabaseImplement/Implements/ServiceStorage.cs index 728bb6a..f7fa16f 100644 --- a/BeautySaloon/BeautySaloonDatabaseImplement/Implements/ServiceStorage.cs +++ b/BeautySaloon/BeautySaloonDatabaseImplement/Implements/ServiceStorage.cs @@ -58,12 +58,14 @@ namespace BeautySaloonDatabaseImplement.Implements public ServiceViewModel? Insert(ServiceBindingModel model) { + using var context = new NewdbContext(); + model.Id = context.Services + .Count() > 0 ? context.Services.Max(x => x.Id) + 1 : 1; var newService = Service.Create(model); if (newService == null) { return null; } - using var context = new NewdbContext(); context.Services.Add(newService); context.SaveChanges(); return newService.GetViewModel; diff --git a/BeautySaloon/BeautySaloonDatabaseImplement/Order.cs b/BeautySaloon/BeautySaloonDatabaseImplement/Order.cs index d2e444e..d1cf920 100644 --- a/BeautySaloon/BeautySaloonDatabaseImplement/Order.cs +++ b/BeautySaloon/BeautySaloonDatabaseImplement/Order.cs @@ -1,9 +1,6 @@ using BeautySaloonContracts.BindingModels; using BeautySaloonContracts.ViewModels; using BeautySaloonDataModels; -using System; -using System.ComponentModel.DataAnnotations.Schema; -using System.Numerics; namespace BeautySaloonDatabaseImplement; @@ -44,25 +41,26 @@ public partial class Order : IOrderModel public virtual ServiceOrder? ServiceOrder { get; set; } - public Dictionary _orderServices = null; + public Dictionary _orderServices = null; public virtual List Services { get; set; } = new(); - public Dictionary OrderServices + public Dictionary OrderServices { get { - if (ServiceOrder != null) + if (_orderServices == null) { _orderServices = Services - .ToDictionary(x => x.ServiceId, - x => (x.Date, x.Service as IServiceModel, x.Employee as IEmployeeModel)); + .ToDictionary(serviceOrd => serviceOrd.ServiceId, + serviceOrd => (serviceOrd.Date, serviceOrd.Service as IServiceModel, + serviceOrd.EmployeeId)); } return _orderServices; } } - public static Order? Create(OrderBindingModel? model) + public static Order? Create(NewdbContext context, OrderBindingModel? model) { if (model == null) { @@ -74,10 +72,24 @@ public partial class Order : IOrderModel Date = model.Date, Sum = model.Sum, ClientId = model.ClientId, - EmployeeId = model.EmployeeId + EmployeeId = model.EmployeeId, + Services = model.OrderServices.Select(x => new ServiceOrder + { + Service = context.Services.First(y => y.Id == x.Key), + Date = x.Value.Item1, + EmployeeId = x.Value.Item3, + }).ToList() }; } + public void Update(OrderBindingModel model) + { + Date = model.Date; + Sum = model.Sum; + EmployeeId = model.EmployeeId; + ClientId = model.ClientId; + } + public OrderViewModel GetViewModel => new() { Id = Id, @@ -85,9 +97,45 @@ public partial class Order : IOrderModel Sum = Sum, ClientId = ClientId, EmployeeId = EmployeeId, - ClientName = Client.Name, - EmployeeName = Employee.Name, + ClientName = Client.Name + " " + Client.Surname + " " + Client.Patronymic, + EmployeeName = Employee.Name + " " + Employee.Surname + " " + Employee.Patronymic, ClientPhone = Client.Phone, EmployeePhone = Employee.Phone }; + + public void UpdateServices(NewdbContext context, OrderBindingModel model) + { + var orderServices = context.ServiceOrders + .Where(rec => rec.OrderId == model.Id).ToList(); + + if (orderServices != null && orderServices.Count > 0) + { // удалили те, которых нет в модели + context.ServiceOrders + .RemoveRange(orderServices + .Where(rec => !model.OrderServices.ContainsKey(rec.ServiceId))); + context.SaveChanges(); + // обновили данные у существующих записей + foreach (var updateService in orderServices) + { + updateService.Date = model.OrderServices[updateService.ServiceId].Item1; + updateService.EmployeeId = + model.OrderServices[updateService.ServiceId].Item3; + model.OrderServices.Remove(updateService.ServiceId); + } + context.SaveChanges(); + } + var order = context.Orders.First(x => x.Id == Id); + foreach (var os in model.OrderServices) + { + context.ServiceOrders.Add(new ServiceOrder + { + Order = order, + Service = context.Services.First(x => x.Id == os.Key), + Date = os.Value.Item1, + EmployeeId = os.Value.Item3 + }); + context.SaveChanges(); + } + _orderServices = null; + } } diff --git a/BeautySaloon/BeautySaloonView/FormClient.Designer.cs b/BeautySaloon/BeautySaloonView/FormClient.Designer.cs new file mode 100644 index 0000000..bac3e02 --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormClient.Designer.cs @@ -0,0 +1,166 @@ +namespace BeautySaloonView +{ + partial class FormClient + { + /// + /// 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.textBoxSurname = new System.Windows.Forms.TextBox(); + this.textBoxPatronymic = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.labelName = new System.Windows.Forms.Label(); + this.labelSurname = new System.Windows.Forms.Label(); + this.labelPatronymic = new System.Windows.Forms.Label(); + this.labelPhone = new System.Windows.Forms.Label(); + this.maskedTextBox = new System.Windows.Forms.MaskedTextBox(); + this.SuspendLayout(); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(125, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(244, 23); + this.textBoxName.TabIndex = 0; + // + // textBoxSurname + // + this.textBoxSurname.Location = new System.Drawing.Point(125, 41); + this.textBoxSurname.Name = "textBoxSurname"; + this.textBoxSurname.Size = new System.Drawing.Size(244, 23); + this.textBoxSurname.TabIndex = 1; + // + // textBoxPatronymic + // + this.textBoxPatronymic.Location = new System.Drawing.Point(125, 70); + this.textBoxPatronymic.Name = "textBoxPatronymic"; + this.textBoxPatronymic.Size = new System.Drawing.Size(244, 23); + this.textBoxPatronymic.TabIndex = 2; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(288, 127); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 15; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(200, 127); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + this.buttonSave.TabIndex = 14; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 15); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(31, 15); + this.labelName.TabIndex = 16; + this.labelName.Text = "Имя"; + // + // labelSurname + // + this.labelSurname.AutoSize = true; + this.labelSurname.Location = new System.Drawing.Point(12, 44); + this.labelSurname.Name = "labelSurname"; + this.labelSurname.Size = new System.Drawing.Size(58, 15); + this.labelSurname.TabIndex = 17; + this.labelSurname.Text = "Фамилия"; + // + // labelPatronymic + // + this.labelPatronymic.AutoSize = true; + this.labelPatronymic.Location = new System.Drawing.Point(12, 73); + this.labelPatronymic.Name = "labelPatronymic"; + this.labelPatronymic.Size = new System.Drawing.Size(58, 15); + this.labelPatronymic.TabIndex = 18; + this.labelPatronymic.Text = "Отчество"; + // + // labelPhone + // + this.labelPhone.AutoSize = true; + this.labelPhone.Location = new System.Drawing.Point(12, 102); + this.labelPhone.Name = "labelPhone"; + this.labelPhone.Size = new System.Drawing.Size(101, 15); + this.labelPhone.TabIndex = 19; + this.labelPhone.Text = "Номер телефона"; + // + // maskedTextBox + // + this.maskedTextBox.Location = new System.Drawing.Point(125, 99); + this.maskedTextBox.Mask = "00000000000"; + this.maskedTextBox.Name = "maskedTextBox"; + this.maskedTextBox.Size = new System.Drawing.Size(244, 23); + this.maskedTextBox.TabIndex = 21; + // + // FormClient + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(390, 157); + this.Controls.Add(this.maskedTextBox); + this.Controls.Add(this.labelPhone); + this.Controls.Add(this.labelPatronymic); + this.Controls.Add(this.labelSurname); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxPatronymic); + this.Controls.Add(this.textBoxSurname); + this.Controls.Add(this.textBoxName); + this.Name = "FormClient"; + this.Text = "Создание клиента"; + this.Load += new System.EventHandler(this.FormClient_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxName; + private TextBox textBoxSurname; + private TextBox textBoxPatronymic; + private Button buttonCancel; + private Button buttonSave; + private Label labelName; + private Label labelSurname; + private Label labelPatronymic; + private Label labelPhone; + private MaskedTextBox maskedTextBox; + } +} \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormClient.cs b/BeautySaloon/BeautySaloonView/FormClient.cs new file mode 100644 index 0000000..1c10807 --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormClient.cs @@ -0,0 +1,92 @@ +using BeautySaloonContracts.BindingModels; +using BeautySaloonContracts.BusinessLogicsContracts; +using BeautySaloonContracts.SearchModels; + +namespace BeautySaloonView +{ + public partial class FormClient : Form + { + private readonly IClientLogic _logicC; + private readonly IOrderLogic _logicO; + private int? _id; + public int Id { set { _id = value; } } + public FormClient(IClientLogic logicС, IOrderLogic logicO) + { + InitializeComponent(); + _logicC = logicС; + _logicO = logicO; + } + private void FormClient_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var view = _logicC.ReadElement(new ClientSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.Name; + textBoxSurname.Text = view.Surname; + textBoxPatronymic.Text = view.Patronymic; + maskedTextBox.Text = view.Phone; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните имя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxSurname.Text)) + { + MessageBox.Show("Заполните фамилию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (!maskedTextBox.MaskFull) + { + MessageBox.Show("Заполните номер телефона", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + var model = new ClientBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text, + Surname = textBoxSurname.Text, + Patronymic = textBoxPatronymic.Text, + Phone = maskedTextBox.Text + }; + var operationResult = _id.HasValue ? _logicC.Update(model) : _logicC.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/BeautySaloon/BeautySaloonView/FormClient.resx b/BeautySaloon/BeautySaloonView/FormClient.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormClient.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/BeautySaloon/BeautySaloonView/FormClientOrders.Designer.cs b/BeautySaloon/BeautySaloonView/FormClientOrders.Designer.cs new file mode 100644 index 0000000..87fdd2e --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormClientOrders.Designer.cs @@ -0,0 +1,108 @@ +namespace BeautySaloonView +{ + partial class FormClientOrders + { + /// + /// 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.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + 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(921, 337); + this.dataGridView.TabIndex = 10; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(927, 156); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(130, 22); + this.buttonUpdate.TabIndex = 14; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(927, 130); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 22); + this.buttonEdit.TabIndex = 12; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(927, 104); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 22); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormClientOrders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1065, 337); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormClientOrders"; + this.Text = "Заказы клиента"; + this.Load += new System.EventHandler(this.FormClientOrders_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpdate; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormClientOrders.cs b/BeautySaloon/BeautySaloonView/FormClientOrders.cs new file mode 100644 index 0000000..504b455 --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormClientOrders.cs @@ -0,0 +1,77 @@ +using BeautySaloonContracts.BindingModels; +using BeautySaloonContracts.BusinessLogicsContracts; +using BeautySaloonContracts.SearchModels; + +namespace BeautySaloonView +{ + public partial class FormClientOrders : Form + { + private readonly IOrderLogic _logic; + private int? _idClient; + public int IdClient { set { _idClient = value; } } + public FormClientOrders(IOrderLogic logic) + { + InitializeComponent(); + _logic = logic; + } + private void FormClientOrders_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(new OrderSearchModel + { + ClientId = _idClient + }); + if (list != null) + { + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["EmployeeId"].Visible = false; + dataGridView.Columns["OrderServices"].Visible = false; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.IdClient = _idClient.Value; + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + form.IdClient = _idClient.Value; + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/BeautySaloon/BeautySaloonView/FormClientOrders.resx b/BeautySaloon/BeautySaloonView/FormClientOrders.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormClientOrders.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/BeautySaloon/BeautySaloonView/FormClients.Designer.cs b/BeautySaloon/BeautySaloonView/FormClients.Designer.cs new file mode 100644 index 0000000..6ef9d6a --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormClients.Designer.cs @@ -0,0 +1,136 @@ +namespace BeautySaloonView +{ + 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonOrders = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + 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(652, 337); + this.dataGridView.TabIndex = 10; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(658, 194); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(130, 22); + this.buttonUpdate.TabIndex = 14; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(658, 168); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(130, 22); + this.buttonDelete.TabIndex = 13; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(658, 142); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 22); + this.buttonEdit.TabIndex = 12; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(658, 116); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 22); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonOrders + // + this.buttonOrders.Location = new System.Drawing.Point(658, 220); + this.buttonOrders.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonOrders.Name = "buttonOrders"; + this.buttonOrders.Size = new System.Drawing.Size(130, 22); + this.buttonOrders.TabIndex = 15; + this.buttonOrders.Text = "Посмотреть заказы"; + this.buttonOrders.UseVisualStyleBackColor = true; + this.buttonOrders.Click += new System.EventHandler(this.ButtonOrders_Click); + // + // FormClients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(796, 337); + this.Controls.Add(this.buttonOrders); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormClients"; + this.Text = "Клиенты"; + this.Load += new System.EventHandler(this.FormClients_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + private Button buttonOrders; + } +} \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormClients.cs b/BeautySaloon/BeautySaloonView/FormClients.cs new file mode 100644 index 0000000..6989a4a --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormClients.cs @@ -0,0 +1,109 @@ +using BeautySaloonContracts.BindingModels; +using BeautySaloonContracts.BusinessLogicsContracts; + +namespace BeautySaloonView +{ + public partial class FormClients : Form + { + private readonly IClientLogic _logic; + public FormClients(IClientLogic logic) + { + InitializeComponent(); + _logic = logic; + } + private void FormClients_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClient)); + if (service is FormClient form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClient)); + if (service is FormClient form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonOrders_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClientOrders)); + if (service is FormClientOrders form) + { + form.IdClient = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + else + MessageBox.Show("Выберите пользователя для отображения заказов", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + private void ButtonDel_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); + try + { + if (!_logic.Delete(new ClientBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении."); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/BeautySaloon/BeautySaloonView/FormClients.resx b/BeautySaloon/BeautySaloonView/FormClients.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BeautySaloon/BeautySaloonView/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/BeautySaloon/BeautySaloonView/FormCreateOrder.Designer.cs b/BeautySaloon/BeautySaloonView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..ecace9d --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormCreateOrder.Designer.cs @@ -0,0 +1,275 @@ +namespace BeautySaloonView +{ + partial class FormCreateOrder + { + /// + /// 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.dateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.comboBoxEmployee = new System.Windows.Forms.ComboBox(); + this.textBox = new System.Windows.Forms.TextBox(); + this.labelDate = new System.Windows.Forms.Label(); + this.labelCashier = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.groupBoxServices = new System.Windows.Forms.GroupBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnServiceName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnDate = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnEmployeeName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBoxServices.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dateTimePicker + // + this.dateTimePicker.Location = new System.Drawing.Point(109, 18); + this.dateTimePicker.Name = "dateTimePicker"; + this.dateTimePicker.Size = new System.Drawing.Size(525, 23); + this.dateTimePicker.TabIndex = 0; + // + // comboBoxEmployee + // + this.comboBoxEmployee.FormattingEnabled = true; + this.comboBoxEmployee.Location = new System.Drawing.Point(109, 47); + this.comboBoxEmployee.Name = "comboBoxEmployee"; + this.comboBoxEmployee.Size = new System.Drawing.Size(525, 23); + this.comboBoxEmployee.TabIndex = 2; + // + // textBox + // + this.textBox.Location = new System.Drawing.Point(109, 76); + this.textBox.Name = "textBox"; + this.textBox.Size = new System.Drawing.Size(525, 23); + this.textBox.TabIndex = 3; + // + // labelDate + // + this.labelDate.AutoSize = true; + this.labelDate.Location = new System.Drawing.Point(12, 24); + this.labelDate.Name = "labelDate"; + this.labelDate.Size = new System.Drawing.Size(69, 15); + this.labelDate.TabIndex = 4; + this.labelDate.Text = "Дата заказа"; + // + // labelCashier + // + this.labelCashier.AutoSize = true; + this.labelCashier.Location = new System.Drawing.Point(12, 50); + this.labelCashier.Name = "labelCashier"; + this.labelCashier.Size = new System.Drawing.Size(61, 15); + this.labelCashier.TabIndex = 5; + this.labelCashier.Text = "Продавец"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(12, 79); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(82, 15); + this.labelSum.TabIndex = 6; + this.labelSum.Text = "Сумма заказа"; + // + // groupBoxServices + // + this.groupBoxServices.Controls.Add(this.buttonCancel); + this.groupBoxServices.Controls.Add(this.buttonSave); + this.groupBoxServices.Controls.Add(this.buttonUpdate); + this.groupBoxServices.Controls.Add(this.buttonDelete); + this.groupBoxServices.Controls.Add(this.buttonEdit); + this.groupBoxServices.Controls.Add(this.buttonAdd); + this.groupBoxServices.Controls.Add(this.dataGridView); + this.groupBoxServices.Dock = System.Windows.Forms.DockStyle.Bottom; + this.groupBoxServices.Location = new System.Drawing.Point(0, 105); + this.groupBoxServices.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxServices.Name = "groupBoxServices"; + this.groupBoxServices.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxServices.Size = new System.Drawing.Size(737, 206); + this.groupBoxServices.TabIndex = 18; + this.groupBoxServices.TabStop = false; + this.groupBoxServices.Text = "Услуги"; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(646, 176); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(79, 22); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(646, 150); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(79, 22); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(646, 98); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(79, 22); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(646, 72); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(79, 22); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(646, 46); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(79, 22); + this.buttonEdit.TabIndex = 2; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(646, 20); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(79, 22); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.ColumnServiceName, + this.ColumnDate, + this.ColumnEmployeeName}); + this.dataGridView.Location = new System.Drawing.Point(5, 20); + 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(629, 182); + this.dataGridView.TabIndex = 0; + // + // ID + // + this.ID.HeaderText = "ID"; + this.ID.MinimumWidth = 6; + this.ID.Name = "ID"; + this.ID.Visible = false; + this.ID.Width = 125; + // + // ColumnServiceName + // + this.ColumnServiceName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnServiceName.HeaderText = "Услуга"; + this.ColumnServiceName.MinimumWidth = 6; + this.ColumnServiceName.Name = "ColumnServiceName"; + this.ColumnServiceName.Resizable = System.Windows.Forms.DataGridViewTriState.True; + // + // ColumnDate + // + this.ColumnDate.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnDate.HeaderText = "Время"; + this.ColumnDate.MinimumWidth = 6; + this.ColumnDate.Name = "ColumnDate"; + // + // ColumnEmployeeName + // + this.ColumnEmployeeName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnEmployeeName.HeaderText = "Сотрудник"; + this.ColumnEmployeeName.Name = "ColumnEmployeeName"; + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(737, 311); + this.Controls.Add(this.groupBoxServices); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCashier); + this.Controls.Add(this.labelDate); + this.Controls.Add(this.textBox); + this.Controls.Add(this.comboBoxEmployee); + this.Controls.Add(this.dateTimePicker); + this.Name = "FormCreateOrder"; + this.Text = "Форма создания заказа"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.groupBoxServices.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DateTimePicker dateTimePicker; + private ComboBox comboBoxEmployee; + private TextBox textBox; + private Label labelDate; + private Label labelCashier; + private Label labelSum; + private GroupBox groupBoxServices; + private Button buttonCancel; + private Button buttonSave; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ColumnServiceName; + private DataGridViewTextBoxColumn ColumnDate; + private DataGridViewTextBoxColumn ColumnEmployeeName; + } +} \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormCreateOrder.cs b/BeautySaloon/BeautySaloonView/FormCreateOrder.cs new file mode 100644 index 0000000..e38b30a --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormCreateOrder.cs @@ -0,0 +1,221 @@ +using BeautySaloonContracts.BindingModels; +using BeautySaloonContracts.BusinessLogicsContracts; +using BeautySaloonContracts.SearchModels; +using BeautySaloonDataModels; + +namespace BeautySaloonView +{ + public partial class FormCreateOrder : Form + { + private readonly IOrderLogic _logicO; + private readonly IEmployeeLogic _logicE; + private int? _idClient; + private int? _id; + private Dictionary _orderServices; + public int IdClient { set { _idClient = value; } } + public int Id { set { _id = value; } } + public FormCreateOrder(IOrderLogic logic, IEmployeeLogic logicE) + { + InitializeComponent(); + _logicO = logic; + _logicE = logicE; + _orderServices = new(); + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + try + { + // продавцы + var list = _logicE.ReadList(new EmployeeSearchModel + { + Id = 1 + }); + if (list != null) + { + comboBoxEmployee.DisplayMember = "FIO"; + comboBoxEmployee.ValueMember = "Id"; + comboBoxEmployee.DataSource = list; + comboBoxEmployee.SelectedItem = null; + } + // загружаем заказ для изменения + if (_id.HasValue) + { + var view = _logicO.ReadElement(new OrderSearchModel + { + Id = _idClient.Value + }); + if (view != null) + { + textBox.Text = view.Sum.ToString(); + dateTimePicker.Text = view.Date.ToString(); + comboBoxEmployee.SelectedValue = view.EmployeeId; + _orderServices = view.OrderServices ?? new(); + LoadData(); + } + + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка загрузки", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadData() + { + // заполняем datagridview + try + { + if (_orderServices != null) + { + dataGridView.Rows.Clear(); + foreach (var os in _orderServices) + { + var empl = _logicE.ReadElement(new EmployeeSearchModel + { + Id = os.Value.Item3 + }); + if (empl == null) + { + throw new ArgumentNullException("Не найден указанный сотрудник"); + } + dataGridView.Rows.Add(new object[] + { + os.Key, + os.Value.Item2.Name, + os.Value.Item1, + empl.FIO, + }); + } + textBox.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormOrderServices)); + if (service is FormOrderServices form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ServiceModel == null) + { + return; + } + if (_orderServices.ContainsKey(form.IdService)) + { + _orderServices[form.IdService] = (form.Date, + form.ServiceModel, form.IdEmployee); + } + else + { + _orderServices.Add(form.IdService, + (form.Date, form.ServiceModel, form.IdEmployee)); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormOrderServices)); + if (service is FormOrderServices form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.IdService = id; + form.Date = _orderServices[id].Item1; + form.IdEmployee = _orderServices[id].Item3; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ServiceModel == null) + { + return; + } + _orderServices[form.IdService] = (form.Date, + form.ServiceModel, form.IdEmployee); + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _orderServices?.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 (comboBoxEmployee.SelectedValue == null) + { + MessageBox.Show("Выберите продавца", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_orderServices == null || _orderServices.Count == 0) + { + MessageBox.Show("Заполните услуги", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var model = new OrderBindingModel + { + Id = _id ?? 0, + Date = DateOnly.FromDateTime(dateTimePicker.Value), + Sum = Convert.ToDecimal(textBox.Text), + ClientId = _idClient.Value, + EmployeeId = Convert.ToInt32(comboBoxEmployee.SelectedValue), + OrderServices = _orderServices + }; + var operationResult = _id.HasValue ? _logicO.Update(model) : _logicO.CreateOrder(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + private decimal CalcPrice() + { + decimal price = 0; + foreach (var elem in _orderServices) + { + price += elem.Value.Item2?.Price ?? 0; + } + return Math.Round(price, 2); + } + } +} diff --git a/BeautySaloon/BeautySaloonView/FormCreateOrder.resx b/BeautySaloon/BeautySaloonView/FormCreateOrder.resx new file mode 100644 index 0000000..f6a5fe7 --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormCreateOrder.resx @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormEmployee.Designer.cs b/BeautySaloon/BeautySaloonView/FormEmployee.Designer.cs new file mode 100644 index 0000000..3155a85 --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormEmployee.Designer.cs @@ -0,0 +1,189 @@ +namespace BeautySaloonView +{ + partial class FormEmployee + { + /// + /// 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.textBoxSurname = new System.Windows.Forms.TextBox(); + this.textBoxPatronymic = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.labelName = new System.Windows.Forms.Label(); + this.labelSurname = new System.Windows.Forms.Label(); + this.labelPatronymic = new System.Windows.Forms.Label(); + this.labelPhone = new System.Windows.Forms.Label(); + this.labelPosition = new System.Windows.Forms.Label(); + this.maskedTextBox = new System.Windows.Forms.MaskedTextBox(); + this.comboBox = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(125, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(244, 23); + this.textBoxName.TabIndex = 0; + // + // textBoxSurname + // + this.textBoxSurname.Location = new System.Drawing.Point(125, 41); + this.textBoxSurname.Name = "textBoxSurname"; + this.textBoxSurname.Size = new System.Drawing.Size(244, 23); + this.textBoxSurname.TabIndex = 1; + // + // textBoxPatronymic + // + this.textBoxPatronymic.Location = new System.Drawing.Point(125, 70); + this.textBoxPatronymic.Name = "textBoxPatronymic"; + this.textBoxPatronymic.Size = new System.Drawing.Size(244, 23); + this.textBoxPatronymic.TabIndex = 2; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(287, 156); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 15; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(199, 156); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + this.buttonSave.TabIndex = 14; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 15); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(31, 15); + this.labelName.TabIndex = 16; + this.labelName.Text = "Имя"; + // + // labelSurname + // + this.labelSurname.AutoSize = true; + this.labelSurname.Location = new System.Drawing.Point(12, 44); + this.labelSurname.Name = "labelSurname"; + this.labelSurname.Size = new System.Drawing.Size(58, 15); + this.labelSurname.TabIndex = 17; + this.labelSurname.Text = "Фамилия"; + // + // labelPatronymic + // + this.labelPatronymic.AutoSize = true; + this.labelPatronymic.Location = new System.Drawing.Point(12, 73); + this.labelPatronymic.Name = "labelPatronymic"; + this.labelPatronymic.Size = new System.Drawing.Size(58, 15); + this.labelPatronymic.TabIndex = 18; + this.labelPatronymic.Text = "Отчество"; + // + // labelPhone + // + this.labelPhone.AutoSize = true; + this.labelPhone.Location = new System.Drawing.Point(12, 102); + this.labelPhone.Name = "labelPhone"; + this.labelPhone.Size = new System.Drawing.Size(101, 15); + this.labelPhone.TabIndex = 19; + this.labelPhone.Text = "Номер телефона"; + // + // labelPosition + // + this.labelPosition.AutoSize = true; + this.labelPosition.Location = new System.Drawing.Point(12, 131); + this.labelPosition.Name = "labelPosition"; + this.labelPosition.Size = new System.Drawing.Size(69, 15); + this.labelPosition.TabIndex = 20; + this.labelPosition.Text = "Должность"; + // + // maskedTextBox + // + this.maskedTextBox.Location = new System.Drawing.Point(125, 99); + this.maskedTextBox.Mask = "00000000000"; + this.maskedTextBox.Name = "maskedTextBox"; + this.maskedTextBox.Size = new System.Drawing.Size(244, 23); + this.maskedTextBox.TabIndex = 21; + // + // comboBox + // + this.comboBox.FormattingEnabled = true; + this.comboBox.Location = new System.Drawing.Point(125, 128); + this.comboBox.Name = "comboBox"; + this.comboBox.Size = new System.Drawing.Size(244, 23); + this.comboBox.TabIndex = 22; + // + // FormEmployee + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(390, 188); + this.Controls.Add(this.comboBox); + this.Controls.Add(this.maskedTextBox); + this.Controls.Add(this.labelPosition); + this.Controls.Add(this.labelPhone); + this.Controls.Add(this.labelPatronymic); + this.Controls.Add(this.labelSurname); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxPatronymic); + this.Controls.Add(this.textBoxSurname); + this.Controls.Add(this.textBoxName); + this.Name = "FormEmployee"; + this.Text = "Создание сотрудника"; + this.Load += new System.EventHandler(this.FormEmployee_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxName; + private TextBox textBoxSurname; + private TextBox textBoxPatronymic; + private Button buttonCancel; + private Button buttonSave; + private Label labelName; + private Label labelSurname; + private Label labelPatronymic; + private Label labelPhone; + private Label labelPosition; + private MaskedTextBox maskedTextBox; + private ComboBox comboBox; + } +} \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormEmployee.cs b/BeautySaloon/BeautySaloonView/FormEmployee.cs new file mode 100644 index 0000000..76cb44b --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormEmployee.cs @@ -0,0 +1,127 @@ +using BeautySaloonContracts.BindingModels; +using BeautySaloonContracts.BusinessLogicsContracts; +using BeautySaloonContracts.SearchModels; +using Microsoft.IdentityModel.Tokens; + +namespace BeautySaloonView +{ + public partial class FormEmployee : Form + { + private readonly IEmployeeLogic _logicE; + private readonly IPositionLogic _logicP; + private int? _id; + public int Id { set { _id = value; } } + public FormEmployee(IEmployeeLogic logicE, IPositionLogic logicP) + { + InitializeComponent(); + _logicE = logicE; + _logicP = logicP; + } + private void FormEmployee_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var view = _logicE.ReadElement(new EmployeeSearchModel + { + Id = _id.Value + }); + var list = _logicP.ReadList(null); + if (list != null) + { + comboBox.DisplayMember = "Name"; + comboBox.ValueMember = "Id"; + comboBox.DataSource = list; + comboBox.SelectedItem = null; + } + if (view != null) + { + textBoxName.Text = view.Name; + textBoxSurname.Text = view.Surname; + textBoxPatronymic.Text = view.Patronymic; + maskedTextBox.Text = view.Phone; + comboBox.SelectedValue = view.PositionId; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + else + { + try + { + var list = _logicP.ReadList(null); + if (list != null) + { + comboBox.DisplayMember = "Name"; + comboBox.ValueMember = "Id"; + comboBox.DataSource = list; + comboBox.SelectedItem = null; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните имя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxSurname.Text)) + { + MessageBox.Show("Заполните фамилию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (!maskedTextBox.MaskFull) + { + MessageBox.Show("Заполните номер телефона", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBox.SelectedValue == null) + { + MessageBox.Show("Выберите должность", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + var model = new EmployeeBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text, + Surname = textBoxSurname.Text, + Patronymic = textBoxPatronymic.Text, + Phone = maskedTextBox.Text, + PositionId = Convert.ToInt32(comboBox.SelectedValue) + }; + var operationResult = _id.HasValue ? _logicE.Update(model) : _logicE.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/BeautySaloon/BeautySaloonView/FormEmployee.resx b/BeautySaloon/BeautySaloonView/FormEmployee.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormEmployee.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/BeautySaloon/BeautySaloonView/FormEmployees.Designer.cs b/BeautySaloon/BeautySaloonView/FormEmployees.Designer.cs new file mode 100644 index 0000000..15e1ebe --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormEmployees.Designer.cs @@ -0,0 +1,122 @@ +namespace BeautySaloonView +{ + partial class FormEmployees + { + /// + /// 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.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + 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(652, 337); + this.dataGridView.TabIndex = 10; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(658, 194); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(130, 22); + this.buttonUpdate.TabIndex = 14; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(658, 168); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(130, 22); + this.buttonDelete.TabIndex = 13; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(658, 142); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 22); + this.buttonEdit.TabIndex = 12; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(658, 116); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 22); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormEmployees + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(796, 337); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormEmployees"; + this.Text = "Сотрудники"; + this.Load += new System.EventHandler(this.FormEmployees_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormEmployees.cs b/BeautySaloon/BeautySaloonView/FormEmployees.cs new file mode 100644 index 0000000..c425892 --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormEmployees.cs @@ -0,0 +1,93 @@ +using BeautySaloonContracts.BindingModels; +using BeautySaloonContracts.BusinessLogicsContracts; + +namespace BeautySaloonView +{ + public partial class FormEmployees : Form + { + private readonly IEmployeeLogic _logic; + public FormEmployees(IEmployeeLogic logic) + { + InitializeComponent(); + _logic = logic; + } + private void FormEmployees_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["PositionId"].Visible = false; + dataGridView.Columns["FIO"].Visible = false; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormEmployee)); + if (service is FormEmployee form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormEmployee)); + if (service is FormEmployee form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_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); + try + { + if (!_logic.Delete(new EmployeeBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении."); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/BeautySaloon/BeautySaloonView/FormEmployees.resx b/BeautySaloon/BeautySaloonView/FormEmployees.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormEmployees.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/BeautySaloon/BeautySaloonView/FormMain.Designer.cs b/BeautySaloon/BeautySaloonView/FormMain.Designer.cs index 3deb8e0..23c881a 100644 --- a/BeautySaloon/BeautySaloonView/FormMain.Designer.cs +++ b/BeautySaloon/BeautySaloonView/FormMain.Designer.cs @@ -36,7 +36,6 @@ this.сотрудникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.buttonUpdate = new System.Windows.Forms.Button(); - this.buttonCreateOrder = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -50,7 +49,7 @@ this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(854, 515); + this.dataGridView.Size = new System.Drawing.Size(911, 515); this.dataGridView.TabIndex = 8; // // menuStrip1 @@ -77,46 +76,41 @@ // должностиToolStripMenuItem // this.должностиToolStripMenuItem.Name = "должностиToolStripMenuItem"; - this.должностиToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.должностиToolStripMenuItem.Size = new System.Drawing.Size(140, 22); this.должностиToolStripMenuItem.Text = "Должности"; + this.должностиToolStripMenuItem.Click += new System.EventHandler(this.PositionsToolStripMenuItem_Click); // // услугиToolStripMenuItem // this.услугиToolStripMenuItem.Name = "услугиToolStripMenuItem"; - this.услугиToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.услугиToolStripMenuItem.Size = new System.Drawing.Size(140, 22); this.услугиToolStripMenuItem.Text = "Услуги"; + this.услугиToolStripMenuItem.Click += new System.EventHandler(this.ServicesToolStripMenuItem_Click); // // сотрудникиToolStripMenuItem // this.сотрудникиToolStripMenuItem.Name = "сотрудникиToolStripMenuItem"; - this.сотрудникиToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.сотрудникиToolStripMenuItem.Size = new System.Drawing.Size(140, 22); this.сотрудникиToolStripMenuItem.Text = "Сотрудники"; + this.сотрудникиToolStripMenuItem.Click += new System.EventHandler(this.EmployeesToolStripMenuItem_Click); // // клиентыToolStripMenuItem // this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(140, 22); this.клиентыToolStripMenuItem.Text = "Клиенты"; + this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click); // // buttonUpdate // - this.buttonUpdate.Location = new System.Drawing.Point(885, 270); + this.buttonUpdate.Location = new System.Drawing.Point(917, 241); this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonUpdate.Name = "buttonUpdate"; this.buttonUpdate.Size = new System.Drawing.Size(116, 58); this.buttonUpdate.TabIndex = 17; this.buttonUpdate.Text = "Обновить"; this.buttonUpdate.UseVisualStyleBackColor = true; - // - // buttonCreateOrder - // - this.buttonCreateOrder.Location = new System.Drawing.Point(885, 208); - this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(116, 58); - this.buttonCreateOrder.TabIndex = 13; - this.buttonCreateOrder.Text = "Создать заказ"; - this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); // // FormMain // @@ -124,12 +118,12 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1037, 539); this.Controls.Add(this.buttonUpdate); - this.Controls.Add(this.buttonCreateOrder); this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; this.Name = "FormMain"; this.Text = "Салон красоты"; + this.Load += new System.EventHandler(this.FormMain_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); diff --git a/BeautySaloon/BeautySaloonView/FormMain.cs b/BeautySaloon/BeautySaloonView/FormMain.cs index bfc866b..417d81d 100644 --- a/BeautySaloon/BeautySaloonView/FormMain.cs +++ b/BeautySaloon/BeautySaloonView/FormMain.cs @@ -1,10 +1,76 @@ +using BeautySaloonContracts.BusinessLogicsContracts; + namespace BeautySaloonView { public partial class FormMain : Form { - public FormMain() + private readonly IOrderLogic _orderLogic; + public FormMain(IOrderLogic orderLogic) { InitializeComponent(); + _orderLogic = orderLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.DataSource = list; + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["EmployeeId"].Visible = false; + dataGridView.Columns["OrderServices"].Visible = false; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void PositionsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPositions)); + if (service is FormPositions form) + { + form.ShowDialog(); + } + } + + private void ServicesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormServices)); + if (service is FormServices form) + { + form.ShowDialog(); + } + } + + private void EmployeesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormEmployees)); + if (service is FormEmployees form) + { + form.ShowDialog(); + } + } + + private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + if (service is FormClients form) + { + form.ShowDialog(); + } } } } \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormOrderServices.Designer.cs b/BeautySaloon/BeautySaloonView/FormOrderServices.Designer.cs new file mode 100644 index 0000000..8b10db5 --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormOrderServices.Designer.cs @@ -0,0 +1,149 @@ +namespace BeautySaloonView +{ + partial class FormOrderServices + { + /// + /// 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.comboBoxService = new System.Windows.Forms.ComboBox(); + this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.comboBoxEmployee = new System.Windows.Forms.ComboBox(); + this.labelService = new System.Windows.Forms.Label(); + this.labelEmployee = new System.Windows.Forms.Label(); + this.labelDate = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // comboBoxService + // + this.comboBoxService.FormattingEnabled = true; + this.comboBoxService.Location = new System.Drawing.Point(133, 11); + this.comboBoxService.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxService.Name = "comboBoxService"; + this.comboBoxService.Size = new System.Drawing.Size(311, 23); + this.comboBoxService.TabIndex = 9; + // + // dateTimePicker + // + this.dateTimePicker.CustomFormat = "HH:mm"; + this.dateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.dateTimePicker.Location = new System.Drawing.Point(133, 68); + this.dateTimePicker.Name = "dateTimePicker"; + this.dateTimePicker.ShowUpDown = true; + this.dateTimePicker.Size = new System.Drawing.Size(311, 23); + this.dateTimePicker.TabIndex = 10; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(365, 96); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(80, 22); + this.buttonCancel.TabIndex = 13; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(279, 96); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(80, 22); + this.buttonSave.TabIndex = 12; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // comboBoxEmployee + // + this.comboBoxEmployee.FormattingEnabled = true; + this.comboBoxEmployee.Location = new System.Drawing.Point(133, 40); + this.comboBoxEmployee.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxEmployee.Name = "comboBoxEmployee"; + this.comboBoxEmployee.Size = new System.Drawing.Size(311, 23); + this.comboBoxEmployee.TabIndex = 14; + // + // labelService + // + this.labelService.AutoSize = true; + this.labelService.Location = new System.Drawing.Point(12, 14); + this.labelService.Name = "labelService"; + this.labelService.Size = new System.Drawing.Size(44, 15); + this.labelService.TabIndex = 15; + this.labelService.Text = "Услуга"; + // + // labelEmployee + // + this.labelEmployee.AutoSize = true; + this.labelEmployee.Location = new System.Drawing.Point(12, 43); + this.labelEmployee.Name = "labelEmployee"; + this.labelEmployee.Size = new System.Drawing.Size(59, 15); + this.labelEmployee.TabIndex = 16; + this.labelEmployee.Text = "Работник"; + // + // labelDate + // + this.labelDate.AutoSize = true; + this.labelDate.Location = new System.Drawing.Point(12, 74); + this.labelDate.Name = "labelDate"; + this.labelDate.Size = new System.Drawing.Size(82, 15); + this.labelDate.TabIndex = 17; + this.labelDate.Text = "Время услуги"; + // + // FormOrderServices + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(456, 126); + this.Controls.Add(this.labelDate); + this.Controls.Add(this.labelEmployee); + this.Controls.Add(this.labelService); + this.Controls.Add(this.comboBoxEmployee); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.dateTimePicker); + this.Controls.Add(this.comboBoxService); + this.Name = "FormOrderServices"; + this.Text = "Услуга заказа"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxService; + private DateTimePicker dateTimePicker; + private Button buttonCancel; + private Button buttonSave; + private ComboBox comboBoxEmployee; + private Label labelService; + private Label labelEmployee; + private Label labelDate; + } +} \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormOrderServices.cs b/BeautySaloon/BeautySaloonView/FormOrderServices.cs new file mode 100644 index 0000000..5aee4fd --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormOrderServices.cs @@ -0,0 +1,99 @@ +using BeautySaloonContracts.BusinessLogicsContracts; +using BeautySaloonContracts.ViewModels; +using BeautySaloonDataModels; + +namespace BeautySaloonView +{ + public partial class FormOrderServices : Form + { + private readonly List? _listS; + private readonly List? _listE; + public int IdService + { + get + { + return Convert.ToInt32(comboBoxService.SelectedValue); + } + set + { + comboBoxService.SelectedValue = value; + } + } + public int IdEmployee + { + get + { + return Convert.ToInt32(comboBoxEmployee.SelectedValue); + } + set + { + comboBoxEmployee.SelectedValue = value; + } + } + public IServiceModel? ServiceModel + { + get + { + if (_listS == null) + { + return null; + } + foreach (var elem in _listS) + { + if (elem.Id == IdService) + { + return elem; + } + } + return null; + } + } + public TimeOnly Date + { + get { return TimeOnly.FromDateTime(dateTimePicker.Value); } + set { dateTimePicker.Text = value.ToString(); } + } + public FormOrderServices(IServiceLogic logicS, IEmployeeLogic logicE) + { + InitializeComponent(); + _listS = logicS.ReadList(null); + _listE = logicE.ReadList(null); + if (_listS != null) + { + comboBoxService.DisplayMember = "Name"; + comboBoxService.ValueMember = "Id"; + comboBoxService.DataSource = _listS; + comboBoxService.SelectedItem = null; + } + if (_listE != null) + { + comboBoxEmployee.DisplayMember = "FIO"; + comboBoxEmployee.ValueMember = "Id"; + comboBoxEmployee.DataSource = _listE; + comboBoxEmployee.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxService.SelectedValue == null) + { + MessageBox.Show("Выберите услугу", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxEmployee.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/BeautySaloon/BeautySaloonView/FormOrderServices.resx b/BeautySaloon/BeautySaloonView/FormOrderServices.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormOrderServices.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/BeautySaloon/BeautySaloonView/FormPosition.Designer.cs b/BeautySaloon/BeautySaloonView/FormPosition.Designer.cs new file mode 100644 index 0000000..daa3020 --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormPosition.Designer.cs @@ -0,0 +1,99 @@ +namespace BeautySaloonView +{ + partial class FormPosition + { + /// + /// 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.labelPosition = new System.Windows.Forms.Label(); + this.textBox = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelPosition + // + this.labelPosition.AutoSize = true; + this.labelPosition.Location = new System.Drawing.Point(12, 9); + this.labelPosition.Name = "labelPosition"; + this.labelPosition.Size = new System.Drawing.Size(123, 15); + this.labelPosition.TabIndex = 0; + this.labelPosition.Text = "Название должности"; + // + // textBox + // + this.textBox.Location = new System.Drawing.Point(141, 6); + this.textBox.Name = "textBox"; + this.textBox.Size = new System.Drawing.Size(223, 23); + this.textBox.TabIndex = 1; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(282, 34); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 13; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(194, 34); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + this.buttonSave.TabIndex = 12; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormPosition + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(376, 60); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBox); + this.Controls.Add(this.labelPosition); + this.Name = "FormPosition"; + this.Text = "Создание должности"; + this.Load += new System.EventHandler(this.FormPosition_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelPosition; + private TextBox textBox; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormPosition.cs b/BeautySaloon/BeautySaloonView/FormPosition.cs new file mode 100644 index 0000000..90af17e --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormPosition.cs @@ -0,0 +1,75 @@ +using BeautySaloonContracts.BindingModels; +using BeautySaloonContracts.BusinessLogicsContracts; +using BeautySaloonContracts.SearchModels; +using System.Windows.Forms; + +namespace BeautySaloonView +{ + public partial class FormPosition : Form + { + private readonly IPositionLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormPosition(IPositionLogic logic) + { + InitializeComponent(); + _logic = logic; + } + private void FormPosition_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var view = _logic.ReadElement(new PositionSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBox.Text = view.Name; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + var model = new PositionBindingModel + { + Id = _id ?? 0, + Name = textBox.Text + }; + 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) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/BeautySaloon/BeautySaloonView/FormPosition.resx b/BeautySaloon/BeautySaloonView/FormPosition.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormPosition.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/BeautySaloon/BeautySaloonView/FormPositions.Designer.cs b/BeautySaloon/BeautySaloonView/FormPositions.Designer.cs new file mode 100644 index 0000000..c29a0da --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormPositions.Designer.cs @@ -0,0 +1,122 @@ +namespace BeautySaloonView +{ + partial class FormPositions + { + /// + /// 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.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + 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(426, 337); + this.dataGridView.TabIndex = 10; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(435, 195); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(130, 22); + this.buttonUpdate.TabIndex = 14; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(435, 169); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(130, 22); + this.buttonDelete.TabIndex = 13; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(435, 143); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 22); + this.buttonEdit.TabIndex = 12; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(435, 117); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 22); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormPositions + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(577, 337); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormPositions"; + this.Text = "Должности"; + this.Load += new System.EventHandler(this.FormPositions_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormPositions.cs b/BeautySaloon/BeautySaloonView/FormPositions.cs new file mode 100644 index 0000000..72b0486 --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormPositions.cs @@ -0,0 +1,92 @@ +using BeautySaloonContracts.BindingModels; +using BeautySaloonContracts.BusinessLogicsContracts; + +namespace BeautySaloonView +{ + public partial class FormPositions : Form + { + private readonly IPositionLogic _logic; + public FormPositions(IPositionLogic logic) + { + InitializeComponent(); + _logic = logic; + } + private void FormPositions_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPosition)); + if (service is FormPosition form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPosition)); + if (service is FormPosition form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_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); + + try + { + if (!_logic.Delete(new PositionBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении."); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/BeautySaloon/BeautySaloonView/FormPositions.resx b/BeautySaloon/BeautySaloonView/FormPositions.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormPositions.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/BeautySaloon/BeautySaloonView/FormService.Designer.cs b/BeautySaloon/BeautySaloonView/FormService.Designer.cs new file mode 100644 index 0000000..82b6483 --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormService.Designer.cs @@ -0,0 +1,124 @@ +namespace BeautySaloonView +{ + partial class FormService + { + /// + /// 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.labelService = new System.Windows.Forms.Label(); + this.textBox = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.labelPrice = new System.Windows.Forms.Label(); + this.numericUpDown = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown)).BeginInit(); + this.SuspendLayout(); + // + // labelService + // + this.labelService.AutoSize = true; + this.labelService.Location = new System.Drawing.Point(12, 9); + this.labelService.Name = "labelService"; + this.labelService.Size = new System.Drawing.Size(99, 15); + this.labelService.TabIndex = 0; + this.labelService.Text = "Название услуги"; + // + // textBox + // + this.textBox.Location = new System.Drawing.Point(141, 6); + this.textBox.Name = "textBox"; + this.textBox.Size = new System.Drawing.Size(223, 23); + this.textBox.TabIndex = 1; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(282, 63); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 13; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(194, 63); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + this.buttonSave.TabIndex = 12; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(12, 37); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(35, 15); + this.labelPrice.TabIndex = 14; + this.labelPrice.Text = "Цена"; + // + // numericUpDown + // + this.numericUpDown.Location = new System.Drawing.Point(141, 35); + this.numericUpDown.Name = "numericUpDown"; + this.numericUpDown.Size = new System.Drawing.Size(223, 23); + this.numericUpDown.TabIndex = 15; + this.numericUpDown.Maximum = 20000; + // + // FormService + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(376, 91); + this.Controls.Add(this.numericUpDown); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBox); + this.Controls.Add(this.labelService); + this.Name = "FormService"; + this.Text = "Создание услуги"; + this.Load += new System.EventHandler(this.FormService_Load); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelService; + private TextBox textBox; + private Button buttonCancel; + private Button buttonSave; + private Label labelPrice; + private NumericUpDown numericUpDown; + } +} \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormService.cs b/BeautySaloon/BeautySaloonView/FormService.cs new file mode 100644 index 0000000..58fc7e4 --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormService.cs @@ -0,0 +1,81 @@ +using BeautySaloonContracts.BindingModels; +using BeautySaloonContracts.BusinessLogicsContracts; +using BeautySaloonContracts.SearchModels; + +namespace BeautySaloonView +{ + public partial class FormService : Form + { + private readonly IServiceLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormService(IServiceLogic logic) + { + InitializeComponent(); + _logic = logic; + } + private void FormService_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var view = _logic.ReadElement(new ServiceSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBox.Text = view.Name; + numericUpDown.Value = view.Price; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBox.Text) || numericUpDown.Value <= 0) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (numericUpDown.Value <= 0) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + var model = new ServiceBindingModel + { + Id = _id ?? 0, + Name = textBox.Text, + Price = numericUpDown.Value, + }; + 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) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/BeautySaloon/BeautySaloonView/FormService.resx b/BeautySaloon/BeautySaloonView/FormService.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormService.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/BeautySaloon/BeautySaloonView/FormServices.Designer.cs b/BeautySaloon/BeautySaloonView/FormServices.Designer.cs new file mode 100644 index 0000000..da97305 --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormServices.Designer.cs @@ -0,0 +1,122 @@ +namespace BeautySaloonView +{ + partial class FormServices + { + /// + /// 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.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + 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(426, 337); + this.dataGridView.TabIndex = 10; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(435, 195); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(130, 22); + this.buttonUpdate.TabIndex = 14; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(435, 169); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(130, 22); + this.buttonDelete.TabIndex = 13; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(435, 143); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 22); + this.buttonEdit.TabIndex = 12; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(435, 117); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 22); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormServices + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(577, 337); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormServices"; + this.Text = "Услуги"; + this.Load += new System.EventHandler(this.FormServices_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormServices.cs b/BeautySaloon/BeautySaloonView/FormServices.cs new file mode 100644 index 0000000..0e88ca2 --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormServices.cs @@ -0,0 +1,91 @@ +using BeautySaloonContracts.BindingModels; +using BeautySaloonContracts.BusinessLogicsContracts; + +namespace BeautySaloonView +{ + public partial class FormServices : Form + { + private readonly IServiceLogic _logic; + public FormServices(IServiceLogic logic) + { + InitializeComponent(); + _logic = logic; + } + private void FormServices_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormService)); + if (service is FormService form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormService)); + if (service is FormService form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_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); + try + { + if (!_logic.Delete(new ServiceBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении."); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/BeautySaloon/BeautySaloonView/FormServices.resx b/BeautySaloon/BeautySaloonView/FormServices.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormServices.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/BeautySaloon/BeautySaloonView/Program.cs b/BeautySaloon/BeautySaloonView/Program.cs index a08a70e..0624990 100644 --- a/BeautySaloon/BeautySaloonView/Program.cs +++ b/BeautySaloon/BeautySaloonView/Program.cs @@ -1,6 +1,7 @@ using BeautySaloonBusinessLogic; using BeautySaloonContracts.BusinessLogicsContracts; using BeautySaloonContracts.StoragesContracts; +using BeautySaloonDatabaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; namespace BeautySaloonView @@ -28,11 +29,11 @@ namespace BeautySaloonView private static void ConfigureServices(ServiceCollection services) { - /*services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient();*/ + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -40,7 +41,18 @@ namespace BeautySaloonView 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(); } } } \ No newline at end of file