промежуточные

This commit is contained in:
Алексей Крюков 2024-11-06 03:01:20 +04:00
parent 91e2483fef
commit 24146e1a05
2 changed files with 54 additions and 53 deletions

View File

@ -41,7 +41,7 @@
excelTable = new KryukovLib.ExcelTable(components); excelTable = new KryukovLib.ExcelTable(components);
pdfDiagram = new BarsukovComponents.NotVisualComponents.PdfDiagram(components); pdfDiagram = new BarsukovComponents.NotVisualComponents.PdfDiagram(components);
wordWithTable = new BelianinComponents.WordWithTable(components); wordWithTable = new BelianinComponents.WordWithTable(components);
listBoxMany1 = new KashinComponent.ListBoxMany(); customListBox = new BarsukovComponents.VisualComponents.CustomListBox();
menuStrip.SuspendLayout(); menuStrip.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
@ -52,7 +52,7 @@
menuStrip.Location = new Point(0, 0); menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip"; menuStrip.Name = "menuStrip";
menuStrip.Padding = new Padding(5, 2, 0, 2); menuStrip.Padding = new Padding(5, 2, 0, 2);
menuStrip.Size = new Size(514, 24); menuStrip.Size = new Size(724, 24);
menuStrip.TabIndex = 1; menuStrip.TabIndex = 1;
menuStrip.Text = "menuStrip1"; menuStrip.Text = "menuStrip1";
// //
@ -120,22 +120,21 @@
directoryToolStripMenuItem.Text = "Directory"; directoryToolStripMenuItem.Text = "Directory";
directoryToolStripMenuItem.Click += DirectoryToolStripMenuItem_Click; directoryToolStripMenuItem.Click += DirectoryToolStripMenuItem_Click;
// //
// listBoxMany1 // customListBox
// //
listBoxMany1.AutoSizeMode = AutoSizeMode.GrowAndShrink; customListBox.Location = new Point(0, 26);
listBoxMany1.Dock = DockStyle.Fill; customListBox.Margin = new Padding(3, 2, 3, 2);
listBoxMany1.Location = new Point(0, 24); customListBox.Name = "customListBox";
listBoxMany1.Name = "listBoxMany1"; customListBox.SelectedRow = -1;
listBoxMany1.SelectedIndex = -1; customListBox.Size = new Size(724, 308);
listBoxMany1.Size = new Size(514, 406); customListBox.TabIndex = 2;
listBoxMany1.TabIndex = 1;
// //
// FormMain // FormMain
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(514, 430); ClientSize = new Size(724, 323);
Controls.Add(listBoxMany1); Controls.Add(customListBox);
Controls.Add(menuStrip); Controls.Add(menuStrip);
MainMenuStrip = menuStrip; MainMenuStrip = menuStrip;
Margin = new Padding(3, 2, 3, 2); Margin = new Padding(3, 2, 3, 2);
@ -161,6 +160,6 @@
private KryukovLib.ExcelTable excelTable; private KryukovLib.ExcelTable excelTable;
private BarsukovComponents.NotVisualComponents.PdfDiagram pdfDiagram; private BarsukovComponents.NotVisualComponents.PdfDiagram pdfDiagram;
private BelianinComponents.WordWithTable wordWithTable; private BelianinComponents.WordWithTable wordWithTable;
private KashinComponent.ListBoxMany listBoxMany1; private BarsukovComponents.VisualComponents.CustomListBox customListBox;
} }
} }

View File

