diff --git a/COP/PortalAccountsDatabaseImplement/Migrations/20241022165136_InitialCreate.Designer.cs b/COP/PortalAccountsDatabaseImplement/Migrations/20241022165136_InitialCreate.Designer.cs new file mode 100644 index 0000000..77aeb79 --- /dev/null +++ b/COP/PortalAccountsDatabaseImplement/Migrations/20241022165136_InitialCreate.Designer.cs @@ -0,0 +1,91 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using PortalAccountsDatabaseImplement; + +#nullable disable + +namespace PortalAccountsDatabaseImplement.Migrations +{ + [DbContext(typeof(PortalAccountsDatabase))] + [Migration("20241022165136_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("PortalAccountsDatabaseImplement.Models.Account", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Rating") + .HasColumnType("double precision"); + + b.Property("RoleId") + .HasColumnType("integer"); + + b.Property("Warnings") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("Accounts"); + }); + + modelBuilder.Entity("PortalAccountsDatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("PortalAccountsDatabaseImplement.Models.Account", b => + { + b.HasOne("PortalAccountsDatabaseImplement.Models.Role", "Role") + .WithMany("Accounts") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("PortalAccountsDatabaseImplement.Models.Role", b => + { + b.Navigation("Accounts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/COP/PortalAccountsDatabaseImplement/Migrations/20241022165136_InitialCreate.cs b/COP/PortalAccountsDatabaseImplement/Migrations/20241022165136_InitialCreate.cs new file mode 100644 index 0000000..756d6ae --- /dev/null +++ b/COP/PortalAccountsDatabaseImplement/Migrations/20241022165136_InitialCreate.cs @@ -0,0 +1,65 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace PortalAccountsDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Roles", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Roles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Accounts", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Login = table.Column(type: "text", nullable: false), + Warnings = table.Column(type: "text", nullable: true), + RoleId = table.Column(type: "integer", nullable: false), + Rating = table.Column(type: "double precision", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Accounts", x => x.Id); + table.ForeignKey( + name: "FK_Accounts_Roles_RoleId", + column: x => x.RoleId, + principalTable: "Roles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Accounts_RoleId", + table: "Accounts", + column: "RoleId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Accounts"); + + migrationBuilder.DropTable( + name: "Roles"); + } + } +} diff --git a/COP/PortalAccountsDatabaseImplement/Migrations/PortalAccountsDatabaseModelSnapshot.cs b/COP/PortalAccountsDatabaseImplement/Migrations/PortalAccountsDatabaseModelSnapshot.cs new file mode 100644 index 0000000..9df3f52 --- /dev/null +++ b/COP/PortalAccountsDatabaseImplement/Migrations/PortalAccountsDatabaseModelSnapshot.cs @@ -0,0 +1,88 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using PortalAccountsDatabaseImplement; + +#nullable disable + +namespace PortalAccountsDatabaseImplement.Migrations +{ + [DbContext(typeof(PortalAccountsDatabase))] + partial class PortalAccountsDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("PortalAccountsDatabaseImplement.Models.Account", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Rating") + .HasColumnType("double precision"); + + b.Property("RoleId") + .HasColumnType("integer"); + + b.Property("Warnings") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("Accounts"); + }); + + modelBuilder.Entity("PortalAccountsDatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("PortalAccountsDatabaseImplement.Models.Account", b => + { + b.HasOne("PortalAccountsDatabaseImplement.Models.Role", "Role") + .WithMany("Accounts") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("PortalAccountsDatabaseImplement.Models.Role", b => + { + b.Navigation("Accounts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/COP/PortalAccountsView/FormAccount.Designer.cs b/COP/PortalAccountsView/FormAccount.Designer.cs index 9d7854d..d6a3f72 100644 --- a/COP/PortalAccountsView/FormAccount.Designer.cs +++ b/COP/PortalAccountsView/FormAccount.Designer.cs @@ -43,39 +43,36 @@ // controlInputRating // controlInputRating.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - controlInputRating.Location = new Point(8, 197); - controlInputRating.Margin = new Padding(4, 6, 4, 6); + controlInputRating.Location = new Point(9, 263); + controlInputRating.Margin = new Padding(5, 8, 5, 8); controlInputRating.Name = "controlInputRating"; - controlInputRating.Size = new Size(329, 27); + controlInputRating.Size = new Size(376, 36); controlInputRating.TabIndex = 0; controlInputRating.Value = null; // // textBoxLogin // textBoxLogin.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - textBoxLogin.Location = new Point(15, 86); - textBoxLogin.Margin = new Padding(3, 2, 3, 2); + textBoxLogin.Location = new Point(17, 115); textBoxLogin.Name = "textBoxLogin"; - textBoxLogin.Size = new Size(323, 23); + textBoxLogin.Size = new Size(369, 27); textBoxLogin.TabIndex = 2; textBoxLogin.TextChanged += TextBoxLogin_TextChanged; // // textBoxWarnings // textBoxWarnings.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - textBoxWarnings.Location = new Point(15, 143); - textBoxWarnings.Margin = new Padding(3, 2, 3, 2); + textBoxWarnings.Location = new Point(17, 191); textBoxWarnings.Name = "textBoxWarnings"; - textBoxWarnings.Size = new Size(323, 23); + textBoxWarnings.Size = new Size(369, 27); textBoxWarnings.TabIndex = 3; textBoxWarnings.TextChanged += TextBoxWarnings_TextChanged; // // buttonSave // - buttonSave.Location = new Point(25, 232); - buttonSave.Margin = new Padding(3, 2, 3, 2); + buttonSave.Location = new Point(29, 309); buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(92, 27); + buttonSave.Size = new Size(105, 36); buttonSave.TabIndex = 8; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; @@ -84,55 +81,54 @@ // labelLogin // labelLogin.AutoSize = true; - labelLogin.Location = new Point(15, 64); + labelLogin.Location = new Point(17, 85); labelLogin.Name = "labelLogin"; - labelLogin.Size = new Size(41, 15); + labelLogin.Size = new Size(52, 20); labelLogin.TabIndex = 4; labelLogin.Text = "Логин"; // // labelWarnings // labelWarnings.AutoSize = true; - labelWarnings.Location = new Point(15, 120); + labelWarnings.Location = new Point(17, 160); labelWarnings.Name = "labelWarnings"; - labelWarnings.Size = new Size(102, 15); + labelWarnings.Size = new Size(131, 20); labelWarnings.TabIndex = 5; labelWarnings.Text = "Предупреждения"; // // labelRating // labelRating.AutoSize = true; - labelRating.Location = new Point(19, 174); + labelRating.Location = new Point(22, 232); labelRating.Name = "labelRating"; - labelRating.Size = new Size(51, 15); + labelRating.Size = new Size(64, 20); labelRating.TabIndex = 6; labelRating.Text = "Рейтинг"; // // labelRole // labelRole.AutoSize = true; - labelRole.Location = new Point(18, 12); + labelRole.Location = new Point(21, 16); labelRole.Name = "labelRole"; - labelRole.Size = new Size(34, 15); + labelRole.Size = new Size(42, 20); labelRole.TabIndex = 7; labelRole.Text = "Роль"; // // comboBoxControlRole // comboBoxControlRole.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - comboBoxControlRole.Location = new Point(15, 33); - comboBoxControlRole.Margin = new Padding(3, 2, 3, 2); + comboBoxControlRole.Location = new Point(17, 44); + comboBoxControlRole.Margin = new Padding(3, 4, 3, 4); comboBoxControlRole.Name = "comboBoxControlRole"; comboBoxControlRole.SelectedValue = ""; - comboBoxControlRole.Size = new Size(327, 26); + comboBoxControlRole.Size = new Size(369, 35); comboBoxControlRole.TabIndex = 8; // // buttonCancel // - buttonCancel.Location = new Point(147, 232); - buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Location = new Point(168, 309); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(92, 27); + buttonCancel.Size = new Size(105, 36); buttonCancel.TabIndex = 9; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; @@ -140,9 +136,9 @@ // // FormAccount // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(357, 272); + ClientSize = new Size(408, 363); Controls.Add(buttonCancel); Controls.Add(comboBoxControlRole); Controls.Add(labelRole); @@ -153,7 +149,6 @@ Controls.Add(textBoxWarnings); Controls.Add(textBoxLogin); Controls.Add(controlInputRating); - Margin = new Padding(3, 2, 3, 2); Name = "FormAccount"; Text = "Аккаунт"; FormClosing += FormAccount_FormClosing; diff --git a/COP/PortalAccountsView/FormRoles.Designer.cs b/COP/PortalAccountsView/FormRoles.Designer.cs index b51488a..d369b5a 100644 --- a/COP/PortalAccountsView/FormRoles.Designer.cs +++ b/COP/PortalAccountsView/FormRoles.Designer.cs @@ -29,8 +29,8 @@ private void InitializeComponent() { dataGridView = new DataGridView(); - Id = new DataGridViewTextBoxColumn(); NameCol = new DataGridViewTextBoxColumn(); + Id = new DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // @@ -38,17 +38,24 @@ // dataGridView.BackgroundColor = SystemColors.ControlLightLight; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { Id, NameCol }); - dataGridView.Dock = System.Windows.Forms.DockStyle.Fill; - dataGridView.Location = new System.Drawing.Point(0, 0); + dataGridView.Columns.AddRange(new DataGridViewColumn[] { NameCol, Id }); + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); dataGridView.Name = "dataGridView"; dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new System.Drawing.Size(800, 450); + dataGridView.Size = new Size(800, 450); dataGridView.TabIndex = 0; - dataGridView.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataGridView_CellValueChanged); - dataGridView.UserDeletingRow += new System.Windows.Forms.DataGridViewRowCancelEventHandler(this.DataGridView_UserDeletingRow); - dataGridView.KeyUp += new System.Windows.Forms.KeyEventHandler(this.DataGridView_KeyUp); + dataGridView.CellValueChanged += DataGridView_CellValueChanged; + dataGridView.UserDeletingRow += DataGridView_UserDeletingRow; + dataGridView.KeyUp += DataGridView_KeyUp; + // + // NameCol + // + NameCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + NameCol.HeaderText = "Название"; + NameCol.MinimumWidth = 6; + NameCol.Name = "NameCol"; // // Id // @@ -58,30 +65,23 @@ Id.Visible = false; Id.Width = 125; // - // Name - // - NameCol.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - NameCol.HeaderText = "Название"; - NameCol.MinimumWidth = 6; - NameCol.Name = "Name"; - // // FormRoles // - AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - ClientSize = new System.Drawing.Size(800, 450); + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); Controls.Add(dataGridView); Name = "FormRoles"; Text = "FormRoles"; - Load += new System.EventHandler(this.FormRoles_Load); - ((System.ComponentModel.ISupportInitialize)(dataGridView)).EndInit(); + Load += FormRoles_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); } #endregion private DataGridView dataGridView; - private DataGridViewTextBoxColumn Id; private DataGridViewTextBoxColumn NameCol; + private DataGridViewTextBoxColumn Id; } } \ No newline at end of file diff --git a/COP/PortalAccountsView/FormRoles.cs b/COP/PortalAccountsView/FormRoles.cs index 4f74a9a..0fbb901 100644 --- a/COP/PortalAccountsView/FormRoles.cs +++ b/COP/PortalAccountsView/FormRoles.cs @@ -50,18 +50,19 @@ namespace PortalAccountsView { if (dataLoading || e.RowIndex < 0 || e.ColumnIndex != 0) return; - if (dataGridView.Rows[e.RowIndex].Cells[1].Value != null && !string.IsNullOrEmpty(dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString())) + if (dataGridView.Rows[e.RowIndex].Cells[1].Value != null) { - var name = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; - if (name is null) return; - _logic.Update(new RoleBindingModel { Id = Convert.ToInt32(dataGridView.Rows[e.RowIndex].Cells[1].Value), Name = name.ToString() }); + var name = dataGridView.Rows[e.RowIndex].Cells[0].Value.ToString(); + if (string.IsNullOrEmpty(name)) + return; + _logic.Update(new RoleBindingModel { Id = Convert.ToInt32(dataGridView.Rows[e.RowIndex].Cells[1].Value), Name = name }); } else { - var name = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; - if (name is null) + var name = dataGridView.Rows[e.RowIndex].Cells[0].Value.ToString(); + if (string.IsNullOrEmpty(name)) return; - _logic.Create(new RoleBindingModel { Id = 0, Name = name.ToString() }); + _logic.Create(new RoleBindingModel { Id = 0, Name = name }); var list = _logic.ReadList(null) ?? throw new Exception("Не удалось получить список ролей"); int newRoleId = list.Last().Id; dataGridView.Rows[e.RowIndex].Cells[1].Value = newRoleId; @@ -83,7 +84,8 @@ namespace PortalAccountsView for (int i = 0; i < rows.Count; i++) { DataGridViewRow row = rows[i]; - if (!_logic.Delete(new RoleBindingModel { Id = Convert.ToInt32(row.Cells[1].Value) })) continue; + if (!_logic.Delete(new RoleBindingModel { Id = Convert.ToInt32(row.Cells[1].Value) })) + throw new Exception($"Ошибка удаления строки: {row.Cells[0].Value}"); dataGridView.Rows.Remove(row); } } @@ -91,8 +93,10 @@ namespace PortalAccountsView private void DataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { e.Cancel = true; - if (dataGridView.SelectedRows == null) return; - if (MessageBox.Show("Удалить записи?", "Подтвердите действие", MessageBoxButtons.YesNo) == DialogResult.No) return; + if (dataGridView.SelectedRows == null) + return; + if (MessageBox.Show("Удалить записи?", "Подтвердите действие", MessageBoxButtons.YesNo) == DialogResult.No) + return; DeleteRows(dataGridView.SelectedRows); } } diff --git a/COP/PortalAccountsView/FormRoles.resx b/COP/PortalAccountsView/FormRoles.resx index 9d0eaa3..91e09cb 100644 --- a/COP/PortalAccountsView/FormRoles.resx +++ b/COP/PortalAccountsView/FormRoles.resx @@ -120,7 +120,4 @@ True - - True - \ No newline at end of file diff --git a/COP/RodionovLibrary/VisualComponents/ComboBoxControl.Designer.cs b/COP/RodionovLibrary/VisualComponents/ComboBoxControl.Designer.cs index 45e9dc6..22e7ad8 100644 --- a/COP/RodionovLibrary/VisualComponents/ComboBoxControl.Designer.cs +++ b/COP/RodionovLibrary/VisualComponents/ComboBoxControl.Designer.cs @@ -36,18 +36,20 @@ comboBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; comboBox.FormattingEnabled = true; comboBox.Location = new Point(1, 0); + comboBox.Margin = new Padding(3, 4, 3, 4); comboBox.Name = "comboBox"; - comboBox.Size = new Size(323, 23); + comboBox.Size = new Size(874, 28); comboBox.TabIndex = 0; comboBox.SelectedIndexChanged += ComboBox_SelectedIndexChanged; // // ComboBoxControl // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; Controls.Add(comboBox); + Margin = new Padding(3, 4, 3, 4); Name = "ComboBoxControl"; - Size = new Size(327, 26); + Size = new Size(875, 35); ResumeLayout(false); }