This commit is contained in:
goldfest 2024-05-04 00:48:13 +04:00
parent 5e43f07864
commit 5ac916f559
34 changed files with 4789 additions and 0 deletions

View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34616.47
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Transportlog", "Transportlog\Transportlog.csproj", "{BF0F0B14-FDC0-40ED-AC74-0C200A0B77A5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "database", "database\database.csproj", "{6BA90E1A-4B41-499C-AA38-0F3BDC04DB27}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BF0F0B14-FDC0-40ED-AC74-0C200A0B77A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BF0F0B14-FDC0-40ED-AC74-0C200A0B77A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF0F0B14-FDC0-40ED-AC74-0C200A0B77A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF0F0B14-FDC0-40ED-AC74-0C200A0B77A5}.Release|Any CPU.Build.0 = Release|Any CPU
{6BA90E1A-4B41-499C-AA38-0F3BDC04DB27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BA90E1A-4B41-499C-AA38-0F3BDC04DB27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BA90E1A-4B41-499C-AA38-0F3BDC04DB27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BA90E1A-4B41-499C-AA38-0F3BDC04DB27}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CB362534-5D30-4475-919A-D2EDBF9F5E57}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,201 @@
namespace Forms
{
partial class FormCargo
{
/// <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()
{
buttonDelete = new Button();
buttonUpdate = new Button();
buttonCreate = new Button();
textBoxWeight = new TextBox();
textBoxType = new TextBox();
label4 = new Label();
label3 = new Label();
label2 = new Label();
label1 = new Label();
dataGridView = new DataGridView();
textBoxName = new TextBox();
textBoxDescription = new TextBox();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// buttonDelete
//
buttonDelete.Location = new Point(786, 243);
buttonDelete.Margin = new Padding(3, 4, 3, 4);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(86, 31);
buttonDelete.TabIndex = 28;
buttonDelete.Text = "delete";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += buttonDelete_Click;
//
// buttonUpdate
//
buttonUpdate.Location = new Point(786, 205);
buttonUpdate.Margin = new Padding(3, 4, 3, 4);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(86, 31);
buttonUpdate.TabIndex = 27;
buttonUpdate.Text = "update";
buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += buttonUpdate_Click;
//
// buttonCreate
//
buttonCreate.Location = new Point(786, 166);
buttonCreate.Margin = new Padding(3, 4, 3, 4);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(86, 31);
buttonCreate.TabIndex = 26;
buttonCreate.Text = "create";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// textBoxWeight
//
textBoxWeight.Location = new Point(786, 92);
textBoxWeight.Margin = new Padding(3, 4, 3, 4);
textBoxWeight.Name = "textBoxWeight";
textBoxWeight.Size = new Size(114, 27);
textBoxWeight.TabIndex = 23;
//
// textBoxType
//
textBoxType.Location = new Point(786, 131);
textBoxType.Margin = new Padding(3, 4, 3, 4);
textBoxType.Name = "textBoxType";
textBoxType.Size = new Size(114, 27);
textBoxType.TabIndex = 21;
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(696, 135);
label4.Name = "label4";
label4.Size = new Size(40, 20);
label4.TabIndex = 19;
label4.Text = "Type";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(696, 96);
label3.Name = "label3";
label3.Size = new Size(56, 20);
label3.TabIndex = 18;
label3.Text = "Weight";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(696, 57);
label2.Name = "label2";
label2.Size = new Size(85, 20);
label2.TabIndex = 17;
label2.Text = "Description";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(696, 19);
label1.Name = "label1";
label1.Size = new Size(49, 20);
label1.TabIndex = 16;
label1.Text = "Name";
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(15, 19);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(661, 568);
dataGridView.TabIndex = 15;
dataGridView.CellClick += dataGridView_CellClick;
//
// textBoxName
//
textBoxName.Location = new Point(786, 19);
textBoxName.Margin = new Padding(3, 4, 3, 4);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(114, 27);
textBoxName.TabIndex = 29;
//
// textBoxDescription
//
textBoxDescription.Location = new Point(786, 54);
textBoxDescription.Margin = new Padding(3, 4, 3, 4);
textBoxDescription.Name = "textBoxDescription";
textBoxDescription.Size = new Size(114, 27);
textBoxDescription.TabIndex = 30;
//
// FormCargo
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(914, 600);
Controls.Add(textBoxDescription);
Controls.Add(textBoxName);
Controls.Add(buttonDelete);
Controls.Add(buttonUpdate);
Controls.Add(buttonCreate);
Controls.Add(textBoxWeight);
Controls.Add(textBoxType);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(dataGridView);
Margin = new Padding(3, 4, 3, 4);
Name = "FormCargo";
Text = "FormCargo";
Load += FormCargo_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonDelete;
private Button buttonUpdate;
private Button buttonCreate;
private TextBox textBoxWeight;
private TextBox textBoxType;
private Label label4;
private Label label3;
private Label label2;
private Label label1;
private DataGridView dataGridView;
private TextBox textBoxName;
private TextBox textBoxDescription;
}
}

View File

@ -0,0 +1,123 @@
using database;
using System.Data;
namespace Forms
{
public partial class FormCargo : Form
{
private Abstractions bd;
public FormCargo(Abstractions _bd)
{
InitializeComponent();
bd = _bd;
}
private void loadData()
{
// Получаем список автомобилей
List<Cargo> cargos = bd.GetCargos();
// Очищаем dataGridView перед заполнением новыми данными
dataGridView.Rows.Clear();
// Предварительно определяем столбцы, если это не было сделано ранее
if (dataGridView.ColumnCount == 0)
{
dataGridView.Columns.Add("id", "ID");
dataGridView.Columns.Add("Name", "Name");
dataGridView.Columns.Add("Description", "Description");
dataGridView.Columns.Add("Weight", "Weight");
dataGridView.Columns.Add("Type", "Type");
}
// Заполняем dataGridView данными из списка автомобилей
foreach (Cargo cargo in cargos)
{
dataGridView.Rows.Add(cargo.id,
cargo.Name, cargo.Description, cargo.Weight, cargo.Type);
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
// Создаем новый объект Car и заполняем его данными из текстовых полей и комбо-боксов
Cargo newCargo = new Cargo
{
Name = textBoxName.Text,
Description = textBoxDescription.Text,
Weight = decimal.Parse(textBoxWeight.Text),
Type = textBoxType.Text,
};
// Вызываем метод добавления нового автомобиля в базу данных
bd.AddCargo(newCargo);
// Обновляем dataGridView
loadData();
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID редактируемого автомобиля из выбранной строки dataGridView
int cargoId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
// Создаем объект Car и заполняем его данными из текстовых полей и комбо-боксов
Cargo updatedCargo = new Cargo
{
id = cargoId,
Name = textBoxName.Text,
Description = textBoxDescription.Text,
Weight = decimal.Parse(textBoxWeight.Text),
Type = textBoxType.Text,
};
// Вызываем метод обновления автомобиля в базе данных
bd.UpdateCargo(updatedCargo);
// Обновляем dataGridView
loadData();
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID удаляемого автомобиля из выбранной строки dataGridView
int cargoId = (int)dataGridView.Rows[rowIndex].Cells["id"].Value;
// Вызываем метод удаления автомобиля из базы данных
bd.DeleteCargo(cargoId);
// Обновляем dataGridView
loadData();
}
}
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
// Заполняем текстовые поля данными из выбранной строки
textBoxName.Text = row.Cells["Name"].Value.ToString();
textBoxDescription.Text = row.Cells["Description"].Value.ToString();
textBoxWeight.Text = row.Cells["Weight"].Value.ToString();
textBoxType.Text = row.Cells["Type"].Value.ToString();
}
}
private void FormCargo_Load(object sender, EventArgs e)
{
loadData();
}
}
}

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

@ -0,0 +1,180 @@
namespace Forms
{
partial class FormCargoOrders
{
/// <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()
{
buttonDelete = new Button();
buttonUpdate = new Button();
buttonCreate = new Button();
comboBoxCargo = new ComboBox();
label2 = new Label();
label1 = new Label();
dataGridView = new DataGridView();
comboBoxOrders = new ComboBox();
textBoxCount = new TextBox();
label4 = new Label();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// buttonDelete
//
buttonDelete.Location = new Point(1152, 222);
buttonDelete.Margin = new Padding(3, 4, 3, 4);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(86, 31);
buttonDelete.TabIndex = 28;
buttonDelete.Text = "delete";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += buttonDelete_Click;
//
// buttonUpdate
//
buttonUpdate.Location = new Point(1152, 184);
buttonUpdate.Margin = new Padding(3, 4, 3, 4);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(86, 31);
buttonUpdate.TabIndex = 27;
buttonUpdate.Text = "update";
buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += buttonUpdate_Click;
//
// buttonCreate
//
buttonCreate.Location = new Point(1152, 145);
buttonCreate.Margin = new Padding(3, 4, 3, 4);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(86, 31);
buttonCreate.TabIndex = 26;
buttonCreate.Text = "create";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// comboBoxCargo
//
comboBoxCargo.FormattingEnabled = true;
comboBoxCargo.Location = new Point(930, 16);
comboBoxCargo.Margin = new Padding(3, 4, 3, 4);
comboBoxCargo.Name = "comboBoxCargo";
comboBoxCargo.Size = new Size(308, 28);
comboBoxCargo.TabIndex = 25;
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(785, 61);
label2.Name = "label2";
label2.Size = new Size(53, 20);
label2.TabIndex = 17;
label2.Text = "Orders";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(785, 23);
label1.Name = "label1";
label1.Size = new Size(49, 20);
label1.TabIndex = 16;
label1.Text = "Cargo";
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(15, 19);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(689, 568);
dataGridView.TabIndex = 15;
dataGridView.CellClick += dataGridView_CellClick;
//
// comboBoxOrders
//
comboBoxOrders.FormattingEnabled = true;
comboBoxOrders.Location = new Point(930, 54);
comboBoxOrders.Margin = new Padding(3, 4, 3, 4);
comboBoxOrders.Name = "comboBoxOrders";
comboBoxOrders.Size = new Size(308, 28);
comboBoxOrders.TabIndex = 29;
//
// textBoxCount
//
textBoxCount.Location = new Point(930, 96);
textBoxCount.Margin = new Padding(3, 4, 3, 4);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(308, 27);
textBoxCount.TabIndex = 31;
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(785, 103);
label4.Name = "label4";
label4.Size = new Size(48, 20);
label4.TabIndex = 30;
label4.Text = "Count";
//
// FormCargoOrders
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1250, 600);
Controls.Add(textBoxCount);
Controls.Add(label4);
Controls.Add(comboBoxOrders);
Controls.Add(buttonDelete);
Controls.Add(buttonUpdate);
Controls.Add(buttonCreate);
Controls.Add(comboBoxCargo);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(dataGridView);
Margin = new Padding(3, 4, 3, 4);
Name = "FormCargoOrders";
Text = "FormCargoOrders";
Load += FormCargoOrders_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonDelete;
private Button buttonUpdate;
private Button buttonCreate;
private ComboBox comboBoxCargo;
private Label label2;
private Label label1;
private DataGridView dataGridView;
private ComboBox comboBoxOrders;
private TextBox textBoxCount;
private Label label4;
}
}

