本文介绍了通过方法(功能)启用/禁用按钮/上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1。我有8个按钮,每个按钮执行不同的任务,即编辑,删除,创建等,以及每个任务的上下文菜单



2.我是DB中的* Moderations *表,包括bools,即groupTitle,canEdit,canDelete,canCreate ..... groupTitle是字符串而不是bool



3.我有一个bool函数* canDoIt(task,userid)*检查登录用户(具有特定的groupTitle),是否可以执行或不能(函数返回true或false为提供的任务,简而言之)



假设,我想检查登录用户是否可以执行任务,通过canDoit(任务,用户ID)检查,如果他不能,则按钮将被禁用不会....

OnForm_Load我抛出这个功能(或者可能是我需要它的时候)并检查每个按钮,即



btnEdit.Enabled = canDo(canEdit,userID)

btnDelete.Enabled = canDo(canDelete,userID)

btnCreate.Enabled = canDo(canCreat,userID)



cnxMenuEdit.Enabled = canDo(canEdit,userID)

cnxMenuDelete.Enabled = canDo (canDelete,userID)







.....等等等等。



我的方法工作得很好但很好但我有疑问和问题....



第一个问题,好不容易这样?

第二个问题,它是否专业?

另一个是,会影响程序或数据库性能吗?



很抱歉,如果已经询问/发布了.....



我尝试了什么:



btnEdit.Enabled = canDo(canEdit,userID)

btnDelete.Enabled = canDo(canDelete,userID)

btnCreate.Enabled = canDo(canCreat,userID)



cnxMenuEdit.Enabled = canDo(canEdit,userID)

cnxMenuDelete.Enabled = canDo(canDelete,userID)







.....等等等等。

1. I have 8 buttons, each performs a different task, i.e. edit, delete, create etc, and a context​Menu for each of the task

2. I've a table called *Moderations* in DB, which consists of bools i.e. groupTitle, canEdit, canDelete, canCreate..... groupTitle is string not bool

3. I have a bool function *canDoIt(task, userid)* to check whether the logged in user (which will have specific groupTitle), can perform or can't (function return true or false for provided task, in short)

Suppose, I want to check whether a logged in user can perform the task or not, check via canDoit(task, userid), and If he cannot, the button will be disabled otherwise won't....
OnForm_Load I throw the function (or may be another time when I need it) and check for each button, i.e.

btnEdit.Enabled = canDo("canEdit", userID)
btnDelete.Enabled = canDo("canDelete", userID)
btnCreate.Enabled = canDo("canCreat", userID)

cnxMenuEdit.Enabled = canDo("canEdit", userID)
cnxMenuDelete.Enabled = canDo("canDelete", userID)
.
.
.
.....and so on and so forth.

My method work fine and good but I have doubts and questions....

First question, is good to be so?
Second question, is it professional?
Another is, will that effect program or database performance?

Sorry if same has already asked/posted.....

What I have tried:

btnEdit.Enabled = canDo("canEdit", userID)
btnDelete.Enabled = canDo("canDelete", userID)
btnCreate.Enabled = canDo("canCreat", userID)

cnxMenuEdit.Enabled = canDo("canEdit", userID)
cnxMenuDelete.Enabled = canDo("canDelete", userID)
.
.
.
.....and so on and so forth.

推荐答案


这篇关于通过方法(功能)启用/禁用按钮/上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 12:22