From 24146e1a05a5281acf9c6695e44c2a897d89dd40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=9A=D1=80?= =?UTF-8?q?=D1=8E=D0=BA=D0=BE=D0=B2?= Date: Wed, 6 Nov 2024 03:01:20 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=BC=D0=B5=D0=B6=D1=83?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D1=8B=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EmployerForm/FormMain.Designer.cs | 25 +++++----- EmployerForm/FormMain.cs | 82 ++++++++++++++++--------------- 2 files changed, 54 insertions(+), 53 deletions(-) diff --git a/EmployerForm/FormMain.Designer.cs b/EmployerForm/FormMain.Designer.cs index d4f220c..954cf52 100644 --- a/EmployerForm/FormMain.Designer.cs +++ b/EmployerForm/FormMain.Designer.cs @@ -41,7 +41,7 @@ excelTable = new KryukovLib.ExcelTable(components); pdfDiagram = new BarsukovComponents.NotVisualComponents.PdfDiagram(components); wordWithTable = new BelianinComponents.WordWithTable(components); - listBoxMany1 = new KashinComponent.ListBoxMany(); + customListBox = new BarsukovComponents.VisualComponents.CustomListBox(); menuStrip.SuspendLayout(); SuspendLayout(); // @@ -52,7 +52,7 @@ menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Padding = new Padding(5, 2, 0, 2); - menuStrip.Size = new Size(514, 24); + menuStrip.Size = new Size(724, 24); menuStrip.TabIndex = 1; menuStrip.Text = "menuStrip1"; // @@ -120,22 +120,21 @@ directoryToolStripMenuItem.Text = "Directory"; directoryToolStripMenuItem.Click += DirectoryToolStripMenuItem_Click; // - // listBoxMany1 + // customListBox // - listBoxMany1.AutoSizeMode = AutoSizeMode.GrowAndShrink; - listBoxMany1.Dock = DockStyle.Fill; - listBoxMany1.Location = new Point(0, 24); - listBoxMany1.Name = "listBoxMany1"; - listBoxMany1.SelectedIndex = -1; - listBoxMany1.Size = new Size(514, 406); - listBoxMany1.TabIndex = 1; + customListBox.Location = new Point(0, 26); + customListBox.Margin = new Padding(3, 2, 3, 2); + customListBox.Name = "customListBox"; + customListBox.SelectedRow = -1; + customListBox.Size = new Size(724, 308); + customListBox.TabIndex = 2; // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(514, 430); - Controls.Add(listBoxMany1); + ClientSize = new Size(724, 323); + Controls.Add(customListBox); Controls.Add(menuStrip); MainMenuStrip = menuStrip; Margin = new Padding(3, 2, 3, 2); @@ -161,6 +160,6 @@ private KryukovLib.ExcelTable excelTable; private BarsukovComponents.NotVisualComponents.PdfDiagram pdfDiagram; private BelianinComponents.WordWithTable wordWithTable; - private KashinComponent.ListBoxMany listBoxMany1; + private BarsukovComponents.VisualComponents.CustomListBox customListBox; } } diff --git a/EmployerForm/FormMain.cs b/EmployerForm/FormMain.cs index 166ec1b..3104bfa 100644 --- a/EmployerForm/FormMain.cs +++ b/EmployerForm/FormMain.cs @@ -7,6 +7,7 @@ using KryukovLib; using Unity; using DocumentFormat.OpenXml.Bibliography; using KashinComponent; +using BarsukovComponents.VisualComponents; // Assuming CustomListBox is in this namespace namespace EmployerForm { @@ -21,7 +22,6 @@ namespace EmployerForm _LogicS = logicS; } - private void DropComponents() { Controls.Clear(); @@ -33,14 +33,17 @@ namespace EmployerForm try { DropComponents(); - listBoxMany1.SetLayout("{Subdivision} {Id} {Fio} {Experience}", "{", "}"); + + customListBox.setTemplate("{Subdivision} {Id} {Fio} {Experience}", "{", "}"); var list = _LogicE.Read(null) ?? throw new Exception("Error on read"); + for (int i = 0; i < list.Count; i++) { + for (int j = 0; j < 4; j++) { - listBoxMany1.AddItemInList(list[i], i, j); + customListBox.FillProperty(list[i], i, GetPropertyName(j)); } } } @@ -50,6 +53,18 @@ namespace EmployerForm } } + private string GetPropertyName(int index) + { + + switch (index) + { + case 0: return "Subdivision"; + case 1: return "Id"; + case 2: return "Fio"; + case 3: return "Experience"; + default: return string.Empty; + } + } private void FormMain_Load(object sender, EventArgs e) { @@ -67,7 +82,7 @@ namespace EmployerForm private void EditEmployerToolStripMenuItem_Click_1(object sender, EventArgs e) { - var selectedEmployee = listBoxMany1.GetItemFromList(); + var selectedEmployee = customListBox.GetObjectFromStr(); if (selectedEmployee == null) { MessageBox.Show("Please select an employee from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); @@ -85,7 +100,7 @@ namespace EmployerForm private void DeleteEmployerToolStripMenuItem_Click_1(object sender, EventArgs e) { - var selectedEmployee = listBoxMany1.GetItemFromList(); + var selectedEmployee = customListBox.GetObjectFromStr(); if (selectedEmployee == null) { MessageBox.Show("Please select an employee from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); @@ -108,21 +123,18 @@ namespace EmployerForm private void ExcelToolStripMenuItem_Click(object sender, EventArgs e) { - // Проверка инициализации объекта _LogicE if (_LogicE == null) { - MessageBox.Show("Логика не инициализирована.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Logic not initialized.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - // Проверка инициализации объекта excelTable if (excelTable == null) { - MessageBox.Show("Объект для работы с Excel не инициализирован.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Excel object not initialized.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - // Открытие диалога для сохранения файла string fileName = ""; using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }) { @@ -133,61 +145,51 @@ namespace EmployerForm } } - // Получение выбранного элемента из списка - var ent = listBoxMany1.GetItemFromList(); - if (ent == null) + var selectedEmployee = customListBox.GetObjectFromStr(); + if (selectedEmployee == null) { - MessageBox.Show("Выберите элемент из списка.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Select an item from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - // Чтение данных сотрудника - var EmplList = _LogicE.Read(new EmployeeBindingModel { Id = ent.Id }); - if (EmplList == null || EmplList.Count == 0) + var emplList = _LogicE.Read(new EmployeeBindingModel { Id = selectedEmployee.Id }); + if (emplList == null || emplList.Count == 0) { - MessageBox.Show("Не удалось найти сотрудника.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Could not find employee.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - var Empl = EmplList[0]; + var empl = emplList[0]; - // Проверка наличия должностей у сотрудника - if (string.IsNullOrEmpty(Empl.Posts)) + if (string.IsNullOrEmpty(empl.Posts)) { - MessageBox.Show("У сотрудника нет должностей.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); + MessageBox.Show("No positions for the employee.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } - // Создание и заполнение массива Data - var posts = Empl.Posts.Split(","); - var Data = new string[1, Math.Min(posts.Length, 5)]; - for (int i = 0; i < Data.GetLength(1); i++) + 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]; + data[0, i] = posts[i]; } - // Оборачивание Data в список для совместимости с TableConfig - var dataList = new List() { Data }; + var dataList = new List() { data }; - // Проверка выбора файла if (string.IsNullOrEmpty(fileName)) { - MessageBox.Show("Файл не выбран.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("File not selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - // Создание Excel документа excelTable.CreateDoc(new KryukovLib.Models.TableConfig { FilePath = fileName, Header = "Example", - Data = dataList // Передача в виде списка + Data = dataList }); } - - - private void WordToolStripMenuItem_Click(object sender, EventArgs e) { string fileName = ""; @@ -199,6 +201,7 @@ namespace EmployerForm MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); } } + var list = _LogicE.Read(null); wordWithTable.CreateDoc(new WordWithTableDataConfig { @@ -234,7 +237,7 @@ namespace EmployerForm var listEmp = _LogicE.Read(null); var listSubd = _LogicS.Read(null); - var Data = new Dictionary>(); + var data = new Dictionary>(); foreach (var item in listSubd) { @@ -246,13 +249,12 @@ namespace EmployerForm listSorted.Where(y => y.Experience >= 10 && y.Experience < 20).Count(), listSorted.Where(y => y.Experience >= 20 && y.Experience < 30).Count()); - Data.Add(item.Name, new List { x.Item1, x.Item2, x.Item3, x.Item4 }); + data.Add(item.Name, new List { x.Item1, x.Item2, x.Item3, x.Item4 }); } - pdfDiagram.CreateDiagram(fileName, "Chart", "Chart", Data); + pdfDiagram.CreateDiagram(fileName, "Chart", "Chart", data); } - private void DirectoryToolStripMenuItem_Click(object sender, EventArgs e) { var form = Program.Container.Resolve();