Beispiel #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            hasTheSaveButtonPressed = true;

            DealerContact dealerContact = new DealerContact();
            bool          ok            = false;

            dealerContact.DealerContactName = txtDealerContactName.Text;
            dealerContact.Department        = txtDepartment.Text;
            dealerContact.Phone             = txtPhone.Text;
            dealerContact.CellPhone         = txtCellPhone.Text;
            dealerContact.Email             = txtEmail.Text;

            foreach (Country country in countryList)
            {
                if (cmbCountries.Text == country.CountryName)
                {
                    dealerContact.CountryId = country.CountryId;
                }
            }

            foreach (Dealer dealer in dealerList)
            {
                if (cmbDealerName.Text == dealer.DealerName)
                {
                    dealerContact.DealerId = dealer.DealerId;
                }
            }

            if (Validation.DealerContactDataValidation(dealerContact))
            {
                MessageBox.Show("All fields are required.");
                return;
            }

            if (DealerContactId != 0)
            {
                dealerContact.DealerContactId = DealerContactId;
                //UPDATE
                ok = DALHelpers.UpdateDealerContact(dealerContact);

                if (ok == true)
                {
                    MessageBox.Show("The record was successfully saved!");
                }
                else
                {
                    MessageBox.Show("Error: An error has ocurred when trying to update the Dealer Contact!");
                }

                ActivityLog.DealerContactLogger(dealerContact, "UPDATE", "Dealer Contact", Environment.UserName);
                this.Close();
            }
            else //NEW CONTACT
            {
                ok = DALHelpers.AddDealerContact(dealerContact);

                if (ok == true)
                {
                    MessageBox.Show("The record was successfully saved!");
                }

                ActivityLog.DealerContactLogger(dealerContact, "CREATE", "Dealer Contact", Environment.UserName);
                this.Close();
            }
        }