Exemple #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Cookies["Username"] == null)
            Response.Redirect("ourlogon.aspx");

        if ((Request.Cookies["Admin"] == null))
            Response.Redirect("ourlogon.aspx");

        else
        {

            string s = (string)Session["pet_to_buy"];

            if (String.IsNullOrEmpty(s))
            {
                Response.Redirect("sorry.aspx");
            }

            else
            {
                lblAnimalInfo.Visible = true;
                imgPetPic.Visible = true;

                petToBuy = pet_dao.StringToObject(s);

                string captchaString = prxString.GetRandomString("6");
                var image = System.Drawing.Image.FromStream(prxImage.GetImage(captchaString));

                animalType = petToBuy.getPetType();
                name = petToBuy.getId();
                age = petToBuy.getAge().ToString();
                price = petToBuy.getPrice().ToString();
                description = petToBuy.getDescription();

                switch (animalType)
                {
                    case "Cat":
                        Cat c = (Cat)petToBuy;
                        color = c.getColor();
                        breed = c.getBreed();
                        imgPetPic.ImageUrl = "~/Images/cat.jpg";
                        lblAnimalInfo.Text = "Name:\t" + name + "<br />Breed:\t" + breed + "<br /> Color:\t" + color + "<br />Price:\t" + price + "<br />Description:\t" + description;
                        break;

                    case "Dog":
                        Dog d = (Dog)petToBuy;
                        color = d.getColor();
                        breed = d.getBreed();
                        imgPetPic.ImageUrl = "~/Images/dog.jpg";
                        lblAnimalInfo.Text = "Name:\t" + name + "<br />Breed:\t" + breed + "<br />Age:\t" + age + "<br > Color:\t" + color + "<br />Price:\t" + price + "<br />Description:\t" + description;
                        break;

                    case "Bird":
                        Bird b = (Bird)petToBuy;
                        type = b.getType();
                        weight = b.getWeight().ToString();
                        imgPetPic.ImageUrl = "~/Images/bird.jpg";
                        lblAnimalInfo.Text = "Type:\t" + type + "<br /> Age:\t" + age + "<br />Weight:\t" + weight + "<br />Price:\t" + price + "<br />Description:\t" + description;
                        break;
                    default:
                        break;
                }
            }

        }
    }
Exemple #2
0
        public void addPet(Pet p)
        {
            string path = "c:\\Listing.txt";
            string[] lines = System.IO.File.ReadAllLines(path);
            for (int x = 0; x < lines.Count(); x++)
            {
                string[] ind = lines[x].Split('\t');
                if (ind.Count() > 3)
                {
                    if (p.getId() == ind[3])
                    {
                        return;
                    }
                }
            }
            string result = "";

            result += p.getPetType() + "\t";
            switch (p.getPetType())
            {
                case "Dog":
                    Dog d = new Dog();
                    d = (Dog)p;
                    result += d.getBreed() + "\t" + d.getColor() + "\t" + d.getId() + "\t" + d.getAge() + "\t" +
                        d.getPrice() + "\t" + d.getDescription();
                    break;
                case "Cat":
                    Cat c = new Cat();
                    c = (Cat)p;
                    result += c.getBreed() + "\t" + c.getColor() + "\t" + c.getId() + "\t" + c.getAge() + "\t" +
                        c.getPrice() + "\t" + c.getDescription();
                    break;
                case "Bird":
                    Bird b = new Bird();
                    b = (Bird)p;
                    result += b.getType() + "\t" + b.getWeight() + "\t" + b.getId() + "\t" + b.getAge() + "\t" +
                        b.getPrice() + "\t" + b.getDescription();
                    break;
            }
            Debug.WriteLine(result);
            StreamWriter w = File.AppendText(path);

                w.WriteLine(result);

            w.Close();
        }