Пример #1
0
        private void GetAll_Click(object sender, EventArgs e)
        {
            List <Animal> animals = AnimalDbHelper.GetTable();
            string        text    = animals.Aggregate("", (current, animal) => current + string.Format("Name: {0} Type: {1} Food Intake: {2}\n", animal.Name, animal.Type, animal.Food_Intake));

            Animals.Text = text;
        }
Пример #2
0
        private void AddAnimal_Click(object sender, EventArgs e)
        {
            animal.Name     = name.Text;
            animal.Type     = Type.Text;
            animal.Room     = (byte)Room.Value;
            animal.Has_Shot = Shot.Checked;
            animal.Color    = Color.Text;
            Double f;

            if (Double.TryParse(FoodIntake.Text, out f))
            {
                animal.Food_Intake = f;
            }
            else
            {
                MessageBox.Show("Invalid Food Intake!");
                return;
            }
            animal.Adoption_Status = Adopted.Checked;

            if (AnimalDbHelper.UpdateAnimal(animal))
            {
                this.Close();
            }
            else
            {
                MessageBox.Show("There was a failure adding the animal, possibly due to an invalid animal id.");
            }
        }
Пример #3
0
        private void AddAnimal_Click(object sender, EventArgs e)
        {
            Animal a = new Animal();

            a.Name     = name.Text;
            a.Type     = Type.Text;
            a.Room     = (byte)Room.Value;
            a.Has_Shot = Shot.Checked;
            a.Color    = Color.Text;
            Double f;

            if (Double.TryParse(FoodIntake.Text, out f))
            {
                a.Food_Intake = f;
            }
            else
            {
                MessageBox.Show("Invalid Food Intake!");
                return;
            }
            a.Adoption_Status = false;

            AnimalDbHelper.AddAnimal(a);
            this.Close();
        }
Пример #4
0
        private void Search_Click(object sender, EventArgs e)
        {
            List <Animal> animals = AnimalDbHelper.GetTable();
            Animal        animal  = animals.First(x => x.Room == (byte)Room.Value && x.Name == name.Text &&
                                                  x.Type == Type.Text);

            if (animal != null)
            {
                new EditAnimalMenu(animal).Show();
                Close();
            }
            else
            {
                MessageBox.Show("No animal found!");
                return;
            }
        }
Пример #5
0
        private void ImportAnimal_Click(object sender, EventArgs e)
        {
            OpenFileDialog file = new OpenFileDialog();
            string         path = "";

            if (file.ShowDialog() == DialogResult.OK)
            {
                path = file.FileName;
                var data = File.ReadAllLines(path)
                           .Skip(1)
                           .Select(columns => columns.Split(','))
                           .Select(columns => new
                {
                    Name            = columns[0],
                    Type            = columns[1],
                    Room            = (byte)parse(columns[2]),
                    Color           = columns[3],
                    Has_Shot        = (columns[4] == "T"),
                    Food_Intake     = parse(columns[5]),
                    Adoption_Status = false
                });

                List <Animal> animals = new List <Animal>();
                foreach (var line in data)
                {
                    Animal animal = new Animal();
                    animal.Name            = line.Name;
                    animal.Type            = line.Type;
                    animal.Food_Intake     = line.Food_Intake;
                    animal.Room            = line.Room;
                    animal.Color           = line.Color;
                    animal.Has_Shot        = line.Has_Shot;
                    animal.Adoption_Status = line.Adoption_Status;
                    animals.Add(animal);
                }
                if (AnimalDbHelper.AddAnimals(animals))
                {
                    MessageBox.Show("Success!");
                }
                return;
            }
            MessageBox.Show("Not a good file");
            return;
        }