View File

@ -0,0 +1,160 @@
using database;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
namespace Forms
{
public partial class FormCargoOrders : Form
{
private Abstractions bd;
public FormCargoOrders(Abstractions _bd)
{
InitializeComponent();
bd = _bd;
}
private void loadData()
{
// Получаем список грузовых заказов
List<CargoOrder> cargoOrders = bd.GetCargoOrders();
// Очищаем dataGridView перед заполнением новыми данными
dataGridView.Rows.Clear();
// Предварительно определяем столбцы, если это не было сделано ранее
if (dataGridView.ColumnCount == 0)
{
dataGridView.Columns.Add("Id", "ID");
dataGridView.Columns.Add("CargoId", "CargoId");
dataGridView.Columns["CargoId"].Visible = false;
dataGridView.Columns.Add("Cargo", "Cargo");
dataGridView.Columns.Add("OrderId", "OrderId");
dataGridView.Columns["OrderId"].Visible = false;
dataGridView.Columns.Add("Order", "Order");
dataGridView.Columns.Add("Count", "Count");
}
comboBoxCargo.DataSource = bd.GetCargos()
.Select(x => new helpCombobox()
{
Text = x.Name + " " + x.Type,
Id = x.id
}).ToList();
comboBoxCargo.DisplayMember = "Text";
comboBoxCargo.ValueMember = "Id";
comboBoxOrders.DataSource = bd.GetOrders()
.Select(x => new helpCombobox()
{
Text ="id: " + x.id + " " + x.Status,
Id = x.id
}).ToList();
comboBoxOrders.DisplayMember = "Text";
comboBoxOrders.ValueMember = "Id";
// Заполняем dataGridView данными из списка грузовых заказов
foreach (CargoOrder cargoOrder in cargoOrders)
{
dataGridView.Rows.Add(
cargoOrder.id,
cargoOrder.CargoId,
cargoOrder.OrderId,
bd.GetCargoById(cargoOrder.CargoId).Name + " " + bd.GetCargoById(cargoOrder.CargoId).Type,
bd.GetOrdersById(cargoOrder.OrderId).id,
cargoOrder.Count
);
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
// Создаем новый объект CargoOrder и заполняем его данными из комбо-боксов и текстового поля
CargoOrder newCargoOrder = new CargoOrder
{
CargoId = ((helpCombobox)comboBoxCargo.SelectedItem).Id,
OrderId = ((helpCombobox)comboBoxOrders.SelectedItem).Id,
Count = Convert.ToInt32(textBoxCount.Text)
};
// Вызываем метод добавления нового грузового заказа в базу данных
bd.AddCargoOrder(newCargoOrder);
// Обновляем dataGridView
loadData();
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID редактируемого грузового заказа из выбранной строки dataGridView
int cargoOrderId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
// Создаем объект CargoOrder и заполняем его данными из комбо-боксов и текстового поля
CargoOrder updatedCargoOrder = new CargoOrder
{
id = cargoOrderId,
CargoId = ((helpCombobox)comboBoxCargo.SelectedItem).Id,
OrderId = ((helpCombobox)comboBoxOrders.SelectedItem).Id,
Count = Convert.ToInt32(textBoxCount.Text)
};
// Вызываем метод обновления грузового заказа в базе данных
bd.UpdateCargoOrder(updatedCargoOrder);
// Обновляем dataGridView
loadData();
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID удаляемого грузового заказа из выбранной строки dataGridView
int cargoOrderId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
// Вызываем метод удаления грузового заказа из базы данных
bd.DeleteCargoOrder(cargoOrderId);
// Обновляем dataGridView
loadData();
}
}
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
// Получаем значения для комбо-боксов из выбранной строки
textBoxCount.Text = row.Cells["Count"].Value.ToString();
int CargoId = Convert.ToInt32(row.Cells["CargoId"].Value);
string OrderId = Convert.ToString(row.Cells["OrderId"].Value);
comboBoxCargo.SelectedValue = CargoId;
comboBoxOrders.SelectedValue = OrderId;
}
}
private void FormCargoOrders_Load(object sender, EventArgs e)
{
loadData();
}
}
}

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

@ -0,0 +1,157 @@
namespace Forms
{
partial class FormCargoTransport
{
/// <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()
{
buttonDelete = new Button();
buttonUpdate = new Button();
buttonCreate = new Button();
comboBoxCargo = new ComboBox();
label2 = new Label();
label1 = new Label();
dataGridView = new DataGridView();
comboBoxTransport = new ComboBox();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// buttonDelete
//
buttonDelete.Location = new Point(1152, 222);
buttonDelete.Margin = new Padding(3, 4, 3, 4);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(86, 31);
buttonDelete.TabIndex = 28;
buttonDelete.Text = "delete";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += buttonDelete_Click;
//
// buttonUpdate
//
buttonUpdate.Location = new Point(1152, 184);
buttonUpdate.Margin = new Padding(3, 4, 3, 4);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(86, 31);
buttonUpdate.TabIndex = 27;
buttonUpdate.Text = "update";
buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += buttonUpdate_Click;
//
// buttonCreate
//
buttonCreate.Location = new Point(1152, 145);
buttonCreate.Margin = new Padding(3, 4, 3, 4);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(86, 31);
buttonCreate.TabIndex = 26;
buttonCreate.Text = "create";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// comboBoxCargo
//
comboBoxCargo.FormattingEnabled = true;
comboBoxCargo.Location = new Point(930, 16);
comboBoxCargo.Margin = new Padding(3, 4, 3, 4);
comboBoxCargo.Name = "comboBoxCargo";
comboBoxCargo.Size = new Size(308, 28);
comboBoxCargo.TabIndex = 25;
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(785, 61);
label2.Name = "label2";
label2.Size = new Size(71, 20);
label2.TabIndex = 17;
label2.Text = "Transport";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(785, 23);
label1.Name = "label1";
label1.Size = new Size(49, 20);
label1.TabIndex = 16;
label1.Text = "Cargo";
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(15, 19);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(689, 568);
dataGridView.TabIndex = 15;
dataGridView.CellClick += dataGridView_CellClick;
//
// comboBoxTransport
//
comboBoxTransport.FormattingEnabled = true;
comboBoxTransport.Location = new Point(930, 54);
comboBoxTransport.Margin = new Padding(3, 4, 3, 4);
comboBoxTransport.Name = "comboBoxTransport";
comboBoxTransport.Size = new Size(308, 28);
comboBoxTransport.TabIndex = 29;
//
// FormCargoTransport
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1250, 600);
Controls.Add(comboBoxTransport);
Controls.Add(buttonDelete);
Controls.Add(buttonUpdate);
Controls.Add(buttonCreate);
Controls.Add(comboBoxCargo);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(dataGridView);
Margin = new Padding(3, 4, 3, 4);
Name = "FormCargoTransport";
Text = "FormRental";
Load += FormRental_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonDelete;
private Button buttonUpdate;
private Button buttonCreate;
private ComboBox comboBoxCargo;
private Label label2;
private Label label1;
private DataGridView dataGridView;
private ComboBox comboBoxTransport;
}
}

View File

@ -0,0 +1,151 @@
using database;
using System.Data;
namespace Forms
{
public partial class FormCargoTransport : Form
{
private Abstractions bd;
public FormCargoTransport(Abstractions _bd)
{
InitializeComponent();
bd = _bd;
}
private void loadData()
{
// Получаем список аренд
List<CargoTransport> rentals = bd.GetCargoTransports();
// Очищаем dataGridView перед заполнением новыми данными
dataGridView.Rows.Clear();
// Предварительно определяем столбцы, если это не было сделано ранее
if (dataGridView.ColumnCount == 0)
{
dataGridView.Columns.Add("Id", "ID");
dataGridView.Columns.Add("CargoId", "CargoId");
dataGridView.Columns["CargoId"].Visible = false;
dataGridView.Columns.Add("Cargo", "Cargo");
dataGridView.Columns.Add("TransportId", "TransportId");
dataGridView.Columns["TransportId"].Visible = false;
dataGridView.Columns.Add("Transport", "Transport");
}
comboBoxCargo.DataSource = bd.GetCargos()
.Select(x => new helpCombobox()
{
Text = x.Name + " " + x.Type,
Id = x.id
}).ToList();
comboBoxCargo.DisplayMember = "Text";
comboBoxCargo.ValueMember = "Id";
comboBoxTransport.DataSource = bd.GetTransports()
.Select(x => new helpCombobox()
{
Text = x.Type + " " + x.Number,
Id = x.id
}).ToList();
comboBoxTransport.DisplayMember = "Text";
comboBoxTransport.ValueMember = "Id";
// Заполняем dataGridView данными из списка аренд
foreach (CargoTransport CargoTransport in rentals)
{
dataGridView.Rows.Add(
CargoTransport.id,
CargoTransport.CargoId,
CargoTransport.TransportId,
bd.GetCargoById(CargoTransport.CargoId).Name + " " + bd.GetCargoById(CargoTransport.CargoId).Type,
bd.GetTransportById(CargoTransport.TransportId).Type + " " + bd.GetTransportById(CargoTransport.TransportId).Number
);
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
// Создаем новый объект CargoTransport и заполняем его данными из текстовых полей и комбо-боксов
CargoTransport newRental = new CargoTransport
{
CargoId = ((helpCombobox)comboBoxCargo.SelectedItem).Id,
TransportId = ((helpCombobox)comboBoxTransport.SelectedItem).Id
};
// Вызываем метод добавления новой аренды в базу данных
bd.AddCargoTransports(newRental);
// Обновляем dataGridView
loadData();
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID редактируемой аренды из выбранной строки dataGridView
int rentalId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
// Создаем объект CargoTransport и заполняем его данными из текстовых полей и комбо-боксов
CargoTransport updatedRental = new CargoTransport
{
id = rentalId,
CargoId = ((helpCombobox)comboBoxCargo.SelectedItem).Id,
TransportId = ((helpCombobox)comboBoxTransport.SelectedItem).Id
};
// Вызываем метод обновления аренды в базе данных
bd.UpdateCargoTransports(updatedRental);
// Обновляем dataGridView
loadData();
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID удаляемой аренды из выбранной строки dataGridView
int rentalId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
// Вызываем метод удаления аренды из базы данных
bd.DeleteCargoTransports(rentalId);
// Обновляем dataGridView
loadData();
}
}
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
// Получаем значения для комбо-боксов из выбранной строки
int CargoId = Convert.ToInt32(row.Cells["CargoId"].Value);
string TransportId = Convert.ToString(row.Cells["TransportId"].Value);
comboBoxCargo.SelectedValue = CargoId;
comboBoxTransport.SelectedValue = TransportId;
}
}
private void FormRental_Load(object sender, EventArgs e)
{
loadData();
}
}
}

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

