пару форм сделано, скоро будет конец

This commit is contained in:
Baryshev Dmitry 2024-11-06 14:17:39 +04:00
parent f0f3d6dc0e
commit 613ffd491f
15 changed files with 442 additions and 18 deletions

View File

@ -35,9 +35,9 @@
textBoxPhoneNum = new TextBox();
labelPhoneNum = new Label();
labelTruckID = new Label();
textBoxTruckID = new TextBox();
buttonSaveDriver = new Button();
buttonCancelDriver = new Button();
comboBoxTruckID = new ComboBox();
SuspendLayout();
//
// labelFirstName
@ -98,13 +98,6 @@
labelTruckID.TabIndex = 6;
labelTruckID.Text = "Фура";
//
// textBoxTruckID
//
textBoxTruckID.Location = new Point(120, 164);
textBoxTruckID.Name = "textBoxTruckID";
textBoxTruckID.Size = new Size(183, 27);
textBoxTruckID.TabIndex = 7;
//
// buttonSaveDriver
//
buttonSaveDriver.Location = new Point(20, 231);
@ -123,14 +116,22 @@
buttonCancelDriver.Text = "Отмена";
buttonCancelDriver.UseVisualStyleBackColor = true;
//
// comboBoxTruckID
//
comboBoxTruckID.FormattingEnabled = true;
comboBoxTruckID.Location = new Point(120, 156);
comboBoxTruckID.Name = "comboBoxTruckID";
comboBoxTruckID.Size = new Size(151, 28);
comboBoxTruckID.TabIndex = 10;
//
// FormDriver
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(333, 302);
Controls.Add(comboBoxTruckID);
Controls.Add(buttonCancelDriver);
Controls.Add(buttonSaveDriver);
Controls.Add(textBoxTruckID);
Controls.Add(labelTruckID);
Controls.Add(textBoxPhoneNum);
Controls.Add(labelPhoneNum);
@ -154,8 +155,8 @@
private TextBox textBoxPhoneNum;
private Label labelPhoneNum;
private Label labelTruckID;
private TextBox textBoxTruckID;
private Button buttonSaveDriver;
private Button buttonCancelDriver;
private ComboBox comboBoxTruckID;
}
}

View File

@ -101,9 +101,11 @@
// numericUpDownMaxFuel
//
numericUpDownMaxFuel.Location = new Point(158, 156);
numericUpDownMaxFuel.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
numericUpDownMaxFuel.Name = "numericUpDownMaxFuel";
numericUpDownMaxFuel.Size = new Size(117, 27);
numericUpDownMaxFuel.TabIndex = 15;
numericUpDownMaxFuel.Value = new decimal(new int[] { 1, 0, 0, 0 });
//
// buttonTruckSave
//
@ -113,7 +115,7 @@
buttonTruckSave.TabIndex = 16;
buttonTruckSave.Text = "Сохранить";
buttonTruckSave.UseVisualStyleBackColor = true;
buttonTruckSave.Click += buttonTruckSave_Click;
buttonTruckSave.Click += ButtonTruckSave_Click;
//
// buttonTruckCancel
//
@ -123,7 +125,7 @@
buttonTruckCancel.TabIndex = 17;
buttonTruckCancel.Text = "Отмена";
buttonTruckCancel.UseVisualStyleBackColor = true;
buttonTruckCancel.Click += buttonTruckCancel_Click;
buttonTruckCancel.Click += ButtonTruckCancel_Click;
//
// FormTruck
//

View File

@ -1,4 +1,5 @@
using ProjectGarage.Repositories;
using ProjectGarage.Entities;
using ProjectGarage.Repositories;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -48,14 +49,36 @@ namespace ProjectGarage.Forms
throw new ArgumentNullException(nameof(truckRepository));
}
private void buttonTruckSave_Click(object sender, EventArgs e)
private void ButtonTruckSave_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(textBoxTruckNumbers.Text)
|| string.IsNullOrWhiteSpace(textBoxTruckBrand.Text)
|| string.IsNullOrWhiteSpace(textBoxTruckModel.Text))
{
throw new Exception("Имеются незаполненные поля");
}
if (_truckId.HasValue)
{
_truckRepository.UpdateTruck(CreateTruck(_truckId.Value));
}
else
{
_truckRepository.CreateTruck(CreateTruck(0));
}
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonTruckCancel_Click(object sender, EventArgs e)
{
private void ButtonTruckCancel_Click(object sender, EventArgs e) => Close();
}
private Truck CreateTruck(int id) => Truck.CreateTruck(id, textBoxTruckNumbers.Text,
textBoxTruckBrand.Text, textBoxTruckModel.Text, Convert.ToInt32(numericUpDownMaxFuel.Value));
}
}

126
ProjectGarage/Forms/FormTrucks.Designer.cs generated Normal file
View File

