Exemple #1
0
        // adds the new species and goes back to animal Selection Screen
        private void pbxAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtChooseimage.Text == null || txtChooseimage.Text == "")
                {
                    throw new NoImageDirectoryException();
                }
                if (File.Exists(Environment.CurrentDirectory + @"\" + txtName.Text + ".png"))
                {
                    pbxNewAnimal.Image.Save(Environment.CurrentDirectory + @"\" + txtName.Text + ".png", ImageFormat.Png);
                }
                if (txtName != null && txtSpace != null && txtSpeed != null && cbxType.SelectedItem.ToString() != null)
                {
                    Species spec = new Species();
                    spec.AnimalName = txtName.Text;
                    spec.Animaltype = cbxType.SelectedItem.ToString();
                    spec.Space      = double.Parse(txtSpace.Text);
                    spec.Speed      = double.Parse(txtSpeed.Text);
                    MessageObject InsertSpecies = new MessageObject();
                    InsertSpecies.Data             = spec.BinarySerialization();
                    InsertSpecies.FormIdentifier   = 5;
                    InsertSpecies.ObjectIdentifier = 4;
                    InsertSpecies.ActionIdentifier = 2;
                    Client.SendData(InsertSpecies);

                    // animalSpecies.Add(spec);
                    //Write the four items to the text file
                    spec.writeSpecies();
                }



                Animal_Selection form = new Animal_Selection(animalsSelected, animalSpecies, farmerID);
                this.Hide();
                form.ShowDialog();
                this.Close();
            }
            catch (NoImageDirectoryException)
            {
                MessageBox.Show("Please ensure a picture is selected, and the URL to that image is loaded!");
            }
            catch (FormatException)
            {
                MessageBox.Show("Please ensure that Speed and Space are both numbers!");
            }
        }