Example #1
0
 private void btnEdit_Click(object sender, EventArgs e)
 {
     // if user click on Edit button
     try
     {
         if (dgvCountry.RowCount != 0)
         {
             int countryId;
             countryId = (int)(dgvCountry.SelectedRows[0].Cells[0].Value);
             CountryDialog dlgCountry   = new CountryDialog();
             CountryBO     objCountryBO = new CountryBO();
             Country       objCountry   = objCountryBO.GetCountry(countryId);
             dlgCountry.CountryName  = objCountry.CountryName;
             dlgCountry.ZipCodeStart = Convert.ToInt32(objCountry.ZipCodeStart);
             dlgCountry.ZipCodeEnd   = Convert.ToInt32(objCountry.ZipCodeEnd);
             dlgCountry.IsActive     = objCountry.IsActive;
             string country = objCountry.CountryName;
             if (dlgCountry.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
                 objCountry.CountryName  = dlgCountry.CountryName;
                 objCountry.ZipCodeStart = dlgCountry.ZipCodeStart;
                 objCountry.ZipCodeEnd   = dlgCountry.ZipCodeEnd;
                 objCountry.IsActive     = dlgCountry.IsActive;
                 objCountryBO.UpdateCountry(objCountry);
                 BindDataToGrid();
             }
         }
     }
     catch (System.Data.SqlClient.SqlException)
     {
         MessageBox.Show("CountryName AlreadyEntered");
     }
 }
Example #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // if user click on Add button
            CountryDialog dlgCountry = new CountryDialog();

            if (dlgCountry.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    CountryBO objCountryBO = new CountryBO();
                    objCountryBO.InsertCountry(dlgCountry.CountryName, dlgCountry.ZipCodeStart, dlgCountry.ZipCodeEnd, dlgCountry.IsActive);
                    BindDataToGrid();
                }
                catch (Exception)
                {
                    MessageBox.Show("CountryName AlredyEntered");
                }
            }
        }