Some experiences on software permission settings

Source: Internet
Author: User
I have some experience in user permission processing during software development and share it with you. I hope you will give more valuable comments.

Previous majorityArticleThe user permissions set in the document are implemented by associating the actionlist with the permission table in the database. Through the tag attribute of the control (each control has a reserved tag attribute, and the default value is 0), you can also set permissions. The following describes the implementation method.

1. Assign non-repeated Arabic numbers (, 3 ......) from 1 to the tag attribute of all menus and buttons for permission setting ......), 0 is not used here (the default value of the tag attribute of the control), indicating that the control does not require permission settings.

2. Add all permission names to the checkboxlist, including menus and buttons. The order must be exactly the same as that for assigning Arabic numbers.

3. Create an operator table (including numbers, names, and permissions) in the database and use a string containing only 0 and 1. 0 indicates that you have the corresponding permissions (the corresponding menu or button is available, enabled = true), and 1 indicates that you do not have the corresponding permissions (the corresponding menu or button is unavailable, enabled = false ). This field must be long enough (I have reserved 50 digits) for expansion.

4. Set permissionsCodeAs follows:

/* QX, user permission string, Operator table, privilege permission field */
Ansistring QX = "";
For (I = 1; I <= checklistbox1-> items-> count; I ++ ){
If (checklistbox1-> checked [I-1]) {
QX = qx + "0 ";
} Else {
QX = qx + "1 ";
}
}
SQL = "Update operator set privilege =" + qx + "where operator_name =" + cbooperatorname-> text + "";
5. Set the user's global variables and add the permission judgment code to the formshow event of the form as follows:

/* The system administrator has all permissions */
If (frmdm-> GetUserName ()! = "System Administrator "){
Ansistring QX;
/* You have not set the permission */
If (strprivilege. Length () = 0 ){
For (Int J = 0; j <= parent-> componentcount-1; j ++ ){
If (parent-> components [J]-> tag! = 0 ){
If (parent-> components [J]-> classnameis ("tmenuitem ")){
(Tmenuitem *) parent-> components [J])-> enabled = false;
} Else {
(Tbutton *) parent-> components [J])-> enabled = false;
}
}
}
} Else {
For (I = 1; I <= strprivilege. Length (); I ++) {/* permission set */
QX = strprivilege. substring (I, 1 );
If (QX = "1 "){
For (j = 0; j <= parent-> componentcount-1; j ++ ){
If (parent-> components [J]-> tag = I ){
If (parent-> components [J]-> classnameis ("tmenuitem ")){
(Tmenuitem *) parent-> components [J])-> enabled = false;
} Else {
(Tbutton *) parent-> components [J])-> enabled = false;
Break;
}
}
}
}
}
}
The above is my experience on user permission settings during software development.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.