@ -7,6 +7,7 @@ using KryukovLib;
using Unity; using Unity;
using DocumentFormat.OpenXml.Bibliography; using DocumentFormat.OpenXml.Bibliography;
using KashinComponent; using KashinComponent;
using BarsukovComponents.VisualComponents; // Assuming CustomListBox is in this namespace
namespace EmployerForm namespace EmployerForm
{ {
@ -21,7 +22,6 @@ namespace EmployerForm
_LogicS = logicS; _LogicS = logicS;
} }
private void DropComponents() private void DropComponents()
{ {
Controls.Clear(); Controls.Clear();
@ -33,14 +33,17 @@ namespace EmployerForm
try try
{ {
DropComponents(); DropComponents();
listBoxMany1.SetLayout("{Subdivision} {Id} {Fio} {Experience}", "{", "}");
customListBox.setTemplate("{Subdivision} {Id} {Fio} {Experience}", "{", "}");
var list = _LogicE.Read(null) ?? throw new Exception("Error on read"); var list = _LogicE.Read(null) ?? throw new Exception("Error on read");
for (int i = 0; i < list.Count; i++) for (int i = 0; i < list.Count; i++)
{ {
for (int j = 0; j < 4; j++) 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) private void FormMain_Load(object sender, EventArgs e)
{ {
@ -67,7 +82,7 @@ namespace EmployerForm
private void EditEmployerToolStripMenuItem_Click_1(object sender, EventArgs e) private void EditEmployerToolStripMenuItem_Click_1(object sender, EventArgs e)
{ {
var selectedEmployee = listBoxMany1.GetItemFromList<EmployeeViewModel>(); var selectedEmployee = customListBox.GetObjectFromStr<EmployeeViewModel>();
if (selectedEmployee == null) if (selectedEmployee == null)
{ {
MessageBox.Show("Please select an employee from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 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) private void DeleteEmployerToolStripMenuItem_Click_1(object sender, EventArgs e)
{ {
var selectedEmployee = listBoxMany1.GetItemFromList<EmployeeViewModel>(); var selectedEmployee = customListBox.GetObjectFromStr<EmployeeViewModel>();
if (selectedEmployee == null) if (selectedEmployee == null)
{ {
MessageBox.Show("Please select an employee from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 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) private void ExcelToolStripMenuItem_Click(object sender, EventArgs e)
{ {
// Ïðîâåðêà èíèöèàëèçàöèè îáúåêòà _LogicE
if (_LogicE == null) if (_LogicE == null)
{ {
MessageBox.Show("Ëîãèêà íå èíèöèàëèçèðîâàíà.", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Logic not initialized.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
// Ïðîâåðêà èíèöèàëèçàöèè îáúåêòà excelTable
if (excelTable == null) if (excelTable == null)
{ {
MessageBox.Show("Îáúåêò äëÿ ðàáîòû ñ Excel íå èíèöèàëèçèðîâàí.", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Excel object not initialized.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
// Îòêðûòèå äèàëîãà äëÿ ñîõðàíåíèÿ ôàéëà
string fileName = ""; string fileName = "";
using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }) using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" })
{ {
@ -133,61 +145,51 @@ namespace EmployerForm
} }
} }
// Ïîëó÷åíèå âûáðàííîãî ýëåìåíòà èç ñïèñêà var selectedEmployee = customListBox.GetObjectFromStr<EmployeeViewModel>();
var ent = listBoxMany1.GetItemFromList<EmployeeViewModel>(); if (selectedEmployee == null)
if (ent == null)
{ {
MessageBox.Show("Âûáåðèòå ýëåìåíò èç ñïèñêà.", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Select an item from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
// ×òåíèå äàííûõ ñîòðóäíèêà var emplList = _LogicE.Read(new EmployeeBindingModel { Id = selectedEmployee.Id });
var EmplList = _LogicE.Read(new EmployeeBindingModel { Id = ent.Id }); if (emplList == null || emplList.Count == 0)
if (EmplList == null || EmplList.Count == 0)
{ {
MessageBox.Show("Íå óäàëîñü íàéòè ñîòðóäíèêà.", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Could not find employee.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; 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; return;
} }
// Ñîçäàíèå è çàïîëíåíèå ìàññèâà Data var posts = empl.Posts.Split(",");
var posts = Empl.Posts.Split(","); var data = new string[1, Math.Min(posts.Length, 5)];
var Data = new string[1, Math.Min(posts.Length, 5)]; for (int i = 0; i < data.GetLength(1); i++)
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<string[,]>() { data };
var dataList = new List<string[,]>() { Data };
// Ïðîâåðêà âûáîðà ôàéëà
if (string.IsNullOrEmpty(fileName)) if (string.IsNullOrEmpty(fileName))
{ {
MessageBox.Show("Ôàéë íå âûáðàí.", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("File not selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
// Ñîçäàíèå Excel äîêóìåíòà
excelTable.CreateDoc(new KryukovLib.Models.TableConfig excelTable.CreateDoc(new KryukovLib.Models.TableConfig
{ {
FilePath = fileName, FilePath = fileName,
Header = "Example", Header = "Example",
Data = dataList // Ïåðåäà÷à â âèäå ñïèñêà Data = dataList
}); });
} }
private void WordToolStripMenuItem_Click(object sender, EventArgs e) private void WordToolStripMenuItem_Click(object sender, EventArgs e)
{ {
string fileName = ""; string fileName = "";
@ -199,6 +201,7 @@ namespace EmployerForm
MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
} }
var list = _LogicE.Read(null); var list = _LogicE.Read(null);
wordWithTable.CreateDoc(new WordWithTableDataConfig<EmployeeViewModel> wordWithTable.CreateDoc(new WordWithTableDataConfig<EmployeeViewModel>
{ {
@ -234,7 +237,7 @@ namespace EmployerForm
var listEmp = _LogicE.Read(null); var listEmp = _LogicE.Read(null);
var listSubd = _LogicS.Read(null); var listSubd = _LogicS.Read(null);
var Data = new Dictionary<string, List<double>>(); var data = new Dictionary<string, List<double>>();
foreach (var item in listSubd) 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 >= 10 && y.Experience < 20).Count(),
listSorted.Where(y => y.Experience >= 20 && y.Experience < 30).Count()); listSorted.Where(y => y.Experience >= 20 && y.Experience < 30).Count());
Data.Add(item.Name, new List<double> { x.Item1, x.Item2, x.Item3, x.Item4 }); data.Add(item.Name, new List<double> { 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) private void DirectoryToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var form = Program.Container.Resolve<Directory>(); var form = Program.Container.Resolve<Directory>();