private void btnSave_Click(object sender, EventArgs e) { hasTheSaveButtonPressed = true; DealerBranch dealerBranch = new DealerBranch(); bool ok = false; if (txtCTDI.Text == "") { dealerBranch.CTDI = 0; } else { dealerBranch.CTDI = Convert.ToInt32(txtCTDI.Text); } dealerBranch.BranchName = txtBranchName.Text; dealerBranch.PhoneNumber = txtPhoneNumber.Text; dealerBranch.BaldoPartner = txtBaldoPartner.Text; foreach (Country country in countryList) { if (cmbCountries.Text == country.CountryName) { dealerBranch.CountryId = country.CountryId; } } foreach (Dealer dealer in dealerList) { if (cmbMainDealer.Text == dealer.DealerName) { dealerBranch.DealerId = dealer.DealerId; } } if (Validation.DealerBranchDataValidation(dealerBranch)) { MessageBox.Show("All fields are required."); return; } if (DealerBranchId != 0) { dealerBranch.DealerBranchId = DealerBranchId; //UPDATE ok = DALHelpers.UpdateDealerBranch(dealerBranch); if (ok == true) { MessageBox.Show("The record was successfully saved!"); } else { MessageBox.Show("Error: An error has ocurred when trying to update the Branch!"); } ActivityLog.DealerBranchLogger(dealerBranch, "UPDATE", "Dealer Branch", Environment.UserName); this.Close(); } else //NEW CONTACT { bool CTDI = false; bool BranchName = false; bool BaldoPartner = false; foreach (DealerBranch db in dealerBranchList) { if (dealerBranch.CTDI == db.CTDI) { CTDI = true; } if (dealerBranch.BranchName == db.BranchName) { BranchName = true; } if (dealerBranch.BaldoPartner == db.BaldoPartner) { BaldoPartner = true; } } if (CTDI == true || BranchName == true || BaldoPartner == true) { MessageBox.Show("Error: The Branch Name, CTDI or Baldo Partner already exists in the database!"); return; } else { ok = DALHelpers.AddDealerBranch(dealerBranch); if (ok == true) { MessageBox.Show("The record was successfully saved!"); } } ActivityLog.DealerBranchLogger(dealerBranch, "CREATE", "Dealer Branch", Environment.UserName); this.Close(); } }