@ -0,0 +1,179 @@
namespace 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()
{
buttonDelete = new Button();
buttonUpdate = new Button();
buttonCreate = new Button();
textBoxCategory = new TextBox();
label3 = new Label();
label2 = new Label();
label1 = new Label();
dataGridView = new DataGridView();
textBoxName = new TextBox();
textBoxSurname = new TextBox();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// buttonDelete
//
buttonDelete.Location = new Point(786, 243);
buttonDelete.Margin = new Padding(3, 4, 3, 4);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(86, 31);
buttonDelete.TabIndex = 28;
buttonDelete.Text = "delete";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += buttonDelete_Click;
//
// buttonUpdate
//
buttonUpdate.Location = new Point(786, 205);
buttonUpdate.Margin = new Padding(3, 4, 3, 4);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(86, 31);
buttonUpdate.TabIndex = 27;
buttonUpdate.Text = "update";
buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += buttonUpdate_Click;
//
// buttonCreate
//
buttonCreate.Location = new Point(786, 166);
buttonCreate.Margin = new Padding(3, 4, 3, 4);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(86, 31);
buttonCreate.TabIndex = 26;
buttonCreate.Text = "create";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// textBoxCategory
//
textBoxCategory.Location = new Point(786, 92);
textBoxCategory.Margin = new Padding(3, 4, 3, 4);
textBoxCategory.Name = "textBoxCategory";
textBoxCategory.Size = new Size(114, 27);
textBoxCategory.TabIndex = 23;
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(662, 96);
label3.Name = "label3";
label3.Size = new Size(69, 20);
label3.TabIndex = 18;
label3.Text = "Category";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(662, 57);
label2.Name = "label2";
label2.Size = new Size(67, 20);
label2.TabIndex = 17;
label2.Text = "Surname";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(662, 19);
label1.Name = "label1";
label1.Size = new Size(49, 20);
label1.TabIndex = 16;
label1.Text = "Name";
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(15, 19);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(628, 568);
dataGridView.TabIndex = 15;
dataGridView.CellClick += dataGridView_CellClick;
//
// textBoxName
//
textBoxName.Location = new Point(786, 19);
textBoxName.Margin = new Padding(3, 4, 3, 4);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(114, 27);
textBoxName.TabIndex = 29;
//
// textBoxSurname
//
textBoxSurname.Location = new Point(786, 54);
textBoxSurname.Margin = new Padding(3, 4, 3, 4);
textBoxSurname.Name = "textBoxSurname";
textBoxSurname.Size = new Size(114, 27);
textBoxSurname.TabIndex = 30;
//
// FormDriver
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(914, 600);
Controls.Add(textBoxSurname);
Controls.Add(textBoxName);
Controls.Add(buttonDelete);
Controls.Add(buttonUpdate);
Controls.Add(buttonCreate);
Controls.Add(textBoxCategory);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(dataGridView);
Margin = new Padding(3, 4, 3, 4);
Name = "FormDriver";
Text = "FormTransport";
Load += FormTransport_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonDelete;
private Button buttonUpdate;
private Button buttonCreate;
private TextBox textBoxCategory;
private TextBox textBoxName;
private Label label4;
private Label label3;
private Label label2;
private Label label1;
private DataGridView dataGridView;
private TextBox textBoxSurname;
}
}

View File

@ -0,0 +1,120 @@
using database;
using System.Data;
using System.Windows.Forms;
namespace Forms
{
public partial class FormDriver : Form
{
private Abstractions bd;
public FormDriver(Abstractions _bd)
{
InitializeComponent();
bd = _bd;
}
private void loadData()
{
// Получаем список автомобилей
List<Driver> drivers = bd.GetDrivers();
// Очищаем dataGridView перед заполнением новыми данными
dataGridView.Rows.Clear();
// Предварительно определяем столбцы, если это не было сделано ранее
if (dataGridView.ColumnCount == 0)
{
dataGridView.Columns.Add("id", "ID");
dataGridView.Columns.Add("Name", "Name");
dataGridView.Columns.Add("Surname", "Surname");
dataGridView.Columns.Add("Category", "Category");
}
// Заполняем dataGridView данными из списка автомобилей
foreach (Driver Driver in drivers)
{
dataGridView.Rows.Add(Driver.id,
Driver.Name, Driver.Surname, Driver.Category);
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
// Создаем новый объект Car и заполняем его данными из текстовых полей и комбо-боксов
Driver newDriver = new Driver
{
Name = textBoxName.Text,
Surname = textBoxSurname.Text,
Category = int.Parse(textBoxCategory.Text),
};
// Вызываем метод добавления нового автомобиля в базу данных
bd.AddDriver(newDriver);
// Обновляем dataGridView
loadData();
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID редактируемого автомобиля из выбранной строки dataGridView
int driverId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
// Создаем объект Car и заполняем его данными из текстовых полей и комбо-боксов
Driver updatedDriver = new Driver
{
id = driverId,
Name = textBoxName.Text,
Surname = textBoxSurname.Text,
Category = int.Parse(textBoxCategory.Text),
};
// Вызываем метод обновления автомобиля в базе данных
bd.UpdateDriver(updatedDriver);
// Обновляем dataGridView
loadData();
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID удаляемого автомобиля из выбранной строки dataGridView
int driverId = (int)dataGridView.Rows[rowIndex].Cells["id"].Value;
// Вызываем метод удаления автомобиля из базы данных
bd.DeleteDriver(driverId);
// Обновляем dataGridView
loadData();
}
}
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
// Заполняем текстовые поля данными из выбранной строки
textBoxName.Text = row.Cells["Name"].Value.ToString();
textBoxSurname.Text = row.Cells["Surname"].Value.ToString();
textBoxCategory.Text = row.Cells["Category"].Value.ToString();
}
}
private void FormTransport_Load(object sender, EventArgs e)
{
loadData();
}
}
}

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

@ -0,0 +1,176 @@
namespace Forms
{
partial class FormMain
{
/// <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();
tablesToolStripMenuItem = new ToolStripMenuItem();
cargoToolStripMenuItem = new ToolStripMenuItem();
transportToolStripMenuItem = new ToolStripMenuItem();
carModelToolStripMenuItem = new ToolStripMenuItem();
branchToolStripMenuItem = new ToolStripMenuItem();
clientToolStripMenuItem = new ToolStripMenuItem();
rentalToolStripMenuItem = new ToolStripMenuItem();
cargotransportToolStripMenuItem = new ToolStripMenuItem();
cargoordersToolStripMenuItem = new ToolStripMenuItem();
buttonTest = new Button();
textBoxTest = new TextBox();
menuStrip1.SuspendLayout();
SuspendLayout();
//
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { tablesToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Padding = new Padding(7, 3, 0, 3);
menuStrip1.Size = new Size(497, 30);
menuStrip1.TabIndex = 0;
menuStrip1.Text = "menuStrip1";
//
// tablesToolStripMenuItem
//
tablesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { cargoToolStripMenuItem, transportToolStripMenuItem, carModelToolStripMenuItem, branchToolStripMenuItem, clientToolStripMenuItem, rentalToolStripMenuItem, cargotransportToolStripMenuItem, cargoordersToolStripMenuItem });
tablesToolStripMenuItem.Name = "tablesToolStripMenuItem";
tablesToolStripMenuItem.Size = new Size(63, 24);
tablesToolStripMenuItem.Text = "tables";
//
// cargoToolStripMenuItem
//
cargoToolStripMenuItem.Name = "cargoToolStripMenuItem";
cargoToolStripMenuItem.Size = new Size(224, 26);
cargoToolStripMenuItem.Text = "cargo";
cargoToolStripMenuItem.Click += cargoToolStripMenuItem_Click;
//
// transportToolStripMenuItem
//
transportToolStripMenuItem.Name = "transportToolStripMenuItem";
transportToolStripMenuItem.Size = new Size(224, 26);
transportToolStripMenuItem.Text = "transport";
transportToolStripMenuItem.Click += transportToolStripMenuItem_Click;
//
// carModelToolStripMenuItem
//
carModelToolStripMenuItem.Name = "carModelToolStripMenuItem";
carModelToolStripMenuItem.Size = new Size(224, 26);
carModelToolStripMenuItem.Text = "warehouse";
carModelToolStripMenuItem.Click += warehouseToolStripMenuItem_Click;
//
// branchToolStripMenuItem
//
branchToolStripMenuItem.Name = "branchToolStripMenuItem";
branchToolStripMenuItem.Size = new Size(224, 26);
branchToolStripMenuItem.Text = "driver";
branchToolStripMenuItem.Click += driverToolStripMenuItem_Click;
//
// clientToolStripMenuItem
//
clientToolStripMenuItem.Name = "clientToolStripMenuItem";
clientToolStripMenuItem.Size = new Size(224, 26);
clientToolStripMenuItem.Text = "routes";
clientToolStripMenuItem.Click += routesToolStripMenuItem_Click;
//
// rentalToolStripMenuItem
//
rentalToolStripMenuItem.Name = "rentalToolStripMenuItem";
rentalToolStripMenuItem.Size = new Size(224, 26);
rentalToolStripMenuItem.Text = "orders";
rentalToolStripMenuItem.Click += ordersToolStripMenuItem_Click;
//
// cargotransportToolStripMenuItem
//
cargotransportToolStripMenuItem.Name = "cargotransportToolStripMenuItem";
cargotransportToolStripMenuItem.Size = new Size(224, 26);
cargotransportToolStripMenuItem.Text = "cargo_transport";
cargotransportToolStripMenuItem.Click += cargo_transportToolStripMenuItem_Click;
//
// cargoordersToolStripMenuItem
//
cargoordersToolStripMenuItem.Name = "cargoordersToolStripMenuItem";
cargoordersToolStripMenuItem.Size = new Size(224, 26);
cargoordersToolStripMenuItem.Text = "cargo_orders";
cargoordersToolStripMenuItem.Click += cargo_ordersToolStripMenuItem_Click;
//
// buttonTest
//
buttonTest.BackColor = SystemColors.Highlight;
buttonTest.Font = new Font("Showcard Gothic", 19.8000011F, FontStyle.Regular, GraphicsUnit.Point);
buttonTest.ForeColor = SystemColors.ActiveCaption;
buttonTest.Location = new Point(151, 96);
buttonTest.Margin = new Padding(3, 4, 3, 4);
buttonTest.Name = "buttonTest";
buttonTest.Size = new Size(204, 114);
buttonTest.TabIndex = 1;
buttonTest.Text = "Тест";
buttonTest.UseVisualStyleBackColor = false;
buttonTest.Click += buttonTest_Click;
//
// textBoxTest
//
textBoxTest.Location = new Point(111, 36);
textBoxTest.Margin = new Padding(3, 4, 3, 4);
textBoxTest.Multiline = true;
textBoxTest.Name = "textBoxTest";
textBoxTest.Size = new Size(286, 52);
textBoxTest.TabIndex = 2;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(497, 223);
Controls.Add(textBoxTest);
Controls.Add(buttonTest);
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
Margin = new Padding(3, 4, 3, 4);
Name = "FormMain";
Text = "FormMain";
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private MenuStrip menuStrip1;
private ToolStripMenuItem tablesToolStripMenuItem;
private ToolStripMenuItem carModelToolStripMenuItem;
private ToolStripMenuItem cargoToolStripMenuItem;
private ToolStripMenuItem branchToolStripMenuItem;
private ToolStripMenuItem clientToolStripMenuItem;
private ToolStripMenuItem rentalToolStripMenuItem;
private Button buttonTest;
private TextBox textBoxTest;
private ToolStripMenuItem transportToolStripMenuItem;
private ToolStripMenuItem cargotransportToolStripMenuItem;
private ToolStripMenuItem cargoordersToolStripMenuItem;
}
}

