Edit vs ReadOnly

barski

Junior Contributor
Joined
Apr 7, 2002
Messages
240
Location
Tennessee
I Customer Object with three properties

Name
Terms
Region

Now the users are in two groups

Users
RealGoodUsers

Now i want RealGoodUsers to be able to edit but not the Users. Does anyone have any suggestions other than an if=="RealGoodUsers" in the set of the properties? Nothing wrong with the if but what if i add another group...
 
I'm slightly confused about your question. Are the Customer objects members of the user groups, or are the user groups a seperate entity that can view / alter the Customer objects. If the later is true then alot depends on how the data is being displayed to the viewer in the first place. Perhaps a bit more information and I could help more.
 
If the users are objects, then you could have them contain, inherit, or implement a property that indicates if they are able to modify customer objects. :)
 
users and customers are two different objects. I could implement a bool "CanEdit" property therefore no matter how many users i add it wouldn't make a difference. However, what if one group can edit Name and Region but not Terms?
 
The obvious solution is to have a CanEdit property for every property in the Customer class. I'm guessing that you already thought of that though, and discounted it as it hardly lends itself to making an extensible framework.

How about having CanEdit as an arraylist of strings in the user classes. Then wherever you are displaying the information, for each property you check the user class for CanEdit.Contains("Name") if it does you enable edit else you don't.

Heres the code...
C#:
	public interface User
	{
		ArrayList CanEdit { get; }
	}

	public class User1 : User
	{
		private ArrayList arrCanEdit;
		
		public ArrayList CanEdit
		{
			get { return arrCanEdit; }
		}

		public User1()
		{
			string[] sCanEdit = new string[] { "Name" };
			arrCanEdit = new ArrayList();
			arrCanEdit.AddRange(sCanEdit);
		}
	}

	public class User2 : User
	{
		private ArrayList arrCanEdit;
		
		public ArrayList CanEdit
		{
			get { return arrCanEdit; }
		}

		public User2()
		{
			string[] sCanEdit = new string[] { "Region" };
			arrCanEdit = new ArrayList();
			arrCanEdit.AddRange(sCanEdit);
		}
	}

	public class Customer
	{
		private string sName = "Peter";
		private string sTerm = "Summer";
		private string sRegion = "Here and there";

		public string Name
		{
			get { return sName; }
			set { sName = value; }
		}

		public string Term
		{
			get { return sTerm; }
			set { sTerm = value; }
		}

		public string Region
		{
			get { return sRegion; }
			set { sRegion = value; }
		}

		public Customer()
		{
		}
	}
and then on the form something like this...
C#:
		private void Form1_Load(object sender, System.EventArgs e)
		{
			myUser = new User1();
			Customer myCustomer = new Customer();

			textBox1.Text = myCustomer.Name;
			textBox2.Text = myCustomer.Term;
			textBox3.Text = myCustomer.Region;

			if(myUser.CanEdit.Contains("Name"))
				textBox1.ReadOnly = false;
			else
				textBox1.ReadOnly = true;

			if(myUser.CanEdit.Contains("Term"))
				textBox2.ReadOnly = false;
			else
				textBox2.ReadOnly = true;

			if(myUser.CanEdit.Contains("Region"))
				textBox3.ReadOnly = false;
			else
				textBox3.ReadOnly = true;
		}

Perhaps not the most elegant solution, but it should work and could be extended to include more properties with relative ease.
 
my goodness! thanks for the effort. a collection in the user object. i think that concept maybe similar to what i'm looking for. i need to think about it a little more. i'll post something later today on what i went with (well not excactly what i went with but the best thing i can think of today)
 
Back
Top