Persistate

The Borrower class

Hide Navigation Pane

The Borrower class

Previous topic Next topic No directory for this topic  

The Borrower class

Previous topic Next topic Topic directory requires JavaScript JavaScript is required for the print function Mail us feedback on this topic!  

using System;
using System.Data;
using Persistate;
 
namespace Library.Model
{
   
   // This Borrower partial class has been generated by Persistate.  Do
   // not modify as the entire file is recreated on each generation.
 
   [System.Diagnostics.DebuggerDisplay("Borrower {NominativeText}")]   
   public partial class Borrower : Person
   {
      private static ObjectClass objClass = null;   // set at start of session
 
      /// <summary> Sets the objClass field for this class. </summary>
      public new static void SetObjectClass() {
         ObjectClass.SetTargetTypeObjectClass(ref objClass);
      }
      /// <summary> Gets the ObjectClass object associated with this object. </summary>
      public override ObjectClass Class {
         get { return objClass; }
      }
      /// <summary> Gets the ObjectClass object associated with this class. </summary>
      public new static ObjectClass ItsObjectClass {
         get { return objClass; }
      }
      /// <summary> Creates a new Borrower with default property values </summary>
      public Borrower() : this(true, true) { 
      }
      /// <exclude />
      /// <summary> Creates a new Borrower with optional default property values </summary>
      public Borrower(bool initScalars, bool initCollections) : base(false, false) {
         InitialiseMembers(initScalars, initCollections);
      }
      /// <exclude />
      /// <summary> Creates a new Borrower with its reference and parent. </summary>
      protected Borrower(Reference thisObj, IReference parentObj) 
         : base(thisObj, parentObj) {}
 
