From 91e2483fef2832e4d8cbf8462cb290b952618b26 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 02:20:39 +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=B9=20=D0=BF=D1=83=D0=BB,=20?= =?UTF-8?q?=D0=B1=D1=83=D0=B4=D1=83=20=D0=BF=D1=80=D0=BE=D0=B1=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EmployerForm/Directory.Designer.cs | 64 +++++ EmployerForm/Directory.cs | 135 +++++++++ EmployerForm/Directory.resx | 120 ++++++++ EmployerForm/EmployerForm.Designer.cs | 155 +++++++++++ EmployerForm/EmployerForm.cs | 85 ++++++ EmployerForm/EmployerForm.csproj | 25 ++ EmployerForm/EmployerForm.resx | 123 ++++++++ EmployerForm/FormMain.Designer.cs | 166 +++++++++++ EmployerForm/FormMain.cs | 262 ++++++++++++++++++ EmployerForm/FormMain.resx | 132 +++++++++ EmployerForm/Program.cs | 44 +++ EmployerForm/lab_3.sln | 43 +++ .../BusinessLogics/EmployeeLogic.cs | 50 ++++ .../BusinessLogics/SubdivisionLogic.cs | 50 ++++ .../EnterpriseBusinessLogic.csproj | 14 + .../BindingModels/EmployeeBindingModel.cs | 18 ++ .../BindingModels/SubdivisionBindingModel.cs | 14 + .../BusinessLogicContracts/IEmployeeLogic.cs | 17 ++ .../ISubvisionStorage.cs | 17 ++ .../EnterpriseContracts.csproj | 10 + .../StorageContracts/IEmployeeStorage.cs | 20 ++ .../StorageContracts/ISubdivisionStorage.cs | 20 ++ .../ViewModels/EmployeeViewModel.cs | 18 ++ .../ViewModels/SubdivisionViewModel.cs | 14 + .../EnterpriseDataBase.cs | 22 ++ .../EnterpriseDataBaseImplement.csproj | 24 ++ .../Implements/EmployeeStorage.cs | 114 ++++++++ .../Implements/SubdivisionStorage.cs | 95 +++++++ .../20241023131846_Init.Designer.cs | 74 +++++ .../Migrations/20241023131846_Init.cs | 53 ++++ .../EnterpriseDataBaseModelSnapshot.cs | 71 +++++ .../Models/Employee.cs | 59 ++++ .../Models/Subdivision.cs | 48 ++++ 33 files changed, 2176 insertions(+) create mode 100644 EmployerForm/Directory.Designer.cs create mode 100644 EmployerForm/Directory.cs create mode 100644 EmployerForm/Directory.resx create mode 100644 EmployerForm/EmployerForm.Designer.cs create mode 100644 EmployerForm/EmployerForm.cs create mode 100644 EmployerForm/EmployerForm.csproj create mode 100644 EmployerForm/EmployerForm.resx create mode 100644 EmployerForm/FormMain.Designer.cs create mode 100644 EmployerForm/FormMain.cs create mode 100644 EmployerForm/FormMain.resx create mode 100644 EmployerForm/Program.cs create mode 100644 EmployerForm/lab_3.sln create mode 100644 EnterpriseBusinessLogic/BusinessLogics/EmployeeLogic.cs create mode 100644 EnterpriseBusinessLogic/BusinessLogics/SubdivisionLogic.cs create mode 100644 EnterpriseBusinessLogic/EnterpriseBusinessLogic.csproj create mode 100644 EnterpriseContracts/BindingModels/EmployeeBindingModel.cs create mode 100644 EnterpriseContracts/BindingModels/SubdivisionBindingModel.cs create mode 100644 EnterpriseContracts/BusinessLogicContracts/IEmployeeLogic.cs create mode 100644 EnterpriseContracts/BusinessLogicContracts/ISubvisionStorage.cs create mode 100644 EnterpriseContracts/EnterpriseContracts.csproj create mode 100644 EnterpriseContracts/StorageContracts/IEmployeeStorage.cs create mode 100644 EnterpriseContracts/StorageContracts/ISubdivisionStorage.cs create mode 100644 EnterpriseContracts/ViewModels/EmployeeViewModel.cs create mode 100644 EnterpriseContracts/ViewModels/SubdivisionViewModel.cs create mode 100644 EnterpriseDataBaseImplement/EnterpriseDataBase.cs create mode 100644 EnterpriseDataBaseImplement/EnterpriseDataBaseImplement.csproj create mode 100644 EnterpriseDataBaseImplement/Implements/EmployeeStorage.cs create mode 100644 EnterpriseDataBaseImplement/Implements/SubdivisionStorage.cs create mode 100644 EnterpriseDataBaseImplement/Migrations/20241023131846_Init.Designer.cs create mode 100644 EnterpriseDataBaseImplement/Migrations/20241023131846_Init.cs create mode 100644 EnterpriseDataBaseImplement/Migrations/EnterpriseDataBaseModelSnapshot.cs create mode 100644 EnterpriseDataBaseImplement/Models/Employee.cs create mode 100644 EnterpriseDataBaseImplement/Models/Subdivision.cs diff --git a/EmployerForm/Directory.Designer.cs b/EmployerForm/Directory.Designer.cs new file mode 100644 index 0000000..83a4ae4 --- /dev/null +++ b/EmployerForm/Directory.Designer.cs @@ -0,0 +1,64 @@ +namespace EmployerForm +{ + partial class Directory + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(414, 367); + dataGridView.TabIndex = 0; + dataGridView.CellEndEdit += DataGridView_CellEndEdit; + dataGridView.KeyDown += DataGridView_KeyDown; + // + // Directory + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(414, 367); + Controls.Add(dataGridView); + Name = "Directory"; + Text = "Directory"; + Load += Directory_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/EmployerForm/Directory.cs b/EmployerForm/Directory.cs new file mode 100644 index 0000000..73f0438 --- /dev/null +++ b/EmployerForm/Directory.cs @@ -0,0 +1,135 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.BusinessLogicContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace EmployerForm +{ + public partial class Directory : Form + { + private readonly ISubdivisionLogic _logicS; + readonly BindingList list; + + public Directory(ISubdivisionLogic logicS) + { + InitializeComponent(); + _logicS = logicS; + dataGridView.AllowUserToDeleteRows = true; + list = []; + } + + private void LoadData() + { + try + { + var list1 = _logicS.Read(null); + list.Clear(); + foreach (var item in list1) + { + list.Add(new() + { + Id = item.Id, + Name = item.Name, + }); + } + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns[0].Visible = false; + dataGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void Directory_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void DataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) + { + var typeName = (string)dataGridView.CurrentRow.Cells[1].Value; + if (!string.IsNullOrEmpty(typeName)) + { + if (dataGridView.CurrentRow.Cells[0].Value != null) + { + _logicS.CreateOrUpdate(new() + { + Id = Convert.ToInt32(dataGridView.CurrentRow.Cells[0].Value), + Name = (string)dataGridView.CurrentRow.Cells[1].EditedFormattedValue + }); + } + else + { + _logicS.CreateOrUpdate(new() + { + Name = (string)dataGridView.CurrentRow.Cells[1].EditedFormattedValue + }); + } + } + else + { + MessageBox.Show("Empty name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + + private void DataGridView_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyData == Keys.M) + { + if (dataGridView.Rows.Count == 0) + { + list.Add(new()); + dataGridView.DataSource = new List(list); + dataGridView.CurrentCell = dataGridView.Rows[0].Cells[1]; + return; + } + if (dataGridView.Rows[^1].Cells[1].Value != null) + { + list.Add(new()); + dataGridView.DataSource = new List(list); + dataGridView.CurrentCell = dataGridView.Rows[^1].Cells[1]; + return; + } + } + if (e.KeyData == Keys.Delete) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Confirm deleting", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_logicS.Delete(new() + { + Id = id + })) + { + throw new Exception("Error on delete"); + } + dataGridView.Rows.RemoveAt(dataGridView.SelectedRows[0].Index); + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } + } +} diff --git a/EmployerForm/Directory.resx b/EmployerForm/Directory.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/EmployerForm/Directory.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/EmployerForm/EmployerForm.Designer.cs b/EmployerForm/EmployerForm.Designer.cs new file mode 100644 index 0000000..df434ff --- /dev/null +++ b/EmployerForm/EmployerForm.Designer.cs @@ -0,0 +1,155 @@ +namespace EmployerForm +{ + partial class EmployerForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelFio = new Label(); + textBoxFio = new TextBox(); + labelExp = new Label(); + customInputRangeNumber = new BelianinComponents.CustomInputRangeNumber(); + labelSubvision = new Label(); + labelPosts = new Label(); + sqlDataAdapter1 = new Microsoft.Data.SqlClient.SqlDataAdapter(); + textBoxPosts = new TextBox(); + buttonCreate = new Button(); + dropDownList = new KashinComponent.DropDownList(); + SuspendLayout(); + // + // labelFio + // + labelFio.AutoSize = true; + labelFio.Location = new Point(35, 39); + labelFio.Name = "labelFio"; + labelFio.Size = new Size(31, 20); + labelFio.TabIndex = 0; + labelFio.Text = "FIO"; + // + // textBoxFio + // + textBoxFio.Location = new Point(122, 36); + textBoxFio.Name = "textBoxFio"; + textBoxFio.Size = new Size(179, 27); + textBoxFio.TabIndex = 1; + // + // labelExp + // + labelExp.AutoSize = true; + labelExp.Location = new Point(35, 80); + labelExp.Name = "labelExp"; + labelExp.Size = new Size(81, 20); + labelExp.TabIndex = 2; + labelExp.Text = "Experience"; + // + // customInputRangeNumber + // + customInputRangeNumber.Location = new Point(122, 80); + customInputRangeNumber.MaxValue = null; + customInputRangeNumber.MinValue = null; + customInputRangeNumber.Name = "customInputRangeNumber"; + customInputRangeNumber.Size = new Size(161, 45); + customInputRangeNumber.TabIndex = 3; + // + // labelSubvision + // + labelSubvision.AutoSize = true; + labelSubvision.Location = new Point(35, 134); + labelSubvision.Name = "labelSubvision"; + labelSubvision.Size = new Size(72, 20); + labelSubvision.TabIndex = 4; + labelSubvision.Text = "Subvision"; + // + // labelPosts + // + labelPosts.AutoSize = true; + labelPosts.Location = new Point(35, 220); + labelPosts.Name = "labelPosts"; + labelPosts.Size = new Size(42, 20); + labelPosts.TabIndex = 5; + labelPosts.Text = "Posts"; + // + // textBoxPosts + // + textBoxPosts.Location = new Point(122, 217); + textBoxPosts.Name = "textBoxPosts"; + textBoxPosts.Size = new Size(179, 27); + textBoxPosts.TabIndex = 6; + // + // buttonCreate + // + buttonCreate.Location = new Point(113, 274); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(94, 29); + buttonCreate.TabIndex = 8; + buttonCreate.Text = "Create"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonCreate_Click; + // + // dropDownList + // + dropDownList.Location = new Point(120, 132); + dropDownList.Margin = new Padding(3, 4, 3, 4); + dropDownList.Name = "dropDownList"; + dropDownList.SelectedValue = ""; + dropDownList.Size = new Size(181, 49); + dropDownList.TabIndex = 9; + dropDownList.Load += EmployerForm_Load; + // + // EmployerForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(562, 312); + Controls.Add(dropDownList); + Controls.Add(buttonCreate); + Controls.Add(textBoxPosts); + Controls.Add(labelPosts); + Controls.Add(labelSubvision); + Controls.Add(customInputRangeNumber); + Controls.Add(labelExp); + Controls.Add(textBoxFio); + Controls.Add(labelFio); + Name = "EmployerForm"; + Text = "FormEmployer"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelFio; + private TextBox textBoxFio; + private Label labelExp; + private BelianinComponents.CustomInputRangeNumber customInputRangeNumber; + private Label labelSubvision; + private Label labelPosts; + private Microsoft.Data.SqlClient.SqlDataAdapter sqlDataAdapter1; + private TextBox textBoxPosts; + private Button buttonCreate; + private KashinComponent.DropDownList dropDownList; + } +} \ No newline at end of file diff --git a/EmployerForm/EmployerForm.cs b/EmployerForm/EmployerForm.cs new file mode 100644 index 0000000..a8eb627 --- /dev/null +++ b/EmployerForm/EmployerForm.cs @@ -0,0 +1,85 @@ +using BarsukovComponents.VisualComponents; +using BelianinComponents; +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.BusinessLogicContracts; +using EnterpriseContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace EmployerForm +{ + public partial class EmployerForm : Form + { + private readonly IEmployeeLogic _logic; + private readonly ISubdivisionLogic _logicS; + public int? Id { get; set; } + + public EmployerForm(IEmployeeLogic logic, ISubdivisionLogic logicS) + { + InitializeComponent(); + _logic = logic; + _logicS = logicS; + customInputRangeNumber.MinValue = 1; + customInputRangeNumber.MaxValue = 30; + customInputRangeNumber.Value = 1; + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + try + { + _logic.CreateOrUpdate(new EmployeeBindingModel + { + Id = Id, + Fio = textBoxFio.Text, + Subdivision = dropDownList.SelectedValue, + Posts = textBoxPosts.Text, + Experience = (int)customInputRangeNumber.Value + }); + MessageBox.Show("Succesfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void EmployerForm_Load(object sender, EventArgs e) + { + List? viewS = _logicS.Read(null); + + if (viewS != null) + { + dropDownList.Items.AddRange(viewS.Select(x => x.Name).ToArray()); + } + + if (Id.HasValue) + { + try + { + EmployeeViewModel? view = _logic.Read(new EmployeeBindingModel { Id = Id.Value })?[0]; + if (view != null) + { + textBoxFio.Text = view.Fio; + dropDownList.SelectedValue = view.Subdivision; + customInputRangeNumber.Value = view.Experience; + textBoxPosts.Text = view.Posts; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/EmployerForm/EmployerForm.csproj b/EmployerForm/EmployerForm.csproj new file mode 100644 index 0000000..03a7ae9 --- /dev/null +++ b/EmployerForm/EmployerForm.csproj @@ -0,0 +1,25 @@ + + + + WinExe + net8.0-windows7.0 + enable + true + enable + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/EmployerForm/EmployerForm.resx b/EmployerForm/EmployerForm.resx new file mode 100644 index 0000000..e790049 --- /dev/null +++ b/EmployerForm/EmployerForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/EmployerForm/FormMain.Designer.cs b/EmployerForm/FormMain.Designer.cs new file mode 100644 index 0000000..d4f220c --- /dev/null +++ b/EmployerForm/FormMain.Designer.cs @@ -0,0 +1,166 @@ +namespace EmployerForm +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + menuStrip = new MenuStrip(); + actionToolStripMenuItem = new ToolStripMenuItem(); + createEmployerCtrlAToolStripMenuItem = new ToolStripMenuItem(); + editEmployerCtrlUToolStripMenuItem = new ToolStripMenuItem(); + deleteEmployerCtrlDToolStripMenuItem = new ToolStripMenuItem(); + exelCtrlSToolStripMenuItem = new ToolStripMenuItem(); + wordCtrlTToolStripMenuItem = new ToolStripMenuItem(); + pdfCtrlCToolStripMenuItem = new ToolStripMenuItem(); + directoryToolStripMenuItem = new ToolStripMenuItem(); + excelTable = new KryukovLib.ExcelTable(components); + pdfDiagram = new BarsukovComponents.NotVisualComponents.PdfDiagram(components); + wordWithTable = new BelianinComponents.WordWithTable(components); + listBoxMany1 = new KashinComponent.ListBoxMany(); + menuStrip.SuspendLayout(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { actionToolStripMenuItem, directoryToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Padding = new Padding(5, 2, 0, 2); + menuStrip.Size = new Size(514, 24); + menuStrip.TabIndex = 1; + menuStrip.Text = "menuStrip1"; + // + // actionToolStripMenuItem + // + actionToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { createEmployerCtrlAToolStripMenuItem, editEmployerCtrlUToolStripMenuItem, deleteEmployerCtrlDToolStripMenuItem, exelCtrlSToolStripMenuItem, wordCtrlTToolStripMenuItem, pdfCtrlCToolStripMenuItem }); + actionToolStripMenuItem.Name = "actionToolStripMenuItem"; + actionToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.A; + actionToolStripMenuItem.Size = new Size(54, 20); + actionToolStripMenuItem.Text = "Action"; + // + // createEmployerCtrlAToolStripMenuItem + // + createEmployerCtrlAToolStripMenuItem.Name = "createEmployerCtrlAToolStripMenuItem"; + createEmployerCtrlAToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.A; + createEmployerCtrlAToolStripMenuItem.Size = new Size(203, 22); + createEmployerCtrlAToolStripMenuItem.Text = "Create Employer"; + createEmployerCtrlAToolStripMenuItem.Click += CreateEmployerToolStripMenuItem_Click; + // + // editEmployerCtrlUToolStripMenuItem + // + editEmployerCtrlUToolStripMenuItem.Name = "editEmployerCtrlUToolStripMenuItem"; + editEmployerCtrlUToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.U; + editEmployerCtrlUToolStripMenuItem.Size = new Size(203, 22); + editEmployerCtrlUToolStripMenuItem.Text = "Edit Employer"; + editEmployerCtrlUToolStripMenuItem.Click += EditEmployerToolStripMenuItem_Click_1; + // + // deleteEmployerCtrlDToolStripMenuItem + // + deleteEmployerCtrlDToolStripMenuItem.Name = "deleteEmployerCtrlDToolStripMenuItem"; + deleteEmployerCtrlDToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.D; + deleteEmployerCtrlDToolStripMenuItem.Size = new Size(203, 22); + deleteEmployerCtrlDToolStripMenuItem.Text = "Delete Employer"; + deleteEmployerCtrlDToolStripMenuItem.TextDirection = ToolStripTextDirection.Horizontal; + deleteEmployerCtrlDToolStripMenuItem.Click += DeleteEmployerToolStripMenuItem_Click_1; + // + // exelCtrlSToolStripMenuItem + // + exelCtrlSToolStripMenuItem.Name = "exelCtrlSToolStripMenuItem"; + exelCtrlSToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; + exelCtrlSToolStripMenuItem.Size = new Size(203, 22); + exelCtrlSToolStripMenuItem.Text = "Exel"; + exelCtrlSToolStripMenuItem.Click += ExcelToolStripMenuItem_Click; + // + // wordCtrlTToolStripMenuItem + // + wordCtrlTToolStripMenuItem.Name = "wordCtrlTToolStripMenuItem"; + wordCtrlTToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T; + wordCtrlTToolStripMenuItem.Size = new Size(203, 22); + wordCtrlTToolStripMenuItem.Text = "Word"; + wordCtrlTToolStripMenuItem.Click += WordToolStripMenuItem_Click; + // + // pdfCtrlCToolStripMenuItem + // + pdfCtrlCToolStripMenuItem.Name = "pdfCtrlCToolStripMenuItem"; + pdfCtrlCToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.C; + pdfCtrlCToolStripMenuItem.Size = new Size(203, 22); + pdfCtrlCToolStripMenuItem.Text = "Pdf"; + pdfCtrlCToolStripMenuItem.Click += PdfToolStripMenuItem_Click; + // + // directoryToolStripMenuItem + // + directoryToolStripMenuItem.Name = "directoryToolStripMenuItem"; + directoryToolStripMenuItem.Size = new Size(67, 20); + directoryToolStripMenuItem.Text = "Directory"; + directoryToolStripMenuItem.Click += DirectoryToolStripMenuItem_Click; + // + // listBoxMany1 + // + 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; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(514, 430); + Controls.Add(listBoxMany1); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Margin = new Padding(3, 2, 3, 2); + Name = "FormMain"; + Text = "Zavod"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private MenuStrip menuStrip; + private ToolStripMenuItem actionToolStripMenuItem; + private ToolStripMenuItem createEmployerCtrlAToolStripMenuItem; + private ToolStripMenuItem editEmployerCtrlUToolStripMenuItem; + private ToolStripMenuItem deleteEmployerCtrlDToolStripMenuItem; + private ToolStripMenuItem exelCtrlSToolStripMenuItem; + private ToolStripMenuItem wordCtrlTToolStripMenuItem; + private ToolStripMenuItem pdfCtrlCToolStripMenuItem; + private ToolStripMenuItem directoryToolStripMenuItem; + private KryukovLib.ExcelTable excelTable; + private BarsukovComponents.NotVisualComponents.PdfDiagram pdfDiagram; + private BelianinComponents.WordWithTable wordWithTable; + private KashinComponent.ListBoxMany listBoxMany1; + } +} diff --git a/EmployerForm/FormMain.cs b/EmployerForm/FormMain.cs new file mode 100644 index 0000000..166ec1b --- /dev/null +++ b/EmployerForm/FormMain.cs @@ -0,0 +1,262 @@ +using BelianinComponents.Models; +using BelianinComponents; +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.BusinessLogicContracts; +using EnterpriseContracts.ViewModels; +using KryukovLib; +using Unity; +using DocumentFormat.OpenXml.Bibliography; +using KashinComponent; + +namespace EmployerForm +{ + public partial class FormMain : Form + { + private readonly IEmployeeLogic _LogicE; + private readonly ISubdivisionLogic _LogicS; + public FormMain(IEmployeeLogic logicE, ISubdivisionLogic logicS) + { + InitializeComponent(); + _LogicE = logicE; + _LogicS = logicS; + } + + + private void DropComponents() + { + Controls.Clear(); + InitializeComponent(); + } + + private void LoadData() + { + try + { + DropComponents(); + listBoxMany1.SetLayout("{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); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void CreateEmployerToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = Program.Container.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void EditEmployerToolStripMenuItem_Click_1(object sender, EventArgs e) + { + var selectedEmployee = listBoxMany1.GetItemFromList(); + 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; + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void DeleteEmployerToolStripMenuItem_Click_1(object sender, EventArgs e) + { + var selectedEmployee = listBoxMany1.GetItemFromList(); + 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) + { + try + { + _LogicE.Delete(new EmployeeBindingModel { Id = selectedEmployee.Id }); + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ExcelToolStripMenuItem_Click(object sender, EventArgs e) + { + // _LogicE + if (_LogicE == null) + { + MessageBox.Show(" .", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + // excelTable + if (excelTable == null) + { + MessageBox.Show(" Excel .", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + // + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName; + MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + // + var ent = listBoxMany1.GetItemFromList(); + if (ent == null) + { + MessageBox.Show(" .", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + // + var EmplList = _LogicE.Read(new EmployeeBindingModel { Id = ent.Id }); + if (EmplList == null || EmplList.Count == 0) + { + MessageBox.Show(" .", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + var Empl = EmplList[0]; + + // + if (string.IsNullOrEmpty(Empl.Posts)) + { + MessageBox.Show(" .", "", 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++) + { + Data[0, i] = posts[i]; + } + + // Data TableConfig + var dataList = new List() { Data }; + + // + if (string.IsNullOrEmpty(fileName)) + { + MessageBox.Show(" .", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + // Excel + excelTable.CreateDoc(new KryukovLib.Models.TableConfig + { + FilePath = fileName, + Header = "Example", + Data = dataList // + }); + } + + + + + private void WordToolStripMenuItem_Click(object sender, EventArgs e) + { + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "docx|*.docx" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + var list = _LogicE.Read(null); + wordWithTable.CreateDoc(new WordWithTableDataConfig + { + FilePath = fileName, + Header = "Table:", + UseUnion = true, + ColumnsRowsWidth = [(0, 5), (0, 5), (0, 10), (0, 10)], + ColumnUnion = [(2, 2)], + Headers = + [ + (0, 0, "Id", "Id"), + (1, 0, "Fio", "Fio"), + (2, 0, "Work", ""), + (2, 1, "Subdivision", "Subdivision"), + (3, 1, "Experience", "Experience"), + ], + Data = list + }); + } + + private void PdfToolStripMenuItem_Click(object sender, EventArgs e) + { + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + var listEmp = _LogicE.Read(null); + var listSubd = _LogicS.Read(null); + + var Data = new Dictionary>(); + + foreach (var item in listSubd) + { + var listSorted = listEmp.Where(x => x.Subdivision.Equals(item.Name)); + + (int, int, int, int) x = ( + listSorted.Where(y => y.Experience >= 1 && y.Experience < 5).Count(), + listSorted.Where(y => y.Experience >= 5 && y.Experience < 10).Count(), + 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 }); + } + + pdfDiagram.CreateDiagram(fileName, "Chart", "Chart", Data); + } + + + private void DirectoryToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = Program.Container.Resolve(); + form.ShowDialog(); + } + } +} diff --git a/EmployerForm/FormMain.resx b/EmployerForm/FormMain.resx new file mode 100644 index 0000000..007ec9e --- /dev/null +++ b/EmployerForm/FormMain.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 145, 17 + + + 278, 17 + + + 415, 17 + + \ No newline at end of file diff --git a/EmployerForm/Program.cs b/EmployerForm/Program.cs new file mode 100644 index 0000000..b3d2b50 --- /dev/null +++ b/EmployerForm/Program.cs @@ -0,0 +1,44 @@ +using EnterpriseBusinessLogic.BusinessLogics; +using EnterpriseContracts.BusinessLogicContracts; +using EnterpriseContracts.StorageContracts; +using EnterpriseDataBaseImplement.Implements; +using Unity; +using Unity.Lifetime; + +namespace EmployerForm +{ + + internal static class Program + { + private static IUnityContainer container = null; + public static IUnityContainer Container { get { container ??= BuildUnityContainer; return container; } } + + [STAThread] + static void Main() + { + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(Container.Resolve()); + } + + private static IUnityContainer BuildUnityContainer + { + get + { + var currentContainer = new UnityContainer(); + + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + + currentContainer.RegisterType(); + currentContainer.RegisterType(); + + return currentContainer; + } + } + } +} \ No newline at end of file diff --git a/EmployerForm/lab_3.sln b/EmployerForm/lab_3.sln new file mode 100644 index 0000000..ea541e2 --- /dev/null +++ b/EmployerForm/lab_3.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34714.143 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmployerForm", "EmployerForm.csproj", "{6148AD91-F8F3-43B8-829E-21765EADD592}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EnterpriseBusinessLogic", "..\EnterpriseBusinessLogic\EnterpriseBusinessLogic.csproj", "{201B37CD-CC5D-460B-866A-F38AB01B6C86}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EnterpriseContracts", "..\EnterpriseContracts\EnterpriseContracts.csproj", "{1381046B-B45B-4704-8902-2E6F682795B1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EnterpriseDataBaseImplement", "..\EnterpriseDataBaseImplement\EnterpriseDataBaseImplement.csproj", "{FE99B750-6E9A-4BB8-B4D9-FEAD13D8EEAB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6148AD91-F8F3-43B8-829E-21765EADD592}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6148AD91-F8F3-43B8-829E-21765EADD592}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6148AD91-F8F3-43B8-829E-21765EADD592}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6148AD91-F8F3-43B8-829E-21765EADD592}.Release|Any CPU.Build.0 = Release|Any CPU + {201B37CD-CC5D-460B-866A-F38AB01B6C86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {201B37CD-CC5D-460B-866A-F38AB01B6C86}.Debug|Any CPU.Build.0 = Debug|Any CPU + {201B37CD-CC5D-460B-866A-F38AB01B6C86}.Release|Any CPU.ActiveCfg = Release|Any CPU + {201B37CD-CC5D-460B-866A-F38AB01B6C86}.Release|Any CPU.Build.0 = Release|Any CPU + {1381046B-B45B-4704-8902-2E6F682795B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1381046B-B45B-4704-8902-2E6F682795B1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1381046B-B45B-4704-8902-2E6F682795B1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1381046B-B45B-4704-8902-2E6F682795B1}.Release|Any CPU.Build.0 = Release|Any CPU + {FE99B750-6E9A-4BB8-B4D9-FEAD13D8EEAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FE99B750-6E9A-4BB8-B4D9-FEAD13D8EEAB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FE99B750-6E9A-4BB8-B4D9-FEAD13D8EEAB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FE99B750-6E9A-4BB8-B4D9-FEAD13D8EEAB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {AE51D606-3CA5-4880-86BE-23923BFEBF7C} + EndGlobalSection +EndGlobal diff --git a/EnterpriseBusinessLogic/BusinessLogics/EmployeeLogic.cs b/EnterpriseBusinessLogic/BusinessLogics/EmployeeLogic.cs new file mode 100644 index 0000000..5143684 --- /dev/null +++ b/EnterpriseBusinessLogic/BusinessLogics/EmployeeLogic.cs @@ -0,0 +1,50 @@ +using EnterpriseContracts.BusinessLogicContracts; +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.StorageContracts; +using EnterpriseContracts.ViewModels; +using System; +using System.Collections.Generic; + +namespace EnterpriseBusinessLogic.BusinessLogics +{ + + public class EmployeeLogic : IEmployeeLogic + { + private readonly IEmployeeStorage _empStorage; + + public EmployeeLogic(IEmployeeStorage empStorage) + { + _empStorage = empStorage ?? throw new ArgumentNullException(nameof(empStorage), "Хранилище сотрудников не инициализировано."); + } + + public List Read(EmployeeBindingModel? model) + { + if (model == null) + { + return _empStorage.GetFullList(); + } + + return model.Id.HasValue + ? new List { _empStorage.GetElement(model) ?? throw new Exception("Сотрудник не найден.") } + : _empStorage.GetFilteredList(model); + } + + public void CreateOrUpdate(EmployeeBindingModel model) + { + var element = _empStorage.GetElement(new EmployeeBindingModel + { + Id = model.Id + }); + if (element != null) + _empStorage.Update(model); + else + _empStorage.Insert(model); + } + + public void Delete(EmployeeBindingModel model) + { + _ = _empStorage.GetElement(new EmployeeBindingModel { Id = model.Id }) ?? throw new Exception("Id don't exist"); + _empStorage.Delete(model); + } + } +} diff --git a/EnterpriseBusinessLogic/BusinessLogics/SubdivisionLogic.cs b/EnterpriseBusinessLogic/BusinessLogics/SubdivisionLogic.cs new file mode 100644 index 0000000..1f599d9 --- /dev/null +++ b/EnterpriseBusinessLogic/BusinessLogics/SubdivisionLogic.cs @@ -0,0 +1,50 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.BusinessLogicContracts; +using EnterpriseContracts.StorageContracts; +using EnterpriseContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseBusinessLogic.BusinessLogics +{ + public class SubdivisionLogic(ISubdivisionStorage subdivisionStorage) : ISubdivisionLogic + { + private readonly ISubdivisionStorage _subdivisionStorage = subdivisionStorage; + + public List Read(SubdivisionBindingModel? model) + { + if (model == null) + return _subdivisionStorage.GetFullList(); + return model.Id != 0 ? + [_subdivisionStorage.GetElement(model)] : + _subdivisionStorage.GetFilteredList(model); + } + + 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); + } + + public bool Delete(SubdivisionBindingModel model) + { + var element = _subdivisionStorage.GetElement(new SubdivisionBindingModel { Id = model.Id }); + if (element == null) + return false; + _subdivisionStorage.Delete(model); + return true; + } + } +} diff --git a/EnterpriseBusinessLogic/EnterpriseBusinessLogic.csproj b/EnterpriseBusinessLogic/EnterpriseBusinessLogic.csproj new file mode 100644 index 0000000..a89cea6 --- /dev/null +++ b/EnterpriseBusinessLogic/EnterpriseBusinessLogic.csproj @@ -0,0 +1,14 @@ + + + + net8.0-windows7.0 + enable + true + enable + + + + + + + diff --git a/EnterpriseContracts/BindingModels/EmployeeBindingModel.cs b/EnterpriseContracts/BindingModels/EmployeeBindingModel.cs new file mode 100644 index 0000000..bb41750 --- /dev/null +++ b/EnterpriseContracts/BindingModels/EmployeeBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseContracts.BindingModels +{ + public class EmployeeBindingModel + { + public int? Id { get; set; } + public string Fio { get; set; } = string.Empty; + public int Experience { get; set; } + public string Subdivision { get; set; } = string.Empty; + public string Posts { get; set; } = string.Empty; + public (int, int)? ExperienceStep { get; set; } + } +} diff --git a/EnterpriseContracts/BindingModels/SubdivisionBindingModel.cs b/EnterpriseContracts/BindingModels/SubdivisionBindingModel.cs new file mode 100644 index 0000000..2fcd052 --- /dev/null +++ b/EnterpriseContracts/BindingModels/SubdivisionBindingModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseContracts.BindingModels +{ + public class SubdivisionBindingModel + { + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + } +} diff --git a/EnterpriseContracts/BusinessLogicContracts/IEmployeeLogic.cs b/EnterpriseContracts/BusinessLogicContracts/IEmployeeLogic.cs new file mode 100644 index 0000000..ebae265 --- /dev/null +++ b/EnterpriseContracts/BusinessLogicContracts/IEmployeeLogic.cs @@ -0,0 +1,17 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseContracts.BusinessLogicContracts +{ + public interface IEmployeeLogic + { + List Read(EmployeeBindingModel model); + void CreateOrUpdate(EmployeeBindingModel model); + void Delete(EmployeeBindingModel model); + } +} diff --git a/EnterpriseContracts/BusinessLogicContracts/ISubvisionStorage.cs b/EnterpriseContracts/BusinessLogicContracts/ISubvisionStorage.cs new file mode 100644 index 0000000..4de16e6 --- /dev/null +++ b/EnterpriseContracts/BusinessLogicContracts/ISubvisionStorage.cs @@ -0,0 +1,17 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseContracts.BusinessLogicContracts +{ + public interface ISubdivisionLogic + { + List Read(SubdivisionBindingModel model); + void CreateOrUpdate(SubdivisionBindingModel model); + bool Delete(SubdivisionBindingModel model); + } +} diff --git a/EnterpriseContracts/EnterpriseContracts.csproj b/EnterpriseContracts/EnterpriseContracts.csproj new file mode 100644 index 0000000..7f5e6ba --- /dev/null +++ b/EnterpriseContracts/EnterpriseContracts.csproj @@ -0,0 +1,10 @@ + + + + net8.0-windows7.0 + enable + true + enable + + + diff --git a/EnterpriseContracts/StorageContracts/IEmployeeStorage.cs b/EnterpriseContracts/StorageContracts/IEmployeeStorage.cs new file mode 100644 index 0000000..6cca883 --- /dev/null +++ b/EnterpriseContracts/StorageContracts/IEmployeeStorage.cs @@ -0,0 +1,20 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseContracts.StorageContracts +{ + public interface IEmployeeStorage + { + List GetFullList(); + List GetFilteredList(EmployeeBindingModel model); + EmployeeViewModel? GetElement(EmployeeBindingModel model); + void Insert(EmployeeBindingModel model); + void Update(EmployeeBindingModel model); + void Delete(EmployeeBindingModel model); + } +} diff --git a/EnterpriseContracts/StorageContracts/ISubdivisionStorage.cs b/EnterpriseContracts/StorageContracts/ISubdivisionStorage.cs new file mode 100644 index 0000000..102d5ad --- /dev/null +++ b/EnterpriseContracts/StorageContracts/ISubdivisionStorage.cs @@ -0,0 +1,20 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseContracts.StorageContracts +{ + public interface ISubdivisionStorage + { + List GetFullList(); + List GetFilteredList(SubdivisionBindingModel model); + SubdivisionViewModel? GetElement(SubdivisionBindingModel? model); + void Insert(SubdivisionBindingModel model); + void Update(SubdivisionBindingModel model); + void Delete(SubdivisionBindingModel model); + } +} diff --git a/EnterpriseContracts/ViewModels/EmployeeViewModel.cs b/EnterpriseContracts/ViewModels/EmployeeViewModel.cs new file mode 100644 index 0000000..5a9eca2 --- /dev/null +++ b/EnterpriseContracts/ViewModels/EmployeeViewModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseContracts.ViewModels +{ + public class EmployeeViewModel + { + public int Id { get; set; } + public string Fio { get; set; } = string.Empty; + public int Experience { get; set; } + public string Subdivision { get; set; } = string.Empty; + public string Posts { get; set; } = string.Empty; + + } +} diff --git a/EnterpriseContracts/ViewModels/SubdivisionViewModel.cs b/EnterpriseContracts/ViewModels/SubdivisionViewModel.cs new file mode 100644 index 0000000..c17ed1d --- /dev/null +++ b/EnterpriseContracts/ViewModels/SubdivisionViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseContracts.ViewModels +{ + public class SubdivisionViewModel + { + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + } +} diff --git a/EnterpriseDataBaseImplement/EnterpriseDataBase.cs b/EnterpriseDataBaseImplement/EnterpriseDataBase.cs new file mode 100644 index 0000000..be92d8d --- /dev/null +++ b/EnterpriseDataBaseImplement/EnterpriseDataBase.cs @@ -0,0 +1,22 @@ +using EnterpriseDataBaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; + +namespace EnterpriseDataBaseImplement +{ + public class EnterpriseDataBase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured) + { + optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=RabotyagiDatabase;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + + public virtual DbSet Employees { get; set; } + public virtual DbSet Subdivisions { get; set; } + } + +} diff --git a/EnterpriseDataBaseImplement/EnterpriseDataBaseImplement.csproj b/EnterpriseDataBaseImplement/EnterpriseDataBaseImplement.csproj new file mode 100644 index 0000000..9635703 --- /dev/null +++ b/EnterpriseDataBaseImplement/EnterpriseDataBaseImplement.csproj @@ -0,0 +1,24 @@ + + + + net8.0-windows7.0 + enable + true + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/EnterpriseDataBaseImplement/Implements/EmployeeStorage.cs b/EnterpriseDataBaseImplement/Implements/EmployeeStorage.cs new file mode 100644 index 0000000..5912622 --- /dev/null +++ b/EnterpriseDataBaseImplement/Implements/EmployeeStorage.cs @@ -0,0 +1,114 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.StorageContracts; +using EnterpriseContracts.ViewModels; +using EnterpriseDataBaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseDataBaseImplement.Implements +{ + public class EmployeeStorage : IEmployeeStorage + { + public List GetFullList() + { + using var context = new EnterpriseDataBase(); + return context.Employees + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(EmployeeBindingModel model) + { + using var context = new EnterpriseDataBase(); + if (!model.ExperienceStep.HasValue) return new List(); + + return context.Employees + .Where(x => model.ExperienceStep.Value.Item1 <= x.Experience && + model.ExperienceStep.Value.Item2 >= x.Experience) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public EmployeeViewModel? GetElement(EmployeeBindingModel model) + { + if (model == null || !model.Id.HasValue) + { + Console.WriteLine("Model is null or Id is not provided."); + return null; + } + + // Логируем Id, чтобы посмотреть, какое значение передается + Console.WriteLine($"Searching for employee with Id: {model.Id.Value}"); + + using var context = new EnterpriseDataBase(); + var x = context.Employees.FirstOrDefault(rec => rec.Id == model.Id); + + // Логируем результат поиска + if (x == null) + { + Console.WriteLine($"No employee found with Id: {model.Id.Value}"); + } + else + { + Console.WriteLine($"Employee found: {x.Fio}"); // Пример логирования имени найденного сотрудника + } + + return x?.GetViewModel; + } + + + public void Insert(EmployeeBindingModel model) + { + var context = new EnterpriseDataBase(); + var transaction = context.Database.BeginTransaction(); + try + { + var x = Employee.Create(model); + context.Employees.Add(x); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public void Update(EmployeeBindingModel model) + { + var context = new EnterpriseDataBase(); + var transaction = context.Database.BeginTransaction(); + try + { + var x = context.Employees.FirstOrDefault(rec => rec.Id == model.Id) ?? throw new Exception("Not found"); + x.Update(model); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public void Delete(EmployeeBindingModel model) + { + var context = new EnterpriseDataBase(); + var x = context.Employees.FirstOrDefault(rec => rec.Id == model.Id); + if (x != null) + { + context.Employees.Remove(x); + context.SaveChanges(); + } + else + throw new Exception("Id isn't exists"); + } + } +} diff --git a/EnterpriseDataBaseImplement/Implements/SubdivisionStorage.cs b/EnterpriseDataBaseImplement/Implements/SubdivisionStorage.cs new file mode 100644 index 0000000..b3dac39 --- /dev/null +++ b/EnterpriseDataBaseImplement/Implements/SubdivisionStorage.cs @@ -0,0 +1,95 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.StorageContracts; +using EnterpriseContracts.ViewModels; +using EnterpriseDataBaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseDataBaseImplement.Implements +{ + public class SubdivisionStorage : ISubdivisionStorage + { + public List GetFullList() + { + var context = new EnterpriseDataBase(); + return context.Subdivisions + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(SubdivisionBindingModel model) + { + var context = new EnterpriseDataBase(); + return context.Subdivisions + .Where(x => x.Name.Contains(model.Name)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public SubdivisionViewModel? GetElement(SubdivisionBindingModel? model) + { + if (model == null) return null; + using var context = new EnterpriseDataBase(); + var x = context.Subdivisions + .ToList() + .FirstOrDefault(rec => rec.Name == model.Name || rec.Id == model.Id); + return x?.GetViewModel; + } + + public void Insert(SubdivisionBindingModel model) + { + var context = new EnterpriseDataBase(); + var transaction = context.Database.BeginTransaction(); + try + { + var x = Subdivision.Create(model); + context.Subdivisions.Add(x); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public void Update(SubdivisionBindingModel model) + { + var context = new EnterpriseDataBase(); + var transaction = context.Database.BeginTransaction(); + try + { + var x = context.Subdivisions.FirstOrDefault(rec => rec.Id == model.Id); + if (x == null) + throw new Exception("Not found"); + x.Update(model); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public void Delete(SubdivisionBindingModel model) + { + var context = new EnterpriseDataBase(); + var x = context.Subdivisions.FirstOrDefault(rec => rec.Id == model.Id); + if (x != null) + { + context.Subdivisions.Remove(x); + context.SaveChanges(); + } + else + throw new Exception("Id isn't exists"); + } + } +} diff --git a/EnterpriseDataBaseImplement/Migrations/20241023131846_Init.Designer.cs b/EnterpriseDataBaseImplement/Migrations/20241023131846_Init.Designer.cs new file mode 100644 index 0000000..7ec8ab1 --- /dev/null +++ b/EnterpriseDataBaseImplement/Migrations/20241023131846_Init.Designer.cs @@ -0,0 +1,74 @@ +// +using EnterpriseDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EnterpriseDataBaseImplement.Migrations +{ + [DbContext(typeof(EnterpriseDataBase))] + [Migration("20241023131846_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.20") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("EnterpriseDataBaseImplement.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Experience") + .HasColumnType("int"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Posts") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subdivision") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("EnterpriseDataBaseImplement.Models.Subdivision", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Subdivisions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/EnterpriseDataBaseImplement/Migrations/20241023131846_Init.cs b/EnterpriseDataBaseImplement/Migrations/20241023131846_Init.cs new file mode 100644 index 0000000..91a45a2 --- /dev/null +++ b/EnterpriseDataBaseImplement/Migrations/20241023131846_Init.cs @@ -0,0 +1,53 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EnterpriseDataBaseImplement.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Employees", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Fio = table.Column(type: "nvarchar(max)", nullable: false), + Experience = table.Column(type: "int", nullable: false), + Posts = table.Column(type: "nvarchar(max)", nullable: false), + Subdivision = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Employees", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Subdivisions", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Subdivisions", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Employees"); + + migrationBuilder.DropTable( + name: "Subdivisions"); + } + } +} diff --git a/EnterpriseDataBaseImplement/Migrations/EnterpriseDataBaseModelSnapshot.cs b/EnterpriseDataBaseImplement/Migrations/EnterpriseDataBaseModelSnapshot.cs new file mode 100644 index 0000000..da805b9 --- /dev/null +++ b/EnterpriseDataBaseImplement/Migrations/EnterpriseDataBaseModelSnapshot.cs @@ -0,0 +1,71 @@ +// +using EnterpriseDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EnterpriseDataBaseImplement.Migrations +{ + [DbContext(typeof(EnterpriseDataBase))] + partial class EnterpriseDataBaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.20") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("EnterpriseDataBaseImplement.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Experience") + .HasColumnType("int"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Posts") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subdivision") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("EnterpriseDataBaseImplement.Models.Subdivision", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Subdivisions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/EnterpriseDataBaseImplement/Models/Employee.cs b/EnterpriseDataBaseImplement/Models/Employee.cs new file mode 100644 index 0000000..96a02e8 --- /dev/null +++ b/EnterpriseDataBaseImplement/Models/Employee.cs @@ -0,0 +1,59 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseDataBaseImplement.Models +{ + public class Employee + { + public int Id { get; set; } + public string Fio { get; set; } = string.Empty; + public int Experience { get; set; } + public string Posts { get; set; } = string.Empty; + public string Subdivision { get; set; } = string.Empty; + + public static Employee? Create(EmployeeBindingModel? model) + { + if (model == null) return null; + return new() + { + Fio = model.Fio, + Experience = model.Experience, + Posts = model.Posts, + Subdivision = model.Subdivision + }; + } + + public static Employee Create(EmployeeViewModel model) + { + return new Employee + { + Id = model.Id, + Fio = model.Fio, + Experience = model.Experience, + Posts = model.Posts, + Subdivision = model.Subdivision + }; + } + + public void Update(EmployeeBindingModel? model) + { + if (model == null) return; + Posts = model.Posts; + Subdivision = model.Subdivision; + } + + public EmployeeViewModel GetViewModel => new() + { + Id = Id, + Fio = Fio, + Experience = Experience, + Subdivision = Subdivision, + Posts = Posts, + }; + } +} diff --git a/EnterpriseDataBaseImplement/Models/Subdivision.cs b/EnterpriseDataBaseImplement/Models/Subdivision.cs new file mode 100644 index 0000000..44bbf46 --- /dev/null +++ b/EnterpriseDataBaseImplement/Models/Subdivision.cs @@ -0,0 +1,48 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseDataBaseImplement.Models +{ + public class Subdivision + { + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + + public static Subdivision? Create(SubdivisionBindingModel? model) + { + if (model == null) return null; + return new() + { + Id = model.Id, + Name = model.Name + }; + } + + public static Subdivision? Create(SubdivisionViewModel? model) + { + if (model == null) return null; + return new() + { + Id = model.Id, + Name = model.Name + }; + } + + public void Update(SubdivisionBindingModel? model) + { + if (model == null) return; + if (!string.IsNullOrEmpty(model.Name)) Name = model.Name; + } + + public SubdivisionViewModel GetViewModel => new() + { + Id = Id, + Name = Name + }; + } +}