A little experience of software permission setting

Source: Internet
Author: User
Experience
I am in the software development process on the user rights to deal with a little experience, take out to share with you, I hope we have more valuable advice.

In the past, most of the article data set user rights are implemented by ActionList and the permission table in the database. I have practiced through the control of the Tag property (each control has a reserved tag property, the default value is 0), you can also implement permissions settings, below I will specify the implementation method.

1, will all need to set the right menu and button's Tag property from 1 to start assigning 1,2,3 Arabic numerals (...). , this does not need to be 0 (the default value of the control's Tag property), which means that the control does not need permission settings.

2. Add all permission names to CheckBoxList, including menus and buttons, which must be in exactly the same order as the Arabic numerals.

3, in the database to establish an operator table (including number, name, permissions) permissions with a string containing only 0 and 1 representation. With 0 means that the appropriate permissions (the corresponding menu or button available, enabled=true), with 1 means no corresponding permissions (the corresponding menu or button is not available, enabled=false). This field should be set long enough (I reserve 50 digits) for expansion.

4, set the main code of rights as follows:

/* QX, User rights string, operator 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, in the form of the Formshow event to add permissions to judge the code as follows:

/* The system administrator has all permissions */
if (Frmdm->getusername ()!= "system administrator") {
Ansistring QX;
/* has 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++) {/* already set permissions */
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
}
}
}
}
}
}
Above is I in the software development process regarding the user authority setting little experience experience, hoped can the discussion.



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.