Ejemplo n.º 1
0
 public Cat(Pet p)
 {
     setPetType("Cat");
     setId(p.getId());
     setAge(p.getAge());
     setPrice(p.getPrice());
     setDescription(p.getDescription());
 }
Ejemplo n.º 2
0
 public Bird(Pet p)
 {
     setPetType("Bird");
     setId(p.getId());
     setAge(p.getAge());
     setPrice(p.getPrice());
     setDescription(p.getDescription());
 }
Ejemplo n.º 3
0
 public string ObjectToString(Pet obj)
 {
     MemoryStream ms = new MemoryStream();
     new BinaryFormatter().Serialize(ms, obj);
     return Convert.ToBase64String(ms.ToArray());
 }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
0
 public Dog(Pet p)
 {
     setPetType("Dog");
     setId(p.getId());
     setAge(p.getAge());
     setPrice(p.getPrice());
     setDescription(p.getDescription());
 }