示例#1
0
    protected void Button2_Click(object sender, EventArgs e)
    {
        int intTemp;
        double doubTemp;
        if (typeRadio.SelectedIndex == -1)
            return;
        Pet p = new Pet();

        if (Int32.TryParse(ageBox.Text, out intTemp))
            p.setAge(intTemp);
        else
            return;
        if (descBox.Text.Length != 0)
            p.setDescription(descBox.Text);
        else
            return;
        if (idBox.Text.Length != 0)
            p.setId(idBox.Text);
        else
            return;
        if (Double.TryParse(priceBox.Text, out doubTemp))
            p.setPrice(doubTemp);
        else
            return;

        PetDao holder = new PetDao();
        switch (typeRadio.SelectedIndex)
        {
            case 0:
                Dog d = new Dog(p);
                if (breedBox.Text.Length != 0)
                    d.setBreed(breedBox.Text);
                else
                    return;
                if (colorBox.Text.Length != 0)
                    d.setColor(colorBox.Text);
                else
                    return;
                holder.addPet(d);
                break;
            case 2:
                Cat c = new Cat(p);
                if (breedBox.Text.Length != 0)
                    c.setBreed(breedBox.Text);
                else
                    return;
                if (colorBox.Text.Length != 0)
                    c.setColor(colorBox.Text);
                else
                    return;
                holder.addPet(c);
                break;
            case 1:
                Bird b = new Bird(p);
                if (typeBox.Text.Length != 0)
                    b.setType(typeBox.Text);
                else
                    return;
                if (Double.TryParse(weightBox.Text, out doubTemp))
                    b.setWeight(doubTemp);
                else
                    return;
                holder.addPet(b);
                break;
        }
        refreshList();
    }
示例#2
0
        public List<Pet> listPets()
        {
            List<Pet> petList = new List<Pet>();

            string path = "C:\\Listing.txt";
            //string path = "C:/Users/Andrew/Desktop/new_cse445/445Proj5/Assignment 5/WebStore/Listing.txt";

            string[] lines = System.IO.File.ReadAllLines(path);
            for (int x = 0; x < lines.Count(); x++)
            {
                string temp = "";
                Dog d;
                Cat c;
                Bird b;
                string[] p = lines[x].Split('\t');
                switch (p[0])
                {
                    case "Dog":
                        d = new Dog();
                        d.setPetType(p[0]);
                        d.setBreed(p[1]);
                        d.setColor(p[2]);
                        d.setId(p[3]);
                        d.setAge(Convert.ToInt32(p[4]));
                        d.setPrice(Convert.ToDouble(p[5]));
                        for (int y = 6; y < p.Count(); y++)
                            temp += p[y];
                        d.setDescription(temp);
                        petList.Add(d);
                        break;
                    case "Cat":
                        c = new Cat();
                        c.setPetType(p[0]);
                        c.setBreed(p[1]);
                        c.setColor(p[2]);
                        c.setId(p[3]);
                        c.setAge(Convert.ToInt32(p[4]));
                        c.setPrice(Convert.ToDouble(p[5]));
                        for (int y = 6; y < p.Count(); y++)
                            temp += p[y];
                        c.setDescription(temp);
                        petList.Add(c);
                        break;
                    case "Bird":
                        b = new Bird();
                        b.setPetType(p[0]);
                        b.setType(p[1]);
                        b.setWeight(Convert.ToDouble(p[2]));
                        b.setId(p[3]);
                        b.setAge(Convert.ToInt32(p[4]));
                        b.setPrice(Convert.ToDouble(p[5]));
                        for (int y = 6; y < p.Count(); y++)
                            temp += p[y];
                        b.setDescription(temp);
                        petList.Add(b);
                        break;
                }
            }

            return petList;
        }