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)); }