From 93ffc24a903f3f44546c86d9c9ed765a79a02ef6 Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Thu, 30 Nov 2023 00:23:56 +0400 Subject: [PATCH] Add avatars and avatar document --- AbazovApp/AccountsApp/FormAccount.Designer.cs | 30 ++++-- AbazovApp/AccountsApp/FormAccount.cs | 18 +++- AbazovApp/AccountsApp/FormAccount.resx | 11 +-- AbazovApp/AccountsApp/FormMain.Designer.cs | 4 + AbazovApp/AccountsApp/FormMain.cs | 14 ++- AbazovApp/AccountsApp/FormMain.resx | 3 + .../BindingModels/AccountBindingModel.cs | 2 + .../ViewModels/AccountViewModel.cs | 1 + ..._AddColumnAvatarToAccountTable.Designer.cs | 91 +++++++++++++++++++ ...129200602_AddColumnAvatarToAccountTable.cs | 29 ++++++ .../AccountsDatabaseModelSnapshot.cs | 4 + .../Models/Account.cs | 6 ++ .../Models/IAccountModel.cs | 1 + 13 files changed, 198 insertions(+), 16 deletions(-) create mode 100644 AbazovApp/AccountsDataBaseImplement/Migrations/20231129200602_AddColumnAvatarToAccountTable.Designer.cs create mode 100644 AbazovApp/AccountsDataBaseImplement/Migrations/20231129200602_AddColumnAvatarToAccountTable.cs diff --git a/AbazovApp/AccountsApp/FormAccount.Designer.cs b/AbazovApp/AccountsApp/FormAccount.Designer.cs index 38450fe..7067dd5 100644 --- a/AbazovApp/AccountsApp/FormAccount.Designer.cs +++ b/AbazovApp/AccountsApp/FormAccount.Designer.cs @@ -28,7 +28,6 @@ /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormAccount)); this.label1 = new System.Windows.Forms.Label(); this.textBoxLogin = new System.Windows.Forms.TextBox(); this.textBoxPassword = new System.Windows.Forms.TextBox(); @@ -39,6 +38,8 @@ this.label4 = new System.Windows.Forms.Label(); this.buttonSave = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); + this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); + this.buttonAvatar = new System.Windows.Forms.Button(); this.SuspendLayout(); // // label1 @@ -100,7 +101,7 @@ // abazovCheckedListBox // this.abazovCheckedListBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); - this.abazovCheckedListBox.Location = new System.Drawing.Point(12, 195); + this.abazovCheckedListBox.Location = new System.Drawing.Point(12, 207); this.abazovCheckedListBox.Name = "abazovCheckedListBox"; this.abazovCheckedListBox.selectedItem = null; this.abazovCheckedListBox.Size = new System.Drawing.Size(389, 130); @@ -110,7 +111,7 @@ // this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(12, 172); + this.label4.Location = new System.Drawing.Point(12, 184); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(78, 20); this.label4.TabIndex = 7; @@ -118,7 +119,7 @@ // // buttonSave // - this.buttonSave.Location = new System.Drawing.Point(12, 364); + this.buttonSave.Location = new System.Drawing.Point(12, 420); this.buttonSave.Name = "buttonSave"; this.buttonSave.Size = new System.Drawing.Size(94, 29); this.buttonSave.TabIndex = 8; @@ -128,7 +129,7 @@ // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(307, 364); + this.buttonCancel.Location = new System.Drawing.Point(307, 420); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(94, 29); this.buttonCancel.TabIndex = 9; @@ -136,11 +137,26 @@ this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); // + // openFileDialog + // + this.openFileDialog.FileName = "openFileDialog1"; + // + // buttonAvatar + // + this.buttonAvatar.Location = new System.Drawing.Point(12, 343); + this.buttonAvatar.Name = "buttonAvatar"; + this.buttonAvatar.Size = new System.Drawing.Size(389, 29); + this.buttonAvatar.TabIndex = 10; + this.buttonAvatar.Text = "Выбрать аватар"; + this.buttonAvatar.UseVisualStyleBackColor = true; + this.buttonAvatar.Click += new System.EventHandler(this.buttonAvatar_Click); + // // FormAccount // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(413, 405); + this.ClientSize = new System.Drawing.Size(413, 461); + this.Controls.Add(this.buttonAvatar); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonSave); this.Controls.Add(this.label4); @@ -171,5 +187,7 @@ private Label label4; private Button buttonSave; private Button buttonCancel; + private OpenFileDialog openFileDialog; + private Button buttonAvatar; } } \ No newline at end of file diff --git a/AbazovApp/AccountsApp/FormAccount.cs b/AbazovApp/AccountsApp/FormAccount.cs index bbe4096..cc9b2c3 100644 --- a/AbazovApp/AccountsApp/FormAccount.cs +++ b/AbazovApp/AccountsApp/FormAccount.cs @@ -21,6 +21,7 @@ namespace AccountsApp private readonly IAccountLogic _logic; private readonly IInterestLogic _interestLogic; private List _interests; + private string? avatar = null; public int Id { set { _id = value; } } public FormAccount(IAccountLogic logic, IInterestLogic interestLogic) @@ -47,6 +48,7 @@ namespace AccountsApp textBoxLogin.Text = view.Login; textBoxPassword.Text = view.Password; mailControl.Email = view.Email; + avatar = view.Avatar; abazovCheckedListBox.selectedItem = view.InterestName; } @@ -86,6 +88,11 @@ namespace AccountsApp MessageBox.Show("Заполните интересы", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (avatar == null) + { + MessageBox.Show("Выберите аватар", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } try { var model = new AccountBindingModel @@ -94,7 +101,8 @@ namespace AccountsApp Login = textBoxLogin.Text, Password = textBoxPassword.Text, Email = mailControl.Email, - InterestId = _interests.First(x => x.Name == abazovCheckedListBox.selectedItem).Id + InterestId = _interests.First(x => x.Name == abazovCheckedListBox.selectedItem).Id, + Avatar = avatar }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) @@ -110,5 +118,13 @@ namespace AccountsApp MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void buttonAvatar_Click(object sender, EventArgs e) + { + if (openFileDialog.ShowDialog() != DialogResult.Cancel) + { + avatar = openFileDialog.FileName; + } + } } } diff --git a/AbazovApp/AccountsApp/FormAccount.resx b/AbazovApp/AccountsApp/FormAccount.resx index 0c053f3..e6275bd 100644 --- a/AbazovApp/AccountsApp/FormAccount.resx +++ b/AbazovApp/AccountsApp/FormAccount.resx @@ -57,12 +57,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - AAEAAAD/////AQAAAAAAAAAEAQAAAH9TeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYy5MaXN0YDFbW1N5 - c3RlbS5TdHJpbmcsIG1zY29ybGliLCBWZXJzaW9uPTQuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVi - bGljS2V5VG9rZW49Yjc3YTVjNTYxOTM0ZTA4OV1dAwAAAAZfaXRlbXMFX3NpemUIX3ZlcnNpb24GAAAI - CAkCAAAAAAAAAAAAAAARAgAAAAAAAAAL - - + + 17, 17 + \ No newline at end of file diff --git a/AbazovApp/AccountsApp/FormMain.Designer.cs b/AbazovApp/AccountsApp/FormMain.Designer.cs index c67e9ec..332cf77 100644 --- a/AbazovApp/AccountsApp/FormMain.Designer.cs +++ b/AbazovApp/AccountsApp/FormMain.Designer.cs @@ -28,6 +28,7 @@ /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.аккаунтыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.создатьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -39,6 +40,7 @@ this.документСДиаграммойToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.интересыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.controlDataTable = new ControlsLibraryNet60.Data.ControlDataTableTable(); + this.excelImagesComponent = new AbazovViewComponents.LogicalComponents.ExcelImagesComponent(this.components); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -105,6 +107,7 @@ this.документToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); this.документToolStripMenuItem.Size = new System.Drawing.Size(313, 26); this.документToolStripMenuItem.Text = "Документ"; + this.документToolStripMenuItem.Click += new System.EventHandler(this.документToolStripMenuItem_Click); // // документСТаблицейToolStripMenuItem // @@ -167,5 +170,6 @@ private ToolStripMenuItem документСДиаграммойToolStripMenuItem; private ToolStripMenuItem интересыToolStripMenuItem; private ControlsLibraryNet60.Data.ControlDataTableTable controlDataTable; + private AbazovViewComponents.LogicalComponents.ExcelImagesComponent excelImagesComponent; } } \ No newline at end of file diff --git a/AbazovApp/AccountsApp/FormMain.cs b/AbazovApp/AccountsApp/FormMain.cs index 74209f3..d7fd573 100644 --- a/AbazovApp/AccountsApp/FormMain.cs +++ b/AbazovApp/AccountsApp/FormMain.cs @@ -1,4 +1,5 @@ -using AccountsContracts.BindingModels; +using AbazovViewComponents.LogicalComponents; +using AccountsContracts.BindingModels; using AccountsContracts.BusinessLogicContracts; using AccountsContracts.ViewModels; using ControlsLibraryNet60.Core; @@ -90,5 +91,16 @@ namespace AccountsApp } } } + + private void документToolStripMenuItem_Click(object sender, EventArgs e) + { + List avatars = new List(); + foreach (var account in _logic.ReadList(null)) + { + avatars.Add(account.Avatar); + } + string path = AppDomain.CurrentDomain.BaseDirectory + "Аватары.xlsx"; + if (excelImagesComponent.createWithImages(new ExcelImageInfo(path, "Аватары", avatars.ToArray()))) MessageBox.Show("Документ создан"); + } } } diff --git a/AbazovApp/AccountsApp/FormMain.resx b/AbazovApp/AccountsApp/FormMain.resx index 05252e7..e9680e0 100644 --- a/AbazovApp/AccountsApp/FormMain.resx +++ b/AbazovApp/AccountsApp/FormMain.resx @@ -60,6 +60,9 @@ 17, 17 + + 152, 0 + 25 diff --git a/AbazovApp/AccountsContracts/BindingModels/AccountBindingModel.cs b/AbazovApp/AccountsContracts/BindingModels/AccountBindingModel.cs index d14882d..9e832c0 100644 --- a/AbazovApp/AccountsContracts/BindingModels/AccountBindingModel.cs +++ b/AbazovApp/AccountsContracts/BindingModels/AccountBindingModel.cs @@ -18,5 +18,7 @@ namespace AccountsContracts.BindingModels public int Id { get; set; } public int InterestId { get; set; } + + public string Avatar { get; set; } } } diff --git a/AbazovApp/AccountsContracts/ViewModels/AccountViewModel.cs b/AbazovApp/AccountsContracts/ViewModels/AccountViewModel.cs index b58a412..e8e6793 100644 --- a/AbazovApp/AccountsContracts/ViewModels/AccountViewModel.cs +++ b/AbazovApp/AccountsContracts/ViewModels/AccountViewModel.cs @@ -19,5 +19,6 @@ namespace AccountsContracts.ViewModels public int Id { get; set; } public int InterestId { get; set; } public string InterestName { get; set; } = string.Empty; + public string Avatar { get; set; } = string.Empty; } } diff --git a/AbazovApp/AccountsDataBaseImplement/Migrations/20231129200602_AddColumnAvatarToAccountTable.Designer.cs b/AbazovApp/AccountsDataBaseImplement/Migrations/20231129200602_AddColumnAvatarToAccountTable.Designer.cs new file mode 100644 index 0000000..34d5749 --- /dev/null +++ b/AbazovApp/AccountsDataBaseImplement/Migrations/20231129200602_AddColumnAvatarToAccountTable.Designer.cs @@ -0,0 +1,91 @@ +// +using AccountsDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace AccountsDataBaseImplement.Migrations +{ + [DbContext(typeof(AccountsDatabase))] + [Migration("20231129200602_AddColumnAvatarToAccountTable")] + partial class AddColumnAvatarToAccountTable + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("AccountsDataBaseImplement.Models.Account", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Avatar") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("InterestId") + .HasColumnType("integer"); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("InterestId"); + + b.ToTable("Accounts"); + }); + + modelBuilder.Entity("AccountsDataBaseImplement.Models.Interest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Interests"); + }); + + modelBuilder.Entity("AccountsDataBaseImplement.Models.Account", b => + { + b.HasOne("AccountsDataBaseImplement.Models.Interest", "Interest") + .WithMany() + .HasForeignKey("InterestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Interest"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/AbazovApp/AccountsDataBaseImplement/Migrations/20231129200602_AddColumnAvatarToAccountTable.cs b/AbazovApp/AccountsDataBaseImplement/Migrations/20231129200602_AddColumnAvatarToAccountTable.cs new file mode 100644 index 0000000..24ef39e --- /dev/null +++ b/AbazovApp/AccountsDataBaseImplement/Migrations/20231129200602_AddColumnAvatarToAccountTable.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AccountsDataBaseImplement.Migrations +{ + /// + public partial class AddColumnAvatarToAccountTable : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Avatar", + table: "Accounts", + type: "text", + nullable: false, + defaultValue: ""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Avatar", + table: "Accounts"); + } + } +} diff --git a/AbazovApp/AccountsDataBaseImplement/Migrations/AccountsDatabaseModelSnapshot.cs b/AbazovApp/AccountsDataBaseImplement/Migrations/AccountsDatabaseModelSnapshot.cs index 10f6a17..85660f3 100644 --- a/AbazovApp/AccountsDataBaseImplement/Migrations/AccountsDatabaseModelSnapshot.cs +++ b/AbazovApp/AccountsDataBaseImplement/Migrations/AccountsDatabaseModelSnapshot.cs @@ -29,6 +29,10 @@ namespace AccountsDataBaseImplement.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("Avatar") + .IsRequired() + .HasColumnType("text"); + b.Property("Email") .IsRequired() .HasColumnType("text"); diff --git a/AbazovApp/AccountsDataBaseImplement/Models/Account.cs b/AbazovApp/AccountsDataBaseImplement/Models/Account.cs index c25f6a6..9853671 100644 --- a/AbazovApp/AccountsDataBaseImplement/Models/Account.cs +++ b/AbazovApp/AccountsDataBaseImplement/Models/Account.cs @@ -26,6 +26,9 @@ namespace AccountsDataBaseImplement.Models public virtual Interest Interest { get; set; } = new(); + [Required] + public string Avatar { get; set; } = string.Empty; + public static Account? Create(AccountsDatabase context, AccountBindingModel? model) { if (model == null) @@ -40,6 +43,7 @@ namespace AccountsDataBaseImplement.Models Email = model.Email, InterestId = model.InterestId, Interest = context.Interests.First(x => x.Id == model.InterestId), + Avatar = model.Avatar, }; } @@ -53,6 +57,7 @@ namespace AccountsDataBaseImplement.Models Password = model.Password; InterestId = model.InterestId; Interest = context.Interests.First(x => x.Id == model.InterestId); + Avatar = model.Avatar; } public AccountViewModel GetViewModel => new() @@ -63,6 +68,7 @@ namespace AccountsDataBaseImplement.Models Email = Email, InterestId = InterestId, InterestName = Interest.Name, + Avatar = Avatar, }; } } diff --git a/AbazovApp/AccountsDataModels/Models/IAccountModel.cs b/AbazovApp/AccountsDataModels/Models/IAccountModel.cs index 20f8d7f..ebf2f07 100644 --- a/AbazovApp/AccountsDataModels/Models/IAccountModel.cs +++ b/AbazovApp/AccountsDataModels/Models/IAccountModel.cs @@ -12,5 +12,6 @@ namespace AccountsDataModels.Models string Password { get; } string Email { get; } public int InterestId { get; } + public string Avatar { get; } } }