Создание формы топлива

This commit is contained in:
Павел Ладягин 2024-11-17 16:16:03 +04:00
parent f3befed5dd
commit 123401c619
5 changed files with 366 additions and 21 deletions

View File

@ -29,8 +29,8 @@
private void InitializeComponent()
{
checkedListBoxDriverLicense = new CheckedListBox();
buttonDriverCancel = new Button();
buttonDriverSave = new Button();
buttonCancel = new Button();
buttonCarSave = new Button();
label3 = new Label();
textBoxCarModel = new TextBox();
label2 = new Label();
@ -51,23 +51,25 @@
checkedListBoxDriverLicense.Size = new Size(140, 94);
checkedListBoxDriverLicense.TabIndex = 17;
//
// buttonDriverCancel
// buttonCancel
//
buttonDriverCancel.Location = new Point(172, 232);
buttonDriverCancel.Name = "buttonDriverCancel";
buttonDriverCancel.Size = new Size(75, 23);
buttonDriverCancel.TabIndex = 16;
buttonDriverCancel.Text = "Отмена";
buttonDriverCancel.UseVisualStyleBackColor = true;
buttonCancel.Location = new Point(172, 232);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 23);
buttonCancel.TabIndex = 16;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// buttonDriverSave
// buttonCarSave
//
buttonDriverSave.Location = new Point(9, 232);
buttonDriverSave.Name = "buttonDriverSave";
buttonDriverSave.Size = new Size(75, 23);
buttonDriverSave.TabIndex = 15;
buttonDriverSave.Text = "Сохранить";
buttonDriverSave.UseVisualStyleBackColor = true;
buttonCarSave.Location = new Point(9, 232);
buttonCarSave.Name = "buttonCarSave";
buttonCarSave.Size = new Size(75, 23);
buttonCarSave.TabIndex = 15;
buttonCarSave.Text = "Сохранить";
buttonCarSave.UseVisualStyleBackColor = true;
buttonCarSave.Click += ButtonCarSave_Click;
//
// label3
//
@ -157,8 +159,8 @@
Controls.Add(label4);
Controls.Add(comboBoxCarType);
Controls.Add(checkedListBoxDriverLicense);
Controls.Add(buttonDriverCancel);
Controls.Add(buttonDriverSave);
Controls.Add(buttonCancel);
Controls.Add(buttonCarSave);
Controls.Add(label3);
Controls.Add(textBoxCarModel);
Controls.Add(label2);
@ -174,8 +176,8 @@
#endregion
private CheckedListBox checkedListBoxDriverLicense;
private Button buttonDriverCancel;
private Button buttonDriverSave;
private Button buttonCancel;
private Button buttonCarSave;
private Label label3;
private TextBox textBoxCarModel;
private Label label2;

View File

