根据登录用户的部门显示相同部门的记录
我有个考勤系统,现在想在考勤登记页面进行修改,想根据登录用户的部门来显示相同部门的用户信息,例如信息科的记录员只能看到信息科的员工的用户信息,并且对其进行考勤登记操作。代码不太会改,有高手能帮我改一下吗。public partial class LoginAdmin_SignIn : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Session["User"] == null || Session["User"].ToString() == "")
{
Response.Write("<script>alert('超时,请重新登录!');top.location.href='../Login.aspx'</script>"); return;
}
}
}
public void Bind()
{
User user = (User)Session["User"];
if (user.Roleid == 1 || user.Roleid == 2)
{
IList<User> list = UserManager.GetUserByDepId(int depId);
this.GridView1.DataSource = list;
this.GridView1.DataBind();
}
else
{
this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('对不起,您没有权限修改考勤记录!')", true);
}
}
#region 数据格式化
//部门名称
public string DepName(object depId)
{
int id = Convert.ToInt32(depId.ToString());
Dep dep = DepManager.GetDepByDepid(id);
if (dep != null)
{
return dep.Depname;
}
else
{
return "";
}
}
//角色名称
public string RoleName(object roleId)
{
int id = Convert.ToInt32(roleId.ToString());
Role role = RoleManager.GetRoleByRoleid(id);
if (role != null)
{
return role.Rolename;
}
else
{
return "";
}
}
#endregion
#region 签到
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if ( == "go")
{
Kaoqin kaoqin = new Kaoqin();
kaoqin.Kintime = DateTime.Now;
kaoqin.State = 0;
kaoqin.Userid=Convert.ToInt32();
kaoqin.Kouttime = DateTime.Today;
Kaoqin k= KaoqinManager.AddKaoqin(kaoqin);
if (k != null)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('签到成功!');", true);
GridView1.DataBind();
}
else
{
this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('签到失败!');", true);
}
}
else if()
{
Response.Redirect("QingJia.aspx?UserId="+());
}
}
#endregion
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HiddenField hf = e.Row.FindControl("hfUserId") as HiddenField;
Button signIn = e.Row.FindControl("btnSignIn") as Button;
Button qinjia = e.Row.FindControl("btnQinjia") as Button;
int userId=Convert.ToInt32( hf.Value);
Kaoqin kaoqin= KaoqinManager.GetKaoqinByUserIdAndTime(userId);
if (kaoqin != null)
{
signIn.Enabled = false;
qinjia.Enabled = false;
}
else
{
signIn.Enabled = true;
qinjia.Enabled = true;
}
}
}
}
斜体是我写的代码就是实现这个功能的,总是保错,不知道对不对,高手帮我看一下吧。