Compare commits

...

4 Commits

Author SHA1 Message Date
fe3d9fc978 полностью готовая 2 лаба 2025-01-31 10:14:28 +04:00
b8a0e14aa4 лаб 2 врооде бы все 2024-12-23 16:41:51 +04:00
b5197a4c75 в процессе 2024-12-23 13:06:19 +04:00
260bb1d7f3 лаб1 финиш 2024-12-23 11:33:05 +04:00
78 changed files with 5830 additions and 78 deletions

View File

@ -0,0 +1,27 @@
using ProjectFuel.Entities.Enums;
using ProjectFuel.Entities.Enums;
namespace ProjectFuel.Entities;
public class Car
{
public int Car_ID { get; private set; }
public string Car_Mark { get; private set; } = string.Empty;
public string Car_Model { get; private set; } = string.Empty;
public Car_Type Car_Type { get; private set; }
public Driver_License License { get; private set; }
public float Consumption_Rate { get; private set; }
public static Car CreateEntity(int car_ID, string car_mark, string car_model, Car_Type car_type, Driver_License license, float consumption)
{
return new Car
{
Car_ID = car_ID,
Car_Mark = car_mark ?? string.Empty,
Car_Model = car_model ?? string.Empty,
Car_Type = car_type,
License = license,
Consumption_Rate = consumption
};
}
}

View File