@ -0,0 +1,126 @@
namespace ProjectGarage.Forms
{
partial class FormTrucks
{
/// <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()
{
panelFormTrucksButtons = new Panel();
buttonUpdateTruck = new Button();
buttonDeleteTruck = new Button();
buttonAddTruck = new Button();
dataGridViewTrucks = new DataGridView();
panelFormTrucksButtons.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewTrucks).BeginInit();
SuspendLayout();
//
// panelFormTrucksButtons
//
panelFormTrucksButtons.Controls.Add(buttonUpdateTruck);
panelFormTrucksButtons.Controls.Add(buttonDeleteTruck);
panelFormTrucksButtons.Controls.Add(buttonAddTruck);
panelFormTrucksButtons.Dock = DockStyle.Right;
panelFormTrucksButtons.Location = new Point(441, 0);
panelFormTrucksButtons.Name = "panelFormTrucksButtons";
panelFormTrucksButtons.Size = new Size(161, 360);
panelFormTrucksButtons.TabIndex = 0;
//
// buttonUpdateTruck
//
buttonUpdateTruck.BackgroundImage = Properties.Resources.каранд;
buttonUpdateTruck.BackgroundImageLayout = ImageLayout.Stretch;
buttonUpdateTruck.Location = new Point(35, 140);
buttonUpdateTruck.Name = "buttonUpdateTruck";
buttonUpdateTruck.Size = new Size(94, 75);
buttonUpdateTruck.TabIndex = 2;
buttonUpdateTruck.UseVisualStyleBackColor = true;
buttonUpdateTruck.Click += ButtonUpdateTruck_Click;
//
// buttonDeleteTruck
//
buttonDeleteTruck.BackgroundImage = Properties.Resources.минусик;
buttonDeleteTruck.BackgroundImageLayout = ImageLayout.Stretch;
buttonDeleteTruck.Location = new Point(35, 247);
buttonDeleteTruck.Name = "buttonDeleteTruck";
buttonDeleteTruck.Size = new Size(94, 78);
buttonDeleteTruck.TabIndex = 1;
buttonDeleteTruck.UseVisualStyleBackColor = true;
buttonDeleteTruck.Click += ButtonDeleteTruck_Click;
//
// buttonAddTruck
//
buttonAddTruck.BackgroundImage = Properties.Resources.плюсик;
buttonAddTruck.BackgroundImageLayout = ImageLayout.Stretch;
buttonAddTruck.Location = new Point(35, 23);
buttonAddTruck.Name = "buttonAddTruck";
buttonAddTruck.Size = new Size(94, 75);
buttonAddTruck.TabIndex = 0;
buttonAddTruck.UseVisualStyleBackColor = true;
buttonAddTruck.Click += ButtonAddTruck_Click;
//
// dataGridViewTrucks
//
dataGridViewTrucks.AllowUserToAddRows = false;
dataGridViewTrucks.AllowUserToDeleteRows = false;
dataGridViewTrucks.AllowUserToResizeColumns = false;
dataGridViewTrucks.AllowUserToResizeRows = false;
dataGridViewTrucks.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewTrucks.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewTrucks.Dock = DockStyle.Fill;
dataGridViewTrucks.Location = new Point(0, 0);
dataGridViewTrucks.Name = "dataGridViewTrucks";
dataGridViewTrucks.ReadOnly = true;
dataGridViewTrucks.RowHeadersVisible = false;
dataGridViewTrucks.RowHeadersWidth = 51;
dataGridViewTrucks.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewTrucks.Size = new Size(441, 360);
dataGridViewTrucks.TabIndex = 1;
//
// FormTrucks
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(602, 360);
Controls.Add(dataGridViewTrucks);
Controls.Add(panelFormTrucksButtons);
Name = "FormTrucks";
StartPosition = FormStartPosition.CenterParent;
Text = "Фуры";
Load += FormTrucks_Load;
panelFormTrucksButtons.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewTrucks).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panelFormTrucksButtons;
private Button buttonUpdateTruck;
private Button buttonDeleteTruck;
private Button buttonAddTruck;
private DataGridView dataGridViewTrucks;
}
}

View File

@ -0,0 +1,110 @@
using ProjectGarage.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 ProjectGarage.Forms
{
public partial class FormTrucks : Form
{
private readonly IUnityContainer _container;
private readonly ITruckRepository _truckRepository;
public FormTrucks(IUnityContainer container, ITruckRepository truckRepository)
{
InitializeComponent();
_container = container ?? throw new ArgumentNullException(nameof(container));
_truckRepository = truckRepository ?? throw new ArgumentNullException(nameof(truckRepository));
}
private void FormTrucks_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при закгрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAddTruck_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormTruck>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDeleteTruck_Click(object sender, EventArgs e)
{
if (!TryGetIDFromSelectedRow(out var findid))
{
return;
}
if (MessageBox.Show("Удалить звпись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
try
{
_truckRepository.DeleteTruck(findid);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonUpdateTruck_Click(object sender, EventArgs e)
{
if (!TryGetIDFromSelectedRow(out var findid))
{
return;
}
try
{
var form = _container.Resolve<FormTruck>();
form.Id = findid;
form.ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridViewTrucks.DataSource = _truckRepository.ReadTrucks();
private bool TryGetIDFromSelectedRow(out int id)
{
id = 0;
if (dataGridViewTrucks.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error);
return false;
}
id = Convert.ToInt32(dataGridViewTrucks.SelectedRows[0].Cells["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>

View File

@ -59,5 +59,35 @@ namespace ProjectGarage.Properties {
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));
}
}
}
}

View File

@ -117,4 +117,14 @@
<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\плюсик.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\каранд.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@ -12,4 +12,6 @@ public interface ITransportationRepository
IEnumerable<Transportation> ReadTransportation(DateTime? dateForm = null, DateTime? dateTo = null, int? fuelId = null,
int? driverId = null, int? routeId = null);
void CreateTransportation(Transportation transportation);
void DeleteTransportation(int id);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

BIN
каранд.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
минусик.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
плюсик.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB