diff --git a/project/ProjectTourAgency/Enities/Receipt.cs b/project/ProjectTourAgency/Enities/Receipt.cs index f160c77..2efef05 100644 --- a/project/ProjectTourAgency/Enities/Receipt.cs +++ b/project/ProjectTourAgency/Enities/Receipt.cs @@ -12,18 +12,19 @@ public class Receipt { public int ClientId { get; private set; } public DateTime Date { get; private set; } - public int Duration { get; private set; } public int TourId { get; private set; } - public int FinalCost { get; private set; } - public static Receipt CreateEntity(int clientId, int tourId, int duration, int finalCost) + public int DiscountId { get; private set; } + public decimal FinalCost { get; private set; } + + public static Receipt CreateEntity(int clientId, int tourId,int discountId, decimal finalCost) { return new Receipt { ClientId = clientId, TourId = tourId, + DiscountId = discountId, Date = DateTime.Now, - Duration = duration, FinalCost = finalCost }; diff --git a/project/ProjectTourAgency/Forms/FormReceipt.Designer.cs b/project/ProjectTourAgency/Forms/FormReceipt.Designer.cs new file mode 100644 index 0000000..e2320c1 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormReceipt.Designer.cs @@ -0,0 +1,167 @@ +namespace ProjectTourAgency.Forms +{ + partial class FormReceipt + { + /// + /// 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() + { + labelCLientId = new Label(); + labelTourId = new Label(); + labelDIscountId = new Label(); + label1 = new Label(); + textBoxFinalCost = new TextBox(); + comboBoxClientId = new ComboBox(); + comboBoxDIscountId = new ComboBox(); + comboBoxTourId = new ComboBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelCLientId + // + labelCLientId.AutoSize = true; + labelCLientId.Location = new Point(12, 29); + labelCLientId.Name = "labelCLientId"; + labelCLientId.Size = new Size(142, 15); + labelCLientId.TabIndex = 0; + labelCLientId.Text = "Идентификатор Клиента"; + // + // labelTourId + // + labelTourId.AutoSize = true; + labelTourId.Location = new Point(12, 73); + labelTourId.Name = "labelTourId"; + labelTourId.Size = new Size(122, 15); + labelTourId.TabIndex = 1; + labelTourId.Text = "Идентификатор Тура"; + // + // labelDIscountId + // + labelDIscountId.AutoSize = true; + labelDIscountId.Location = new Point(12, 118); + labelDIscountId.Name = "labelDIscountId"; + labelDIscountId.Size = new Size(137, 15); + labelDIscountId.TabIndex = 2; + labelDIscountId.Text = "Идентификатор Скидки"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 156); + label1.Name = "label1"; + label1.Size = new Size(95, 15); + label1.TabIndex = 3; + label1.Text = "Сумма к опалет"; + // + // textBoxFinalCost + // + textBoxFinalCost.Location = new Point(160, 153); + textBoxFinalCost.Name = "textBoxFinalCost"; + textBoxFinalCost.Size = new Size(100, 23); + textBoxFinalCost.TabIndex = 4; + // + // comboBoxClientId + // + comboBoxClientId.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxClientId.FormattingEnabled = true; + comboBoxClientId.Location = new Point(160, 26); + comboBoxClientId.Name = "comboBoxClientId"; + comboBoxClientId.Size = new Size(121, 23); + comboBoxClientId.TabIndex = 5; + // + // comboBoxDIscountId + // + comboBoxDIscountId.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxDIscountId.FormattingEnabled = true; + comboBoxDIscountId.Location = new Point(160, 110); + comboBoxDIscountId.Name = "comboBoxDIscountId"; + comboBoxDIscountId.Size = new Size(121, 23); + comboBoxDIscountId.TabIndex = 6; + // + // comboBoxTourId + // + comboBoxTourId.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxTourId.FormattingEnabled = true; + comboBoxTourId.Location = new Point(160, 65); + comboBoxTourId.Name = "comboBoxTourId"; + comboBoxTourId.Size = new Size(121, 23); + comboBoxTourId.TabIndex = 7; + // + // buttonCancel + // + buttonCancel.Location = new Point(250, 211); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 15; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(57, 211); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 14; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // FormReceipt + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(361, 254); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(comboBoxTourId); + Controls.Add(comboBoxDIscountId); + Controls.Add(comboBoxClientId); + Controls.Add(textBoxFinalCost); + Controls.Add(label1); + Controls.Add(labelDIscountId); + Controls.Add(labelTourId); + Controls.Add(labelCLientId); + Name = "FormReceipt"; + Text = "FormReceipt"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelCLientId; + private Label labelTourId; + private Label labelDIscountId; + private Label label1; + private TextBox textBoxFinalCost; + private ComboBox comboBoxClientId; + private ComboBox comboBoxDIscountId; + private ComboBox comboBoxTourId; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/project/ProjectTourAgency/Forms/FormReceipt.cs b/project/ProjectTourAgency/Forms/FormReceipt.cs new file mode 100644 index 0000000..f1db7c1 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormReceipt.cs @@ -0,0 +1,68 @@ +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 FormReceipt : Form +{ + private readonly IReceiptRepository _receiptRepository; + public FormReceipt(IReceiptRepository receiptRepository, + IClientRepository clientRepository, + ITourRepository tourRepository, + IDiscountRepository discountRepository) + { + InitializeComponent(); + _receiptRepository = receiptRepository ?? + throw new ArgumentNullException(nameof(receiptRepository)); + comboBoxClientId.DataSource = clientRepository.ReadClients(); + comboBoxClientId.DisplayMember = "FullName"; + comboBoxClientId.ValueMember = "Id"; + + comboBoxTourId.DataSource = tourRepository.ReadTours(); + comboBoxTourId.DisplayMember = "Destination"; + comboBoxTourId.ValueMember = "Id"; + + comboBoxDIscountId.DataSource = discountRepository.ReadDiscounts(); + comboBoxDIscountId.DisplayMember = "DiscountPercent"; + comboBoxDIscountId.ValueMember = "Id"; + } + + private void buttonSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxClientId.SelectedIndex < 0 || + comboBoxDIscountId.SelectedIndex < 0 || + comboBoxTourId.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля"); + } + + var selectedTour = (Tour)comboBoxTourId.SelectedItem; + var selectedDiscount = (Discount)comboBoxDIscountId.SelectedItem; + + decimal finalCost = selectedTour.Cost - (selectedTour.Cost * (selectedDiscount.DiscountPercent /100)); + textBoxFinalCost.Text = finalCost.ToString(); + + + _receiptRepository.CreateReceipt(Receipt.CreateEntity( (int)(comboBoxClientId.SelectedValue!), (int)(comboBoxTourId.SelectedValue!), (int)(comboBoxDIscountId.SelectedValue!),Convert.ToDecimal(finalCost))); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) => Close(); +} diff --git a/project/ProjectTourAgency/Forms/FormReceipt.resx b/project/ProjectTourAgency/Forms/FormReceipt.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/project/ProjectTourAgency/Forms/FormReceipt.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/FormTour.Designer.cs b/project/ProjectTourAgency/Forms/FormTour.Designer.cs index df8a697..97209a8 100644 --- a/project/ProjectTourAgency/Forms/FormTour.Designer.cs +++ b/project/ProjectTourAgency/Forms/FormTour.Designer.cs @@ -128,7 +128,7 @@ buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(75, 23); buttonSave.TabIndex = 12; - buttonSave.Text = "button1"; + buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; buttonSave.Click += buttonSave_Click; // @@ -138,7 +138,7 @@ buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(75, 23); buttonCancel.TabIndex = 13; - buttonCancel.Text = "button2"; + buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += buttonCancel_Click; //