开发者

c# show/hide button when admin/user login

I'm writing an app with client - server model. When the client starts, it will show the loginform with username and password field. When the Sign in button is clicked, client will send these username & pw 开发者_运维百科to server to check. If server checks ok, then at client mainform will appear. my code is like this:

At client, loginForm.cs:

if (execmd == "OK") // server sends "OK" or "FAILED" after checking authentication
    this.DialogResult = DialogResult.OK

At client, program.cs:

login = new loginForm();
DialogResult result = login.showDialog();
login.Dispose();
if (result != DialogResult.Cancel)
    Application.Run(new MainForm(login));

Now I want to improve my app with admin/user authentication. In MainForm there's a Setting button. If users log in then this button will be hidden. If admin logs in then this button will be shown. With the above code, how do I do to make the MainForm Show() or Hide() the button depending on what string server will send after checking authentication?(for example execmd == "admin" if admin logs in).

Thanks in advance for your help.


Keep your existing logic in loginForm, but add a test to see if the user is the admin. And then set a boolean value in loginForm that indicates if it is the admin (something like IsAdmin).

You're already passing the loginForm to your MainForm, so your MainForm could then check the IsAdmin property to determine if the button should be displayed.

btnSetting.Visible = login.IsAdmin;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