Ejemplo n.º 1
0
 public Branch(string town)
 {
     Town = town;
     Dogs = new Dog[Program.MaxNumberOfAnimals];
     Cats = new Cat[Program.MaxNumberOfAnimals];
     Pigs = new Guinea_Pig[Program.MaxNumberOfAnimals];
 }
Ejemplo n.º 2
0
 public void AddPig(Guinea_Pig pig)
 {
     Pigs[PigCount] = pig;
     PigCount++;
 }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="file"></param>
        /// <param name="branches"></param>
        private static void ReadAnimalData(string file, Branch[] branches)
        {
            string town = null;

            using (StreamReader reader = new StreamReader(@file))
            {
                string line = null;
                line = reader.ReadLine();
                if (line != null)
                {
                    town = line;
                }
                Branch branch = GetBranchByTown(branches, town);
                while (null != (line = reader.ReadLine()))
                {
                    string[] values = line.Split(',');
                    char     type   = Convert.ToChar(line[0]);
                    string   name   = values[1];
                    switch (type)
                    {
                    case 'D':
                        int      chipId     = int.Parse(values[2]);
                        string   breed      = values[3];
                        string   owner      = values[4];
                        string   phone      = values[5];
                        DateTime vd         = DateTime.Parse(values[6]);
                        bool     aggressive = bool.Parse(values[7]);
                        Dog      dog        = new Dog(name, chipId, breed, owner, phone, vd, aggressive);
                        if (!branch.Dogs.Contains(dog))
                        {
                            branch.AddDog(dog);
                        }
                        break;

                    case 'C':
                        int      chipId1 = int.Parse(values[2]);
                        string   breed1  = values[3];
                        string   owner1  = values[4];
                        string   phone1  = values[5];
                        DateTime vd1     = DateTime.Parse(values[6]);
                        Cat      cat     = new Cat(name, chipId1, breed1, owner1, phone1, vd1);
                        if (!branch.Cats.Contains(cat))
                        {
                            branch.AddCat(cat);
                        }
                        break;

                    case 'G':
                        string     breed2 = values[2];
                        string     owner2 = values[3];
                        string     phone2 = values[4];
                        DateTime   vd2    = DateTime.Parse(values[5]);
                        Guinea_Pig pig    = new Guinea_Pig(name, breed2, owner2, phone2, vd2);
                        Console.WriteLine("{0} {1} {2} {3} {4}", name, breed2, owner2, phone2, vd2);
                        if ((!branch.Pigs.Contains(pig)))
                        {
                            branch.AddPig(pig);
                        }
                        break;
                    }
                }
            }
        }