From 754edb3e2ab750a8a8391d493d157c97b76ae032 Mon Sep 17 00:00:00 2001 From: kotcheshir73 Date: Thu, 8 Apr 2021 14:27:21 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=82=D0=B5=D0=BB=D1=8F=20=D1=81=D0=BE=D1=82=D1=80=D1=83?= =?UTF-8?q?=D0=B4=D0=BD=D0=B8=D0=BA=D1=83=20=D0=B8=20=D0=BF=D1=80=D0=B5?= =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=B0=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Employee/ControlEmployeeElement.cs | 58 ++++++++++++++++++- .../Lecturer/ControlLecturerElement.cs | 58 ++++++++++++++++++- 2 files changed, 114 insertions(+), 2 deletions(-) diff --git a/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Employee/ControlEmployeeElement.cs b/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Employee/ControlEmployeeElement.cs index a72e8d0..5a705de 100644 --- a/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Employee/ControlEmployeeElement.cs +++ b/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Employee/ControlEmployeeElement.cs @@ -1,10 +1,17 @@ using DepartmentBusinessLogic.BindingModels; using DepartmentBusinessLogic.BusinessLogics; using DepartmentBusinessLogic.ViewModels; +using DesktopTools.BaseControls; using DesktopTools.Controls; +using DesktopTools.Helpers; using DesktopTools.Interfaces; using DesktopTools.Models; +using ModuleTools.BusinessLogics; +using ModuleTools.Extensions; +using SecurityBusinessLogic.BindingModels; +using SecurityBusinessLogic.BusinessLogics; using System; +using System.Collections.Generic; namespace DepartmentWindowsDesktop.EntityControls { @@ -25,6 +32,55 @@ namespace DepartmentWindowsDesktop.EntityControls public IControl GetInstanceGenericControl() => new ControlEmployeeElement() { ControlId = Guid.NewGuid() }; - public ControlViewEntityElementConfiguration GetConfigControl() => new(); + public ControlViewEntityElementConfiguration GetConfigControl() => new() + { + ControlOnMoveElem = new Dictionary + { + { "ToolStripMenuItemAddUser", ("Добавить пользователя", (object sender, EventArgs e) => { AddUser(); }) } + } + }; + + private void AddUser() + { + var model = new EmployeeSetBindingModel(); + if (FillModel(model)) + { + var logic = DependencyManager.Instance.Resolve(); + var userName = $"{model.LastName}{(model.FirstName.IsNotEmpty() ? $" {model.FirstName[0]}." : string.Empty)}{(model.Patronymic.IsNotEmpty() ? $"{model.Patronymic[0]}." : string.Empty)}"; + var result = logic.GetList(new UserGetBindingModel { UserNameForSearch = userName }); + if (result != null) + { + if (result.List.Count > 1) + { + DialogHelper.MessageException("Существует несколько пользователей с такой сигнатурой", "Ошибка"); + return; + } + if (result.List.Count == 1) + { + model.UserId = result.List[0].Id; + } + else + { + var newuser = logic.Create(new UserSetBindingModel + { + Login = userName, + Password = model.DateBirth.ToShortDateString(), + Avatar = model.Photo + }); + if (newuser == null) + { + DialogHelper.MessageException(logic.Errors, "Ошибка при создании пользователя"); + return; + } + model.UserId = newuser.Id; + } + var controls = tabPageMain.Controls.Find($"ControlUserId", true); + if (controls != null) + { + (controls[0] as AbstractBaseControl).SetValue(model); + } + } + } + } } } \ No newline at end of file diff --git a/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Lecturer/ControlLecturerElement.cs b/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Lecturer/ControlLecturerElement.cs index cfa04a2..3cf3b31 100644 --- a/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Lecturer/ControlLecturerElement.cs +++ b/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/Lecturer/ControlLecturerElement.cs @@ -1,10 +1,17 @@ using DepartmentBusinessLogic.BindingModels; using DepartmentBusinessLogic.BusinessLogics; using DepartmentBusinessLogic.ViewModels; +using DesktopTools.BaseControls; using DesktopTools.Controls; +using DesktopTools.Helpers; using DesktopTools.Interfaces; using DesktopTools.Models; +using ModuleTools.BusinessLogics; +using ModuleTools.Extensions; +using SecurityBusinessLogic.BindingModels; +using SecurityBusinessLogic.BusinessLogics; using System; +using System.Collections.Generic; namespace DepartmentWindowsDesktop.EntityControls { @@ -22,6 +29,55 @@ namespace DepartmentWindowsDesktop.EntityControls public IControl GetInstanceGenericControl() => new ControlLecturerElement() { ControlId = Guid.NewGuid() }; - public ControlViewEntityElementConfiguration GetConfigControl() => new(); + public ControlViewEntityElementConfiguration GetConfigControl() => new() + { + ControlOnMoveElem = new Dictionary + { + { "ToolStripMenuItemAddUser", ("Добавить пользователя", (object sender, EventArgs e) => { AddUser(); }) } + } + }; + + private void AddUser() + { + var model = new LecturerSetBindingModel(); + if (FillModel(model)) + { + var logic = DependencyManager.Instance.Resolve(); + var userName = $"{model.LastName}{(model.FirstName.IsNotEmpty() ? $" {model.FirstName[0]}." : string.Empty)}{(model.Patronymic.IsNotEmpty() ? $"{model.Patronymic[0]}." : string.Empty)}"; + var result = logic.GetList(new UserGetBindingModel { UserNameForSearch = userName }); + if (result != null) + { + if (result.List.Count > 1) + { + DialogHelper.MessageException("Существует несколько пользователей с такой сигнатурой", "Ошибка"); + return; + } + if (result.List.Count == 1) + { + model.UserId = result.List[0].Id; + } + else + { + var newuser = logic.Create(new UserSetBindingModel + { + Login = userName, + Password = model.DateBirth.ToShortDateString(), + Avatar = model.Photo + }); + if (newuser == null) + { + DialogHelper.MessageException(logic.Errors, "Ошибка при создании пользователя"); + return; + } + model.UserId = newuser.Id; + } + var controls = tabPageMain.Controls.Find($"ControlUserId", true); + if (controls != null) + { + (controls[0] as AbstractBaseControl).SetValue(model); + } + } + } + } } } \ No newline at end of file