示例#1
0
		public static  string GetTypeInfo(int id, out string extension, out string contentType, out bool showInBrowser)
		{
			Database db = new Database();
			OleDbCommand cmd = db.Connection.CreateCommand();
			cmd.CommandText = "select * from FileTypes where id = " + id.ToString();
			OleDbDataReader reader = cmd.ExecuteReader();
			string typeName = "";
			extension = "";
			contentType = "";
			showInBrowser = false;
			if(reader.Read())
			{
				typeName = (string) reader["Name"];
				extension = (string) reader["Extension"];
				contentType = (string) reader["ContentType"];
				showInBrowser = DbConvert.ToBoolean(reader["ShowInBrowser"]);
			}
			
			reader.Close();
			cmd.Dispose();

			if(typeName == null || typeName == "")
				throw new BipFatalException();
			return typeName;
		}
示例#2
0
		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;
		}
示例#3
0
		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;		
		}
示例#4
0
		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;
		}
示例#5
0
		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;
		}
示例#6
0
		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;
		}
示例#7
0
		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;
		}
示例#8
0
		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;
		}
示例#9
0
		protected static string GetEntityName(string tableName, int id)
		{
			Database db = new Database();
			OleDbCommand cmd = db.Connection.CreateCommand();
			string commandText = "select * from " + tableName + " where id = " + id.ToString();
			OleDbDataReader reader = cmd.ExecuteReader();
			string res = "";
			if(reader.Read())
				res = (string)reader[0];

			reader.Close();
			cmd.Dispose();
			return res;
		}
示例#10
0
		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;
		}
示例#11
0
		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;
		}
示例#12
0
		public void Dispose() 
		{
			// make sure connection is closed
			if (Db != null) 
			{
				Db.Dispose();
				Db = null;
			}				
		}