private void buttonDonate_Click(object sender, EventArgs e) { try { int caseId = Int32.Parse(dataGridViewCases.SelectedRows[0].Cells["CaseId"].Value.ToString()); double sumToDonate = Double.Parse(textBoxSumToDonate.Text); int donorId = 0; if (dataGridViewDonors.SelectedRows.Count > 0) { donorId = Int32.Parse(dataGridViewDonors.SelectedRows[0].Cells["DonorId"].Value.ToString()); } else { string name = textBoxDonorName.Text; string address = textBoxDonorAddress.Text; string phoneNumber = textBoxDonorPhoneNumber.Text; donorId = _serverService.AddDonor(name, address, phoneNumber); } _serverService.AddDonation(donorId, caseId, sumToDonate); _serverService.UpdateCase(caseId, sumToDonate); Init(); } catch (Exception ex) { MessageBox.Show("Data not inserted corectly!\n" + ex); } }