Пример #1
0
        public void AddCat(Cat cat, string changes)
        {
            var conn = new SqlConnection(GetConnectionString());
            var sql = "INSERT INTO " + _table + " VALUES('" + cat.GetBreed().Trim() + "','" + cat.GetCountry().Trim() + "','" + cat.GetOrigin().Trim() + "','" + cat.GetBodyType().Trim() + "','" + cat.GetCoat().Trim() + "','" + cat.GetPattern().Trim() + "','" + cat.GetImage().Trim() + "','" + cat.GetInfo().Trim();

            if (_admin)
            {
                sql += "','" + changes;
            }
            sql += "')";

            try
            {
                conn.Open();
                var cmd = new SqlCommand(sql, conn);

                cmd.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                var msg = "AddCat Sql Error: ";
                msg += ex.Message;
                throw new Exception(msg);
            }
            finally
            {
                conn.Close();
            }
        }
Пример #2
0
        //protected void TextStyle(object sender, EventArgs e)
        //{
        //    var btn = (Button)sender;
        //    var btnText = btn.Text;
        //    if (btnText.Equals("b"))
        //    {
        //    }
        //    else if (btnText.Equals("/"))
        //    {
        //    }
        //    else if (btnText.Equals("_"))
        //    {
        //    }
        //    else if (btnText.Equals("h1"))
        //    {
        //    }
        //    else if (btnText.Equals("h2"))
        //    {
        //    }
        //    else if (btnText.Equals("h3"))
        //    {
        //        textDiv.InnerHtml += "catInformation";
        //    }
        //}
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            //ADD IMAGE!!!!!!!!!!!!
            var breed = CatBreedNameTextBox.Text.Trim();
            var country = CountryTextBox.Text.Trim();
            var origin = OriginTextBox.Text.Trim();
            var bodyType = BodyTypeTextBox.Text.Trim();
            var coat = CoatTextBox.Text.Trim();
            var pattern = PatternTextBox.Text.Trim();
            var image = "";
            var information = EditTextBox.Text.Trim();

            var cat = new Cat(breed, country, origin, bodyType, coat, pattern, image, information);

            if (_admin == false)
            {
                _catBL.AddCat(cat, "new cat");
                Response.Write("<script>alert('You successfully added a breed, the changes are waiting for the approval of the administrator');</script>");
            }
            else
            {
                if (_catBL.AddCat(cat, ""))
                {
                    Response.Write("<script>alert('You successfully added a breed');</script>");
                    return;
                }
                Response.Write("<script>alert('Breed is already exists, try the add specifications page');</script>");
            }
            Page_Load(sender, e);
        }
Пример #3
0
 public Boolean AddCat(Cat cat, string changes)
 {
     var catBl = new CatBL(_admin);
     if (!_admin && catBl.IsCatExist(cat.GetBreed().Trim()))
     {
         return false;
     }
     _catDal.AddCat(cat, changes);
     return true;
 }
Пример #4
0
        public Cat GetCat(string breed)
        {
            Cat cat = null;

            var conn = new SqlConnection(GetConnectionString());
            var sql = "SELECT * FROM " + _table + " WHERE [Breed]='" + breed + "'";

            try
            {
                conn.Open();
                var cmd = new SqlCommand(sql, conn);
                var catReader = cmd.ExecuteReader();
                if (catReader.HasRows)
                {
                    catReader.Read();
                    cat = new Cat(Convert.ToString(catReader["Breed"]).Trim(),
                                         Convert.ToString(catReader["Country"]).Trim(),
                                         Convert.ToString(catReader["Origin"]).Trim(),
                                         Convert.ToString(catReader["Body Type"]).Trim(),
                                         Convert.ToString(catReader["Coat"]).Trim(),
                                         Convert.ToString(catReader["Pattern"]).Trim(),
                                         Convert.ToString(catReader["Image"]).Trim(),
                                         Convert.ToString(catReader["Information"]).Trim());
                }
            }
            catch (SqlException ex)
            {
                var msg = "GetCat Sql Error: ";
                msg += ex.Message;
                throw new Exception(msg);
            }
            finally
            {
                conn.Close();
            }
            return cat;
        }
