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

            Dealer dealer = new Dealer();
            bool   ok     = false;

            if (Validation.DealerDataValidation(txtDealerName.Text, cmbCountries.Text))
            {
                MessageBox.Show("All fields are required.");
                return;
            }

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

            dealer.DealerName = txtDealerName.Text;

            if (GlobalDealerId != 0)
            {
                dealer.DealerId = GlobalDealerId;
                //UPDATE
                ok = DALHelpers.UpdateMainDealer(dealer);

                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.DealerLogger(dealer, "UPDATE", "Main Dealer", Environment.UserName);
                this.Close();
            }
            else //NEW MAIN DEALER
            {
                ok = DALHelpers.AddMainDealer(dealer);

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

                ActivityLog.DealerLogger(dealer, "CREATE", "Main Dealer", Environment.UserName);
                this.Close();
            }
        }