Измннили логику форме Receipt для получения итоговой цена автоматически

This commit is contained in:
Tonb73 2024-11-10 14:27:32 +04:00
parent 80ea9fa153
commit 47d6fe77ed
5 changed files with 362 additions and 6 deletions

View File

@ -12,18 +12,19 @@ public class Receipt
{ {
public int ClientId { get; private set; } public int ClientId { get; private set; }
public DateTime Date { get; private set; } public DateTime Date { get; private set; }
public int Duration { get; private set; }
public int TourId { 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 return new Receipt
{ {
ClientId = clientId, ClientId = clientId,
TourId = tourId, TourId = tourId,
DiscountId = discountId,
Date = DateTime.Now, Date = DateTime.Now,
Duration = duration,
FinalCost = finalCost FinalCost = finalCost
}; };

View File

@ -0,0 +1,167 @@
namespace ProjectTourAgency.Forms
{
partial class FormReceipt
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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();
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -128,7 +128,7 @@
buttonSave.Name = "buttonSave"; buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(75, 23); buttonSave.Size = new Size(75, 23);
buttonSave.TabIndex = 12; buttonSave.TabIndex = 12;
buttonSave.Text = "button1"; buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true; buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click; buttonSave.Click += buttonSave_Click;
// //
@ -138,7 +138,7 @@
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 23); buttonCancel.Size = new Size(75, 23);
buttonCancel.TabIndex = 13; buttonCancel.TabIndex = 13;
buttonCancel.Text = "button2"; buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click; buttonCancel.Click += buttonCancel_Click;
// //