public static DataTable FindAll() { Database db = new Database(); OleDbCommand cmd = db.Connection.CreateCommand(); string commandText = "select * from FileTypes"; OleDbDataAdapter adapter = new OleDbDataAdapter(commandText, db.Connection); DataTable table= new DataTable(); adapter.Fill(table); db.Dispose(); return table; }
public static bool Authenticate(string login, string password) { Database db = new Database(); System.Data.OleDb.OleDbConnection con = db.Connection; OleDbCommand cmd = con.CreateCommand(); cmd.CommandText = @"select count(1) from users where upper(login) = upper(?) and Password=?"; cmd.Parameters.Add(new OleDbParameter("login", login)); cmd.Parameters.Add(new OleDbParameter("password", password)); bool authenticated = (bool)((int)cmd.ExecuteScalar() > 0); cmd.Dispose(); db.Dispose(); return(authenticated); }
public void Dispose() { Db.Dispose(); }
public static DataTable FindUsers(int groupId) { Database db = new Database(); OleDbCommand cmd = db.Connection.CreateCommand(); string commandText = @"select * from users inner join usergroups on id=UserId where GroupId=" + groupId.ToString() + " order by login"; OleDbDataAdapter adapter = new OleDbDataAdapter(commandText, db.Connection); DataTable table= new DataTable(); adapter.Fill(table); db.Dispose(); return table; }
public static DataTable FindEnum(IEnumerable ids) { if(ids == null) return null; IEnumerator enum_ids = ids.GetEnumerator(); enum_ids.Reset(); if(!enum_ids.MoveNext()) return null; string securityConstraint = null; UserIdentity user = UserIdentity.Current; if(user.UserRole != UserRoles.Administrator && user.UserRole != UserRoles.SystemOperator) securityConstraint = " (IsPublic=1 or OwnerUserId= " + user.UserId.ToString() + @" or exists (select top 1 1 from UserGroups inner join DocGroups on UserGroups.GroupId = DocGroups.GroupId where DocGroups.DocId = Documents.id and UserGroups.UserId = " + user.UserId.ToString() + " )) "; string selectDocs = @" select * from documents where id in ( " + EnumUtils.ConvertToString(ids) + " ) "; if(securityConstraint != null) selectDocs += " and " + securityConstraint; DataTable res = new DataTable(); Database db = new Database(); OleDbDataAdapter adapter = new OleDbDataAdapter(selectDocs,db.Connection); adapter.Fill(res); db.Dispose(); return res; }
static public IEnumerable CanRead(IEnumerable ids) { if(ids == null) return null; IEnumerator enum_ids = ids.GetEnumerator(); enum_ids.Reset(); if(!enum_ids.MoveNext()) return ids; UserIdentity user = UserIdentity.Current; if(user.UserRole == UserRoles.Administrator || user.UserRole == UserRoles.SystemOperator) return ids; ArrayList res = new ArrayList(); Database db = new Database(); System.Data.OleDb.OleDbConnection con = db.Connection; OleDbCommand cmd = con.CreateCommand(); cmd.CommandText = @" select id from documents where id in ( " + EnumUtils.ConvertToString(ids) + @" ) and (IsPublic=1 or OwnerUserId= " + user.UserId.ToString() + @" or exists (select top 1 1 from UserGroups inner join DocGroups on UserGroups.GroupId = DocGroups.GroupId where DocGroups.DocId = Documents.id and UserGroups.UserId = " + user.UserId.ToString() + " ))"; OleDbDataReader reader = cmd.ExecuteReader(); while(reader.Read()) { res.Add(Convert.ToInt32(reader["id"])); } reader.Close(); cmd.Dispose(); db.Dispose(); return res; }
static public bool CanRead(int id) { UserIdentity user = UserIdentity.Current; if(user.UserRole == UserRoles.Administrator || user.UserRole == UserRoles.SystemOperator) return true; Database db = new Database(); System.Data.OleDb.OleDbConnection con = db.Connection; OleDbCommand cmd = con.CreateCommand(); cmd.CommandText = @"select count(1) from documents where id = " + id.ToString() + @" and( IsPublic=1 or OwnerUserId= " + user.UserId.ToString() + @" or exists (select top 1 1 from UserGroups inner join DocGroups on UserGroups.GroupId = DocGroups.GroupId where DocGroups.DocId = Documents.id and UserGroups.UserId = " + user.UserId.ToString() + " ))"; bool canRead = (bool)(((int)cmd.ExecuteScalar()) > 0 ); cmd.Dispose(); db.Dispose(); return canRead; }
public static bool Authenticate(string login, string password) { Database db = new Database(); System.Data.OleDb.OleDbConnection con = db.Connection; OleDbCommand cmd = con.CreateCommand(); cmd.CommandText = @"select count(1) from users where upper(login) = upper(?) and Password=?"; cmd.Parameters.Add(new OleDbParameter("login", login)); cmd.Parameters.Add(new OleDbParameter("password", password)); bool authenticated = (bool)((int) cmd.ExecuteScalar() > 0); cmd.Dispose(); db.Dispose(); return authenticated; }
public static int GetPrincipalInfo(string login, out string role) { Database db = new Database(); System.Data.OleDb.OleDbConnection con = db.Connection; OleDbCommand cmd = con.CreateCommand(); cmd.CommandText = @"select Id, Role from users where upper(login) = upper(?)"; cmd.Parameters.Add(new OleDbParameter("login", login)); OleDbDataReader reader = cmd.ExecuteReader(); if(!reader.Read()) { reader.Close(); cmd.Dispose(); db.Dispose(); role = ""; return 0; //throw new BipAccessDeniedException(); } role = (string)reader["Role"]; int id = Convert.ToInt32((Decimal)reader["Id"]); reader.Close(); cmd.Dispose(); db.Dispose(); return id; }
protected static DataTable FindEnumEntries(string tableName, IEnumerable ids) { if(ids == null) return null; IEnumerator enum_ids = ids.GetEnumerator(); enum_ids.Reset(); if(!enum_ids.MoveNext()) return null; Database db = new Database(); OleDbCommand cmd = db.Connection.CreateCommand(); string commandText = "select * from " + tableName + " where id in ( " + EnumUtils.ConvertToString(ids) + " ) " + " order by name "; OleDbDataAdapter adapter = new OleDbDataAdapter(commandText, db.Connection); DataTable table= new DataTable(); adapter.Fill(table); db.Dispose(); return table; }
protected static DataTable FindAllEntries(string tableName) { Database db = new Database(); OleDbCommand cmd = db.Connection.CreateCommand(); string commandText = "select * from " + tableName + " order by name"; OleDbDataAdapter adapter = new OleDbDataAdapter(commandText, db.Connection); DataTable table= new DataTable(); adapter.Fill(table); db.Dispose(); return table; }