View File

@ -0,0 +1,101 @@
using database;
namespace Forms
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
private void cargoToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCargo));
if (service is FormCargo form)
{
form.ShowDialog();
}
}
private void transportToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormTransport));
if (service is FormTransport form)
{
form.ShowDialog();
}
}
private void warehouseToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormWarehouse));
if (service is FormWarehouse form)
{
form.ShowDialog();
}
}
private void driverToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDriver));
if (service is FormDriver form)
{
form.ShowDialog();
}
}
private void routesToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormRoutes));
if (service is FormRoutes form)
{
form.ShowDialog();
}
}
private void ordersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormOrders));
if (service is FormOrders form)
{
form.ShowDialog();
}
}
private void cargo_transportToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCargoTransport));
if (service is FormCargoTransport form)
{
form.ShowDialog();
}
}
private void cargo_ordersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCargoOrders));
if (service is FormCargoOrders form)
{
form.ShowDialog();
}
}
private void buttonTest_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(Abstractions));
if (service is Abstractions bd)
{
var cars = bd.GetCargos();
int id = cars.Last().id;
DateTime startTime = DateTime.Now;
bd.DeleteCargo(id);
DateTime endTime = DateTime.Now;
textBoxTest.Text = $"Время выполнения запроса: {(endTime - startTime).TotalMilliseconds} миллисекунд";
}
}
}
}

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>

View File

@ -0,0 +1,181 @@
namespace Forms
{
partial class FormOrders
{
/// <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()
{
buttonDelete = new Button();
buttonUpdate = new Button();
buttonCreate = new Button();
this.comboBoxRoutes = new ComboBox();
this.textBoxStatus = new TextBox();
textBoxOrderDate = new TextBox();
label4 = new Label();
label3 = new Label();
label1 = new Label();
dataGridView = new DataGridView();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// buttonDelete
//
buttonDelete.Location = new Point(1152, 303);
buttonDelete.Margin = new Padding(3, 4, 3, 4);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(86, 31);
buttonDelete.TabIndex = 28;
buttonDelete.Text = "delete";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += buttonDelete_Click;
//
// buttonUpdate
//
buttonUpdate.Location = new Point(1152, 265);
buttonUpdate.Margin = new Padding(3, 4, 3, 4);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(86, 31);
buttonUpdate.TabIndex = 27;
buttonUpdate.Text = "update";
buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += buttonUpdate_Click;
//
// buttonCreate
//
buttonCreate.Location = new Point(1152, 226);
buttonCreate.Margin = new Padding(3, 4, 3, 4);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(86, 31);
buttonCreate.TabIndex = 26;
buttonCreate.Text = "create";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// comboBoxRoutes
//
this.comboBoxRoutes.FormattingEnabled = true;
this.comboBoxRoutes.Location = new Point(930, 16);
this.comboBoxRoutes.Margin = new Padding(3, 4, 3, 4);
this.comboBoxRoutes.Name = "comboBoxRoutes";
this.comboBoxRoutes.Size = new Size(308, 28);
this.comboBoxRoutes.TabIndex = 25;
//
// textBoxStatus
//
this.textBoxStatus.Location = new Point(930, 52);
this.textBoxStatus.Margin = new Padding(3, 4, 3, 4);
this.textBoxStatus.Name = "textBoxStatus";
this.textBoxStatus.Size = new Size(308, 27);
this.textBoxStatus.TabIndex = 23;
//
// textBoxOrderDate
//
textBoxOrderDate.Location = new Point(930, 91);
textBoxOrderDate.Margin = new Padding(3, 4, 3, 4);
textBoxOrderDate.Name = "textBoxOrderDate";
textBoxOrderDate.Size = new Size(308, 27);
textBoxOrderDate.TabIndex = 21;
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(785, 98);
label4.Name = "label4";
label4.Size = new Size(83, 20);
label4.TabIndex = 19;
label4.Text = "Order Date";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(785, 59);
label3.Name = "label3";
label3.Size = new Size(49, 20);
label3.TabIndex = 18;
label3.Text = "Status";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(785, 24);
label1.Name = "label1";
label1.Size = new Size(54, 20);
label1.TabIndex = 16;
label1.Text = "Routes";
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(15, 19);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(689, 568);
dataGridView.TabIndex = 15;
dataGridView.CellClick += dataGridView_CellClick;
//
// FormOrders
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1250, 600);
Controls.Add(buttonDelete);
Controls.Add(buttonUpdate);
Controls.Add(buttonCreate);
Controls.Add(this.comboBoxRoutes);
Controls.Add(this.textBoxStatus);
Controls.Add(textBoxOrderDate);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(label1);
Controls.Add(dataGridView);
Margin = new Padding(3, 4, 3, 4);
Name = "FormOrders";
Text = "FormRental";
Load += FormRental_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonDelete;
private Button buttonUpdate;
private Button buttonCreate;
private ComboBox comboBoxRoutes;
private TextBox textBoxOrderDate;
private TextBox textBoxStatus;
private Label label5;
private Label label4;
private Label label3;
private Label label2;
private Label label1;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,141 @@
using database;
using System.Data;
namespace Forms
{
public partial class FormOrders : Form
{
private Abstractions bd;
public FormOrders(Abstractions _bd)
{
InitializeComponent();
bd = _bd;
}
private void loadData()
{
// Получаем список аренд
List<Orders> rentals = bd.GetOrders();
// Очищаем dataGridView перед заполнением новыми данными
dataGridView.Rows.Clear();
// Предварительно определяем столбцы, если это не было сделано ранее
if (dataGridView.ColumnCount == 0)
{
dataGridView.Columns.Add("Id", "ID");
dataGridView.Columns.Add("Status", "Status");
dataGridView.Columns.Add("OrderDate", "Order Date");
dataGridView.Columns.Add("RoutesId", "RoutesId");
dataGridView.Columns["RoutesId"].Visible = false;
dataGridView.Columns.Add("Routes", "Routes");
}
comboBoxRoutes.DataSource = bd.GetRoutes()
.Select(x => new helpCombobox()
{
Text = x.EndPoint,
Id = x.id
}).ToList();
comboBoxRoutes.DisplayMember = "Text";
comboBoxRoutes.ValueMember = "Id";
// Заполняем dataGridView данными из списка аренд
foreach (Orders Orders in rentals)
{
dataGridView.Rows.Add(
Orders.id,
Orders.Status,
Orders.OrderDate.ToString().Split(" ")[0],
Orders.RoutesId,
bd.GetRoutesById(Orders.RoutesId).EndPoint
);
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
// Создаем новый объект Routes и заполняем его данными из текстовых полей и комбо-боксов
Orders newRental = new Orders
{
Status = textBoxStatus.Text,
OrderDate = DateTime.Parse(textBoxOrderDate.Text + " 00:00:00"),
RoutesId = ((helpCombobox)comboBoxRoutes.SelectedItem).Id
};
// Вызываем метод добавления новой аренды в базу данных
bd.AddOrders(newRental);
// Обновляем dataGridView
loadData();
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID редактируемой аренды из выбранной строки dataGridView
int rentalId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
// Создаем объект Routes и заполняем его данными из текстовых полей и комбо-боксов
Orders updatedRental = new Orders
{
id = rentalId,
Status = textBoxStatus.Text,
OrderDate = DateTime.Parse(textBoxOrderDate.Text + " 00:00:00"),
RoutesId = ((helpCombobox)comboBoxRoutes.SelectedItem).Id
};
// Вызываем метод обновления аренды в базе данных
bd.UpdateOrders(updatedRental);
// Обновляем dataGridView
loadData();
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID удаляемой аренды из выбранной строки dataGridView
int rentalId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
// Вызываем метод удаления аренды из базы данных
bd.DeleteOrders(rentalId);
// Обновляем dataGridView
loadData();
}
}
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
// Заполняем текстовые поля данными из выбранной строки
textBoxStatus.Text = row.Cells["Status"].Value.ToString();
textBoxOrderDate.Text = row.Cells["OrderDate"].Value.ToString().Split(" ")[0];
string routesId = Convert.ToString(row.Cells["RoutesId"].Value);
comboBoxRoutes.SelectedValue = routesId;
}
}
private void FormRental_Load(object sender, EventArgs e)
{
loadData();
}
}
}

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

