PB Multiple User Rights Management Implementation
When the general management system is implemented in PB, we will encounter such a situation. As a system, you can be divided into several subsystems, with multiple operators to operate, each operator is different for each subsystem Even in the same subsystem, the operator is different for the operation permissions of each menu item, more details, different operators are different for the operation permissions of a button in the same window, then, how to better Realize the permission control of different users to a button? The author has accumulated some experience in conducting a system development process, and discussed with you.
First, how to make a operator to operate the menu item or button of him, we certainly don't have to make different menu items or windows for different users (of course, this is not a way), considering the menu item And the Visible and Enabled attributes of the button, we naturally think that the two properties can complete the above requirements, such as
m_1.m_2.visible = false or
CB_1.enabled = false
The menu is not visible, and the operator will naturally be indispensable.
Secondly, for a multi-user system, we naturally need to use a table to store basic user information, including the username, password of the user login system, if you want to perform grading control, some fields need to be stored related permissions Information, some finished products are doing this, but they use a menu item that needs to be controlled in a field, which is not very good, in case the design of a permission control, this is done Feasibility is not good, in fact, when performing permission control with a menu item or other control, the status is only two, and the True OR FALSE can be used in one binary number 0 or 1, we can put one All items in the subsystem need to perform permission control are combined into a binary string, each four binary numbers are converted to a character (can be "0", "1", "2" ... "A", "B" , "c", "d", "e", "f"), save in the table, so let's count, if there is 64 items in a subsystem need permission control, only one 64 / 4 = 16-bit character types of character types can be represented, and 64 fields are required to be marked separately as in the past.
Ok, the first step is stored, so how does the Visible or Enabled property of each menu item or other control according to the string of such tag permissions? I noticed that there is a tag property in the PB menu item and other controls, and this attribute we generally don't use it, we can use the Tag property to store a number, this number indicates that the control is in the permission control field. That binary is indicated by 0/1 of the access rights of the control, an example, there is a permission control binary string '01001111010 ....', the menu item "Open file" TAG is 7, then the binary The 7th bit "1" in the string labeled the current user's control permission to "Open File" as "1".
When a user logs in to the system, after password verification, he reads the string of the rights control field of the system to a global variable, rests the string to 0,1 strings, and permissions for each need The item can be managed according to the 0 or 1 setting of the corresponding location of the TAG record, and can be managed to complete the permissions.
Of course, it is to be noted that some control of the authority is not done after entering the system, but is preliminating when the control is called. An example is given below to illustrate the above discussion.
There are three menu items and 2 buttons that need to be controlled.
3 menu item names are:
M_a.m_h1.m_m1 m_a.m_h1.m_m2 m_a.m_h1.m_m3
The TAG of the three menu items above is set to 1-3
2 buttons are located in two windows
CB_1 is located in W_1
CB_2 is located in W_2
The TAG of the above 2 buttons is set to 4, 5
In this way, it is necessary to represent their access rights.
The function getbin is used to conversion from "0", "1" ..., "a" ... "f" to four binary strings.
getbin (string s_ch) returns stringstring s_out, s_tempinteger i_leninteger istring tempi_len = len (s_ch) if i_len = 0 or isnull (s_ch) thens_out = "0" end iftemp = "" s_temp = "" for i = 1 to i_len temp = mid (S_CH, I, 1) CASE CASE LOWER (TEMP) CASE "A" S_TEMP = "1010" CASE "B" S_TEMP = "1011" Case "C" s_temp = "1100" Case "D" s_temp = "1101" CASE "e" s_temp = "1110" case "f" s_temp = "1111" case "s_temp =" 0000 "case" 1 "s_temp =" 0001 "Case" 2 "s_temp =" 0010 "Case" 3 "S_TEMP = "0011" case "4" s_temp = "0100" case "5" s_temp = "0101" case "7" s_temp = "0111" case "8" s_temp = "1000" Case " 9 "S_TEMP =" 1001 "Case Else S_Temp =" 0000 "End ChooseS_out = S_OUT S_TEMPS_TEMP =" "NextReturn S_OUT
Define a global variable S_Admin to store the user's login permission information:
String S_Tempselect Rights Into: s_temp where user =: username and password =: userpassword; s_admin = getbin (s_temp) // s_admin is stored in transforming permission information.
Define a permission function check to complete the conversion from 0, 1 to TRUE, FALSE.
check (string menutag) returns booleanstring s_temps_temp = mid (s_admin, integer (menutag), 1) // s_admin global variables if isnull (s_temp) or s_temp = "1" thenreturn trueelsereturn falseend if the main window is assumed w_main after login, Its menu is M_A
Then write this in the Open event of W_main:
m_a.m_h1.m_m1.enabled = CHECK (m_a.m_h1.m_m1.tag) m_a.m_h1.m_m2.enabled = Check (m_a.m_h1.m_m_m3.enabled = Check (m_a.m_h1. m_m3.tag)
In the OPEN event in W_1:
CB_1.enabled = Check (CB_1.TAG)
Similarly, in the OPEN event in W_2
CB_2.enabled = check (cb_2.tag)
This allows the above 5 control.
Of course, this method is more obvious when the item needs to be controlled (reaching dozens).
Above above discusses the implementation of authority control, in multi-user systems, there is also a set function of user permissions, this and above
A reverse process, I believe that the reader will grasp the practice settings after reading the above content, which is no longer redundant.