private void editContractButton_Click(object sender, EventArgs e) { DataGridViewRow selectedRow = contractsDataGridView.SelectedRows[0]; int contractId = (int)selectedRow.Cells["contractidDataGridViewTextBoxColumn1"].Value; DataRow[] rows = contractsDataTable.Select(String.Format("contract_id = {0}", contractId)); int maxContractId = dataController.GetMaxId(contractsDataTable, "contract_id"); int maxClientId = dataController.GetMaxId(contractsDataTable, "client_id"); int maxHouseId = dataController.GetMaxId(contractsDataTable, "house_id"); int maxApartmentId = dataController.GetMaxId(contractsDataTable, "apartment_id"); ContractForm contractForm = new ContractForm(rows[0], true, maxContractId, maxClientId, maxHouseId, maxApartmentId); if (contractForm.ShowDialog() == DialogResult.OK) { ContractController contractController = new ContractController(contractForm.Row); int result = contractController.Update(); if (result == 0) { MessageBox.Show("Ошибка выполнения редактирования"); } else { MessageBox.Show("Изменения сохранены"); } FillTables(); ShowRowsCountEverywhere(); } }
private void addContractButton_Click(object sender, EventArgs e) { int maxContractId = dataController.GetMaxId(contractsDataTable, "contract_id"); int maxClientId = dataController.GetMaxId(contractsDataTable, "client_id"); int maxHouseId = dataController.GetMaxId(contractsDataTable, "house_id"); int maxApartmentId = dataController.GetMaxId(contractsDataTable, "apartment_id"); ContractForm contractForm = new ContractForm(contractsDataTable.NewRow(), false, maxContractId, maxClientId, maxHouseId, maxApartmentId); if (contractForm.ShowDialog() == DialogResult.OK) { ContractController contractController = new ContractController(contractForm.Row); int result = contractController.Insert(maxClientId, maxHouseId, maxApartmentId); if (result == 0) { MessageBox.Show("Ошибка выполнения вставки"); } FillTables(); ShowRowsCountEverywhere(); } }