private void addBuyer_Click(object sender, RoutedEventArgs e) { WindowAddBuyer winAddBuyer = new WindowAddBuyer(); winAddBuyer.ShowDialog(); UpdateSelectedBuyer(); }
private void ButtonAddCOS_Click(object sender, RoutedEventArgs e) { try { if (!string.IsNullOrWhiteSpace(_newContractOfSale.Error)) { return; } bool beBuyer = true; int _idCounter = 1; foreach (ContractOfSale cos in cosRepository.GetAll()) { _idCounter++; } _newContractOfSale.ContractOfSaleID = _idCounter++; _newContractOfSale.ContractOfSaleNumber = TextBoxAddCOSNumber.Text; _newContractOfSale.ContractOfSaleDate = DateTime.Parse(DPAddCOSDate.Text); _newContractOfSale.ContractOfSaleOwner = ComboBoxAddCOSOwner.SelectedItem.ToString().Trim(); _newContractOfSale.ContractOfSaleBuyer = ComboBoxAddCOSBuyer.Text.Trim(); _newContractOfSale.ContractOfSaleCost = double.Parse(TextBoxAddCOSCost.Text); _newContractOfSale.ContractOfSaleEstateInventoryNumber = ComboBoxAddCOSEstateInventoryNumber.SelectedItem.ToString().Trim(); foreach (Buyer buyer in new BuyerRepository().GetAll()) { if (_newContractOfSale.ContractOfSaleBuyer.Trim() == buyer.BuyerName.Trim()) { beBuyer = true; _newContractOfSale.ContractOfSaleBuyerID = buyer.BuyerID; break; } else { beBuyer = false; } } if (beBuyer == false) { winAddBuyer.ShowDialog(); } foreach (Estate estate in new EstateRepository().GetAll()) { if (_newContractOfSale.ContractOfSaleEstateInventoryNumber.Trim() == estate.EstateInventoryNumber.Trim()) { _newContractOfSale.ContractOfSaleEstateID = estate.EstateID; estate.EstateState = "Продан"; estateRepository.UpdateEstate(estate); break; } } cosRepository.AddContractOfSale(_newContractOfSale); MessageBox.Show("Данные добавлены."); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка"); } }