/// <summary> /// 添加角色对应的菜单的权限 /// </summary> /// <param name="updbhelper">数据库连接对象</param> /// <param name="roleno">角色编号</param> /// <param name="menuno">角单编号</param> /// <param name="powerno">权限编号</param> /// <param name="roleobjects">角色权限信息</param> /// <returns></returns> public bool InsertRoleObjects(DBFactory updbhelper, string roleno, string menuno, string powerno, List <sysrole_menu_power_object> roleobjects) { OperateResultModel orm = new OperateResultModel(); List <DBMemberEntity> entities = new List <DBMemberEntity>(); entities.AddMember("roleno", roleno); entities.AddMember("menuno", menuno); entities.AddMember("powerno", powerno); orm = Query(entities, null, null); DataTable oldroleobjects = orm.rows as DataTable; foreach (sysrole_menu_power_object roleobject in roleobjects) { if (oldroleobjects == null || oldroleobjects.AsEnumerable().Count(p => p.Field <string>("roleno") == roleobject.roleno && p.Field <string>("menuno") == roleobject.menuno && p.Field <string>("powerno") == roleobject.powerno && p.Field <string>("forobject") == roleobject.forobject) == 0) { if (!updbhelper.Insert(updbhelper.Connection(), updbhelper.Transaction(), roleobject)) { throw new Exception("插入角色对应菜单权限【" + roleobject.menuno + "|" + roleobject.powerno + "|" + roleobject.forobject + "】失败"); } } } if (oldroleobjects != null) { foreach (DataRow roleobject in oldroleobjects.Rows) { if (roleobjects.Count(p => p.roleno == roleobject["roleno"].ToString() && p.menuno == roleobject["menuno"].ToString() && p.powerno == roleobject["powerno"].ToString() && p.forobject == roleobject["forobject"].ToString()) == 0) { sysrole_menu_power_object roleobjectmodel = new sysrole_menu_power_object() { pkid = roleobject["pkid"].ToString() }; if (updbhelper.Delete(updbhelper.Connection(), updbhelper.Transaction(), roleobjectmodel) != 1) { throw new Exception("删除角色对应菜单【" + roleobject["menuno"] + "|" + roleobject["powerno"] + "|" + roleobject["forobject"] + "】失败"); } } } } return(true); }
/// <summary> /// 删除试卷与题目的对应关系 /// </summary> /// <param name="factory">数据库连接工厂</param> /// <param name="paperid">试卷ID</param> /// <param name="bankid">题目ID</param> /// <returns></returns> public bool Delete(DBFactory factory, int?paperid, int?bankid) { tbl_paper_bank model = new tbl_paper_bank() { }; if (paperid == null && bankid == null) { throw new Exception("试卷ID和题目ID不能同时为空"); } if (paperid != null) { model.paperid = paperid; } if (bankid != null) { model.bankid = bankid; } factory.Delete(factory.Connection(), factory.Transaction(), model); return(true); }