From 755ce796a05032bd81a0024e68c260c519a509b0 Mon Sep 17 00:00:00 2001 From: kaznacheeva Date: Mon, 11 Nov 2024 22:18:51 +0400 Subject: [PATCH] =?UTF-8?q?=D1=87=D1=82=D0=BE=20=D1=82=D0=BE=20=D0=B5?= =?UTF-8?q?=D1=89=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/EmployeeLogic.cs | 11 ++- .../BusinessLogics/SubdivisionLogic.cs | 75 ++++++++--------- ....cs => 20241111144747_Initial.Designer.cs} | 4 +- ...7_Initial.cs => 20241111144747_Initial.cs} | 2 +- .../EnterpriseDataBaseModelSnapshot.cs | 2 +- COP_9/FormView/EmployerForm.cs | 3 - COP_9/FormView/FormMain.cs | 84 ++++--------------- COP_9/FormView/Program.cs | 4 +- 8 files changed, 63 insertions(+), 122 deletions(-) rename COP_9/EnterpriseDataBaseImplemen/Migrations/{20241028192747_Initial.Designer.cs => 20241111144747_Initial.Designer.cs} (96%) rename COP_9/EnterpriseDataBaseImplemen/Migrations/{20241028192747_Initial.cs => 20241111144747_Initial.cs} (97%) diff --git a/COP_9/EnterpriseBusinessLogic/BusinessLogics/EmployeeLogic.cs b/COP_9/EnterpriseBusinessLogic/BusinessLogics/EmployeeLogic.cs index a90e6aa..4c6dce6 100644 --- a/COP_9/EnterpriseBusinessLogic/BusinessLogics/EmployeeLogic.cs +++ b/COP_9/EnterpriseBusinessLogic/BusinessLogics/EmployeeLogic.cs @@ -14,18 +14,15 @@ namespace EnterpriseBusinessLogic.BusinessLogics public EmployeeLogic(IEmployeeStorage empStorage) { - _empStorage = empStorage ?? throw new ArgumentNullException(nameof(empStorage), "Хранилище сотрудников не инициализировано."); + _empStorage = empStorage; } public List Read(EmployeeBindingModel? model) { if (model == null) - { return _empStorage.GetFullList(); - } - return model.Id.HasValue - ? new List { _empStorage.GetElement(model) ?? throw new Exception("Сотрудник не найден.") } + ? new List { _empStorage.GetElement(model) } : _empStorage.GetFilteredList(model); } @@ -43,7 +40,9 @@ namespace EnterpriseBusinessLogic.BusinessLogics public void Delete(EmployeeBindingModel model) { - _ = _empStorage.GetElement(new EmployeeBindingModel { Id = model.Id }) ?? throw new Exception("Id don't exist"); + var element = _empStorage.GetElement(new EmployeeBindingModel { Id = model.Id }); + if (element == null) + throw new Exception("Id don't exists"); _empStorage.Delete(model); } } diff --git a/COP_9/EnterpriseBusinessLogic/BusinessLogics/SubdivisionLogic.cs b/COP_9/EnterpriseBusinessLogic/BusinessLogics/SubdivisionLogic.cs index 7902ddb..2162b52 100644 --- a/COP_9/EnterpriseBusinessLogic/BusinessLogics/SubdivisionLogic.cs +++ b/COP_9/EnterpriseBusinessLogic/BusinessLogics/SubdivisionLogic.cs @@ -3,48 +3,47 @@ using EnterpriseContracts.BusinessLogicContracts; using EnterpriseContracts.StorageContracts; using EnterpriseContracts.ViewModels; -namespace EnterpriseBusinessLogic.BusinessLogics +namespace EnterpriseBusinessLogic.BusinessLogics; + +public class SubdivisionLogic : ISubdivisionLogic { - public class SubdivisionLogic : ISubdivisionLogic - { - private readonly ISubdivisionStorage _subdivisionStorage; + private readonly ISubdivisionStorage _subdivisionStorage; - public SubdivisionLogic(ISubdivisionStorage subdivisionStorage) - { - _subdivisionStorage = subdivisionStorage; - } + public SubdivisionLogic(ISubdivisionStorage subdivisionStorage) + { + _subdivisionStorage = subdivisionStorage; + } - public List Read(SubdivisionBindingModel? model) - { - if (model == null) - return _subdivisionStorage.GetFullList(); - return model.Id != 0 ? - new List { _subdivisionStorage.GetElement(model) } : - _subdivisionStorage.GetFilteredList(model); - } + public List Read(SubdivisionBindingModel? model) + { + if (model == null) + return _subdivisionStorage.GetFullList(); + return model.Id != 0 ? + new List { _subdivisionStorage.GetElement(model) } : + _subdivisionStorage.GetFilteredList(model); + } - public void CreateOrUpdate(SubdivisionBindingModel model) - { - var element = _subdivisionStorage.GetElement(new SubdivisionBindingModel - { - Name = model.Name - }); + public void CreateOrUpdate(SubdivisionBindingModel model) + { + var element = _subdivisionStorage.GetElement(new SubdivisionBindingModel + { + Name = model.Name + }); - if (element != null && element.Id != model.Id) - throw new Exception("This name is exists!"); - if (model.Id != 0) - _subdivisionStorage.Update(model); - else - _subdivisionStorage.Insert(model); - } + if (element != null && element.Id != model.Id) + throw new Exception("This name is exists!"); + if (model.Id != 0) + _subdivisionStorage.Update(model); + else + _subdivisionStorage.Insert(model); + } - public bool Delete(SubdivisionBindingModel model) - { - var element = _subdivisionStorage.GetElement(new SubdivisionBindingModel { Id = model.Id }); - if (element == null) - return false; - _subdivisionStorage.Delete(model); - return true; - } - } + public bool Delete(SubdivisionBindingModel model) + { + var element = _subdivisionStorage.GetElement(new SubdivisionBindingModel { Id = model.Id }); + if (element == null) + return false; + _subdivisionStorage.Delete(model); + return true; + } } \ No newline at end of file diff --git a/COP_9/EnterpriseDataBaseImplemen/Migrations/20241028192747_Initial.Designer.cs b/COP_9/EnterpriseDataBaseImplemen/Migrations/20241111144747_Initial.Designer.cs similarity index 96% rename from COP_9/EnterpriseDataBaseImplemen/Migrations/20241028192747_Initial.Designer.cs rename to COP_9/EnterpriseDataBaseImplemen/Migrations/20241111144747_Initial.Designer.cs index 87ab4c4..de91bfa 100644 --- a/COP_9/EnterpriseDataBaseImplemen/Migrations/20241028192747_Initial.Designer.cs +++ b/COP_9/EnterpriseDataBaseImplemen/Migrations/20241111144747_Initial.Designer.cs @@ -8,10 +8,10 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable -namespace EnterpriseDataBaseImplemen.Migrations +namespace EnterpriseDataBaseImplement.Migrations { [DbContext(typeof(EnterpriseDataBase))] - [Migration("20241028192747_Initial")] + [Migration("20241111144747_Initial")] partial class Initial { /// diff --git a/COP_9/EnterpriseDataBaseImplemen/Migrations/20241028192747_Initial.cs b/COP_9/EnterpriseDataBaseImplemen/Migrations/20241111144747_Initial.cs similarity index 97% rename from COP_9/EnterpriseDataBaseImplemen/Migrations/20241028192747_Initial.cs rename to COP_9/EnterpriseDataBaseImplemen/Migrations/20241111144747_Initial.cs index e4f86b9..f991ae8 100644 --- a/COP_9/EnterpriseDataBaseImplemen/Migrations/20241028192747_Initial.cs +++ b/COP_9/EnterpriseDataBaseImplemen/Migrations/20241111144747_Initial.cs @@ -2,7 +2,7 @@ #nullable disable -namespace EnterpriseDataBaseImplemen.Migrations +namespace EnterpriseDataBaseImplement.Migrations { /// public partial class Initial : Migration diff --git a/COP_9/EnterpriseDataBaseImplemen/Migrations/EnterpriseDataBaseModelSnapshot.cs b/COP_9/EnterpriseDataBaseImplemen/Migrations/EnterpriseDataBaseModelSnapshot.cs index 7fd61b2..863c673 100644 --- a/COP_9/EnterpriseDataBaseImplemen/Migrations/EnterpriseDataBaseModelSnapshot.cs +++ b/COP_9/EnterpriseDataBaseImplemen/Migrations/EnterpriseDataBaseModelSnapshot.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable -namespace EnterpriseDataBaseImplemen.Migrations +namespace EnterpriseDataBaseImplement.Migrations { [DbContext(typeof(EnterpriseDataBase))] partial class EnterpriseDataBaseModelSnapshot : ModelSnapshot diff --git a/COP_9/FormView/EmployerForm.cs b/COP_9/FormView/EmployerForm.cs index 3899e37..9896fef 100644 --- a/COP_9/FormView/EmployerForm.cs +++ b/COP_9/FormView/EmployerForm.cs @@ -69,10 +69,7 @@ namespace FormView if (view != null) { textBoxFio.Text = view.Fio; - - // Используем свойство SelectedItem для установки выбранного элемента dropDownList.SelectedItem = view.Subdivision; - customInputRangeNumber.Value = view.Experience; textBoxPosts.Text = view.Posts; } diff --git a/COP_9/FormView/FormMain.cs b/COP_9/FormView/FormMain.cs index f7eeff8..12ccf6e 100644 --- a/COP_9/FormView/FormMain.cs +++ b/COP_9/FormView/FormMain.cs @@ -41,7 +41,7 @@ namespace FormView { DropComponents(); - listBoxMany.SetTemplateString("Индификатор: {Id} Имя: {Fio} Опыт: {Experience} Подразделение: {Subdivision}", "{", "}"); + listBoxMany.SetTemplateString("ID: {Id} ФИО: {Fio} Опыт: {Experience} Подраз-ие: {Subdivision}", "{", "}"); var list = _LogicE.Read(null) ?? throw new Exception("Error on read"); @@ -89,16 +89,8 @@ namespace FormView private void EditEmployerToolStripMenuItem_Click(object sender, EventArgs e) { - var selectedEmployee = listBoxMany.GetObjectFromStr(); - if (selectedEmployee == null) - { - MessageBox.Show("Please select an employee from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - var form = Program.Container.Resolve(); - form.Id = selectedEmployee.Id; - + form.Id = Convert.ToInt32(listBoxMany.GetObjectFromStr().Id); if (form.ShowDialog() == DialogResult.OK) { LoadData(); @@ -107,93 +99,47 @@ namespace FormView private void DeleteEmployerToolStripMenuItem_Click(object sender, EventArgs e) { - var selectedEmployee = listBoxMany.GetObjectFromStr(); - if (selectedEmployee == null) - { - MessageBox.Show("Please select an employee from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (MessageBox.Show("Delete record", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { + var ent = listBoxMany.GetObjectFromStr(); + try { - _LogicE.Delete(new EmployeeBindingModel { Id = selectedEmployee.Id }); - LoadData(); + int id = Convert.ToInt32(ent.Id); + _LogicE.Delete(new EmployeeBindingModel { Id = id }); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } + LoadData(); } } private void ExcelToolStripMenuItem_Click(object sender, EventArgs e) { - if (_LogicE == null) - { - MessageBox.Show("Logic not initialized.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - if (excelTable == null) - { - MessageBox.Show("Excel object not initialized.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - string fileName = ""; using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }) { if (dialog.ShowDialog() == DialogResult.OK) { - fileName = dialog.FileName; + fileName = dialog.FileName.ToString(); MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); } } - - var selectedEmployee = listBoxMany.GetObjectFromStr(); - if (selectedEmployee == null) + var ent = listBoxMany.GetObjectFromStr(); + var Empl = _LogicE.Read(new EmployeeBindingModel { Id = ent.Id })[0]; + var Data = new string[1, 5]; + int i = 0; + foreach (var post in Empl.Posts.Split(",")) { - MessageBox.Show("Select an item from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; + Data[0, i++] = post; } - - var emplList = _LogicE.Read(new EmployeeBindingModel { Id = selectedEmployee.Id }); - if (emplList == null || emplList.Count == 0) - { - MessageBox.Show("Could not find employee.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - var empl = emplList[0]; - - if (string.IsNullOrEmpty(empl.Posts)) - { - MessageBox.Show("No positions for the employee.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); - return; - } - - var posts = empl.Posts.Split(","); - var data = new string[1, Math.Min(posts.Length, 5)]; - for (int i = 0; i < data.GetLength(1); i++) - { - data[0, i] = posts[i]; - } - - var dataList = new List() { data }; - - if (string.IsNullOrEmpty(fileName)) - { - MessageBox.Show("File not selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - excelTable.CreateDoc(new WinFormsLibrary1.Models.TableConfig { FilePath = fileName, Header = "Example", - Data = dataList + Data = new List { Data } }); } diff --git a/COP_9/FormView/Program.cs b/COP_9/FormView/Program.cs index 36d0c97..76d420b 100644 --- a/COP_9/FormView/Program.cs +++ b/COP_9/FormView/Program.cs @@ -20,7 +20,7 @@ namespace FormView Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(Container.Resolve()); + Application.Run(Container.Resolve()); } private static IUnityContainer BuildUnityContainer @@ -35,7 +35,7 @@ namespace FormView currentContainer.RegisterType(new HierarchicalLifetimeManager()); currentContainer.RegisterType(new HierarchicalLifetimeManager()); - currentContainer.RegisterType(); + currentContainer.RegisterType(); currentContainer.RegisterType(); return currentContainer;