//Method for the event to go to a specific form if a farmer that exists is selected private void NavResumeOrFarmView(Farmer CurrentFarmer) { if (CurrentFarmer.GetFarmSize() > 0) { if (CurrentFarmer.numOfAnimals() > 0) { Farm_View form = new Farm_View(CurrentFarmer.ID); this.Hide(); form.ShowDialog(); this.Close(); } else { Animal_Selection form = new Animal_Selection(CurrentFarmer.ID, CurrentFarmer.GetFarmSize()); this.Hide(); form.ShowDialog(); this.Close(); } } else { Farm_Creation form = new Farm_Creation(CurrentFarmer.ID); this.Hide(); form.ShowDialog(); this.Close(); } }
private void pbxCreate_Click(object sender, EventArgs e) { name = txtFarmName.Text; if (size == 0) { MessageBox.Show("Please Select a Farm Size"); } else if (txtFarmName.ForeColor.Name == "GrayText" || txtFarmName.ForeColor.Name == "Gray" || name == "") { MessageBox.Show("Please enter a Farm Name"); } else { Farm f = new Farm(name, size); // f.insertFarm(); MessageObject FarmToInsert = new MessageObject(); FarmToInsert.Data = f.BinarySerialization(); FarmToInsert.FormIdentifier = 3; FarmToInsert.ObjectIdentifier = 2; FarmToInsert.ActionIdentifier = 2; Client.SendData(FarmToInsert); Animal_Selection form = new Animal_Selection(farmer.ID, (int)size); this.Hide(); form.ShowDialog(); this.Close(); } }
//goes back to animal Selection private void pbxBack_Click(object sender, EventArgs e) { Animal_Selection form = new Animal_Selection(animalsSelected, animalSpecies, farmerID); this.Hide(); form.ShowDialog(); this.Close(); }
// 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!"); } }