internal Rol getRolByname(string nombreRol) { Rol rol = null; try { // // Open the SqlConnection. // con.Open(); // // The following code uses an SqlCommand based on the SqlConnection. // SqlCommand cmd = new SqlCommand(String.Format("SELECT TOP 1 Id,Nombre,Habilitado FROM [GD2C2015].[JANADIAN_DATE].[Rol] r WHERE r.Nombre = '{0}' ", nombreRol), con); DataTable dt = new DataTable(); dt.TableName = "Tabla"; dt.Load(cmd.ExecuteReader()); if (dt.Rows.Count == 0) { con.Close(); return null; } foreach (DataRow Fila in dt.Rows) { rol = new Rol(Convert.ToInt32(Fila["Id"]), Convert.ToString(Fila["Nombre"]), Convert.ToBoolean(Fila["Habilitado"])); } con.Close(); } catch (Exception exAlta) { con.Close(); throw (new Exception(exAlta.ToString())); } return rol; }
internal void modificarRol(Rol rolSel) { try { con.Open(); SqlCommand updateRol = new SqlCommand(String.Format("UPDATE [GD2C2015].[JANADIAN_DATE].[Rol] SET Nombre='{0}',Habilitado={1} WHERE Id={2}", rolSel.getNombre, rolSel.getHabilitado ? "1" : "0", rolSel.getId), con); updateRol.ExecuteNonQuery(); SqlCommand deleteOldRol_Func = new SqlCommand(String.Format("DELETE FROM [GD2C2015].[JANADIAN_DATE].[Rol_Funcionalidad] where Rol={0}", rolSel.getId), con); deleteOldRol_Func.ExecuteNonQuery(); SqlCommand insertRol_Func = new SqlCommand(String.Format("INSERT INTO [GD2C2015].[JANADIAN_DATE].[Rol_Funcionalidad] (Rol,Funcionalidad) select r.Id,f.Id from [GD2C2015].[JANADIAN_DATE].[Funcionalidad] f , [GD2C2015].[JANADIAN_DATE].[Rol] r where f.Descripcion in ('{0}') and r.Id={1}", string.Join("','", rolSel.getFuncionalidades), rolSel.getId), con); insertRol_Func.ExecuteNonQuery(); con.Close(); } catch (Exception exAlta) { con.Close(); throw (new Exception(exAlta.ToString())); } }