@ -0,0 +1,226 @@
namespace 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()
{
buttonDelete = new Button();
buttonUpdate = new Button();
buttonCreate = new Button();
comboBoxWarehouse = new ComboBox();
textBoxDepartureTime = new TextBox();
textBoxEndPoint = new TextBox();
textBoxArrivalTime = new TextBox();
label5 = new Label();
label4 = new Label();
label3 = new Label();
label2 = new Label();
label1 = new Label();
dataGridView = new DataGridView();
comboBoxDriver = new ComboBox();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// buttonDelete
//
buttonDelete.Location = new Point(1152, 303);
buttonDelete.Margin = new Padding(3, 4, 3, 4);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(86, 31);
buttonDelete.TabIndex = 28;
buttonDelete.Text = "delete";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += buttonDelete_Click;
//
// buttonUpdate
//
buttonUpdate.Location = new Point(1152, 265);
buttonUpdate.Margin = new Padding(3, 4, 3, 4);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(86, 31);
buttonUpdate.TabIndex = 27;
buttonUpdate.Text = "update";
buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += buttonUpdate_Click;
//
// buttonCreate
//
buttonCreate.Location = new Point(1152, 226);
buttonCreate.Margin = new Padding(3, 4, 3, 4);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(86, 31);
buttonCreate.TabIndex = 26;
buttonCreate.Text = "create";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// comboBoxWarehouse
//
comboBoxWarehouse.FormattingEnabled = true;
comboBoxWarehouse.Location = new Point(930, 16);
comboBoxWarehouse.Margin = new Padding(3, 4, 3, 4);
comboBoxWarehouse.Name = "comboBoxWarehouse";
comboBoxWarehouse.Size = new Size(308, 28);
comboBoxWarehouse.TabIndex = 25;
//
// textBoxDepartureTime
//
textBoxDepartureTime.Location = new Point(930, 170);
textBoxDepartureTime.Margin = new Padding(3, 4, 3, 4);
textBoxDepartureTime.Name = "textBoxDepartureTime";
textBoxDepartureTime.Size = new Size(308, 27);
textBoxDepartureTime.TabIndex = 24;
//
// textBoxEndPoint
//
textBoxEndPoint.Location = new Point(930, 93);
textBoxEndPoint.Margin = new Padding(3, 4, 3, 4);
textBoxEndPoint.Name = "textBoxEndPoint";
textBoxEndPoint.Size = new Size(308, 27);
textBoxEndPoint.TabIndex = 23;
//
// textBoxArrivalTime
//
textBoxArrivalTime.Location = new Point(930, 132);
textBoxArrivalTime.Margin = new Padding(3, 4, 3, 4);
textBoxArrivalTime.Name = "textBoxArrivalTime";
textBoxArrivalTime.Size = new Size(308, 27);
textBoxArrivalTime.TabIndex = 21;
//
// label5
//
label5.AutoSize = true;
label5.Location = new Point(785, 177);
label5.Name = "label5";
label5.Size = new Size(110, 20);
label5.TabIndex = 20;
label5.Text = "Departure time";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(785, 139);
label4.Name = "label4";
label4.Size = new Size(86, 20);
label4.TabIndex = 19;
label4.Text = "Arrival time";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(785, 100);
label3.Name = "label3";
label3.Size = new Size(73, 20);
label3.TabIndex = 18;
label3.Text = "End point";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(785, 61);
label2.Name = "label2";
label2.Size = new Size(49, 20);
label2.TabIndex = 17;
label2.Text = "Driver";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(785, 23);
label1.Name = "label1";
label1.Size = new Size(82, 20);
label1.TabIndex = 16;
label1.Text = "Warehouse";
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(15, 19);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(689, 568);
dataGridView.TabIndex = 15;
dataGridView.CellClick += dataGridView_CellClick;
//
// comboBoxDriver
//
comboBoxDriver.FormattingEnabled = true;
comboBoxDriver.Location = new Point(930, 54);
comboBoxDriver.Margin = new Padding(3, 4, 3, 4);
comboBoxDriver.Name = "comboBoxDriver";
comboBoxDriver.Size = new Size(308, 28);
comboBoxDriver.TabIndex = 29;
//
// FormRoutes
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1250, 600);
Controls.Add(comboBoxDriver);
Controls.Add(buttonDelete);
Controls.Add(buttonUpdate);
Controls.Add(buttonCreate);
Controls.Add(comboBoxWarehouse);
Controls.Add(textBoxDepartureTime);
Controls.Add(textBoxEndPoint);
Controls.Add(textBoxArrivalTime);
Controls.Add(label5);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(dataGridView);
Margin = new Padding(3, 4, 3, 4);
Name = "FormRoutes";
Text = "FormRental";
Load += FormRental_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonDelete;
private Button buttonUpdate;
private Button buttonCreate;
private ComboBox comboBoxWarehouse;
private TextBox textBoxDepartureTime;
private TextBox textBoxEndPoint;
private TextBox textBoxArrivalTime;
private Label label5;
private Label label4;
private Label label3;
private Label label2;
private Label label1;
private DataGridView dataGridView;
private ComboBox comboBoxDriver;
}
}

View File

@ -0,0 +1,168 @@
using database;
using System.Data;
namespace Forms
{
public partial class FormRoutes : Form
{
private Abstractions bd;
public FormRoutes(Abstractions _bd)
{
InitializeComponent();
bd = _bd;
}
private void loadData()
{
// Получаем список аренд
List<Routes> rentals = bd.GetRoutes();
// Очищаем dataGridView перед заполнением новыми данными
dataGridView.Rows.Clear();
// Предварительно определяем столбцы, если это не было сделано ранее
if (dataGridView.ColumnCount == 0)
{
dataGridView.Columns.Add("Id", "ID");
dataGridView.Columns.Add("EndPoint", "End Point");
dataGridView.Columns.Add("ArrivalTime", "Arrival Time");
dataGridView.Columns.Add("DepartureTime", "Departure Time");
dataGridView.Columns.Add("WarehouseId", "WarehouseId");
dataGridView.Columns["WarehouseId"].Visible = false;
dataGridView.Columns.Add("Warehouse", "Warehouse");
dataGridView.Columns.Add("DriverId", "DriverId");
dataGridView.Columns["DriverId"].Visible = false;
dataGridView.Columns.Add("Driver", "Driver");
}
comboBoxDriver.DataSource = bd.GetDrivers()
.Select(x => new helpCombobox()
{
Text = x.Name + " " + x.Surname,
Id = x.id
}).ToList();
comboBoxDriver.DisplayMember = "Text";
comboBoxDriver.ValueMember = "Id";
comboBoxWarehouse.DataSource = bd.GetWarehouses()
.Select(x => new helpCombobox()
{
Text = x.Name + " " + x.Address,
Id = x.id
}).ToList();
comboBoxWarehouse.DisplayMember = "Text";
comboBoxWarehouse.ValueMember = "Id";
// Заполняем dataGridView данными из списка аренд
foreach (Routes Routes in rentals)
{
dataGridView.Rows.Add(
Routes.id,
Routes.EndPoint,
Routes.ArrivalTime.ToString().Split(" ")[0],
Routes.DepartureTime.ToString().Split(" ")[0],
Routes.WarehouseId,
Routes.DriverId,
bd.GetWarehouseById(Routes.WarehouseId).Name + " " + bd.GetWarehouseById(Routes.WarehouseId).Address,
bd.GetDriverById(Routes.DriverId).Name + " " + bd.GetDriverById(Routes.DriverId).Surname
);
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
// Создаем новый объект Routes и заполняем его данными из текстовых полей и комбо-боксов
Routes newRental = new Routes
{
EndPoint = textBoxEndPoint.Text,
ArrivalTime = DateTime.Parse(textBoxArrivalTime.Text + " 00:00:00"),
DepartureTime = DateTime.Parse(textBoxDepartureTime.Text + " 00:00:00"),
WarehouseId = ((helpCombobox)comboBoxWarehouse.SelectedItem).Id,
DriverId = ((helpCombobox)comboBoxDriver.SelectedItem).Id
};
// Вызываем метод добавления новой аренды в базу данных
bd.AddRoutes(newRental);
// Обновляем dataGridView
loadData();
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID редактируемой аренды из выбранной строки dataGridView
int rentalId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
// Создаем объект Routes и заполняем его данными из текстовых полей и комбо-боксов
Routes updatedRental = new Routes
{
id = rentalId,
EndPoint = textBoxEndPoint.Text,
ArrivalTime = DateTime.Parse(textBoxArrivalTime.Text + " 00:00:00"),
DepartureTime = DateTime.Parse(textBoxDepartureTime.Text + " 00:00:00"),
WarehouseId = ((helpCombobox)comboBoxWarehouse.SelectedItem).Id,
DriverId = ((helpCombobox)comboBoxDriver.SelectedItem).Id
};
// Вызываем метод обновления аренды в базе данных
bd.UpdateRoutes(updatedRental);
// Обновляем dataGridView
loadData();
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID удаляемой аренды из выбранной строки dataGridView
int rentalId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
// Вызываем метод удаления аренды из базы данных
bd.DeleteRoutes(rentalId);
// Обновляем dataGridView
loadData();
}
}
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
// Заполняем текстовые поля данными из выбранной строки
textBoxEndPoint.Text = row.Cells["EndPoint"].Value.ToString();
textBoxArrivalTime.Text = row.Cells["ArrivalTime"].Value.ToString().Split(" ")[0];
textBoxDepartureTime.Text = row.Cells["DepartureTime"].Value.ToString().Split(" ")[0];
// Получаем значения для комбо-боксов из выбранной строки
int warehouseId = Convert.ToInt32(row.Cells["WarehouseId"].Value);
string driverId = Convert.ToString(row.Cells["DriverId"].Value);
comboBoxWarehouse.SelectedValue = warehouseId;
comboBoxDriver.SelectedValue = driverId;
}
}
private void FormRental_Load(object sender, EventArgs e)
{
loadData();
}
}
}

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