      /// <summary> Gets the class flags for the Borrower class. </summary>
      public override FlagSet ClassFlags {
         get { return new FlagSet(FlagSet.CloneOnMutate |FlagSet.UseCache); }
      }
      /// <exclude />
      /// <summary> Creates a new Borrower from data read from persistent storage. </summary>
      public new static Borrower CreateFromDatabase(Database db, IDataReader dr, Reference thisObj, Persistent parentObj) {
         Borrower obj = new Borrower(thisObj, parentObj);
         obj.FillFromDatabase(db, dr);
         return obj;
      }
      /// <exclude />
      /// <summary> Populates this object from data read from persistent storage. </summary>
      public override void FillFromDatabase(Database db__, IDataReader dr__) {
         base.FillFromDatabase(db__, dr__);
         postalAddress = db__.ReadIReference(dr__, "Borrower_postalAddress");
         telephoneNumber = db__.ReadString(dr__, "Borrower_telephoneNumber");
         homeEmailAddress = db__.ReadString(dr__, "Borrower_homeEmailAddress");
         businessEmailAddress = db__.ReadString(dr__, "Borrower_businessEmailAddress");
         maximumLendCount = db__.ReadInt32(dr__, "Borrower_maximumLendCount");
         baseClassReference = db__.ReadIReference(dr__, "Borrower_parent");
      }
      /// <exclude />
      /// <summary> Populates persistent storage update parameters from this object. </summary>
      public override bool SaveToDatabase(Database db__, Reference id__, object context__) {
         if (!base.SaveToDatabase(db__, baseClassReference, context__))
            return false;
         bool reSave__;
         do {
            db__.SetParameter("id", id__);
            db__.SetParameter("parent", baseClassReference);
            db__.SetParameter("PostalAddress", postalAddress);
            db__.SetParameter("TelephoneNumber", telephoneNumber);
            db__.SetParameter("HomeEmailAddress", homeEmailAddress);
            db__.SetParameter("BusinessEmailAddress", businessEmailAddress);
            db__.SetParameter("MaximumLendCount", maximumLendCount);
            if (!db__.SaveObject(context__, objClass, out reSave__))
               return false;
         } while (reSave__);      // save again if an update conflict on first try was resolved
         return true;
      }
      /// <exclude />
      /// <summary> Creates a new Borrower from a Persistate.Message. </summary>
      public new static Borrower CreateFromMessage(Message message, Reference thisObj, IReference parentObj) {
         Borrower obj = new Borrower(thisObj, parentObj);
         obj.FillFromMessage(message);
         return obj;
      }
      /// <exclude />
      /// <summary> Sets a single member value for a given slot from a message. </summary>
      protected override void SetMemberFromMessage(int slot__, int length__, Message message__) {
         switch (slot__) {
            case 1001: postalAddress = message__.ReadIReference(); break;
            case 1002: telephoneNumber = message__.ReadString(); break;
            case 1003: homeEmailAddress = message__.ReadString(); break;
            case 1004: businessEmailAddress = message__.ReadString(); break;
            case 1005: maximumLendCount = message__.ReadInt32(); break;
            case 1000: baseClassReference = message__.ReadIReference(); break;
            default: base.SetMemberFromMessage(slot__, length__, message__); break;
         }
      }
      /// <exclude />
      /// <summary> Populates a Persistate.Message from this object. </summary>
      protected override void SaveToMessage(Message message__, bool topLevel__) {
         base.SaveToMessage(message__, false);
         message__.Append(1001, postalAddress);
         message__.Append(1002, telephoneNumber);
         message__.Append(1003, homeEmailAddress);
         message__.Append(1004, businessEmailAddress);
         message__.Append(1005, maximumLendCount);
         message__.Append(1000, baseClassReference);
         if (topLevel__)
            message__.Append(-1);
      }
      /// <exclude />
      /// <summary> Initialises members of a Borrower object to default values. </summary>
      public override void InitialiseMembers(bool initScalars__, bool initCollections__) {
         base.InitialiseMembers(initScalars__, initCollections__);
         if (initScalars__) {
            PostalAddress = new PostalAddress();
            telephoneNumber = String.Empty;
            homeEmailAddress = String.Empty;
            businessEmailAddress = String.Empty;
         }
         if (initCollections__) {
            lentStockCopies = StockCopy.Collection(this, LentStockCopiesFlagSet, 1006, false);
         }
      }
      /// <exclude />
      /// <summary> Removes this Borrower and all objects under it from persistent storage. </summary>
      public override void DePersist() {
         if (PostalAddress != null)
            PostalAddress.DePersist();
         foreach (StockCopy obj in LentStockCopies)
            obj.DePersistFrom(LentStockCopies);
         base.DePersist();
      }
      /// <exclude />
      /// <summary> calls a method for every node in the persistent tree under this object. </summary>
      public override bool CallTree(CallTreeData callTreeData__, int slot__) {
         if (callTreeData__.RootFirst && !base.CallTree(callTreeData__, slot__))
            return false;
         if (PostalAddress != null)
            PostalAddress.CallTree(callTreeData__, 1001);
         callTreeData__.TreeCallAssociated(LentStockCopies, this, 1006, callTreeData__);
         if (!callTreeData__.RootFirst)
            base.CallTree(callTreeData__, slot__);
         return true;
      }
      /// <summary> Gets the value of the member property with a particular slot number. </summary>
      /// <param name="slot__"> The member slot number. </param>
      /// <returns> An object containing the value of the member with the given slot. </returns>
      public override object GetMemberValue(int slot__) {
         switch (slot__) {
            case 1001: return PostalAddress;
            case 1002: return TelephoneNumber;
            case 1003: return HomeEmailAddress;
            case 1004: return BusinessEmailAddress;
            case 1005: return MaximumLendCount;
            case 1006: return LentStockCopies;
            case 1007: return OverdueCounts;
            default: return base.GetMemberValue(slot__);
         }
      }
      /// <summary> Sets the value of the member property with a particularn slot number. </summary>
      /// <param name="slot__"> The member slot number. </param>
      /// <param name="value__"> The new value to set into the member with the given slot. </param>
      public override void SetMemberValue(int slot__, object value__) {
         switch (slot__) {
            case 1001: PostalAddress = (PostalAddress)value__; break;
            case 1002: TelephoneNumber = ValueOf<String>(value__); break;
            case 1003: HomeEmailAddress = ValueOf<String>(value__); break;
            case 1004: BusinessEmailAddress = ValueOf<String>(value__); break;
            case 1005: MaximumLendCount = ValueOf<Int32>(value__); break;
            default: base.SetMemberValue(slot__, value__); break;
         }
      }
      /// <summary> Gets the value of the field backing the member with a particular slot number. </summary>
      /// <param name="slot__"> The member slot number. </param>
      /// <returns> An object containing the value of the field with the given slot. </returns>
      public override object GetFieldValue(int slot__) {
         switch (slot__) {
            case 1001: return postalAddress;
            case 1002: return telephoneNumber;
            case 1003: return homeEmailAddress;
            case 1004: return businessEmailAddress;
            case 1005: return maximumLendCount;
            case 1006: return lentStockCopies;
            default: return base.GetFieldValue(slot__);
         }
      }
      /// <summary> Sets the value of the field backing the member with a particular slot number. </summary>
      /// <param name="slot__"> The member slot number. </param>
      /// <param name="value__"> The new value to set into the field with the given slot. </param>
      public override void SetFieldValue(int slot__, object value__) {
         switch (slot__) {
            case 1001: postalAddress = (IReference)value__; break;
            case 1002: telephoneNumber = ValueOf<String>(value__); break;
            case 1003: homeEmailAddress = ValueOf<String>(value__); break;
            case 1004: businessEmailAddress = ValueOf<String>(value__); break;
            case 1005: maximumLendCount = ValueOf<Int32>(value__); break;
            default: base.SetFieldValue(slot__, value__); break;
         }
      }
      /// <summary> Creates a Borrower collection to contain transient objects. </summary>
      /// <returns> An empty IndexedList(Borrower) collection. </returns>
      public new static IndexedList<Borrower> Collection() {
         return new IndexedList<Borrower>(ItsObjectClass, null, FlagSet.Associated, 0, false, 0, -1);
      }
      /// <summary> Creates a Borrower collection to contain persistent objects. </summary>
      /// <param name="parent"> The parent object of the collection. </param>
      /// <param name="flags"> A FlagSet containing the collection flags. </param>
      /// <param name="slot"> The slot of its parent member containing the collection. </param>
      /// <param name="getData"> If true, objects belonging in the collection are fetched from persistent storage. </param>
      /// <returns> An IndexedList(Borrower) containing the new collection. </returns>
      public new static IndexedList<Borrower> Collection(Persistent parent, FlagSet flags, int slot, bool getData) {
         return new IndexedList<Borrower>(ItsObjectClass, parent, flags, slot, getData, 0, -1);
      }
      /// <summary> Gets the Parent object as a Library. </summary>
      public Library ParentLibrary {
         get { return Parent as Library; }
      }
      //      Property for postal address
      private IReference postalAddress;
      /// <summary> Property for postal address. </summary> 
      public PostalAddress PostalAddress {
         get {
            if (!(postalAddress is PostalAddress) && postalAddress != null) 
               postalAddress = postalAddress.DeReference(this);
            return (PostalAddress)postalAddress;
         }
         set { Adopt(value, ref postalAddress, 1001); } 
      }
      //      Property for telephone number
      private String telephoneNumber;
      /// <summary> Property for telephone number. </summary> 
      public String TelephoneNumber {
         get { return telephoneNumber; }
         set { SetModified();  telephoneNumber = value;  OnModified(); }
      }
      //      Property for home_ email address
      private String homeEmailAddress;
      /// <summary> Property for home email address. </summary> 
      public String HomeEmailAddress {
         get { return homeEmailAddress; }
         set { SetModified();  homeEmailAddress = value;  OnModified(); }
      }
      //      Property for business_ email address
      private String businessEmailAddress;
      /// <summary> Property for business email address. </summary> 
      public String BusinessEmailAddress {
         get { return businessEmailAddress; }
         set { SetModified();  businessEmailAddress = value;  OnModified(); }
      }
      //      Property for maximum lend count
      private Int32 maximumLendCount;
      /// <summary> Property for maximum lend count. </summary> 
      public Int32 MaximumLendCount {
         get { return maximumLendCount; }
         set { SetModified();  maximumLendCount = value;  OnModified(); }
      }
      //      Property for lent_ stock copies
      private IndexedList<StockCopy> lentStockCopies = null;
      private static readonly FlagSet LentStockCopiesFlagSet = FlagSet.Associated |FlagSet.MultipleObject |FlagSet.UseLinkTable;
      /// <summary> Property for lent stock copies. </summary> 
      public IndexedList<StockCopy> LentStockCopies {
         get {
            if (lentStockCopies == null) 
               lentStockCopies = StockCopy.Collection(this, LentStockCopiesFlagSet, 1006, true);
            return lentStockCopies;
         }
      }
      /// <summary> Gets the number of items in the LentStockCopies collection. </summary>
      public int LentStockCopiesCount {
         get { return LentStockCopies.Count; }
      }
      //      Property for overdue counts
      private SessionSpecific<IndexedList<OverdueCount>> overdueCounts;
      private static readonly FlagSet OverdueCountsFlagSet = FlagSet.MultipleObject;
      /// <summary> Property for overdue counts. </summary> 
      public IndexedList<OverdueCount> OverdueCounts {
         get {
            IndexedList<OverdueCount> collection = overdueCounts.Value;
            if (collection == null) {
               collection = OverdueCount.Collection(this, OverdueCountsFlagSet, 1007, false);
               overdueCounts.Value = collection;
            }
            return collection;
         }
      }
      /// <summary> Retrieves selected objects into the OverdueCounts collection. </summary>
      /// <param name="now"> The value for the now parameter. </param>
      /// <returns>  The OverdueCounts collection, now containing the selected objects. </returns>
      public IndexedList<OverdueCount> SelectOverdueCounts(DateTime now) {
         IndexedList<OverdueCount> collection = OverdueCounts;
         collection.Clear();
         GetSelected(collection, OverdueCount.ItsObjectClass, now, this);
         return collection;
      }
      //      Reference to base class data (internal use)
      private Reference baseClassReference;
      /// <exclude />
      /// <summary> Gets or sets the reference to base class data. </summary>
      public new static Reference BaseClassReference(Persistent obj, Reference value) {
         Borrower castObj = (Borrower)obj;
         if (value != Reference.Empty) castObj.baseClassReference = value;
         return castObj.baseClassReference;
      }
      /// <summary> Returns property value for given key number. </summary>
      /// <param name="keyNum__"> The key number to use. </param>
      /// <returns> an object containing the value of the property indicated by the given key.  </returns>
      public override object GetKey(int keyNum__) {
         switch (keyNum__) {
            default: return base.GetKey(keyNum__);
         }
      }
      /// <summary> Gets a string containing values of nominative properties. </summary>
      public override string NominativeText {
         get { return Utl.Join(AnnotationSeparator, base.NominativeText); }
      }
      /// <summary> Gets a string containing values of discriminative properties. </summary>
      public override string DiscriminativeText {
         get { return Utl.Join(AnnotationSeparator, base.DiscriminativeText, PostalAddress.DiscriminativeText); }
      }
   }
 
}