@ -0,0 +1,23 @@
using ProjectFuel.Entities.Enums;
using ProjectFuel.Entities.Enums;
namespace ProjectFuel.Entities;
public class Driver
{
public int Driver_ID { get; private set; }
public string Firstname { get; private set; } = string.Empty;
public string Secondname { get; private set; } = string.Empty;
public Driver_License Driver_License { get; private set; }
public static Driver CreateEntity(int driver_ID, string firstname, string secondname, Driver_License license)
{
return new Driver
{
Driver_ID = driver_ID,
Firstname = firstname ?? string.Empty,
Secondname = secondname ?? string.Empty,
Driver_License = license
};
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectFuel.Entities.Enums;
[Flags]
public enum Driver_License
{
None = 0,
A = 1,
B = 2,
C = 4,
D = 8,
BE = 16,
CE = 32,
}

View File

@ -0,0 +1,10 @@
namespace ProjectFuel.Entities.Enums;
public enum Fuel_Type
{
None = 0,
Petrol = 1,
Diesel = 2
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectFuel.Entities.Enums;
public enum Shift
{
None = 0,
Day = 1,
Night = 2
}

View File

@ -0,0 +1,9 @@
namespace ProjectFuel.Entities.Enums;
public enum Car_Type
{
None = 0,
Passenger = 1,
Cargo = 2,
Bus = 3
}

View File

@ -0,0 +1,22 @@
using ProjectFuel.Entities.Enums;
namespace ProjectFuel.Entities;
public class Fuel
{
public int Fuel_ID { get; private set; }
public Fuel_Type Fuel_Type { get; private set; }
public float Price_Per_Liter { get; private set; }
public float Amount { get; private set; }
public static Fuel CreateEntity(int fuel_id, Fuel_Type type, float price, float amount)
{
return new Fuel
{
Fuel_ID = fuel_id,
Fuel_Type = type,
Price_Per_Liter = price,
Amount = amount
};
}
}

View File

@ -0,0 +1,22 @@
namespace ProjectFuel.Entities;
public class Refill
{
public int Refill_ID { get; private set; }
public DateTime Refill_Date { get; private set; }
public float Refill_Amount { get; private set; }
public int Fuel_ID { get; private set; }
public int Car_ID { get; private set; }
public static Refill CreateOperation(int refill_ID, DateTime refill_date, float refill_amount, int fuel_id, int car_id)
{
return new Refill
{
Refill_ID = refill_ID,
Refill_Date = refill_date,
Refill_Amount = refill_amount,
Fuel_ID = fuel_id,
Car_ID = car_id
};
}
}

View File

@ -0,0 +1,20 @@
namespace ProjectFuel.Entities;
public class Route
{
public int Route_ID { get; private set; }
public string Start_Point { get; private set; } = string.Empty;
public string End_Point { get; private set; } = string.Empty;
public float Route_Length { get; private set; }
public static Route CreateEntity(int route_id, string start_point, string end_point, float length)
{
return new Route
{
Route_ID = route_id,
Start_Point = start_point ?? string.Empty,
End_Point = end_point ?? string.Empty,
Route_Length = length
};
}
}

View File

@ -0,0 +1,30 @@
using ProjectFuel.Entities.Enums;
namespace ProjectFuel.Entities;
public class Trip
{
public int Trip_ID { get; private set; }
public DateTime Start_Date { get; private set; }
public DateTime End_Date { get; private set; }
public Shift Shift { get; private set; }
public float Fuel_Consumption { get; private set; }
public int Car_ID { get; private set; }
public int Driver_ID { get; private set; }
public IEnumerable<TripRoute> Routes { get; private set; } = [];
public static Trip CreateOperation(int trip_id, DateTime start_date, DateTime end_date, Shift shift, float consumption, int car_id, int driver_id, IEnumerable<TripRoute> routes)
{
return new Trip
{
Trip_ID = trip_id,
Start_Date = start_date,
End_Date = end_date,
Shift = shift,
Fuel_Consumption = consumption,
Car_ID = car_id,
Driver_ID = driver_id,
Routes = routes
};
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectFuel.Entities;
public class TripRoute
{
public int Trip_ID { get; private set; }
public int Route_ID { get; private set; }
public int Fuel_Init { get; private set; }
public static TripRoute CreateOperation(int trip_Id, int route_ID, int fuel_Init)
{
return new TripRoute
{
Trip_ID = trip_Id,
Route_ID = route_ID,
Fuel_Init = fuel_Init
};
}
}

View File

@ -1,39 +0,0 @@
namespace ProjectFuel
{
partial class Form1
{
/// <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()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace ProjectFuel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

147
ProjectFuel/FormFuel.Designer.cs generated Normal file
View File

@ -0,0 +1,147 @@
namespace ProjectFuel
{
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()
{
menuStrip1 = new MenuStrip();
справочникиToolStripMenuItem = new ToolStripMenuItem();
CarsToolStripMenuItem = new ToolStripMenuItem();
DriversToolStripMenuItem = new ToolStripMenuItem();
FuelToolStripMenuItem = new ToolStripMenuItem();
RoutesToolStripMenuItem = new ToolStripMenuItem();
операцииToolStripMenuItem = new ToolStripMenuItem();
RefillToolStripMenuItem = new ToolStripMenuItem();
TripToolStripMenuItem = new ToolStripMenuItem();
отчетыToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.SuspendLayout();
SuspendLayout();
//
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(32, 32);
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(800, 42);
menuStrip1.TabIndex = 0;
menuStrip1.Text = "menuStrip1";
//
// справочникиToolStripMenuItem
//
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { CarsToolStripMenuItem, DriversToolStripMenuItem, FuelToolStripMenuItem, RoutesToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(184, 38);
справочникиToolStripMenuItem.Text = "Справочники";
//
// CarsToolStripMenuItem
//
CarsToolStripMenuItem.Name = "CarsToolStripMenuItem";
CarsToolStripMenuItem.Size = new Size(359, 44);
CarsToolStripMenuItem.Text = "Машины";
CarsToolStripMenuItem.Click += CarsToolStripMenuItem_Click;
//
// DriversToolStripMenuItem
//
DriversToolStripMenuItem.Name = "DriversToolStripMenuItem";
DriversToolStripMenuItem.Size = new Size(359, 44);
DriversToolStripMenuItem.Text = "Водители";
DriversToolStripMenuItem.Click += DriversToolStripMenuItem_Click;
//
// FuelToolStripMenuItem
//
FuelToolStripMenuItem.Name = "FuelToolStripMenuItem";
FuelToolStripMenuItem.Size = new Size(359, 44);
FuelToolStripMenuItem.Text = "Топливо";
FuelToolStripMenuItem.Click += FuelToolStripMenuItem_Click;
//
// RoutesToolStripMenuItem
//
RoutesToolStripMenuItem.Name = "RoutesToolStripMenuItem";
RoutesToolStripMenuItem.Size = new Size(359, 44);
RoutesToolStripMenuItem.Text = "Маршруты";
RoutesToolStripMenuItem.Click += RoutesToolStripMenuItem_Click;
//
// операцииToolStripMenuItem
//
операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { RefillToolStripMenuItem, TripToolStripMenuItem });
операцииToolStripMenuItem.Name = "операцииToolStripMenuItem";
операцииToolStripMenuItem.Size = new Size(147, 38);
операцииToolStripMenuItem.Text = "Операции";
//
// RefillToolStripMenuItem
//
RefillToolStripMenuItem.Name = "RefillToolStripMenuItem";
RefillToolStripMenuItem.Size = new Size(359, 44);
RefillToolStripMenuItem.Text = "Заправка";
RefillToolStripMenuItem.Click += RefillToolStripMenuItem_Click;
//
// TripToolStripMenuItem
//
TripToolStripMenuItem.Name = "TripToolStripMenuItem";
TripToolStripMenuItem.Size = new Size(359, 44);
TripToolStripMenuItem.Text = "Поездка";
TripToolStripMenuItem.Click += TripToolStripMenuItem_Click;
//
// отчетыToolStripMenuItem
//
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
отчетыToolStripMenuItem.Size = new Size(116, 38);
отчетыToolStripMenuItem.Text = "Отчеты";
//
// FormFuel
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
BackgroundImage = Properties.Resources.топливо;
BackgroundImageLayout = ImageLayout.Stretch;
ClientSize = new Size(800, 450);
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
Name = "FormFuel";
StartPosition = FormStartPosition.CenterScreen;
Text = "Перевозка топлива";
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private MenuStrip menuStrip1;
private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem CarsToolStripMenuItem;
private ToolStripMenuItem DriversToolStripMenuItem;
private ToolStripMenuItem FuelToolStripMenuItem;
private ToolStripMenuItem RoutesToolStripMenuItem;
private ToolStripMenuItem операцииToolStripMenuItem;
private ToolStripMenuItem отчетыToolStripMenuItem;
private ToolStripMenuItem RefillToolStripMenuItem;
private ToolStripMenuItem TripToolStripMenuItem;
}
}

98
ProjectFuel/FormFuel.cs Normal file
View File

@ -0,0 +1,98 @@
using ProjectFuel.Forms_;
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 ProjectFuel
{
public partial class FormFuel : Form
{
private readonly IUnityContainer _container;
public FormFuel(IUnityContainer container)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
}
private void CarsToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormCars>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void DriversToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormDrivers>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FuelToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormFuels>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void RoutesToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormRoutes>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void RefillToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormRefills>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void TripToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormTrips>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

123
ProjectFuel/FormFuel.resx Normal file
View File

@ -0,0 +1,123 @@
<?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>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

188
ProjectFuel/Forms_/FormCar.Designer.cs generated Normal file
View File

@ -0,0 +1,188 @@
namespace ProjectFuel.Forms_
{
partial class FormCar
{
/// <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()
{
label1 = new Label();
label2 = new Label();
label3 = new Label();
label4 = new Label();
label5 = new Label();
textBoxCarMark = new TextBox();
textBoxCarModel = new TextBox();
comboBoxCarType = new ComboBox();
checkedListBoxDriverLicense = new CheckedListBox();
numericUpDownConsumptionRate = new NumericUpDown();
buttonCarSave = new Button();
buttonCancel = new Button();
((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).BeginInit();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(48, 70);
label1.Name = "label1";
label1.Size = new Size(86, 32);
label1.TabIndex = 0;
label1.Text = "Марка";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(50, 138);
label2.Name = "label2";
label2.Size = new Size(101, 32);
label2.TabIndex = 1;
label2.Text = "Модель";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(48, 323);
label3.Name = "label3";
label3.Size = new Size(186, 32);
label3.TabIndex = 2;
label3.Text = "Категория прав";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(48, 247);
label4.Name = "label4";
label4.Size = new Size(155, 32);
label4.TabIndex = 3;
label4.Text = "Тип машины";
//
// label5
//
label5.AutoSize = true;
label5.Location = new Point(48, 428);
label5.Name = "label5";
label5.Size = new Size(185, 32);
label5.TabIndex = 4;
label5.Text = "Расход топлива";
//
// textBoxCarMark
//
textBoxCarMark.Location = new Point(282, 73);
textBoxCarMark.Name = "textBoxCarMark";
textBoxCarMark.Size = new Size(200, 39);
textBoxCarMark.TabIndex = 5;
//
// textBoxCarModel
//
textBoxCarModel.Location = new Point(269, 147);
textBoxCarModel.Name = "textBoxCarModel";
textBoxCarModel.Size = new Size(200, 39);
textBoxCarModel.TabIndex = 6;
//
// comboBoxCarType
//
comboBoxCarType.FormattingEnabled = true;
comboBoxCarType.Location = new Point(301, 248);
comboBoxCarType.Name = "comboBoxCarType";
comboBoxCarType.Size = new Size(242, 40);
comboBoxCarType.TabIndex = 7;
//
// checkedListBoxDriverLicense
//
checkedListBoxDriverLicense.FormattingEnabled = true;
checkedListBoxDriverLicense.Location = new Point(305, 321);
checkedListBoxDriverLicense.Name = "checkedListBoxDriverLicense";
checkedListBoxDriverLicense.Size = new Size(240, 76);
checkedListBoxDriverLicense.TabIndex = 8;
//
// numericUpDownConsumptionRate
//
numericUpDownConsumptionRate.Location = new Point(295, 443);
numericUpDownConsumptionRate.Name = "numericUpDownConsumptionRate";
numericUpDownConsumptionRate.Size = new Size(240, 39);
numericUpDownConsumptionRate.TabIndex = 9;
//
// buttonCarSave
//
buttonCarSave.Location = new Point(75, 543);
buttonCarSave.Name = "buttonCarSave";
buttonCarSave.Size = new Size(150, 46);
buttonCarSave.TabIndex = 10;
buttonCarSave.Text = "Сохранить";
buttonCarSave.UseVisualStyleBackColor = true;
buttonCarSave.Click += ButtonCarSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(341, 543);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(150, 46);
buttonCancel.TabIndex = 11;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormCar
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(905, 627);
Controls.Add(buttonCancel);
Controls.Add(buttonCarSave);
Controls.Add(numericUpDownConsumptionRate);
Controls.Add(checkedListBoxDriverLicense);
Controls.Add(comboBoxCarType);
Controls.Add(textBoxCarModel);
Controls.Add(textBoxCarMark);
Controls.Add(label5);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormCar";
StartPosition = FormStartPosition.CenterParent;
Text = "FormCar";
((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private Label label3;
private Label label4;
private Label label5;
private TextBox textBoxCarMark;
private TextBox textBoxCarModel;
private ComboBox comboBoxCarType;
private CheckedListBox checkedListBoxDriverLicense;
private NumericUpDown numericUpDownConsumptionRate;
private Button buttonCarSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,96 @@
using ProjectFuel.Entities;
using ProjectFuel.Entities.Enums;
using ProjectFuel.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 ProjectFuel.Forms_
{
public partial class FormCar : Form
{
private readonly ICarRepository _carRepository;
private int? _carId;
public int Id
{
set
{
try
{
var car = _carRepository.ReadCarByID(value);
if (car == null)
throw new InvalidOperationException(nameof(car));
foreach (Driver_License elem in Enum.GetValues(typeof(Driver_License)))
{
if ((elem & car.License) != 0)
{
checkedListBoxDriverLicense.SetItemChecked(checkedListBoxDriverLicense.Items.IndexOf(elem), true);
}
}
textBoxCarMark.Text = car.Car_Mark;
textBoxCarModel.Text = car.Car_Model;
comboBoxCarType.SelectedItem = car.Car_Type;
numericUpDownConsumptionRate.Value = (decimal)car.Consumption_Rate;
_carId = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
public FormCar(ICarRepository carRepository)
{
InitializeComponent();
_carRepository = carRepository ??
throw new ArgumentNullException(nameof(carRepository));
foreach (var elem in Enum.GetValues(typeof(Driver_License)))
checkedListBoxDriverLicense.Items.Add(elem);
comboBoxCarType.DataSource = Enum.GetValues(typeof(Car_Type));
}
private void ButtonCarSave_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(textBoxCarMark.Text) || string.IsNullOrWhiteSpace(textBoxCarModel.Text) || comboBoxCarType.SelectedIndex < 1 || checkedListBoxDriverLicense.CheckedItems.Count == 0)
throw new Exception("Имеются незаполненные поля");
if (_carId.HasValue)
_carRepository.UpdateCar(CreateCar(_carId.Value));
else
_carRepository.CreateCar(CreateCar(0));
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private Car CreateCar(int id)
{
Driver_License driver_License = Driver_License.None;
foreach (var elem in checkedListBoxDriverLicense.CheckedItems)
{
driver_License |= (Driver_License)elem;
}
return Car.CreateEntity(id, textBoxCarMark.Text, textBoxCarModel.Text, (Car_Type)comboBoxCarType.SelectedItem!, driver_License, (float)numericUpDownConsumptionRate.Value);
}
}
}

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
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
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>
@ -26,36 +26,36 @@
<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
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
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
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
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
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
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
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

128
ProjectFuel/Forms_/FormCars.Designer.cs generated Normal file
View File

@ -0,0 +1,128 @@
namespace ProjectFuel.Forms_
{
partial class FormCars
{
/// <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()
{
panel1 = new Panel();
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
dataGridView = new DataGridView();
panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// panel1
//
panel1.Controls.Add(buttonDel);
panel1.Controls.Add(buttonUpd);
panel1.Controls.Add(buttonAdd);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(624, 0);
panel1.Name = "panel1";
panel1.Size = new Size(334, 577);
panel1.TabIndex = 0;
//
// buttonDel
//
buttonDel.BackgroundImage = Properties.Resources.удалять;
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
buttonDel.Location = new Point(94, 349);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(158, 120);
buttonDel.TabIndex = 2;
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonUpd
//
buttonUpd.BackgroundImage = Properties.Resources.ред;
buttonUpd.BackgroundImageLayout = ImageLayout.Stretch;
buttonUpd.Location = new Point(94, 201);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(158, 118);
buttonUpd.TabIndex = 1;
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources._;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(94, 64);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(158, 114);
buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToResizeColumns = false;
dataGridView.AllowUserToResizeRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Fill;
dataGridView.Location = new Point(0, 0);
dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 82;
dataGridView.RowTemplate.Height = 41;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(624, 577);
dataGridView.TabIndex = 1;
//
// FormCars
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(958, 577);
Controls.Add(dataGridView);
Controls.Add(panel1);
Name = "FormCars";
StartPosition = FormStartPosition.CenterParent;
Text = "Машины";
Load += FormCars_Load;
panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel1;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,103 @@
using ProjectFuel.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 ProjectFuel.Forms_
{
public partial class FormCars : Form
{
private readonly IUnityContainer _container;
private readonly ICarRepository _carRepository;
public FormCars(IUnityContainer container, ICarRepository carRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_carRepository = carRepository ??
throw new ArgumentNullException(nameof(carRepository));
}
private void FormCars_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<FormCar>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
return;
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
return;
try
{
_carRepository.DeleteCar(findId);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
return;
try
{
var form = _container.Resolve<FormCar>();
form.Id = findId;
form.ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridView.DataSource = _carRepository.ReadCars();
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
if (dataGridView.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Car_ID"].Value);
return true;
}
}
}

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>

141
ProjectFuel/Forms_/FormDriver.Designer.cs generated Normal file
View File

@ -0,0 +1,141 @@
namespace ProjectFuel.Forms_
{
partial class FormDriver
{
/// <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()
{
label1 = new Label();
label2 = new Label();
label3 = new Label();
textBoxDriverFirstname = new TextBox();
textBoxDriverSecondname = new TextBox();
checkedListBoxDriverLicense = new CheckedListBox();
buttonDriverSave = new Button();
buttonDriverCancel = new Button();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(31, 35);
label1.Name = "label1";
label1.Size = new Size(61, 32);
label1.TabIndex = 0;
label1.Text = "Имя";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(31, 108);
label2.Name = "label2";
label2.Size = new Size(113, 32);
label2.TabIndex = 1;
label2.Text = "Фамилия";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(31, 192);
label3.Name = "label3";
label3.Size = new Size(281, 32);
label3.TabIndex = 2;
label3.Text = "Водительская категория";
//
// textBoxDriverFirstname
//
textBoxDriverFirstname.Location = new Point(282, 28);
textBoxDriverFirstname.Name = "textBoxDriverFirstname";
textBoxDriverFirstname.Size = new Size(200, 39);
textBoxDriverFirstname.TabIndex = 3;
//
// textBoxDriverSecondname
//
textBoxDriverSecondname.Location = new Point(285, 105);
textBoxDriverSecondname.Name = "textBoxDriverSecondname";
textBoxDriverSecondname.Size = new Size(200, 39);
textBoxDriverSecondname.TabIndex = 4;
//
// checkedListBoxDriverLicense
//
checkedListBoxDriverLicense.FormattingEnabled = true;
checkedListBoxDriverLicense.Location = new Point(352, 199);
checkedListBoxDriverLicense.Name = "checkedListBoxDriverLicense";
checkedListBoxDriverLicense.Size = new Size(240, 76);
checkedListBoxDriverLicense.TabIndex = 5;
//
// buttonDriverSave
//
buttonDriverSave.Location = new Point(66, 359);
buttonDriverSave.Name = "buttonDriverSave";
buttonDriverSave.Size = new Size(150, 46);
buttonDriverSave.TabIndex = 6;
buttonDriverSave.Text = "Сохранить";
buttonDriverSave.UseVisualStyleBackColor = true;
buttonDriverSave.Click += ButtonDriverSave_Click;
//
// buttonDriverCancel
//
buttonDriverCancel.Location = new Point(364, 356);
buttonDriverCancel.Name = "buttonDriverCancel";
buttonDriverCancel.Size = new Size(150, 46);
buttonDriverCancel.TabIndex = 7;
buttonDriverCancel.Text = "Отмена";
buttonDriverCancel.UseVisualStyleBackColor = true;
buttonDriverCancel.Click += ButtonDriverCancel_Click;
//
// FormDriver
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(buttonDriverCancel);
Controls.Add(buttonDriverSave);
Controls.Add(checkedListBoxDriverLicense);
Controls.Add(textBoxDriverSecondname);
Controls.Add(textBoxDriverFirstname);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormDriver";
StartPosition = FormStartPosition.CenterParent;
Text = "Водитель";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private Label label3;
private TextBox textBoxDriverFirstname;
private TextBox textBoxDriverSecondname;
private CheckedListBox checkedListBoxDriverLicense;
private Button buttonDriverSave;
private Button buttonDriverCancel;
}
}

View File

@ -0,0 +1,93 @@
using ProjectFuel.Entities;
using ProjectFuel.Entities.Enums;
using ProjectFuel.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 ProjectFuel.Forms_
{
public partial class FormDriver : Form
{
private readonly IDriverRepository _driverRepository;
private int? _driverId;
public int Id
{
set
{
try
{
var driver = _driverRepository.ReadDriverByID(value);
if (driver == null)
throw new InvalidOperationException(nameof(driver));
foreach (Driver_License elem in Enum.GetValues(typeof(Driver_License)))
{
if ((elem & driver.Driver_License) != 0)
{
checkedListBoxDriverLicense.SetItemChecked(checkedListBoxDriverLicense.Items.IndexOf(elem), true);
}
}
textBoxDriverFirstname.Text = driver.Firstname;
textBoxDriverSecondname.Text = driver.Secondname;
_driverId = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
public FormDriver(IDriverRepository driverRepository)
{
InitializeComponent();
_driverRepository = driverRepository ??
throw new ArgumentNullException(nameof(driverRepository));
foreach (var elem in Enum.GetValues(typeof(Driver_License)))
checkedListBoxDriverLicense.Items.Add(elem);
}
private void ButtonDriverSave_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(textBoxDriverFirstname.Text) || string.IsNullOrWhiteSpace(textBoxDriverSecondname.Text) || checkedListBoxDriverLicense.CheckedItems.Count == 0)
throw new Exception("Имеются незаполненные поля");
if (_driverId.HasValue)
_driverRepository.UpdateDriver(CreateDriver(_driverId.Value));
else
_driverRepository.CreateDriver(CreateDriver(0));
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDriverCancel_Click(object sender, EventArgs e) => Close();
private Driver CreateDriver(int id)
{
Driver_License driver_License = Driver_License.None;
foreach (var elem in checkedListBoxDriverLicense.CheckedItems)
{
driver_License |= (Driver_License)elem;
}
return Driver.CreateEntity(id, textBoxDriverFirstname.Text, textBoxDriverSecondname.Text, driver_License);
}
}
}

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>

128
ProjectFuel/Forms_/FormDrivers.Designer.cs generated Normal file
View File

@ -0,0 +1,128 @@
namespace ProjectFuel.Forms_
{
partial class FormDrivers
{
/// <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()
{
panel1 = new Panel();
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
dataGridView = new DataGridView();
panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// panel1
//
panel1.Controls.Add(buttonDel);
panel1.Controls.Add(buttonUpd);
panel1.Controls.Add(buttonAdd);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(819, 0);
panel1.Name = "panel1";
panel1.Size = new Size(242, 569);
panel1.TabIndex = 0;
//
// buttonDel
//
buttonDel.BackgroundImage = Properties.Resources.удалять;
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
buttonDel.Location = new Point(67, 400);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(151, 126);
buttonDel.TabIndex = 2;
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonUpd
//
buttonUpd.BackgroundImage = Properties.Resources.ред;
buttonUpd.BackgroundImageLayout = ImageLayout.Stretch;
buttonUpd.Location = new Point(67, 224);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(152, 115);
buttonUpd.TabIndex = 1;
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources._;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(68, 52);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(151, 131);
buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToResizeColumns = false;
dataGridView.AllowUserToResizeRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Fill;
dataGridView.Location = new Point(0, 0);
dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 82;
dataGridView.RowTemplate.Height = 41;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(819, 569);
dataGridView.TabIndex = 1;
//
// FormDrivers
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1061, 569);
Controls.Add(dataGridView);
Controls.Add(panel1);
Name = "FormDrivers";
StartPosition = FormStartPosition.CenterParent;
Text = "Водители";
Load += FormDrivers_Load;
panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel1;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,104 @@
using ProjectFuel.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 ProjectFuel.Forms_
{
public partial class FormDrivers : Form
{
private readonly IUnityContainer _container;
private readonly IDriverRepository _driverRepository;
public FormDrivers(IUnityContainer container, IDriverRepository driverRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_driverRepository = driverRepository ??
throw new ArgumentNullException(nameof(driverRepository));
}
private void FormDrivers_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<FormDriver>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
return;
try
{
var form = _container.Resolve<FormDriver>();
form.Id = findId;
form.ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
return;
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
return;
try
{
_driverRepository.DeleteDriver(findId);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridView.DataSource = _driverRepository.ReadDrivers();
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
if (dataGridView.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Driver_ID"].Value);
return true;
}
}
}

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>

148
ProjectFuel/Forms_/FormFuel.Designer.cs generated Normal file
View File

@ -0,0 +1,148 @@
namespace ProjectFuel.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()
{
label1 = new Label();
label2 = new Label();
label3 = new Label();
buttonFuelSave = new Button();
buttonCancel = new Button();
comboBoxFuelType = new ComboBox();
numericUpDownPrice = new NumericUpDown();
numericUpDownAmount = new NumericUpDown();
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownAmount).BeginInit();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(41, 58);
label1.Name = "label1";
label1.Size = new Size(152, 32);
label1.TabIndex = 0;
label1.Text = "Вид топлива";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(47, 126);
label2.Name = "label2";
label2.Size = new Size(159, 32);
label2.TabIndex = 1;
label2.Text = "Цена за литр";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(52, 198);
label3.Name = "label3";
label3.Size = new Size(144, 32);
label3.TabIndex = 2;
label3.Text = "Количество";
//
// buttonFuelSave
//
buttonFuelSave.Location = new Point(71, 338);
buttonFuelSave.Name = "buttonFuelSave";
buttonFuelSave.Size = new Size(150, 46);
buttonFuelSave.TabIndex = 3;
buttonFuelSave.Text = "Сохранить";
buttonFuelSave.UseVisualStyleBackColor = true;
buttonFuelSave.Click += ButtonFuelSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(306, 338);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(150, 46);
buttonCancel.TabIndex = 4;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// comboBoxFuelType
//
comboBoxFuelType.FormattingEnabled = true;
comboBoxFuelType.Location = new Point(272, 65);
comboBoxFuelType.Name = "comboBoxFuelType";
comboBoxFuelType.Size = new Size(242, 40);
comboBoxFuelType.TabIndex = 5;
//
// numericUpDownPrice
//
numericUpDownPrice.DecimalPlaces = 2;
numericUpDownPrice.InterceptArrowKeys = false;
numericUpDownPrice.Location = new Point(271, 129);
numericUpDownPrice.Name = "numericUpDownPrice";
numericUpDownPrice.Size = new Size(240, 39);
numericUpDownPrice.TabIndex = 6;
//
// numericUpDownAmount
//
numericUpDownAmount.DecimalPlaces = 2;
numericUpDownAmount.Location = new Point(268, 203);
numericUpDownAmount.Name = "numericUpDownAmount";
numericUpDownAmount.Size = new Size(240, 39);
numericUpDownAmount.TabIndex = 7;
//
// FormFuel
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(numericUpDownAmount);
Controls.Add(numericUpDownPrice);
Controls.Add(comboBoxFuelType);
Controls.Add(buttonCancel);
Controls.Add(buttonFuelSave);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormFuel";
StartPosition = FormStartPosition.CenterParent;
Text = "FormFuel";
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownAmount).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private Label label3;
private Button buttonFuelSave;
private Button buttonCancel;
private ComboBox comboBoxFuelType;
private NumericUpDown numericUpDownPrice;
private NumericUpDown numericUpDownAmount;
}
}

View File

@ -0,0 +1,79 @@
using ProjectFuel.Entities;
using ProjectFuel.Entities.Enums;
using ProjectFuel.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 ProjectFuel.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 CreateFuel(int id)
{
return Fuel.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>

128
ProjectFuel/Forms_/FormFuels.Designer.cs generated Normal file
View File

@ -0,0 +1,128 @@
namespace ProjectFuel.Forms_
{
partial class FormFuels
{
/// <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()
{
panel1 = new Panel();
buttonAdd = new Button();
buttonUpd = new Button();
buttonDel = new Button();
dataGridView = new DataGridView();
panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// panel1
//
panel1.Controls.Add(buttonAdd);
panel1.Controls.Add(buttonUpd);
panel1.Controls.Add(buttonDel);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(836, 0);
panel1.Name = "panel1";
panel1.Size = new Size(230, 618);
panel1.TabIndex = 0;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources._;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(59, 64);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(151, 131);
buttonAdd.TabIndex = 5;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// buttonUpd
//
buttonUpd.BackgroundImage = Properties.Resources.ред;
buttonUpd.BackgroundImageLayout = ImageLayout.Stretch;
buttonUpd.Location = new Point(58, 246);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(152, 115);
buttonUpd.TabIndex = 4;
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonDel
//
buttonDel.BackgroundImage = Properties.Resources.удалять;
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
buttonDel.Location = new Point(58, 422);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(151, 126);
buttonDel.TabIndex = 3;
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToResizeColumns = false;
dataGridView.AllowUserToResizeRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Fill;
dataGridView.Location = new Point(0, 0);
dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 82;
dataGridView.RowTemplate.Height = 41;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(836, 618);
dataGridView.TabIndex = 1;
//
// FormFuels
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1066, 618);
Controls.Add(dataGridView);
Controls.Add(panel1);
Name = "FormFuels";
StartPosition = FormStartPosition.CenterParent;
Text = "Топлива";
Load += FormFuels_Load;
panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel1;
private DataGridView dataGridView;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
}
}

View File

@ -0,0 +1,104 @@
using ProjectFuel.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 ProjectFuel.Forms_
{
public partial class FormFuels : Form
{
private readonly IUnityContainer _container;
private readonly IFuelRepository _fuelRepository;
public FormFuels(IUnityContainer container, IFuelRepository fuelRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_fuelRepository = fuelRepository ??
throw new ArgumentNullException(nameof(fuelRepository));
}
private void FormFuels_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<FormFuel>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
return;
try
{
var form = _container.Resolve<FormFuel>();
form.Id = findId;
form.ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
return;
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
return;
try
{
_fuelRepository.DeleteFuel(findId);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridView.DataSource = _fuelRepository.ReadFuels();
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
if (dataGridView.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Fuel_ID"].Value);
return true;
}
}
}

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>

169
ProjectFuel/Forms_/FormRefill.Designer.cs generated Normal file
View File

@ -0,0 +1,169 @@
namespace ProjectFuel.Forms_
{
partial class FormRefill
{
/// <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()
{
label1 = new Label();
label2 = new Label();
label3 = new Label();
label4 = new Label();
dateTimePickerRefillDate = new DateTimePicker();
numericUpDownRefillAmount = new NumericUpDown();
comboBoxFuelID = new ComboBox();
comboBoxCarID = new ComboBox();
buttonRefillSave = new Button();
buttonCancel = new Button();
((System.ComponentModel.ISupportInitialize)numericUpDownRefillAmount).BeginInit();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(44, 49);
label1.Name = "label1";
label1.Size = new Size(174, 32);
label1.TabIndex = 0;
label1.Text = "Дата заправки";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(48, 112);
label2.Name = "label2";
label2.Size = new Size(144, 32);
label2.TabIndex = 1;
label2.Text = "Количество";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(50, 179);
label3.Name = "label3";
label3.Size = new Size(109, 32);
label3.TabIndex = 2;
label3.Text = "Топливо";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(57, 250);
label4.Name = "label4";
label4.Size = new Size(107, 32);
label4.TabIndex = 3;
label4.Text = "Машина";
//
// dateTimePickerRefillDate
//
dateTimePickerRefillDate.Location = new Point(291, 42);
dateTimePickerRefillDate.Name = "dateTimePickerRefillDate";
dateTimePickerRefillDate.Size = new Size(400, 39);
dateTimePickerRefillDate.TabIndex = 4;
//
// numericUpDownRefillAmount
//
numericUpDownRefillAmount.DecimalPlaces = 2;
numericUpDownRefillAmount.Location = new Point(281, 114);
numericUpDownRefillAmount.Name = "numericUpDownRefillAmount";
numericUpDownRefillAmount.Size = new Size(240, 39);
numericUpDownRefillAmount.TabIndex = 5;
//
// comboBoxFuelID
//
comboBoxFuelID.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxFuelID.FormattingEnabled = true;
comboBoxFuelID.Location = new Point(282, 180);
comboBoxFuelID.Name = "comboBoxFuelID";
comboBoxFuelID.Size = new Size(242, 40);
comboBoxFuelID.TabIndex = 6;
//
// comboBoxCarID
//
comboBoxCarID.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxCarID.FormattingEnabled = true;
comboBoxCarID.Location = new Point(277, 256);
comboBoxCarID.Name = "comboBoxCarID";
comboBoxCarID.Size = new Size(242, 40);
comboBoxCarID.TabIndex = 7;
//
// buttonRefillSave
//
buttonRefillSave.Location = new Point(57, 367);
buttonRefillSave.Name = "buttonRefillSave";
buttonRefillSave.Size = new Size(150, 46);
buttonRefillSave.TabIndex = 8;
buttonRefillSave.Text = "Сохранить";
buttonRefillSave.UseVisualStyleBackColor = true;
buttonRefillSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(315, 368);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(150, 46);
buttonCancel.TabIndex = 9;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormRefill
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(buttonCancel);
Controls.Add(buttonRefillSave);
Controls.Add(comboBoxCarID);
Controls.Add(comboBoxFuelID);
Controls.Add(numericUpDownRefillAmount);
Controls.Add(dateTimePickerRefillDate);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormRefill";
StartPosition = FormStartPosition.CenterParent;
Text = "FormRefill";
((System.ComponentModel.ISupportInitialize)numericUpDownRefillAmount).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private Label label3;
private Label label4;
private DateTimePicker dateTimePickerRefillDate;
private NumericUpDown numericUpDownRefillAmount;
private ComboBox comboBoxFuelID;
private ComboBox comboBoxCarID;
private Button buttonRefillSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,51 @@
using ProjectFuel.Entities;
using ProjectFuel.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 ProjectFuel.Forms_
{
public partial class FormRefill : Form
{
private readonly IRefillRepository _refillRepository;
public FormRefill(IRefillRepository refillRepository, IFuelRepository fuelRepository, ICarRepository carRepository)
{
InitializeComponent();
_refillRepository = refillRepository ??
throw new ArgumentNullException(nameof(refillRepository));
comboBoxFuelID.DataSource = fuelRepository.ReadFuels();
comboBoxFuelID.DisplayMember = "Fuel_Type";
comboBoxFuelID.ValueMember = "Fuel_ID";
comboBoxCarID.DataSource = carRepository.ReadCars();
comboBoxCarID.DisplayMember = "Car_Mark";
comboBoxCarID.ValueMember = "Car_ID";
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (comboBoxFuelID.SelectedIndex < 0 || comboBoxCarID.SelectedIndex < 0)
throw new Exception("Имеются незаполненные поля");
_refillRepository.CreateRefill(Refill.CreateOperation(0, dateTimePickerRefillDate.Value, (float)numericUpDownRefillAmount.Value, (int)comboBoxFuelID.SelectedValue!, (int)comboBoxCarID.SelectedValue!));
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>

100
ProjectFuel/Forms_/FormRefills.Designer.cs generated Normal file
View File

@ -0,0 +1,100 @@
namespace ProjectFuel.Forms_
{
partial class FormRefills
{
/// <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()
{
panel1 = new Panel();
buttonAdd = new Button();
dataGridView = new DataGridView();
panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// panel1
//
panel1.Controls.Add(buttonAdd);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(824, 0);
panel1.Name = "panel1";
panel1.Size = new Size(266, 634);
panel1.TabIndex = 0;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources._;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(72, 74);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(151, 131);
buttonAdd.TabIndex = 6;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToResizeColumns = false;
dataGridView.AllowUserToResizeRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Fill;
dataGridView.Location = new Point(0, 0);
dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 82;
dataGridView.RowTemplate.Height = 41;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(824, 634);
dataGridView.TabIndex = 1;
//
// FormRefills
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1090, 634);
Controls.Add(dataGridView);
Controls.Add(panel1);
Name = "FormRefills";
StartPosition = FormStartPosition.CenterParent;
Text = "Заправки";
Load += FormRefills_Load;
panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel1;
private DataGridView dataGridView;
private Button buttonAdd;
}
}

View File

@ -0,0 +1,64 @@
using ProjectFuel.Entities;
using ProjectFuel.Repositories;
using ProjectFuel.Repositories.Implementations;
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 ProjectFuel.Forms_
{
public partial class FormRefills : Form
{
private readonly IUnityContainer _container;
private readonly IRefillRepository _refillRepository;
public FormRefills(IUnityContainer container, IRefillRepository refillRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_refillRepository = refillRepository ??
throw new ArgumentNullException(nameof(refillRepository));
}
private void FormRefills_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<FormRefill>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridView.DataSource = _refillRepository.ReadRefills();
}
}

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>

143
ProjectFuel/Forms_/FormRoute.Designer.cs generated Normal file
View File

@ -0,0 +1,143 @@
namespace ProjectFuel.Forms_
{
partial class FormRoute
{
/// <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()
{
label1 = new Label();
label2 = new Label();
label3 = new Label();
buttonRouteSave = new Button();
buttonCancel = new Button();
textBoxStartPoint = new TextBox();
textBoxEndPoint = new TextBox();
numericUpDownLength = new NumericUpDown();
((System.ComponentModel.ISupportInitialize)numericUpDownLength).BeginInit();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(38, 56);
label1.Name = "label1";
label1.Size = new Size(201, 32);
label1.TabIndex = 0;
label1.Text = "Начальная точка";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(42, 130);
label2.Name = "label2";
label2.Size = new Size(190, 32);
label2.TabIndex = 1;
label2.Text = "Конечная точка";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(47, 207);
label3.Name = "label3";
label3.Size = new Size(201, 32);
label3.TabIndex = 2;
label3.Text = "Длина маршрута";
//
// buttonRouteSave
//
buttonRouteSave.Location = new Point(66, 337);
buttonRouteSave.Name = "buttonRouteSave";
buttonRouteSave.Size = new Size(150, 46);
buttonRouteSave.TabIndex = 3;
buttonRouteSave.Text = "Сохранить";
buttonRouteSave.UseVisualStyleBackColor = true;
buttonRouteSave.Click += ButtonRouteSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(367, 342);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(150, 46);
buttonCancel.TabIndex = 4;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// textBoxStartPoint
//
textBoxStartPoint.Location = new Point(307, 60);
textBoxStartPoint.Name = "textBoxStartPoint";
textBoxStartPoint.Size = new Size(200, 39);
textBoxStartPoint.TabIndex = 5;
//
// textBoxEndPoint
//
textBoxEndPoint.Location = new Point(311, 130);
textBoxEndPoint.Name = "textBoxEndPoint";
textBoxEndPoint.Size = new Size(200, 39);
textBoxEndPoint.TabIndex = 6;
//
// numericUpDownLength
//
numericUpDownLength.DecimalPlaces = 2;
numericUpDownLength.Location = new Point(308, 207);
numericUpDownLength.Name = "numericUpDownLength";
numericUpDownLength.Size = new Size(240, 39);
numericUpDownLength.TabIndex = 7;
//
// FormRoute
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(numericUpDownLength);
Controls.Add(textBoxEndPoint);
Controls.Add(textBoxStartPoint);
Controls.Add(buttonCancel);
Controls.Add(buttonRouteSave);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormRoute";
StartPosition = FormStartPosition.CenterParent;
Text = "Маршрут";
((System.ComponentModel.ISupportInitialize)numericUpDownLength).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private Label label3;
private Button buttonRouteSave;
private Button buttonCancel;
private TextBox textBoxStartPoint;
private TextBox textBoxEndPoint;
private NumericUpDown numericUpDownLength;
}
}

View File

@ -0,0 +1,76 @@
using ProjectFuel.Entities;
using ProjectFuel.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 ProjectFuel.Forms_
{
public partial class FormRoute : Form
{
private readonly IRouteRepository _routeRepository;
private int? _routeId;
public int Id
{
set
{
try
{
var route = _routeRepository.ReadRouteByID(value);
if (route == null)
throw new InvalidOperationException(nameof(route));
textBoxStartPoint.Text = route.Start_Point;
textBoxEndPoint.Text = route.End_Point;
numericUpDownLength.Value = (decimal)route.Route_Length;
_routeId = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
public FormRoute(IRouteRepository routeRepository)
{
InitializeComponent();
_routeRepository = routeRepository ??
throw new ArgumentNullException(nameof(routeRepository));
}
private void ButtonRouteSave_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(textBoxStartPoint.Text) || string.IsNullOrWhiteSpace(textBoxEndPoint.Text))
throw new Exception("Имеются незаполненные поля");
if (_routeId.HasValue)
_routeRepository.UpdateRoute(CreateRoute(_routeId.Value));
else
_routeRepository.CreateRoute(CreateRoute(0));
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private Route CreateRoute(int id)
{
return Route.CreateEntity(id, textBoxStartPoint.Text, textBoxEndPoint.Text, (float)numericUpDownLength.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>

128
ProjectFuel/Forms_/FormRoutes.Designer.cs generated Normal file
View File

@ -0,0 +1,128 @@
namespace ProjectFuel.Forms_
{
partial class FormRoutes
{
/// <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()
{
panel1 = new Panel();
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
dataGridView = new DataGridView();
panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// panel1
//
panel1.Controls.Add(buttonDel);
panel1.Controls.Add(buttonUpd);
panel1.Controls.Add(buttonAdd);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(583, 0);
panel1.Name = "panel1";
panel1.Size = new Size(217, 450);
panel1.TabIndex = 0;
//
// buttonDel
//
buttonDel.BackgroundImage = Properties.Resources.удалять;
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
buttonDel.Location = new Point(41, 312);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(151, 126);
buttonDel.TabIndex = 9;
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonUpd
//
buttonUpd.BackgroundImage = Properties.Resources.ред;
buttonUpd.BackgroundImageLayout = ImageLayout.Stretch;
buttonUpd.Location = new Point(40, 184);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(152, 115);
buttonUpd.TabIndex = 8;
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources._;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(40, 33);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(151, 131);
buttonAdd.TabIndex = 7;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.AllowUserToResizeColumns = false;
dataGridView.AllowUserToResizeRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Fill;
dataGridView.Location = new Point(0, 0);
dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 82;
dataGridView.RowTemplate.Height = 41;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(583, 450);
dataGridView.TabIndex = 1;
//
// FormRoutes
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(dataGridView);
Controls.Add(panel1);
Name = "FormRoutes";
StartPosition = FormStartPosition.CenterParent;
Text = "Маршруты";
Load += FormRoutes_Load;
panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel1;
private DataGridView dataGridView;
private Button buttonAdd;
private Button buttonUpd;
private Button buttonDel;
}
}

View File

@ -0,0 +1,103 @@
using ProjectFuel.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 ProjectFuel.Forms_
{
public partial class FormRoutes : Form
{
private readonly IUnityContainer _container;
private readonly IRouteRepository _routeRepository;
public FormRoutes(IUnityContainer container, IRouteRepository routeRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_routeRepository = routeRepository ??
throw new ArgumentNullException(nameof(routeRepository));
}
private void FormRoutes_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<FormRoute>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
return;
try
{
var form = _container.Resolve<FormRoute>();
form.Id = findId;
form.ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
return;
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
return;
try
{
_routeRepository.DeleteRoute(findId);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridView.DataSource = _routeRepository.ReadRoutes();
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
if (dataGridView.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Route_ID"].Value);
return true;
}
}
}

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>

283
ProjectFuel/Forms_/FormTrip.Designer.cs generated Normal file
View File

@ -0,0 +1,283 @@
namespace ProjectFuel.Forms_
{
partial class FormTrip
{
/// <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()
{
label1 = new Label();
label2 = new Label();
label4 = new Label();
label5 = new Label();
label6 = new Label();
dateTimePickerStartDate = new DateTimePicker();
dateTimePickerEndDate = new DateTimePicker();
numericUpDownConsumptionRate = new NumericUpDown();
comboBoxCarID = new ComboBox();
comboBoxDriverID = new ComboBox();
buttonTripSave = new Button();
buttonCancel = new Button();
groupBox = new GroupBox();
dataGridViewRoutes = new DataGridView();
label3 = new Label();
comboBoxShift = new ComboBox();
ColumnRoute = new DataGridViewComboBoxColumn();
ColumnFuelInit = new DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).BeginInit();
groupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewRoutes).BeginInit();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(28, 18);
label1.Margin = new Padding(2, 0, 2, 0);
label1.Name = "label1";
label1.Size = new Size(74, 15);
label1.TabIndex = 0;
label1.Text = "Дата начала";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(33, 49);
label2.Margin = new Padding(2, 0, 2, 0);
label2.Name = "label2";
label2.Size = new Size(68, 15);
label2.TabIndex = 1;
label2.Text = "Дата конца";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(32, 103);
label4.Margin = new Padding(2, 0, 2, 0);
label4.Name = "label4";
label4.Size = new Size(93, 15);
label4.TabIndex = 3;
label4.Text = "Расход топлива";
//
// label5
//
label5.AutoSize = true;
label5.Location = new Point(30, 129);
label5.Margin = new Padding(2, 0, 2, 0);
label5.Name = "label5";
label5.Size = new Size(55, 15);
label5.TabIndex = 4;
label5.Text = "Машина";
//
// label6
//
label6.AutoSize = true;
label6.Location = new Point(33, 159);
label6.Margin = new Padding(2, 0, 2, 0);
label6.Name = "label6";
label6.Size = new Size(58, 15);
label6.TabIndex = 5;
label6.Text = "Водитель";
//
// dateTimePickerStartDate
//
dateTimePickerStartDate.Location = new Point(163, 15);
dateTimePickerStartDate.Margin = new Padding(2, 1, 2, 1);
dateTimePickerStartDate.Name = "dateTimePickerStartDate";
dateTimePickerStartDate.Size = new Size(217, 23);
dateTimePickerStartDate.TabIndex = 6;
//
// dateTimePickerEndDate
//
dateTimePickerEndDate.Location = new Point(159, 50);
dateTimePickerEndDate.Margin = new Padding(2, 1, 2, 1);
dateTimePickerEndDate.Name = "dateTimePickerEndDate";
dateTimePickerEndDate.Size = new Size(217, 23);
dateTimePickerEndDate.TabIndex = 7;
//
// numericUpDownConsumptionRate
//
numericUpDownConsumptionRate.Location = new Point(155, 109);
numericUpDownConsumptionRate.Margin = new Padding(2, 1, 2, 1);
numericUpDownConsumptionRate.Name = "numericUpDownConsumptionRate";
numericUpDownConsumptionRate.Size = new Size(129, 23);
numericUpDownConsumptionRate.TabIndex = 9;
//
// comboBoxCarID
//
comboBoxCarID.FormattingEnabled = true;
comboBoxCarID.Location = new Point(151, 135);
comboBoxCarID.Margin = new Padding(2, 1, 2, 1);
comboBoxCarID.Name = "comboBoxCarID";
comboBoxCarID.Size = new Size(132, 23);
comboBoxCarID.TabIndex = 10;
//
// comboBoxDriverID
//
comboBoxDriverID.FormattingEnabled = true;
comboBoxDriverID.Location = new Point(148, 163);
comboBoxDriverID.Margin = new Padding(2, 1, 2, 1);
comboBoxDriverID.Name = "comboBoxDriverID";
comboBoxDriverID.Size = new Size(132, 23);
comboBoxDriverID.TabIndex = 11;
//
// buttonTripSave
//
buttonTripSave.Location = new Point(43, 304);
buttonTripSave.Margin = new Padding(2, 1, 2, 1);
buttonTripSave.Name = "buttonTripSave";
buttonTripSave.Size = new Size(81, 22);
buttonTripSave.TabIndex = 14;
buttonTripSave.Text = "Сохранить";
buttonTripSave.UseVisualStyleBackColor = true;
buttonTripSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(186, 304);
buttonCancel.Margin = new Padding(2, 1, 2, 1);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(81, 22);
buttonCancel.TabIndex = 15;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// groupBox
//
groupBox.Controls.Add(dataGridViewRoutes);
groupBox.Location = new Point(28, 198);
groupBox.Margin = new Padding(2, 1, 2, 1);
groupBox.Name = "groupBox";
groupBox.Padding = new Padding(2, 1, 2, 1);
groupBox.Size = new Size(308, 104);
groupBox.TabIndex = 16;
groupBox.TabStop = false;
groupBox.Text = "Маршруты";
//
// dataGridViewRoutes
//
dataGridViewRoutes.AllowUserToResizeColumns = false;
dataGridViewRoutes.AllowUserToResizeRows = false;
dataGridViewRoutes.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewRoutes.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewRoutes.Columns.AddRange(new DataGridViewColumn[] { ColumnRoute, ColumnFuelInit });
dataGridViewRoutes.Dock = DockStyle.Fill;
dataGridViewRoutes.Location = new Point(2, 17);
dataGridViewRoutes.Margin = new Padding(3, 2, 3, 2);
dataGridViewRoutes.MultiSelect = false;
dataGridViewRoutes.Name = "dataGridViewRoutes";
dataGridViewRoutes.RowHeadersVisible = false;
dataGridViewRoutes.RowHeadersWidth = 51;
dataGridViewRoutes.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewRoutes.Size = new Size(304, 86);
dataGridViewRoutes.TabIndex = 1;
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(33, 76);
label3.Margin = new Padding(2, 0, 2, 0);
label3.Name = "label3";
label3.Size = new Size(43, 15);
label3.TabIndex = 2;
label3.Text = "Смена";
//
// comboBoxShift
//
comboBoxShift.FormattingEnabled = true;
comboBoxShift.Location = new Point(157, 80);
comboBoxShift.Margin = new Padding(2, 1, 2, 1);
comboBoxShift.Name = "comboBoxShift";
comboBoxShift.Size = new Size(132, 23);
comboBoxShift.TabIndex = 8;
//
// ColumnRoute
//
ColumnRoute.FillWeight = 92.25092F;
ColumnRoute.HeaderText = "Маршрут";
ColumnRoute.MinimumWidth = 6;
ColumnRoute.Name = "ColumnRoute";
//
// ColumnFuelInit
//
ColumnFuelInit.FillWeight = 107.749069F;
ColumnFuelInit.HeaderText = "Изначальное кол-во топлива";
ColumnFuelInit.MinimumWidth = 6;
ColumnFuelInit.Name = "ColumnFuelInit";
//
// FormTrip
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(454, 349);
Controls.Add(groupBox);
Controls.Add(buttonCancel);
Controls.Add(buttonTripSave);
Controls.Add(comboBoxDriverID);
Controls.Add(comboBoxCarID);
Controls.Add(numericUpDownConsumptionRate);
Controls.Add(comboBoxShift);
Controls.Add(dateTimePickerEndDate);
Controls.Add(dateTimePickerStartDate);
Controls.Add(label6);
Controls.Add(label5);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Margin = new Padding(2, 1, 2, 1);
Name = "FormTrip";
StartPosition = FormStartPosition.CenterParent;
Text = "FormTrip";
((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).EndInit();
groupBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewRoutes).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private Label label4;
private Label label5;
private Label label6;
private DateTimePicker dateTimePickerStartDate;
private DateTimePicker dateTimePickerEndDate;
private NumericUpDown numericUpDownConsumptionRate;
private ComboBox comboBoxCarID;
private ComboBox comboBoxDriverID;
private Button buttonTripSave;
private Button buttonCancel;
private GroupBox groupBox;
private DataGridView dataGridViewRoutes;
private Label label3;
private ComboBox comboBoxShift;
private DataGridViewComboBoxColumn ColumnRoute;
private DataGridViewTextBoxColumn ColumnFuelInit;
}
}

View File

@ -0,0 +1,76 @@
using ProjectFuel.Entities.Enums;
using ProjectFuel.Entities;
using ProjectFuel.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 ProjectFuel.Repositories.Implementations;
namespace ProjectFuel.Forms_
{
public partial class FormTrip : Form
{
private readonly ITripRepository _tripRepository;
public FormTrip(ITripRepository tripRepository, ICarRepository carRepository, IDriverRepository driverRepository, IRouteRepository routeRepository)
{
InitializeComponent();
_tripRepository = tripRepository ??
throw new ArgumentNullException(nameof(tripRepository));
comboBoxCarID.DataSource = carRepository.ReadCars();
comboBoxCarID.DisplayMember = "Car_Mark";
comboBoxCarID.ValueMember = "Car_ID";
comboBoxDriverID.DataSource = driverRepository.ReadDrivers();
comboBoxDriverID.DisplayMember = "Firstname";
comboBoxDriverID.ValueMember = "Driver_ID";
ColumnRoute.DataSource = routeRepository.ReadRoutes();
ColumnRoute.DisplayMember = "Start_Point";
ColumnRoute.ValueMember = "Route_ID";
comboBoxShift.DataSource = Enum.GetValues(typeof(Shift));
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (comboBoxCarID.SelectedIndex < 0 || comboBoxDriverID.SelectedIndex < 0 || dataGridViewRoutes.RowCount < 0)
throw new Exception("Имеются незаполненные поля");
_tripRepository.CreateTrip(Trip.CreateOperation(0, dateTimePickerStartDate.Value, dateTimePickerEndDate.Value, (Shift)comboBoxShift.SelectedItem!, (float)numericUpDownConsumptionRate.Value, (int)comboBoxCarID.SelectedValue!, (int)comboBoxDriverID.SelectedValue!, CreateListDriversFromDataGrid()));
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private List<TripRoute> CreateListDriversFromDataGrid()
{
var list = new List<TripRoute>();
foreach (DataGridViewRow row in dataGridViewRoutes.Rows)
{
if (row.Cells["ColumnRoute"].Value == null || row.Cells["ColumnFuelInit"].Value == null)
continue;
list.Add(TripRoute.CreateOperation(0, Convert.ToInt32(row.Cells["ColumnRoute"].Value), Convert.ToInt32(row.Cells["ColumnFuelInit"].Value)));
}
return list;
}
}
}

View File

@ -0,0 +1,129 @@
<?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>
<metadata name="dataGridViewRoutes.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnRoute.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnFuelInit.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

100
ProjectFuel/Forms_/FormTrips.Designer.cs generated Normal file
View File

@ -0,0 +1,100 @@
namespace ProjectFuel.Forms_
{
partial class FormTrips
{
/// <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()
{
panel1 = new Panel();
buttonAdd = new Button();
dataGridViewTrips = new DataGridView();
panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewTrips).BeginInit();
SuspendLayout();
//
// panel1
//
panel1.Controls.Add(buttonAdd);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(545, 0);
panel1.Name = "panel1";
panel1.Size = new Size(255, 450);
panel1.TabIndex = 0;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources._;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(45, 42);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(151, 131);
buttonAdd.TabIndex = 8;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridViewTrips
//
dataGridViewTrips.AllowUserToAddRows = false;
dataGridViewTrips.AllowUserToDeleteRows = false;
dataGridViewTrips.AllowUserToResizeColumns = false;
dataGridViewTrips.AllowUserToResizeRows = false;
dataGridViewTrips.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewTrips.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewTrips.Dock = DockStyle.Fill;
dataGridViewTrips.Location = new Point(0, 0);
dataGridViewTrips.MultiSelect = false;
dataGridViewTrips.Name = "dataGridViewTrips";
dataGridViewTrips.ReadOnly = true;
dataGridViewTrips.RowHeadersVisible = false;
dataGridViewTrips.RowHeadersWidth = 82;
dataGridViewTrips.RowTemplate.Height = 41;
dataGridViewTrips.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewTrips.Size = new Size(545, 450);
dataGridViewTrips.TabIndex = 1;
//
// FormTrips
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(dataGridViewTrips);
Controls.Add(panel1);
Name = "FormTrips";
StartPosition = FormStartPosition.CenterParent;
Text = " Поездки";
Load += FormTrips_Load;
panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewTrips).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel1;
private DataGridView dataGridViewTrips;
private Button buttonAdd;
}
}

View File

@ -0,0 +1,57 @@
using ProjectFuel.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 ProjectFuel.Forms_
{
public partial class FormTrips : Form
{
private readonly IUnityContainer _container;
private readonly ITripRepository _tripRepository;
public FormTrips(IUnityContainer container, ITripRepository tripRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_tripRepository = tripRepository ??
throw new ArgumentNullException(nameof(tripRepository));
}
private void FormTrips_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<FormTrip>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridViewTrips.DataSource = _tripRepository.ReadTrips();
}
}

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

@ -1,3 +1,11 @@
using ProjectFuel.Repositories.Implementations;
using ProjectFuel.Repositories;
using Unity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Serilog;
using Unity.Microsoft.Logging;
namespace ProjectFuel
{
internal static class Program
@ -11,7 +19,36 @@ namespace ProjectFuel
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
Application.Run(CreateContainer().Resolve<FormFuel>());
}
private static UnityContainer CreateContainer()
{
var container = new UnityContainer();
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
container.RegisterType<ICarRepository, CarRepository>();
container.RegisterType<IDriverRepository, DriverRepository>();
container.RegisterType<IFuelRepository, FuelRepository>();
container.RegisterType<IRefillRepository, RefillRepository>();
container.RegisterType<IRouteRepository, RouteRepository>();
container.RegisterType<ITripRepository, TripRepository>();
container.RegisterType<IConnectionString, ConnectionString>();
return container;
}
private static LoggerFactory CreateLoggerFactory()
{
var loggerFactory = new LoggerFactory();
loggerFactory.AddSerilog(new LoggerConfiguration()
.ReadFrom.Configuration(new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build())
.CreateLogger());
return loggerFactory;
}
}
}

View File

@ -2,10 +2,47 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net8.0-windows7.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Npgsql" Version="9.0.2" />
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,113 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ProjectFuel.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectFuel.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap _ {
get {
object obj = ResourceManager.GetObject("+", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap плюс {
get {
object obj = ResourceManager.GetObject("плюс", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap ред {
get {
object obj = ResourceManager.GetObject("ред", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap топливо {
get {
object obj = ResourceManager.GetObject("топливо", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap удалять {
get {
object obj = ResourceManager.GetObject("удалять", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -0,0 +1,136 @@
<?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>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="+" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\+.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="удалять" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\удалять.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="плюс" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\плюс.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="топливо" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\топливо.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ред" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ред.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@ -0,0 +1,8 @@
{
"profiles": {
"ProjectFuel": {
"commandName": "Project",
"workingDirectory": "C:\\Users\\annny\\OneDrive\\Рабочий стол\\ОТП"
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectFuel.Repositories;
public class ConnectionString : IConnectionString
{
string IConnectionString.ConnectionString => "Server=localhost, 5432;Username=postgres;Password=postgres;Database=";
}

View File

@ -0,0 +1,17 @@
using ProjectFuel.Entities;
using ProjectFuel.Entities;
namespace ProjectFuel.Repositories;
public interface ICarRepository
{
IEnumerable<Car> ReadCars();
Car ReadCarByID(int id);
void CreateCar(Car car);
void UpdateCar(Car car);
void DeleteCar(int id);
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectFuel.Repositories;
public interface IConnectionString
{
public string ConnectionString { get; }
}

View File

@ -0,0 +1,17 @@
using ProjectFuel.Entities;
using ProjectFuel.Entities;
namespace ProjectFuel.Repositories;
public interface IDriverRepository
{
IEnumerable<Driver> ReadDrivers();
Driver ReadDriverByID(int id);
void CreateDriver(Driver driver);
void UpdateDriver(Driver driver);
void DeleteDriver(int id);
}

View File

@ -0,0 +1,16 @@
using ProjectFuel.Entities;
namespace ProjectFuel.Repositories;
public interface IFuelRepository
{
IEnumerable<Fuel> ReadFuels();
Fuel ReadFuelByID(int id);
void CreateFuel(Fuel fuel);
void UpdateFuel(Fuel fuel);
void DeleteFuel(int id);
}

View File

@ -0,0 +1,11 @@
using ProjectFuel.Entities;
using ProjectFuel.Entities;
namespace ProjectFuel.Repositories;
public interface IRefillRepository
{
IEnumerable<Refill> ReadRefills(DateTime? dateFrom = null, DateTime? dateTo = null, int? fuelId = null, int? carId = null);
void CreateRefill(Refill refill);
}

View File

@ -0,0 +1,17 @@
using ProjectFuel.Entities;
using ProjectFuel.Entities;
namespace ProjectFuel.Repositories;
public interface IRouteRepository
{
IEnumerable<Route> ReadRoutes();
Route ReadRouteByID(int id);
void CreateRoute(Route route);
void UpdateRoute(Route route);
void DeleteRoute(int id);
}

View File

@ -0,0 +1,11 @@
using ProjectFuel.Entities;
using ProjectFuel.Entities;
namespace ProjectFuel.Repositories;
public interface ITripRepository
{
IEnumerable<Trip> ReadTrips(DateTime? dateFrom = null, DateTime? dateTo = null, int? carId = null, int? driverId = null, int? routeId = null);
void CreateTrip(Trip trip);
}

View File

@ -0,0 +1,123 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectFuel.Entities;
using ProjectFuel.Entities;
using ProjectFuel.Repositories;
namespace ProjectFuel.Repositories.Implementations;
public class CarRepository : ICarRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<CarRepository> _logger;
public CarRepository(IConnectionString connectionString, ILogger<CarRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateCar(Car car)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(car));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"INSERT INTO Car (Car_Mark, Car_Model, Car_Type, License, Consumption_Rate)
VALUES (@Car_Mark, @Car_Model, @Car_Type, @License, @Consumption_Rate)";
connection.Execute(queryInsert, car);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void DeleteCar(int id)
{
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Car
WHERE Car_ID=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
}
public Car ReadCarByID(int id)
{
_logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM Car
WHERE Car_ID=@id";
var car = connection.QueryFirst<Car>(querySelect, new { id });
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(car));
return car;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
}
public IEnumerable<Car> ReadCars()
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Car";
var cars = connection.Query<Car>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(cars));
return cars;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
public void UpdateCar(Car car)
{
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(car));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE Car
SET
Car_Mark=@Car_Mark,
Car_Model=@Car_Model,
Car_Type=@Car_Type,
License=@License,
Consumption_Rate=@Consumption_Rate
WHERE Car_ID=@Car_ID";
connection.Execute(queryUpdate, car);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
}
}

View File

@ -0,0 +1,123 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectFuel.Entities;
using ProjectFuel.Entities;
using ProjectFuel.Repositories;
namespace ProjectFuel.Repositories.Implementations;
public class DriverRepository : IDriverRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<DriverRepository> _logger;
public DriverRepository(IConnectionString connectionString, ILogger<DriverRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateDriver(Driver driver)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(driver));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"INSERT INTO Driver (Firstname, Secondname, Driver_License)
VALUES (@Firstname, @Secondname, @Driver_License)";
connection.Execute(queryInsert, driver);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void DeleteDriver(int id)
{
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Driver
WHERE Driver_ID=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
}
public Driver ReadDriverByID(int id)
{
_logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM Driver
WHERE Driver_ID=@id";
var driver = connection.QueryFirst<Driver>(querySelect, new { id });
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(driver));
return driver;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
}
public IEnumerable<Driver> ReadDrivers()
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Driver";
var drivers = connection.Query<Driver>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(drivers));
return drivers;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
public void UpdateDriver(Driver driver)
{
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(driver));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE Driver
SET
Firstname=@Firstname,
Secondname=@Secondname,
Driver_License=@Driver_License
WHERE Driver_ID=@Driver_ID";
connection.Execute(queryUpdate, driver);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
}
}

View File

@ -0,0 +1,120 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectFuel.Entities;
using ProjectFuel.Repositories;
namespace ProjectFuel.Repositories.Implementations;
public class FuelRepository : IFuelRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<FuelRepository> _logger;
public FuelRepository(IConnectionString connectionString, ILogger<FuelRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateFuel(Fuel fuel)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(fuel));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"INSERT INTO Fuel_And_Lubricants (Fuel_Type, Price_Per_Liter, Amount)
VALUES (@Fuel_Type, @Price_Per_Liter, @Amount)";
connection.Execute(queryInsert, fuel);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void DeleteFuel(int id)
{
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Fuel_And_Lubricants
WHERE Fuel_ID=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
}
public Fuel ReadFuelByID(int id)
{
_logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM Fuel_And_Lubricants
WHERE Fuel_ID=@id";
var fuel = connection.QueryFirst<Fuel>(querySelect, new { id });
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(fuel));
return fuel;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
}
public IEnumerable<Fuel> ReadFuels()
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Fuel_And_Lubricants";
var fuels = connection.Query<Fuel>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(fuels));
return fuels;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
public void UpdateFuel(Fuel fuel)
{
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(fuel));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE Fuel_And_Lubricants
SET
Fuel_Type=@Fuel_Type,
Price_Per_Liter=@Price_Per_Liter,
Amount=@Amount
WHERE Fuel_ID=@Fuel_ID";
connection.Execute(queryUpdate, fuel);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
}
}

View File

@ -0,0 +1,56 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectFuel.Entities;
using ProjectFuel.Entities;
using ProjectFuel.Repositories;
namespace ProjectFuel.Repositories.Implementations;
public class RefillRepository : IRefillRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<RefillRepository> _logger;
public RefillRepository(IConnectionString connectionString, ILogger<RefillRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateRefill(Refill refill)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(refill));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"INSERT INTO Refill (Refill_Date, Refill_Amount, Fuel_ID, Car_ID)
VALUES (@Refill_Date, @Refill_Amount, @Fuel_ID, @Car_ID)";
connection.Execute(queryInsert, refill);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public IEnumerable<Refill> ReadRefills(DateTime? dateFrom = null, DateTime? dateTo = null, int? fuelId = null, int? carId = null)
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Refill";
var refills = connection.Query<Refill>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(refills));
return refills;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
}

View File

@ -0,0 +1,121 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectFuel.Entities;
using ProjectFuel.Entities;
using ProjectFuel.Repositories;
namespace ProjectFuel.Repositories.Implementations;
public class RouteRepository : IRouteRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<RouteRepository> _logger;
public RouteRepository(IConnectionString connectionString, ILogger<RouteRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateRoute(Route route)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(route));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"INSERT INTO Route (Start_Point, End_Point, Route_Length)
VALUES (@Start_Point, @End_Point, @Route_Length)";
connection.Execute(queryInsert, route);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void DeleteRoute(int id)
{
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Route
WHERE Route_ID=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
}
public Route ReadRouteByID(int id)
{
_logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM Route
WHERE Route_ID=@id";
var route = connection.QueryFirst<Route>(querySelect, new { id });
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(route));
return route;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
}
public IEnumerable<Route> ReadRoutes()
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Route";
var routes = connection.Query<Route>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(routes));
return routes;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
public void UpdateRoute(Route route)
{
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(route));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE Route
SET
Start_Point=@Start_Point,
End_Point=@End_Point,
Route_Length=@Route_Length
WHERE Route_ID=@Route_ID";
connection.Execute(queryUpdate, route);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
}
}

View File

@ -0,0 +1,77 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectFuel.Entities;
using ProjectFuel.Entities;
using ProjectFuel.Repositories;
namespace ProjectFuel.Repositories.Implementations;
public class TripRepository : ITripRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<TripRepository> _logger;
public TripRepository(IConnectionString connectionString, ILogger<TripRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateTrip(Trip trip)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(trip));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open();
using var transaction = connection.BeginTransaction();
var queryInsert = @"
INSERT INTO Trip (Start_Date, End_Date, Shift, Fuel_Consumption, Car_ID, Driver_ID)
VALUES (@Start_Date, @End_Date, @Shift, @Fuel_Consumption, @Car_ID, @Driver_ID);
SELECT MAX(Trip_ID) FROM Trip";
var tripId = connection.QueryFirst<int>(queryInsert, trip, transaction);
var querySubInsert = @"
INSERT INTO Trip_Route (Trip_ID, Route_ID, Fuel_Init)
VALUES (@tripId, @Route_ID, @Fuel_Init)";
foreach (var elem in trip.Routes)
{
connection.Execute(querySubInsert, new
{
tripId,
elem.Route_ID,
elem.Fuel_Init
}, transaction);
}
transaction.Commit();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public IEnumerable<Trip> ReadTrips(DateTime? dateFrom = null, DateTime? dateTo = null, int? carId = null, int? driverId = null, int? routeId = null)
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Trip";
var trips = connection.Query<Trip>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(trips));
return trips;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
}

BIN
ProjectFuel/Resources/+.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

View File

@ -0,0 +1,15 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs/fuel_log.txt",
"rollingInterval": "Day"
}
}
]
}
}

15
appsettings.json Normal file
View File

@ -0,0 +1,15 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs/fuel_log.txt",
"rollingInterval": "Day"
}
}
]
}
}