2 Replies - 499 Views - Last Post: 27 September 2013 - 02:43 PM Rate Topic: -----

#1 ScottinTexas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 13-March 12

My Class and A Collection Class

Posted 27 September 2013 - 11:39 AM

I have a class (Instrument, which is another word for a document found in the public records at a courthouse) and a Collection (InstrumentCollection). I would like someone to look at these and see if everything looks right. Then I need to figure out the best way to instantiate each Instrument. The data is in an Access Data Base that I have spent a few years building. As I use it now (VB In Access) I have the data bound to the form and move through the recordset. In my WPF application I want the current instrument in the collection to be bound to the UI controls. So to start with I created the Instrument, then implemented a collection to hold all of the relevant Instruments. I have read a lot of stuff on collections. I designed my class based on the Microsoft tutorial for collections. I want to be able to move to an Instrument by several different methods, but I am not sure how I will go about that until I have live data to work with. For example, one of the ways to access the Instrument is by the Volume and Page and Book where that Instrument is recorded (Vol/Pg Bk). Another way is by File # (00001234).

Question 1 - Are my classes set up correctly?
Question 2 - Is there a better way of doing this?

I assume that App is the best place to connect to the data and select the records that will load each Instrument and add it to the collection. What I face with that problem is that the data is stored with keys to counties and states so that has to be selected before creating objects.

There are my thoughts. I look forward to yours.

//Instrument.cs
//This represents one document.

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Media;
using System.Windows.Input;
using System.ComponentModel;

namespace GlobalPlant
{
	internal class Instrument:INotifyPropertyChanged
	{
        private bool isChanged;
		public event PropertyChangedEventHandler PropertyChanged;

		private void onpropertychanged(string propertyName)
		{
			if (PropertyChanged != null)
			{
				isChanged=true;
			}
		}

		public Instrument()
		{
			myVolume = null;
			myPage = null;
			myFileNumber = null;
			myFilmstripNumber = null;

		}

		public bool RecChanged
		{
			set 
			{
				if (isChanged == false) return;
				isChanged = false;
			}
		}

		private string myFileNumber;
		public string FileNumber
		{
			get { return myFileNumber;  }
			set 
			{
				if (myFileNumber == value) return;
				myFileNumber = value;
				onpropertychanged(FileNumber);
			}
		}

		private string myFilmstripNumber;
		public string FilmstripNumber
		{
			get { return myFilmstripNumber; }
			set 
			{
				if (myFilmstripNumber == value) return;
				myFilmstripNumber = value;
				onpropertychanged(FilmstripNumber);
			}
		}

		private string myVolume;
		public string Volume
		{
			get { return myVolume; }
			set 
			{
				if (myVolume == value) return;
				myVolume = value;
				onpropertychanged(Volume);
			}
		}

		private string myPage;
		public string Page
		{
			get { return myPage; }
			set 
			{
				if (myVolume == value) return;
				myPage = value;
				onpropertychanged(Page);
			}
		}

		private string myBook;
		public string Book
		{
			get { return myBook; }
			set 
			{
				if (myBook == value) return;
				myBook = value;
				onpropertychanged(Book);
			}
		}

		private DateTime myExecDate;
		public DateTime ExecDate
		{
			get { return myExecDate; }
			set
			{
				if (myExecDate == value) return;
				myExecDate = value;
				onpropertychanged("Execution Date");
			}
		}

		private DateTime myEffectDate;
		public DateTime EffectDate
		{
			get { return myEffectDate; }
			set 
			{
				if (myEffectDate == value) return;
				myEffectDate = value;
				onpropertychanged("Effective Date");
			}
		}

		private DateTime myFileDate;
		public DateTime FileDate
		{
			get { return myFileDate; }
			set 
			{
				if (myFileDate == value) return;
				myFileDate = value;
				onpropertychanged("File Date");
			}
		}

		private string myGrantor;
		public string Grantor
		{
			get { return Grantor; }
			set 
			{
				if (myGrantor == value) return;
				myGrantor = value;
				onpropertychanged(Grantor);
			}
		}

