/// <summary> /// Updates an existing animal data source. Animals in the passed animal list but /// not in the datasource are added to the data source. Animal in the list and in /// the data source are updated. /// </summary> /// <param name="Animals"> /// The animal list containing the animals to be added and updated. /// </param> /// <param name="BG">The background that the animals occupy.</param> public void UpdateAnimalData(cAnimalList Animals, cBackground BG) { if (Animals == null) { ThrowAnimalsException(); } if (BG == null) { ThrowBGException(); } // throw an exception if data source is read only if (this.ReadOnly) { ThrowReadOnlyException(); } // create a cAnimalAttributes object cAnimalAttributes Attributes = new cAnimalAttributes(); // write the time stamp this.WriteTime(BG.Years.CurrentYearNum, BG.Years.CurrentYear.CurrentWeek, BG.HaveRunWeeklyEvents); // loop through all foxes, writing each one to the datasource for (int i = 0; i < Animals.Count; i++) { Animals[i].GetAttributes(Attributes); Attributes.ListIndex = i; this.WriteAnimalRecord(Attributes, true); // write markers if the version is correct if (GetVersion() > 1) { this.WriteMarkers(Attributes, true); } } }
/// <summary> /// Writes the animals in the passed animal list into the data source. This /// method overwrites any data that is already in the data source. /// </summary> /// <param name="Animals"> /// The list of animals to be written into the datasource. /// </param> /// <param name="BG">The background that the animals occupy.</param> public void WriteAnimalData(cAnimalList Animals, cBackground BG) { //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData()"); if (Animals == null) { ThrowAnimalsException(); } //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 01"); if (BG == null) { ThrowBGException(); } //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 02"); // throw an exception if data source is read only if (this.ReadOnly) { ThrowReadOnlyException(); } //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 03"); // erase the existing contents of this datasource this.Clear(); //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 04"); // write the time stamp this.WriteTime(BG.Years.CurrentYearNum, BG.Years.CurrentYear.CurrentWeek, BG.HaveRunWeeklyEvents); //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 05"); // create a cAnimalAttributes object cAnimalAttributes Attributes = new cAnimalAttributes(); //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 06"); // loop through all foxes, writing each one to the datasource for (int i = 0; i < Animals.Count; i++) { //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() i = " + i); //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 06 i = " + i); Animals[i].GetAttributes(Attributes); //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 06 b"); Attributes.ListIndex = i; //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 06 c"); this.WriteAnimalRecord(Attributes, false); //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 06 d"); // write markers if the version is correct if (GetVersion() > 1) { this.WriteMarkers(Attributes, false); } } //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 07"); // lastly, reset the datasource so that subsequent reads are correct this.Reset(); }
/// <summary> /// Read animal data from the data source and fill the passed animal list. /// </summary> /// <param name="Animals"> /// The animal list to fill. The animals are added to any that are already in /// the list. /// </param> /// <param name="BG">The background that these animals will occupy.</param> public void GetAnimalData(cAnimalList Animals, cBackground BG) { cAnimal AnimalObj; if (Animals == null) { ThrowAnimalsException(); } if (BG == null) { ThrowBackgroundException(); } // go to the beginning of the list this.Reset(); // get subtraction factor for year of birth // this.ReadTimeRecord(ref DataYear, ref DataWeek); cAnimalAttributes NewAnimal = new cAnimalAttributes(); // loop through all animals in the list while (this.GetNextAnimalRecord(NewAnimal, BG)) { // create the new animal AnimalObj = GetNewAnimal(NewAnimal, BG); AnimalObj.ListIndex = NewAnimal.ListIndex; // read markers for this animal if datasource is of appropriate version // number if (GetVersion() > 1) { ReadMarkers(NewAnimal); AnimalObj.AutoMarker = NewAnimal.AutoMarker; AnimalObj.Marker = NewAnimal.Marker; } // add the animal to the list Animals.Add(AnimalObj); // create a new animal attributes object so that we don't load the // same data into all animals NewAnimal = new cAnimalAttributes(); // advance to the next record in the dataset this.MoveToNextRecord(); } // now reorder the list based on current list index Animals.ReorderByListIndex(); }
/// <summary> /// Read markers for a single animal record from the database. /// </summary> /// <param name="Data"> /// The animal attributes object that will contain the marker data /// </param> protected abstract void ReadMarkers(cAnimalAttributes Data);
/// <summary> /// Write markers for a single animal record into the database. /// </summary> /// <param name="Data"> /// The animal attributes object containing the data to be written. /// </param> /// <param name="DeleteFirst"> /// A flag indicating whether or not an existing record with the same ID should /// be deleted before the current data is written. /// </param> protected abstract void WriteMarkers(cAnimalAttributes Data, bool DeleteFirst);
/// <summary> /// Write a single animal record into the database. /// </summary> /// <param name="Data"> /// The animal attributes object containing the data to be written. /// </param> /// <param name="DeleteFirst"> /// A flag indicating whether or not an existing record with the same ID should /// be deleted before the current data is written. /// </param> protected abstract void WriteAnimalRecord(cAnimalAttributes Data, bool DeleteFirst);
/// <summary> /// Retrieves a single Animal record from the data source and places it in the /// passed Animal data object. /// </summary> /// <param name="Data"> /// The Animal data object that will contain the Animal data. /// </param> /// <returns> /// True if the retrieval was successful, False if there are no more records to /// retrieve. /// </returns> protected abstract bool GetNextAnimalRecord(cAnimalAttributes Data, cBackground Background);
/// <summary> /// Create a new specific animal type /// </summary> /// <param name="Animal">The animal attributes used to define the animal.</param> /// <param name="BG">The background in which the animal will live.</param> /// <returns>The new animal as a cAnimal type.</returns> protected abstract cAnimal GetNewAnimal(cAnimalAttributes NewAnimal, cBackground BG);