From 5ac916f559cba50cb4f99f6cd6989a1cbe696d3d Mon Sep 17 00:00:00 2001 From: goldfest Date: Sat, 4 May 2024 00:48:13 +0400 Subject: [PATCH] 4 laba --- Transportlog/Transportlog.sln | 31 + .../Transportlog/FormCargo.Designer.cs | 201 ++++++ Transportlog/Transportlog/FormCargo.cs | 123 ++++ Transportlog/Transportlog/FormCargo.resx | 120 ++++ .../Transportlog/FormCargoOrders.Designer.cs | 180 ++++++ Transportlog/Transportlog/FormCargoOrders.cs | 160 +++++ .../Transportlog/FormCargoOrders.resx | 120 ++++ .../FormCargoTransport.Designer.cs | 157 +++++ .../Transportlog/FormCargoTransport.cs | 151 +++++ .../Transportlog/FormCargoTransport.resx | 120 ++++ .../Transportlog/FormDriver.Designer.cs | 179 ++++++ Transportlog/Transportlog/FormDriver.cs | 120 ++++ Transportlog/Transportlog/FormDriver.resx | 120 ++++ .../Transportlog/FormMain.Designer.cs | 176 +++++ Transportlog/Transportlog/FormMain.cs | 101 +++ Transportlog/Transportlog/FormMain.resx | 123 ++++ .../Transportlog/FormOrders.Designer.cs | 181 ++++++ Transportlog/Transportlog/FormOrders.cs | 141 ++++ Transportlog/Transportlog/FormOrders.resx | 120 ++++ .../Transportlog/FormRoutes.Designer.cs | 226 +++++++ Transportlog/Transportlog/FormRoutes.cs | 168 +++++ Transportlog/Transportlog/FormRoutes.resx | 120 ++++ .../Transportlog/FormTransport.Designer.cs | 179 ++++++ Transportlog/Transportlog/FormTransport.cs | 119 ++++ Transportlog/Transportlog/FormTransport.resx | 120 ++++ .../Transportlog/FormWarehouse.Designer.cs | 179 ++++++ Transportlog/Transportlog/FormWarehouse.cs | 119 ++++ Transportlog/Transportlog/FormWarehouse.resx | 120 ++++ Transportlog/Transportlog/Program.cs | 40 ++ Transportlog/Transportlog/Transportlog.csproj | 19 + Transportlog/database/Abstractions.cs | 66 ++ Transportlog/database/Implementation.cs | 603 ++++++++++++++++++ Transportlog/database/database.csproj | 13 + Transportlog/database/models.cs | 74 +++ 34 files changed, 4789 insertions(+) create mode 100644 Transportlog/Transportlog.sln create mode 100644 Transportlog/Transportlog/FormCargo.Designer.cs create mode 100644 Transportlog/Transportlog/FormCargo.cs create mode 100644 Transportlog/Transportlog/FormCargo.resx create mode 100644 Transportlog/Transportlog/FormCargoOrders.Designer.cs create mode 100644 Transportlog/Transportlog/FormCargoOrders.cs create mode 100644 Transportlog/Transportlog/FormCargoOrders.resx create mode 100644 Transportlog/Transportlog/FormCargoTransport.Designer.cs create mode 100644 Transportlog/Transportlog/FormCargoTransport.cs create mode 100644 Transportlog/Transportlog/FormCargoTransport.resx create mode 100644 Transportlog/Transportlog/FormDriver.Designer.cs create mode 100644 Transportlog/Transportlog/FormDriver.cs create mode 100644 Transportlog/Transportlog/FormDriver.resx create mode 100644 Transportlog/Transportlog/FormMain.Designer.cs create mode 100644 Transportlog/Transportlog/FormMain.cs create mode 100644 Transportlog/Transportlog/FormMain.resx create mode 100644 Transportlog/Transportlog/FormOrders.Designer.cs create mode 100644 Transportlog/Transportlog/FormOrders.cs create mode 100644 Transportlog/Transportlog/FormOrders.resx create mode 100644 Transportlog/Transportlog/FormRoutes.Designer.cs create mode 100644 Transportlog/Transportlog/FormRoutes.cs create mode 100644 Transportlog/Transportlog/FormRoutes.resx create mode 100644 Transportlog/Transportlog/FormTransport.Designer.cs create mode 100644 Transportlog/Transportlog/FormTransport.cs create mode 100644 Transportlog/Transportlog/FormTransport.resx create mode 100644 Transportlog/Transportlog/FormWarehouse.Designer.cs create mode 100644 Transportlog/Transportlog/FormWarehouse.cs create mode 100644 Transportlog/Transportlog/FormWarehouse.resx create mode 100644 Transportlog/Transportlog/Program.cs create mode 100644 Transportlog/Transportlog/Transportlog.csproj create mode 100644 Transportlog/database/Abstractions.cs create mode 100644 Transportlog/database/Implementation.cs create mode 100644 Transportlog/database/database.csproj create mode 100644 Transportlog/database/models.cs diff --git a/Transportlog/Transportlog.sln b/Transportlog/Transportlog.sln new file mode 100644 index 0000000..990c330 --- /dev/null +++ b/Transportlog/Transportlog.sln @@ -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 diff --git a/Transportlog/Transportlog/FormCargo.Designer.cs b/Transportlog/Transportlog/FormCargo.Designer.cs new file mode 100644 index 0000000..d6a2d89 --- /dev/null +++ b/Transportlog/Transportlog/FormCargo.Designer.cs @@ -0,0 +1,201 @@ +namespace Forms +{ + partial class FormCargo + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/Transportlog/Transportlog/FormCargo.cs b/Transportlog/Transportlog/FormCargo.cs new file mode 100644 index 0000000..6f16157 --- /dev/null +++ b/Transportlog/Transportlog/FormCargo.cs @@ -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 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(); + } + } +} diff --git a/Transportlog/Transportlog/FormCargo.resx b/Transportlog/Transportlog/FormCargo.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Transportlog/Transportlog/FormCargo.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Transportlog/Transportlog/FormCargoOrders.Designer.cs b/Transportlog/Transportlog/FormCargoOrders.Designer.cs new file mode 100644 index 0000000..0745128 --- /dev/null +++ b/Transportlog/Transportlog/FormCargoOrders.Designer.cs @@ -0,0 +1,180 @@ +namespace Forms +{ + partial class FormCargoOrders + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/Transportlog/Transportlog/FormCargoOrders.cs b/Transportlog/Transportlog/FormCargoOrders.cs new file mode 100644 index 0000000..f46099c --- /dev/null +++ b/Transportlog/Transportlog/FormCargoOrders.cs @@ -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 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(); + } + } +} diff --git a/Transportlog/Transportlog/FormCargoOrders.resx b/Transportlog/Transportlog/FormCargoOrders.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Transportlog/Transportlog/FormCargoOrders.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Transportlog/Transportlog/FormCargoTransport.Designer.cs b/Transportlog/Transportlog/FormCargoTransport.Designer.cs new file mode 100644 index 0000000..b338aa9 --- /dev/null +++ b/Transportlog/Transportlog/FormCargoTransport.Designer.cs @@ -0,0 +1,157 @@ +namespace Forms +{ + partial class FormCargoTransport + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/Transportlog/Transportlog/FormCargoTransport.cs b/Transportlog/Transportlog/FormCargoTransport.cs new file mode 100644 index 0000000..d0d8216 --- /dev/null +++ b/Transportlog/Transportlog/FormCargoTransport.cs @@ -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 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(); + } + } +} diff --git a/Transportlog/Transportlog/FormCargoTransport.resx b/Transportlog/Transportlog/FormCargoTransport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Transportlog/Transportlog/FormCargoTransport.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Transportlog/Transportlog/FormDriver.Designer.cs b/Transportlog/Transportlog/FormDriver.Designer.cs new file mode 100644 index 0000000..6949936 --- /dev/null +++ b/Transportlog/Transportlog/FormDriver.Designer.cs @@ -0,0 +1,179 @@ +namespace Forms +{ + partial class FormDriver + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/Transportlog/Transportlog/FormDriver.cs b/Transportlog/Transportlog/FormDriver.cs new file mode 100644 index 0000000..93f08e6 --- /dev/null +++ b/Transportlog/Transportlog/FormDriver.cs @@ -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 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(); + } + } +} diff --git a/Transportlog/Transportlog/FormDriver.resx b/Transportlog/Transportlog/FormDriver.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Transportlog/Transportlog/FormDriver.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Transportlog/Transportlog/FormMain.Designer.cs b/Transportlog/Transportlog/FormMain.Designer.cs new file mode 100644 index 0000000..e1b50b2 --- /dev/null +++ b/Transportlog/Transportlog/FormMain.Designer.cs @@ -0,0 +1,176 @@ +namespace Forms +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/Transportlog/Transportlog/FormMain.cs b/Transportlog/Transportlog/FormMain.cs new file mode 100644 index 0000000..d51e403 --- /dev/null +++ b/Transportlog/Transportlog/FormMain.cs @@ -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} миллисекунд"; + } + } + } +} diff --git a/Transportlog/Transportlog/FormMain.resx b/Transportlog/Transportlog/FormMain.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/Transportlog/Transportlog/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Transportlog/Transportlog/FormOrders.Designer.cs b/Transportlog/Transportlog/FormOrders.Designer.cs new file mode 100644 index 0000000..9592272 --- /dev/null +++ b/Transportlog/Transportlog/FormOrders.Designer.cs @@ -0,0 +1,181 @@ +namespace Forms +{ + partial class FormOrders + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/Transportlog/Transportlog/FormOrders.cs b/Transportlog/Transportlog/FormOrders.cs new file mode 100644 index 0000000..a8c5749 --- /dev/null +++ b/Transportlog/Transportlog/FormOrders.cs @@ -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 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(); + } + } +} diff --git a/Transportlog/Transportlog/FormOrders.resx b/Transportlog/Transportlog/FormOrders.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Transportlog/Transportlog/FormOrders.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Transportlog/Transportlog/FormRoutes.Designer.cs b/Transportlog/Transportlog/FormRoutes.Designer.cs new file mode 100644 index 0000000..68385c3 --- /dev/null +++ b/Transportlog/Transportlog/FormRoutes.Designer.cs @@ -0,0 +1,226 @@ +namespace Forms +{ + partial class FormRoutes + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/Transportlog/Transportlog/FormRoutes.cs b/Transportlog/Transportlog/FormRoutes.cs new file mode 100644 index 0000000..e9ca829 --- /dev/null +++ b/Transportlog/Transportlog/FormRoutes.cs @@ -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 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(); + } + } +} diff --git a/Transportlog/Transportlog/FormRoutes.resx b/Transportlog/Transportlog/FormRoutes.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Transportlog/Transportlog/FormRoutes.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Transportlog/Transportlog/FormTransport.Designer.cs b/Transportlog/Transportlog/FormTransport.Designer.cs new file mode 100644 index 0000000..9708846 --- /dev/null +++ b/Transportlog/Transportlog/FormTransport.Designer.cs @@ -0,0 +1,179 @@ +namespace Forms +{ + partial class FormTransport + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/Transportlog/Transportlog/FormTransport.cs b/Transportlog/Transportlog/FormTransport.cs new file mode 100644 index 0000000..132fc4f --- /dev/null +++ b/Transportlog/Transportlog/FormTransport.cs @@ -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 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(); + } + } +} diff --git a/Transportlog/Transportlog/FormTransport.resx b/Transportlog/Transportlog/FormTransport.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Transportlog/Transportlog/FormTransport.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Transportlog/Transportlog/FormWarehouse.Designer.cs b/Transportlog/Transportlog/FormWarehouse.Designer.cs new file mode 100644 index 0000000..a12ba4c --- /dev/null +++ b/Transportlog/Transportlog/FormWarehouse.Designer.cs @@ -0,0 +1,179 @@ +namespace Forms +{ + partial class FormWarehouse + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/Transportlog/Transportlog/FormWarehouse.cs b/Transportlog/Transportlog/FormWarehouse.cs new file mode 100644 index 0000000..2f440ad --- /dev/null +++ b/Transportlog/Transportlog/FormWarehouse.cs @@ -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 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(); + } + } +} diff --git a/Transportlog/Transportlog/FormWarehouse.resx b/Transportlog/Transportlog/FormWarehouse.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Transportlog/Transportlog/FormWarehouse.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Transportlog/Transportlog/Program.cs b/Transportlog/Transportlog/Program.cs new file mode 100644 index 0000000..a6c0c64 --- /dev/null +++ b/Transportlog/Transportlog/Program.cs @@ -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; + /// + /// The main entry point for the application. + /// + [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()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + } + } +} \ No newline at end of file diff --git a/Transportlog/Transportlog/Transportlog.csproj b/Transportlog/Transportlog/Transportlog.csproj new file mode 100644 index 0000000..14c9dec --- /dev/null +++ b/Transportlog/Transportlog/Transportlog.csproj @@ -0,0 +1,19 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + \ No newline at end of file diff --git a/Transportlog/database/Abstractions.cs b/Transportlog/database/Abstractions.cs new file mode 100644 index 0000000..7f9bf12 --- /dev/null +++ b/Transportlog/database/Abstractions.cs @@ -0,0 +1,66 @@ +using Npgsql; + +namespace database +{ + public abstract class Abstractions + { + + // CDUD операции для каждой сущности + + // Cargo + public abstract void AddCargo(Cargo cargo); + public abstract List 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 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 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 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 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 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 GetCargoTransports(); + public abstract void UpdateCargoTransports(CargoTransport cargoTransport); + public abstract void DeleteCargoTransports(int id); + + //CargoOrder + public abstract void AddCargoOrder(CargoOrder cargoOrder); + public abstract List GetCargoOrders(); + public abstract CargoOrder GetCargoOrderById(int id); + public abstract void UpdateCargoOrder(CargoOrder cargoOrder); + public abstract void DeleteCargoOrder(int id); + } +} diff --git a/Transportlog/database/Implementation.cs b/Transportlog/database/Implementation.cs new file mode 100644 index 0000000..d0d87ce --- /dev/null +++ b/Transportlog/database/Implementation.cs @@ -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 GetCargos() + { + var cars = new List(); + 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 GetTransports() + { + var cars = new List(); + 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 GetWarehouses() + { + var warehouses = new List(); + 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 GetDrivers() + { + var drivers = new List(); + 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 GetRoutes() + { + var routesList = new List(); + 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 GetOrders() + { + var ordersList = new List(); + 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 GetCargoTransports() + { + var cargoTransportList = new List(); + 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 GetCargoOrders() + { + var cargoOrderList = new List(); + 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(); + } + + + } +} diff --git a/Transportlog/database/database.csproj b/Transportlog/database/database.csproj new file mode 100644 index 0000000..23b43f6 --- /dev/null +++ b/Transportlog/database/database.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Transportlog/database/models.cs b/Transportlog/database/models.cs new file mode 100644 index 0000000..14d0b35 --- /dev/null +++ b/Transportlog/database/models.cs @@ -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; } + } +}