@ -0,0 +1,179 @@
namespace Forms
{
partial class FormTransport
{
/// <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()
{
buttonDelete = new Button();
buttonUpdate = new Button();
buttonCreate = new Button();
textBoxNumber = new TextBox();
label3 = new Label();
label2 = new Label();
label1 = new Label();
dataGridView = new DataGridView();
textBoxType = new TextBox();
textBoxPayload = new TextBox();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// buttonDelete
//
buttonDelete.Location = new Point(786, 243);
buttonDelete.Margin = new Padding(3, 4, 3, 4);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(86, 31);
buttonDelete.TabIndex = 28;
buttonDelete.Text = "delete";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += buttonDelete_Click;
//
// buttonUpdate
//
buttonUpdate.Location = new Point(786, 205);
buttonUpdate.Margin = new Padding(3, 4, 3, 4);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(86, 31);
buttonUpdate.TabIndex = 27;
buttonUpdate.Text = "update";
buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += buttonUpdate_Click;
//
// buttonCreate
//
buttonCreate.Location = new Point(786, 166);
buttonCreate.Margin = new Padding(3, 4, 3, 4);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(86, 31);
buttonCreate.TabIndex = 26;
buttonCreate.Text = "create";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// textBoxNumber
//
textBoxNumber.Location = new Point(786, 92);
textBoxNumber.Margin = new Padding(3, 4, 3, 4);
textBoxNumber.Name = "textBoxNumber";
textBoxNumber.Size = new Size(114, 27);
textBoxNumber.TabIndex = 23;
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(662, 96);
label3.Name = "label3";
label3.Size = new Size(63, 20);
label3.TabIndex = 18;
label3.Text = "Number";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(662, 57);
label2.Name = "label2";
label2.Size = new Size(122, 20);
label2.TabIndex = 17;
label2.Text = "Payload_capacity";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(662, 19);
label1.Name = "label1";
label1.Size = new Size(40, 20);
label1.TabIndex = 16;
label1.Text = "Type";
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(15, 19);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(628, 568);
dataGridView.TabIndex = 15;
dataGridView.CellClick += dataGridView_CellClick;
//
// textBoxType
//
textBoxType.Location = new Point(786, 19);
textBoxType.Margin = new Padding(3, 4, 3, 4);
textBoxType.Name = "textBoxType";
textBoxType.Size = new Size(114, 27);
textBoxType.TabIndex = 29;
//
// textBoxPayload
//
textBoxPayload.Location = new Point(786, 54);
textBoxPayload.Margin = new Padding(3, 4, 3, 4);
textBoxPayload.Name = "textBoxPayload";
textBoxPayload.Size = new Size(114, 27);
textBoxPayload.TabIndex = 30;
//
// FormTransport
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(914, 600);
Controls.Add(textBoxPayload);
Controls.Add(textBoxType);
Controls.Add(buttonDelete);
Controls.Add(buttonUpdate);
Controls.Add(buttonCreate);
Controls.Add(textBoxNumber);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(dataGridView);
Margin = new Padding(3, 4, 3, 4);
Name = "FormTransport";
Text = "FormTransport";
Load += FormTransport_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonDelete;
private Button buttonUpdate;
private Button buttonCreate;
private TextBox textBoxNumber;
private TextBox textBoxType;
private Label label4;
private Label label3;
private Label label2;
private Label label1;
private DataGridView dataGridView;
private TextBox textBoxPayload;
}
}

View File

@ -0,0 +1,119 @@
using database;
using System.Data;
namespace Forms
{
public partial class FormTransport : Form
{
private Abstractions bd;
public FormTransport(Abstractions _bd)
{
InitializeComponent();
bd = _bd;
}
private void loadData()
{
// Получаем список автомобилей
List<Transport> transports = bd.GetTransports();
// Очищаем dataGridView перед заполнением новыми данными
dataGridView.Rows.Clear();
// Предварительно определяем столбцы, если это не было сделано ранее
if (dataGridView.ColumnCount == 0)
{
dataGridView.Columns.Add("id", "ID");
dataGridView.Columns.Add("Type", "Type");
dataGridView.Columns.Add("PayloadCapacity", "PayloadCapacity");
dataGridView.Columns.Add("Number", "Number");
}
// Заполняем dataGridView данными из списка автомобилей
foreach (Transport Transport in transports)
{
dataGridView.Rows.Add(Transport.id,
Transport.Type, Transport.PayloadCapacity, Transport.Number);
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
// Создаем новый объект Car и заполняем его данными из текстовых полей и комбо-боксов
Transport newTransport = new Transport
{
Type = textBoxType.Text,
PayloadCapacity = decimal.Parse(textBoxPayload.Text),
Number = textBoxNumber.Text,
};
// Вызываем метод добавления нового автомобиля в базу данных
bd.AddTransport(newTransport);
// Обновляем dataGridView
loadData();
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID редактируемого автомобиля из выбранной строки dataGridView
int cargoId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
// Создаем объект Car и заполняем его данными из текстовых полей и комбо-боксов
Transport updatedTransport = new Transport
{
id = cargoId,
Type = textBoxType.Text,
PayloadCapacity = decimal.Parse(textBoxPayload.Text),
Number = textBoxNumber.Text,
};
// Вызываем метод обновления автомобиля в базе данных
bd.UpdateTransport(updatedTransport);
// Обновляем dataGridView
loadData();
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID удаляемого автомобиля из выбранной строки dataGridView
int transportId = (int)dataGridView.Rows[rowIndex].Cells["id"].Value;
// Вызываем метод удаления автомобиля из базы данных
bd.DeleteTransport(transportId);
// Обновляем dataGridView
loadData();
}
}
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
// Заполняем текстовые поля данными из выбранной строки
textBoxType.Text = row.Cells["Type"].Value.ToString();
textBoxPayload.Text = row.Cells["PayloadCapacity"].Value.ToString();
textBoxNumber.Text = row.Cells["Number"].Value.ToString();
}
}
private void FormTransport_Load(object sender, EventArgs e)
{
loadData();
}
}
}

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

@ -0,0 +1,179 @@
namespace Forms
{
partial class FormWarehouse
{
/// <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()
{
buttonDelete = new Button();
buttonUpdate = new Button();
buttonCreate = new Button();
textBoxCapacity = new TextBox();
label3 = new Label();
label2 = new Label();
label1 = new Label();
dataGridView = new DataGridView();
textBoxName = new TextBox();
textBoxAddress = new TextBox();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// buttonDelete
//
buttonDelete.Location = new Point(786, 243);
buttonDelete.Margin = new Padding(3, 4, 3, 4);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(86, 31);
buttonDelete.TabIndex = 28;
buttonDelete.Text = "delete";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += buttonDelete_Click;
//
// buttonUpdate
//
buttonUpdate.Location = new Point(786, 205);
buttonUpdate.Margin = new Padding(3, 4, 3, 4);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(86, 31);
buttonUpdate.TabIndex = 27;
buttonUpdate.Text = "update";
buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += buttonUpdate_Click;
//
// buttonCreate
//
buttonCreate.Location = new Point(786, 166);
buttonCreate.Margin = new Padding(3, 4, 3, 4);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(86, 31);
buttonCreate.TabIndex = 26;
buttonCreate.Text = "create";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// textBoxCapacity
//
textBoxCapacity.Location = new Point(786, 92);
textBoxCapacity.Margin = new Padding(3, 4, 3, 4);
textBoxCapacity.Name = "textBoxCapacity";
textBoxCapacity.Size = new Size(114, 27);
textBoxCapacity.TabIndex = 23;
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(662, 96);
label3.Name = "label3";
label3.Size = new Size(66, 20);
label3.TabIndex = 18;
label3.Text = "Capacity";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(662, 57);
label2.Name = "label2";
label2.Size = new Size(62, 20);
label2.TabIndex = 17;
label2.Text = "Address";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(662, 19);
label1.Name = "label1";
label1.Size = new Size(49, 20);
label1.TabIndex = 16;
label1.Text = "Name";
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(15, 19);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(628, 568);
dataGridView.TabIndex = 15;
dataGridView.CellClick += dataGridView_CellClick;
//
// textBoxName
//
textBoxName.Location = new Point(786, 19);
textBoxName.Margin = new Padding(3, 4, 3, 4);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(114, 27);
textBoxName.TabIndex = 29;
//
// textBoxAddress
//
textBoxAddress.Location = new Point(786, 54);
textBoxAddress.Margin = new Padding(3, 4, 3, 4);
textBoxAddress.Name = "textBoxAddress";
textBoxAddress.Size = new Size(114, 27);
textBoxAddress.TabIndex = 30;
//
// FormWarehouse
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(914, 600);
Controls.Add(textBoxAddress);
Controls.Add(textBoxName);
Controls.Add(buttonDelete);
Controls.Add(buttonUpdate);
Controls.Add(buttonCreate);
Controls.Add(textBoxCapacity);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(dataGridView);
Margin = new Padding(3, 4, 3, 4);
Name = "FormWarehouse";
Text = "FormTransport";
Load += FormTransport_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonDelete;
private Button buttonUpdate;
private Button buttonCreate;
private TextBox textBoxCapacity;
private TextBox textBoxName;
private Label label4;
private Label label3;
private Label label2;
private Label label1;
private DataGridView dataGridView;
private TextBox textBoxAddress;
}
}

View File

@ -0,0 +1,119 @@
using database;
using System.Data;
namespace Forms
{
public partial class FormWarehouse : Form
{
private Abstractions bd;
public FormWarehouse(Abstractions _bd)
{
InitializeComponent();
bd = _bd;
}
private void loadData()
{
// Получаем список автомобилей
List<Warehouse> Warehouses = bd.GetWarehouses();
// Очищаем dataGridView перед заполнением новыми данными
dataGridView.Rows.Clear();
// Предварительно определяем столбцы, если это не было сделано ранее
if (dataGridView.ColumnCount == 0)
{
dataGridView.Columns.Add("id", "ID");
dataGridView.Columns.Add("Name", "Name");
dataGridView.Columns.Add("Address", "Address");
dataGridView.Columns.Add("Capacity", "Capacity");
}
// Заполняем dataGridView данными из списка автомобилей
foreach (Warehouse warehouse in Warehouses)
{
dataGridView.Rows.Add(warehouse.id,
warehouse.Name, warehouse.Address, warehouse.Capacity);
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
// Создаем новый объект Car и заполняем его данными из текстовых полей и комбо-боксов
Warehouse newWarehouse = new Warehouse
{
Name = textBoxName.Text,
Address = textBoxCapacity.Text,
Capacity = decimal.Parse(textBoxAddress.Text),
};
// Вызываем метод добавления нового автомобиля в базу данных
bd.AddWarehouse(newWarehouse);
// Обновляем dataGridView
loadData();
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID редактируемого автомобиля из выбранной строки dataGridView
int warehouseId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
// Создаем объект Car и заполняем его данными из текстовых полей и комбо-боксов
Warehouse updatedWarehouse = new Warehouse
{
id = warehouseId,
Name = textBoxName.Text,
Address = textBoxCapacity.Text,
Capacity = decimal.Parse(textBoxAddress.Text),
};
// Вызываем метод обновления автомобиля в базе данных
bd.UpdateWarehouse(updatedWarehouse);
// Обновляем dataGridView
loadData();
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count > 0)
{
// Получаем индекс выбранной строки
int rowIndex = dataGridView.CurrentCell.RowIndex;
// Получаем ID удаляемого автомобиля из выбранной строки dataGridView
int warehouseId = (int)dataGridView.Rows[rowIndex].Cells["id"].Value;
// Вызываем метод удаления автомобиля из базы данных
bd.DeleteWarehouse(warehouseId);
// Обновляем dataGridView
loadData();
}
}
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
// Заполняем текстовые поля данными из выбранной строки
textBoxName.Text = row.Cells["Name"].Value.ToString();
textBoxAddress.Text = row.Cells["Address"].Value.ToString();
textBoxCapacity.Text = row.Cells["Capacity"].Value.ToString();
}
}
private void FormTransport_Load(object sender, EventArgs e)
{
loadData();
}
}
}

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

