管理员,即 John 在注册时链接到 HR 部门,然后选择 HR 部门,他的数据存储在userss表中,在此表中,id 设置为 dep id =2,即 dep2。
然后我想当他通过他的登录名和密码登录时,他只能访问人力资源文件,而不是金融、计算机科学、市场营销等其他文件,我已经尝试过这个查询。
首先我选择 dep id:
ALTER procedure [dbo].[sphrdoc]
@UserName nvarchar(50),
@Password nvarchar(50)
as
select DepID from Userss where UserName=@UserName AND [Password]=@Password
然后我创建一个函数:
publicint hrdoc(string Username,string password)
{
return Convert.ToInt32( db.ExecuteScalar("sphrdoc",newobject[]
{Username,password}));
}
然后在页面加载中:
Session["a"] = dd.hrdoc(Convert.ToString(Session["Login2"]),
(Convert.ToString(Session["Login3"])));
然后我设置了这个查询:
ALTER procedure [dbo].[sphrdocid1]
@DepID int
as
SELECT DocumentInfo.DocID,
dbo.DocumentInfo.DocName,
dbo.DocumentInfo.Uploadfile,
dbo.DocType.DocType,
dbo.Department.DepType ,
dbo.ApproveType.ApproveType AS ApproveID
FROM dbo.DocumentInfo
left JOIN dbo.DocType ON dbo.DocumentInfo.DocTypeID=dbo.DocType.DocTypeID
left JOIN dbo.Department ON dbo.DocumentInfo.DepID=dbo.Department.DepID
LEFT JOIN dbo.ApproveType ON dbo.ApproveType.approveid=dbo.Department.DepID where
dbo.Department.DepID=@DepID
public DataTable hrdoc1(int id)
{
DataTable table = db.ExecuteDataSet("sphrdocid1", new object[] { id
}).Tables[0];
return table;
}
然后在页面加载中我称之为:
GrdFileApprove.DataSource = dd.hrdoc1(Convert.ToInt32(Session["a"]));
GrdFileApprove.DataBind();
但是当 John 登录时,他仍然可以看到与人力资源、市场营销、财务、计算机科学相关的所有文档。