tags:

views:

60

answers:

2

Hi, I am working on Windows Form (C#) visual studio and .net 3.5,
my program is a database-based, with multi-user,
database store info about devices and contract,

what I need is a way to restrict specific fields to (Modify,ReadOnly,Hidden)
receptively to the logged-in user privileges,
I don't want to use windows users, I want my users (from a database)to make them separate from OS, at least for now,
so for example I have a form with 21 fields,
five of them must be hidden when employee with no financial privileges has logged-in,
but when his supervisor is the user, then he can see the financial field but not modify it's value,
and when the administrator is logged-in he can do what every he wants to do

I hope I make it clear enough to help me out,

A: 

If you've read the user and their privileges from your database, it's just a matter of setting the Visible property of any control you don't want shown.

this.FinanceField1.Visible = !IsEmployee();
this.FinanceField2.Visible = !IsEmployee();

this.FinanceField3.Enabled = !IsSupervisor();

Or something similar to this.

Matthew Ferreira
Or perhaps `Enabled`, if you want it to be visible but not editable
dsolimano
Yeah, I just made the edit accordingly.
Matthew Ferreira
as I comment at Drakinfar, I want a more persistent solution, but thank you anyway
Mysterious
A: 

Implement a permissions table in your database that you read when the use logs in. Then set your form state based upon the passed permission.

Drakinfar
first of all thank you for your response,I have that in mind, but I need a better solution that is independent from form or visual ... in another word, I a have reports and queries for the same field (SalesPrice appear on the device form and on the report form and on the finance form) I was looking for something like ErrorProvider, I make the restriction once and it will be apply whenever I access that field
Mysterious