From c36ff898f67480a1c3cae24c7d4ed629a0bae284 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Wed, 10 May 2023 17:45:58 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B4=D0=B8=D0=B2=D0=B8=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TransportCompany/FormCreateTrucking.cs | 46 ++++++++++++++----- .../TransportCompany/FormTrucking.cs | 4 ++ .../BusinessLogic/TruckingLogic.cs | 8 ++-- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/TransportCompany/TransportCompany/FormCreateTrucking.cs b/TransportCompany/TransportCompany/FormCreateTrucking.cs index 29b729c..f7c3035 100644 --- a/TransportCompany/TransportCompany/FormCreateTrucking.cs +++ b/TransportCompany/TransportCompany/FormCreateTrucking.cs @@ -3,6 +3,8 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; +using System.Diagnostics.Eventing.Reader; using System.Drawing; using System.Linq; using System.Text; @@ -98,7 +100,7 @@ namespace TransportCompany } else { - comboBoxTypeTransportations.SelectedItem = "Сейчас это недоступно"; + comboBoxTypeTransportations.Text = "Сейчас это недоступно"; } } catch (Exception ex) @@ -153,20 +155,40 @@ namespace TransportCompany try { - var operationResult = _logic.Create(new TruckingBindingModel + if (isMongo) { - ClientId = Convert.ToInt32(comboBoxClients.SelectedValue), - CargoId = Convert.ToInt32(comboBoxCargos.SelectedValue), - TransportId = Convert.ToInt32(comboBoxTransports.SelectedValue), - TransportationId = isMongo ? 404 : Convert.ToInt32(comboBoxTypeTransportations.SelectedValue), - Price = Convert.ToInt32(textBoxPrice.Text), - DateStart = dateTimePickerStart.Value, - DateEnd = dateTimePickerEnd.Value - }); + var operationResult = _logic.Create(new TruckingBindingModel + { + Client = comboBoxClients.SelectedValue.ToString(), + Cargo = comboBoxCargos.SelectedValue.ToString(), + Transport = comboBoxTransports.SelectedValue.ToString(), + Price = Convert.ToInt32(textBoxPrice.Text), + DateStart = dateTimePickerStart.Value, + DateEnd = dateTimePickerEnd.Value + }); - if (!operationResult) + if (!operationResult) + { + throw new Exception("Ошибка при создании сводки по перевозке. Дополнительная информация в логах."); + } + } + else { - throw new Exception("Ошибка при создании сводки по перевозке. Дополнительная информация в логах."); + var operationResult = _logic.Create(new TruckingBindingModel + { + ClientId = Convert.ToInt32(comboBoxClients.SelectedValue), + CargoId = Convert.ToInt32(comboBoxCargos.SelectedValue), + TransportId = Convert.ToInt32(comboBoxTransports.SelectedValue), + TransportationId = Convert.ToInt32(comboBoxTypeTransportations.SelectedValue), + Price = Convert.ToInt32(textBoxPrice.Text), + DateStart = dateTimePickerStart.Value, + DateEnd = dateTimePickerEnd.Value + }); + + if (!operationResult) + { + throw new Exception("Ошибка при создании сводки по перевозке. Дополнительная информация в логах."); + } } MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); diff --git a/TransportCompany/TransportCompany/FormTrucking.cs b/TransportCompany/TransportCompany/FormTrucking.cs index 88db852..22db6a2 100644 --- a/TransportCompany/TransportCompany/FormTrucking.cs +++ b/TransportCompany/TransportCompany/FormTrucking.cs @@ -257,6 +257,8 @@ namespace TransportCompany _truckingLogic = Program.ServiceProvider.GetService(typeof(ITruckingLogic)) as TruckingLogic; _clientLogic = Program.ServiceProvider.GetService(typeof(IClientLogic)) as ClientLogic; + + LoadData(); } private void StartMongoDBToolStripMenuItem_Click(object sender, EventArgs e) @@ -267,6 +269,8 @@ namespace TransportCompany _truckingLogic = Program.ServiceProvider.GetService(typeof(ITruckingLogic)) as TruckingLogic; _clientLogic = Program.ServiceProvider.GetService(typeof(IClientLogic)) as ClientLogic; + + LoadData(); } } } \ No newline at end of file diff --git a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogic/TruckingLogic.cs b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogic/TruckingLogic.cs index 260a4cf..79bce11 100644 --- a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogic/TruckingLogic.cs +++ b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogic/TruckingLogic.cs @@ -142,25 +142,25 @@ namespace TransportCompanyBusinessLogic.BusinessLogic } //проверка на корректный id заказчика - if (model.ClientId <= 0) + if (model.ClientId <= 0 && string.IsNullOrEmpty(model.Client)) { throw new ArgumentNullException("Некорректный id заказчика", nameof(model.ClientId)); } //проверка на корректный id груза - if (model.CargoId <= 0) + if (model.CargoId <= 0 && string.IsNullOrEmpty(model.Cargo)) { throw new ArgumentNullException("Некорректный id груза", nameof(model.CargoId)); } //проверка на корректный id транспорта - if (model.TransportId <= 0) + if (model.TransportId <= 0 && string.IsNullOrEmpty(model.Transport)) { throw new ArgumentNullException("Некорректный id транспорта", nameof(model.TransportId)); } //проверка на корректный id типа транспортировки - if (model.TransportationId <= 0) + if (model.TransportationId <= 0 && string.IsNullOrEmpty(model.Transport)) { throw new ArgumentNullException("Некорректный id типа транспортировки", nameof(model.TransportationId)); }