Beispiel #1
0
 public ZooKeeperForm(User user)
 {
     InitializeComponent();
     animalList = AnimalHelper.GetAnimalList();
     tabControl1.SelectedIndex = 1;
     loggedUser = user;
 }
Beispiel #2
0
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex.Equals(7) && e.RowIndex >= 0)
     {
         DataGridViewRow row           = dataGridView1.Rows[e.RowIndex];
         string          value1        = row.Cells[0].Value.ToString();
         Animal          updatedAnimal = new Animal();
         foreach (Animal item in animalList)
         {
             if (item.AnimalID == Int16.Parse(value1))
             {
                 updatedAnimal = item;
                 break;
             }
         }
         updateAnimalForm updateAnimalForm = new updateAnimalForm(animalList, updatedAnimal);
         updateAnimalForm.ShowDialog();
         if (updateAnimalForm.animalUpdated)
         {
             animalList = AnimalHelper.GetAnimalList();
             PopulateData();
         }
     }
 }
        private void ConnectAnimal()
        {
            animalList = AnimalHelper.GetAnimalList();

            int ampCount = 0, birdCount = 0, mamalCount = 0, reptileCount = 0;
            int NormalCount = 0, ExtinctCount = 0, VulnerableCount = 0, NearThreatCount = 0, EndangeredCount = 0, LeastConcernCount = 0,
                CriticallyCount = 0;

            //count animals by class and by status
            foreach (Animal item in animalList)
            {
                switch (item.AnimalClass)
                {
                case AnimalClass.Amphibian:
                    ampCount++;
                    break;

                case AnimalClass.Bird:
                    birdCount++;
                    break;

                case AnimalClass.Mammal:
                    mamalCount++;
                    break;

                case AnimalClass.Reptile:
                    reptileCount++;
                    break;

                default:
                    break;
                }
                // count animal by status
                switch (item.Status)
                {
                case AnimalStatus.Normal:
                    NormalCount++;
                    break;

                case AnimalStatus.ExtinctInTheWild:
                    ExtinctCount++;
                    break;

                case AnimalStatus.Vulnerable:
                    VulnerableCount++;
                    break;

                case AnimalStatus.NearThreatened:
                    NearThreatCount++;
                    break;

                case AnimalStatus.Endangered:
                    EndangeredCount++;
                    break;

                case AnimalStatus.LeastConcern:
                    LeastConcernCount++;
                    break;

                case AnimalStatus.CriticallyEndangered:
                    CriticallyCount++;
                    break;

                default:
                    break;
                }
            }
            // write count values
            totalLabel.Text   = animalList.Count.ToString();
            amplabel.Text     = ampCount.ToString();
            birdLabel.Text    = birdCount.ToString();
            mamalLabel.Text   = mamalCount.ToString();
            reptileLabel.Text = reptileCount.ToString();
            normlabel.Text    = NormalCount.ToString();
            extlabel.Text     = ExtinctCount.ToString();
            vullabel.Text     = VulnerableCount.ToString();
            nearlabel.Text    = NearThreatCount.ToString();
            endlabel.Text     = EndangeredCount.ToString();
            leastlabel.Text   = LeastConcernCount.ToString();
            criticlabel.Text  = CriticallyCount.ToString();

            animalLoaded = true;
        }
Beispiel #4
0
        // Add Animals to database and update
        private void UpdateBTN_Click(object sender, EventArgs e)
        {
            // Check if Valid user info is entered
            if (addedAnimalList.Count != 0)
            {
                string          connetionString = null;
                MySqlConnection cnn;
                connetionString = "server=96.125.160.33;database=uptodeal_ZooDatabase;uid=uptodeal_ZooApp;pwd=ZooAppPass@;";
                cnn             = new MySqlConnection(connetionString);
                try
                {
                    MySqlCommand    command;
                    MySqlDataReader mdr;
                    foreach (Animal animal in addedAnimalList)
                    {
                        string selectQuery = "INSERT INTO uptodeal_ZooDatabase.Animal (Class,Species,Status,Name,Gender,LastFeed) VALUES (@class, @species,@status,@name, @gender,@LastFeed)";

                        command = new MySqlCommand(selectQuery, cnn);
                        command.Parameters.Add("@class", MySqlDbType.Text);
                        command.Parameters["@class"].Value = animal.AnimalClass.ToString();

                        command.Parameters.Add("@species", MySqlDbType.Text);
                        command.Parameters["@species"].Value = animal.Species.ToString();

                        command.Parameters.Add("@status", MySqlDbType.Text);
                        command.Parameters["@status"].Value = animal.Status.ToString();

                        command.Parameters.Add("@name", MySqlDbType.Text);
                        command.Parameters["@name"].Value = animal.AnimalName.ToString();

                        command.Parameters.Add("@gender", MySqlDbType.Text);
                        command.Parameters["@gender"].Value = animal.Gender.ToString();

                        command.Parameters.Add("@LastFeed", MySqlDbType.Datetime);
                        command.Parameters["@LastFeed"].Value = animal.LastFeed;

                        cnn.Open();
                        mdr = command.ExecuteReader();
                        cnn.Close();
                    }
                    addAnimalGridView.Rows.Clear();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                MessageBox.Show("Added Successfully\t\t");
                // update the initial array list that used for populate animal data in the main view
                // to show the newly added data
                animalList = AnimalHelper.GetAnimalList();
                addedAnimalList.Clear();
            }
            // if no animals added to Queue
            else if (ValidateAddAnimal())
            {
                MessageBox.Show("Please Add Animal First\t\t", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                //If no Animal added to the list before update
                MessageBox.Show("Nothing to ADD\t\t", "Error");
            }
        }