From 84cfc659fd0f37afb80b1dfec0668d78b68581a9 Mon Sep 17 00:00:00 2001 From: "nikbel2004@outlook.com" Date: Wed, 23 Oct 2024 15:52:24 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lab 3/Belianin_3/Belianin_3.sln | 43 +++ .../DesktopWithMyVisualComponents.csproj | 31 +++ .../FormEmployee.Designer.cs | 188 +++++++++++++ .../FormEmployee.cs | 148 +++++++++++ .../FormEmployee.resx | 120 +++++++++ .../FormMain.Designer.cs | 182 +++++++++++++ .../DesktopWithMyVisualComponents/FormMain.cs | 248 ++++++++++++++++++ .../FormMain.resx | 132 ++++++++++ .../FormSkill.Designer.cs | 66 +++++ .../FormSkill.cs | 145 ++++++++++ .../FormSkill.resx | 120 +++++++++ .../DesktopWithMyVisualComponents/Program.cs | 50 ++++ .../BusinessLogics/EmployeeLogic.cs | 83 ++++++ .../BusinessLogics/SkillLogic.cs | 89 +++++++ .../EnterpriseBusinessLogic.csproj | 14 + .../BindingModels/EmployeeBindingModel.cs | 21 ++ .../BindingModels/SkillBindingModel.cs | 15 ++ .../BusinessLogicContracts/IEmployeeLogic.cs | 19 ++ .../BusinessLogicContracts/ISkillLogic.cs | 19 ++ .../EnterpriseContracts.csproj | 10 + .../StorageContracts/IEmployeeStorage.cs | 25 ++ .../StorageContracts/ISkillStorage.cs | 25 ++ .../ViewModels/EmployeeViewModel.cs | 25 ++ .../ViewModels/SkillViewModel.cs | 15 ++ .../EnterpriseDataBase.cs | 27 ++ .../EnterpriseDataBaseImplement.csproj | 28 ++ .../Implements/EmployeeStorage.cs | 135 ++++++++++ .../Implements/SkillStorage.cs | 133 ++++++++++ .../20241022142146_Initial.Designer.cs | 75 ++++++ .../Migrations/20241022142146_Initial.cs | 53 ++++ .../EnterpriseDataBaseModelSnapshot.cs | 72 +++++ .../Models/Employee.cs | 26 ++ .../Models/Skill.cs | 17 ++ 33 files changed, 2399 insertions(+) create mode 100644 Lab 3/Belianin_3/Belianin_3.sln create mode 100644 Lab 3/Belianin_3/DesktopWithMyVisualComponents/DesktopWithMyVisualComponents.csproj create mode 100644 Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormEmployee.Designer.cs create mode 100644 Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormEmployee.cs create mode 100644 Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormEmployee.resx create mode 100644 Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormMain.Designer.cs create mode 100644 Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormMain.cs create mode 100644 Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormMain.resx create mode 100644 Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormSkill.Designer.cs create mode 100644 Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormSkill.cs create mode 100644 Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormSkill.resx create mode 100644 Lab 3/Belianin_3/DesktopWithMyVisualComponents/Program.cs create mode 100644 Lab 3/Belianin_3/EnterpriseBusinessLogic/BusinessLogics/EmployeeLogic.cs create mode 100644 Lab 3/Belianin_3/EnterpriseBusinessLogic/BusinessLogics/SkillLogic.cs create mode 100644 Lab 3/Belianin_3/EnterpriseBusinessLogic/EnterpriseBusinessLogic.csproj create mode 100644 Lab 3/Belianin_3/EnterpriseContracts/BindingModels/EmployeeBindingModel.cs create mode 100644 Lab 3/Belianin_3/EnterpriseContracts/BindingModels/SkillBindingModel.cs create mode 100644 Lab 3/Belianin_3/EnterpriseContracts/BusinessLogicContracts/IEmployeeLogic.cs create mode 100644 Lab 3/Belianin_3/EnterpriseContracts/BusinessLogicContracts/ISkillLogic.cs create mode 100644 Lab 3/Belianin_3/EnterpriseContracts/EnterpriseContracts.csproj create mode 100644 Lab 3/Belianin_3/EnterpriseContracts/StorageContracts/IEmployeeStorage.cs create mode 100644 Lab 3/Belianin_3/EnterpriseContracts/StorageContracts/ISkillStorage.cs create mode 100644 Lab 3/Belianin_3/EnterpriseContracts/ViewModels/EmployeeViewModel.cs create mode 100644 Lab 3/Belianin_3/EnterpriseContracts/ViewModels/SkillViewModel.cs create mode 100644 Lab 3/Belianin_3/EnterpriseDataBaseImplement/EnterpriseDataBase.cs create mode 100644 Lab 3/Belianin_3/EnterpriseDataBaseImplement/EnterpriseDataBaseImplement.csproj create mode 100644 Lab 3/Belianin_3/EnterpriseDataBaseImplement/Implements/EmployeeStorage.cs create mode 100644 Lab 3/Belianin_3/EnterpriseDataBaseImplement/Implements/SkillStorage.cs create mode 100644 Lab 3/Belianin_3/EnterpriseDataBaseImplement/Migrations/20241022142146_Initial.Designer.cs create mode 100644 Lab 3/Belianin_3/EnterpriseDataBaseImplement/Migrations/20241022142146_Initial.cs create mode 100644 Lab 3/Belianin_3/EnterpriseDataBaseImplement/Migrations/EnterpriseDataBaseModelSnapshot.cs create mode 100644 Lab 3/Belianin_3/EnterpriseDataBaseImplement/Models/Employee.cs create mode 100644 Lab 3/Belianin_3/EnterpriseDataBaseImplement/Models/Skill.cs diff --git a/Lab 3/Belianin_3/Belianin_3.sln b/Lab 3/Belianin_3/Belianin_3.sln new file mode 100644 index 0000000..784963a --- /dev/null +++ b/Lab 3/Belianin_3/Belianin_3.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34728.123 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopWithMyVisualComponents", "DesktopWithMyVisualComponents\DesktopWithMyVisualComponents.csproj", "{D784BAED-C48F-46F2-A6A0-BBD6CE599A59}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EnterpriseContracts", "EnterpriseContracts\EnterpriseContracts.csproj", "{B07E9BAB-F7E0-4191-A9A5-FECA4127F6FF}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EnterpriseDataBaseImplement", "EnterpriseDataBaseImplement\EnterpriseDataBaseImplement.csproj", "{D4FEF8DA-7060-4BF5-BB44-E5676DAE83E9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EnterpriseBusinessLogic", "EnterpriseBusinessLogic\EnterpriseBusinessLogic.csproj", "{80D54561-34CE-4DE8-BF20-30A38B393D4B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D784BAED-C48F-46F2-A6A0-BBD6CE599A59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D784BAED-C48F-46F2-A6A0-BBD6CE599A59}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D784BAED-C48F-46F2-A6A0-BBD6CE599A59}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D784BAED-C48F-46F2-A6A0-BBD6CE599A59}.Release|Any CPU.Build.0 = Release|Any CPU + {B07E9BAB-F7E0-4191-A9A5-FECA4127F6FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B07E9BAB-F7E0-4191-A9A5-FECA4127F6FF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B07E9BAB-F7E0-4191-A9A5-FECA4127F6FF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B07E9BAB-F7E0-4191-A9A5-FECA4127F6FF}.Release|Any CPU.Build.0 = Release|Any CPU + {D4FEF8DA-7060-4BF5-BB44-E5676DAE83E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D4FEF8DA-7060-4BF5-BB44-E5676DAE83E9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D4FEF8DA-7060-4BF5-BB44-E5676DAE83E9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D4FEF8DA-7060-4BF5-BB44-E5676DAE83E9}.Release|Any CPU.Build.0 = Release|Any CPU + {80D54561-34CE-4DE8-BF20-30A38B393D4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {80D54561-34CE-4DE8-BF20-30A38B393D4B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {80D54561-34CE-4DE8-BF20-30A38B393D4B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {80D54561-34CE-4DE8-BF20-30A38B393D4B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {26502496-F9AE-4E02-986A-76FD9595E9AE} + EndGlobalSection +EndGlobal diff --git a/Lab 3/Belianin_3/DesktopWithMyVisualComponents/DesktopWithMyVisualComponents.csproj b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/DesktopWithMyVisualComponents.csproj new file mode 100644 index 0000000..f555424 --- /dev/null +++ b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/DesktopWithMyVisualComponents.csproj @@ -0,0 +1,31 @@ + + + + WinExe + net8.0-windows7.0 + enable + true + enable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormEmployee.Designer.cs b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormEmployee.Designer.cs new file mode 100644 index 0000000..a2e46aa --- /dev/null +++ b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormEmployee.Designer.cs @@ -0,0 +1,188 @@ +namespace DesktopWithMyVisualComponents +{ + partial class FormEmployee + { + /// + /// 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(); + labelPhoneNumber = new Label(); + barsukovTextBoxPhoneNumber = new BarsukovComponents.VisualComponents.CustomTextBox(); + labelSkill = new Label(); + customSelectedCheckedListBoxProperty = new BelianinComponents.CustomSelectedCheckedListBoxProperty(); + buttonPhoto = new Button(); + buttonSave = new Button(); + buttonCancelAdd = new Button(); + pictureBoxPhoto = new PictureBox(); + ((System.ComponentModel.ISupportInitialize)pictureBoxPhoto).BeginInit(); + SuspendLayout(); + // + // labelFIO + // + labelFIO.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + labelFIO.AutoSize = true; + labelFIO.Location = new Point(30, 10); + labelFIO.Name = "labelFIO"; + labelFIO.Size = new Size(45, 20); + labelFIO.TabIndex = 0; + labelFIO.Text = "ФИО:"; + // + // textBoxFIO + // + textBoxFIO.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + textBoxFIO.Location = new Point(35, 34); + textBoxFIO.Margin = new Padding(3, 4, 3, 4); + textBoxFIO.Name = "textBoxFIO"; + textBoxFIO.Size = new Size(493, 27); + textBoxFIO.TabIndex = 1; + // + // labelPhoneNumber + // + labelPhoneNumber.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + labelPhoneNumber.AutoSize = true; + labelPhoneNumber.Location = new Point(242, 98); + labelPhoneNumber.Name = "labelPhoneNumber"; + labelPhoneNumber.Size = new Size(130, 20); + labelPhoneNumber.TabIndex = 2; + labelPhoneNumber.Text = "Номер телефона:"; + // + // barsukovTextBoxPhoneNumber + // + barsukovTextBoxPhoneNumber.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + barsukovTextBoxPhoneNumber.BorderStyle = BorderStyle.FixedSingle; + barsukovTextBoxPhoneNumber.Location = new Point(242, 122); + barsukovTextBoxPhoneNumber.Margin = new Padding(3, 4, 3, 4); + barsukovTextBoxPhoneNumber.Name = "barsukovTextBoxPhoneNumber"; + barsukovTextBoxPhoneNumber.numberPattern = ""; + barsukovTextBoxPhoneNumber.Size = new Size(275, 81); + barsukovTextBoxPhoneNumber.TabIndex = 3; + barsukovTextBoxPhoneNumber.textBoxNumber = ""; + barsukovTextBoxPhoneNumber.Enter += barsukovTextBoxPhoneNumber_Enter; + // + // labelSkill + // + labelSkill.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + labelSkill.AutoSize = true; + labelSkill.Location = new Point(35, 65); + labelSkill.Name = "labelSkill"; + labelSkill.Size = new Size(57, 20); + labelSkill.TabIndex = 4; + labelSkill.Text = "Навык:"; + // + // customSelectedCheckedListBoxProperty + // + customSelectedCheckedListBoxProperty.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + customSelectedCheckedListBoxProperty.Location = new Point(34, 84); + customSelectedCheckedListBoxProperty.Margin = new Padding(3, 4, 3, 4); + customSelectedCheckedListBoxProperty.Name = "customSelectedCheckedListBoxProperty"; + customSelectedCheckedListBoxProperty.SelectedElement = ""; + customSelectedCheckedListBoxProperty.Size = new Size(202, 207); + customSelectedCheckedListBoxProperty.TabIndex = 5; + // + // buttonPhoto + // + buttonPhoto.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + buttonPhoto.Location = new Point(35, 615); + buttonPhoto.Margin = new Padding(3, 4, 3, 4); + buttonPhoto.Name = "buttonPhoto"; + buttonPhoto.Size = new Size(494, 48); + buttonPhoto.TabIndex = 6; + buttonPhoto.Text = "Загрузить фото"; + buttonPhoto.UseVisualStyleBackColor = true; + buttonPhoto.Click += buttonPhoto_Click; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSave.Location = new Point(309, 671); + buttonSave.Margin = new Padding(3, 4, 3, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 41); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancelAdd + // + buttonCancelAdd.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancelAdd.Location = new Point(427, 671); + buttonCancelAdd.Margin = new Padding(3, 4, 3, 4); + buttonCancelAdd.Name = "buttonCancelAdd"; + buttonCancelAdd.Size = new Size(102, 41); + buttonCancelAdd.TabIndex = 8; + buttonCancelAdd.Text = "Отмена"; + buttonCancelAdd.UseVisualStyleBackColor = true; + buttonCancelAdd.Click += buttonCancelAdd_Click; + // + // pictureBoxPhoto + // + pictureBoxPhoto.Location = new Point(35, 281); + pictureBoxPhoto.Margin = new Padding(3, 4, 3, 4); + pictureBoxPhoto.Name = "pictureBoxPhoto"; + pictureBoxPhoto.Size = new Size(493, 327); + pictureBoxPhoto.TabIndex = 9; + pictureBoxPhoto.TabStop = false; + // + // FormEmployee + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(559, 717); + Controls.Add(pictureBoxPhoto); + Controls.Add(buttonCancelAdd); + Controls.Add(buttonSave); + Controls.Add(buttonPhoto); + Controls.Add(customSelectedCheckedListBoxProperty); + Controls.Add(labelSkill); + Controls.Add(barsukovTextBoxPhoneNumber); + Controls.Add(labelPhoneNumber); + Controls.Add(textBoxFIO); + Controls.Add(labelFIO); + Margin = new Padding(3, 4, 3, 4); + Name = "FormEmployee"; + Text = "Сотрудник"; + Load += FormEmployee_Load; + ((System.ComponentModel.ISupportInitialize)pictureBoxPhoto).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelFIO; + private TextBox textBoxFIO; + private Label labelPhoneNumber; + private BarsukovComponents.VisualComponents.CustomTextBox barsukovTextBoxPhoneNumber; + private Label labelSkill; + private BelianinComponents.CustomSelectedCheckedListBoxProperty customSelectedCheckedListBoxProperty; + private Button buttonPhoto; + private Button buttonSave; + private Button buttonCancelAdd; + private PictureBox pictureBoxPhoto; + } +} \ No newline at end of file diff --git a/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormEmployee.cs b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormEmployee.cs new file mode 100644 index 0000000..742f3e2 --- /dev/null +++ b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormEmployee.cs @@ -0,0 +1,148 @@ +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 DesktopWithMyVisualComponents +{ + public partial class FormEmployee : Form + { + public int Id { set { id = value; } } + + private readonly IEmployeeLogic _logic; + + private readonly ISkillLogic _logicS; + + private string image = null; + + private int? id; + + public FormEmployee(IEmployeeLogic logic, ISkillLogic logicS) + { + InitializeComponent(); + _logic = logic; + _logicS = logicS; + } + + private void barsukovTextBoxPhoneNumber_Enter(object sender, EventArgs e) + { + ToolTip tt = new ToolTip(); + + // Формат записи телефона + tt.Show("X-XXX-XX-XX", barsukovTextBoxPhoneNumber, 30, -20, 1000); + } + + private void FormEmployee_Load(object sender, EventArgs e) + { + barsukovTextBoxPhoneNumber.numberPattern = @"^\d{1}-\d{3}-\d{2}-\d{2}$"; + List viewS = _logicS.Read(null); + + if (viewS != null) + { + foreach (SkillViewModel skill in viewS) + { + customSelectedCheckedListBoxProperty.Items.Add(skill.Name); + } + } + + if (id.HasValue) + { + try + { + EmployeeViewModel view = _logic.Read(new EmployeeBindingModel { Id = id.Value })?[0]; + + if (view != null) + { + textBoxFIO.Text = view.FIO; + barsukovTextBoxPhoneNumber.textBoxNumber = view.PhoneNumber; + customSelectedCheckedListBoxProperty.SelectedElement = view.Skill; + + pictureBoxPhoto.Image = StringToImage(view.Photo); + image = view.Photo; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private Image StringToImage(string bytes) + { + byte[] arrayimg = Convert.FromBase64String(bytes); + Image imageStr = Image.FromStream(new MemoryStream(arrayimg)); + + return imageStr; + } + + private string ImageToString(Image image) + { + using (var ms = new MemoryStream()) + { + image.Save(ms, image.RawFormat); + byte[] imageBytes = ms.ToArray(); + + // Convert byte[] to Base64 String + string base64String = Convert.ToBase64String(imageBytes); + return base64String; + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + List viewS = _logicS.Read(null); + + try + { + _logic.CreateOrUpdate(new EmployeeBindingModel + { + Id = id, + FIO = textBoxFIO.Text, + Photo = image, + Skill = customSelectedCheckedListBoxProperty.SelectedElement, + PhoneNumber = barsukovTextBoxPhoneNumber.textBoxNumber, + }); + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancelAdd_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void buttonPhoto_Click(object sender, EventArgs e) + { + var dialog = new OpenFileDialog(); + + dialog.Title = "Выберите изображение"; + dialog.Filter = "jpg files (*.jpg)|*.jpg"; + + if (dialog.ShowDialog() == DialogResult.OK) + { + var image_new = new Bitmap(dialog.FileName); + pictureBoxPhoto.Image = image_new; + image = ImageToString(image_new); + } + + dialog.Dispose(); + } + } +} diff --git a/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormEmployee.resx b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormEmployee.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormEmployee.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/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormMain.Designer.cs b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormMain.Designer.cs new file mode 100644 index 0000000..7605249 --- /dev/null +++ b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormMain.Designer.cs @@ -0,0 +1,182 @@ +namespace DesktopWithMyVisualComponents +{ + 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(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + навыкиToolStripMenuItem = new ToolStripMenuItem(); + действияToolStripMenuItem = new ToolStripMenuItem(); + добавитьToolStripMenuItem = new ToolStripMenuItem(); + изменитьToolStripMenuItem = new ToolStripMenuItem(); + удалитьToolStripMenuItem = new ToolStripMenuItem(); + документыToolStripMenuItem = new ToolStripMenuItem(); + wordСФотоToolStripMenuItem = new ToolStripMenuItem(); + pdfТаблицаToolStripMenuItem = new ToolStripMenuItem(); + excelГистограммаToolStripMenuItem = new ToolStripMenuItem(); + wordWithImages = new BelianinComponents.WordWithImages(components); + componentTableToPdf = new BarsukovComponents.NotVisualComponents.PdfTable(components); + krykovItemTable = new KryukovLib.CustomDataGridView(); + excelGistogram = new KryukovLib.ExcelGistogram(components); + menuStrip.SuspendLayout(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, действияToolStripMenuItem, документыToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Padding = new Padding(7, 3, 0, 3); + menuStrip.Size = new Size(661, 30); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { навыкиToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // навыкиToolStripMenuItem + // + навыкиToolStripMenuItem.Name = "навыкиToolStripMenuItem"; + навыкиToolStripMenuItem.Size = new Size(146, 26); + навыкиToolStripMenuItem.Text = "Навыки"; + навыкиToolStripMenuItem.Click += навыкиToolStripMenuItem_Click; + // + // действияToolStripMenuItem + // + действияToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { добавитьToolStripMenuItem, изменитьToolStripMenuItem, удалитьToolStripMenuItem }); + действияToolStripMenuItem.Name = "действияToolStripMenuItem"; + действияToolStripMenuItem.Size = new Size(88, 24); + действияToolStripMenuItem.Text = "Действия"; + // + // добавитьToolStripMenuItem + // + добавитьToolStripMenuItem.Name = "добавитьToolStripMenuItem"; + добавитьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.A; + добавитьToolStripMenuItem.Size = new Size(213, 26); + добавитьToolStripMenuItem.Text = "Добавить"; + добавитьToolStripMenuItem.Click += добавитьToolStripMenuItem_Click; + // + // изменитьToolStripMenuItem + // + изменитьToolStripMenuItem.Name = "изменитьToolStripMenuItem"; + изменитьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.U; + изменитьToolStripMenuItem.Size = new Size(213, 26); + изменитьToolStripMenuItem.Text = "Изменить"; + изменитьToolStripMenuItem.Click += изменитьToolStripMenuItem_Click; + // + // удалитьToolStripMenuItem + // + удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem"; + удалитьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.D; + удалитьToolStripMenuItem.Size = new Size(213, 26); + удалитьToolStripMenuItem.Text = "Удалить"; + удалитьToolStripMenuItem.Click += удалитьToolStripMenuItem_Click; + // + // документыToolStripMenuItem + // + документыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { wordСФотоToolStripMenuItem, pdfТаблицаToolStripMenuItem, excelГистограммаToolStripMenuItem }); + документыToolStripMenuItem.Name = "документыToolStripMenuItem"; + документыToolStripMenuItem.Size = new Size(101, 24); + документыToolStripMenuItem.Text = "Документы"; + // + // wordСФотоToolStripMenuItem + // + wordСФотоToolStripMenuItem.Name = "wordСФотоToolStripMenuItem"; + wordСФотоToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; + wordСФотоToolStripMenuItem.Size = new Size(271, 26); + wordСФотоToolStripMenuItem.Text = "Word с фото"; + wordСФотоToolStripMenuItem.Click += wordСФотоToolStripMenuItem_Click; + // + // pdfТаблицаToolStripMenuItem + // + pdfТаблицаToolStripMenuItem.Name = "pdfТаблицаToolStripMenuItem"; + pdfТаблицаToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T; + pdfТаблицаToolStripMenuItem.Size = new Size(271, 26); + pdfТаблицаToolStripMenuItem.Text = "Pdf таблица"; + pdfТаблицаToolStripMenuItem.Click += pdfТаблицаToolStripMenuItem_Click; + // + // excelГистограммаToolStripMenuItem + // + excelГистограммаToolStripMenuItem.Name = "excelГистограммаToolStripMenuItem"; + excelГистограммаToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.C; + excelГистограммаToolStripMenuItem.Size = new Size(271, 26); + excelГистограммаToolStripMenuItem.Text = "Excel гистограмма"; + excelГистограммаToolStripMenuItem.Click += excelГистограммаToolStripMenuItem_Click; + // + // krykovItemTable + // + krykovItemTable.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + krykovItemTable.Location = new Point(14, 36); + krykovItemTable.Margin = new Padding(3, 5, 3, 5); + krykovItemTable.Name = "krykovItemTable"; + krykovItemTable.Size = new Size(630, 477); + krykovItemTable.TabIndex = 2; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(661, 529); + Controls.Add(krykovItemTable); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Margin = new Padding(3, 4, 3, 4); + Name = "FormMain"; + Text = "Главная"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem навыкиToolStripMenuItem; + private ToolStripMenuItem действияToolStripMenuItem; + private ToolStripMenuItem добавитьToolStripMenuItem; + private ToolStripMenuItem изменитьToolStripMenuItem; + private ToolStripMenuItem удалитьToolStripMenuItem; + private ToolStripMenuItem документыToolStripMenuItem; + private ToolStripMenuItem wordСФотоToolStripMenuItem; + private ToolStripMenuItem pdfТаблицаToolStripMenuItem; + private ToolStripMenuItem excelГистограммаToolStripMenuItem; + private BelianinComponents.WordWithImages wordWithImages; + private BarsukovComponents.NotVisualComponents.PdfTable componentTableToPdf; + private KryukovLib.CustomDataGridView krykovItemTable; + private KryukovLib.ExcelGistogram excelGistogram; + } +} \ No newline at end of file diff --git a/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormMain.cs b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormMain.cs new file mode 100644 index 0000000..01bd850 --- /dev/null +++ b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormMain.cs @@ -0,0 +1,248 @@ +using BelianinComponents; +using BelianinComponents.Models; +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; +using EnterpriseContracts.ViewModels; +using EnterpriseDataBaseImplement.Models; +using Unity; +using BarsukovComponents.NotVisualComponents.Configs; + +namespace DesktopWithMyVisualComponents +{ + public partial class FormMain : Form + { + private readonly IEmployeeLogic _employeeLogic; + + private readonly ISkillLogic _skillLogic; + + // Конструктор + public FormMain(IEmployeeLogic employeeLogic, ISkillLogic skillLogic) + { + InitializeComponent(); + _employeeLogic = employeeLogic; + + krykovItemTable.ConfigColumn(new() + { + ColumnsCount = 4, + NameColumn = new string[] { "Id", "ФИО", "Навык", "Номер телефона" }, + Width = new int[] { 10, 150, 250, 200 }, + Visible = new bool[] { false, true, true, true }, + PropertiesObject = new string[] { "Id", "FIO", "Skill", "PhoneNumber" } + }); + + _skillLogic = skillLogic; + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + krykovItemTable.ClearDataGrid(); + // Поиск записей в бд + var list = _employeeLogic.Read(null); + + if (list != null) + { + for (int j = 0; j < list.Count; j++) + { + krykovItemTable.AddItem(list[j], j); + krykovItemTable.Update(); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void добавитьToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = Program.Container.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void изменитьToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = Program.Container.Resolve(); + + form.Id = Convert.ToInt32(krykovItemTable.GetSelectedObjectInRow().Id); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void удалитьToolStripMenuItem_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(krykovItemTable.GetSelectedObjectInRow().Id); + + try + { + _employeeLogic.Delete(new EmployeeBindingModel { Id = id }); + krykovItemTable.ClearDataGrid(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + LoadData(); + } + } + + private void навыкиToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = Program.Container.Resolve(); + + form.ShowDialog(); + } + + private byte[] StringToImage(string bytes) + { + byte[] arrayimg = Convert.FromBase64String(bytes); + + return arrayimg; + } + + private void wordСФотоToolStripMenuItem_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("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + var list = _employeeLogic.Read(null); + + var list_images = new List(); + + foreach (var item in list) + { + var img = StringToImage(item.Photo); + list_images.Add(img); + } + + wordWithImages.CreateDoc(new WordWithImageConfig + { + FilePath = fileName, + Header = "Фотографии:", + Images = list_images + }); + } + + private void pdfТаблицаToolStripMenuItem_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("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + // Вызов метода CreateTable + componentTableToPdf.CreateDoc(new ComponentTableToPdfConfig + { + // Путь к файлу + FilePath = fileName, + // Заголовок таблицы + Header = "Таблица с сотрудниками", + UseUnion = true, + // Информация о колонках + ColumnsRowsWidth = new List<(int, int)> { (20, 0), (20, 0), (20, 0), (20, 0) }, + // Объединённые ячейки + ColumnUnion = new List<(int StartIndex, int Count)> { (2, 2) }, + + Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>() + { + (0, 0, "Идент.", "Id"), + (1, 0, "ФИО", "FIO"), + (2, 0, "Работа", ""), + (2, 1, "Номер телефона", "PhoneNumber"), + (3, 1, "Навык", "Skill") + }, + + // Данные для таблицы + Data = _employeeLogic.Read(null) + }); + } + + private void excelГистограммаToolStripMenuItem_Click(object sender, EventArgs e) + { + string fileName = ""; + + using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + } + + var list2D = new List<(string Date, double Value)>(); + + var emps = _employeeLogic.Read(null); + var skills = _skillLogic.Read(null); + + foreach (var skill in skills) + { + double count = 0; + + foreach (var emp in emps) + { + if (skill.Name.Equals(emp.Skill)) + { + count++; + } + } + + var elem = (skill.Name, count); + list2D.Add(elem); + } + + excelGistogram.CreateDoc(new() + { + FilePath = fileName, + Header = "Chart", + ChartTitle = "BarChart", + LegendLocation = KryukovLib.Models.Location.Top, + Data = new Dictionary> + { + { "Series 1", list2D } + } + }); + } + } +} diff --git a/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormMain.resx b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormMain.resx new file mode 100644 index 0000000..5b46608 --- /dev/null +++ b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/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 + + + 508, 17 + + + 145, 17 + + + 349, 17 + + \ No newline at end of file diff --git a/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormSkill.Designer.cs b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormSkill.Designer.cs new file mode 100644 index 0000000..84fa9c0 --- /dev/null +++ b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormSkill.Designer.cs @@ -0,0 +1,66 @@ +namespace DesktopWithMyVisualComponents +{ + partial class FormSkill + { + /// + /// 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() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(247, 150); + this.dataGridView.TabIndex = 0; + this.dataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellEndEdit); + this.dataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dataGridView_KeyDown); + // + // FormSkill + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(271, 180); + this.Controls.Add(this.dataGridView); + this.Name = "FormSkill"; + this.Text = "Навыки"; + this.Load += new System.EventHandler(this.FormSkill_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormSkill.cs b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormSkill.cs new file mode 100644 index 0000000..caa847c --- /dev/null +++ b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormSkill.cs @@ -0,0 +1,145 @@ +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 DesktopWithMyVisualComponents +{ + public partial class FormSkill : Form + { + private readonly ISkillLogic _skillLogic; + + BindingList list; + + public FormSkill(ISkillLogic skillLogic) + { + InitializeComponent(); + + _skillLogic = skillLogic; + dataGridView.AllowUserToDeleteRows = true; + list = new BindingList(); + } + + private void LoadData() + { + try + { + var list1 = _skillLogic.Read(null); + list.Clear(); + + foreach (var item in list1) + { + list.Add(new SkillBindingModel + { + 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, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FormSkill_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) + { + _skillLogic.CreateOrUpdate(new SkillBindingModel() + { + Id = Convert.ToInt32(dataGridView.CurrentRow.Cells[0].Value), + Name = (string)dataGridView.CurrentRow.Cells[1].EditedFormattedValue + }); + } + else + { + _skillLogic.CreateOrUpdate(new SkillBindingModel() + { + Name = (string)dataGridView.CurrentRow.Cells[1].EditedFormattedValue + }); + } + } + else + { + MessageBox.Show("Введена пустая строка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + LoadData(); + } + + private void dataGridView_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyData == Keys.Insert) + { + if (dataGridView.Rows.Count == 0) + { + list.Add(new SkillBindingModel()); + dataGridView.DataSource = new List(list); + dataGridView.CurrentCell = dataGridView.Rows[0].Cells[1]; + + return; + } + + if (dataGridView.Rows[dataGridView.Rows.Count - 1].Cells[1].Value != null) + { + list.Add(new SkillBindingModel()); + dataGridView.DataSource = new List(list); + dataGridView.CurrentCell = dataGridView.Rows[dataGridView.Rows.Count - 1].Cells[1]; + + return; + } + } + + if (e.KeyData == Keys.Delete) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + + try + { + if (!_skillLogic.Delete(new SkillBindingModel() { Id = id })) + { + throw new Exception("Ошибка при удалении"); + } + + dataGridView.Rows.RemoveAt(dataGridView.SelectedRows[0].Index); + + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } + } +} diff --git a/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormSkill.resx b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormSkill.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/FormSkill.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/Lab 3/Belianin_3/DesktopWithMyVisualComponents/Program.cs b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/Program.cs new file mode 100644 index 0000000..6e07304 --- /dev/null +++ b/Lab 3/Belianin_3/DesktopWithMyVisualComponents/Program.cs @@ -0,0 +1,50 @@ +using EnterpriseBusinessLogic.BusinessLogics; +using EnterpriseContracts.BusinessLogicContracts; +using EnterpriseContracts.StorageContracts; +using EnterpriseDataBaseImplement.Implements; +using Unity; +using Unity.Lifetime; + +namespace DesktopWithMyVisualComponents +{ + internal static class Program + { + private static IUnityContainer container = null; + + public static IUnityContainer Container + { + get + { + if (container == null) + { + container = BuildUnityContainer(); + } + return container; + } + } + + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(Container.Resolve()); + } + private static IUnityContainer BuildUnityContainer() + { + var currentContainer = new UnityContainer(); + + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + + return currentContainer; + } + } +} \ No newline at end of file diff --git a/Lab 3/Belianin_3/EnterpriseBusinessLogic/BusinessLogics/EmployeeLogic.cs b/Lab 3/Belianin_3/EnterpriseBusinessLogic/BusinessLogics/EmployeeLogic.cs new file mode 100644 index 0000000..c582c97 --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseBusinessLogic/BusinessLogics/EmployeeLogic.cs @@ -0,0 +1,83 @@ +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 EmployeeLogic : IEmployeeLogic + { + private readonly IEmployeeStorage _employeeStorage; + + public EmployeeLogic(IEmployeeStorage employeeStorage) + { + _employeeStorage = employeeStorage; + } + + // Создание и обновление записи о работнике + public void CreateOrUpdate(EmployeeBindingModel model) + { + var element = _employeeStorage.GetElement(new EmployeeBindingModel + { + FIO = model.FIO + }); + + if (element != null && element.Id != model.Id) + { + throw new Exception("Сотрудник с таким именем уже существует"); + } + + // Если уже создан, то обновляем, иначе создаём + if (model.Id.HasValue) + { + _employeeStorage.Update(model); + } + else + { + _employeeStorage.Insert(model); + } + } + + // Удаление записи о работнике + public void Delete(EmployeeBindingModel model) + { + var element = _employeeStorage.GetElement(new EmployeeBindingModel + { + Id = model.Id + }); + + if (element == null) + { + throw new Exception("Сотрудник не найден"); + } + + _employeeStorage.Delete(model); + } + + // Чтение записей о работнике + public List Read(EmployeeBindingModel model) + { + // Если неконкретная запись, то выводим все + if (model == null) + { + return _employeeStorage.GetFullList(); + } + + // Если конкретная запись о навыке + if (model.Id.HasValue) + { + return new List + { + _employeeStorage.GetElement(model) + }; + } + + return _employeeStorage.GetFullList(); + } + } +} diff --git a/Lab 3/Belianin_3/EnterpriseBusinessLogic/BusinessLogics/SkillLogic.cs b/Lab 3/Belianin_3/EnterpriseBusinessLogic/BusinessLogics/SkillLogic.cs new file mode 100644 index 0000000..e720d8b --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseBusinessLogic/BusinessLogics/SkillLogic.cs @@ -0,0 +1,89 @@ +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 SkillLogic : ISkillLogic + { + private readonly ISkillStorage _skillStorage; + + public SkillLogic(ISkillStorage skillStorage) + { + _skillStorage = skillStorage; + } + + // Создание и обновление записи о навыке + public void CreateOrUpdate(SkillBindingModel model) + { + var element = _skillStorage.GetElement( + new SkillBindingModel + { + Name = model.Name + }); + + if (element != null && element.Id != model.Id) + { + throw new Exception("Такой навык уже существует"); + } + + // Если уже создан, то обновляем, иначе создаём + if (model.Id.HasValue) + { + _skillStorage.Update(model); + } + else + { + _skillStorage.Insert(model); + } + } + + // Удаление записи о навыке + public bool Delete(SkillBindingModel model) + { + var element = _skillStorage.GetElement(new SkillBindingModel + { + Id = model.Id + }); + + if (element == null) + { + throw new Exception("Навык не найден"); + } + + if (_skillStorage.Delete(model) == null) + { + return false; + } + + return true; + } + + // Чтение записей о навыках + public List Read(SkillBindingModel model) + { + // Если неконкретная запись, то выводим все + if (model == null) + { + return _skillStorage.GetFullList(); + } + + // Если конкретная запись о навыке + if (model.Id.HasValue) + { + return new List + { + _skillStorage.GetElement(model) + }; + } + + return _skillStorage.GetFilteredList(model); + } + } +} diff --git a/Lab 3/Belianin_3/EnterpriseBusinessLogic/EnterpriseBusinessLogic.csproj b/Lab 3/Belianin_3/EnterpriseBusinessLogic/EnterpriseBusinessLogic.csproj new file mode 100644 index 0000000..8322eb6 --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseBusinessLogic/EnterpriseBusinessLogic.csproj @@ -0,0 +1,14 @@ + + + + net6.0-windows + enable + true + enable + + + + + + + diff --git a/Lab 3/Belianin_3/EnterpriseContracts/BindingModels/EmployeeBindingModel.cs b/Lab 3/Belianin_3/EnterpriseContracts/BindingModels/EmployeeBindingModel.cs new file mode 100644 index 0000000..bb6c7d5 --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseContracts/BindingModels/EmployeeBindingModel.cs @@ -0,0 +1,21 @@ +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 Skill { get; set; } + + public string Photo { get; set; } + + public string FIO { get; set; } + + public string PhoneNumber { get; set; } + } +} diff --git a/Lab 3/Belianin_3/EnterpriseContracts/BindingModels/SkillBindingModel.cs b/Lab 3/Belianin_3/EnterpriseContracts/BindingModels/SkillBindingModel.cs new file mode 100644 index 0000000..9dc4854 --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseContracts/BindingModels/SkillBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseContracts.BindingModels +{ + public class SkillBindingModel + { + public int? Id { get; set; } + + public string Name { get; set; } + } +} diff --git a/Lab 3/Belianin_3/EnterpriseContracts/BusinessLogicContracts/IEmployeeLogic.cs b/Lab 3/Belianin_3/EnterpriseContracts/BusinessLogicContracts/IEmployeeLogic.cs new file mode 100644 index 0000000..18bc785 --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseContracts/BusinessLogicContracts/IEmployeeLogic.cs @@ -0,0 +1,19 @@ +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/Lab 3/Belianin_3/EnterpriseContracts/BusinessLogicContracts/ISkillLogic.cs b/Lab 3/Belianin_3/EnterpriseContracts/BusinessLogicContracts/ISkillLogic.cs new file mode 100644 index 0000000..52f1e68 --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseContracts/BusinessLogicContracts/ISkillLogic.cs @@ -0,0 +1,19 @@ +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 ISkillLogic + { + List Read(SkillBindingModel model); + + void CreateOrUpdate(SkillBindingModel model); + + bool Delete(SkillBindingModel model); + } +} diff --git a/Lab 3/Belianin_3/EnterpriseContracts/EnterpriseContracts.csproj b/Lab 3/Belianin_3/EnterpriseContracts/EnterpriseContracts.csproj new file mode 100644 index 0000000..060aa1c --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseContracts/EnterpriseContracts.csproj @@ -0,0 +1,10 @@ + + + + net6.0-windows + enable + true + enable + + + diff --git a/Lab 3/Belianin_3/EnterpriseContracts/StorageContracts/IEmployeeStorage.cs b/Lab 3/Belianin_3/EnterpriseContracts/StorageContracts/IEmployeeStorage.cs new file mode 100644 index 0000000..70ae523 --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseContracts/StorageContracts/IEmployeeStorage.cs @@ -0,0 +1,25 @@ +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/Lab 3/Belianin_3/EnterpriseContracts/StorageContracts/ISkillStorage.cs b/Lab 3/Belianin_3/EnterpriseContracts/StorageContracts/ISkillStorage.cs new file mode 100644 index 0000000..7b116a6 --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseContracts/StorageContracts/ISkillStorage.cs @@ -0,0 +1,25 @@ +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 ISkillStorage + { + List GetFullList(); + + List GetFilteredList(SkillBindingModel model); + + SkillViewModel GetElement(SkillBindingModel model); + + void Insert(SkillBindingModel model); + + void Update(SkillBindingModel model); + + bool Delete(SkillBindingModel model); + } +} diff --git a/Lab 3/Belianin_3/EnterpriseContracts/ViewModels/EmployeeViewModel.cs b/Lab 3/Belianin_3/EnterpriseContracts/ViewModels/EmployeeViewModel.cs new file mode 100644 index 0000000..979a3cd --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseContracts/ViewModels/EmployeeViewModel.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseContracts.ViewModels +{ + public class EmployeeViewModel + { + public int? Id { get; set; } + + [DisplayName("Навык")] + public string Skill { get; set; } + + public string Photo { get; set; } + + [DisplayName("ФИО")] + public string FIO { get; set; } + + [DisplayName("Номер телефона")] + public string PhoneNumber { get; set; } + } +} diff --git a/Lab 3/Belianin_3/EnterpriseContracts/ViewModels/SkillViewModel.cs b/Lab 3/Belianin_3/EnterpriseContracts/ViewModels/SkillViewModel.cs new file mode 100644 index 0000000..ba7f53e --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseContracts/ViewModels/SkillViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseContracts.ViewModels +{ + public class SkillViewModel + { + public int? Id { get; set; } + + public string Name { get; set; } + } +} diff --git a/Lab 3/Belianin_3/EnterpriseDataBaseImplement/EnterpriseDataBase.cs b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/EnterpriseDataBase.cs new file mode 100644 index 0000000..3a8a66b --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/EnterpriseDataBase.cs @@ -0,0 +1,27 @@ +using EnterpriseDataBaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseDataBaseImplement +{ + public class EnterpriseDataBase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=EnterpriseDataBase;Integrated Security=True;MultipleActiveResultSets=True; TrustServerCertificate=True"); + } + + base.OnConfiguring(optionsBuilder); + } + + public virtual DbSet Employees { set; get; } + + public virtual DbSet Skills { set; get; } + } +} diff --git a/Lab 3/Belianin_3/EnterpriseDataBaseImplement/EnterpriseDataBaseImplement.csproj b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/EnterpriseDataBaseImplement.csproj new file mode 100644 index 0000000..12c1e07 --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/EnterpriseDataBaseImplement.csproj @@ -0,0 +1,28 @@ + + + + net6.0-windows + enable + true + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Implements/EmployeeStorage.cs b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Implements/EmployeeStorage.cs new file mode 100644 index 0000000..991991b --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Implements/EmployeeStorage.cs @@ -0,0 +1,135 @@ +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 + { + // Создание работника + private static Employee CreateModel(EmployeeBindingModel model, Employee employee) + { + employee.FIO = model.FIO; + employee.Skill = model.Skill; + employee.PhoneNumber = model.PhoneNumber; + employee.Photo = model.Photo; + + return employee; + } + + private EmployeeViewModel CreateModel(Employee employee) + { + return new EmployeeViewModel + { + Id = employee.Id, + FIO = employee.FIO, + Photo = employee.Photo, + PhoneNumber = employee.PhoneNumber, + Skill = employee.Skill + }; + } + + // Добавление работника + public void Insert(EmployeeBindingModel model) + { + var context = new EnterpriseDataBase(); + var transaction = context.Database.BeginTransaction(); + + try + { + context.Employees.Add(CreateModel(model, new Employee())); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + // Обновление данных о работнике + public void Update(EmployeeBindingModel model) + { + var context = new EnterpriseDataBase(); + var transaction = context.Database.BeginTransaction(); + + try + { + var employee = context.Employees.FirstOrDefault(rec => rec.Id == model.Id); + + if (employee == null) + { + throw new Exception("Сотрудник не найден"); + } + + CreateModel(model, employee); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public void Delete(EmployeeBindingModel model) + { + var context = new EnterpriseDataBase(); + var employee = context.Employees.FirstOrDefault(rec => rec.Id == model.Id); + + if (employee != null) + { + context.Employees.Remove(employee); + context.SaveChanges(); + } + else + { + throw new Exception("Сотрудник не найден"); + } + } + + // Получение записи о работнике + public EmployeeViewModel GetElement(EmployeeBindingModel model) + { + // Если пусто + if (model == null) + { + return null; + } + + using var context = new EnterpriseDataBase(); + + var employee = context.Employees.ToList() + .FirstOrDefault(rec => rec.FIO == model.FIO || rec.Id == model.Id); + + return employee != null ? CreateModel(employee) : null; + } + + // Получение отфильтрованного списка + public List GetFilteredList(EmployeeBindingModel model) + { + var context = new EnterpriseDataBase(); + + return context.Employees + .Where(employee => employee.FIO.Contains(model.FIO) && employee.Skill.Contains(model.Skill)) + .ToList().Select(CreateModel).ToList(); + } + + // Получение всех записей + public List GetFullList() + { + using (var context = new EnterpriseDataBase()) + { + return context.Employees.ToList().Select(CreateModel).ToList(); + } + } + } +} diff --git a/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Implements/SkillStorage.cs b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Implements/SkillStorage.cs new file mode 100644 index 0000000..9fe3be6 --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Implements/SkillStorage.cs @@ -0,0 +1,133 @@ +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 SkillStorage : ISkillStorage + { + // Создание навыка + private static Skill CreateModel(SkillBindingModel model, Skill skill) + { + skill.Name = model.Name; + return skill; + } + + private static SkillViewModel CreateModel(Skill skill) + { + return new SkillViewModel + { + Id = skill.Id, + Name = skill.Name + }; + } + + // Добавление навыка + public void Insert(SkillBindingModel model) + { + var context = new EnterpriseDataBase(); + var transaction = context.Database.BeginTransaction(); + + try + { + context.Skills.Add(CreateModel(model, new Skill())); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + // Обновление навыка + public void Update(SkillBindingModel model) + { + var context = new EnterpriseDataBase(); + var transaction = context.Database.BeginTransaction(); + + try + { + var skill = context.Skills.FirstOrDefault(rec => rec.Id == model.Id); + + // Навык не найден -> исключение + if (skill == null) + { + throw new Exception("Навык не найден :("); + } + + CreateModel(model, skill); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + // Удаление навыка + public bool Delete(SkillBindingModel model) + { + var context = new EnterpriseDataBase(); + var skill = context.Skills.FirstOrDefault(rec => rec.Id == model.Id); + + if (skill != null) + { + context.Skills.Remove(skill); + context.SaveChanges(); + return true; + } + else + { + throw new Exception("Навык не найден"); + } + } + + // Получение записи о навыке + public SkillViewModel GetElement(SkillBindingModel model) + { + if (model == null) + { + return null; + } + + using var context = new EnterpriseDataBase(); + + var skill = context.Skills.ToList().FirstOrDefault(rec => rec.Id == model.Id || rec.Name == model.Name); + + return skill != null ? CreateModel(skill) : null; + } + + // Получение фильтрованного списка + public List GetFilteredList(SkillBindingModel model) + { + // Если пусто + if (model == null) + { + return null; + } + + using var context = new EnterpriseDataBase(); + + return context.Skills.Where(rec => rec.Name.Contains(model.Name)) + .Select(CreateModel).ToList(); + } + + // Получение всего списка навыков + public List GetFullList() + { + using var context = new EnterpriseDataBase(); + + return context.Skills.Select(CreateModel).ToList(); + } + } +} diff --git a/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Migrations/20241022142146_Initial.Designer.cs b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Migrations/20241022142146_Initial.Designer.cs new file mode 100644 index 0000000..c2ce5df --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Migrations/20241022142146_Initial.Designer.cs @@ -0,0 +1,75 @@ +// +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("20241022142146_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.11") + .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("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Photo") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Skill") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("EnterpriseDataBaseImplement.Models.Skill", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Skills"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Migrations/20241022142146_Initial.cs b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Migrations/20241022142146_Initial.cs new file mode 100644 index 0000000..7e933d5 --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Migrations/20241022142146_Initial.cs @@ -0,0 +1,53 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EnterpriseDataBaseImplement.Migrations +{ + /// + public partial class Initial : 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"), + Skill = table.Column(type: "nvarchar(max)", nullable: false), + Photo = table.Column(type: "nvarchar(max)", nullable: false), + FIO = table.Column(type: "nvarchar(max)", nullable: false), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Employees", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Skills", + 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_Skills", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Employees"); + + migrationBuilder.DropTable( + name: "Skills"); + } + } +} diff --git a/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Migrations/EnterpriseDataBaseModelSnapshot.cs b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Migrations/EnterpriseDataBaseModelSnapshot.cs new file mode 100644 index 0000000..221140f --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Migrations/EnterpriseDataBaseModelSnapshot.cs @@ -0,0 +1,72 @@ +// +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.11") + .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("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Photo") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Skill") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("EnterpriseDataBaseImplement.Models.Skill", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Skills"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Models/Employee.cs b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Models/Employee.cs new file mode 100644 index 0000000..c186d05 --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Models/Employee.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseDataBaseImplement.Models +{ + public class Employee + { + public int Id { get; set; } + + [Required] + public string Skill { get; set; } + + [Required] + public string Photo { get; set; } + + [Required] + public string FIO { get; set; } + + [Required] + public string PhoneNumber { get; set; } + } +} diff --git a/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Models/Skill.cs b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Models/Skill.cs new file mode 100644 index 0000000..1d1b623 --- /dev/null +++ b/Lab 3/Belianin_3/EnterpriseDataBaseImplement/Models/Skill.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EnterpriseDataBaseImplement.Models +{ + public class Skill + { + public int Id { get; set; } + + [Required] + public string Name { get; set; } + } +}