что то еще

This commit is contained in:
Казначеева Елизавета 2024-11-11 22:18:51 +04:00
parent 3fb1d0a75a
commit 755ce796a0
8 changed files with 63 additions and 122 deletions

View File

@ -14,18 +14,15 @@ namespace EnterpriseBusinessLogic.BusinessLogics
public EmployeeLogic(IEmployeeStorage empStorage)
{
_empStorage = empStorage ?? throw new ArgumentNullException(nameof(empStorage), "Хранилище сотрудников не инициализировано.");
_empStorage = empStorage;
}
public List<EmployeeViewModel> Read(EmployeeBindingModel? model)
{
if (model == null)
{
return _empStorage.GetFullList();
}
return model.Id.HasValue
? new List<EmployeeViewModel> { _empStorage.GetElement(model) ?? throw new Exception("Сотрудник не найден.") }
? new List<EmployeeViewModel> { _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);
}
}

View File

@ -3,10 +3,10 @@ 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;
public SubdivisionLogic(ISubdivisionStorage subdivisionStorage)
@ -46,5 +46,4 @@ namespace EnterpriseBusinessLogic.BusinessLogics
_subdivisionStorage.Delete(model);
return true;
}
}
}

View File

@ -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
{
/// <inheritdoc />

View File

@ -2,7 +2,7 @@
#nullable disable
namespace EnterpriseDataBaseImplemen.Migrations
namespace EnterpriseDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class Initial : Migration

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EnterpriseDataBaseImplemen.Migrations
namespace EnterpriseDataBaseImplement.Migrations
{
[DbContext(typeof(EnterpriseDataBase))]
partial class EnterpriseDataBaseModelSnapshot : ModelSnapshot

View File

@ -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;
}

View File

@ -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<EmployeeViewModel>();
if (selectedEmployee == null)
{
MessageBox.Show("Please select an employee from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
var form = Program.Container.Resolve<EmployerForm>();
form.Id = selectedEmployee.Id;
form.Id = Convert.ToInt32(listBoxMany.GetObjectFromStr<EmployeeViewModel>().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<EmployeeViewModel>();
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<EmployeeViewModel>();
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<EmployeeViewModel>();
if (selectedEmployee == null)
var ent = listBoxMany.GetObjectFromStr<EmployeeViewModel>();
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<string[,]>() { 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<string[,]> { Data }
});
}

View File

@ -20,7 +20,7 @@ namespace FormView
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(Container.Resolve<FormMain1>());
Application.Run(Container.Resolve<FormMain>());
}
private static IUnityContainer BuildUnityContainer
@ -35,7 +35,7 @@ namespace FormView
currentContainer.RegisterType<IEmployeeLogic, EmployeeLogic>(new HierarchicalLifetimeManager());
currentContainer.RegisterType<ISubdivisionLogic, SubdivisionLogic>(new HierarchicalLifetimeManager());
currentContainer.RegisterType<EmployerForm1>();
currentContainer.RegisterType<EmployerForm>();
currentContainer.RegisterType<Directory>();
return currentContainer;