diff --git a/COP/COP.sln b/COP/COP.sln index 610bbdd..eaf92b6 100644 --- a/COP/COP.sln +++ b/COP/COP.sln @@ -7,15 +7,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COP", "COP.csproj", "{B22B2 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestComponents", "..\TestComponents\TestComponents.csproj", "{C0F09A72-65A3-49DD-8208-291778E03E81}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityDataModels", "..\UniversityDataModels\UniversityDataModels.csproj", "{843E5B85-F60A-45D7-9B52-96284FFDCA1F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityDataModels", "..\UniversityDataModels\UniversityDataModels.csproj", "{843E5B85-F60A-45D7-9B52-96284FFDCA1F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityBusinessLogic", "..\UniversityBusinessLogic\UniversityBusinessLogic.csproj", "{453BBFDD-7D8B-463F-A622-AFD6F3E6C644}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityBusinessLogic", "..\UniversityBusinessLogic\UniversityBusinessLogic.csproj", "{453BBFDD-7D8B-463F-A622-AFD6F3E6C644}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityContracts", "..\UniversityContracts\UniversityContracts.csproj", "{2EFD9DCC-226F-45D0-8688-4E0D716BC179}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityContracts", "..\UniversityContracts\UniversityContracts.csproj", "{2EFD9DCC-226F-45D0-8688-4E0D716BC179}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityDatabaseImplement", "..\UniversityDatabaseImplement\UniversityDatabaseImplement.csproj", "{7ED4372B-4D10-411D-9CC1-13CAA2833789}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityDatabaseImplement", "..\UniversityDatabaseImplement\UniversityDatabaseImplement.csproj", "{7ED4372B-4D10-411D-9CC1-13CAA2833789}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityView", "..\UniversityView\UniversityView.csproj", "{99AE36FC-FEF0-4E8C-8C0B-F6AB1952DEE6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityView", "..\UniversityView\UniversityView.csproj", "{99AE36FC-FEF0-4E8C-8C0B-F6AB1952DEE6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginsConventionLibrary", "..\PluginsConventionLibrary\PluginsConventionLibrary.csproj", "{651E8CAB-EEAD-41A7-AC99-F0F7D853AD84}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -51,6 +53,10 @@ Global {99AE36FC-FEF0-4E8C-8C0B-F6AB1952DEE6}.Debug|Any CPU.Build.0 = Debug|Any CPU {99AE36FC-FEF0-4E8C-8C0B-F6AB1952DEE6}.Release|Any CPU.ActiveCfg = Release|Any CPU {99AE36FC-FEF0-4E8C-8C0B-F6AB1952DEE6}.Release|Any CPU.Build.0 = Release|Any CPU + {651E8CAB-EEAD-41A7-AC99-F0F7D853AD84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {651E8CAB-EEAD-41A7-AC99-F0F7D853AD84}.Debug|Any CPU.Build.0 = Debug|Any CPU + {651E8CAB-EEAD-41A7-AC99-F0F7D853AD84}.Release|Any CPU.ActiveCfg = Release|Any CPU + {651E8CAB-EEAD-41A7-AC99-F0F7D853AD84}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PluginsConventionLibrary/Forms/FormDirection.Designer.cs b/PluginsConventionLibrary/Forms/FormDirection.Designer.cs new file mode 100644 index 0000000..f5bfb84 --- /dev/null +++ b/PluginsConventionLibrary/Forms/FormDirection.Designer.cs @@ -0,0 +1,66 @@ +namespace PluginsConventionLibrary.Forms +{ + partial class FormDirection + { + /// + /// 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.BackgroundColor = System.Drawing.SystemColors.Control; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(429, 297); + 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); + // + // FormHandbooks + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(429, 297); + this.Controls.Add(this.dataGridView); + this.Name = "FormDirection"; + this.Text = "Направления"; + this.Load += new System.EventHandler(this.FormDirection_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/PluginsConventionLibrary/Forms/FormDirection.cs b/PluginsConventionLibrary/Forms/FormDirection.cs new file mode 100644 index 0000000..efa17a8 --- /dev/null +++ b/PluginsConventionLibrary/Forms/FormDirection.cs @@ -0,0 +1,110 @@ +using System.ComponentModel; +using UniversityContracts.BindingModels; +using UniversityContracts.BusinessLogicsContracts; + +namespace PluginsConventionLibrary.Forms +{ + public partial class FormDirection : Form + { + private readonly IDirectionLogic _logic; + BindingList _list; + private int? _id; + public int Id { set { _id = value; } } + public FormDirection(IDirectionLogic logic) + { + InitializeComponent(); + _logic = logic; + _list = new BindingList(); + dataGridView.AllowUserToAddRows = false; + } + + private void FormDirection_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.Read(null); + _list.Clear(); + foreach (var item in list) + { + _list.Add(new DirectionBindingModel + { + 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 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) + { + _logic.CreateOrUpdate(new DirectionBindingModel() + { + Id = Convert.ToInt32(dataGridView.CurrentRow.Cells[0].Value), + Name = (string)dataGridView.CurrentRow.Cells[1].EditedFormattedValue + }); + } + else + { + _logic.CreateOrUpdate(new DirectionBindingModel() + { + 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 DirectionBindingModel()); + dataGridView.DataSource = new BindingList(_list); + dataGridView.CurrentCell = dataGridView.Rows[0].Cells[1]; + return; + } + if (dataGridView.Rows[dataGridView.Rows.Count - 1].Cells[1].Value != null) + { + _list.Add(new DirectionBindingModel()); + dataGridView.DataSource = new BindingList(_list); + dataGridView.CurrentCell = dataGridView.Rows[dataGridView.Rows.Count - 1].Cells[1]; + return; + } + } + if (e.KeyData == Keys.Delete) + { + if (MessageBox.Show("Удалить выбранный элемент", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + _logic.Delete(new DirectionBindingModel() { Id = (int)dataGridView.CurrentRow.Cells[0].Value }); + LoadData(); + } + } + } + } +} diff --git a/PluginsConventionLibrary/Forms/FormDirection.resx b/PluginsConventionLibrary/Forms/FormDirection.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PluginsConventionLibrary/Forms/FormDirection.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/PluginsConventionLibrary/Forms/FormStudent.Designer.cs b/PluginsConventionLibrary/Forms/FormStudent.Designer.cs new file mode 100644 index 0000000..334fb60 --- /dev/null +++ b/PluginsConventionLibrary/Forms/FormStudent.Designer.cs @@ -0,0 +1,173 @@ +namespace PluginsConventionLibrary.Forms +{ + partial class FormStudent + { + /// + /// 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.textBoxFIO = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.componenttBox1 = new COPWinForms.ComponentTBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.userCheckedListBox1 = new COP.UserCheckedListBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonAddPhoto = new System.Windows.Forms.Button(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.SuspendLayout(); + // + // textBoxFIO + // + this.textBoxFIO.Location = new System.Drawing.Point(105, 27); + this.textBoxFIO.Name = "textBoxFIO"; + this.textBoxFIO.Size = new System.Drawing.Size(214, 23); + this.textBoxFIO.TabIndex = 0; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(65, 30); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(34, 15); + this.label1.TabIndex = 1; + this.label1.Text = "ФИО"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(65, 68); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(113, 15); + this.label2.TabIndex = 3; + this.label2.Text = "Электронная почта"; + // + // componenttBox1 + // + this.componenttBox1.Location = new System.Drawing.Point(184, 65); + this.componenttBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.componenttBox1.Name = "componenttBox1"; + this.componenttBox1.Pattern = null; + this.componenttBox1.Size = new System.Drawing.Size(135, 38); + this.componenttBox1.TabIndex = 4; + this.componenttBox1.TextBoxValue = null; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.userCheckedListBox1); + this.groupBox1.Location = new System.Drawing.Point(12, 108); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(362, 150); + this.groupBox1.TabIndex = 5; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Направление"; + // + // userCheckedListBox1 + // + this.userCheckedListBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.userCheckedListBox1.Location = new System.Drawing.Point(3, 19); + this.userCheckedListBox1.Name = "userCheckedListBox1"; + this.userCheckedListBox1.SelectedValue = ""; + this.userCheckedListBox1.Size = new System.Drawing.Size(356, 128); + this.userCheckedListBox1.TabIndex = 0; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(218, 465); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(299, 465); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonAddPhoto + // + this.buttonAddPhoto.Location = new System.Drawing.Point(12, 264); + this.buttonAddPhoto.Name = "buttonAddPhoto"; + this.buttonAddPhoto.Size = new System.Drawing.Size(360, 23); + this.buttonAddPhoto.TabIndex = 8; + this.buttonAddPhoto.Text = "Загрузить фото"; + this.buttonAddPhoto.UseVisualStyleBackColor = true; + this.buttonAddPhoto.Click += new System.EventHandler(this.buttonAddPhoto_Click); + // + // pictureBox + // + this.pictureBox.Location = new System.Drawing.Point(12, 293); + this.pictureBox.Name = "pictureBox"; + this.pictureBox.Size = new System.Drawing.Size(359, 166); + this.pictureBox.TabIndex = 9; + this.pictureBox.TabStop = false; + // + // FormStudent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(384, 500); + this.Controls.Add(this.pictureBox); + this.Controls.Add(this.buttonAddPhoto); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.componenttBox1); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBoxFIO); + this.Name = "FormStudent"; + this.Text = "Студент"; + this.Load += new System.EventHandler(this.FormStudent_Load); + this.groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + } + + #endregion + + private TextBox textBoxFIO; + private Label label1; + private Label label2; + private COPWinForms.ComponentTBox componenttBox1; + private GroupBox groupBox1; + private Button buttonSave; + private Button buttonCancel; + private COP.UserCheckedListBox userCheckedListBox1; + private Button buttonAddPhoto; + private PictureBox pictureBox; + } +} \ No newline at end of file diff --git a/PluginsConventionLibrary/Forms/FormStudent.cs b/PluginsConventionLibrary/Forms/FormStudent.cs new file mode 100644 index 0000000..ee23297 --- /dev/null +++ b/PluginsConventionLibrary/Forms/FormStudent.cs @@ -0,0 +1,148 @@ +using Microsoft.Extensions.Logging; +using System.ComponentModel; +using UniversityContracts.BindingModels; +using UniversityContracts.BusinessLogicsContracts; +using UniversityContracts.ViewModels; + +namespace PluginsConventionLibrary.Forms +{ + public partial class FormStudent : Form + { + private readonly IStudentLogic _studentLogic; + private readonly IDirectionLogic _directionLogic; + private string imagePath; + BindingList _list; + private int? _id; + public int Id { set { _id = value; } } + List directions = new(); + public FormStudent( IStudentLogic studentLogic, IDirectionLogic directionLogic) + { + InitializeComponent(); + _studentLogic = studentLogic; + _directionLogic = directionLogic; + imagePath = ""; + _list = new BindingList(); + componenttBox1.Pattern = @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"; + componenttBox1.setExample("example@mail.ru"); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxFIO.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(componenttBox1.TextBoxValue)) + { + MessageBox.Show("Заполните электронную почту", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (userCheckedListBox1.SelectedValue == null) + { + MessageBox.Show("Заполните направление", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (pictureBox.Image == null) + { + MessageBox.Show("Загрузите фото", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + _studentLogic.CreateOrUpdate(new StudentBindingModel + { + Id = _id, + FIO = textBoxFIO.Text, + PhotoFilePath = imagePath, + Email = componenttBox1.TextBoxValue, + DirectionName = userCheckedListBox1.SelectedValue + }); ; + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void FormStudent_Load(object sender, EventArgs e) + { + LoadData(); + if (_id.HasValue) + { + try + { + StudentViewModel? view = _studentLogic.Read(new StudentBindingModel { Id = _id.Value })?[0]; + if (view != null) + { + textBoxFIO.Text = view.FIO; + componenttBox1.TextBoxValue = view.Email; + imagePath = view.PhotoFilePath; + string[] dirs = view.DirectionName.Split(";"); + foreach (var dir in dirs) + { + userCheckedListBox1.SelectedValue = dir; + } + pictureBox.Image = Image.FromFile(imagePath); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + try + { + var list = _directionLogic.Read(null); + userCheckedListBox1.ClearList(); + directions.Clear(); + _list.Clear(); + if (list != null) + { + foreach (var item in list) + { + directions.Add(item.Name); + _list.Add(new DirectionBindingModel + { + Id = item.Id, + Name = item.Name, + }); + } + } + userCheckedListBox1.FillList(directions); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAddPhoto_Click(object sender, EventArgs e) + { + OpenFileDialog openFileDialog = new() + { + Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG|All files (*.*)|*.*" + }; + + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + imagePath = openFileDialog.FileName; + pictureBox.Image = Image.FromFile(imagePath); + } + } + } +} diff --git a/PluginsConventionLibrary/Forms/FormStudent.resx b/PluginsConventionLibrary/Forms/FormStudent.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PluginsConventionLibrary/Forms/FormStudent.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/PluginsConventionLibrary/MainPluginConvention.cs b/PluginsConventionLibrary/MainPluginConvention.cs new file mode 100644 index 0000000..c997f4f --- /dev/null +++ b/PluginsConventionLibrary/MainPluginConvention.cs @@ -0,0 +1,254 @@ +using COP; +using COP.Info; +using COPWinForms; +using PluginsConventionLibrary.Forms; +using PluginsConventionLibrary.Plugins; +using System.ComponentModel.Composition; +using UniversityBusinessLogic.BusinessLogics; +using UniversityContracts.BindingModels; +using UniversityContracts.BusinessLogicsContracts; +using WinFormsControlLibrary; +using static COP.ExcelComponent; +using static COPWinForms.ComponentWord2; +using LegendPosition = WinFormsControlLibrary.LegendPosition; + +namespace PluginsConventionLibrary +{ + [Export(typeof(IPluginsConvention))] + public class MainPluginConvention : IPluginsConvention + { + + private TableOfValues tableOfValues; + private readonly IStudentLogic _studentLogic; + private readonly IDirectionLogic _directionLogic; + + public MainPluginConvention() + { + _studentLogic = new StudentLogic(); + _directionLogic = new DirectionLogic(); + + tableOfValues = new TableOfValues(); + var menu = new ContextMenuStrip(); + var directionMenuItem = new ToolStripMenuItem("Формы"); + menu.Items.Add(directionMenuItem); + directionMenuItem.Click += (sender, e) => + { + var formDirection = new FormDirection(_directionLogic); + formDirection.ShowDialog(); + }; + tableOfValues.ContextMenuStrip = menu; + ReloadData(); + } + + /// Название плагина + string IPluginsConvention.PluginName => PluginName(); + public string PluginName() + { + return "Студенты"; + } + + public UserControl GetControl => tableOfValues; + + PluginsConventionElement IPluginsConvention.GetElement => GetElement(); + + public PluginsConventionElement GetElement() + { + var student = tableOfValues.GetSelectedObject(); ; + MainPluginConventionElement element = null; + if (tableOfValues != null) + { + element = new MainPluginConventionElement + { + Id = student.Id, + FIO = student.FIO, + PhotoFilePath = student.PhotoFilePath, + Email = student.Email, + DirectionName = student.DirectionName, + }; + } + return (new PluginsConventionElement { Id = element.Id }); + } + + public Form GetForm(PluginsConventionElement element) + { + var formOrder = new FormStudent(_studentLogic, _directionLogic); + if (element != null) + { + formOrder.Id = element.Id; + } + return formOrder; + } + + public bool DeleteElement(PluginsConventionElement element) + { + try + { + _studentLogic.Delete(new StudentBindingModel { Id = element.Id }); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + return true; + } + + public void ReloadData() + { + var columnConfigs = new List + { + new GridColumnConfig { HeaderText = "Id", Width = 100, Visible = false, PropertyName = "Id" }, + new GridColumnConfig { HeaderText = "ФИО", Width = 100, Visible = true, PropertyName = "FIO" }, + new GridColumnConfig { HeaderText = "Направление", Width = 80, Visible = true, PropertyName = "DirectionName" }, + new GridColumnConfig { HeaderText = "Электронная почта", Width = 80, Visible = true, PropertyName = "Email" }, + }; + + tableOfValues.ConfigureColumns(columnConfigs); + } + + private byte[] StringToImage(string bytes) + { + byte[] arrayimg = Convert.FromBase64String(bytes); + return arrayimg; + } + + public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument) + { + ExcelComponent excelComponent = new(); + var list = _studentLogic.Read(null); + List images = new(); + using var dialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + if (list != null) + { + foreach (var item in list) + { + images.Add(new ImageInfo() { FilePath = item.PhotoFilePath }); + } + } + ExcelImageInfo info = new(dialog.FileName, "Документ с фотографиями студентов", images); + excelComponent.GenerateExcelWithImages(info); + MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + return true; + } + + public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument) + { + ComponentWord2 componentWord = new(); + var list = _studentLogic.Read(null); + List data = new(); + List mergedColumns = new() + { + new int[] { 1, 2 } + }; + + List columnDefinitions = new() + { + new ColumnDefinition { Header = "ID", PropertyName = "Id", Width = 11 }, + new ColumnDefinition { Header = "Личные данные", PropertyName = "PersonalData", Width = 11 }, + new ColumnDefinition { Header = "Личные данные", PropertyName = "PersonalData1", Width = 11 }, + new ColumnDefinition { Header = "Направление", PropertyName = "DirectionName", Width = 21 } + }; + + List columnDefinitions2 = new() + { + new ColumnDefinition { Header = "ID", PropertyName = "Id", Width = 11 }, + new ColumnDefinition { Header = "ФИО", PropertyName = "FIO", Width = 11 }, + new ColumnDefinition { Header = "Электронная почта", PropertyName = "Email", Width = 70 }, + new ColumnDefinition { Header = "Направление", PropertyName = "DirectionName", Width = 21 } + }; + + using var dialog = new SaveFileDialog + { + Filter = "docx|*.docx" + }; + + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + if (list != null) + { + foreach (var item in list) + { + data.Add(new StudentBindingModel() { Id = item.Id, FIO = item.FIO, Email = item.Email, DirectionName = item.DirectionName }); + } + } + TableWord tableWord = new(dialog.FileName, "Таблица со студентами", columnDefinitions, columnDefinitions2, data, mergedColumns); + componentWord.CreateTable(tableWord); + MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + return true; + } + + public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument) + { + GistogramPdfComponent3 gistogramPdfComponent = new(); + var listStudents = _studentLogic.Read(null); + var listDirections = _directionLogic.Read(null); + List<(string, int)> data = new(); + List gistData = new(); + using var dialog = new SaveFileDialog + { + Filter = "pdf|*.pdf" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + for (int i = 0; i < listDirections.Count; i++) + { + int count = 0; + for (int j = 0; j < listStudents.Count; j++) + { + string[] dirs = listStudents[j].DirectionName.Split(";"); + foreach (var dir in dirs) + { + if (dir == listDirections[i].Name) count++; + } + } + data.Add((listDirections[i].Name, count)); + } + if (data != null) + { + foreach (var item in data) + { + gistData.Add(new HistogramData + { + SeriesName = item.Item1, + Data = new double[] { item.Item2 } + }); + } + } + gistogramPdfComponent.GenerateHistogramDocument(dialog.FileName, "Histogram", "Students-Directions", LegendPosition.TopRight, gistData); + MessageBox.Show("Сохарнено успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + return true; + } + } +} diff --git a/PluginsConventionLibrary/MainPluginConventionElement.cs b/PluginsConventionLibrary/MainPluginConventionElement.cs new file mode 100644 index 0000000..d70871c --- /dev/null +++ b/PluginsConventionLibrary/MainPluginConventionElement.cs @@ -0,0 +1,15 @@ +using PluginsConventionLibrary.Plugins; + +namespace PluginsConventionLibrary +{ + public class MainPluginConventionElement : PluginsConventionElement + { + public string DirectionName { get; set; } + + public string PhotoFilePath { get; set; } + + public string FIO { get; set; } + + public string Email { get; set; } + } +} diff --git a/PluginsConventionLibrary/Plugins/IPluginsConvention.cs b/PluginsConventionLibrary/Plugins/IPluginsConvention.cs new file mode 100644 index 0000000..f85aa18 --- /dev/null +++ b/PluginsConventionLibrary/Plugins/IPluginsConvention.cs @@ -0,0 +1,60 @@ +namespace PluginsConventionLibrary.Plugins +{ + public interface IPluginsConvention + { + /// + /// Название плагина + /// + string PluginName { get; } + + /// + /// Получение контрола для вывода набора данных + /// + UserControl GetControl { get; } + + /// + /// Получение элемента, выбранного в контроле + /// + PluginsConventionElement GetElement { get; } + + /// + /// Получение формы для создания/редактирования объекта + /// + /// + /// + Form GetForm(PluginsConventionElement element); + + /// + /// Удаление элемента + /// + /// + /// + bool DeleteElement(PluginsConventionElement element); + + /// + /// Обновление набора данных в контроле + /// + void ReloadData(); + + /// + /// Создание простого документа + /// + /// + /// + bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument); + + /// + /// Создание простого документа + /// + /// + /// + bool CreateTableDocument(PluginsConventionSaveDocument saveDocument); + + /// + /// Создание документа с диаграммой + /// + /// + /// + bool CreateChartDocument(PluginsConventionSaveDocument saveDocument); + } +} diff --git a/PluginsConventionLibrary/Plugins/PluginsConventionElement.cs b/PluginsConventionLibrary/Plugins/PluginsConventionElement.cs new file mode 100644 index 0000000..99f7ef9 --- /dev/null +++ b/PluginsConventionLibrary/Plugins/PluginsConventionElement.cs @@ -0,0 +1,7 @@ +namespace PluginsConventionLibrary.Plugins +{ + public class PluginsConventionElement + { + public int Id { get; set; } + } +} diff --git a/PluginsConventionLibrary/Plugins/PluginsConventionSaveDocument.cs b/PluginsConventionLibrary/Plugins/PluginsConventionSaveDocument.cs new file mode 100644 index 0000000..a0a7ce1 --- /dev/null +++ b/PluginsConventionLibrary/Plugins/PluginsConventionSaveDocument.cs @@ -0,0 +1,7 @@ +namespace PluginsConventionLibrary.Plugins +{ + public class PluginsConventionSaveDocument + { + public string FileName { get; set; } + } +} diff --git a/PluginsConventionLibrary/PluginsConventionLibrary.csproj b/PluginsConventionLibrary/PluginsConventionLibrary.csproj new file mode 100644 index 0000000..f34c76b --- /dev/null +++ b/PluginsConventionLibrary/PluginsConventionLibrary.csproj @@ -0,0 +1,21 @@ + + + + net6.0-windows + enable + true + enable + + + + + + + + + + + + + + diff --git a/UniversityBusinessLogic/BusinessLogics/DirectionLogic.cs b/UniversityBusinessLogic/BusinessLogics/DirectionLogic.cs index b11577c..ed2c9de 100644 --- a/UniversityBusinessLogic/BusinessLogics/DirectionLogic.cs +++ b/UniversityBusinessLogic/BusinessLogics/DirectionLogic.cs @@ -4,6 +4,7 @@ using UniversityContracts.BusinessLogicsContracts; using UniversityContracts.SearchModels; using UniversityContracts.StoragesContracts; using UniversityContracts.ViewModels; +using UniversityUniversityDatabaseImplement.Implements; namespace UniversityBusinessLogic.BusinessLogics { @@ -14,7 +15,10 @@ namespace UniversityBusinessLogic.BusinessLogics { _directionStorage = directionStorage; } - + public DirectionLogic() + { + _directionStorage = new DirectionStorage(); + } public void CreateOrUpdate(DirectionBindingModel model) { var element = _directionStorage.GetElement( diff --git a/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs b/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs index bcffca3..3bb75fc 100644 --- a/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs +++ b/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs @@ -4,6 +4,7 @@ using UniversityContracts.BusinessLogicsContracts; using UniversityContracts.SearchModels; using UniversityContracts.StoragesContracts; using UniversityContracts.ViewModels; +using UniversityUniversityDatabaseImplement.Implements; namespace UniversityBusinessLogic.BusinessLogics { @@ -14,6 +15,10 @@ namespace UniversityBusinessLogic.BusinessLogics { _studentStorage = studentStorage; } + public StudentLogic() + { + _studentStorage = new StudentStorage(); + } public void CreateOrUpdate(StudentBindingModel model) { var element = _studentStorage.GetElement( diff --git a/UniversityBusinessLogic/UniversityBusinessLogic.csproj b/UniversityBusinessLogic/UniversityBusinessLogic.csproj index c25f64d..436dc10 100644 --- a/UniversityBusinessLogic/UniversityBusinessLogic.csproj +++ b/UniversityBusinessLogic/UniversityBusinessLogic.csproj @@ -13,6 +13,7 @@ + diff --git a/UniversityView/FormMainPlugins.Designer.cs b/UniversityView/FormMainPlugins.Designer.cs new file mode 100644 index 0000000..a40a321 --- /dev/null +++ b/UniversityView/FormMainPlugins.Designer.cs @@ -0,0 +1,180 @@ +namespace UniversityView +{ + partial class FormMainPlugins + { + /// + /// 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.components = new System.ComponentModel.Container(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.ControlsStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ActionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.AddElementToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.UpdElementToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.DelElementToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.DocsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.SimpleDocToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.TableDocToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ChartDocToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.panelControl = new System.Windows.Forms.Panel(); + this.excelComponent1 = new COP.ExcelComponent(this.components); + this.gistogramPdfComponent31 = new WinFormsControlLibrary.GistogramPdfComponent3(this.components); + this.componentWord21 = new COPWinForms.ComponentWord2(this.components); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // menuStrip + // + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ControlsStripMenuItem, + this.ActionsToolStripMenuItem, + this.DocsToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(800, 24); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "Меню"; + // + // ControlsStripMenuItem + // + this.ControlsStripMenuItem.Name = "ControlsStripMenuItem"; + this.ControlsStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.ControlsStripMenuItem.Text = "Справочники"; + // + // ActionsToolStripMenuItem + // + this.ActionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.AddElementToolStripMenuItem, + this.UpdElementToolStripMenuItem, + this.DelElementToolStripMenuItem}); + this.ActionsToolStripMenuItem.Name = "ActionsToolStripMenuItem"; + this.ActionsToolStripMenuItem.Size = new System.Drawing.Size(70, 20); + this.ActionsToolStripMenuItem.Text = "Действия"; + // + // AddElementToolStripMenuItem + // + this.AddElementToolStripMenuItem.Name = "AddElementToolStripMenuItem"; + this.AddElementToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.A))); + this.AddElementToolStripMenuItem.Size = new System.Drawing.Size(170, 22); + this.AddElementToolStripMenuItem.Text = "Добавить"; + this.AddElementToolStripMenuItem.Click += new System.EventHandler(this.AddElementToolStripMenuItem_Click); + // + // UpdElementToolStripMenuItem + // + this.UpdElementToolStripMenuItem.Name = "UpdElementToolStripMenuItem"; + this.UpdElementToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.U))); + this.UpdElementToolStripMenuItem.Size = new System.Drawing.Size(170, 22); + this.UpdElementToolStripMenuItem.Text = "Изменить"; + this.UpdElementToolStripMenuItem.Click += new System.EventHandler(this.UpdElementToolStripMenuItem_Click); + // + // DelElementToolStripMenuItem + // + this.DelElementToolStripMenuItem.Name = "DelElementToolStripMenuItem"; + this.DelElementToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.D))); + this.DelElementToolStripMenuItem.Size = new System.Drawing.Size(170, 22); + this.DelElementToolStripMenuItem.Text = "Удалить"; + this.DelElementToolStripMenuItem.Click += new System.EventHandler(this.DelElementToolStripMenuItem_Click); + // + // DocsToolStripMenuItem + // + this.DocsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.SimpleDocToolStripMenuItem, + this.TableDocToolStripMenuItem, + this.ChartDocToolStripMenuItem}); + this.DocsToolStripMenuItem.Name = "DocsToolStripMenuItem"; + this.DocsToolStripMenuItem.Size = new System.Drawing.Size(82, 20); + this.DocsToolStripMenuItem.Text = "Документы"; + // + // SimpleDocToolStripMenuItem + // + this.SimpleDocToolStripMenuItem.Name = "SimpleDocToolStripMenuItem"; + this.SimpleDocToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); + this.SimpleDocToolStripMenuItem.Size = new System.Drawing.Size(232, 22); + this.SimpleDocToolStripMenuItem.Text = "Простой документ"; + this.SimpleDocToolStripMenuItem.Click += new System.EventHandler(this.SimpleDocToolStripMenuItem_Click); + // + // TableDocToolStripMenuItem + // + this.TableDocToolStripMenuItem.Name = "TableDocToolStripMenuItem"; + this.TableDocToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.T))); + this.TableDocToolStripMenuItem.Size = new System.Drawing.Size(232, 22); + this.TableDocToolStripMenuItem.Text = "Документ с таблицей"; + this.TableDocToolStripMenuItem.Click += new System.EventHandler(this.TableDocToolStripMenuItem_Click); + // + // ChartDocToolStripMenuItem + // + this.ChartDocToolStripMenuItem.Name = "ChartDocToolStripMenuItem"; + this.ChartDocToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C))); + this.ChartDocToolStripMenuItem.Size = new System.Drawing.Size(232, 22); + this.ChartDocToolStripMenuItem.Text = "Диаграмма"; + this.ChartDocToolStripMenuItem.Click += new System.EventHandler(this.ChartDocToolStripMenuItem_Click); + // + // panelControl + // + this.panelControl.Dock = System.Windows.Forms.DockStyle.Fill; + this.panelControl.Location = new System.Drawing.Point(0, 24); + this.panelControl.Name = "panelControl"; + this.panelControl.Size = new System.Drawing.Size(800, 426); + this.panelControl.TabIndex = 1; + // + // FormMainPlugins + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.panelControl); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMainPlugins"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Главная форма"; + this.WindowState = System.Windows.Forms.FormWindowState.Maximized; + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FormMainPlugins_KeyDown); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.MenuStrip menuStrip; + private System.Windows.Forms.ToolStripMenuItem ControlsStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem DocsToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem SimpleDocToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem TableDocToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem ChartDocToolStripMenuItem; + private System.Windows.Forms.Panel panelControl; + private System.Windows.Forms.ToolStripMenuItem ActionsToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem AddElementToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem UpdElementToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem DelElementToolStripMenuItem; + private COP.ExcelComponent excelComponent1; + private WinFormsControlLibrary.GistogramPdfComponent3 gistogramPdfComponent31; + private COPWinForms.ComponentWord2 componentWord21; + } +} \ No newline at end of file diff --git a/UniversityView/FormMainPlugins.cs b/UniversityView/FormMainPlugins.cs new file mode 100644 index 0000000..81e89f8 --- /dev/null +++ b/UniversityView/FormMainPlugins.cs @@ -0,0 +1,162 @@ +using PluginsConventionLibrary.Plugins; + +namespace UniversityView +{ + public partial class FormMainPlugins : Form + { + private readonly Dictionary _plugins; + private string _selectedPlugin; + private ContextMenuStrip contextMenu = new ContextMenuStrip(); + public FormMainPlugins() + { + InitializeComponent(); + _plugins = LoadPlugins(); + _selectedPlugin = string.Empty; + } + private Dictionary LoadPlugins() + { + PluginsManager manager = new(); + var plugins = manager.plugins_dictionary; + + ToolStripItem[] toolStripItems = new ToolStripItem[plugins.Count]; + int i = 0; + if (plugins.Count > 0) + { + foreach (var plugin in plugins) + { + ToolStripMenuItem itemMenu = new() + { + Text = plugin.Value.PluginName + }; + itemMenu.Click += (sender, e) => + { + _selectedPlugin = plugin.Value.PluginName; + panelControl.Controls.Clear(); + panelControl.Controls.Add(_plugins[_selectedPlugin].GetControl); + panelControl.Controls[0].Dock = DockStyle.Fill; + }; + toolStripItems[i] = itemMenu; + i++; + } + ControlsStripMenuItem.DropDownItems.AddRange(toolStripItems); + } + return plugins; + } + private void FormMainPlugins_KeyDown(object sender, KeyEventArgs e) + { + if (!e.Control) + { + return; + } + switch (e.KeyCode) + { + case Keys.A: + AddNewElement(); + break; + case Keys.U: + UpdateElement(); + break; + case Keys.D: + DeleteElement(); + break; + case Keys.S: + CreateSimpleDoc(); + break; + case Keys.T: + CreateTableDoc(); + break; + case Keys.C: + CreateChartDoc(); + break; + } + } + private void AddNewElement() + { + var form = _plugins[_selectedPlugin].GetForm(null); + if (form != null && form.ShowDialog() == DialogResult.OK) + { + _plugins[_selectedPlugin].ReloadData(); + } + } + private void UpdateElement() + { + var element = _plugins[_selectedPlugin].GetElement; + if (element == null) + { + MessageBox.Show("Нет выбранного элемента", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + var form = _plugins[_selectedPlugin].GetForm(element); + if (form != null && form.ShowDialog() == DialogResult.OK) + { + _plugins[_selectedPlugin].ReloadData(); + } + } + private void DeleteElement() + { + if (MessageBox.Show("Удалить выбранный элемент", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + var element = _plugins[_selectedPlugin].GetElement; + if (element == null) + { + MessageBox.Show("Нет выбранного элемента", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_plugins[_selectedPlugin].DeleteElement(element)) + { + _plugins[_selectedPlugin].ReloadData(); + } + } + private void CreateSimpleDoc() + { + using var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }; + if (_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument { FileName = dialog.FileName })) + { + MessageBox.Show("Документ сохранен", "Создание документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Ошибка при создании документа", + "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CreateTableDoc() + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (_plugins[_selectedPlugin].CreateTableDocument(new PluginsConventionSaveDocument())) + { + MessageBox.Show("Документ сохранен", "Создание документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Ошибка при создании документа", + "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CreateChartDoc() + { + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (_plugins[_selectedPlugin].CreateChartDocument(new + PluginsConventionSaveDocument())) + { + MessageBox.Show("Документ сохранен", "Создание документа", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Ошибка при создании документа", + "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void AddElementToolStripMenuItem_Click(object sender, EventArgs e) => AddNewElement(); + private void UpdElementToolStripMenuItem_Click(object sender, EventArgs e) => UpdateElement(); + private void DelElementToolStripMenuItem_Click(object sender, EventArgs e) => DeleteElement(); + private void SimpleDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateSimpleDoc(); + private void TableDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateTableDoc(); + private void ChartDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateChartDoc(); + } +} diff --git a/UniversityView/FormMainPlugins.resx b/UniversityView/FormMainPlugins.resx new file mode 100644 index 0000000..3b38943 --- /dev/null +++ b/UniversityView/FormMainPlugins.resx @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 125, 17 + + + 275, 17 + + + 478, 17 + + \ No newline at end of file diff --git a/UniversityView/PluginsManager.cs b/UniversityView/PluginsManager.cs new file mode 100644 index 0000000..fb6a818 --- /dev/null +++ b/UniversityView/PluginsManager.cs @@ -0,0 +1,43 @@ +using PluginsConventionLibrary.Plugins; +using System.ComponentModel.Composition; +using System.ComponentModel.Composition.Hosting; + +namespace UniversityView +{ + public class PluginsManager + { + //Тег, указывающий, что plugins должны быть заполнены CompositionContainer + [ImportMany(typeof(IPluginsConvention))] + IEnumerable plugins { get; set; } + + public readonly Dictionary plugins_dictionary = new Dictionary(); + + public PluginsManager() + { + AggregateCatalog catalog = new AggregateCatalog(); + catalog.Catalogs.Add(new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory)); + catalog.Catalogs.Add(new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins"))); + + //Контейнер композиции + CompositionContainer container = new CompositionContainer(catalog); + try + { + container.ComposeParts(this); + } + catch (CompositionException compositionException) + { + MessageBox.Show(compositionException.ToString()); + } + if (plugins.Any()) + { + plugins + .ToList() + .ForEach(p => + { + if (!plugins_dictionary.Keys.Contains(p.PluginName)) + plugins_dictionary.Add(p.PluginName, p); + }); + } + } + } +} \ No newline at end of file diff --git a/UniversityView/Program.cs b/UniversityView/Program.cs index bf2a326..21eec3d 100644 --- a/UniversityView/Program.cs +++ b/UniversityView/Program.cs @@ -1,7 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -using System; using UniversityBusinessLogic.BusinessLogics; using UniversityContracts.BusinessLogicsContracts; using UniversityContracts.StoragesContracts; @@ -21,7 +20,7 @@ namespace UniversityView var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(_serviceProvider.GetRequiredService()); } private static void ConfigureServices(ServiceCollection services) @@ -35,9 +34,9 @@ namespace UniversityView services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + //services.AddTransient(); + //services.AddTransient(); } } } \ No newline at end of file diff --git a/UniversityView/UniversityView.csproj b/UniversityView/UniversityView.csproj index 9198c2d..dbbabdf 100644 --- a/UniversityView/UniversityView.csproj +++ b/UniversityView/UniversityView.csproj @@ -18,11 +18,13 @@ + +