@ -0,0 +1,40 @@
using database;
using Microsoft.Extensions.DependencyInjection;
namespace Forms
{
internal static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddTransient<Abstractions, Implementation>();
services.AddTransient<FormMain>();
services.AddTransient<FormCargo>();
services.AddTransient<FormTransport>();
services.AddTransient<FormWarehouse>();
services.AddTransient<FormDriver>();
services.AddTransient<FormRoutes>();
services.AddTransient<FormOrders>();
services.AddTransient<FormCargoTransport>();
services.AddTransient<FormCargoOrders>();
}
}
}

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\database\database.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,66 @@
using Npgsql;
namespace database
{
public abstract class Abstractions
{
// CDUD операции для каждой сущности
// Cargo
public abstract void AddCargo(Cargo cargo);
public abstract List<Cargo> GetCargos();
public abstract Cargo GetCargoById(int id);
public abstract void UpdateCargo(Cargo cargo);
public abstract void DeleteCargo(int id);
//Transport
public abstract void AddTransport(Transport transport);
public abstract List<Transport> GetTransports();
public abstract Transport GetTransportById(int id);
public abstract void UpdateTransport(Transport transport);
public abstract void DeleteTransport(int id);
//Warehouse
public abstract void AddWarehouse(Warehouse warehouse);
public abstract List<Warehouse> GetWarehouses();
public abstract Warehouse GetWarehouseById(int id);
public abstract void UpdateWarehouse(Warehouse warehouse);
public abstract void DeleteWarehouse(int id);
//Driver
public abstract void AddDriver(Driver driver);
public abstract List<Driver> GetDrivers();
public abstract Driver GetDriverById(int id);
public abstract void UpdateDriver(Driver driver);
public abstract void DeleteDriver(int id);
// Routes
public abstract void AddRoutes(Routes routes);
public abstract Routes GetRoutesById(int id);
public abstract List<Routes> GetRoutes();
public abstract void UpdateRoutes(Routes routes);
public abstract void DeleteRoutes(int id);
// Orders
public abstract void AddOrders(Orders orders);
public abstract Orders GetOrdersById(int id);
public abstract List<Orders> GetOrders();
public abstract void UpdateOrders(Orders orders);
public abstract void DeleteOrders(int id);
// CargoTransport
public abstract void AddCargoTransports(CargoTransport cargoTransport);
public abstract CargoTransport GetCargoTransportsById(int id);
public abstract List<CargoTransport> GetCargoTransports();
public abstract void UpdateCargoTransports(CargoTransport cargoTransport);
public abstract void DeleteCargoTransports(int id);
//CargoOrder
public abstract void AddCargoOrder(CargoOrder cargoOrder);
public abstract List<CargoOrder> GetCargoOrders();
public abstract CargoOrder GetCargoOrderById(int id);
public abstract void UpdateCargoOrder(CargoOrder cargoOrder);
public abstract void DeleteCargoOrder(int id);
}
}

View File

