public bool CreateSpecies(BirdSpecies item) { bool result = false; try { using (RCID_DWHEntities context = new RCID_DWHEntities()) { short newid = context.Bird_Species.OrderByDescending(u => u.SpeciesID).FirstOrDefault().SpeciesID; newid++; Bird_Species efItem = new Bird_Species() { SpeciesID = newid, SpeciesActive = true, SpeciesName = item.SpeciesName }; context.Bird_Species.Add(efItem); if (context.SaveChanges() > 0) { result = true; } } } catch (Exception e) { throw e; } return(result); }
public static Bird CreateBird(BirdSpecies Species) { Bird animalObj = null;//Birdtype unknown at this time. //Lets determine users choice of animal. switch (Species) { case BirdSpecies.Crow: animalObj = new Crow(); break; case BirdSpecies.Eagle: animalObj = new Eagle(); break; case BirdSpecies.Penguin: animalObj = new Penguin(); break; default: Debug.Assert(false, "Not implemented"); break; } //Set animal category animalObj.Category = CategoryType.Bird; return animalObj;//Return created instance of object. }
public bool InactivateSpecies(BirdSpecies item) { bool result = false; try { using (RCID_DWHEntities context = new RCID_DWHEntities()) { Bird_Species efItem = context.Bird_Species.Where(b => b.SpeciesID == item.SpeciesID).FirstOrDefault(); if (efItem == null) { return(result); } efItem.SpeciesActive = false; if (context.SaveChanges() > 0) { result = true; } } } catch (Exception) { } return(result); }
public static Birds CreateBird(BirdSpecies Species) { Birds animalObj = null; //type not known at this time //type determined by late binding switch (Species) { case BirdSpecies.Ostrich: animalObj = new Ostrich(); //Late binding break; //Continue with the rest case BirdSpecies.Parrot: animalObj = new Parrot(); //Late binding break; default: Debug.Assert(false, "To be completed!"); break; } //set the category animalObj.Category = CategoryType.Bird; return animalObj; //return the created animal Object }
private Animal castAnimal(int speciesIndex, CategoryType type) { //Checking which object to create: if (type == CategoryType.Bird) { BirdSpecies speciestype = (BirdSpecies)speciesIndex; animalis = BirdFactory.CreateBird(speciestype); } else if (type == CategoryType.Insect) { InsectSpecies insectSpec = (InsectSpecies)speciesIndex; animalis = InsectFactory.CreateInsect(insectSpec); } else if (type == CategoryType.Mammal) { MammalSpecies mammalSpec = (MammalSpecies)speciesIndex; animalis = MammalFactory.CreateMammal(mammalSpec); } else if (type == CategoryType.Marine) { MarineSpecies marineSpec = (MarineSpecies)speciesIndex; animalis = MarineFactory.CreateMarine(marineSpec); } else if (type == CategoryType.Reptile) { ReptileSpecies reptileSpec = (ReptileSpecies)speciesIndex; animalis = ReptileFactory.CreateReptile(reptileSpec); } return(animalis); }
public Animal Createbird(BirdSpecies birdSpecies) { Bird animalObj = null; switch (birdSpecies) { case BirdSpecies.Dove: animalObj = new Dove(); break; case BirdSpecies.Eagle: animalObj = new Eagle(); break; case BirdSpecies.Pelican: animalObj = new Pelican(); break; default: Debug.Assert(false, "To be completed!"); break; } animalObj.CategoryType = CategoryType.Bird; return(animalObj); //return the created animal object. }
public static Bird CreateBird(BirdSpecies Species) { Bird animalObj = null;//Birdtype unknown at this time. //Lets determine users choice of animal. switch (Species) { case BirdSpecies.Crow: animalObj = new Crow(); break; case BirdSpecies.Eagle: animalObj = new Eagle(); break; case BirdSpecies.Penguin: animalObj = new Penguin(); break; default: Debug.Assert(false, "Not implemented"); break; } //Set animal category animalObj.Category = CategoryType.Bird; return(animalObj);//Return created instance of object. }
public static Bird CreateBird(BirdSpecies species) { Bird animalObject = null; try { switch (species) { case BirdSpecies.Falcon: animalObject = new Falcon(); break; case BirdSpecies.Parrot: animalObject = new Parrot(); break; default: Debug.Assert(false, "Not implemented yet"); break; } } catch (Exception ex) { ex.Message.ToString(); } finally { animalObject.Category = Category.Bird; } return(animalObject); }
// Adds an animal to the list in AnimalManager(via ListManager). private void addAnimal(object sender, EventArgs e) { Animal animalObject; if (listBoxCategories.SelectedItem != null) { if (listBoxAnimalObjects.SelectedItem != null) { CategoryType selectedCategory = getSelectedCategory(); /* Depending on the category selected, an animal object * will be created of type Mammal or Bird, by calling either * the MammalFactory or the BirdFactory. */ switch (selectedCategory) { case CategoryType.Mammal: MammalSpecies mammalSpecie = (MammalSpecies)Enum.Parse(typeof(MammalSpecies), listBoxAnimalObjects.SelectedItem.ToString()); animalObject = MammalFactory.CreateMammal(mammalSpecie); break; case CategoryType.Bird: BirdSpecies birdSpecie = (BirdSpecies)Enum.Parse(typeof(BirdSpecies), listBoxAnimalObjects.SelectedItem.ToString()); animalObject = BirdFactory.CreateBird(birdSpecie); break; default: animalObject = null; break; } // If validation of entered data is successful. (validateInput returns true) if (validateInput(animalObject)) { // Generates a unique id for the animal animalManager.generateUniqueId(animalObject); // Adds the validated animal object to the list in ListManager. animalManager.Add(animalObject); listViewAnimals.Items.Add(createListViewItem(animalObject)); // Informs the user that everything succeeded. MessageBox.Show(animalObject.Name + " has been added to the list!", "Animal has been added successfully", MessageBoxButtons.OK, MessageBoxIcon.Information); // Resets graphical elements to their initial state. initInterface(); unsavedChanges = true; } } // If trying to add an animal with no specific animal selected. else { validationNotSuccessful("Please select an animal to add"); } } // If trying to add an animal with no category selected. else { validationNotSuccessful("Please select a category"); } }
/* Shows attribute(s) for the specific animal selected. * This function gets called when the value of the selected animal in * the listbox changes. */ private void showSpecificAnimalAttributes(object sender, EventArgs e) { if (listBoxAnimalObjects.SelectedItem != null) { labelAnimalAttr.Visible = true; textBoxAnimalAttr.Visible = true; CategoryType category = getSelectedCategory(); switch (category) { case CategoryType.Bird: BirdSpecies bird = (BirdSpecies)Enum.Parse(typeof(BirdSpecies), listBoxAnimalObjects.SelectedItem.ToString()); switch (bird) { case BirdSpecies.Crow: labelAnimalAttr.Text = "Weight(kg): "; break; case BirdSpecies.Eagle: labelAnimalAttr.Text = "Wing spread(cm): "; break; case BirdSpecies.Vulture: labelAnimalAttr.Text = "Neck color: "; break; } break; case CategoryType.Mammal: MammalSpecies mammal = (MammalSpecies)Enum.Parse(typeof(MammalSpecies), listBoxAnimalObjects.SelectedItem.ToString()); switch (mammal) { case MammalSpecies.Cat: labelAnimalAttr.Text = "Whisker length(cm): "; break; case MammalSpecies.Dog: labelAnimalAttr.Text = "Breed: "; break; case MammalSpecies.Lion: labelAnimalAttr.Text = "Tail length(cm): "; break; } break; } } }
public static Bird CreateBird(BirdSpecies category, GenderType gender, string name, int age, int wingLength) { switch (category) { case BirdSpecies.Eagle: Eagle eggy = new Eagle(gender, name, age, wingLength); return(eggy); case BirdSpecies.Duck: Duck ducky = new Duck(gender, name, age, wingLength); return(ducky); default: return(null); } }
public static Bird CreateBird(BirdSpecies species, int lengthOfBeak, double flyingSpeed) { Bird bird = null; switch (species) { case BirdSpecies.Ostrich: bird = new Ostrich(lengthOfBeak, flyingSpeed); break; case BirdSpecies.Peacock: bird = new Peacock(lengthOfBeak, flyingSpeed); break; } return(bird); }
private Animal CreateBird() { Animal animal = null; int lengthOfBeak = 0; if (!int.TryParse(txt1Species.Text, out lengthOfBeak)) { MessageBox.Show("Please enter a valid value as beak length"); } double flyingSpeed = 0; if (!double.TryParse(txt2Species.Text, out flyingSpeed)) { MessageBox.Show("Please enter a valid value as flying speed"); } BirdSpecies species = (BirdSpecies)Enum.Parse(typeof(BirdSpecies), lstSpecies.Text); animal = BirdFactory.CreateBird(species, lengthOfBeak, flyingSpeed); if (species == BirdSpecies.Ostrich) { int neckLength = 0; if (!int.TryParse(txtBreed.Text, out neckLength)) { MessageBox.Show("Please enter a valid necklength"); } ((Ostrich)animal).LengthOfNeck = neckLength; } else if (species == BirdSpecies.Peacock) { ((Peacock)animal).ColourOfBird = txtBreed.Text; } return(animal); }
public string EditSpecies(BirdSpecies item) { string msg = string.Empty; try { if (ModelState.IsValid) { _birdSvc.UpdateSpecies(item); msg = "Species saved succesfully"; } else { msg = "Data validation not successfull"; } } catch (Exception e) { msg = "Edit Species. An error has ocurred"; } return(msg); }
public string CreateSpecies([Bind(Exclude = "SpeciesID")] BirdSpecies item) { string msg = string.Empty; try { if (ModelState.IsValid) { _birdSvc.CreateSpecies(item); msg = "Species created succesfully"; } else { msg = "Data validation not successfull"; } } catch (Exception e) { msg = "Create Species. An error has ocurred"; } return(msg); }
// Creates and returns a bird object of the selected animal specie public static Bird CreateBird(BirdSpecies birdSpecie) { Animal birdObject; switch (birdSpecie) { case BirdSpecies.Crow: birdObject = new Crow(); break; case BirdSpecies.Eagle: birdObject = new Eagle(); break; case BirdSpecies.Vulture: birdObject = new Vulture(); break; default: birdObject = null; break; } return((Bird)birdObject); }
public string DeleteSpecies(BirdSpecies item) { string msg = string.Empty; if (item == null) { msg = "Nothing to delete"; return(msg); } item.SpeciesActive = false; try { _birdSvc.InactivateSpecies(item); msg = "Species inactivated succesfully"; } catch (Exception e) { msg = "Delete Species. An error has ocurred"; } return(msg); }
public static Bird CreateBird(BirdSpecies species) { //type not known at this time Bird animalObj = null; try { //type determined by late binding switch (species) { case BirdSpecies.Eagle: animalObj = new Eagle();//late binding if (animalObj == null) { NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException(); throw (ex); } break; case BirdSpecies.Falcon: animalObj = new Falcon();//late binding if (animalObj == null) { NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException(); throw (ex); } break; case BirdSpecies.Duck: animalObj = null; if (animalObj == null) { NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException(); throw (ex); } break; default: Debug.Assert(false, "to be completed"); break; } } //custom exception catch (Exception e) { e.Message.ToString(); NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException(); throw (ex); } //set the category animalObj.Category = CategoryType.Bird; return animalObj; }
} // in km/h public Bird(Coordinate coordinate, BirdSpecies species, bool isExtincting, double speed) : base(coordinate) { Species = species; IsExtincting = isExtincting; Speed = speed; }
private Animal SetAnimalType() { Animal newAnimal = new Animal(); var selectedCategori = listBxCategori.SelectedIndex; if (string.IsNullOrEmpty(listbxAnimalSpecies.Text)) { showValidationMessage.ShowNewMessageBox("Du måste välja djurarten från listan!"); return(newAnimal = null); } else { switch (selectedCategori) { case 0: BirdSpecies birdSpecies = (BirdSpecies)Enum.Parse(typeof(BirdSpecies), listbxAnimalSpecies.Text); BirdFactory birdFactory = new BirdFactory(); newAnimal = birdFactory.Createbird(birdSpecies); break; case 1: InsectSpecies insectSpecies = (InsectSpecies)Enum.Parse(typeof(InsectSpecies), listbxAnimalSpecies.Text); InsectFactory insectFactory = new InsectFactory(); newAnimal = insectFactory.CreateInsect(insectSpecies); break; case 2: MammalSpecies mammalSpecies = (MammalSpecies)Enum.Parse(typeof(MammalSpecies), listbxAnimalSpecies.Text); MammalFactory mammalFactory = new MammalFactory(); int daysOfQuarantine; int numberOfteeth; bool underQuarantine = chBoxUnderQuarantine.Checked; if (!helper.CheckInteger(texBoxDaysInQuarantine.Text, out daysOfQuarantine) && underQuarantine == true) { string messageDayOfQuarantine = "You have entered the error value in days of quarantine"; errorDayInQuarantiner.SetError(texBoxDaysInQuarantine, messageDayOfQuarantine); showValidationMessage.ShowNewMessageBox(messageDayOfQuarantine); newAnimal = null; break; } else { errorDayInQuarantiner.Clear(); } if (!int.TryParse(tboxNoOfTeeth.Text, out numberOfteeth)) { errorNoOfTeeth.SetError(tboxNoOfTeeth, "You have entered the error value"); showValidationMessage.TeethException(tboxNoOfTeeth.Text); newAnimal = null; break; } else { errorNoOfTeeth.Clear(); } newAnimal = mammalFactory.CreateMammal(mammalSpecies, daysOfQuarantine, underQuarantine, numberOfteeth); break; case 3: MarineSpecies marineSpecies = (MarineSpecies)Enum.Parse(typeof(MarineSpecies), listbxAnimalSpecies.Text); MarineFactory marineFactory = new MarineFactory(); newAnimal = marineFactory.CreateMarine(marineSpecies); break; case 4: ReptileSpecies reptileSpecies = (ReptileSpecies)Enum.Parse(typeof(ReptileSpecies), listbxAnimalSpecies.Text); ReptileFactory reptileFactory = new ReptileFactory(); newAnimal = reptileFactory.CreateReptile(reptileSpecies); break; } } return(newAnimal); }
public bool InactivateSpecies(BirdSpecies item) { return(_birdRepo.InactivateSpecies(item)); }
public bool CreateSpecies(BirdSpecies item) { return(_birdRepo.CreateSpecies(item)); }
public bool UpdateSpecies(BirdSpecies item) { return(_birdRepo.UpdateSpecies(item)); }
private void button1_Click(object sender, EventArgs e) { // int.TryParse(AgeTbx.Text, out int age); // convert Agebox Context to int, and name it age. if (string.IsNullOrEmpty(NameTbx.Text)) { MessageBox.Show("Name should not be empty!, Please write the name of your animal", "Wrong input!", MessageBoxButtons.OK, MessageBoxIcon.Error // for Warning //MessageBoxIcon.Error // for Error //MessageBoxIcon.Information // for Information //MessageBoxIcon.Question // for Question ); } else if (string.IsNullOrEmpty(AgeTbx.Text)) { MessageBox.Show("Age should not be empty!, Please write the Age of your animal", "Wrong input!", MessageBoxButtons.OK, MessageBoxIcon.Error // for Warning //MessageBoxIcon.Error // for Error //MessageBoxIcon.Information // for Information //MessageBoxIcon.Question // for Question ); } else if (GenderLbx.SelectedIndex < 0) { MessageBox.Show("Please select a gender for your animal", "Wrong input!", MessageBoxButtons.OK, MessageBoxIcon.Error // for Warning //MessageBoxIcon.Error // for Error //MessageBoxIcon.Information // for Information //MessageBoxIcon.Question // for Question ); } else if (CategoryLbx.SelectedIndex < 0) { MessageBox.Show("Please select an animal category for your animal", "Wrong input!", MessageBoxButtons.OK, MessageBoxIcon.Error // for Warning //MessageBoxIcon.Error // for Error //MessageBoxIcon.Information // for Information //MessageBoxIcon.Question // for Question ); } else if (AnimalLbx.SelectedIndex < 0) { MessageBox.Show("Please select an Animal", "Wrong input!", MessageBoxButtons.OK, MessageBoxIcon.Error // for Warning //MessageBoxIcon.Error // for Error //MessageBoxIcon.Information // for Information //MessageBoxIcon.Question // for Question ); } // (string.IsNullOrEmpty(AgeTbx.Text)) //if (title == "User greeting" || title == "User name") { do stuff}; else if (string.IsNullOrEmpty(SpcTbx.Text)) { MessageBox.Show("Please select an Animal Specification", "Wrong input!", MessageBoxButtons.OK, MessageBoxIcon.Error // for Warning //MessageBoxIcon.Error // for Error //MessageBoxIcon.Information // for Information //MessageBoxIcon.Question // for Question ); } else if (!int.TryParse(AgeTbx.Text, out int age)) // { MessageBox.Show("Age should contain only numbers", "Wrong input!", MessageBoxButtons.OK, MessageBoxIcon.Warning // for Warning //MessageBoxIcon.Error // for Error //MessageBoxIcon.Information // for Information //MessageBoxIcon.Question // for Question ); } else if (!int.TryParse(SpcTbx.Text, out int isNumber2)) { MessageBox.Show("Animal Specification should contain only numbers", "Wrong input!", MessageBoxButtons.OK, MessageBoxIcon.Warning // for Warning //MessageBoxIcon.Error // for Error //MessageBoxIcon.Information // for Information //MessageBoxIcon.Question // for Question ); } else { //int.TryParse(AgeTbx.Text, out int age); // convert Agebox Context to int, and name it age. string nameOfAnimal = this.NameTbx.Text; // convert Namebox context to string and name it nameOfAnimal; GenderType gender = (GenderType)this.GenderLbx.SelectedIndex; int id = this.CategoryLbx.SelectedIndex; // choose the classes under the selected index in category list box. switch (id) { case (int)AnimalCategory.Mammal: // when mammal int.TryParse(SpcTbx.Text, out int teeth); // convert T1 Context to int, and name it teeth. MammalSpecies species = (MammalSpecies)AnimalLbx.SelectedIndex; //we cast the index of animal list box to mammel species. Mammal mammal = MammalFactory.CreateMammal(species, gender, nameOfAnimal, age, teeth); //Create obj Mammal am.AddAnimal(mammal); //Add Animal mammal to our list(Animal Manager). break; case (int)AnimalCategory.Bird: //when bird int.TryParse(SpcTbx.Text, out int wing); // convert T2 Context to int, and name it wing. BirdSpecies species2 = (BirdSpecies)this.AnimalLbx.SelectedIndex; //we cast the index of animal list box to bird species. Bird bird = BirdFactory.CreateBird(species2, gender, nameOfAnimal, age, wing); //Create obj Bird am.AddAnimal(bird); break; } UpdateListbox(); } }
public static Bird CreateBird(BirdSpecies species) { //type not known at this time Bird animalObj = null; try { //type determined by late binding switch (species) { case BirdSpecies.Eagle: animalObj = new Eagle(); //late binding if (animalObj == null) { NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException(); throw (ex); } break; case BirdSpecies.Falcon: animalObj = new Falcon(); //late binding if (animalObj == null) { NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException(); throw (ex); } break; case BirdSpecies.Duck: animalObj = null; if (animalObj == null) { NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException(); throw (ex); } break; default: Debug.Assert(false, "to be completed"); break; } } //custom exception catch (Exception e) { e.Message.ToString(); NonExistentAnimalTypeException ex = new NonExistentAnimalTypeException(); throw (ex); } //set the category animalObj.Category = CategoryType.Bird; return(animalObj); }