diff --git a/TransportCompany/TransportCompamyMongoDBImplementer/DBMSContext.cs b/TransportCompany/TransportCompamyMongoDBImplementer/DBMSContext.cs index 6fea2f6..662a9cf 100644 --- a/TransportCompany/TransportCompamyMongoDBImplementer/DBMSContext.cs +++ b/TransportCompany/TransportCompamyMongoDBImplementer/DBMSContext.cs @@ -9,7 +9,7 @@ namespace TransportCompamyMongoDBImplementer { public class DBMSContext { - private const string ConnectionString = "mongodb://192.168.1.135:27017"; + private const string ConnectionString = "mongodb://127.0.0.1:27017"; private const string DatabaseName = "transportcompany"; diff --git a/TransportCompany/TransportCompamyMongoDBImplementer/Implements/TruckingStorage.cs b/TransportCompany/TransportCompamyMongoDBImplementer/Implements/TruckingStorage.cs index e1540f1..7d384f8 100644 --- a/TransportCompany/TransportCompamyMongoDBImplementer/Implements/TruckingStorage.cs +++ b/TransportCompany/TransportCompamyMongoDBImplementer/Implements/TruckingStorage.cs @@ -96,9 +96,9 @@ namespace TransportCompamyMongoDBImplementer.Implements public bool InsertFromPostgres(List model) { - var clientCollection = context.ConnectToMongo("client"); - var cargoCollection = context.ConnectToMongo("cargo"); - var transportCollection = context.ConnectToMongo("transport"); + var clientCollection = context.ConnectToMongo("client"); + var cargoCollection = context.ConnectToMongo("cargo"); + var transportCollection = context.ConnectToMongo("transport"); var truckingCollection = context.ConnectToMongo("trucking"); //список, который по итогу и будем вставлять @@ -111,9 +111,9 @@ namespace TransportCompamyMongoDBImplementer.Implements newTrucking.DateStart = element.DateStart; newTrucking.DateEnd = element.DateEnd; newTrucking.Price = element.Price; - newTrucking.Cargo = cargoCollection.Find(x => x.Cargo.TypeCargo == element.Cargo).FirstOrDefault().Id; - newTrucking.Client = clientCollection.Find(x => x.Client.Email == element.ClientEmail).FirstOrDefault().Id; - newTrucking.Transport = transportCollection.Find(x => x.Transport.TransportType == element.TransportName).FirstOrDefault().Id; + newTrucking.Cargo = cargoCollection.Find(x => x.TypeCargo == element.Cargo).FirstOrDefault().Id; + newTrucking.Client = clientCollection.Find(x => x.Email == element.ClientEmail).FirstOrDefault().Id; + newTrucking.Transport = transportCollection.Find(x => x.TransportType == element.TransportName).FirstOrDefault().Id; models.Add(Trucking.Create(context, newTrucking)); } diff --git a/TransportCompany/TransportCompamyMongoDBImplementer/Models/Trucking.cs b/TransportCompany/TransportCompamyMongoDBImplementer/Models/Trucking.cs index 4eb1236..3b05b75 100644 --- a/TransportCompany/TransportCompamyMongoDBImplementer/Models/Trucking.cs +++ b/TransportCompany/TransportCompamyMongoDBImplementer/Models/Trucking.cs @@ -69,7 +69,9 @@ namespace TransportCompamyMongoDBImplementer.Models ClientName = Client == null ? string.Empty : Client.Name, ClientSurname = Client == null ? string.Empty : Client.Surname, ClientPatronymic = Client == null ? string.Empty : Client.Patronymic, + ClientEmail = Client == null ? string.Empty : Client.Email, TransportName = Transport == null ? string.Empty : Transport.TransportType, + TypeTransportation = Transport == null ? string.Empty : Transport.TransportationType, Cargo = Cargo == null ? string.Empty : Cargo.TypeCargo }; } diff --git a/TransportCompany/TransportCompamyMongoDBImplementer/TransportCompamyMongoDBImplementer.csproj b/TransportCompany/TransportCompamyMongoDBImplementer/TransportCompamyMongoDBImplementer.csproj index 132c02c..de818f8 100644 --- a/TransportCompany/TransportCompamyMongoDBImplementer/TransportCompamyMongoDBImplementer.csproj +++ b/TransportCompany/TransportCompamyMongoDBImplementer/TransportCompamyMongoDBImplementer.csproj @@ -6,4 +6,13 @@ enable + + + + + + + + + diff --git a/TransportCompany/TransportCompany/App.config b/TransportCompany/TransportCompany/App.config index 65f2f7c..2d2a6fb 100644 --- a/TransportCompany/TransportCompany/App.config +++ b/TransportCompany/TransportCompany/App.config @@ -4,4 +4,4 @@ - \ No newline at end of file + diff --git a/TransportCompany/TransportCompany/FormCreateTrucking.cs b/TransportCompany/TransportCompany/FormCreateTrucking.cs index 753771c..29b729c 100644 --- a/TransportCompany/TransportCompany/FormCreateTrucking.cs +++ b/TransportCompany/TransportCompany/FormCreateTrucking.cs @@ -18,7 +18,11 @@ namespace TransportCompany { private readonly ILogger _logger; - private readonly IClientLogic _logicCl; + private bool isMongo; + + public bool Mongo { set { isMongo = value; } } + + private readonly IClientLogic _logicCl; private readonly ITransportLogic _logicTransport; @@ -82,12 +86,19 @@ namespace TransportCompany comboBoxTransports.SelectedItem = null; } - if (viewTransportation != null) + if (!isMongo) { - comboBoxTypeTransportations.DisplayMember = "TransportationType"; - comboBoxTypeTransportations.ValueMember = "Id"; - comboBoxTypeTransportations.DataSource = viewTransportation; - comboBoxTypeTransportations.SelectedItem = null; + if (viewTransportation != null) + { + comboBoxTypeTransportations.DisplayMember = "TransportationType"; + comboBoxTypeTransportations.ValueMember = "Id"; + comboBoxTypeTransportations.DataSource = viewTransportation; + comboBoxTypeTransportations.SelectedItem = null; + } + } + else + { + comboBoxTypeTransportations.SelectedItem = "Сейчас это недоступно"; } } catch (Exception ex) @@ -128,12 +139,15 @@ namespace TransportCompany return; } - if (comboBoxTypeTransportations.SelectedValue == null) + if (!isMongo) { - MessageBox.Show("Выберите тип транспортировки", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + if (comboBoxTypeTransportations.SelectedValue == null) + { + MessageBox.Show("Выберите тип транспортировки", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } + return; + } + } _logger.LogInformation("Создание сводки по перевозке"); @@ -144,7 +158,7 @@ namespace TransportCompany ClientId = Convert.ToInt32(comboBoxClients.SelectedValue), CargoId = Convert.ToInt32(comboBoxCargos.SelectedValue), TransportId = Convert.ToInt32(comboBoxTransports.SelectedValue), - TransportationId = Convert.ToInt32(comboBoxTypeTransportations.SelectedValue), + TransportationId = isMongo ? 404 : Convert.ToInt32(comboBoxTypeTransportations.SelectedValue), Price = Convert.ToInt32(textBoxPrice.Text), DateStart = dateTimePickerStart.Value, DateEnd = dateTimePickerEnd.Value diff --git a/TransportCompany/TransportCompany/FormTransferData.cs b/TransportCompany/TransportCompany/FormTransferData.cs index ee62224..b9e5dad 100644 --- a/TransportCompany/TransportCompany/FormTransferData.cs +++ b/TransportCompany/TransportCompany/FormTransferData.cs @@ -60,7 +60,10 @@ namespace TransportCompany _truckingLogic = Program.ServiceProvider.GetService(typeof(ITruckingLogic)) as TruckingLogic; _transportLogic = Program.ServiceProvider.GetService(typeof(ITransportLogic)) as TransportLogic; - + _cargoLogic.TransferData(cargolist); + _clientLogic.TransferData(clientlist); + _transportLogic.TransferData(transportlist); + _truckingLogic.TransferData(truckinglist); MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); diff --git a/TransportCompany/TransportCompany/FormTransport.cs b/TransportCompany/TransportCompany/FormTransport.cs index 65da68b..2d5718b 100644 --- a/TransportCompany/TransportCompany/FormTransport.cs +++ b/TransportCompany/TransportCompany/FormTransport.cs @@ -19,6 +19,10 @@ namespace TransportCompany private readonly ITransportLogic _logic; + private bool isMongo; + + public bool SetMongo { set { isMongo = value;} } + public FormTransport(ILogger logger, ITransportLogic logic) { InitializeComponent(); @@ -42,9 +46,19 @@ namespace TransportCompany if (list != null) { dataGridView.DataSource = list; - dataGridView.Columns["MongoId"].Visible = false; - dataGridView.Columns["TransportationType"].Visible = false; - dataGridView.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + if (!isMongo) + { + dataGridView.Columns["Id"].Visible = true; + dataGridView.Columns["MongoId"].Visible = false; + } + else + { + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["MongoId"].Visible = true; + } + + dataGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка транспортных средств"); diff --git a/TransportCompany/TransportCompany/FormTrucking.cs b/TransportCompany/TransportCompany/FormTrucking.cs index 3f32385..88db852 100644 --- a/TransportCompany/TransportCompany/FormTrucking.cs +++ b/TransportCompany/TransportCompany/FormTrucking.cs @@ -90,6 +90,8 @@ namespace TransportCompany if (service is FormCreateTrucking form) { + form.Mongo = _mongo; + form.ShowDialog(); LoadData(); } @@ -130,12 +132,15 @@ namespace TransportCompany private void TypeTransportationToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormTypeTransportation)); - - if (service is FormTypeTransportation form) + if (!_mongo) { - form.ShowDialog(); - LoadData(); + var service = Program.ServiceProvider?.GetService(typeof(FormTypeTransportation)); + + if (service is FormTypeTransportation form) + { + form.ShowDialog(); + LoadData(); + } } } diff --git a/TransportCompany/TransportCompany/Program.cs b/TransportCompany/TransportCompany/Program.cs index 3485722..58416a8 100644 --- a/TransportCompany/TransportCompany/Program.cs +++ b/TransportCompany/TransportCompany/Program.cs @@ -94,7 +94,6 @@ namespace TransportCompany _serviseCollection.Remove(_serviseCollection.FirstOrDefault(descriptor => descriptor.ServiceType == typeof(IClientStorage))); _serviseCollection.Remove(_serviseCollection.FirstOrDefault(descriptor => descriptor.ServiceType == typeof(ITruckingStorage))); _serviseCollection.Remove(_serviseCollection.FirstOrDefault(descriptor => descriptor.ServiceType == typeof(ITransportStorage))); - _serviseCollection.Remove(_serviseCollection.FirstOrDefault(descriptor => descriptor.ServiceType == typeof(ITransportationStorage))); _serviseCollection.AddTransient(); _serviseCollection.AddTransient(); diff --git a/TransportCompany/TransportCompanyContracts/ViewModels/TransportViewModel.cs b/TransportCompany/TransportCompanyContracts/ViewModels/TransportViewModel.cs index b440cb3..ffce457 100644 --- a/TransportCompany/TransportCompanyContracts/ViewModels/TransportViewModel.cs +++ b/TransportCompany/TransportCompanyContracts/ViewModels/TransportViewModel.cs @@ -10,13 +10,16 @@ namespace TransportCompanyContracts.ViewModels { public class TransportViewModel : ITransportModel { + [DisplayName("Номер")] public int Id { get; set; } + [DisplayName("Номер")] public string? MongoId { get; set; } - public string? TransportationType { get; set; } - [DisplayName("Вид транспорта")] public string Tranport { get; set; } = string.Empty; + + [DisplayName("Тип перевозки")] + public string? TransportationType { get; set; } } }