From 19bfe37214276aff2f53eca911811f13c3c6f5a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Sat, 6 May 2023 01:31:48 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BE=D0=B1=D1=8B=D1=87=D0=BD=D1=8B=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=B5=D0=B9=D1=81=D1=82=D0=B2=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Subd/BusinessLogic/BusinessLogic.csproj | 2 +- Subd/BusinessLogic/BusinessLogic/CarBL.cs | 6 +- Subd/BusinessLogic/BusinessLogic/CompanyBL.cs | 8 +- Subd/BusinessLogic/BusinessLogic/HumanBL.cs | 6 +- Subd/BusinessLogic/BusinessLogic/PlaceBL.cs | 1 - Subd/BusinessLogic/BusinessLogic/RouteBL.cs | 15 +-- Subd/BusinessLogic/BusinessLogic/VoyageBL.cs | 17 +-- Subd/Contracts/BindingModels/CarBM.cs | 3 +- Subd/Contracts/BindingModels/CompanyBM.cs | 2 +- Subd/Contracts/BindingModels/HumanBM.cs | 2 +- Subd/Contracts/BindingModels/PlaceBM.cs | 2 +- Subd/Contracts/BindingModels/RouteBM.cs | 10 +- Subd/Contracts/BindingModels/StatusBM.cs | 2 +- Subd/Contracts/SearchModel/RouteSM.cs | 1 + Subd/Contracts/ViewModels/CarVM.cs | 1 + Subd/Forms/FormCar.Designer.cs | 11 ++ Subd/Forms/FormCar.cs | 1 + Subd/Forms/FormCars.cs | 4 +- Subd/Forms/FormCompanies.cs | 4 +- Subd/Forms/FormHuman.Designer.cs | 11 ++ Subd/Forms/FormHuman.cs | 2 +- Subd/Forms/FormHumans.cs | 4 +- Subd/Forms/FormMain.Designer.cs | 26 ++-- Subd/Forms/FormMain.cs | 11 ++ Subd/Forms/FormPlaces.cs | 4 +- Subd/Forms/FormRoute.cs | 2 + Subd/Forms/FormRoutes.cs | 4 +- Subd/Forms/FormStatuses.cs | 3 +- Subd/Forms/FormVoyage.cs | 23 ++-- Subd/Forms/Forms.csproj | 2 +- Subd/Forms/Program.cs | 2 +- Subd/GoingToMongo/GoingToMongo.csproj | 14 ++ Subd/GoingToMongo/Program.cs | 15 +++ Subd/MongoDB/CarStorage.cs | 122 ++++++++++++++++++ Subd/MongoDB/CompanyStorage.cs | 107 +++++++++++++++ Subd/MongoDB/HumanStorage.cs | 113 ++++++++++++++++ Subd/MongoDB/MongoDB.csproj | 18 +++ Subd/MongoDB/MongoDateBase.cs | 24 ++++ Subd/MongoDB/PlaceStorage.cs | 107 +++++++++++++++ Subd/MongoDB/RouteStorage.cs | 104 +++++++++++++++ Subd/MongoDB/StatusStorage.cs | 88 +++++++++++++ Subd/MongoDB/VoyageStorage.cs | 77 +++++++++++ Subd/Subd.sln | 22 +++- 43 files changed, 910 insertions(+), 93 deletions(-) create mode 100644 Subd/GoingToMongo/GoingToMongo.csproj create mode 100644 Subd/GoingToMongo/Program.cs create mode 100644 Subd/MongoDB/CarStorage.cs create mode 100644 Subd/MongoDB/CompanyStorage.cs create mode 100644 Subd/MongoDB/HumanStorage.cs create mode 100644 Subd/MongoDB/MongoDB.csproj create mode 100644 Subd/MongoDB/MongoDateBase.cs create mode 100644 Subd/MongoDB/PlaceStorage.cs create mode 100644 Subd/MongoDB/RouteStorage.cs create mode 100644 Subd/MongoDB/StatusStorage.cs create mode 100644 Subd/MongoDB/VoyageStorage.cs diff --git a/Subd/BusinessLogic/BusinessLogic.csproj b/Subd/BusinessLogic/BusinessLogic.csproj index d446313..806de21 100644 --- a/Subd/BusinessLogic/BusinessLogic.csproj +++ b/Subd/BusinessLogic/BusinessLogic.csproj @@ -8,7 +8,7 @@ - + diff --git a/Subd/BusinessLogic/BusinessLogic/CarBL.cs b/Subd/BusinessLogic/BusinessLogic/CarBL.cs index 6f68a6f..6328124 100644 --- a/Subd/BusinessLogic/BusinessLogic/CarBL.cs +++ b/Subd/BusinessLogic/BusinessLogic/CarBL.cs @@ -100,11 +100,7 @@ namespace BusinessBL.BusinessBL { throw new ArgumentNullException("Грузоподъемность должна быть больше 0", nameof(model.Tonnage)); } - if (model.StatusId <= 0) - { - throw new ArgumentNullException("Стутус должн быть ", nameof(model.StatusId)); - } - + } } } diff --git a/Subd/BusinessLogic/BusinessLogic/CompanyBL.cs b/Subd/BusinessLogic/BusinessLogic/CompanyBL.cs index 9765ef7..a81fcee 100644 --- a/Subd/BusinessLogic/BusinessLogic/CompanyBL.cs +++ b/Subd/BusinessLogic/BusinessLogic/CompanyBL.cs @@ -96,10 +96,10 @@ namespace BusinessLogic.BusinessLogic throw new ArgumentNullException("Нет названия ", nameof(model.Title)); } - if (model.StatusId <= 0) - { - throw new ArgumentNullException("Стутус должн быть ", nameof(model.StatusId)); - } + //if (model.StatusId <= 0) + //{ + // throw new ArgumentNullException("Стутус должн быть ", nameof(model.StatusId)); + // } _logger.LogInformation("Car. CarName:{CarName}.Cost:{ Cost}. Id: { Id}", model.Title); var element = _companyStorage.GetElement(new CompanySM { diff --git a/Subd/BusinessLogic/BusinessLogic/HumanBL.cs b/Subd/BusinessLogic/BusinessLogic/HumanBL.cs index 9a382de..6ef2ddd 100644 --- a/Subd/BusinessLogic/BusinessLogic/HumanBL.cs +++ b/Subd/BusinessLogic/BusinessLogic/HumanBL.cs @@ -4,7 +4,6 @@ using Contracts.BusinessLogic; using Contracts.SearchModel; using Contracts.Storage; using Contracts.ViewModels; -using DataBase.Implements; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -101,10 +100,7 @@ namespace BusinessLogic.BusinessLogic { throw new ArgumentNullException("Нет номера телефона", nameof(model.Phone)); } - if (model.StatusId <= 0) - { - throw new ArgumentNullException("Стутус должн быть ", nameof(model.StatusId)); - } + _logger.LogInformation("Car. CarName:{CarName}.Cost:{ Cost}. Id: { Id}", model.Name); var element = _humanStorage.GetElement(new HumanSM { diff --git a/Subd/BusinessLogic/BusinessLogic/PlaceBL.cs b/Subd/BusinessLogic/BusinessLogic/PlaceBL.cs index 60de938..95446ed 100644 --- a/Subd/BusinessLogic/BusinessLogic/PlaceBL.cs +++ b/Subd/BusinessLogic/BusinessLogic/PlaceBL.cs @@ -3,7 +3,6 @@ using Contracts.BusinessLogic; using Contracts.SearchModel; using Contracts.Storage; using Contracts.ViewModels; -using DataBase.Implements; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; diff --git a/Subd/BusinessLogic/BusinessLogic/RouteBL.cs b/Subd/BusinessLogic/BusinessLogic/RouteBL.cs index 3ad50d0..226e38f 100644 --- a/Subd/BusinessLogic/BusinessLogic/RouteBL.cs +++ b/Subd/BusinessLogic/BusinessLogic/RouteBL.cs @@ -4,7 +4,6 @@ using Contracts.BusinessLogic; using Contracts.SearchModel; using Contracts.Storage; using Contracts.ViewModels; -using DataBase.Implements; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -97,20 +96,12 @@ namespace BusinessLogic.BusinessLogic { throw new ArgumentNullException("Нет длины маршрута", nameof(model.Length)); } - if (model.PlaceStart <= 0) - { - throw new ArgumentNullException("нет т-ки отправления", nameof(model.PlaceStart)); - } - if (model.PlaceStart <= 0) - { - throw new ArgumentNullException("нет т-ки назначения", nameof(model.PlaceEnd)); - } + var element = _routeStorage.GetElement(new RouteSM { - Id = model.Id, - Start = model.PlaceStart, - End = model.PlaceEnd + Title = model.Title, + }); if (element != null && element.Id != model.Id) { diff --git a/Subd/BusinessLogic/BusinessLogic/VoyageBL.cs b/Subd/BusinessLogic/BusinessLogic/VoyageBL.cs index d046300..3b6b2bc 100644 --- a/Subd/BusinessLogic/BusinessLogic/VoyageBL.cs +++ b/Subd/BusinessLogic/BusinessLogic/VoyageBL.cs @@ -86,22 +86,7 @@ namespace BusinessLogic.BusinessLogic { return; } - if (model.CarId <= 0) - { - throw new ArgumentNullException("Нет машины", nameof(model.CarId)); - } - if (model.CompanyId <= 0) - { - throw new ArgumentNullException("нет заказчкика", nameof(model.CompanyId)); - } - if (model.HumanId <= 0) - { - throw new ArgumentNullException("нет водилы", nameof(model.HumanId)); - } - if (model.HumanId <= 0) - { - throw new ArgumentNullException("нет водилы", nameof(model.HumanId)); - } + if (!model.DateEnd.HasValue) { throw new ArgumentNullException("нет дедлайна", nameof(model.HumanId)); diff --git a/Subd/Contracts/BindingModels/CarBM.cs b/Subd/Contracts/BindingModels/CarBM.cs index 63dfe1d..7bb76b1 100644 --- a/Subd/Contracts/BindingModels/CarBM.cs +++ b/Subd/Contracts/BindingModels/CarBM.cs @@ -10,7 +10,8 @@ namespace Contracts.BindingModels public class CarBM : ICar { public string Model { get; set; } = string.Empty; - + public string oldModel { get; set; } = string.Empty ; + public string number { get; set; } = string.Empty; public int Tonnage { get; set; } public int? StatusId { get; set; } diff --git a/Subd/Contracts/BindingModels/CompanyBM.cs b/Subd/Contracts/BindingModels/CompanyBM.cs index 1f05048..74c57e9 100644 --- a/Subd/Contracts/BindingModels/CompanyBM.cs +++ b/Subd/Contracts/BindingModels/CompanyBM.cs @@ -10,7 +10,7 @@ namespace Contracts.BindingModels public class CompanyBM : ICompany { public string Title { get; set; } = string.Empty; - + public string oldTitle { get; set; } = string.Empty; public int? StatusId {get; set; } public string? StatusTitle { get; set; } = string.Empty; diff --git a/Subd/Contracts/BindingModels/HumanBM.cs b/Subd/Contracts/BindingModels/HumanBM.cs index 0bb8e6e..be89b9f 100644 --- a/Subd/Contracts/BindingModels/HumanBM.cs +++ b/Subd/Contracts/BindingModels/HumanBM.cs @@ -10,7 +10,7 @@ namespace Contracts.BindingModels public class HumanBM : IHuman { public string Name { get; set; } = string.Empty; - + public string oldName { get; set; } = string.Empty; public string Phone { get; set; } = string.Empty; public int? StatusId { get; set; } diff --git a/Subd/Contracts/BindingModels/PlaceBM.cs b/Subd/Contracts/BindingModels/PlaceBM.cs index 2af18de..ef0cdb0 100644 --- a/Subd/Contracts/BindingModels/PlaceBM.cs +++ b/Subd/Contracts/BindingModels/PlaceBM.cs @@ -10,7 +10,7 @@ namespace Contracts.BindingModels public class PlaceBM : IPlace { public string Title { get; set; } = string.Empty; - + public string oldTitle { get; set; } = string.Empty; public int Id { get; set; } } } diff --git a/Subd/Contracts/BindingModels/RouteBM.cs b/Subd/Contracts/BindingModels/RouteBM.cs index 356d992..f4d45de 100644 --- a/Subd/Contracts/BindingModels/RouteBM.cs +++ b/Subd/Contracts/BindingModels/RouteBM.cs @@ -9,14 +9,14 @@ namespace Contracts.BindingModels { public class RouteBM : IRoute { - public int? PlaceStart { get; set; } - - public int? PlaceEnd { get; set; } - + public int? PlaceStart { get; set; } + public string PlaceStartName { get; set; } = string.Empty; + public int? PlaceEnd { get; set; } + public string PlaceEndName { get; set; } = string.Empty; public int Length { get; set; } public string Title { get; set; } = string.Empty; - + public string oldTitle { get; set; } = string.Empty; public int Id { get; set; } } } diff --git a/Subd/Contracts/BindingModels/StatusBM.cs b/Subd/Contracts/BindingModels/StatusBM.cs index ea18f31..3943620 100644 --- a/Subd/Contracts/BindingModels/StatusBM.cs +++ b/Subd/Contracts/BindingModels/StatusBM.cs @@ -10,7 +10,7 @@ namespace Contracts.BindingModels public class StatusBM : IStatus { public string Title { get; set; } = string.Empty; - + public string oldTitle { get; set; } = string.Empty; public int Id {get; set;} } } diff --git a/Subd/Contracts/SearchModel/RouteSM.cs b/Subd/Contracts/SearchModel/RouteSM.cs index cbfd662..672422b 100644 --- a/Subd/Contracts/SearchModel/RouteSM.cs +++ b/Subd/Contracts/SearchModel/RouteSM.cs @@ -12,5 +12,6 @@ namespace Contracts.SearchModel public int? Id { get; set; } public int? Start { get; set; } public int? End { get; set; } + public string Title { get; set; } } } diff --git a/Subd/Contracts/ViewModels/CarVM.cs b/Subd/Contracts/ViewModels/CarVM.cs index dc6e5cd..4f4decb 100644 --- a/Subd/Contracts/ViewModels/CarVM.cs +++ b/Subd/Contracts/ViewModels/CarVM.cs @@ -11,6 +11,7 @@ namespace Contracts.ViewModels public class CarVM : ICar { [DisplayName("Номер")] + public string number { get; set; } public int Id { get; set; } [DisplayName("Модель")] public string Model { get; set; } = string.Empty; diff --git a/Subd/Forms/FormCar.Designer.cs b/Subd/Forms/FormCar.Designer.cs index b9c0bbd..80de490 100644 --- a/Subd/Forms/FormCar.Designer.cs +++ b/Subd/Forms/FormCar.Designer.cs @@ -40,6 +40,7 @@ this.label1 = new System.Windows.Forms.Label(); this.Timelabel = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); + this.NumberBox1 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // ModelLabel @@ -153,11 +154,20 @@ this.label2.TabIndex = 12; this.label2.Text = "мс"; // + // NumberBox1 + // + this.NumberBox1.Location = new System.Drawing.Point(241, 60); + this.NumberBox1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.NumberBox1.Name = "NumberBox1"; + this.NumberBox1.Size = new System.Drawing.Size(100, 27); + this.NumberBox1.TabIndex = 13; + // // FormCar // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(375, 305); + this.Controls.Add(this.NumberBox1); this.Controls.Add(this.label2); this.Controls.Add(this.Timelabel); this.Controls.Add(this.label1); @@ -193,5 +203,6 @@ private Label label1; private Label Timelabel; private Label label2; + private TextBox NumberBox1; } } \ No newline at end of file diff --git a/Subd/Forms/FormCar.cs b/Subd/Forms/FormCar.cs index 2cff7ba..20f06e2 100644 --- a/Subd/Forms/FormCar.cs +++ b/Subd/Forms/FormCar.cs @@ -84,6 +84,7 @@ namespace Forms { Id = _id ?? 0, Model = ModelTextBox.Text, + number = NumberBox1.Text, Tonnage = Convert.ToInt32(TonnageTextBox.Text), StatusId = Convert.ToInt32(StatuscomboBox.SelectedValue), StatusTitle = StatuscomboBox.Text, diff --git a/Subd/Forms/FormCars.cs b/Subd/Forms/FormCars.cs index cfb515b..6f5ddc8 100644 --- a/Subd/Forms/FormCars.cs +++ b/Subd/Forms/FormCars.cs @@ -90,14 +90,14 @@ namespace Forms { if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + string id = (DataGridView.SelectedRows[0].Cells["number"].Value.ToString()); _logger.LogInformation("Удаление изделия"); try { if (!_logic.Delete(new CarBM { - Id = id + number = id })) { throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); diff --git a/Subd/Forms/FormCompanies.cs b/Subd/Forms/FormCompanies.cs index e306785..f694b47 100644 --- a/Subd/Forms/FormCompanies.cs +++ b/Subd/Forms/FormCompanies.cs @@ -90,14 +90,14 @@ namespace Forms { if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + string id = (DataGridView.SelectedRows[0].Cells["Title"].Value.ToString()); _logger.LogInformation("Удаление изделия"); try { if (!_logic.Delete(new CompanyBM { - Id = id + Title = id })) { throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); diff --git a/Subd/Forms/FormHuman.Designer.cs b/Subd/Forms/FormHuman.Designer.cs index 195afba..84b5897 100644 --- a/Subd/Forms/FormHuman.Designer.cs +++ b/Subd/Forms/FormHuman.Designer.cs @@ -39,6 +39,7 @@ this.AddTenbutton = new System.Windows.Forms.Button(); this.Timelabel = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); + this.NumbertextBox = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // ComponentNameLabel @@ -143,11 +144,20 @@ this.label1.TabIndex = 11; this.label1.Text = "mc"; // + // NumbertextBox + // + this.NumbertextBox.Location = new System.Drawing.Point(272, 64); + this.NumbertextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.NumbertextBox.Name = "NumbertextBox"; + this.NumbertextBox.Size = new System.Drawing.Size(69, 27); + this.NumbertextBox.TabIndex = 12; + // // FormHuman // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(375, 318); + this.Controls.Add(this.NumbertextBox); this.Controls.Add(this.label1); this.Controls.Add(this.Timelabel); this.Controls.Add(this.AddTenbutton); @@ -181,5 +191,6 @@ private Button AddTenbutton; private Label Timelabel; private Label label1; + private TextBox NumbertextBox; } } \ No newline at end of file diff --git a/Subd/Forms/FormHuman.cs b/Subd/Forms/FormHuman.cs index c28dd33..02b3de0 100644 --- a/Subd/Forms/FormHuman.cs +++ b/Subd/Forms/FormHuman.cs @@ -82,7 +82,7 @@ namespace Forms { var model = new HumanBM { - Id = _id ?? 0, + Id = Convert.ToInt32(NumbertextBox.Text), Name = FIOTextBox.Text, Phone = PhoneTextBox.Text, StatusId = Convert.ToInt32(StatuscomboBox.SelectedValue), diff --git a/Subd/Forms/FormHumans.cs b/Subd/Forms/FormHumans.cs index 6a1fd56..0dd280b 100644 --- a/Subd/Forms/FormHumans.cs +++ b/Subd/Forms/FormHumans.cs @@ -90,14 +90,14 @@ namespace Forms { if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + string id = DataGridView.SelectedRows[0].Cells["Phone"].Value.ToString(); _logger.LogInformation("Удаление изделия"); try { if (!_logic.Delete(new HumanBM { - Id = id + Phone = id })) { throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); diff --git a/Subd/Forms/FormMain.Designer.cs b/Subd/Forms/FormMain.Designer.cs index aa60293..21eb5f0 100644 --- a/Subd/Forms/FormMain.Designer.cs +++ b/Subd/Forms/FormMain.Designer.cs @@ -41,6 +41,7 @@ this.DataGridView = new System.Windows.Forms.DataGridView(); this.CreateOrderButton = new System.Windows.Forms.Button(); this.UpdateListButton = new System.Windows.Forms.Button(); + this.статусToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.MenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); @@ -65,7 +66,8 @@ this.КомпонентыToolStripMenuItem, this.компанииToolStripMenuItem, this.маршрутыToolStripMenuItem, - this.местаToolStripMenuItem}); + this.местаToolStripMenuItem, + this.статусToolStripMenuItem}); this.СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem"; this.СправочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); this.СправочникиToolStripMenuItem.Text = "Cправочники"; @@ -73,35 +75,35 @@ // ИзделияToolStripMenuItem // this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; - this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(167, 26); + this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.ИзделияToolStripMenuItem.Text = "Машины"; this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.МашиныToolStripMenuItem_Click); // // КомпонентыToolStripMenuItem // this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; - this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(167, 26); + this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.КомпонентыToolStripMenuItem.Text = "Водители"; this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.ВодителиToolStripMenuItem_Click); // // компанииToolStripMenuItem // this.компанииToolStripMenuItem.Name = "компанииToolStripMenuItem"; - this.компанииToolStripMenuItem.Size = new System.Drawing.Size(167, 26); + this.компанииToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.компанииToolStripMenuItem.Text = "Компании"; this.компанииToolStripMenuItem.Click += new System.EventHandler(this.компанииToolStripMenuItem_Click); // // маршрутыToolStripMenuItem // this.маршрутыToolStripMenuItem.Name = "маршрутыToolStripMenuItem"; - this.маршрутыToolStripMenuItem.Size = new System.Drawing.Size(167, 26); + this.маршрутыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.маршрутыToolStripMenuItem.Text = "Маршруты"; this.маршрутыToolStripMenuItem.Click += new System.EventHandler(this.маршрутыToolStripMenuItem_Click); // // местаToolStripMenuItem // this.местаToolStripMenuItem.Name = "местаToolStripMenuItem"; - this.местаToolStripMenuItem.Size = new System.Drawing.Size(167, 26); + this.местаToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.местаToolStripMenuItem.Text = "Места"; this.местаToolStripMenuItem.Click += new System.EventHandler(this.местаToolStripMenuItem_Click); // @@ -117,14 +119,14 @@ // водителиToolStripMenuItem // this.водителиToolStripMenuItem.Name = "водителиToolStripMenuItem"; - this.водителиToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.водителиToolStripMenuItem.Size = new System.Drawing.Size(165, 26); this.водителиToolStripMenuItem.Text = "Водители"; this.водителиToolStripMenuItem.Click += new System.EventHandler(this.водителиToolStripMenuItem_Click_1); // // компанииToolStripMenuItem1 // this.компанииToolStripMenuItem1.Name = "компанииToolStripMenuItem1"; - this.компанииToolStripMenuItem1.Size = new System.Drawing.Size(224, 26); + this.компанииToolStripMenuItem1.Size = new System.Drawing.Size(165, 26); this.компанииToolStripMenuItem1.Text = "Компании"; this.компанииToolStripMenuItem1.Click += new System.EventHandler(this.компанииToolStripMenuItem1_Click); // @@ -161,6 +163,13 @@ this.UpdateListButton.UseVisualStyleBackColor = true; this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); // + // статусToolStripMenuItem + // + this.статусToolStripMenuItem.Name = "статусToolStripMenuItem"; + this.статусToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.статусToolStripMenuItem.Text = "Статус"; + this.статусToolStripMenuItem.Click += new System.EventHandler(this.статусToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -198,5 +207,6 @@ private ToolStripMenuItem отчетыToolStripMenuItem; private ToolStripMenuItem водителиToolStripMenuItem; private ToolStripMenuItem компанииToolStripMenuItem1; + private ToolStripMenuItem статусToolStripMenuItem; } } \ No newline at end of file diff --git a/Subd/Forms/FormMain.cs b/Subd/Forms/FormMain.cs index b998838..a8419c7 100644 --- a/Subd/Forms/FormMain.cs +++ b/Subd/Forms/FormMain.cs @@ -50,6 +50,7 @@ namespace Forms DataGridView.Columns["RouteId"].Visible = false; DataGridView.Columns["RouteName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["Km"].Visible = false; } _logger.LogInformation("Загрузка "); @@ -148,5 +149,15 @@ namespace Forms form.ShowDialog(); } } + + private void статусToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStatuses)); + + if (service is FormStatuses form) + { + form.ShowDialog(); + } + } } } diff --git a/Subd/Forms/FormPlaces.cs b/Subd/Forms/FormPlaces.cs index 9ff9ed5..c849de0 100644 --- a/Subd/Forms/FormPlaces.cs +++ b/Subd/Forms/FormPlaces.cs @@ -90,14 +90,14 @@ namespace Forms { if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + string id = (DataGridView.SelectedRows[0].Cells["Title"].Value.ToString()); _logger.LogInformation("Удаление изделия"); try { if (!_logic.Delete(new PlaceBM { - Id = id + Title = id })) { throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); diff --git a/Subd/Forms/FormRoute.cs b/Subd/Forms/FormRoute.cs index 748bf1d..4dbfdaa 100644 --- a/Subd/Forms/FormRoute.cs +++ b/Subd/Forms/FormRoute.cs @@ -84,7 +84,9 @@ namespace Forms Length = Convert.ToInt32(LengthTextBox.Text), PlaceStart = Convert.ToInt32(StartcomboBox.SelectedValue), + PlaceStartName = StartcomboBox.SelectedValue.ToString(), PlaceEnd = Convert.ToInt32(EndcomboBox.SelectedValue), + PlaceEndName = EndcomboBox.SelectedValue.ToString(), Title = StartcomboBox.Text + " - " + EndcomboBox.Text }; diff --git a/Subd/Forms/FormRoutes.cs b/Subd/Forms/FormRoutes.cs index 7e7b7dc..ffee917 100644 --- a/Subd/Forms/FormRoutes.cs +++ b/Subd/Forms/FormRoutes.cs @@ -91,14 +91,14 @@ namespace Forms { if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + string id = DataGridView.SelectedRows[0].Cells["Title"].Value.ToString(); _logger.LogInformation("Удаление изделия"); try { if (!_logic.Delete(new RouteBM { - Id = id + Title = id })) { throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); diff --git a/Subd/Forms/FormStatuses.cs b/Subd/Forms/FormStatuses.cs index 2c983cf..14b122f 100644 --- a/Subd/Forms/FormStatuses.cs +++ b/Subd/Forms/FormStatuses.cs @@ -91,13 +91,14 @@ namespace Forms if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + string title = DataGridView.SelectedRows[0].Cells["Title"].Value.ToString(); _logger.LogInformation("Удаление изделия"); try { if (!_logic.Delete(new StatusBM { - Id = id + Title = title })) { throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); diff --git a/Subd/Forms/FormVoyage.cs b/Subd/Forms/FormVoyage.cs index e33d354..ec8b321 100644 --- a/Subd/Forms/FormVoyage.cs +++ b/Subd/Forms/FormVoyage.cs @@ -1,7 +1,6 @@ using Contracts.BindingModels; using Contracts.BusinessLogic; using Contracts.SearchModel; -using DataBase; using Microsoft.Extensions.Logging; using NLog.LayoutRenderers; using System.Collections.Generic; @@ -40,31 +39,31 @@ namespace Forms if (routes != null) { RoutecomboBox.DisplayMember = "Title"; - RoutecomboBox.ValueMember = "Id"; + RoutecomboBox.ValueMember = "Title"; RoutecomboBox.DataSource = routes; RoutecomboBox.SelectedItem = null; } - var cars = _carLogic.ReadList(new CarSM { StatusId = 1}); + var cars = _carLogic.ReadList(null); if (cars != null) { CarcomboBox.DisplayMember = "Model"; - CarcomboBox.ValueMember = "Id"; + CarcomboBox.ValueMember = "Model"; CarcomboBox.DataSource = cars; CarcomboBox.SelectedItem = null; } - var companys = _companyLogic.ReadList(new CompanySM { StatusId =1}); + var companys = _companyLogic.ReadList(null); if (companys != null) { CompanycomboBox.DisplayMember = "Title"; - CompanycomboBox.ValueMember = "Id"; + CompanycomboBox.ValueMember = "Title"; CompanycomboBox.DataSource = companys; CompanycomboBox.SelectedItem = null; } - var humans = _humanLogic.ReadList(new HumanSM { StatusId=1}); + var humans = _humanLogic.ReadList(null); if (humans != null) { HumancomboBox.DisplayMember = "Name"; - HumancomboBox.ValueMember = "Id"; + HumancomboBox.ValueMember = "Name"; HumancomboBox.DataSource = humans; HumancomboBox.SelectedItem = null; } @@ -92,10 +91,10 @@ namespace Forms var model = new VoyageBM { Id = _id ?? 0, - RouteId = Convert.ToInt32(RoutecomboBox.SelectedValue), - CarId = Convert.ToInt32(CarcomboBox.SelectedValue), - HumanId = Convert.ToInt32(HumancomboBox.SelectedValue), - CompanyId = Convert.ToInt32(CompanycomboBox.SelectedValue), + RouteName = (RoutecomboBox.SelectedValue.ToString()), + CarName = (CarcomboBox.SelectedValue.ToString()), + HumanName = (HumancomboBox.SelectedValue.ToString()), + CompanyName = CompanycomboBox.SelectedValue.ToString(), DateStart = DateOnly.FromDateTime(DateTime.SpecifyKind(dateTimePickerFrom.Value, DateTimeKind.Utc)), DateEnd = DateOnly.FromDateTime(DateTime.SpecifyKind(dateTimePickerTo.Value, DateTimeKind.Utc)), }; diff --git a/Subd/Forms/Forms.csproj b/Subd/Forms/Forms.csproj index c178c26..c67e436 100644 --- a/Subd/Forms/Forms.csproj +++ b/Subd/Forms/Forms.csproj @@ -20,7 +20,7 @@ - + diff --git a/Subd/Forms/Program.cs b/Subd/Forms/Program.cs index 19bd1d8..1ef8bcf 100644 --- a/Subd/Forms/Program.cs +++ b/Subd/Forms/Program.cs @@ -3,9 +3,9 @@ using BusinessBL.BusinessBL; using BusinessLogic.BusinessLogic; using Contracts.BusinessLogic; using Contracts.Storage; -using DataBase.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using MongoDB; using NLog.Extensions.Logging; using System; diff --git a/Subd/GoingToMongo/GoingToMongo.csproj b/Subd/GoingToMongo/GoingToMongo.csproj new file mode 100644 index 0000000..5e99167 --- /dev/null +++ b/Subd/GoingToMongo/GoingToMongo.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/Subd/GoingToMongo/Program.cs b/Subd/GoingToMongo/Program.cs new file mode 100644 index 0000000..77ee9d3 --- /dev/null +++ b/Subd/GoingToMongo/Program.cs @@ -0,0 +1,15 @@ +// See https://aka.ms/new-console-template for more information +using MongoDB; +using MongoDB.Driver; +using System.Data; + +MongoClient context = MongoDateBase.getInstance().client; +foreach (var datab in context.ListDatabaseNames().ToList()) +{ + Console.WriteLine(datab); +} +IMongoDatabase logistic = context.GetDatabase("logistic"); +foreach(var collection in logistic.ListCollections().ToList()) +{ + Console.WriteLine(collection); +} \ No newline at end of file diff --git a/Subd/MongoDB/CarStorage.cs b/Subd/MongoDB/CarStorage.cs new file mode 100644 index 0000000..869d75c --- /dev/null +++ b/Subd/MongoDB/CarStorage.cs @@ -0,0 +1,122 @@ +using Contracts.BindingModels; +using Contracts.SearchModel; +using Contracts.Storage; +using Contracts.ViewModels; +using MongoDB.Bson; +using MongoDB.Driver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MongoDB +{ + public class CarStorage : ICarStorage + { + public MongoClient contex; + public CarStorage() + { + contex = MongoDateBase.getInstance().client; + } + public CarVM? Delete(CarBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Car"); + var res = collection.FindOneAndDelete(new BsonDocument("number", model.number)); + if (res == null) + return null; + return new CarVM + { + Model = res["model"].ToString(), + number = res["number"].ToString(), + StatusTitle = res["Status"].ToString(), + + }; + } + + public CarVM? GetElement(CarSM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Car"); + BsonDocument car = collection.Find(new BsonDocument("number", model.Id)).FirstOrDefault(); + if (car == null) + return null; + return new CarVM + { + Model = car["name"].ToString(), + number = car["phone"].ToString(), + Tonnage = car["tonnage"].ToInt32(), + StatusTitle = car["Status"].ToString() + }; + } + + public List GetFilteredList(CarSM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Car"); + List cars = collection.Find(new BsonDocument { { "$regex", $"^.{model.Model}.$" } }).ToList(); + List res = new List(); + foreach (var car in cars) + { + res.Add(new CarVM + { + Model = car["name"].ToString(), + number = car["phone"].ToString(), + Tonnage = car["tonnage"].ToInt32(), + StatusTitle = car["Status"].ToString() + }); + } + return res; + } + + public List GetFullList() + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Car"); + List cars = collection.Find(new BsonDocument()).ToList(); + List res = new List(); + foreach (var car in cars) + { + res.Add(new CarVM + { + Model = car["model"].ToString(), + number = car["number"].ToString(), + Tonnage = car["tonnage"].ToInt32(), + StatusTitle = car["Status"].ToString() + }); + } + return res; + } + + public CarVM? Insert(CarBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Car"); + BsonDocument car = new BsonDocument { { "number", model.number }, { "model", model.Model }, { "Status", model.StatusTitle }, { "tonnage", model.Tonnage } }; + collection.InsertOne(car); + return new CarVM { + Model = car["model"].ToString(), + number = car["number"].ToString(), + Tonnage = car["tonnage"].ToInt32(), + StatusTitle = car["Status"].ToString() + }; + } + + public CarVM? Update(CarBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Car"); + var result = collection.UpdateOneAsync(new BsonDocument("name", model.oldModel), new BsonDocument("$set", new BsonDocument("name", model.Model))); + if (result == null) + return null; + return new CarVM + { + Model = model.Model, + StatusTitle = model.StatusTitle, + Tonnage = model.Tonnage, + number = model.number + }; + } + } +} diff --git a/Subd/MongoDB/CompanyStorage.cs b/Subd/MongoDB/CompanyStorage.cs new file mode 100644 index 0000000..d093dae --- /dev/null +++ b/Subd/MongoDB/CompanyStorage.cs @@ -0,0 +1,107 @@ +using Contracts.BindingModels; +using Contracts.SearchModel; +using Contracts.Storage; +using Contracts.ViewModels; +using MongoDB.Bson; +using MongoDB.Driver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MongoDB +{ + public class CompanyStorage : ICompanyStorage + { + public MongoClient contex; + public CompanyStorage() + { + contex = MongoDateBase.getInstance().client; + } + public CompanyVM? Delete(CompanyBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Company"); + var res = collection.FindOneAndDelete(new BsonDocument("name", model.Title)); + if (res == null) + return null; + return new CompanyVM + { + Title = res["name"].ToString(), + StatusTitle = res["Status"].ToString() + }; + } + + public CompanyVM? GetElement(CompanySM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Company"); + BsonDocument company = collection.Find(new BsonDocument("name", model.Title)).FirstOrDefault(); + if (company == null) + return null; + return new CompanyVM + { + Title = company["name"].ToString(), + StatusTitle = company["Status"].ToString() + }; + } + + public List GetFilteredList(CompanySM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Company"); + List statuses = collection.Find(new BsonDocument { { "$regex",$"^.{model.Title}.$"} }).ToList(); + List res = new List(); + foreach (var status in statuses) + { + res.Add(new CompanyVM + { + Title = status["name"].ToString(), + StatusTitle = status["Status"].ToString() + }); + } + return res; + } + + public List GetFullList() + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Company"); + List statuses = collection.Find(new BsonDocument()).ToList(); + List res = new List(); + foreach (var status in statuses) + { + res.Add(new CompanyVM + { + Title = status["name"].ToString(), + StatusTitle = status["Status"].ToString() + }); + } + return res; + } + + public CompanyVM? Insert(CompanyBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Company"); + BsonDocument status = new BsonDocument { { "name", model.Title },{"Status", model.StatusTitle } }; + collection.InsertOne(status); + return new CompanyVM { Title = model.Title, StatusTitle = model.StatusTitle }; + } + + public CompanyVM? Update(CompanyBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Company"); + var result = collection.UpdateOneAsync(new BsonDocument("name", model.oldTitle), new BsonDocument("$set", new BsonDocument("name", model.Title))); + if (result == null) + return null; + return new CompanyVM + { + Title = model.Title, + StatusTitle = model.StatusTitle, + }; + } + } +} diff --git a/Subd/MongoDB/HumanStorage.cs b/Subd/MongoDB/HumanStorage.cs new file mode 100644 index 0000000..b10f410 --- /dev/null +++ b/Subd/MongoDB/HumanStorage.cs @@ -0,0 +1,113 @@ +using Contracts.BindingModels; +using Contracts.SearchModel; +using Contracts.Storage; +using Contracts.ViewModels; +using MongoDB.Bson; +using MongoDB.Driver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MongoDB +{ + public class HumanStorage : IHumanStorage + { + public MongoClient contex; + public HumanStorage() + { + contex = MongoDateBase.getInstance().client; + } + public HumanVM? Delete(HumanBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Human"); + var res = collection.FindOneAndDelete(new BsonDocument("phone", model.Phone)); + if (res == null) + return null; + return new HumanVM + { + Name = res["name"].ToString(), + Phone = res["phone"].ToString(), + StatusTitle = res["Status"].ToString(), + + }; + } + + public HumanVM? GetElement(HumanSM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Human"); + BsonDocument human = collection.Find(new BsonDocument("number", model.Id)).FirstOrDefault(); + if (human == null) + return null; + return new HumanVM + { + Name = human["name"].ToString(), + Phone = human["phone"].ToString(), + StatusTitle = human["Status"].ToString() + }; + } + + public List GetFilteredList(HumanSM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Human"); + List humans = collection.Find(new BsonDocument { { "$regex", $"^.{model.Name}.$" } }).ToList(); + List res = new List(); + foreach (var human in humans) + { + res.Add(new HumanVM + { + Name = human["name"].ToString(), + Phone = human["phone"].ToString(), + StatusTitle = human["Status"].ToString() + }); + } + return res; + } + + public List GetFullList() + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Human"); + List humans = collection.Find(new BsonDocument()).ToList(); + List res = new List(); + foreach (var human in humans) + { + res.Add(new HumanVM + { + Name = human["name"].ToString(), + Phone = human["phone"].ToString(), + StatusTitle = human["Status"].ToString() + }); + } + return res; + } + + public HumanVM? Insert(HumanBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Human"); + BsonDocument human = new BsonDocument { {"number", model.Id }, { "name", model.Name }, { "Status", model.StatusTitle }, { "phone" , model.Phone} }; + collection.InsertOne(human); + return new HumanVM { Name = model.Name, StatusTitle = model.StatusTitle,Phone = model.Phone }; + } + + public HumanVM? Update(HumanBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Human"); + var result = collection.UpdateOneAsync(new BsonDocument("name", model.oldName), new BsonDocument("$set", new BsonDocument("name", model.Name))); + if (result == null) + return null; + return new HumanVM + { + Name = model.Name, + StatusTitle = model.StatusTitle, + Phone = model.Phone + }; + } + } +} diff --git a/Subd/MongoDB/MongoDB.csproj b/Subd/MongoDB/MongoDB.csproj new file mode 100644 index 0000000..ed93856 --- /dev/null +++ b/Subd/MongoDB/MongoDB.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/Subd/MongoDB/MongoDateBase.cs b/Subd/MongoDB/MongoDateBase.cs new file mode 100644 index 0000000..5ed1f5a --- /dev/null +++ b/Subd/MongoDB/MongoDateBase.cs @@ -0,0 +1,24 @@ +using MongoDB.Driver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MongoDB +{ + public class MongoDateBase + { + private static MongoDateBase instance; + public MongoClient client; + private MongoDateBase() + { client = new MongoClient("mongodb://localhost:27017"); } + + public static MongoDateBase getInstance() + { + if (instance == null) + instance = new MongoDateBase(); + return instance; + } + } +} diff --git a/Subd/MongoDB/PlaceStorage.cs b/Subd/MongoDB/PlaceStorage.cs new file mode 100644 index 0000000..18ab077 --- /dev/null +++ b/Subd/MongoDB/PlaceStorage.cs @@ -0,0 +1,107 @@ +using Contracts.BindingModels; +using Contracts.SearchModel; +using Contracts.Storage; +using Contracts.ViewModels; +using MongoDB.Bson; +using MongoDB.Driver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MongoDB +{ + public class PlaceStorage : IPlaceStorage + { + public MongoClient contex; + public PlaceStorage() + { + contex = MongoDateBase.getInstance().client; + } + public PlaceVM? Delete(PlaceBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Place"); + var res = collection.FindOneAndDelete(new BsonDocument("name", model.Title)); + if (res == null) + return null; + return new PlaceVM + { + Title = res["name"].ToString(), + + }; + } + + public PlaceVM? GetElement(PlaceSM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Place"); + BsonDocument place = collection.Find(new BsonDocument("name", model.Title)).FirstOrDefault(); + if (place == null) + return null; + return new PlaceVM + { + Title = place["name"].ToString(), + + }; + } + + public List GetFilteredList(PlaceSM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Place"); + List statuses = collection.Find(new BsonDocument { { "$regex", $"^.{model.Title}.$" } }).ToList(); + List res = new List(); + foreach (var status in statuses) + { + res.Add(new PlaceVM + { + Title = status["name"].ToString(), + + }); + } + return res; + } + + public List GetFullList() + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Place"); + List statuses = collection.Find(new BsonDocument()).ToList(); + List res = new List(); + foreach (var status in statuses) + { + res.Add(new PlaceVM + { + Title = status["name"].ToString(), + + }); + } + return res; + } + + public PlaceVM? Insert(PlaceBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Place"); + BsonDocument status = new BsonDocument { { "name", model.Title } }; + collection.InsertOne(status); + return new PlaceVM { Title = model.Title}; + } + + public PlaceVM? Update(PlaceBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Place"); + var result = collection.UpdateOneAsync(new BsonDocument("name", model.oldTitle), new BsonDocument("$set", new BsonDocument("name", model.Title))); + if (result == null) + return null; + return new PlaceVM + { + Title = model.Title, + + }; + } + } +} diff --git a/Subd/MongoDB/RouteStorage.cs b/Subd/MongoDB/RouteStorage.cs new file mode 100644 index 0000000..0417ab5 --- /dev/null +++ b/Subd/MongoDB/RouteStorage.cs @@ -0,0 +1,104 @@ +using Contracts.BindingModels; +using Contracts.SearchModel; +using Contracts.Storage; +using Contracts.ViewModels; +using MongoDB.Bson; +using MongoDB.Driver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MongoDB +{ + public class RouteStorage : IRouteStorage + { + public MongoClient contex; + public RouteStorage() + { + contex = MongoDateBase.getInstance().client; + } + public RouteVM? Delete(RouteBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Route"); + var res = collection.FindOneAndDelete(new BsonDocument("name", model.Title)); + if (res == null) + return null; + return new RouteVM + { + Title = res["name"].ToString(), + + }; + } + + public RouteVM? GetElement(RouteSM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Route"); + BsonDocument route = collection.Find(new BsonDocument("name", model.Title)).FirstOrDefault(); + if (route == null) + return null; + return new RouteVM + { + Title = route["name"].ToString(), + }; + } + + public List GetFilteredList(RouteSM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Route"); + List statuses = collection.Find(new BsonDocument { { "$regex", $"^.{model.Title}.$" } }).ToList(); + List res = new List(); + foreach (var status in statuses) + { + res.Add(new RouteVM + { + Title = status["name"].ToString(), + }); + } + return res; + } + + public List GetFullList() + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Route"); + List statuses = collection.Find(new BsonDocument()).ToList(); + List res = new List(); + foreach (var status in statuses) + { + res.Add(new RouteVM + { + Title = status["name"].ToString(), + Length = status["length"].ToInt32() + }); + } + return res; + } + + public RouteVM? Insert(RouteBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Route"); + BsonDocument status = new BsonDocument { { "name", model.Title }, { "length", model.Length }, { "place_From" , model.PlaceStartName}, { "place_To", model.PlaceEndName } }; + collection.InsertOne(status); + return new RouteVM { Title = model.Title, Length = model.Length }; + } + + public RouteVM? Update(RouteBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Route"); + var result = collection.UpdateOneAsync(new BsonDocument("name", model.oldTitle), new BsonDocument("$set", new BsonDocument("name", model.Title))); + if (result == null) + return null; + return new RouteVM + { + Title = model.Title, + }; + } + } +} diff --git a/Subd/MongoDB/StatusStorage.cs b/Subd/MongoDB/StatusStorage.cs new file mode 100644 index 0000000..884eb99 --- /dev/null +++ b/Subd/MongoDB/StatusStorage.cs @@ -0,0 +1,88 @@ +using Contracts.BindingModels; +using Contracts.SearchModel; +using Contracts.Storage; +using Contracts.ViewModels; +using MongoDB.Bson; +using MongoDB.Driver; +using System; +using System.Collections.Generic; +using System.Diagnostics.Metrics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MongoDB +{ + public class StatusStorage : IStatusStorage + { + public MongoClient contex; + public StatusStorage() + { + contex = MongoDateBase.getInstance().client; + } + + public StatusVM? Delete(StatusBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Status"); + var res = collection.FindOneAndDelete(new BsonDocument("name", model.Title)); + if (res == null) + return null; + return new StatusVM + { + Title = res["name"].ToString() + }; + } + + public StatusVM? GetElement(StatusSM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Status"); + BsonDocument status = collection.Find(new BsonDocument("name",model.Title)).FirstOrDefault(); + if (status == null) + return null; + return new StatusVM + { + Title = status["name"].ToString() + }; + } + + public List GetFullList() + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Status"); + List statuses = collection.Find(new BsonDocument()).ToList(); + List < StatusVM > res = new List(); + foreach (var status in statuses) + { + res.Add(new StatusVM + { + Title = status["name"].ToString() + }) ; + } + return res; + } + + public StatusVM? Insert(StatusBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Status"); + BsonDocument status = new BsonDocument { { "name", model.Title } }; + collection.InsertOne(status); + return new StatusVM { Title = model.Title }; + } + + public StatusVM? Update(StatusBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Status"); + var result = collection.UpdateOneAsync(new BsonDocument("name", model.oldTitle), new BsonDocument("$set", new BsonDocument("name", model.Title))); + if(result == null) + return null; + return new StatusVM + { + Title = model.Title + }; + } + } +} diff --git a/Subd/MongoDB/VoyageStorage.cs b/Subd/MongoDB/VoyageStorage.cs new file mode 100644 index 0000000..ef20e18 --- /dev/null +++ b/Subd/MongoDB/VoyageStorage.cs @@ -0,0 +1,77 @@ +using Contracts.BindingModels; +using Contracts.SearchModel; +using Contracts.Storage; +using Contracts.ViewModels; +using MongoDB.Bson; +using MongoDB.Driver; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static System.Net.Mime.MediaTypeNames; + +namespace MongoDB +{ + public class VoyageStorage : IVoyageStorage + { + public MongoClient contex; + public VoyageStorage() + { + contex = MongoDateBase.getInstance().client; + } + public VoyageVM? Delete(VoyageBM model) + { + throw new Exception("DONT DO IT!!!"); + } + + public VoyageVM? GetElement(VoyageSM model) + { + throw new Exception("DONT DO IT!!!"); + } + + public List GetFilteredList(VoyageSM model) + { + throw new Exception("DONT DO IT!!!"); + } + + public List GetFullList() + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Voyage"); + List humans = collection.Find(new BsonDocument()).ToList(); + List res = new List(); + foreach (var human in humans) + { + res.Add(new VoyageVM + { + CarName = human["car"].ToString(), + HumanName = human["human"].ToString(), + RouteName = human["route"].ToString(), + CompanyName = human["company"].ToString(), + DateStart = DateOnly.Parse(human["date_From"].ToString().Substring(0,10)), + DateEnd = DateOnly.Parse(human["date_To"].ToString().Substring(0,10)), + }); + } + return res; + } + + public VoyageVM? Insert(VoyageBM model) + { + IMongoDatabase db = contex.GetDatabase("logistic"); + var collection = db.GetCollection("Voyage"); + BsonDocument human = new BsonDocument { { "car", model.CarName }, { "human", model.HumanName }, { "route", model.RouteName }, {"company", model.CompanyName } ,{ "date_From", DateTime.Parse(model.DateStart.ToString()) }, { "date_To", DateTime.Parse(model.DateEnd.ToString()) } }; + collection.InsertOne(human); + return new VoyageVM { + CarName = human["car"].ToString(), + HumanName = human["human"].ToString(), + RouteName = human["route"].ToString(), + CompanyName = human["company"].ToString(), + DateStart = DateOnly.Parse(human["date_From"].ToString().Substring(0, 10)), + DateEnd = DateOnly.Parse(human["date_To"].ToString().Substring(0, 10)) + }; + } + + + } +} diff --git a/Subd/Subd.sln b/Subd/Subd.sln index 72aaa19..aa9daee 100644 --- a/Subd/Subd.sln +++ b/Subd/Subd.sln @@ -3,15 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataModels", "Subd\DataModels.csproj", "{4F51BFA8-D899-4A30-96AA-0B6BFE630E9C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataModels", "Subd\DataModels.csproj", "{4F51BFA8-D899-4A30-96AA-0B6BFE630E9C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "Contracts\Contracts.csproj", "{AB284C76-C880-4A90-8E6D-00A8ACCA531A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contracts", "Contracts\Contracts.csproj", "{AB284C76-C880-4A90-8E6D-00A8ACCA531A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataBase", "DataBase\DataBase.csproj", "{1BD4BC13-350F-48B2-8A5D-55585620470B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataBase", "DataBase\DataBase.csproj", "{1BD4BC13-350F-48B2-8A5D-55585620470B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Forms", "Forms\Forms.csproj", "{1901CFE4-7DA9-423E-A3A1-20A3444CC7F7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Forms", "Forms\Forms.csproj", "{1901CFE4-7DA9-423E-A3A1-20A3444CC7F7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLogic", "BusinessLogic\BusinessLogic.csproj", "{6ED0D589-EC71-42CE-A20E-C7C1E036F26B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BusinessLogic", "BusinessLogic\BusinessLogic.csproj", "{6ED0D589-EC71-42CE-A20E-C7C1E036F26B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB", "MongoDB\MongoDB.csproj", "{679402AD-48C2-424E-A64A-D76493B13B15}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GoingToMongo", "GoingToMongo\GoingToMongo.csproj", "{4FC61670-0BE7-4119-ACBF-CE75EB6836F3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +43,14 @@ Global {6ED0D589-EC71-42CE-A20E-C7C1E036F26B}.Debug|Any CPU.Build.0 = Debug|Any CPU {6ED0D589-EC71-42CE-A20E-C7C1E036F26B}.Release|Any CPU.ActiveCfg = Release|Any CPU {6ED0D589-EC71-42CE-A20E-C7C1E036F26B}.Release|Any CPU.Build.0 = Release|Any CPU + {679402AD-48C2-424E-A64A-D76493B13B15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {679402AD-48C2-424E-A64A-D76493B13B15}.Debug|Any CPU.Build.0 = Debug|Any CPU + {679402AD-48C2-424E-A64A-D76493B13B15}.Release|Any CPU.ActiveCfg = Release|Any CPU + {679402AD-48C2-424E-A64A-D76493B13B15}.Release|Any CPU.Build.0 = Release|Any CPU + {4FC61670-0BE7-4119-ACBF-CE75EB6836F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4FC61670-0BE7-4119-ACBF-CE75EB6836F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4FC61670-0BE7-4119-ACBF-CE75EB6836F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4FC61670-0BE7-4119-ACBF-CE75EB6836F3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE