Exemplo n.º 1
0
    //修改管理员是否为监考老师
    public int ChangeAdminExamTeacher(string tId)
    {
        int res = 0;

        try
        {
            Teacher teacher = db.Teacher.First(t => t.TId == tId);

            if (teacher.isExamTeacher == (int)IsExamTeacher.Yes)//取消该教师的监考老师资格
            {
                teacher.isExamTeacher = (int)IsExamTeacher.No;
                db.SubmitChanges();

                List <Authority> deleteAuthority = (from p in db.Authority
                                                    join q in db.TeaAuthority on p.AuthorityId equals q.AuthorityId
                                                    where q.TId == tId && p.AuthorityType == (int)AuthorityBLL.AuthorityType.ExamTeacher
                                                    select p).ToList();

                //从权限信息中删除监考老师权限
                foreach (var item in deleteAuthority)
                {
                    TeaAuthority teaAu = db.TeaAuthority.First(t => t.TId == tId && t.AuthorityId == item.AuthorityId);
                    db.TeaAuthority.DeleteOnSubmit(teaAu);
                    db.SubmitChanges();
                }
            }
            else  //设置管理员为该监考老师
            {
                teacher.isExamTeacher = (int)IsExamTeacher.Yes;

                //获取监考老师权限
                List <Authority> examTeacherAu = db.Authority.Where(t => t.AuthorityType == (int)AuthorityBLL.AuthorityType.ExamTeacher).ToList();

                //插入该管理员的权限信息中
                foreach (var item in examTeacherAu)
                {
                    TeaAuthority teaAu = new TeaAuthority()
                    {
                        AuthorityId = item.AuthorityId,
                        TId         = tId
                    };

                    db.TeaAuthority.InsertOnSubmit(teaAu);
                    db.SubmitChanges();
                }
            }
            res = 1;
        }
        catch (Exception ex)
        {
            res = 0;
        }


        return(res);
    }
Exemplo n.º 2
0
    protected void btn_GrantGroup_Click(object sender, EventArgs e)
    {
        bool flag = false;

        userName = Request.QueryString["username"].ToString();

        try
        {
            foreach (RepeaterItem item in rp_AutorityGrant.Items)
            {
                if (((CheckBox)item.FindControl("cb_Select")).Checked == true)
                {
                    flag = true;
                    int Aid = Int32.Parse(((HiddenField)item.FindControl("hi_Id")).Value);
                    var cs  = new TeaAuthority
                    {
                        AuthorityId = Aid,
                        TId         = userName
                    };
                    db.TeaAuthority.InsertOnSubmit(cs);
                }
            }

            if (flag == false)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "message", "<script>alert('请先勾选功能!');</script>");

                return;
            }
            else
            {
                db.SubmitChanges();

                ClientScript.RegisterStartupScript(this.GetType(), "message", "<script> alert('权限授予成功!');</script>");


                //              ClientScript.RegisterStartupScript(this.GetType(), "message", "<script> alert('权限授予成功!');window.location='GrantAuthority.aspx?username=userName';</script>");
            }
            Bindata();
        }
        catch (Exception ex)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "message", "<script>alert('权限授予失败,请重试!');</script>");
            return;
        }
    }
Exemplo n.º 3
0
    protected void btn_GrantGroup_Click(object sender, EventArgs e)
    {
        bool flag = false;

        userName = Request.QueryString["username"].ToString();

        try
        {
            foreach (RepeaterItem item in rp_AutorityGrant.Items)
            {
                if (((CheckBox)item.FindControl("cb_Select")).Checked == true)
                {
                    flag = true;
                    int          Aid = Int32.Parse(((HiddenField)item.FindControl("hi_Id")).Value);
                    TeaAuthority cs  = db.TeaAuthority.Single(a => a.TId == userName && a.AuthorityId == Aid);//删除权限
                    db.TeaAuthority.DeleteOnSubmit(cs);
                }
            }

            if (flag == false)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "message", "<script>alert('请先勾选功能!');</script>");

                return;
            }
            else
            {
                db.SubmitChanges();
                ClientScript.RegisterStartupScript(this.GetType(), "message", "<script>alert('权限回收成功!');</script>");
                Bindata();
            }
            Bindata();
        }
        catch (Exception ex)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "message", "<script>alert('权限回收失败,请重试!');</script>");
            return;
        }
    }
Exemplo n.º 4
0
    ///删除教师
    public int DeleteTeacher(Teacher teacher)
    {
        try
        {
            List <Authority> authority = authorityBll.GetAuthorityByUserId(teacher.TId);
            foreach (var item in authority)
            {
                TeaAuthority teaAu = db.TeaAuthority.Where(t => t.TId == teacher.TId &&
                                                           t.AuthorityId == item.AuthorityId).First();
                db.TeaAuthority.DeleteOnSubmit(teaAu);
            }
            Teacher deleteTeacher = db.Teacher.Where(t => t.TId == teacher.TId).First();

            db.Teacher.DeleteOnSubmit(deleteTeacher);
            db.SubmitChanges();
            return(1);
        }
        catch (Exception ex)
        {
            return(0);
        }
    }