From 80ea9fa153458cb692110021696bf874c84572a9 Mon Sep 17 00:00:00 2001 From: Tonb73 Date: Sun, 10 Nov 2024 13:31:10 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B8=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20Discount=20=D0=B8=20D?= =?UTF-8?q?iscounts=20=D0=B8=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BD=D0=B8=D1=85.=20=D0=9D=D0=B5=D0=BC?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20=D1=81=D1=83?= =?UTF-8?q?=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20Discount,=20=D1=82=D0=B5?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BE=D0=BD=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=8F=D0=B5=D1=82=D1=81=D1=8F=20=D0=BA=20?= =?UTF-8?q?=D1=87=D0=B5=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/ProjectTourAgency/Enities/Discount.cs | 8 +- .../Forms/FormClients.Designer.cs | 8 +- .../ProjectTourAgency/Forms/FormClients.cs | 2 +- .../Forms/FormDiscount.Designer.cs | 122 +++++++++++++++++ .../ProjectTourAgency/Forms/FormDiscount.cs | 81 ++++++++++++ .../ProjectTourAgency/Forms/FormDiscount.resx | 120 +++++++++++++++++ .../Forms/FormDiscounts.Designer.cs | 125 ++++++++++++++++++ .../ProjectTourAgency/Forms/FormDiscounts.cs | 110 +++++++++++++++ .../Forms/FormDiscounts.resx | 120 +++++++++++++++++ .../Forms/FormTours.Designer.cs | 8 +- .../Implementations/DiscountRepository.cs | 2 +- 11 files changed, 691 insertions(+), 15 deletions(-) create mode 100644 project/ProjectTourAgency/Forms/FormDiscount.Designer.cs create mode 100644 project/ProjectTourAgency/Forms/FormDiscount.cs create mode 100644 project/ProjectTourAgency/Forms/FormDiscount.resx create mode 100644 project/ProjectTourAgency/Forms/FormDiscounts.Designer.cs create mode 100644 project/ProjectTourAgency/Forms/FormDiscounts.cs create mode 100644 project/ProjectTourAgency/Forms/FormDiscounts.resx diff --git a/project/ProjectTourAgency/Enities/Discount.cs b/project/ProjectTourAgency/Enities/Discount.cs index bc5b181..30e99fe 100644 --- a/project/ProjectTourAgency/Enities/Discount.cs +++ b/project/ProjectTourAgency/Enities/Discount.cs @@ -10,16 +10,14 @@ namespace ProjectTourAgency.Enities; public class Discount { public int Id { get; private set; } - public float DiscountPercent { get; private set; } + public decimal DiscountPercent { get; private set; } public ClientSocialStatus ClientSocialStatus { get; private set; } - public int ClientId { get; private set; } - public static Discount CreateEntity(int id, int clientId, - ClientSocialStatus clientSocialStatus,float discountPercent) + public static Discount CreateEntity(int id, + ClientSocialStatus clientSocialStatus,decimal discountPercent) { return new Discount { Id = id, - ClientId = clientId, ClientSocialStatus = clientSocialStatus, DiscountPercent = discountPercent }; diff --git a/project/ProjectTourAgency/Forms/FormClients.Designer.cs b/project/ProjectTourAgency/Forms/FormClients.Designer.cs index cf905fa..f9bfecd 100644 --- a/project/ProjectTourAgency/Forms/FormClients.Designer.cs +++ b/project/ProjectTourAgency/Forms/FormClients.Designer.cs @@ -43,9 +43,9 @@ panel1.Controls.Add(buttonUpdate); panel1.Controls.Add(buttonAdd); panel1.Dock = DockStyle.Right; - panel1.Location = new Point(778, 0); + panel1.Location = new Point(775, 0); panel1.Name = "panel1"; - panel1.Size = new Size(149, 378); + panel1.Size = new Size(149, 371); panel1.TabIndex = 0; // // buttonDelete @@ -96,14 +96,14 @@ dataGridViewData.ReadOnly = true; dataGridViewData.RowHeadersVisible = false; dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridViewData.Size = new Size(778, 378); + dataGridViewData.Size = new Size(775, 371); dataGridViewData.TabIndex = 1; // // FormClients // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(927, 378); + ClientSize = new Size(924, 371); Controls.Add(dataGridViewData); Controls.Add(panel1); Name = "FormClients"; diff --git a/project/ProjectTourAgency/Forms/FormClients.cs b/project/ProjectTourAgency/Forms/FormClients.cs index 109c5e2..b557f14 100644 --- a/project/ProjectTourAgency/Forms/FormClients.cs +++ b/project/ProjectTourAgency/Forms/FormClients.cs @@ -46,7 +46,7 @@ namespace ProjectTourAgency.Forms } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка рот добавлении", MessageBoxButtons.OK,MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK,MessageBoxIcon.Error); } } diff --git a/project/ProjectTourAgency/Forms/FormDiscount.Designer.cs b/project/ProjectTourAgency/Forms/FormDiscount.Designer.cs new file mode 100644 index 0000000..723c0c4 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormDiscount.Designer.cs @@ -0,0 +1,122 @@ +namespace ProjectTourAgency.Forms +{ + partial class FormDiscount + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelDiscount = new Label(); + comboBoxSocialStatus = new ComboBox(); + labelSocialStatus = new Label(); + buttonCancel = new Button(); + buttonSave = new Button(); + numericUpDownDiscount = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)numericUpDownDiscount).BeginInit(); + SuspendLayout(); + // + // labelDiscount + // + labelDiscount.AutoSize = true; + labelDiscount.Location = new Point(25, 82); + labelDiscount.Name = "labelDiscount"; + labelDiscount.Size = new Size(88, 15); + labelDiscount.TabIndex = 0; + labelDiscount.Text = "Размер скидки"; + // + // comboBoxSocialStatus + // + comboBoxSocialStatus.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSocialStatus.FormattingEnabled = true; + comboBoxSocialStatus.Location = new Point(182, 33); + comboBoxSocialStatus.Name = "comboBoxSocialStatus"; + comboBoxSocialStatus.Size = new Size(121, 23); + comboBoxSocialStatus.TabIndex = 13; + // + // labelSocialStatus + // + labelSocialStatus.AutoSize = true; + labelSocialStatus.Location = new Point(25, 33); + labelSocialStatus.Name = "labelSocialStatus"; + labelSocialStatus.Size = new Size(131, 15); + labelSocialStatus.TabIndex = 12; + labelSocialStatus.Text = "Основания для скидки"; + // + // buttonCancel + // + buttonCancel.Location = new Point(228, 139); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 15; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + // + // buttonSave + // + buttonSave.Location = new Point(65, 139); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 14; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + // + // numericUpDownDiscount + // + numericUpDownDiscount.DecimalPlaces = 2; + numericUpDownDiscount.Increment = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDownDiscount.Location = new Point(182, 82); + numericUpDownDiscount.Maximum = new decimal(new int[] { 1, 0, 0, 0 }); + numericUpDownDiscount.Name = "numericUpDownDiscount"; + numericUpDownDiscount.Size = new Size(121, 23); + numericUpDownDiscount.TabIndex = 16; + // + // FormDiscount + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(383, 174); + Controls.Add(numericUpDownDiscount); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(comboBoxSocialStatus); + Controls.Add(labelSocialStatus); + Controls.Add(labelDiscount); + Name = "FormDiscount"; + Text = "FormDiscount"; + ((System.ComponentModel.ISupportInitialize)numericUpDownDiscount).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelDiscount; + private ComboBox comboBoxSocialStatus; + private Label labelSocialStatus; + private Button buttonCancel; + private Button buttonSave; + private NumericUpDown numericUpDownDiscount; + } +} \ No newline at end of file diff --git a/project/ProjectTourAgency/Forms/FormDiscount.cs b/project/ProjectTourAgency/Forms/FormDiscount.cs new file mode 100644 index 0000000..79aae23 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormDiscount.cs @@ -0,0 +1,81 @@ +using ProjectTourAgency.Enities.Enums; +using ProjectTourAgency.Enities; +using ProjectTourAgency.Repositories; +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; + +namespace ProjectTourAgency.Forms; + +public partial class FormDiscount : Form +{ + private readonly IDiscountRepository _discountRepository; + + private int? _discountId; + + public int Id + { + set + { + try + { + var discount = _discountRepository.ReadDiscountById(value); + if (discount == null) + { + throw new InvalidDataException(nameof(discount)); + } + + + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormDiscount(IDiscountRepository discountRepository) + { + InitializeComponent(); + _discountRepository = discountRepository ?? + throw new ArgumentNullException(nameof(discountRepository)); + comboBoxSocialStatus.DataSource = Enum.GetValues(typeof(ClientSocialStatus)); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(numericUpDownDiscount.Text) + || comboBoxSocialStatus.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля"); + } + + if (_discountId.HasValue) + { + _discountRepository.UpdateDiscount(CreateDiscount(_discountId.Value)); + } + else + { + _discountRepository.CreateDiscount(CreateDiscount(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) => Close(); + + private Discount CreateDiscount(int id) => Discount.CreateEntity(id, (ClientSocialStatus)comboBoxSocialStatus.SelectedItem!,numericUpDownDiscount.Value ); +} diff --git a/project/ProjectTourAgency/Forms/FormDiscount.resx b/project/ProjectTourAgency/Forms/FormDiscount.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormDiscount.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/project/ProjectTourAgency/Forms/FormDiscounts.Designer.cs b/project/ProjectTourAgency/Forms/FormDiscounts.Designer.cs new file mode 100644 index 0000000..ddad0af --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormDiscounts.Designer.cs @@ -0,0 +1,125 @@ +namespace ProjectTourAgency.Forms +{ + partial class FormDiscounts + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridViewData = new DataGridView(); + panel1 = new Panel(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + panel1.SuspendLayout(); + SuspendLayout(); + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(775, 371); + dataGridViewData.TabIndex = 3; + // + // panel1 + // + panel1.Controls.Add(buttonDelete); + panel1.Controls.Add(buttonUpdate); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(775, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(149, 371); + panel1.TabIndex = 2; + // + // buttonDelete + // + buttonDelete.BackgroundImage = Properties.Resources.free_icon_delete_3807871; + buttonDelete.BackgroundImageLayout = ImageLayout.Stretch; + buttonDelete.Location = new Point(43, 276); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(61, 59); + buttonDelete.TabIndex = 3; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.BackgroundImage = Properties.Resources.free_icon_edit_8679935; + buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpdate.Location = new Point(43, 142); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(61, 59); + buttonUpdate.TabIndex = 2; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.free_icon_add_button_5974633; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(43, 25); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(61, 59); + buttonAdd.TabIndex = 1; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // FormDiscounts + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(924, 371); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormDiscounts"; + Text = "FormDiscounts"; + Load += FormDiscounts_Load; + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + panel1.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridViewData; + private Panel panel1; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/project/ProjectTourAgency/Forms/FormDiscounts.cs b/project/ProjectTourAgency/Forms/FormDiscounts.cs new file mode 100644 index 0000000..c87aa38 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormDiscounts.cs @@ -0,0 +1,110 @@ +using ProjectTourAgency.Repositories; +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 Unity; + +namespace ProjectTourAgency.Forms +{ + public partial class FormDiscounts : Form + { + private readonly IUnityContainer _container; + + private readonly IDiscountRepository _discountRepository; + + public FormDiscounts(IDiscountRepository discountRepository, IUnityContainer container) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _discountRepository = discountRepository ?? throw new ArgumentNullException(nameof(_discountRepository)); + } + + private void FormDiscounts_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch(Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK,MessageBoxIcon.Error); + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + if(!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if(!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + + if(MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + + try + { + _discountRepository.DeleteDiscount(findId); + LoadList(); + } + catch(Exception ex) + { + MessageBox.Show(ex.Message,"Ошибка при удалении", MessageBoxButtons.OK,MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewData.DataSource = _discountRepository.ReadDiscounts(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if(dataGridViewData.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["ID"].Value); + return true; + } + } +} diff --git a/project/ProjectTourAgency/Forms/FormDiscounts.resx b/project/ProjectTourAgency/Forms/FormDiscounts.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormDiscounts.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/project/ProjectTourAgency/Forms/FormTours.Designer.cs b/project/ProjectTourAgency/Forms/FormTours.Designer.cs index a22f020..62f9d9c 100644 --- a/project/ProjectTourAgency/Forms/FormTours.Designer.cs +++ b/project/ProjectTourAgency/Forms/FormTours.Designer.cs @@ -52,7 +52,7 @@ dataGridViewData.ReadOnly = true; dataGridViewData.RowHeadersVisible = false; dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridViewData.Size = new Size(651, 450); + dataGridViewData.Size = new Size(775, 371); dataGridViewData.TabIndex = 3; // // panel1 @@ -61,9 +61,9 @@ panel1.Controls.Add(buttonUpdate); panel1.Controls.Add(buttonAdd); panel1.Dock = DockStyle.Right; - panel1.Location = new Point(651, 0); + panel1.Location = new Point(775, 0); panel1.Name = "panel1"; - panel1.Size = new Size(149, 450); + panel1.Size = new Size(149, 371); panel1.TabIndex = 2; // // buttonDelete @@ -103,7 +103,7 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(924, 371); Controls.Add(dataGridViewData); Controls.Add(panel1); Name = "FormTours"; diff --git a/project/ProjectTourAgency/Implementations/DiscountRepository.cs b/project/ProjectTourAgency/Implementations/DiscountRepository.cs index 12fd57c..fbe9a2e 100644 --- a/project/ProjectTourAgency/Implementations/DiscountRepository.cs +++ b/project/ProjectTourAgency/Implementations/DiscountRepository.cs @@ -22,7 +22,7 @@ public class DiscountRepository : IDiscountRepository public Discount ReadDiscountById(int id) { - return Discount.CreateEntity(0, 0, 0, 0); + return Discount.CreateEntity(0, 0, 0); } public IEnumerable ReadDiscounts()