/// <summary> /// 添加数据 /// <param name="es">数据实体对象数组</param> /// <returns></returns> /// </summary> public bool Insert(SysRoleFunction e) { MySqlConnection oc = ConnectManager.Create(); MySqlCommand _cmdInsertSysRoleFunction = cmdInsertSysRoleFunction.Clone() as MySqlCommand; bool returnValue = false; _cmdInsertSysRoleFunction.Connection = oc; try { if (oc.State == ConnectionState.Closed) { oc.Open(); } _cmdInsertSysRoleFunction.Parameters["@SysRoleFunctionId"].Value = e.SysRoleFunctionId; _cmdInsertSysRoleFunction.Parameters["@RoleId"].Value = e.RoleId; _cmdInsertSysRoleFunction.Parameters["@FunctionId"].Value = e.FunctionId; _cmdInsertSysRoleFunction.ExecuteNonQuery(); return(returnValue); } finally { oc.Close(); oc.Dispose(); oc = null; _cmdInsertSysRoleFunction.Dispose(); _cmdInsertSysRoleFunction = null; } }
/// <summary> /// 修改指定的数据 /// <param name="e">修改后的数据实体对象</param> /// <para>数据对应的主键必须在实例中设置</para> /// </summary> public void Update(SysRoleFunction e) { MySqlConnection oc = ConnectManager.Create(); MySqlCommand _cmdUpdateSysRoleFunction = cmdUpdateSysRoleFunction.Clone() as MySqlCommand; _cmdUpdateSysRoleFunction.Connection = oc; try { if (oc.State == ConnectionState.Closed) { oc.Open(); } _cmdUpdateSysRoleFunction.Parameters["@SysRoleFunctionId"].Value = e.SysRoleFunctionId; _cmdUpdateSysRoleFunction.Parameters["@RoleId"].Value = e.RoleId; _cmdUpdateSysRoleFunction.Parameters["@FunctionId"].Value = e.FunctionId; _cmdUpdateSysRoleFunction.ExecuteNonQuery(); } finally { oc.Close(); oc.Dispose(); oc = null; _cmdUpdateSysRoleFunction.Dispose(); _cmdUpdateSysRoleFunction = null; GC.Collect(); } }
/// <summary> /// 获取指定记录 /// <param name="id">Id值</param> /// </summary> public SysRoleFunction Get(int SysRoleFunctionId) { SysRoleFunction returnValue = null; MySqlConnection oc = ConnectManager.Create(); MySqlCommand _cmdGetSysRoleFunction = cmdGetSysRoleFunction.Clone() as MySqlCommand; _cmdGetSysRoleFunction.Connection = oc; try { _cmdGetSysRoleFunction.Parameters["@SysRoleFunctionId"].Value = SysRoleFunctionId; if (oc.State == ConnectionState.Closed) { oc.Open(); } MySqlDataReader reader = _cmdGetSysRoleFunction.ExecuteReader(); if (reader.HasRows) { reader.Read(); returnValue = new SysRoleFunction().BuildSampleEntity(reader); } } finally { oc.Close(); oc.Dispose(); oc = null; _cmdGetSysRoleFunction.Dispose(); _cmdGetSysRoleFunction = null; GC.Collect(); } return(returnValue); }
/// <summary> /// 添加数据 /// <param name="es">数据实体对象数组</param> /// <returns></returns> /// </summary> public int Insert(SysRoleFunction e) { MySqlConnection oc = ConnectManager.Create(); MySqlCommand _cmdInsertSysRoleFunction = cmdInsertSysRoleFunction.Clone() as MySqlCommand; int returnValue = 0; _cmdInsertSysRoleFunction.Connection = oc; try { if (oc.State == ConnectionState.Closed) { oc.Open(); } _cmdInsertSysRoleFunction.Parameters["@RoleId"].Value = e.RoleId; _cmdInsertSysRoleFunction.Parameters["@FunctionId"].Value = e.FunctionId; _cmdInsertSysRoleFunction.Parameters["@EntId"].Value = e.EntId; _cmdInsertSysRoleFunction.ExecuteNonQuery(); returnValue = Convert.ToInt32(_cmdInsertSysRoleFunction.LastInsertedId); return(returnValue); } finally { oc.Close(); oc.Dispose(); oc = null; _cmdInsertSysRoleFunction.Dispose(); _cmdInsertSysRoleFunction = null; } }
//初始化企业权限(后期改为异步) private void initEntRole(int entId) { try { if (roleXmlModel == null) { string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "Config/Role.xml"; if (System.IO.File.Exists(filePath) == false) { throw new FileNotFoundException("默认权限模板配置文件没有找到", filePath); } string roleConfig = System.IO.File.ReadAllText(filePath); roleXmlModel = new XmlDocument(); roleXmlModel.LoadXml(roleConfig); } int newadminId = 0; foreach (XmlNode rolenode in roleXmlModel.SelectNodes("//role")) { string rolenodename = rolenode.Attributes["name"].Value; //添加企业角色 SysRole erole = new SysRole(); erole.EntId = entId; erole.FatherId = 0; erole.RoleName = rolenodename; int eroleid = SysRoleAccessor.Instance.Insert(erole); if (rolenodename == "管理员") { newadminId = eroleid; } foreach (XmlNode fathernode in rolenode.ChildNodes) { string fnname = fathernode.Attributes["name"].Value; string fnid = fathernode.Attributes["id"].Value; //添加企业角色权限 SysRoleFunction frf = new SysRoleFunction(); frf.EntId = entId; frf.RoleId = eroleid; frf.FunctionId = Convert.ToInt32(fnid); SysRoleFunctionAccessor.Instance.Insert(frf); foreach (XmlNode sonnode in fathernode.ChildNodes) { string sname = sonnode.Attributes["name"].Value; string sid = sonnode.Attributes["id"].Value; SysRoleFunction srf = new SysRoleFunction(); srf.EntId = entId; srf.RoleId = eroleid; srf.FunctionId = Convert.ToInt32(sid); SysRoleFunctionAccessor.Instance.Insert(srf); } } } SysRoleUser ru = new SysRoleUser(); ru.EntId = entId; ru.UserId = entId; ru.RoleId = newadminId; SysRoleUserAccessor.Instance.Insert(ru); } catch { throw new InvalidDataException("权限模板配置文件内容不正确"); } }