@ -0,0 +1,151 @@
namespace FuelAndLubricants.Forms
{
partial class FormFuel
{
/// <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()
{
label5 = new Label();
numericUpDownPrice = new NumericUpDown();
buttonCancel = new Button();
buttonFuelSave = new Button();
label1 = new Label();
comboBoxFuelType = new ComboBox();
label2 = new Label();
numericUpDownAmount = new NumericUpDown();
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownAmount).BeginInit();
SuspendLayout();
//
// label5
//
label5.AutoSize = true;
label5.Location = new Point(7, 40);
label5.Name = "label5";
label5.Size = new Size(78, 15);
label5.TabIndex = 33;
label5.Text = "Цена за литр";
//
// numericUpDownPrice
//
numericUpDownPrice.DecimalPlaces = 2;
numericUpDownPrice.Location = new Point(105, 38);
numericUpDownPrice.Minimum = new decimal(new int[] { 1, 0, 0, 131072 });
numericUpDownPrice.Name = "numericUpDownPrice";
numericUpDownPrice.Size = new Size(140, 23);
numericUpDownPrice.TabIndex = 32;
numericUpDownPrice.Value = new decimal(new int[] { 1, 0, 0, 131072 });
//
// buttonCancel
//
buttonCancel.Location = new Point(170, 106);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 23);
buttonCancel.TabIndex = 28;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// buttonFuelSave
//
buttonFuelSave.Location = new Point(7, 106);
buttonFuelSave.Name = "buttonFuelSave";
buttonFuelSave.Size = new Size(75, 23);
buttonFuelSave.TabIndex = 27;
buttonFuelSave.Text = "Сохранить";
buttonFuelSave.UseVisualStyleBackColor = true;
buttonFuelSave.Click += ButtonFuelSave_Click;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(7, 12);
label1.Name = "label1";
label1.Size = new Size(75, 15);
label1.TabIndex = 35;
label1.Text = "Тип топлива";
//
// comboBoxFuelType
//
comboBoxFuelType.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxFuelType.FormattingEnabled = true;
comboBoxFuelType.Location = new Point(105, 9);
comboBoxFuelType.Name = "comboBoxFuelType";
comboBoxFuelType.Size = new Size(140, 23);
comboBoxFuelType.TabIndex = 34;
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(7, 69);
label2.Name = "label2";
label2.Size = new Size(72, 15);
label2.TabIndex = 37;
label2.Text = "Количество";
//
// numericUpDownAmount
//
numericUpDownAmount.DecimalPlaces = 2;
numericUpDownAmount.Location = new Point(105, 67);
numericUpDownAmount.Minimum = new decimal(new int[] { 1, 0, 0, 131072 });
numericUpDownAmount.Name = "numericUpDownAmount";
numericUpDownAmount.Size = new Size(140, 23);
numericUpDownAmount.TabIndex = 36;
numericUpDownAmount.Value = new decimal(new int[] { 1, 0, 0, 131072 });
//
// FormFuel
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(256, 136);
Controls.Add(label2);
Controls.Add(numericUpDownAmount);
Controls.Add(label1);
Controls.Add(comboBoxFuelType);
Controls.Add(label5);
Controls.Add(numericUpDownPrice);
Controls.Add(buttonCancel);
Controls.Add(buttonFuelSave);
Name = "FormFuel";
Text = "FormFuel";
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownAmount).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label5;
private NumericUpDown numericUpDownPrice;
private Button buttonCancel;
private Button buttonFuelSave;
private Label label1;
private ComboBox comboBoxFuelType;
private Label label2;
private NumericUpDown numericUpDownAmount;
}
}

View File

@ -0,0 +1,72 @@
using FuelAndLubricants.Entities;
using FuelAndLubricants.Entities.Enums;
using FuelAndLubricants.Repositories;
namespace FuelAndLubricants.Forms
{
public partial class FormFuel : Form
{
private readonly IFuelRepository _fuelRepository;
private int? _fuelId;
public int Id
{
set
{
try
{
var fuel = _fuelRepository.ReadFuelByID(value);
if (fuel == null)
throw new InvalidOperationException(nameof(fuel));
comboBoxFuelType.SelectedItem = fuel.Fuel_Type;
numericUpDownPrice.Value = (decimal)fuel.Price_Per_Liter;
numericUpDownAmount.Value = (decimal)fuel.Amount;
_fuelId = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
public FormFuel(IFuelRepository fuelRepository)
{
InitializeComponent();
_fuelRepository = fuelRepository ??
throw new ArgumentNullException(nameof(fuelRepository));
comboBoxFuelType.DataSource = Enum.GetValues(typeof(Fuel_Type));
}
private void ButtonFuelSave_Click(object sender, EventArgs e)
{
try
{
if (comboBoxFuelType.SelectedIndex < 1)
throw new Exception("Имеются незаполненные поля");
if (_fuelId.HasValue)
_fuelRepository.UpdateFuel(CreateFuel(_fuelId.Value));
else
_fuelRepository.CreateFuel(CreateFuel(0));
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private Fuel_And_Lubricants CreateFuel(int id)
{
return Fuel_And_Lubricants.CreateEntity(id, (Fuel_Type)comboBoxFuelType.SelectedItem!, (float)numericUpDownPrice.Value, (float)numericUpDownAmount.Value);
}
}
}

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

@ -8,7 +8,7 @@ public interface IFuelRepository
Fuel_And_Lubricants ReadFuelByID(int id);
void CreateDriver(Fuel_And_Lubricants fuel);
void CreateFuel(Fuel_And_Lubricants fuel);
void UpdateFuel(Fuel_And_Lubricants fuel);