예제 #1
0
        protected void countrySaveButton_Click(object sender, EventArgs e)
        {
            Country aCountry = new Country();
            aCountry.Name = Request.Form["countryNameTextBox"];
            aCountry.About = Request.Form["edit"];

            string message = countryManager.SaveCountry(aCountry);
            if (message == "1")
            {
                messageLabel.Text = "Successfully saved";
                messageLabel.ForeColor = Color.Green;
            }
            else if (message == "2")
            {
                messageLabel.Text = "Name already Exists!";
                messageLabel.ForeColor = Color.Red;
            }
            else
            {
                messageLabel.Text = "Save Failed!";
                messageLabel.ForeColor = Color.Red;
            }

            LoadAllCountryGridView();
        }
예제 #2
0
        public bool SaveCountry(Country aCountry)
        {
            string insertSQL;
            insertSQL = "INSERT INTO tbl_country (";
            insertSQL += "CountryName, AboutCountry) ";
            insertSQL += "VALUES (";
            insertSQL += "@name, @about)";

            sqlConnection.Open();
            sqlCommand.CommandText = insertSQL;
            sqlCommand.Parameters.AddWithValue("@name", aCountry.Name);
            sqlCommand.Parameters.AddWithValue("@about", aCountry.About);

            int saveRowAffected = sqlCommand.ExecuteNonQuery();
            sqlConnection.Close();

            if (saveRowAffected > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
예제 #3
0
 public string SaveCountry(Country aCountry)
 {
     if (countryGateway.HasCountryNameExists(aCountry.Name))
     {
         return "2";
     }
     else
     {
         if (countryGateway.SaveCountry(aCountry))
         {
             return "1";
         }
         else
         {
             return "0";
         }
     }
     return null;
 }
예제 #4
0
        private List<Country> GetQueryinList(string query)
        {
            sqlConnection.Open();
            sqlCommand.CommandText = query;
            SqlDataReader reader = sqlCommand.ExecuteReader();

            List<Country> allCountryList = new List<Country>();

            while (reader.Read())
            {
                Country aCountry =new Country();

                aCountry.Id = int.Parse(reader["id"].ToString());
                aCountry.Name = reader["countryName"].ToString();
                aCountry.About = reader["AboutCountry"].ToString();

                allCountryList.Add(aCountry);
            }
            reader.Close();
            sqlConnection.Close();

            return allCountryList;
        }