/// <summary> /// Creates an animal. /// </summary> /// <param name="chipRegistrationNumber">The chipnumber of the animal. /// Must be unique. Must be zero or greater than zero.</param> /// <param name="dateOfBirth">The date of birth of the animal.</param> /// <param name="name">The name of the animal.</param> public Animal(int chipRegistrationNumber, SimpleDate dateOfBirth, string name) { ChipRegistrationNumber = chipRegistrationNumber; DateOfBirth = dateOfBirth; Name = name; IsReserved = false; }
/// <summary> /// Creates a cat. /// </summary> /// <param name="chipRegistrationNumber">A five digit number containing the chip registration /// number of the animal. If the given number contains less than 5 digits, then it will be /// stuffed with zero's from the left. So "5" becomes "00005". If the given number contains /// more than 5 digits, then the number is truncated after the 5th position. So "1234567" /// becomes "12345"</param> /// <param name="dateOfBirth">The date of birth of the animal or null if unknown</param> /// <param name="name">The name of the animal or null if unknown</param> /// <param name="badHabits">The nasty habbits of the cat (e.g. "scratches the couch") /// or null if none.</param> public Cat(string chipRegistrationNumber, SimpleDate dateOfBirth, string name, string badHabits) : base(chipRegistrationNumber, dateOfBirth, name) { BadHabits = badHabits; price = 60 - BadHabits.Length; }
/// <summary> /// Creates an animal. /// </summary> /// <param name="chipRegistrationNumber"> /// A five digit number containing the chip registration /// number of the animal. If the given number contains less than 5 digits, then it will be /// stuffed with zero's from the left. So "5" becomes "00005". If the given number contains /// more than 5 digits, then the number is truncated after the 5th position. So "1234567" /// becomes "12345" /// </param> /// <param name="dateOfBirth">The date of birth of the animal or null if unknown</param> /// <param name="name">The name of the animal or null if unknown</param> /// <param name="gender">The gender of the animal</param> protected Animal(int chipRegistrationNumber, SimpleDate dateOfBirth, string name, Gender gender) { ChipRegistrationNumber = chipRegistrationNumber; DateOfBirth = dateOfBirth; Name = name; Gender = gender; Reserved = false; }
public Administration() { SimpleDate birth = new SimpleDate(9, 4, 2020); Animal dog = new Dog(3450, birth, "hans", null); Animal cat = new Cat(12, birth, "Peta", null); AddAnimal(dog); AddAnimal(cat); }
/// <summary> /// Get the tumber of days between this objects date and the given date. /// </summary> /// <param name="date">The end date.</param> /// <returns>The number of days between this date and endDate.</returns> /// <exception>gives an exception when date is not a date</exception> public int DaysDifference(SimpleDate date) //enddate { if (!(date is SimpleDate)) { throw new ArgumentException("please fill in a SimpleDate"); } TimeSpan timespan = date.date.Subtract(this.date); return(timespan.Days); }
public Animal(int chipRegistrationNumber, SimpleDate dateOfBirth, string name) { if (chipRegistrationNumber > 0 && dateOfBirth != null && name != "") { ChipRegistrationNumber = chipRegistrationNumber; DateOfBirth = dateOfBirth; Name = name; IsReserved = false; } }
/// <summary> /// Creates a cat. /// </summary> /// <param name="chipRegistrationNumber">The chipnumber of the animal. /// Must be unique. Must be zero or greater than zero.</param> /// <param name="dateOfBirth">The date of birth of the animal.</param> /// <param name="name">The name of the animal.</param> /// <param name="badHabits">The bad habbits of the cat (e.g. "scratches the couch") /// or null if none.</param> public Cat(int chipRegistrationNumber, SimpleDate dateOfBirth, string name, string badHabits, string photo) : base(chipRegistrationNumber, dateOfBirth, name, photo) { // TODO: Modify the constructor. Make sure it initializes all properties of the class. BadHabits = badHabits; if (DateOfBirth == null || Name == null || BadHabits == null || Photo == null) { throw new NullReferenceException("please fill in all arguments"); } }
public TestForm() { InitializeComponent(); SimpleDate birth = new SimpleDate(4, 5, 6); SimpleDate birth2 = new SimpleDate(7, 2, 20); //Dog dog1 = new Dog(1234,) //Dog dog2 = new Dog(); //Dog dog3 = new Dog(); //Cat cat1 = new Cat(); //Cat cat2 = new Cat(); //Cat cat3 = new Cat(); }
/// <summary> /// Creates a dog. /// </summary> /// <param name="chipRegistrationNumber">The chipnumber of the animal. /// Must be unique. Must be zero or greater than zero.</param> /// <param name="dateOfBirth">The date of birth of the animal.</param> /// <param name="name">The name of the animal.</param> /// <param name="lastWalkDate">The date of the last walk with the dog or null if unknown.</param> /// <exception cref="ArgumentNullException"></exception> public Dog(int chipRegistrationNumber, SimpleDate dateOfBirth, string name, SimpleDate lastWalkDate, string photo) : base(chipRegistrationNumber, dateOfBirth, name, photo) { // TODO: Modify the constructor. Make sure it initializes all properties of the class. LastWalkDate = lastWalkDate; if (dateOfBirth == null || name == null || lastWalkDate == null || Photo == null) { throw new NullReferenceException("please fill in all arguments"); } //Photo = photo; }
/// <summary> /// Creates a dog. /// </summary> /// <param name="chipRegistrationNumber">The chipnumber of the animal. /// Must be unique. Must be zero or greater than zero.</param> /// <param name="dateOfBirth">The date of birth of the animal.</param> /// <param name="name">The name of the animal.</param> /// <param name="lastWalkDate">The date of the last walk with the dog or null if unknown.</param> public Dog(int chipRegistrationNumber, SimpleDate dateOfBirth, string name, SimpleDate lwd) : base(chipRegistrationNumber, dateOfBirth, name) { // TODO: Modify the constructor. Make sure it initializes all properties of the class. if (chipRegistrationNumber >= 0 && dateOfBirth != null && name != null && name != "" && lwd != null) { LastWalkDate = lwd; } else { throw new ArgumentException("vul de juiste waardes in!"); } }
/// <summary> /// Creates a cat. /// </summary> /// <param name="chipRegistrationNumber">The chipnumber of the animal. /// Must be unique. Must be zero or greater than zero.</param> /// <param name="dateOfBirth">The date of birth of the animal.</param> /// <param name="name">The name of the animal.</param> /// <param name="badHabits">The bad habbits of the cat (e.g. "scratches the couch") /// or null if none.</param> public Cat(int chipRegistrationNumber, SimpleDate dateOfBirth, string name, string badHabits) : base(chipRegistrationNumber, dateOfBirth, name) { if (string.IsNullOrWhiteSpace(badHabits)) { BadHabits = "No bad habits"; } else { BadHabits = badHabits; } Price = GetPrice(); }
/// <summary> /// Creates an animal. /// </summary> /// <param name="chipRegistrationNumber">The chipnumber of the animal. /// Must be unique. Must be zero or greater than zero.</param> /// <param name="dateOfBirth">The date of birth of the animal.</param> /// <param name="name">The name of the animal.</param> public Animal(int chipRegistrationNumber, SimpleDate dateOfBirth, string name, string photo) { if (name == null || dateOfBirth == null) { throw new NullReferenceException("please fill in all parameters"); } ChipRegistrationNumber = chipRegistrationNumber; DateOfBirth = dateOfBirth; Name = name; IsReserved = false; Photo = photo; }
/// <summary> /// Creates an animal. /// </summary> /// <param name="chipRegistrationNumber">The chipnumber of the animal. /// Must be unique. Must be zero or greater than zero.</param> /// <param name="dateOfBirth">The date of birth of the animal.</param> /// <param name="name">The name of the animal.</param> public Animal(int chipRegistrationNumber, SimpleDate dateOfBirth, string name) { if (chipRegistrationNumber >= 0 && dateOfBirth != null && name != null && name != "") { ChipRegistrationNumber = chipRegistrationNumber; DateOfBirth = dateOfBirth; Name = name; IsReserved = false; } else { throw new ArgumentNullException(); } }
protected Animal(int chipRegistrationNumber, SimpleDate dateOfBirth, string name) { if (chipRegistrationNumber == 0) { throw new ArgumentOutOfRangeException("ChipregistrationNumber moet groter zijn dan 0"); } if (name == null) { throw new ArgumentNullException("name"); } ChipRegistrationNumber = chipRegistrationNumber; DateOfBirth = dateOfBirth; Name = name; IsReserved = false; }
public Dog(int chipRegistrationNumber, SimpleDate dateOfBirth, string name, SimpleDate lastWalkDate) : base(chipRegistrationNumber, dateOfBirth, name) { if (chipRegistrationNumber > 0 && dateOfBirth != null && name != "") { this.LastWalkDate = lastWalkDate; if (ChipRegistrationNumber < 50000) { Price = 200; } else { Price = 350; } } }
public Dog(SerializationInfo info, StreamingContext ctxt) : base(info, ctxt) { SimpleDate lastWalkDate = (SimpleDate)info.GetValue("LastWalkDate", typeof(SimpleDate)); if (lastWalkDate != null) { if (SimpleDate.Compare(lastWalkDate, base.DateOfBirth) >= 0 && SimpleDate.Compare(lastWalkDate, new SimpleDate(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year)) < 0) { throw new ArgumentException("The dog's lastwalkdate is before birthday or after today."); } LastWalkDate = lastWalkDate; } }
public Animal(SerializationInfo info, StreamingContext ctxt) { int chipnumber = (int)info.GetValue("ChipRegistrationNumber", typeof(int)); string name = (string)info.GetValue("Name", typeof(string)); SimpleDate dateofbirth = (SimpleDate)info.GetValue("BirthDate", typeof(SimpleDate)); bool isreserved = (bool)info.GetValue("Reserved", typeof(bool)); if (chipnumber < 0 && string.IsNullOrWhiteSpace(name) && dateofbirth == null) { throw new ArgumentException("One or more parameters are incorrect, aborting import."); } ChipRegistrationNumber = chipnumber; Name = name; DateOfBirth = dateofbirth; IsReserved = isreserved; }
/// <summary> /// this method creates 3 animals, with a random date of birth and last date walked /// </summary> private void StartAnimal() { Random random = new Random(); SimpleDate simpleDate = new SimpleDate(random.Next(1, 28), random.Next(1, 12), random.Next(1990, 1999)); SimpleDate simpleDate2 = new SimpleDate(random.Next(1, 28), random.Next(1, 12), random.Next(1999, 2005)); SimpleDate simpleDate3 = new SimpleDate(random.Next(1, 28), random.Next(1, 12), random.Next(2005, 2014)); Cat cat = new Cat(random.Next(0, 20000), simpleDate2, "Dave", "", ""); AddAnimal(cat); Dog dog = new Dog(random.Next(0, 20000), simpleDate, "Geisha", simpleDate2, ""); AddAnimal(dog); Cat cat2 = new Cat(random.Next(0, 20000), simpleDate3, "Smokey", "Scratching", ""); AddAnimal(cat2); }
/// <summary> /// Creates a dog. /// </summary> /// <param name="chipRegistrationNumber">The chipnumber of the animal. /// Must be unique. Must be zero or greater than zero.</param> /// <param name="dateOfBirth">The date of birth of the animal.</param> /// <param name="name">The name of the animal.</param> /// <param name="lastWalkDate">The date of the last walk with the dog or null if unknown.</param> public Dog(int chipRegistrationNumber, SimpleDate dateOfBirth, string name, SimpleDate lastWalkDate) : base(chipRegistrationNumber, dateOfBirth, name) { if (lastWalkDate != null) { if (SimpleDate.Compare(lastWalkDate, dateOfBirth) < 0 && SimpleDate.Compare(lastWalkDate, new SimpleDate(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year)) >= 0) { LastWalkDate = lastWalkDate; } else { throw new ArgumentException("The dog's lastwalkdate is before birthday or after today."); } } }
/// <summary> /// Create an Animal object and store it in the administration. /// If "Dog" is selected in the animalTypeCombobox then a Dog object should be created. /// If "Cat" is selected in the animalTypeCombobox then a Cat object should be created. /// </summary> private void createAnimalButton_Click(object sender, EventArgs e) { int registrationNumber = Convert.ToInt32(tbChipRegistrationNumber.Text); var dateOfBirth = new SimpleDate(dtpBirthday.Value); string name = tbName.Text; Animal a; if (animalTypeComboBox.Text == "Dog") { a = new Dog(registrationNumber, dateOfBirth, name, new SimpleDate(dtpLastWalked.Value), (Gender)ddbGender.SelectedIndex); } else { a = new Cat(registrationNumber, dateOfBirth, name, tbBadHabits.Text, (Gender)ddbGender.SelectedIndex); } AddAnimal(a); }
/// <summary> /// Creates an animal. /// </summary> /// <param name="chipRegistrationNumber">A five digit number containing the chip registration /// number of the animal. If the given number contains less than 5 digits, then it will be /// stuffed with zero's from the left. So "5" becomes "00005". If the given number contains /// more than 5 digits, then the number is truncated after the 5th position. So "1234567" /// becomes "12345"</param> /// <param name="dateOfBirth">The date of birth of the animal or null if unknown</param> /// <param name="name">The name of the animal or null if unknown</param> public Animal(string chipRegistrationNumber, SimpleDate dateOfBirth, string name) { if (chipRegistrationNumber.Length < chipRegistrationNumberMaxLength) { this.chipRegistrationNumber = chipRegistrationNumber.PadLeft(chipRegistrationNumberMaxLength, '0'); } else if (chipRegistrationNumber.Length > chipRegistrationNumberMaxLength) { this.chipRegistrationNumber = chipRegistrationNumber.Substring(0, chipRegistrationNumberMaxLength); } else { this.chipRegistrationNumber = chipRegistrationNumber; } this.dateOfBirth = dateOfBirth; this.name = name; isReserved = false; }
public Cat(int chipRegistrationNumber, SimpleDate dateOfBirth, string name, string badHabits) : base(chipRegistrationNumber, dateOfBirth, name) { if (chipRegistrationNumber > 0 && dateOfBirth != null && name != "") { if (badHabits == "") { BadHabits = "none"; } else { BadHabits = badHabits; } int count = badHabits.Length; Price = 60 - (20 * count); if (Price < 20) { Price = 20; } } }
public static int Compare(SimpleDate sd1, SimpleDate sd2) { int result = 0; if (sd1 != null && sd2 != null) { if (sd1.date <= sd2.date) { result = 1; } else if (sd1.date > sd2.date) { result = -1; } } else { throw new NullReferenceException("simpledate was null"); } return(result); }
public void loadPremades() { SimpleDate premadeBirth1 = new SimpleDate(06, 11, 1996); SimpleDate premadeLWD1 = new SimpleDate(22, 09, 2015); SimpleDate premadeBirth2 = new SimpleDate(22, 08, 2002); SimpleDate premadeLWD2 = new SimpleDate(15, 08, 2015); //Dogs administration.Add(new Dog("00001", premadeBirth1, "Piet", premadeLWD1)); administration.Add(new Dog("00002", premadeBirth2, "Jan", premadeLWD1)); administration.Add(new Dog("50003", premadeBirth1, "Bert", premadeLWD2)); administration.Add(new Dog("50004", premadeBirth2, "Kees", premadeLWD2)); //Cats administration.Add(new Cat("00005", premadeBirth1, "Maarten", "Hates children")); administration.Add(new Cat("00006", premadeBirth2, "Arjan", "Attacks virgins")); administration.Add(new Cat("00007", premadeBirth1, "Robin", "Opens your browserhistory")); administration.Add(new Cat("00008", premadeBirth2, "Luigi", "Destroys your furniture")); reloadLists(); }
/// <summary> /// Create an Animal object and store it in the administration. /// If "Dog" is selected in the animalTypeCombobox then a Dog object should be created. /// If "Cat" is selected in the animalTypeCombobox then a Cat object should be created. /// </summary> private void createAnimalButton_Click(object sender, EventArgs e) { string selecteditem = animalTypeComboBox.SelectedItem.ToString(); string chipnr = numChipNr.Value.ToString(); if (chipnr == "") { MessageBox.Show("Voer een chipnummer in!"); return; } string name = txtName.Text; DateTime dateofbirth = dateBirth.Value; SimpleDate simpledateofbirth = new SimpleDate(dateofbirth.Day, dateofbirth.Month, dateofbirth.Year); if (selecteditem == "Cat") { if (administration.Add(new Cat(chipnr, simpledateofbirth, name, txtBadHabits.Text))) { FillLists(); } else { MessageBox.Show("Er bestaat al een dier met dit chipnummer"); } } else if (selecteditem == "Dog") { SimpleDate simpledatelastwalk = new SimpleDate(dateLastWalk.Value.Day, dateLastWalk.Value.Month, dateLastWalk.Value.Year); if (administration.Add(new Dog(chipnr, simpledateofbirth, name, simpledatelastwalk))) { FillLists(); } else { MessageBox.Show("Er bestaat al een dier met dit chipnummer"); } } }
/// <summary> /// Create an Animal object and store it in the administration. /// If "Dog" is selected in the animalTypeCombobox then a Dog object should be created. /// If "Cat" is selected in the animalTypeCombobox then a Cat object should be created. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void createAnimalButton_Click(object sender, EventArgs e) { Animal animal = null; int chipNumber; int.TryParse(chipBox.Text, out chipNumber); SimpleDate birth = new SimpleDate(birthBox.Value.Day, birthBox.Value.Month, birthBox.Value.Year); SimpleDate walk = new SimpleDate(walkBox.Value.Day, walkBox.Value.Month, walkBox.Value.Year); if (animalTypeComboBox.Text == "Dog") { animal = new Dog(chipNumber, birth, nameBox.Text, walk); MessageBox.Show("Dog created"); } if (animalTypeComboBox.Text == "Cat") { animal = new Cat(chipNumber, birth, nameBox.Text, habitsBox.Text); MessageBox.Show("Cat created"); } admin.AddAnimal(animal); animalBox.Items.Add(animal); }
/// <summary> /// Create an Animal object and store it in the administration. /// If "Dog" is selected in the animalTypeCombobox then a Dog object should be created. /// If "Cat" is selected in the animalTypeCombobox then a Cat object should be created. /// </summary> private void createAnimalButton_Click(object sender, EventArgs e) { string selecteditem = animalTypeComboBox.SelectedItem.ToString(); string chipnr = numChipNr.Value.ToString(); if(chipnr == "") { MessageBox.Show("Voer een chipnummer in!"); return; } string name = txtName.Text; DateTime dateofbirth = dateBirth.Value; SimpleDate simpledateofbirth = new SimpleDate(dateofbirth.Day, dateofbirth.Month, dateofbirth.Year); if(selecteditem == "Cat") { if (administration.Add(new Cat(chipnr, simpledateofbirth, name, txtBadHabits.Text))) { FillLists(); } else { MessageBox.Show("Er bestaat al een dier met dit chipnummer"); } } else if(selecteditem == "Dog") { SimpleDate simpledatelastwalk = new SimpleDate(dateLastWalk.Value.Day, dateLastWalk.Value.Month, dateLastWalk.Value.Year); if(administration.Add(new Dog(chipnr, simpledateofbirth, name, simpledatelastwalk))) { FillLists(); } else { MessageBox.Show("Er bestaat al een dier met dit chipnummer"); } } }
/// <summary> /// Create an Animal object and store it in the administration. /// If "Dog" is selected in the animalTypeCombobox then a Dog object should be created. /// If "Cat" is selected in the animalTypeCombobox then a Cat object should be created. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void createAnimalButton_Click(object sender, EventArgs e) { SimpleDate birthday = new SimpleDate(dtBirth.Value.Day, dtBirth.Value.Month, dtBirth.Value.Year); SimpleDate walked = new SimpleDate(DateWalked.Value.Day, DateWalked.Value.Month, DateWalked.Value.Year); if (tbName.Text != null && tbName.Text != "") { if (int.TryParse(tbChip.Text, out number)) { try { AddAnAnimal(birthday, walked); } catch (BornInFutureException borninfuture) { MessageBox.Show(borninfuture.Message); } catch (WalkBeforeBornException walk) { MessageBox.Show(walk.Message); } catch (IndexOutOfRangeException index) { MessageBox.Show(index.Message); } } else { MessageBox.Show("Please fill in a legit Chipregistrationnumber, whitch is positive"); } } else { MessageBox.Show("Please fill in a name"); } }
private void AddAnAnimal(SimpleDate birthday, SimpleDate walked) { if (cbAnimalType.Text == "Dog") { Dog dog = new Dog(number, birthday, tbName.Text, walked, tbPhoto.Text); AddAnimal(dog); UpdateGUI(); } if (cbAnimalType.Text == "Cat") { Cat cat = new Cat(number, birthday, tbName.Text, tbBadHabits.Text, tbPhoto.Text); if (tbBadHabits.Text == "") { badHabits = Microsoft.VisualBasic.Interaction.InputBox ("Are you sure your cat does't have bad habits? If it have bad habbits, you can fill it in here", "Title", "", -1, -1); cat.BadHabits = badHabits; AddAnimal(cat); } AddAnimal(cat); } }
/// <summary> /// Creates an animal. /// </summary> /// <param name="chipRegistrationNumber">The chipnumber of the animal. /// Must be unique. Must be zero or greater than zero.</param> /// <param name="dateOfBirth">The date of birth of the animal.</param> /// <param name="name">The name of the animal.</param> public Animal(int chipRegistrationNumber, SimpleDate dateOfBirth, string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Invalid name"); } if (chipRegistrationNumber <= 0) { throw new ArgumentException("Chipnumber wrong"); } if (dateOfBirth == null || SimpleDate.Compare(dateOfBirth, new SimpleDate(DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year)) <= 0) { throw new ArgumentException("Date of birth is of the wrong type or later than today"); } DateOfBirth = dateOfBirth; Name = name; ChipRegistrationNumber = chipRegistrationNumber; IsReserved = false; }
/// <summary> /// Get the tumber of days between this objects date and the given date. /// </summary> /// <param name="date">The end date.</param> /// <returns>The number of days between this date and endDate.</returns> public int DaysDifference(SimpleDate date) { TimeSpan timespan = date.date.Subtract(this.date); return(timespan.Days); }
/// <summary> /// Create an Animal object and store it in the administration. /// If "Dog" is selected in the animalTypeCombobox then a Dog object should be created. /// If "Cat" is selected in the animalTypeCombobox then a Cat object should be created. /// </summary> private void createAnimalButton_Click(object sender, EventArgs e) { SimpleDate DateOfBirth = new SimpleDate(dtpDateOfBirth.Value.Day, dtpDateOfBirth.Value.Month, dtpDateOfBirth.Value.Year); int chipNumber; bool result = Int32.TryParse(tbChipRegistrationNumber.Text, out chipNumber); if (result) { if (animalTypeComboBox.Text == "Dog") { SimpleDate LastWalkDate = new SimpleDate(dtpLastWalkDate.Value.Day, dtpLastWalkDate.Value.Month, dtpLastWalkDate.Value.Year); bool addControle = administration.Add(new Dog(tbChipRegistrationNumber.Text, DateOfBirth, tbName.Text, LastWalkDate)); if (addControle) { MessageBox.Show("Dog has been added succesfully"); } else { MessageBox.Show("Please use a unique Chipnumber"); } } else if(animalTypeComboBox.Text == "Cat") { bool addControle = administration.Add(new Cat(tbChipRegistrationNumber.Text, DateOfBirth, tbName.Text, tbBadHabits.Text)); if (addControle) { MessageBox.Show("Cat has been added succesfully"); } else { MessageBox.Show("Please use a unique Chipnumber"); } } } reloadLists(); }
/// <summary> /// Create an Animal object and store it in the administration. /// If "Dog" is selected in the animalTypeCombobox then a Dog object should be created. /// If "Cat" is selected in the animalTypeCombobox then a Cat object should be created. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void createAnimalButton_Click(object sender, EventArgs e) { // TODO: See method description int chipNumber = chipNumberCounter(nudChipNumber.Value); if (animalTypeComboBox.Text == "Cat") { SimpleDate simpleDate = new SimpleDate(Convert.ToInt32(nudDayBirthday.Value), Convert.ToInt32(nudMonthBirthday.Value), Convert.ToInt32(nudYearBirthday.Value)); try { if (admin.CheckChipNrIsAvailable(chipNumber)) { Cat cat = new Cat(chipNumber, simpleDate, tbName.Text, tbBadHabits.Text); if (!rbIsReserved.Checked) { admin.Add(cat); lbNotReserved.Items.Add(cat); } if (rbIsReserved.Checked) { cat.IsReserved = true; admin.Add(cat); lbIsReserved.Items.Add(cat); } } else if (!admin.CheckChipNrIsAvailable(chipNumber)) { MessageBox.Show("Toevoegen niet gelukt"); } } catch (ArgumentNullException) { MessageBox.Show("Vul alle waardes in voor cat"); } } else if (animalTypeComboBox.Text == "Dog") { SimpleDate simpleDate = new SimpleDate(Convert.ToInt32(nudDayBirthday.Value), Convert.ToInt32(nudMonthBirthday.Value), Convert.ToInt32(nudYearBirthday.Value)); SimpleDate walkDate = new SimpleDate(Convert.ToInt32(nudWalkDay.Value), Convert.ToInt32(nudWalkMonth.Value), Convert.ToInt32(nudWalkYear.Value)); try { if (admin.CheckChipNrIsAvailable(chipNumber)) { Dog dog = new Dog(chipNumber, simpleDate, tbName.Text, walkDate); if (!rbIsReserved.Checked) { lbNotReserved.Items.Add(dog); admin.Add(dog); } if (rbIsReserved.Checked) { dog.IsReserved = true; admin.Add(dog); lbIsReserved.Items.Add(dog); } } else if (!admin.CheckChipNrIsAvailable(chipNumber)) { MessageBox.Show("Toevoegen niet gelukt"); } } catch (ArgumentNullException) { MessageBox.Show("Vul alle waardes in voor dog"); } } else { MessageBox.Show("Select an Animal!"); } }
public void ReadAnimals(bool local) { if (local) { try { using (FileStream FS = new FileStream("objects.bin", FileMode.Open, FileAccess.Read)) { BinaryFormatter BF = new BinaryFormatter(); animals = (List<Animal>)BF.Deserialize(FS); } } catch (FileNotFoundException FNFE) { Console.WriteLine(FNFE.Message); } } else { using (OracleConnection connection = Database.Connection) { string sqlquery = "SELECT CHIPREGISTRATIONNUMBER, DATEOFBIRTH, NAME, RESERVED, PRICE, LASTWALKDATE, BADHABITS FROM ANIMALS"; OracleCommand OC = new OracleCommand(sqlquery, connection); OracleDataReader ODR = OC.ExecuteReader(); string ChipRegistrationNumber = ""; string Name = ""; string BadHabits = ""; SimpleDate DateOfBirth = null; SimpleDate LastWalkDate = null; bool Reserved = false; decimal Price = 0; //List<Animal> animal = new List<Animal>(); while (ODR.Read()) { ChipRegistrationNumber = ODR["CHIPREGISTRATIONNUMBER"].ToString(); Name = ODR["NAME"].ToString(); BadHabits = ODR["BADHABITS"].ToString(); DateTime DT = DateTime.Parse(ODR["DATEOFBIRTH"].ToString()); DateOfBirth = new SimpleDate(DT.Day, DT.Month, DT.Year); if (ODR["LASTWALKDATE"].ToString() != "") { DT = DateTime.Parse(ODR["LASTWALKDATE"].ToString()); } LastWalkDate = new SimpleDate(DT.Day, DT.Month, DT.Year); Reserved = Convert.ToBoolean(ODR["RESERVED"]); Price = Convert.ToDecimal(ODR["PRICE"]); if (BadHabits != "") { Cat cat = new Cat(ChipRegistrationNumber, DateOfBirth, Name, BadHabits); cat.IsReserved = Reserved; animals.Add(cat); } else { Dog dog = new Dog(ChipRegistrationNumber, DateOfBirth, Name, LastWalkDate); dog.IsReserved = Reserved; animals.Add(dog); } } } } }
//Constructor public Cat(string chipRegistrationNumber, SimpleDate dateOfBirth, string name, string isReserved, string badHabits) : base(chipRegistrationNumber, dateOfBirth, name, isReserved) { BadHabits = badHabits; }
/// <summary> /// Get the number of days between this object's date and the given date. /// </summary> /// <param name="date">The end date.</param> /// <returns>The number of days between this date and endDate.</returns> public int DaysDifference(SimpleDate date) { TimeSpan timespan = date.date.Subtract(this.date); return timespan.Days; }
/// <summary> /// Creates a cat. /// </summary> /// <param name="chipRegistrationNumber">A five digit number containing the chip registration /// number of the animal. If the given number contains less than 5 digits, then it will be /// stuffed with zero's from the left. So "5" becomes "00005". If the given number contains /// more than 5 digits, then the number is truncated after the 5th position. So "1234567" /// becomes "12345"</param> /// <param name="dateOfBirth">The date of birth of the animal or null if unknown</param> /// <param name="name">The name of the animal or null if unknown</param> /// <param name="badHabits">The nasty habbits of the cat (e.g. "scratches the couch") /// or null if none.</param> public Cat(string chipRegistrationNumber, SimpleDate dateOfBirth, string name, string badHabits) : base(chipRegistrationNumber, dateOfBirth, name) { this.BadHabits = badHabits; }
/// <summary> /// Creates a cat. /// </summary> /// <param name="chipRegistrationNumber">A five digit number containing the chip registration /// number of the animal. If the given number contains less than 5 digits, then it will be /// stuffed with zero's from the left. So "5" becomes "00005". If the given number contains /// more than 5 digits, then the number is truncated after the 5th position. So "1234567" /// becomes "12345"</param> /// <param name="dateOfBirth">The date of birth of the animal or null if unknown</param> /// <param name="name">The name of the animal or null if unknown</param> /// <param name="badHabits">The nasty habbits of the cat (e.g. "scratches the couch") /// or null if none.</param> public Cat(string chipRegistrationNumber, SimpleDate dateOfBirth, string name, string badHabits) : base(chipRegistrationNumber, dateOfBirth, name) { BadHabits = badHabits; Price = CalculatePrice(badHabits.Length); }
/// <summary> /// Creates a dog. /// </summary> /// <param name="chipRegistrationNumber">A five digit number containing the chip registration /// number of the animal. If the given number contains less than 5 digits, then it will be /// stuffed with zero's from the left. So "5" becomes "00005". If the given number contains /// more than 5 digits, then the number is truncated after the 5th position. So "1234567" /// becomes "12345"</param> /// <param name="dateOfBirth">The date of birth of the animal or null if unknown</param> /// <param name="name">The name of the animal or null if unknown</param> /// <param name="lastWalkDate">The date of the last walk with the dog or null if unknown.</param> public Dog(string chipRegistrationNumber, SimpleDate dateOfBirth, string name, SimpleDate lastWalkDate) : base(chipRegistrationNumber, dateOfBirth, name) { LastWalkDate = lastWalkDate; }
/// <summary> /// Methode die alle data uit de textboxes haalt en met deze informatie een cat of een dog /// aanmaakt (Dit gebeurd in de button waar deze methode wordt aangeroepen. /// Tevens wordt er gecontroleerd of alles met de juiste waardes is ingevuld. Anders /// wordt er een foutmelding teruggegeven. /// </summary> /// <returns></returns> private bool Textboxes() { if(rbCat.Checked == true) { if(tbName.Text == "") { return false; } name = tbName.Text; if(tbNumber.Text == "") { return false; } chipNumber = tbNumber.Text; birthDay = Convert.ToInt32(nudBirthDay.Text); birthMonth = Convert.ToInt32(nudBirthMonth.Text); birthYear = Convert.ToInt32(nudBirthYear.Text); if (birthDay == 1 && birthMonth == 1 && birthYear == 1950) { return false; } date = new SimpleDate(birthDay, birthMonth, birthYear); if (tbBadHabit.Text == null) { badHabit = ""; } else { badHabit = tbBadHabit.Text; } } else if (rbDog.Checked == true) { if (tbName.Text == "") { return false; } name = tbName.Text; if (tbNumber.Text == "") { return false; } try { chipNumber = tbNumber.Text; } catch { MessageBox.Show("Vul alleen cijfers in!"); } birthDay = Convert.ToInt32(nudBirthDay.Text); birthMonth = Convert.ToInt32(nudBirthMonth.Text); birthYear = Convert.ToInt32(nudBirthYear.Text); if (birthDay == 1 && birthMonth == 1 && birthYear == 1950) { return false; } date = new SimpleDate(birthDay, birthMonth, birthYear); walkDay = Convert.ToInt32(nudDateDay.Text); walkMonth = Convert.ToInt32(nudDateMonth.Text); walkYear = Convert.ToInt32(nudDateYear.Text); if (walkDay == 1 && walkMonth == 1 && walkYear == 1950) { return false; } lastWalk = new SimpleDate(walkDay, walkMonth, walkYear); } return true; }
public void SimpleDateDaysDifference() { //Check if difference between dates is correct. SimpleDate simpleDate2 = new SimpleDate(20, 11, 1996); Assert.AreEqual(14, simpleDate.DaysDifference(simpleDate2)); }
public void Initialize() { simpleDate = new SimpleDate(06, 11, 1996); lastWalk = new SimpleDate(06, 11, 1996); administration = new Administration(); dog = new Dog("12345", simpleDate, "testdog", lastWalk); cat = new Cat("12345", simpleDate, "testcat", "0123456789"); }