diff --git a/ClientRecordBuisinessLogic/BuisinessLogic/ClientLogic.cs b/ClientRecordBuisinessLogic/BuisinessLogic/ClientLogic.cs index c758e40..4c6fd22 100644 --- a/ClientRecordBuisinessLogic/BuisinessLogic/ClientLogic.cs +++ b/ClientRecordBuisinessLogic/BuisinessLogic/ClientLogic.cs @@ -23,7 +23,7 @@ namespace ClientRecordBuisinessLogic.BuisinessLogic public bool Delete(ClientBindingModel model) { - CheckModel(model); + CheckModel(model,false); return _clientStorage.Delete(model) != null; } diff --git a/ClientRecordContracts/BindingModels/ClientBindingModel.cs b/ClientRecordContracts/BindingModels/ClientBindingModel.cs index 1313ca7..3c6152c 100644 --- a/ClientRecordContracts/BindingModels/ClientBindingModel.cs +++ b/ClientRecordContracts/BindingModels/ClientBindingModel.cs @@ -7,7 +7,7 @@ namespace ClientRecordContracts.BindingModels public int Id { get; set; } public string? Reviews { get; set; } public string ClientFIO { get; set; } = string.Empty; - public double? Amount { get; set; } + public int? Amount { get; set; } public int StatusId { get; set; } } diff --git a/ClientRecordContracts/ViewModels/ClientViewModel.cs b/ClientRecordContracts/ViewModels/ClientViewModel.cs index dc7e481..5d7d4b4 100644 --- a/ClientRecordContracts/ViewModels/ClientViewModel.cs +++ b/ClientRecordContracts/ViewModels/ClientViewModel.cs @@ -11,7 +11,7 @@ namespace ClientRecordContracts.ViewModels [DisplayName("Отзывы")] public string? Reviews { get; set; } [DisplayName("Сумма покупок")] - public double? Amount { get; set; } + public int? Amount { get; set; } public int StatusId { get; set; } diff --git a/ClientRecordDataModels/Models/IClientModel.cs b/ClientRecordDataModels/Models/IClientModel.cs index d419bb4..a887ad0 100644 --- a/ClientRecordDataModels/Models/IClientModel.cs +++ b/ClientRecordDataModels/Models/IClientModel.cs @@ -4,7 +4,7 @@ { string ClientFIO{ get; } string? Reviews{ get; } - double? Amount{ get; } + int? Amount{ get; } int StatusId{ get; } } } diff --git a/ClientRecordDatabaseImplement/ClientRecordDatabase.cs b/ClientRecordDatabaseImplement/ClientRecordDatabase.cs index e2fd37d..d021e4d 100644 --- a/ClientRecordDatabaseImplement/ClientRecordDatabase.cs +++ b/ClientRecordDatabaseImplement/ClientRecordDatabase.cs @@ -9,7 +9,7 @@ namespace ClientRecordDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseNpgsql(@"Host=localhost;Database=Factory;Username=postgres;Password=postgres"); + optionsBuilder.UseNpgsql(@"Host=localhost;Database=COP;Username=postgres;Password=postgres"); } base.OnConfiguring(optionsBuilder); diff --git a/ClientRecordDatabaseImplement/Migrations/20241029151814_init.Designer.cs b/ClientRecordDatabaseImplement/Migrations/20241030093837_init.Designer.cs similarity index 95% rename from ClientRecordDatabaseImplement/Migrations/20241029151814_init.Designer.cs rename to ClientRecordDatabaseImplement/Migrations/20241030093837_init.Designer.cs index aab37a2..651c866 100644 --- a/ClientRecordDatabaseImplement/Migrations/20241029151814_init.Designer.cs +++ b/ClientRecordDatabaseImplement/Migrations/20241030093837_init.Designer.cs @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace ClientRecordDatabaseImplement.Migrations { [DbContext(typeof(ClientRecordDatabase))] - [Migration("20241029151814_init")] + [Migration("20241030093837_init")] partial class init { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -32,8 +32,8 @@ namespace ClientRecordDatabaseImplement.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("Amount") - .HasColumnType("double precision"); + b.Property("Amount") + .HasColumnType("integer"); b.Property("ClientFIO") .IsRequired() diff --git a/ClientRecordDatabaseImplement/Migrations/20241029151814_init.cs b/ClientRecordDatabaseImplement/Migrations/20241030093837_init.cs similarity index 96% rename from ClientRecordDatabaseImplement/Migrations/20241029151814_init.cs rename to ClientRecordDatabaseImplement/Migrations/20241030093837_init.cs index 773202c..0ade366 100644 --- a/ClientRecordDatabaseImplement/Migrations/20241029151814_init.cs +++ b/ClientRecordDatabaseImplement/Migrations/20241030093837_init.cs @@ -32,7 +32,7 @@ namespace ClientRecordDatabaseImplement.Migrations StatusId = table.Column(type: "integer", nullable: false), ClientId = table.Column(type: "integer", nullable: false), Reviews = table.Column(type: "text", nullable: true), - Amount = table.Column(type: "double precision", nullable: true) + Amount = table.Column(type: "integer", nullable: true) }, constraints: table => { diff --git a/ClientRecordDatabaseImplement/Migrations/20241030102017_fix.Designer.cs b/ClientRecordDatabaseImplement/Migrations/20241030102017_fix.Designer.cs new file mode 100644 index 0000000..669fd99 --- /dev/null +++ b/ClientRecordDatabaseImplement/Migrations/20241030102017_fix.Designer.cs @@ -0,0 +1,90 @@ +// +using System; +using ClientRecordDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ClientRecordDatabaseImplement.Migrations +{ + [DbContext(typeof(ClientRecordDatabase))] + [Migration("20241030102017_fix")] + partial class fix + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.35") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ClientRecordDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Reviews") + .HasColumnType("text"); + + b.Property("StatusId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StatusId"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("ClientRecordDatabaseImplement.Models.Status", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Statuses"); + }); + + modelBuilder.Entity("ClientRecordDatabaseImplement.Models.Client", b => + { + b.HasOne("ClientRecordDatabaseImplement.Models.Status", "Status") + .WithMany("Clients") + .HasForeignKey("StatusId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Status"); + }); + + modelBuilder.Entity("ClientRecordDatabaseImplement.Models.Status", b => + { + b.Navigation("Clients"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ClientRecordDatabaseImplement/Migrations/20241030102017_fix.cs b/ClientRecordDatabaseImplement/Migrations/20241030102017_fix.cs new file mode 100644 index 0000000..a35a791 --- /dev/null +++ b/ClientRecordDatabaseImplement/Migrations/20241030102017_fix.cs @@ -0,0 +1,68 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ClientRecordDatabaseImplement.Migrations +{ + public partial class fix : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Clients_Statuses_ClientId", + table: "Clients"); + + migrationBuilder.DropIndex( + name: "IX_Clients_ClientId", + table: "Clients"); + + migrationBuilder.DropColumn( + name: "ClientId", + table: "Clients"); + + migrationBuilder.CreateIndex( + name: "IX_Clients_StatusId", + table: "Clients", + column: "StatusId"); + + migrationBuilder.AddForeignKey( + name: "FK_Clients_Statuses_StatusId", + table: "Clients", + column: "StatusId", + principalTable: "Statuses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Clients_Statuses_StatusId", + table: "Clients"); + + migrationBuilder.DropIndex( + name: "IX_Clients_StatusId", + table: "Clients"); + + migrationBuilder.AddColumn( + name: "ClientId", + table: "Clients", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateIndex( + name: "IX_Clients_ClientId", + table: "Clients", + column: "ClientId"); + + migrationBuilder.AddForeignKey( + name: "FK_Clients_Statuses_ClientId", + table: "Clients", + column: "ClientId", + principalTable: "Statuses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/ClientRecordDatabaseImplement/Migrations/ClientRecordDatabaseModelSnapshot.cs b/ClientRecordDatabaseImplement/Migrations/ClientRecordDatabaseModelSnapshot.cs index 2857bcc..6d9e825 100644 --- a/ClientRecordDatabaseImplement/Migrations/ClientRecordDatabaseModelSnapshot.cs +++ b/ClientRecordDatabaseImplement/Migrations/ClientRecordDatabaseModelSnapshot.cs @@ -30,16 +30,13 @@ namespace ClientRecordDatabaseImplement.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("Amount") - .HasColumnType("double precision"); + b.Property("Amount") + .HasColumnType("integer"); b.Property("ClientFIO") .IsRequired() .HasColumnType("text"); - b.Property("ClientId") - .HasColumnType("integer"); - b.Property("Reviews") .HasColumnType("text"); @@ -48,7 +45,7 @@ namespace ClientRecordDatabaseImplement.Migrations b.HasKey("Id"); - b.HasIndex("ClientId"); + b.HasIndex("StatusId"); b.ToTable("Clients"); }); @@ -74,7 +71,7 @@ namespace ClientRecordDatabaseImplement.Migrations { b.HasOne("ClientRecordDatabaseImplement.Models.Status", "Status") .WithMany("Clients") - .HasForeignKey("ClientId") + .HasForeignKey("StatusId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); diff --git a/ClientRecordDatabaseImplement/Models/Client.cs b/ClientRecordDatabaseImplement/Models/Client.cs index 31f2b71..fa1999d 100644 --- a/ClientRecordDatabaseImplement/Models/Client.cs +++ b/ClientRecordDatabaseImplement/Models/Client.cs @@ -15,7 +15,7 @@ namespace ClientRecordDatabaseImplement.Models public int StatusId { get; set; } public virtual Status Status { get; set; } public string? Reviews { get; set; } - public double? Amount { get; set; } + public int? Amount { get; set; } public static Client? Create(ClientBindingModel model) { diff --git a/ClientRecordDatabaseImplement/Models/Status.cs b/ClientRecordDatabaseImplement/Models/Status.cs index 84279eb..22deb06 100644 --- a/ClientRecordDatabaseImplement/Models/Status.cs +++ b/ClientRecordDatabaseImplement/Models/Status.cs @@ -14,7 +14,7 @@ namespace ClientRecordDatabaseImplement.Models [Required] public string Name { get; private set; } = string.Empty; - [ForeignKey("ClientId")] + [ForeignKey("StatusId")] public virtual List Clients { get; set; } = new(); public static Status? Create(StatusBindingModel model) diff --git a/ClientRecordView/ClientRecordView.csproj b/ClientRecordView/ClientRecordView.csproj index a4cf86a..c14c906 100644 --- a/ClientRecordView/ClientRecordView.csproj +++ b/ClientRecordView/ClientRecordView.csproj @@ -2,13 +2,16 @@ WinExe - net6.0-windows + net7.0-windows enable true enable + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/ClientRecordView/FormClient.Designer.cs b/ClientRecordView/FormClient.Designer.cs index d7f62f4..a9645c5 100644 --- a/ClientRecordView/FormClient.Designer.cs +++ b/ClientRecordView/FormClient.Designer.cs @@ -28,12 +28,163 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.labelStatus = new System.Windows.Forms.Label(); + this.labelAmount = new System.Windows.Forms.Label(); + this.labelReviews = new System.Windows.Forms.Label(); + this.labelFIO = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxReviews = new System.Windows.Forms.TextBox(); + this.textBoxFIO = new System.Windows.Forms.TextBox(); + this.userControlIntegerInput = new Components.UserControlIntegerInput(); + this.dropDownList = new WinFormsLibrary.DropDownList(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(258, 392); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(4); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(131, 45); + this.buttonCancel.TabIndex = 17; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // labelStatus + // + this.labelStatus.AutoSize = true; + this.labelStatus.Location = new System.Drawing.Point(13, 9); + this.labelStatus.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelStatus.Name = "labelStatus"; + this.labelStatus.Size = new System.Drawing.Size(63, 25); + this.labelStatus.TabIndex = 15; + this.labelStatus.Text = "Статус"; + // + // labelAmount + // + this.labelAmount.AutoSize = true; + this.labelAmount.Location = new System.Drawing.Point(20, 283); + this.labelAmount.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelAmount.Name = "labelAmount"; + this.labelAmount.Size = new System.Drawing.Size(141, 25); + this.labelAmount.TabIndex = 14; + this.labelAmount.Text = "Сумма покупок"; + // + // labelReviews + // + this.labelReviews.AutoSize = true; + this.labelReviews.Location = new System.Drawing.Point(13, 193); + this.labelReviews.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelReviews.Name = "labelReviews"; + this.labelReviews.Size = new System.Drawing.Size(77, 25); + this.labelReviews.TabIndex = 13; + this.labelReviews.Text = "Отзывы"; + // + // labelFIO + // + this.labelFIO.AutoSize = true; + this.labelFIO.Location = new System.Drawing.Point(13, 99); + this.labelFIO.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelFIO.Name = "labelFIO"; + this.labelFIO.Size = new System.Drawing.Size(52, 25); + this.labelFIO.TabIndex = 12; + this.labelFIO.Text = "ФИО"; + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(13, 392); + this.buttonSave.Margin = new System.Windows.Forms.Padding(4); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(131, 45); + this.buttonSave.TabIndex = 16; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // textBoxReviews + // + this.textBoxReviews.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxReviews.Location = new System.Drawing.Point(13, 232); + this.textBoxReviews.Margin = new System.Windows.Forms.Padding(4); + this.textBoxReviews.Name = "textBoxReviews"; + this.textBoxReviews.Size = new System.Drawing.Size(376, 31); + this.textBoxReviews.TabIndex = 11; + this.textBoxReviews.TextChanged += new System.EventHandler(this.textBoxReviews_TextChanged); + // + // textBoxFIO + // + this.textBoxFIO.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxFIO.Location = new System.Drawing.Point(13, 137); + this.textBoxFIO.Margin = new System.Windows.Forms.Padding(4); + this.textBoxFIO.Name = "textBoxFIO"; + this.textBoxFIO.Size = new System.Drawing.Size(376, 31); + this.textBoxFIO.TabIndex = 10; + this.textBoxFIO.TextChanged += new System.EventHandler(this.textBoxFIO_TextChanged); + // + // userControlIntegerInput + // + this.userControlIntegerInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.userControlIntegerInput.Location = new System.Drawing.Point(13, 324); + this.userControlIntegerInput.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.userControlIntegerInput.Name = "userControlIntegerInput"; + this.userControlIntegerInput.Size = new System.Drawing.Size(384, 75); + this.userControlIntegerInput.TabIndex = 19; + // + // dropDownList + // + this.dropDownList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dropDownList.Location = new System.Drawing.Point(13, 37); + this.dropDownList.Name = "dropDownList"; + this.dropDownList.Selected = ""; + this.dropDownList.Size = new System.Drawing.Size(376, 51); + this.dropDownList.TabIndex = 20; + // + // FormClient + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; + this.ClientSize = new System.Drawing.Size(402, 450); + this.Controls.Add(this.dropDownList); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.labelStatus); + this.Controls.Add(this.labelAmount); + this.Controls.Add(this.labelReviews); + this.Controls.Add(this.labelFIO); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxReviews); + this.Controls.Add(this.textBoxFIO); + this.Controls.Add(this.userControlIntegerInput); + this.Name = "FormClient"; + this.Text = "Клиент"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormClient_FormClosing); + this.Load += new System.EventHandler(this.FormClient_Load); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private Button buttonCancel; + private Label labelStatus; + private Label labelAmount; + private Label labelReviews; + private Label labelFIO; + private Button buttonSave; + private TextBox textBoxReviews; + private TextBox textBoxFIO; + private Components.UserControlIntegerInput userControlIntegerInput; + private WinFormsLibrary.DropDownList dropDownList; } } \ No newline at end of file diff --git a/ClientRecordView/FormClient.cs b/ClientRecordView/FormClient.cs index 14b987d..7851f1e 100644 --- a/ClientRecordView/FormClient.cs +++ b/ClientRecordView/FormClient.cs @@ -1,10 +1,125 @@ +using ClientRecordContracts.BindingModels; +using ClientRecordContracts.BusinessLogicContracts; +using ClientRecordContracts.SearchModels; +using ClientRecordContracts.ViewModels; +using DocumentFormat.OpenXml.Vml.Office; + namespace ClientRecordView { public partial class FormClient : Form { - public FormClient() + private int? _id; + + private bool _isModified = false; + + private readonly IClientLogic _clientlogic; + + private readonly IStatusLogic _statusLogic; + + private List _statuses; + public int Id { set { _id = value; } } + public FormClient(IClientLogic logic, IStatusLogic statusLogic) { InitializeComponent(); + _clientlogic = logic; + _statusLogic = statusLogic; + _statuses = new List(); + dropDownList.ValueChanged += (_, _) => _isModified = true; + userControlIntegerInput.ElementChanged += (_, _) => _isModified = true; + } + + private void FormClient_Load(object sender, EventArgs e) + { + _statuses = _statusLogic.ReadList(null) ?? throw new Exception(" "); + dropDownList.LoadValues(_statuses.Select(x => x.Name).ToList()); + if (_id.HasValue) + { + try + { + var client = _clientlogic.ReadElement(new ClientSearchModel { Id = _id.Value }); + if (client != null) + { + textBoxFIO.Text = client.ClientFIO; + textBoxReviews.Text = client.Reviews; + userControlIntegerInput.InputtedInteger = client.Amount; + dropDownList.Selected = client.Status; + _isModified = false; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxFIO.Text)) + { + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(dropDownList.Selected)) + { + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var model = new ClientBindingModel + { + Id = _id ?? 0, + ClientFIO = textBoxFIO.Text, + Reviews = textBoxReviews.Text, + Amount = userControlIntegerInput.InputtedInteger, + StatusId = _statuses.First(x => x.Name == dropDownList.Selected).Id, + }; + var operationResult = _id.HasValue ? _clientlogic.Update(model) : _clientlogic.Create(model); + if (!operationResult) + { + throw new Exception(" "); + } + 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 textBoxFIO_TextChanged(object sender, EventArgs e) + { + _isModified = true; + } + + private void textBoxReviews_TextChanged(object sender, EventArgs e) + { + _isModified = true; + } + + private void FormClient_FormClosing(object sender, FormClosingEventArgs e) + { + if (!_isModified || DialogResult == DialogResult.OK) + return; + + var result = MessageBox.Show( + " . ?", + "", + MessageBoxButtons.YesNo, + MessageBoxIcon.Warning + ); + + if (result == DialogResult.No) + e.Cancel = true; } } } \ No newline at end of file diff --git a/ClientRecordView/FormClient.resx b/ClientRecordView/FormClient.resx index 1af7de1..f298a7b 100644 --- a/ClientRecordView/FormClient.resx +++ b/ClientRecordView/FormClient.resx @@ -1,64 +1,4 @@ - - - + diff --git a/ClientRecordView/FormMain.Designer.cs b/ClientRecordView/FormMain.Designer.cs index f1f4045..dbb9639 100644 --- a/ClientRecordView/FormMain.Designer.cs +++ b/ClientRecordView/FormMain.Designer.cs @@ -29,11 +29,153 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.СозданиеToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.редToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.удалениеToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ОтзывыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ОтчетпоклиентамExcelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.отчетСДиаграммойToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.статусыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.componentDocumentWithChartPieExcel = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartPieExcel(this.components); + this.wordText = new WinFormsLibrary.WordText(this.components); + this.controlDataTreeTable = new ControlsLibraryNet60.Data.ControlDataTreeTable(); + this.userControlConfigurableTableDocument = new Components.Nonvisual.UserControlConfigurableTableDocument(this.components); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.клиентыToolStripMenuItem, + this.отчетыToolStripMenuItem, + this.статусыToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(800, 33); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "menuStrip"; + // + // клиентыToolStripMenuItem + // + this.клиентыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.СозданиеToolStripMenuItem, + this.редToolStripMenuItem, + this.удалениеToolStripMenuItem}); + this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(96, 29); + this.клиентыToolStripMenuItem.Text = "Клиенты"; + // + // СозданиеToolStripMenuItem + // + this.СозданиеToolStripMenuItem.Name = "СозданиеToolStripMenuItem"; + this.СозданиеToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.A))); + this.СозданиеToolStripMenuItem.Size = new System.Drawing.Size(311, 34); + this.СозданиеToolStripMenuItem.Text = "Создание"; + this.СозданиеToolStripMenuItem.Click += new System.EventHandler(this.СозданиеToolStripMenuItem_Click); + // + // редToolStripMenuItem + // + this.редToolStripMenuItem.Name = "редToolStripMenuItem"; + this.редToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.U))); + this.редToolStripMenuItem.Size = new System.Drawing.Size(311, 34); + this.редToolStripMenuItem.Text = "Редактирование"; + this.редToolStripMenuItem.Click += new System.EventHandler(this.редToolStripMenuItem_Click); + // + // удалениеToolStripMenuItem + // + this.удалениеToolStripMenuItem.Name = "удалениеToolStripMenuItem"; + this.удалениеToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.D))); + this.удалениеToolStripMenuItem.Size = new System.Drawing.Size(311, 34); + this.удалениеToolStripMenuItem.Text = "Удаление"; + this.удалениеToolStripMenuItem.Click += new System.EventHandler(this.удалениеToolStripMenuItem_Click); + // + // отчетыToolStripMenuItem + // + this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ОтзывыToolStripMenuItem, + this.ОтчетпоклиентамExcelToolStripMenuItem, + this.отчетСДиаграммойToolStripMenuItem}); + this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(88, 29); + this.отчетыToolStripMenuItem.Text = "Отчеты"; + // + // ОтзывыToolStripMenuItem + // + this.ОтзывыToolStripMenuItem.Name = "ОтзывыToolStripMenuItem"; + this.ОтзывыToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); + this.ОтзывыToolStripMenuItem.Size = new System.Drawing.Size(344, 34); + this.ОтзывыToolStripMenuItem.Text = "Отзывы о покупках"; + this.ОтзывыToolStripMenuItem.Click += new System.EventHandler(this.ОтзывыToolStripMenuItem_Click); + // + // ОтчетпоклиентамExcelToolStripMenuItem + // + this.ОтчетпоклиентамExcelToolStripMenuItem.Name = "ОтчетпоклиентамExcelToolStripMenuItem"; + this.ОтчетпоклиентамExcelToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.T))); + this.ОтчетпоклиентамExcelToolStripMenuItem.Size = new System.Drawing.Size(344, 34); + this.ОтчетпоклиентамExcelToolStripMenuItem.Text = "Отчет по клиентам"; + this.ОтчетпоклиентамExcelToolStripMenuItem.Click += new System.EventHandler(this.ОтчетпоклиентамExcelToolStripMenuItem_Click); + // + // отчетСДиаграммойToolStripMenuItem + // + this.отчетСДиаграммойToolStripMenuItem.Name = "отчетСДиаграммойToolStripMenuItem"; + this.отчетСДиаграммойToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C))); + this.отчетСДиаграммойToolStripMenuItem.Size = new System.Drawing.Size(344, 34); + this.отчетСДиаграммойToolStripMenuItem.Text = "Отчет с диаграммой"; + this.отчетСДиаграммойToolStripMenuItem.Click += new System.EventHandler(this.отчетСДиаграммойToolStripMenuItem_Click); + // + // статусыToolStripMenuItem + // + this.статусыToolStripMenuItem.Name = "статусыToolStripMenuItem"; + this.статусыToolStripMenuItem.Size = new System.Drawing.Size(92, 29); + this.статусыToolStripMenuItem.Text = "Статусы"; + this.статусыToolStripMenuItem.Click += new System.EventHandler(this.статусыToolStripMenuItem_Click); + // + // controlDataTreeTable + // + this.controlDataTreeTable.Dock = System.Windows.Forms.DockStyle.Fill; + this.controlDataTreeTable.Location = new System.Drawing.Point(0, 33); + this.controlDataTreeTable.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.controlDataTreeTable.Name = "controlDataTreeTable"; + this.controlDataTreeTable.Size = new System.Drawing.Size(800, 417); + this.controlDataTreeTable.TabIndex = 1; + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormMain"; + this.Controls.Add(this.controlDataTreeTable); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.Text = "Основная форма"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem СозданиеToolStripMenuItem; + private ToolStripMenuItem редToolStripMenuItem; + private ToolStripMenuItem удалениеToolStripMenuItem; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem ОтзывыToolStripMenuItem; + private ToolStripMenuItem ОтчетпоклиентамExcelToolStripMenuItem; + private ToolStripMenuItem отчетСДиаграммойToolStripMenuItem; + private ToolStripMenuItem статусыToolStripMenuItem; + private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartPieExcel componentDocumentWithChartPieExcel; + private WinFormsLibrary.WordText wordText; + private ControlsLibraryNet60.Data.ControlDataTreeTable controlDataTreeTable; + private Components.Nonvisual.UserControlConfigurableTableDocument userControlConfigurableTableDocument; } } \ No newline at end of file diff --git a/ClientRecordView/FormMain.cs b/ClientRecordView/FormMain.cs index ea3846f..eb20afb 100644 --- a/ClientRecordView/FormMain.cs +++ b/ClientRecordView/FormMain.cs @@ -1,20 +1,219 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; +using ClientRecordContracts.BindingModels; +using ClientRecordContracts.BusinessLogicContracts; +using ClientRecordContracts.ViewModels; +using ComponentsLibraryNet60.DocumentWithTable; +using ComponentsLibraryNet60.Models; +using ControlsLibraryNet60.Data; +using ControlsLibraryNet60.Models; +using DocumentFormat.OpenXml.Spreadsheet; using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using WinFormsLibrary.NonVisualComponents.Helpers; namespace ClientRecordView { public partial class FormMain : Form { - public FormMain() + private readonly IClientLogic _logic; + public FormMain(IClientLogic clientLogic) { InitializeComponent(); + _logic = clientLogic; + + var nodeNames = new Queue(); + nodeNames.Enqueue("Status"); + nodeNames.Enqueue("AmountString"); + nodeNames.Enqueue("Id"); + nodeNames.Enqueue("ClientFIO"); + controlDataTreeTable.LoadConfig(new DataTreeNodeConfig { NodeNames = nodeNames}); + + } + + private void LoadData() + { + controlDataTreeTable.Clear(); + var clients = _logic.ReadList(null); + if (clients != null) + { + foreach (var client in clients) + { + client.AmountString = client.Amount?.ToString() ?? "Нет"; + } + controlDataTreeTable.AddTable(clients); + } + } + + private void СозданиеToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClient)); + if (service is FormClient form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void редToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClient)); + if (service is FormClient form) + { + var selected = controlDataTreeTable.GetSelectedObject(); + if (selected == null) + return; + form.Id = selected.Id; + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void удалениеToolStripMenuItem_Click(object sender, EventArgs e) + { + var selected = controlDataTreeTable.GetSelectedObject(); + if (selected == null) + return; + if (MessageBox.Show("Удалить запись?", "", MessageBoxButtons.YesNo) == DialogResult.Yes) + { + if (_logic.Delete(new ClientBindingModel { Id = selected.Id })) + { + LoadData(); + } + } + } + + private void ОтзывыToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog + { + Filter = "docx|*.docx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + var clients = _logic.ReadList(null) ?? throw new Exception("Не удалось получить список клиентов"); + List paragraphs = new(); + foreach (var client in clients) + { + if (client.Amount != null) + { + paragraphs.Add($"{client.ClientFIO}: {(string.IsNullOrWhiteSpace(client.ClientFIO) ? "Отзывы отсутствуют" : client.Reviews)}"); + } + } + wordText.CreateWordText(new LongWordInfo() + { + Path = dialog.FileName, + Title = "Клиенты, совершашие покупки", + Paragraphs = paragraphs.ToArray() + }); + MessageBox.Show("Готово!"); + } + catch (Exception ex) + { + MessageBox.Show("Произошла ошибка: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ОтчетпоклиентамExcelToolStripMenuItem_Click(object sender, EventArgs e) + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + using var dialog = new SaveFileDialog + { + Filter = "PDF Files|*.pdf" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + var clients = _logic.ReadList(null) ?? throw new Exception("Не удалось получить список аккаунтов"); + foreach (var account in clients) + { + account.AmountString = account.Amount?.ToString() ?? "нет"; + } + userControlConfigurableTableDocument.SaveToDocument( + dialog.FileName, + "Учет клиентов", + new List<(double , string Header, string PropertyName)> + { + (1, "Id", "Id"), + (3, "ФИО", "ClientFIO"), + (2, "Статус", "Status"), + (3, "Сумма", "AmountString") + }, + 2, + 2, + clients.OrderBy(x => x.Id).ToList() + ); + MessageBox.Show("Готово!"); + } + catch (Exception ex) + { + MessageBox.Show("Произошла ошибка: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void отчетСДиаграммойToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog + { + Filter = "Excel Files|*.xlsx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + var clients = _logic.ReadList(null) ?? throw new Exception("Не удалось получить список клиентов"); + var statusMapping = new List(); + var data = new Dictionary> + { + { + "Клиенты", + clients + .Where(x => x.Status != null) + .GroupBy(x => x.Status) + .Select((group, index) => + { + statusMapping.Add($"{group.Key} - {index + 1}"); + + return (Date: index + 1, Value: (double)group.Count()); + }) + .ToList() + } + }; + componentDocumentWithChartPieExcel.CreateDoc(new ComponentDocumentWithChartConfig + { + FilePath = dialog.FileName, + Header = $"Клиенты, совершавшие покупки, по статусам ({string.Join(", ", statusMapping)})", + ChartTitle = "Круговая диаграмма", + LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom, + Data = data + }); + MessageBox.Show("Готово!"); + } + catch (Exception ex) + { + MessageBox.Show("Произошла ошибка: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void статусыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStatuses)); + if (service is FormStatuses form) + { + form.ShowDialog(); + } + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); } } } diff --git a/ClientRecordView/FormMain.resx b/ClientRecordView/FormMain.resx index 1af7de1..f1e3bbe 100644 --- a/ClientRecordView/FormMain.resx +++ b/ClientRecordView/FormMain.resx @@ -1,64 +1,4 @@ - - - + @@ -117,4 +57,19 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 302, 17 + + + 295, 49 + + + 424, 49 + + + 112 + \ No newline at end of file diff --git a/ClientRecordView/FormStatuses.Designer.cs b/ClientRecordView/FormStatuses.Designer.cs index dcdd014..0b8f0eb 100644 --- a/ClientRecordView/FormStatuses.Designer.cs +++ b/ClientRecordView/FormStatuses.Designer.cs @@ -28,12 +28,65 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.NameCol = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.NameCol, + this.Id}); + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(4); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(800, 450); + this.dataGridView.TabIndex = 1; + this.dataGridView.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellValueChanged); + this.dataGridView.UserDeletingRow += new System.Windows.Forms.DataGridViewRowCancelEventHandler(this.dataGridView_UserDeletingRow); + this.dataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dataGridView_KeyDown); + this.dataGridView.KeyUp += new System.Windows.Forms.KeyEventHandler(this.dataGridView_KeyUp); + // + // NameCol + // + this.NameCol.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.NameCol.HeaderText = "Название"; + this.NameCol.MinimumWidth = 6; + this.NameCol.Name = "NameCol"; + // + // Id + // + this.Id.HeaderText = "Id"; + this.Id.MinimumWidth = 6; + this.Id.Name = "Id"; + this.Id.Visible = false; + this.Id.Width = 6; + // + // FormStatuses + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormStatuse"; + this.Controls.Add(this.dataGridView); + this.Name = "FormStatuses"; + this.Text = "Статусы"; + this.Load += new System.EventHandler(this.FormStatuses_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + } #endregion + + private DataGridView dataGridView; + private DataGridViewTextBoxColumn NameCol; + private DataGridViewTextBoxColumn Id; } } \ No newline at end of file diff --git a/ClientRecordView/FormStatuses.cs b/ClientRecordView/FormStatuses.cs index 053e35f..79d2263 100644 --- a/ClientRecordView/FormStatuses.cs +++ b/ClientRecordView/FormStatuses.cs @@ -1,20 +1,109 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using ClientRecordContracts.BindingModels; +using ClientRecordContracts.BusinessLogicContracts; +using ClientRecordContracts.SearchModels; namespace ClientRecordView { public partial class FormStatuses : Form { - public FormStatuses() + private readonly IStatusLogic _logic; + + private bool dataLoading = false; + public FormStatuses(IStatusLogic statusLogic) { InitializeComponent(); + _logic = statusLogic; + } + + private void FormStatuses_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + dataLoading = true; + try + { + var list = _logic.ReadList(null); + if (list != null) + { + foreach (var role in list) + { + int rowIndex = dataGridView.Rows.Add(); + dataGridView.Rows[rowIndex].Cells[0].Value = role.Name; + dataGridView.Rows[rowIndex].Cells[1].Value = role.Id; + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + finally + { + dataLoading = false; + } + } + + private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) + { + if (dataLoading || e.RowIndex < 0 || e.ColumnIndex != 0) + return; + if (dataGridView.Rows[e.RowIndex].Cells[1].Value != null) + { + var name = dataGridView.Rows[e.RowIndex].Cells[0].Value?.ToString() + ?? throw new Exception("Не заполнено название статуса"); + _logic.Update(new StatusBindingModel { Id = Convert.ToInt32(dataGridView.Rows[e.RowIndex].Cells[1].Value), Name = name }); + } + else + { + var name = dataGridView.Rows[e.RowIndex].Cells[0].Value?.ToString() + ?? throw new Exception("Не заполнено название статуса"); + _logic.Create(new StatusBindingModel { 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; + } + } + + private void dataGridView_KeyUp(object sender, KeyEventArgs e) + { + switch (e.KeyCode) + { + case Keys.Insert: + dataGridView.Rows.Add(); + break; + } + } + + private void DeleteRows(DataGridViewSelectedRowCollection rows) + { + for (int i = 0; i < rows.Count; i++) + { + DataGridViewRow row = rows[i]; + if (row.IsNewRow) + continue; + if (row.Cells[1].Value != null && !_logic.Delete(new StatusBindingModel { Id = Convert.ToInt32(row.Cells[1].Value), Name = row.Cells[0].Value?.ToString() })) + throw new Exception($"Ошибка удаления строки: {row.Cells[0].Value}"); + dataGridView.Rows.Remove(row); + } + } + + private void dataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) + { + e.Cancel = true; + if (dataGridView.SelectedRows == null) + return; + if (MessageBox.Show("Удалить записи?", "Подтвердите действие", MessageBoxButtons.YesNo) == DialogResult.No) + return; + DeleteRows(dataGridView.SelectedRows); + } + + private void dataGridView_KeyDown(object sender, KeyEventArgs e) + { + + } } } diff --git a/ClientRecordView/FormStatuses.resx b/ClientRecordView/FormStatuses.resx index 1af7de1..d220d6c 100644 --- a/ClientRecordView/FormStatuses.resx +++ b/ClientRecordView/FormStatuses.resx @@ -1,64 +1,4 @@ - - - + @@ -117,4 +57,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + \ No newline at end of file diff --git a/WinFormsLibrary/VisualComponent/DropDownList.Designer.cs b/WinFormsLibrary/VisualComponent/DropDownList.Designer.cs index 0337b6e..37df086 100644 --- a/WinFormsLibrary/VisualComponent/DropDownList.Designer.cs +++ b/WinFormsLibrary/VisualComponent/DropDownList.Designer.cs @@ -29,43 +29,31 @@ private void InitializeComponent() { this.comboBox = new System.Windows.Forms.ComboBox(); - this.labelDropDownList = new System.Windows.Forms.Label(); this.SuspendLayout(); // // comboBox // - this.comboBox.FormattingEnabled = true; - this.comboBox.Location = new System.Drawing.Point(3, 60); + this.comboBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.comboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox.Location = new System.Drawing.Point(0, 0); this.comboBox.Name = "comboBox"; - this.comboBox.Size = new System.Drawing.Size(182, 33); + this.comboBox.Size = new System.Drawing.Size(199, 33); this.comboBox.TabIndex = 0; this.comboBox.SelectedIndexChanged += new System.EventHandler(this.comboBox_SelectedIndexChanged); // - // labelDropDownList - // - this.labelDropDownList.AutoSize = true; - this.labelDropDownList.Location = new System.Drawing.Point(3, 12); - this.labelDropDownList.Name = "labelDropDownList"; - this.labelDropDownList.Size = new System.Drawing.Size(184, 25); - this.labelDropDownList.TabIndex = 1; - this.labelDropDownList.Text = "Выпадающий список"; - // // DropDownList // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.labelDropDownList); this.Controls.Add(this.comboBox); this.Name = "DropDownList"; - this.Size = new System.Drawing.Size(199, 105); + this.Size = new System.Drawing.Size(199, 34); this.ResumeLayout(false); - this.PerformLayout(); } #endregion private ComboBox comboBox; - private Label labelDropDownList; } } diff --git a/WinFormsLibrary/VisualComponent/EmailTextBox.Designer.cs b/WinFormsLibrary/VisualComponent/EmailTextBox.Designer.cs index 4818796..ed3d2ac 100644 --- a/WinFormsLibrary/VisualComponent/EmailTextBox.Designer.cs +++ b/WinFormsLibrary/VisualComponent/EmailTextBox.Designer.cs @@ -38,7 +38,7 @@ // this.textBoxEmail.Location = new System.Drawing.Point(0, 55); this.textBoxEmail.Name = "textBoxEmail"; - this.textBoxEmail.Size = new System.Drawing.Size(181, 31); + this.textBoxEmail.Size = new System.Drawing.Size(209, 31); this.textBoxEmail.TabIndex = 0; this.textBoxEmail.TextChanged += new System.EventHandler(this.textBoxEmail_TextChanged); this.textBoxEmail.MouseEnter += new System.EventHandler(this.textBoxEmail_MouseEnter); @@ -48,9 +48,9 @@ this.labelEmail.AutoSize = true; this.labelEmail.Location = new System.Drawing.Point(3, 6); this.labelEmail.Name = "labelEmail"; - this.labelEmail.Size = new System.Drawing.Size(129, 25); + this.labelEmail.Size = new System.Drawing.Size(62, 25); this.labelEmail.TabIndex = 1; - this.labelEmail.Text = "Введите почту"; + this.labelEmail.Text = "Почта"; // // EmailTextBox // @@ -59,7 +59,7 @@ this.Controls.Add(this.labelEmail); this.Controls.Add(this.textBoxEmail); this.Name = "EmailTextBox"; - this.Size = new System.Drawing.Size(209, 118); + this.Size = new System.Drawing.Size(185, 86); this.ResumeLayout(false); this.PerformLayout(); diff --git a/WinFormsLibrary/WinFormsLibraryRazubaev.csproj b/WinFormsLibrary/WinFormsLibraryRazubaev.csproj index 9abf70a..80da30c 100644 --- a/WinFormsLibrary/WinFormsLibraryRazubaev.csproj +++ b/WinFormsLibrary/WinFormsLibraryRazubaev.csproj @@ -5,6 +5,7 @@ enable true enable + True