Пример #5
0
        public LinkedList<Cat> GetAllCatsWithChanges()
        {
            var catsList = new LinkedList<Cat>();

            var conn = new SqlConnection(GetConnectionString());
            const string sql = "SELECT * FROM CatsAdmin";

            try
            {
                conn.Open();
                var cmd = new SqlCommand(sql, conn);
                var catsReader = cmd.ExecuteReader();
                if (catsReader.HasRows)
                {
                    while (catsReader.Read())
                    {
                        var cat = new Cat(Convert.ToString(catsReader["Breed"]).Trim(),
                                             Convert.ToString(catsReader["Country"]).Trim(),
                                             Convert.ToString(catsReader["Origin"]).Trim(),
                                             Convert.ToString(catsReader["Body Type"]).Trim(),
                                             Convert.ToString(catsReader["Coat"]).Trim(),
                                             Convert.ToString(catsReader["Pattern"]).Trim(),
                                             Convert.ToString(catsReader["Image"]).Trim(),
                                             Convert.ToString(catsReader["Information"]).Trim(),
                                             Convert.ToString(catsReader["Changes"]).Trim());

                        if (catsList.Count == 0)
                        {
                            catsList.AddFirst(cat);
                        }
                        else
                        {
                            catsList.AddAfter(catsList.Last, cat);
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                var msg = "GetAllCatsWithChanges Sql Error: ";
                msg += ex.Message;
                throw new Exception(msg);
            }
            finally
            {
                conn.Close();
            }
            return catsList;
        }
Пример #6
0
        public LinkedList<Cat> FindBreedBySpecifications(string[] specifications)
        {
            var breedList = new LinkedList<Cat>();

            var conn = new SqlConnection(GetConnectionString());
            var sql = "SELECT [Breed], [Image] FROM " + _table + " WHERE [Body type]='" + specifications[0] + "' OR [Coat]='" + specifications[1] + "' OR [Pattern]='" + specifications[2] + "'";
            try
            {
                conn.Open();
                var cmd = new SqlCommand(sql, conn);
                var breedAndImageReader = cmd.ExecuteReader();
                while (breedAndImageReader.Read())
                {
                    var cat = new Cat(Convert.ToString(breedAndImageReader["Breed"]).Trim(), Convert.ToString(breedAndImageReader["Image"]).Trim());
                    if (breedList.Count == 0)
                    {
                        breedList.AddFirst(cat);
                    }
                    else
                    {
                        breedList.AddAfter(breedList.Last, cat);
                    }
                }
            }
            catch (SqlException ex)
            {
                var msg = "FindBreedBySpecification Sql Error: ";
                msg += ex.Message;
                throw new Exception(msg);
            }
            finally
            {
                conn.Close();
            }
            return breedList;
        }
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            var breed = ChooseBreedDownList.SelectedItem.Text.Trim();
            var country = CountryTextBox.Text.Trim();
            var origin = OriginTextBox.Text.Trim();
            var bodyType = BodyTypeTextBox.Text.Trim();
            var coat = CoatTextBox.Text.Trim();
            var pattern = PatternTextBox.Text.Trim();
            var image = "";

            var specifications = new string[6];
            specifications[0] = "Country";
            specifications[1] = "Origin";
            specifications[2] = "Body Type";
            specifications[3] = "Coat";
            specifications[4] = "Pattern";
            specifications[5] = "Image";
            var specificationsValues = new string[7];
            specificationsValues[0] = country;
            specificationsValues[1] = origin;
            specificationsValues[2] = bodyType;
            specificationsValues[3] = coat;
            specificationsValues[4] = pattern;
            specificationsValues[5] = image;

            if (_admin == false)
            {
                var cat = _userCatBL.GetCat(breed);
                var newCat = new Cat(breed, country, origin, bodyType, coat, pattern, cat.GetInfo(), image);
                _catBL.AddCat(newCat, "specifications");
            }
            else
            {
                _catBL.AddSpecificationsToBreed(breed, specifications, specificationsValues);
            }
            Response.Write(_admin
                ? "<script>alert('You successfully added specifications');</script>"
                : "<script>alert('You successfully added specifications, the changes are waiting for the approval of the administrator');</script>");
        }