Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            hasTheSaveButtonPressed = true;

            Country country = new Country();
            bool    ok      = false;

            country.CountryId   = Convert.ToInt32(txtCountryCode.Text);
            country.CountryName = txtCountryName.Text;

            if (Validation.CountryDataValidation(country))
            {
                MessageBox.Show("Please enter the Contact details.");
                return;
            }

            if (CountryID > 0)
            {
                //UPDATE
                ok = DALHelpers.UpdateCountry(country, CountryID);

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

                ActivityLog.CountryLogger(country, "UPDATE", CountryName, CountryID, Environment.UserName);
                this.Close();
            }
            else //NEW COUNTRY
            {
                List <Country> countryList = new List <Country>();

                countryList = DALHelpers.GetCountryById(country.CountryId);
                if (countryList.Count > 0)
                {
                    MessageBox.Show("Error: The ID: " + country.CountryId + " already exists in the database!");
                    return;
                }
                else
                {
                    ok = DALHelpers.AddCrountry(country);

                    if (ok == true)
                    {
                        ActivityLog.CountryLogger(country, "CREATE", "", 0, Environment.UserName);
                        MessageBox.Show("The record was successfully saved!");
                    }
                }

                this.Close();
            }
        }