diff --git a/DepartmentPortal/Common/DatabaseCore/Migrations/20210327194001_ChangeSecurityFields.Designer.cs b/DepartmentPortal/Common/DatabaseCore/Migrations/20210327194001_ChangeSecurityFields.Designer.cs
new file mode 100644
index 0000000..755f5e4
--- /dev/null
+++ b/DepartmentPortal/Common/DatabaseCore/Migrations/20210327194001_ChangeSecurityFields.Designer.cs
@@ -0,0 +1,217 @@
+//
+using System;
+using DatabaseCore;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+namespace DatabaseCore.Migrations
+{
+ [DbContext(typeof(DatabaseContext))]
+ [Migration("20210327194001_ChangeSecurityFields")]
+ partial class ChangeSecurityFields
+ {
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("Relational:MaxIdentifierLength", 128)
+ .HasAnnotation("ProductVersion", "5.0.4")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ modelBuilder.Entity("DatabaseCore.Models.Security.Access", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("uniqueidentifier");
+
+ b.Property("AccessOperation")
+ .HasColumnType("int");
+
+ b.Property("AccessType")
+ .HasColumnType("int");
+
+ b.Property("DateCreate")
+ .HasColumnType("datetime2");
+
+ b.Property("DateDelete")
+ .HasColumnType("datetime2");
+
+ b.Property("IsDeleted")
+ .HasColumnType("bit");
+
+ b.Property("RoleId")
+ .HasColumnType("uniqueidentifier");
+
+ b.HasKey("Id");
+
+ b.HasIndex("RoleId");
+
+ b.ToTable("Accesses");
+ });
+
+ modelBuilder.Entity("DatabaseCore.Models.Security.EnviromentSetting", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("uniqueidentifier");
+
+ b.Property("Key")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Value")
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("EnviromentSettings");
+ });
+
+ modelBuilder.Entity("DatabaseCore.Models.Security.Role", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("uniqueidentifier");
+
+ b.Property("DateCreate")
+ .HasColumnType("datetime2");
+
+ b.Property("DateDelete")
+ .HasColumnType("datetime2");
+
+ b.Property("IsDeleted")
+ .HasColumnType("bit");
+
+ b.Property("RoleName")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("RolePriority")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.ToTable("Roles");
+ });
+
+ modelBuilder.Entity("DatabaseCore.Models.Security.User", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("uniqueidentifier");
+
+ b.Property("Avatar")
+ .HasColumnType("varbinary(max)");
+
+ b.Property("CountAttempt")
+ .HasColumnType("int");
+
+ b.Property("DateBanned")
+ .HasColumnType("datetime2");
+
+ b.Property("DateCreate")
+ .HasColumnType("datetime2");
+
+ b.Property("DateDelete")
+ .HasColumnType("datetime2");
+
+ b.Property("DateLastVisit")
+ .HasColumnType("datetime2");
+
+ b.Property("EmployeeId")
+ .HasColumnType("uniqueidentifier");
+
+ b.Property("IsBanned")
+ .HasColumnType("bit");
+
+ b.Property("IsDeleted")
+ .HasColumnType("bit");
+
+ b.Property("LecturerId")
+ .HasColumnType("uniqueidentifier");
+
+ b.Property("PasswordHash")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("StudentId")
+ .HasColumnType("uniqueidentifier");
+
+ b.Property("UserName")
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Users");
+ });
+
+ modelBuilder.Entity("DatabaseCore.Models.Security.UserRole", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("uniqueidentifier");
+
+ b.Property("DateCreate")
+ .HasColumnType("datetime2");
+
+ b.Property("DateDelete")
+ .HasColumnType("datetime2");
+
+ b.Property("IsDeleted")
+ .HasColumnType("bit");
+
+ b.Property("RoleId")
+ .HasColumnType("uniqueidentifier");
+
+ b.Property("UserId")
+ .HasColumnType("uniqueidentifier");
+
+ b.HasKey("Id");
+
+ b.HasIndex("RoleId");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("UserRoles");
+ });
+
+ modelBuilder.Entity("DatabaseCore.Models.Security.Access", b =>
+ {
+ b.HasOne("DatabaseCore.Models.Security.Role", "Role")
+ .WithMany("Access")
+ .HasForeignKey("RoleId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Role");
+ });
+
+ modelBuilder.Entity("DatabaseCore.Models.Security.UserRole", b =>
+ {
+ b.HasOne("DatabaseCore.Models.Security.Role", "Role")
+ .WithMany("UserRoles")
+ .HasForeignKey("RoleId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("DatabaseCore.Models.Security.User", "User")
+ .WithMany("UserRoles")
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Role");
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("DatabaseCore.Models.Security.Role", b =>
+ {
+ b.Navigation("Access");
+
+ b.Navigation("UserRoles");
+ });
+
+ modelBuilder.Entity("DatabaseCore.Models.Security.User", b =>
+ {
+ b.Navigation("UserRoles");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/DepartmentPortal/Common/DatabaseCore/Migrations/20210327194001_ChangeSecurityFields.cs b/DepartmentPortal/Common/DatabaseCore/Migrations/20210327194001_ChangeSecurityFields.cs
new file mode 100644
index 0000000..4b37ee3
--- /dev/null
+++ b/DepartmentPortal/Common/DatabaseCore/Migrations/20210327194001_ChangeSecurityFields.cs
@@ -0,0 +1,66 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace DatabaseCore.Migrations
+{
+ public partial class ChangeSecurityFields : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropColumn(
+ name: "DateLocked",
+ table: "Users");
+
+ migrationBuilder.RenameColumn(
+ name: "Operation",
+ table: "Accesses",
+ newName: "AccessOperation");
+
+ migrationBuilder.AddColumn(
+ name: "DateCreate",
+ table: "UserRoles",
+ type: "datetime2",
+ nullable: false,
+ defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
+
+ migrationBuilder.AddColumn(
+ name: "DateDelete",
+ table: "UserRoles",
+ type: "datetime2",
+ nullable: true);
+
+ migrationBuilder.AddColumn(
+ name: "IsDeleted",
+ table: "UserRoles",
+ type: "bit",
+ nullable: false,
+ defaultValue: false);
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropColumn(
+ name: "DateCreate",
+ table: "UserRoles");
+
+ migrationBuilder.DropColumn(
+ name: "DateDelete",
+ table: "UserRoles");
+
+ migrationBuilder.DropColumn(
+ name: "IsDeleted",
+ table: "UserRoles");
+
+ migrationBuilder.RenameColumn(
+ name: "AccessOperation",
+ table: "Accesses",
+ newName: "Operation");
+
+ migrationBuilder.AddColumn(
+ name: "DateLocked",
+ table: "Users",
+ type: "datetime2",
+ nullable: true);
+ }
+ }
+}
diff --git a/DepartmentPortal/Common/DatabaseCore/Migrations/DatabaseContextModelSnapshot.cs b/DepartmentPortal/Common/DatabaseCore/Migrations/DatabaseContextModelSnapshot.cs
index fe854ca..00acc4a 100644
--- a/DepartmentPortal/Common/DatabaseCore/Migrations/DatabaseContextModelSnapshot.cs
+++ b/DepartmentPortal/Common/DatabaseCore/Migrations/DatabaseContextModelSnapshot.cs
@@ -24,6 +24,9 @@ namespace DatabaseCore.Migrations
b.Property("Id")
.HasColumnType("uniqueidentifier");
+ b.Property("AccessOperation")
+ .HasColumnType("int");
+
b.Property("AccessType")
.HasColumnType("int");
@@ -36,9 +39,6 @@ namespace DatabaseCore.Migrations
b.Property("IsDeleted")
.HasColumnType("bit");
- b.Property("Operation")
- .HasColumnType("int");
-
b.Property("RoleId")
.HasColumnType("uniqueidentifier");
@@ -113,9 +113,6 @@ namespace DatabaseCore.Migrations
b.Property("DateLastVisit")
.HasColumnType("datetime2");
- b.Property("DateLocked")
- .HasColumnType("datetime2");
-
b.Property("EmployeeId")
.HasColumnType("uniqueidentifier");
@@ -147,6 +144,15 @@ namespace DatabaseCore.Migrations
b.Property("Id")
.HasColumnType("uniqueidentifier");
+ b.Property("DateCreate")
+ .HasColumnType("datetime2");
+
+ b.Property("DateDelete")
+ .HasColumnType("datetime2");
+
+ b.Property("IsDeleted")
+ .HasColumnType("bit");
+
b.Property("RoleId")
.HasColumnType("uniqueidentifier");
diff --git a/DepartmentPortal/Common/DatabaseCore/Models/Security/Access.cs b/DepartmentPortal/Common/DatabaseCore/Models/Security/Access.cs
index c4a0b5c..aa77122 100644
--- a/DepartmentPortal/Common/DatabaseCore/Models/Security/Access.cs
+++ b/DepartmentPortal/Common/DatabaseCore/Models/Security/Access.cs
@@ -22,7 +22,7 @@ namespace DatabaseCore.Models.Security
[Required]
[DataMember]
[MapConfiguration("Operation")]
- public AccessOperation Operation { get; set; }
+ public AccessOperation AccessOperation { get; set; }
[Required]
[DataMember]
diff --git a/DepartmentPortal/Common/DatabaseCore/SecurityManager.cs b/DepartmentPortal/Common/DatabaseCore/SecurityManager.cs
index 2ed76c5..e31ad93 100644
--- a/DepartmentPortal/Common/DatabaseCore/SecurityManager.cs
+++ b/DepartmentPortal/Common/DatabaseCore/SecurityManager.cs
@@ -1,7 +1,7 @@
using DatabaseCore.Models.Security;
-using ModelTools.BindingModels;
using ModelTools.Enums;
using ModelTools.Interfaces;
+using ModelTools.Models;
using SecurityBusinessLogic.BusinessLogics;
using System.Linq;
@@ -11,52 +11,52 @@ namespace DatabaseCore
{
public string ErrorMessage { get; set; }
- public bool CheckAccess(AccessBindingModel model, AccessOperation operation, AccessType type, string entity)
+ public bool CheckAccess(SecurityManagerCheckAccessModel model)
{
using var context = DatabaseManager.GetContext;
Access access;
if (model != null)
{
// простой просмотр возможен
- if (model.SkipCheck && type == AccessType.SimpleView)
+ if (model.Model.SkipCheck && model.Type == AccessType.SimpleView)
{
return true;
}
// если не указан идентификатор пользователя, то смотрим, может он авторизован
- if (!model.UserId.HasValue && UserManager.GetInstance.User != null)
+ if (!model.Model.UserId.HasValue && UserManager.GetInstance.User != null)
{
- model.UserId = UserManager.GetInstance.UserId;
+ model.Model.UserId = UserManager.GetInstance.UserId;
}
- var roles = context.UserRoles.Where(x => x.UserId == model.UserId).Select(x => x.Role).OrderByDescending(x => x.RolePriority).ToList();
+ var roles = context.UserRoles.Where(x => x.UserId == model.Model.UserId).Select(x => x.Role).OrderByDescending(x => x.RolePriority).ToList();
if (roles == null)
{
ErrorMessage = $"Не верный пользователь";
return false;
}
- access = context.Accesses.FirstOrDefault(a => a.Operation == operation && roles.Contains(a.Role));
+ access = context.Accesses.FirstOrDefault(a => a.AccessOperation == model.Operation && roles.Contains(a.Role));
}
else
{
- access = context.Accesses.FirstOrDefault(a => a.Operation == operation && UserManager.GetInstance.Roles.Contains(a.RoleId));
+ access = context.Accesses.FirstOrDefault(a => a.AccessOperation == model.Operation && UserManager.GetInstance.Roles.Contains(a.RoleId));
}
if (access != null)
{
- if (access.AccessType >= type) return true;
+ if (access.AccessType >= model.Type) return true;
}
- switch (type)
+ switch (model.Type)
{
case AccessType.FullView:
- ErrorMessage = $"Нет доступа на чтение данных по сущности '{entity}'";
+ ErrorMessage = $"Нет доступа на чтение данных по сущности '{model.Entity}'";
return false;
case AccessType.Change:
- ErrorMessage = $"Нет доступа на изменение данных по сущности '{entity}'";
+ ErrorMessage = $"Нет доступа на изменение данных по сущности '{model.Entity}'";
return false;
case AccessType.Delete:
- ErrorMessage = $"Нет доступа на удаление данных по сущности '{entity}'";
+ ErrorMessage = $"Нет доступа на удаление данных по сущности '{model.Entity}'";
return false;
default:
- ErrorMessage = $"Нет доступа по сущности '{entity}'";
+ ErrorMessage = $"Нет доступа по сущности '{model.Entity}'";
return false;
}
}
diff --git a/DepartmentPortal/Common/DesktopTools/Controls/AbstractGenerticControlEntityList.Designer.cs b/DepartmentPortal/Common/DesktopTools/Controls/AbstractGenerticControlEntityList.Designer.cs
new file mode 100644
index 0000000..1e33f0d
--- /dev/null
+++ b/DepartmentPortal/Common/DesktopTools/Controls/AbstractGenerticControlEntityList.Designer.cs
@@ -0,0 +1,330 @@
+namespace DesktopTools.Controls
+{
+ partial class AbstractGenerticControlEntityList
+ {
+ ///
+ /// Освободить все используемые ресурсы.
+ ///
+ /// истинно, если управляемый ресурс должен быть удален; иначе ложно.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Код, автоматически созданный конструктором компонентов
+
+ ///
+ /// Требуемый метод для поддержки конструктора — не изменяйте
+ /// содержимое этого метода с помощью редактора кода.
+ ///
+ private void InitializeComponent()
+ {
+ this.components = new System.ComponentModel.Container();
+ this.toolStripMenu = new System.Windows.Forms.ToolStrip();
+ this.toolStripButtonAdd = new System.Windows.Forms.ToolStripButton();
+ this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
+ this.toolStripButtonUpd = new System.Windows.Forms.ToolStripButton();
+ this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
+ this.toolStripButtonDel = new System.Windows.Forms.ToolStripButton();
+ this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
+ this.toolStripButtonSearch = new System.Windows.Forms.ToolStripButton();
+ this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
+ this.toolStripButtonRef = new System.Windows.Forms.ToolStripButton();
+ this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
+ this.toolStripSplitButtonActions = new System.Windows.Forms.ToolStripSplitButton();
+ this.toolStripButtonClose = new System.Windows.Forms.ToolStripButton();
+ this.panelSearch = new System.Windows.Forms.Panel();
+ this.buttonCancelSearch = new System.Windows.Forms.Button();
+ this.buttonSearch = new System.Windows.Forms.Button();
+ this.toolStripFooter = new System.Windows.Forms.ToolStrip();
+ this.toolStripButtonPrev = new System.Windows.Forms.ToolStripButton();
+ this.toolStripLabelPage = new System.Windows.Forms.ToolStripLabel();
+ this.toolStripTextBoxPage = new System.Windows.Forms.ToolStripTextBox();
+ this.toolStripLabelCountPages = new System.Windows.Forms.ToolStripLabel();
+ this.toolStripButtonNext = new System.Windows.Forms.ToolStripButton();
+ this.toolStripLabelPageName = new System.Windows.Forms.ToolStripLabel();
+ this.toolStripComboBoxPageNames = new System.Windows.Forms.ToolStripComboBox();
+ this.contextMenuStripDataGrid = new System.Windows.Forms.ContextMenuStrip(this.components);
+ this.dataGridViewList = new System.Windows.Forms.DataGridView();
+ this.toolStripMenu.SuspendLayout();
+ this.panelSearch.SuspendLayout();
+ this.toolStripFooter.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridViewList)).BeginInit();
+ this.SuspendLayout();
+ //
+ // toolStripMenu
+ //
+ this.toolStripMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripButtonAdd,
+ this.toolStripSeparator1,
+ this.toolStripButtonUpd,
+ this.toolStripSeparator2,
+ this.toolStripButtonDel,
+ this.toolStripSeparator3,
+ this.toolStripButtonSearch,
+ this.toolStripSeparator4,
+ this.toolStripButtonRef,
+ this.toolStripSeparator5,
+ this.toolStripSplitButtonActions,
+ this.toolStripButtonClose});
+ this.toolStripMenu.Location = new System.Drawing.Point(0, 0);
+ this.toolStripMenu.Name = "toolStripMenu";
+ this.toolStripMenu.Size = new System.Drawing.Size(1000, 25);
+ this.toolStripMenu.TabIndex = 0;
+ this.toolStripMenu.Text = "Главное меню";
+ //
+ // toolStripButtonAdd
+ //
+ this.toolStripButtonAdd.Image = global::DesktopTools.Properties.Resources.Add;
+ this.toolStripButtonAdd.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.toolStripButtonAdd.Name = "toolStripButtonAdd";
+ this.toolStripButtonAdd.Size = new System.Drawing.Size(79, 22);
+ this.toolStripButtonAdd.Text = "Добавить";
+ //
+ // toolStripSeparator1
+ //
+ this.toolStripSeparator1.Name = "toolStripSeparator1";
+ this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
+ //
+ // toolStripButtonUpd
+ //
+ this.toolStripButtonUpd.Image = global::DesktopTools.Properties.Resources.Upd;
+ this.toolStripButtonUpd.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.toolStripButtonUpd.Name = "toolStripButtonUpd";
+ this.toolStripButtonUpd.Size = new System.Drawing.Size(81, 22);
+ this.toolStripButtonUpd.Text = "Изменить";
+ //
+ // toolStripSeparator2
+ //
+ this.toolStripSeparator2.Name = "toolStripSeparator2";
+ this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25);
+ //
+ // toolStripButtonDel
+ //
+ this.toolStripButtonDel.Image = global::DesktopTools.Properties.Resources.Del;
+ this.toolStripButtonDel.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.toolStripButtonDel.Name = "toolStripButtonDel";
+ this.toolStripButtonDel.Size = new System.Drawing.Size(71, 22);
+ this.toolStripButtonDel.Text = "Удалить";
+ //
+ // toolStripSeparator3
+ //
+ this.toolStripSeparator3.Name = "toolStripSeparator3";
+ this.toolStripSeparator3.Size = new System.Drawing.Size(6, 25);
+ //
+ // toolStripButtonSearch
+ //
+ this.toolStripButtonSearch.Image = global::DesktopTools.Properties.Resources.Search;
+ this.toolStripButtonSearch.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.toolStripButtonSearch.Name = "toolStripButtonSearch";
+ this.toolStripButtonSearch.Size = new System.Drawing.Size(62, 22);
+ this.toolStripButtonSearch.Text = "Поиск";
+ //
+ // toolStripSeparator4
+ //
+ this.toolStripSeparator4.Name = "toolStripSeparator4";
+ this.toolStripSeparator4.Size = new System.Drawing.Size(6, 25);
+ //
+ // toolStripButtonRef
+ //
+ this.toolStripButtonRef.Image = global::DesktopTools.Properties.Resources.Ref;
+ this.toolStripButtonRef.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.toolStripButtonRef.Name = "toolStripButtonRef";
+ this.toolStripButtonRef.Size = new System.Drawing.Size(81, 22);
+ this.toolStripButtonRef.Text = "Обновить";
+ //
+ // toolStripSeparator5
+ //
+ this.toolStripSeparator5.Name = "toolStripSeparator5";
+ this.toolStripSeparator5.Size = new System.Drawing.Size(6, 25);
+ //
+ // toolStripSplitButtonActions
+ //
+ this.toolStripSplitButtonActions.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
+ this.toolStripSplitButtonActions.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.toolStripSplitButtonActions.Name = "toolStripSplitButtonActions";
+ this.toolStripSplitButtonActions.Size = new System.Drawing.Size(74, 22);
+ this.toolStripSplitButtonActions.Text = "Действия";
+ //
+ // toolStripButtonClose
+ //
+ this.toolStripButtonClose.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
+ this.toolStripButtonClose.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+ this.toolStripButtonClose.Image = global::DesktopTools.Properties.Resources.Close;
+ this.toolStripButtonClose.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.toolStripButtonClose.Name = "toolStripButtonClose";
+ this.toolStripButtonClose.Size = new System.Drawing.Size(23, 22);
+ this.toolStripButtonClose.Text = "Закрть";
+ //
+ // panelSearch
+ //
+ this.panelSearch.Controls.Add(this.buttonCancelSearch);
+ this.panelSearch.Controls.Add(this.buttonSearch);
+ this.panelSearch.Dock = System.Windows.Forms.DockStyle.Top;
+ this.panelSearch.Location = new System.Drawing.Point(0, 25);
+ this.panelSearch.Name = "panelSearch";
+ this.panelSearch.Size = new System.Drawing.Size(1000, 87);
+ this.panelSearch.TabIndex = 1;
+ this.panelSearch.Visible = false;
+ //
+ // buttonCancelSearch
+ //
+ this.buttonCancelSearch.Location = new System.Drawing.Point(11, 47);
+ this.buttonCancelSearch.Name = "buttonCancelSearch";
+ this.buttonCancelSearch.Size = new System.Drawing.Size(89, 24);
+ this.buttonCancelSearch.TabIndex = 1;
+ this.buttonCancelSearch.Text = "Скрыть";
+ this.buttonCancelSearch.UseVisualStyleBackColor = true;
+ //
+ // buttonSearch
+ //
+ this.buttonSearch.Location = new System.Drawing.Point(11, 13);
+ this.buttonSearch.Name = "buttonSearch";
+ this.buttonSearch.Size = new System.Drawing.Size(89, 24);
+ this.buttonSearch.TabIndex = 0;
+ this.buttonSearch.Text = "Запуск";
+ this.buttonSearch.UseVisualStyleBackColor = true;
+ //
+ // toolStripFooter
+ //
+ this.toolStripFooter.Dock = System.Windows.Forms.DockStyle.Bottom;
+ this.toolStripFooter.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripButtonPrev,
+ this.toolStripLabelPage,
+ this.toolStripTextBoxPage,
+ this.toolStripLabelCountPages,
+ this.toolStripButtonNext,
+ this.toolStripLabelPageName,
+ this.toolStripComboBoxPageNames});
+ this.toolStripFooter.Location = new System.Drawing.Point(0, 775);
+ this.toolStripFooter.Name = "toolStripFooter";
+ this.toolStripFooter.Size = new System.Drawing.Size(1000, 25);
+ this.toolStripFooter.TabIndex = 2;
+ this.toolStripFooter.Text = "Пагинация";
+ //
+ // toolStripButtonPrev
+ //
+ this.toolStripButtonPrev.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+ this.toolStripButtonPrev.Image = global::DesktopTools.Properties.Resources.Left;
+ this.toolStripButtonPrev.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.toolStripButtonPrev.Name = "toolStripButtonPrev";
+ this.toolStripButtonPrev.Size = new System.Drawing.Size(23, 22);
+ this.toolStripButtonPrev.Text = "Назад";
+ //
+ // toolStripLabelPage
+ //
+ this.toolStripLabelPage.Name = "toolStripLabelPage";
+ this.toolStripLabelPage.Size = new System.Drawing.Size(60, 22);
+ this.toolStripLabelPage.Text = "Страница";
+ //
+ // toolStripTextBoxPage
+ //
+ this.toolStripTextBoxPage.Name = "toolStripTextBoxPage";
+ this.toolStripTextBoxPage.Size = new System.Drawing.Size(30, 25);
+ this.toolStripTextBoxPage.Text = "1";
+ //
+ // toolStripLabelCountPages
+ //
+ this.toolStripLabelCountPages.Name = "toolStripLabelCountPages";
+ this.toolStripLabelCountPages.Size = new System.Drawing.Size(28, 22);
+ this.toolStripLabelCountPages.Text = "из 0";
+ //
+ // toolStripButtonNext
+ //
+ this.toolStripButtonNext.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
+ this.toolStripButtonNext.Image = global::DesktopTools.Properties.Resources.Right;
+ this.toolStripButtonNext.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.toolStripButtonNext.Name = "toolStripButtonNext";
+ this.toolStripButtonNext.Size = new System.Drawing.Size(23, 22);
+ this.toolStripButtonNext.Text = "Вперед";
+ //
+ // toolStripLabelPageName
+ //
+ this.toolStripLabelPageName.Name = "toolStripLabelPageName";
+ this.toolStripLabelPageName.Size = new System.Drawing.Size(62, 22);
+ this.toolStripLabelPageName.Text = "Параметр";
+ //
+ // toolStripComboBoxPageNames
+ //
+ this.toolStripComboBoxPageNames.Name = "toolStripComboBoxPageNames";
+ this.toolStripComboBoxPageNames.Size = new System.Drawing.Size(200, 25);
+ this.toolStripComboBoxPageNames.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ //
+ // contextMenuStripDataGrid
+ //
+ this.contextMenuStripDataGrid.Name = "contextMenuStripDataGrid";
+ this.contextMenuStripDataGrid.Size = new System.Drawing.Size(61, 4);
+ //
+ // dataGridViewList
+ //
+ this.dataGridViewList.AllowUserToAddRows = false;
+ this.dataGridViewList.AllowUserToDeleteRows = false;
+ this.dataGridViewList.AllowUserToResizeRows = false;
+ this.dataGridViewList.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
+ this.dataGridViewList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridViewList.ContextMenuStrip = this.contextMenuStripDataGrid;
+ this.dataGridViewList.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.dataGridViewList.Location = new System.Drawing.Point(0, 112);
+ this.dataGridViewList.Name = "dataGridViewList";
+ this.dataGridViewList.ReadOnly = true;
+ this.dataGridViewList.RowHeadersVisible = false;
+ this.dataGridViewList.RowTemplate.Height = 25;
+ this.dataGridViewList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
+ this.dataGridViewList.Size = new System.Drawing.Size(1000, 663);
+ this.dataGridViewList.TabIndex = 3;
+ //
+ // AbstractControlEntityList
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.dataGridViewList);
+ this.Controls.Add(this.toolStripFooter);
+ this.Controls.Add(this.panelSearch);
+ this.Controls.Add(this.toolStripMenu);
+ this.Name = "AbstractControlEntityList";
+ this.Size = new System.Drawing.Size(1000, 800);
+ this.toolStripMenu.ResumeLayout(false);
+ this.toolStripMenu.PerformLayout();
+ this.panelSearch.ResumeLayout(false);
+ this.toolStripFooter.ResumeLayout(false);
+ this.toolStripFooter.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridViewList)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.ToolStrip toolStripMenu;
+ private System.Windows.Forms.ToolStripButton toolStripButtonAdd;
+ private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
+ private System.Windows.Forms.ToolStripButton toolStripButtonUpd;
+ private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
+ private System.Windows.Forms.ToolStripButton toolStripButtonDel;
+ private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
+ private System.Windows.Forms.ToolStripButton toolStripButtonSearch;
+ private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
+ private System.Windows.Forms.ToolStripButton toolStripButtonRef;
+ private System.Windows.Forms.ToolStripSeparator toolStripSeparator5;
+ private System.Windows.Forms.ToolStripSplitButton toolStripSplitButtonActions;
+ private System.Windows.Forms.ToolStripButton toolStripButtonClose;
+ protected System.Windows.Forms.Panel panelSearch;
+ private System.Windows.Forms.Button buttonCancelSearch;
+ private System.Windows.Forms.Button buttonSearch;
+ private System.Windows.Forms.ToolStrip toolStripFooter;
+ private System.Windows.Forms.ToolStripButton toolStripButtonPrev;
+ private System.Windows.Forms.ToolStripLabel toolStripLabelPage;
+ private System.Windows.Forms.ToolStripTextBox toolStripTextBoxPage;
+ private System.Windows.Forms.ToolStripLabel toolStripLabelCountPages;
+ private System.Windows.Forms.ToolStripButton toolStripButtonNext;
+ private System.Windows.Forms.ToolStripLabel toolStripLabelPageName;
+ private System.Windows.Forms.ToolStripComboBox toolStripComboBoxPageNames;
+ private System.Windows.Forms.ContextMenuStrip contextMenuStripDataGrid;
+ private System.Windows.Forms.DataGridView dataGridViewList;
+ }
+}
diff --git a/DepartmentPortal/Common/DesktopTools/Controls/AbstractGenerticControlEntityList.cs b/DepartmentPortal/Common/DesktopTools/Controls/AbstractGenerticControlEntityList.cs
new file mode 100644
index 0000000..f96e77a
--- /dev/null
+++ b/DepartmentPortal/Common/DesktopTools/Controls/AbstractGenerticControlEntityList.cs
@@ -0,0 +1,333 @@
+using DesktopTools.Models;
+using ModelTools.Attributes;
+using ModelTools.BindingModels;
+using ModelTools.BusinessLogics;
+using ModelTools.Extensions;
+using ModelTools.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Windows.Forms;
+
+namespace DesktopTools.Controls
+{
+ public partial class AbstractGenerticControlEntityList : ControlViewEntityList
+ where G : GetBindingModel
+ where S : SetBindingModel
+ where L: ListViewModel
+ where E : ElementViewModel
+ where BL : BusinessLogicCore
+ {
+ ///
+ /// Объект бизнес-логики для получения данных
+ ///
+ protected BL _businessLogic;
+
+ ///
+ /// Констркутор
+ ///
+ public AbstractGenerticControlEntityList()
+ {
+ InitializeComponent();
+ InitEvents();
+ }
+
+ public override void Open()
+ {
+ base.Open();
+ if (dataGridViewList.Columns.Count == 0)
+ {
+ Configurate(GetConfig());
+ }
+ LoadList();
+ }
+
+ public override void Close()
+ {
+ base.Close();
+ }
+
+ ///
+ /// Конфигуратор контрола
+ ///
+ /// Настройки
+ private void Configurate(ControlViewEntityListConfiguration config)
+ {
+ if(config == null)
+ {
+ return;
+ }
+ // формирование таблицы на основе модели
+ dataGridViewList.Columns.Clear();
+ var properties = typeof(E).GetProperties();
+ foreach (var property in properties)
+ {
+ var attr = property.GetCustomAttribute();
+ if (attr != null)
+ {
+ dataGridViewList.Columns.Add(new DataGridViewTextBoxColumn
+ {
+ HeaderText = attr.DisplayName,
+ Name = string.Format("Column{0}", property.Name),
+ ReadOnly = true,
+ Visible = !attr.IsHide,
+ Width = attr.ColumnWidth ?? 0,
+ AutoSizeMode = attr.ColumnWidth.HasValue ? DataGridViewAutoSizeColumnMode.None : DataGridViewAutoSizeColumnMode.Fill
+ });
+ }
+ }
+ // настройка отображения основных кнопок
+ if (config.ShowToolStripButton != null)
+ {
+ foreach (ToolStripItem button in toolStripMenu.Items)
+ {
+ if (config.ShowToolStripButton.Contains(button.Name))
+ {
+ button.Visible = false;
+ switch (button.Name)
+ {
+ case "toolStripButtonUpd":
+ toolStripSeparator1.Visible = false;
+ break;
+ case "toolStripButtonDel":
+ toolStripSeparator2.Visible = false;
+ break;
+ case "toolStripButtonRef":
+ toolStripSeparator3.Visible = false;
+ break;
+ case "toolStripButtonSearch":
+ toolStripSeparator4.Visible = false;
+ break;
+ }
+ }
+ }
+ }
+ // Загрузка подпунктов в контекстное меню и в пункт меню "Действие"
+ if (config.ControlOnMoveElem != null)
+ {
+ foreach (var elem in config.ControlOnMoveElem)
+ {
+ ToolStripMenuItem item = new() { Text = elem.Value.Title, Name = elem.Key };
+ item.Click += elem.Value.Event;
+ toolStripSplitButtonActions.DropDownItems.Add(item);
+ contextMenuStripDataGrid.Items.Add(item);
+ }
+ }
+ // либо скрытие пункта, если не предусмотренно подпунктов
+ else
+ {
+ toolStripSplitButtonActions.Visible = false;
+ toolStripSeparator3.Visible = false;
+ }
+
+ // Пагинация
+ if (config.PaginationOn)
+ {
+ if (config.CountElementsOnPage.HasValue)
+ {
+ toolStripTextBoxPage.Tag = config.CountElementsOnPage.Value;
+ }
+ // пагинация по названиям
+ if (config.PageNamesForPagination != null)
+ {
+ toolStripButtonPrev.Visible = toolStripLabelPage.Visible = toolStripTextBoxPage.Visible = toolStripLabelCountPages.Visible =
+ toolStripButtonNext.Visible = false;
+ toolStripComboBoxPageNames.Items.AddRange(config.PageNamesForPagination.ToArray());
+ toolStripComboBoxPageNames.SelectedIndex = 0;
+ }
+ // пагинация по страницам
+ else
+ {
+ toolStripLabelPageName.Visible = toolStripComboBoxPageNames.Visible = false;
+ }
+ }
+ // нет пагинации
+ else
+ {
+ toolStripFooter.Visible = false;
+ }
+ }
+
+ ///
+ /// Инициализация событий к контролам
+ ///
+ private void InitEvents()
+ {
+ toolStripButtonAdd.Click += (object sender, EventArgs e) => { CallAddElementEvent(); };
+ toolStripButtonUpd.Click += (object sender, EventArgs e) => { CallUpdElementEvent(); };
+ toolStripButtonDel.Click += (object sender, EventArgs e) => { CallDelElementEvent(); };
+ toolStripButtonSearch.Click += (object sender, EventArgs e) => { panelSearch.Visible = !panelSearch.Visible; };
+ toolStripButtonRef.Click += (object sender, EventArgs e) => { LoadList(); };
+ toolStripButtonClose.Click += (object sender, EventArgs e) => { Close(); };
+
+ buttonSearch.Click += (object sender, EventArgs e) => { LoadList(); };
+ buttonCancelSearch.Click += (object sender, EventArgs e) => { panelSearch.Visible = false; };
+
+ dataGridViewList.KeyDown += (object sender, KeyEventArgs e) =>
+ {
+ switch (e.KeyCode)
+ {
+ case Keys.Insert:
+ CallAddElementEvent();
+ break;
+ case Keys.Enter:
+ CallUpdElementEvent();
+ break;
+ case Keys.Delete:
+ CallDelElementEvent();
+ break;
+ }
+ };
+ dataGridViewList.CellDoubleClick += (object sender, DataGridViewCellEventArgs e) =>
+ {
+ CallUpdElementEvent();
+ };
+
+ toolStripButtonPrev.Click += (object sender, EventArgs e) =>
+ {
+ if (int.TryParse(toolStripTextBoxPage.Text, out int page))
+ {
+ toolStripTextBoxPage.Text = (page - 1).ToString();
+ LoadList();
+ }
+ };
+ toolStripButtonNext.Click += (object sender, EventArgs e) =>
+ {
+ if (int.TryParse(toolStripTextBoxPage.Text, out int page))
+ {
+ toolStripTextBoxPage.Text = (page + 1).ToString();
+ LoadList();
+ }
+ };
+ toolStripTextBoxPage.KeyDown += (object sender, KeyEventArgs e) =>
+ {
+ if (e.KeyData == Keys.Enter)
+ {
+ LoadList();
+ }
+ };
+
+ toolStripComboBoxPageNames.SelectedIndexChanged += (object sender, EventArgs e) => { LoadList(); };
+ }
+
+ ///
+ /// Вызов события загрузки данных на datagrid
+ ///
+ private void LoadList()
+ {
+ var cursor = Cursor.Current;
+ L data = null;
+ try
+ {
+ Cursor.Current = Cursors.WaitCursor;
+ // если включена пагинация
+ if (toolStripFooter.Visible)
+ {
+ // постраничная
+ if (toolStripTextBoxPage.Visible)
+ {
+ if (int.TryParse(toolStripTextBoxPage.Text, out int page) && int.TryParse(toolStripTextBoxPage.Tag.ToString(), out int count))
+ {
+ data = GetDataWithPageNumber(page, count);
+ }
+ }
+ // поименная
+ else if (toolStripComboBoxPageNames.Visible)
+ {
+ var key = toolStripComboBoxPageNames.Text;
+ if (key.IsNotEmpty())
+ {
+ data = GetDataWithPageName(key);
+ }
+ }
+ }
+ else
+ {
+ data = GetData();
+ }
+
+ if (data == null)
+ {
+ // TODO вывод сообщения об ощибок
+ return;
+ }
+
+ toolStripLabelCountPages.Text = $"из {data.MaxCount}";
+ FillDataOnGrid(data.List);
+ }
+ finally
+ {
+ Cursor.Current = cursor;
+ }
+ }
+
+ ///
+ /// Заполнение таблицы
+ ///
+ ///
+ private void FillDataOnGrid(List data)
+ {
+ if (data == null)
+ {
+ return;
+ }
+ dataGridViewList.Rows.Clear();
+ foreach (var elem in data)
+ {
+ var mas = new List