		private string myStyle;
		public string Style
		{
			get { return myStyle; }
			set 
			{
				if (myStyle == value) return;
				myStyle = value;
				onpropertychanged(Style);
			}
		}

		private string myGrantee;
		public string Grantee
		{
			get { return myGrantee; }
			set 
			{
				if (myGrantee == value) return;
				myGrantee = value;
				onpropertychanged(Grantee);
			}
		}

		private string myRemarks;
		public string Remarks
		{
			get { return myRemarks; }
			set 
			{
				if (myRemarks == value) return;
				myRemarks = value;
				onpropertychanged(Remarks);
			}
		}

		private string myNotes;
		public string Notes
		{
			get { return myNotes; }
			set 
			{
				if (myNotes == value) return;
				myNotes = value;
				onpropertychanged(Notes);
			}
		}

		private bool hasFieldNotes;
		public bool FieldNotes
		{
			get { return hasFieldNotes; }
			set 
			{
				if (hasFieldNotes == value) return;
				hasFieldNotes = value;
				onpropertychanged("FieldNotes");
			}
		}

		private bool hasReservations;
		public bool Reservations
		{
			get { return hasReservations; }
			set 
			{
				if (hasReservations == value) return;
				hasReservations = value;
				onpropertychanged("Reservations");
			}
		}

		private bool hasCopy;
		public bool Copied
		{
			get { return hasCopy; }
			set 
			{
				if (hasCopy == value) return;
				hasCopy = value;
				onpropertychanged("Copied");
			}
		}

		private long myGrossAcres;
		public long GrossAcres
		{
			get { return myGrossAcres; }
			set 
			{
				if (myGrossAcres == value) return;
				myGrossAcres = value;
				onpropertychanged("GrossAcres");
			}
		}

		public string BookReference
		{
			get
			{
				if (Volume == null)
				{ return FileNumber; }
				else
				{ return Volume + "/" + Page + " " + Book; }
			}
		}

	}
}




//InstrumentCollection.cs
//Collection class to hold Instrument objects.


using System;
using System.Collections;

namespace GlobalPlant
{
    public class InstrumentCollection : System.Collections.CollectionBase
    {
        public void Add(Instrument anInstrument)
        {
            List.Add(anInstrument);
        }

        public bool Remove(int index)
        {
            if (index > Count - 1 || index < 0)
            {
                return false;
            }
            else
            {
                List.RemoveAt(index);
            }
        }

        public Instrument Item(int index)
        {
            return (Instrument)List[index];
        }

        public Instruemnt GetInstrumentAt(int i)
        {
            return (Instrument)InstrumentCollection[i];
        }

        public Instrument GetInstrumentAt(string key)
        {
            return (Instrument)InstrumentCollection[key];
        }

        public InstrumentCollection()
        {

        }
    }
}




Is This A Good Question/Topic? 0
  • +

Replies To: My Class and A Collection Class

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: My Class and A Collection Class

Posted 27 September 2013 - 01:39 PM

You have an error on line 86, but I suspect that's from cut/paste :)

Your objects look fine to me, but you might consider splitting the first object into two classes if there is data that is used mostly, then some that is used rarely (notes comes to mind). You can also split it in the database, making less work for the DB server when getting the often used data and lazy loading the rest as needed.

I can explain more if you need :)
Was This Post Helpful? 0
  • +
  • -

#3 ScottinTexas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 13-March 12

Re: My Class and A Collection Class

Posted 27 September 2013 - 02:43 PM

Good catch on the notes! It is actually split in the data base. I use a table with the InstrumentID, RunsheetID, Notes. The Instrument and Runsheet IDs are the Key to the table. I wasn't thinking when I set this class up that the Notes are only there if the instrument is included in a title search. As it is now when the save button is clicked one of the processes is to create a new entry in the notes table if there are any notes typed. As to the rest of the data, its always there and always needed. In fact, the Grantor and Grantee could be classes in themselves as they may include lots of people, companies, Estates, etc. each. One of the things I have battled with is the best way to handle them. But that can come later. Now I want a tight, well formed application that can eventually be moved to a web site and used from anywhere. I think this is the start toward that end.

Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1