禁止用户访问窗口应用程序中的某些任务 [英] Prevent user Access to some task in window application

查看:60
本文介绍了禁止用户访问窗口应用程序中的某些任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我们无权向用户输入冷杉记录,但是当我们登录管理员帐户时,同样会阻止向用户输入记录...我希望管理员输入记录
下面的access.cs代码

hi every one we have not access to enter fir record to user but when we login admin account that same prevent to enter record to admin ...i wish admin enter record
access.cs code below

namespace Crime_System
{
    class access
    {
        public bool fread()
        {
            Hashtable ht = new Hashtable();
            FileStream sfs = new FileStream("temp.xml", FileMode.Open, FileAccess.Read);
            Hashtable h = new Hashtable();
            BinaryFormatter formatter = new BinaryFormatter();
            h = (Hashtable)formatter.Deserialize(sfs);
            string status = Convert.ToString(h["name"]);
            sfs.Close();
            if (status == "Admin" || status == "admin")
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}



下方的表单代码



form code below

private void button1_Click(object sender, EventArgs e)
       {
           access validate = new access();
           MSG message = new MSG();
           if (validate.fread() == true)
           {

               firsave();
           }
           else
           {
               message.Get_MSG_ERR("Sorry,Access is not gurantted");

           }
       }



请帮助我..



plz help me any body..

推荐答案

Hashtable ht = new Hashtable(); //What's this code for? It seems unnecessary here.
FileStream sfs = new FileStream("temp.xml", FileMode.Open, FileAccess.Read);
Hashtable h = new Hashtable();
BinaryFormatter formatter = new BinaryFormatter();
h = (Hashtable)formatter.Deserialize(sfs);
string status = Convert.ToString(h["name"]);//status will never be "Admin" or "admin". Check your file.  
sfs.Close();
if (status == "Admin" || status == "admin") //if (status.ToUpper() == "ADMIN")
{
    return true;
}
else
{
    return false;
}




更好的建议:




and Better suggestion:

FileStream sfs = new FileStream("temp.xml", FileMode.Open, FileAccess.Read);
Hashtable h = new Hashtable();
BinaryFormatter formatter = new BinaryFormatter();
h = (Hashtable)formatter.Deserialize(sfs);
string status = Convert.ToString(h["name"]);
sfs.Close();
return (status.ToUpper() == "ADMIN")? true:false


我上面的代码以管理员用户名密码登录时无法正常工作
然后他们阻止我插入记录...请帮助我
My above code do not work correctely when we login as admin username password
then they stop me for insert record...plz help me


这篇关于禁止用户访问窗口应用程序中的某些任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