@ -0,0 +1,603 @@
using Npgsql;
namespace database
{
public class Implementation : Abstractions
{
private NpgsqlConnection GetConnection()
{
return new NpgsqlConnection("Host=localhost;Username=postgres;Password=5558;Database=transports;");
}
// CDUD операции для каждой сущности
// Cargo
public override void AddCargo(Cargo cargo)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("INSERT INTO Cargo (name, description, weight, type) VALUES (@Name, @Description, @Weight, @Type)", conn);
cmd.Parameters.AddWithValue("@Name", cargo.Name);
cmd.Parameters.AddWithValue("@Description", cargo.Description);
cmd.Parameters.AddWithValue("@Weight", cargo.Weight);
cmd.Parameters.AddWithValue("@Type", cargo.Type);
cmd.ExecuteNonQuery();
}
public override List<Cargo> GetCargos()
{
var cars = new List<Cargo>();
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT * FROM Cargo order by id", conn);
using var reader = cmd.ExecuteReader();
while (reader.Read())
{
cars.Add(new Cargo
{
id = reader.GetInt32(0),
Name = reader.GetString(1),
Description = reader.GetString(2),
Weight = reader.GetDecimal(3),
Type = reader.GetString(4),
});
}
return cars;
}
public override Cargo GetCargoById(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand($"SELECT * FROM cargo WHERE id = {id}", conn);
using var reader = cmd.ExecuteReader();
if (reader.Read())
{
return new Cargo
{
id = reader.GetInt32(0),
Name = reader.GetString(1),
Description = reader.GetString(2),
Weight = reader.GetDecimal(3),
Type = reader.GetString(4),
};
}
return null;
}
public override void UpdateCargo(Cargo cargo)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("UPDATE cargo SET name = @Name, description = @Description, weight = @Weight, type = @Type WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Name", cargo.Name);
cmd.Parameters.AddWithValue("@Description", cargo.Description);
cmd.Parameters.AddWithValue("@Weight", cargo.Weight);
cmd.Parameters.AddWithValue("@Type", cargo.Type);
cmd.Parameters.AddWithValue("@Id", cargo.id);
cmd.ExecuteNonQuery();
}
public override void DeleteCargo(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand($"DELETE FROM cargo WHERE id = {id}", conn);
cmd.ExecuteNonQuery();
}
// Transport
public override void AddTransport(Transport transport)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("INSERT INTO Transport (Type, Payload_capacity, Number) VALUES (@Type, @PayloadCapacity, @Number)", conn);
cmd.Parameters.AddWithValue("@Type", transport.Type);
cmd.Parameters.AddWithValue("@PayloadCapacity", transport.PayloadCapacity);
cmd.Parameters.AddWithValue("@Number", transport.Number);
cmd.ExecuteNonQuery();
}
public override List<Transport> GetTransports()
{
var cars = new List<Transport>();
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT * FROM Transport order by id", conn);
using var reader = cmd.ExecuteReader();
while (reader.Read())
{
cars.Add(new Transport
{
id = reader.GetInt32(0),
Type = reader.GetString(1),
PayloadCapacity = reader.GetDecimal(2),
Number = reader.GetString(3),
});
}
return cars;
}
public override Transport GetTransportById(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand($"SELECT * FROM transport WHERE id = {id}", conn);
using var reader = cmd.ExecuteReader();
if (reader.Read())
{
return new Transport
{
id = reader.GetInt32(0),
Type = reader.GetString(1),
PayloadCapacity = reader.GetDecimal(2),
Number = reader.GetString(3)
};
}
return null;
}
public override void UpdateTransport(Transport transport)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("UPDATE transport SET Type = @Type, Payload_capacity = @PayloadCapacity, Number = @Number WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Type", transport.Type);
cmd.Parameters.AddWithValue("@PayloadCapacity", transport.PayloadCapacity);
cmd.Parameters.AddWithValue("@Number", transport.Number);
cmd.Parameters.AddWithValue("@Id", transport.id);
cmd.ExecuteNonQuery();
}
public override void DeleteTransport(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand($"DELETE FROM transport WHERE id = {id}", conn);
cmd.ExecuteNonQuery();
}
//Warehouse
public override void AddWarehouse(Warehouse warehouse)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("INSERT INTO Warehouse (Name, Address, Capacity) VALUES (@Name, @Address, @Capacity)", conn);
cmd.Parameters.AddWithValue("@Name", warehouse.Name);
cmd.Parameters.AddWithValue("@Address", warehouse.Address);
cmd.Parameters.AddWithValue("@Capacity", warehouse.Capacity);
cmd.ExecuteNonQuery();
}
public override List<Warehouse> GetWarehouses()
{
var warehouses = new List<Warehouse>();
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT * FROM Warehouse ORDER BY id", conn);
using var reader = cmd.ExecuteReader();
while (reader.Read())
{
warehouses.Add(new Warehouse
{
id = reader.GetInt32(0),
Name = reader.GetString(1),
Address = reader.GetString(2),
Capacity = reader.GetDecimal(3)
});
}
return warehouses;
}
public override Warehouse GetWarehouseById(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand($"SELECT * FROM Warehouse WHERE id = {id}", conn);
using var reader = cmd.ExecuteReader();
if (reader.Read())
{
return new Warehouse
{
id = reader.GetInt32(0),
Name = reader.GetString(1),
Address = reader.GetString(2),
Capacity = reader.GetDecimal(3)
};
}
return null;
}
public override void UpdateWarehouse(Warehouse warehouse)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("UPDATE Warehouse SET Name = @Name, Address = @Address, Capacity = @Capacity WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Name", warehouse.Name);
cmd.Parameters.AddWithValue("@Address", warehouse.Address);
cmd.Parameters.AddWithValue("@Capacity", warehouse.Capacity);
cmd.Parameters.AddWithValue("@Id", warehouse.id);
cmd.ExecuteNonQuery();
}
public override void DeleteWarehouse(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand($"DELETE FROM Warehouse WHERE id = {id}", conn);
cmd.ExecuteNonQuery();
}
// Driver
public override void AddDriver(Driver driver)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("INSERT INTO Driver (Name, Surname, Category) VALUES (@Name, @Surname, @Category)", conn);
cmd.Parameters.AddWithValue("@Name", driver.Name);
cmd.Parameters.AddWithValue("@Surname", driver.Surname);
cmd.Parameters.AddWithValue("@Category", driver.Category);
cmd.ExecuteNonQuery();
}
public override List<Driver> GetDrivers()
{
var drivers = new List<Driver>();
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT * FROM Driver ORDER BY id", conn);
using var reader = cmd.ExecuteReader();
while (reader.Read())
{
drivers.Add(new Driver
{
id = reader.GetInt32(0),
Name = reader.GetString(1),
Surname = reader.GetString(2),
Category = reader.GetInt32(3)
});
}
return drivers;
}
public override Driver GetDriverById(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand($"SELECT * FROM Driver WHERE id = {id}", conn);
using var reader = cmd.ExecuteReader();
if (reader.Read())
{
return new Driver
{
id = reader.GetInt32(0),
Name = reader.GetString(1),
Surname = reader.GetString(2),
Category = reader.GetInt32(3)
};
}
return null;
}
public override void UpdateDriver(Driver driver)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("UPDATE Driver SET Name = @Name, Surname = @Surname, Category = @Category WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Name", driver.Name);
cmd.Parameters.AddWithValue("@Surname", driver.Surname);
cmd.Parameters.AddWithValue("@Category", driver.Category);
cmd.Parameters.AddWithValue("@Id", driver.id);
cmd.ExecuteNonQuery();
}
public override void DeleteDriver(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand($"DELETE FROM Driver WHERE id = {id}", conn);
cmd.ExecuteNonQuery();
}
// Routes
public override void AddRoutes(Routes routes)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("INSERT INTO Routes (End_Point, Arrival_Time, Departure_Time, Warehouse_id, Driver_id) VALUES (@EndPoint, @ArrivalTime, @DepartureTime, @WarehouseId, @DriverId)", conn);
cmd.Parameters.AddWithValue("@EndPoint", routes.EndPoint);
cmd.Parameters.AddWithValue("@ArrivalTime", routes.ArrivalTime);
cmd.Parameters.AddWithValue("@DepartureTime", routes.DepartureTime);
cmd.Parameters.AddWithValue("@WarehouseId", routes.WarehouseId);
cmd.Parameters.AddWithValue("@DriverId", routes.DriverId);
cmd.ExecuteNonQuery();
}
public override List<Routes> GetRoutes()
{
var routesList = new List<Routes>();
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT * FROM Routes ORDER BY id", conn);
using var reader = cmd.ExecuteReader();
while (reader.Read())
{
routesList.Add(new Routes
{
id = reader.GetInt32(0),
EndPoint = reader.GetString(1),
ArrivalTime = reader.GetDateTime(2),
DepartureTime = reader.GetDateTime(3),
WarehouseId = reader.GetInt32(4),
DriverId = reader.GetInt32(5)
});
}
return routesList;
}
public override Routes GetRoutesById(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT * FROM Routes WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Id", id);
using var reader = cmd.ExecuteReader();
if (reader.Read())
{
return new Routes
{
id = reader.GetInt32(0),
EndPoint = reader.GetString(1),
ArrivalTime = reader.GetDateTime(2),
DepartureTime = reader.GetDateTime(3),
WarehouseId = reader.GetInt32(4),
DriverId = reader.GetInt32(5)
};
}
return null;
}
public override void UpdateRoutes(Routes routes)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("UPDATE Routes SET End_Point = @EndPoint, Arrival_Time = @ArrivalTime, Departure_Time = @DepartureTime, Warehouse_id = @WarehouseId, Driver_id = @DriverId WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Id", routes.id);
cmd.Parameters.AddWithValue("@EndPoint", routes.EndPoint);
cmd.Parameters.AddWithValue("@ArrivalTime", routes.ArrivalTime);
cmd.Parameters.AddWithValue("@DepartureTime", routes.DepartureTime);
cmd.Parameters.AddWithValue("@WarehouseId", routes.WarehouseId);
cmd.Parameters.AddWithValue("@DriverId", routes.DriverId);
cmd.ExecuteNonQuery();
}
public override void DeleteRoutes(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("DELETE FROM Routes WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Id", id);
cmd.ExecuteNonQuery();
}
// Orders
public override void AddOrders(Orders orders)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("INSERT INTO Orders (Status, Order_Date, Routes_id) VALUES (@Status, @OrderDate, @RoutesId)", conn);
cmd.Parameters.AddWithValue("@Status", orders.Status);
cmd.Parameters.AddWithValue("@OrderDate", orders.OrderDate);
cmd.Parameters.AddWithValue("@RoutesId", orders.RoutesId);
cmd.ExecuteNonQuery();
}
public override List<Orders> GetOrders()
{
var ordersList = new List<Orders>();
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT * FROM Orders ORDER BY id", conn);
using var reader = cmd.ExecuteReader();
while (reader.Read())
{
ordersList.Add(new Orders
{
id = reader.GetInt32(0),
Status = reader.GetString(1),
OrderDate = reader.GetDateTime(2),
RoutesId = reader.GetInt32(3),
});
}
return ordersList;
}
public override Orders GetOrdersById(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT * FROM Orders WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Id", id);
using var reader = cmd.ExecuteReader();
if (reader.Read())
{
return new Orders
{
id = reader.GetInt32(0),
Status = reader.GetString(1),
OrderDate = reader.GetDateTime(2),
RoutesId = reader.GetInt32(3)
};
}
return null;
}
public override void UpdateOrders(Orders orders)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("UPDATE Orders SET Status = @Status, Order_Date = @OrderDate, Routes_id = @RoutesId WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Id", orders.id);
cmd.Parameters.AddWithValue("@Status", orders.Status);
cmd.Parameters.AddWithValue("@OrderDate", orders.OrderDate);
cmd.Parameters.AddWithValue("@RoutesId", orders.RoutesId);
cmd.ExecuteNonQuery();
}
public override void DeleteOrders(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("DELETE FROM Orders WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Id", id);
cmd.ExecuteNonQuery();
}
//CargoTransport
public override void AddCargoTransports(CargoTransport cargoTransport)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("INSERT INTO Cargo_Transport (Cargo_id, Transport_id) VALUES (@CargoId, @TransportId)", conn);
cmd.Parameters.AddWithValue("@CargoId", cargoTransport.CargoId);
cmd.Parameters.AddWithValue("@TransportId", cargoTransport.TransportId);
cmd.ExecuteNonQuery();
}
public override List<CargoTransport> GetCargoTransports()
{
var cargoTransportList = new List<CargoTransport>();
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT * FROM Cargo_Transport ORDER BY id", conn);
using var reader = cmd.ExecuteReader();
while (reader.Read())
{
cargoTransportList.Add(new CargoTransport
{
id = reader.GetInt32(0),
CargoId = reader.GetInt32(1),
TransportId = reader.GetInt32(2)
});
}
return cargoTransportList;
}
public override CargoTransport GetCargoTransportsById(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT * FROM Cargo_Transport WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Id", id);
using var reader = cmd.ExecuteReader();
if (reader.Read())
{
return new CargoTransport
{
id = reader.GetInt32(0),
CargoId = reader.GetInt32(1),
TransportId = reader.GetInt32(2)
};
}
return null;
}
public override void UpdateCargoTransports(CargoTransport cargoTransport)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("UPDATE Cargo_Transport SET Cargo_id = @CargoId, Transport_id = @TransportId WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Id", cargoTransport.id);
cmd.Parameters.AddWithValue("@CargoId", cargoTransport.CargoId);
cmd.Parameters.AddWithValue("@TransportId", cargoTransport.TransportId);
cmd.ExecuteNonQuery();
}
public override void DeleteCargoTransports(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("DELETE FROM Cargo_Transport WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Id", id);
cmd.ExecuteNonQuery();
}
//CargoOrder
public override void AddCargoOrder(CargoOrder cargoOrder)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("INSERT INTO Cargo_Order (Cargo_id, Order_id, Count) VALUES (@CargoId, @OrderId, @Count)", conn);
cmd.Parameters.AddWithValue("@CargoId", cargoOrder.CargoId);
cmd.Parameters.AddWithValue("@OrderId", cargoOrder.OrderId);
cmd.Parameters.AddWithValue("@Count", cargoOrder.Count);
cmd.ExecuteNonQuery();
}
public override List<CargoOrder> GetCargoOrders()
{
var cargoOrderList = new List<CargoOrder>();
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT * FROM Cargo_Order ORDER BY id", conn);
using var reader = cmd.ExecuteReader();
while (reader.Read())
{
cargoOrderList.Add(new CargoOrder
{
id = reader.GetInt32(0),
CargoId = reader.GetInt32(1),
OrderId = reader.GetInt32(2),
Count = reader.GetInt32(3)
});
}
return cargoOrderList;
}
public override CargoOrder GetCargoOrderById(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT * FROM Cargo_Order WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Id", id);
using var reader = cmd.ExecuteReader();
if (reader.Read())
{
return new CargoOrder
{
id = reader.GetInt32(0),
CargoId = reader.GetInt32(1),
OrderId = reader.GetInt32(2),
Count = reader.GetInt32(3)
};
}
return null;
}
public override void UpdateCargoOrder(CargoOrder cargoOrder)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("UPDATE Cargo_Order SET Cargo_id = @CargoId, Order_id = @OrderId, Count = @Count WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Id", cargoOrder.id);
cmd.Parameters.AddWithValue("@CargoId", cargoOrder.CargoId);
cmd.Parameters.AddWithValue("@OrderId", cargoOrder.OrderId);
cmd.Parameters.AddWithValue("@Count", cargoOrder.Count);
cmd.ExecuteNonQuery();
}
public override void DeleteCargoOrder(int id)
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("DELETE FROM Cargo_Order WHERE id = @Id", conn);
cmd.Parameters.AddWithValue("@Id", id);
cmd.ExecuteNonQuery();
}
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Npgsql" Version="8.0.2" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,74 @@
namespace database
{
// Определение моделей данных
public class Cargo
{
public int id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Weight { get; set; }
public string Type { get; set; }
}
public class Transport
{
public int id { get; set; }
public string Type { get; set; }
public decimal PayloadCapacity { get; set; }
public string Number { get; set; }
}
public class Warehouse
{
public int id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public decimal Capacity { get; set; }
}
public class Driver
{
public int id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public int Category { get; set; }
}
public class Routes
{
public int id { get; set; }
public string EndPoint { get; set; }
public DateTime ArrivalTime { get; set; }
public DateTime DepartureTime { get; set; }
public int WarehouseId { get; set; }
public int DriverId { get; set; }
}
public class Orders
{
public int id { get; set; }
public string Status { get; set; }
public DateTime OrderDate { get; set; }
public int RoutesId { get; set; }
}
public class CargoTransport
{
public int id { get; set; }
public int CargoId { get; set; }
public int TransportId { get; set; }
}
public class CargoOrder
{
public int id { get; set; }
public int CargoId { get; set; }
public int OrderId { get; set; }
public int Count { get; set; }
}
public class helpCombobox
{
public string Text { get; set; }
public int Id { get; set; }
}
}