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); }
public override void Load(int id) { System.Data.OleDb.OleDbConnection con = Db.Connection; OleDbCommand cmd = con.CreateCommand(); cmd.CommandText = @"select * from users where id =" + id.ToString(); OleDbDataReader reader = cmd.ExecuteReader(); if (!reader.Read()) { reader.Close(); cmd.Dispose(); throw new BipObjectNotFoundException(); } m_Login = (string)reader["Login"]; m_Password = DbConvert.ToString(reader["Password"]); m_FirstName = DbConvert.ToString(reader["FirstName"]); m_LastName = DbConvert.ToString(reader["LastName"]); m_Email = DbConvert.ToString(reader["Email"]); m_Role = DbConvert.ToString(reader["Role"]); m_Id = id; cmd.CommandText = @"select GroupId from usergroups where Userid =" + id.ToString(); reader.Close(); reader = cmd.ExecuteReader(); ArrayList groups = new ArrayList(); while (reader.Read()) { groups.Add(Convert.ToInt32(reader.GetDecimal(0))); } reader.Close(); cmd.Dispose(); if (groups.Count != 0) { m_Groups = groups; } else { m_Groups = null; } }
public override void Load(int id) { System.Data.OleDb.OleDbConnection con = Db.Connection; OleDbCommand cmd = con.CreateCommand(); cmd.CommandText = "select IsPublic, OwnerUserId from documents where id = " + id.ToString(); OleDbDataReader reader = cmd.ExecuteReader(); if (!reader.Read()) { reader.Close(); throw new BipObjectNotFoundException(); } int ownerUserId = DbConvert.ToInt32(reader["OwnerUserId"]); bool isPublic = DbConvert.ToBoolean(reader["IsPublic"]); reader.Close(); UserIdentity user = UserIdentity.Current; if (!( isPublic || user.UserRole == UserRoles.Administrator || user.UserRole == UserRoles.SystemOperator || user.UserRole == UserRoles.Operator && ownerUserId == user.UserId )) { cmd.CommandText = @"select top 1 1 from UserGroups inner join DocGroups on UserGroups.GroupId = DocGroups.GroupId where DocGroups.DocId = " + id.ToString() + " and UserGroups.UserId = " + user.UserId.ToString(); reader = cmd.ExecuteReader(); if (!reader.Read()) { reader.Close(); throw new BipAccessDeniedException(); } reader.Close(); } cmd.CommandText = @" select documents.*, IsRead=case when exists (select top 1 1 from UserReadDocs where DocId = Documents.Id and UserId=" + user.UserId.ToString() + @") then 1 else 0 end, IsFavorite=case when exists (select top 1 1 from UserFavoriteDocs where DocId = Documents.Id and UserId=" + user.UserId.ToString() + @") then 1 else 0 end from documents where documents.Id= " + id.ToString(); reader = cmd.ExecuteReader(); if (!reader.Read()) { throw new BipObjectNotFoundException(); } m_Id = id; m_CreationTime = DbConvert.ToDateTime(reader["CreationTime"]); m_FileTypeId = DbConvert.ToInt32(reader["FileType"]); m_SavedStorageFileName = DbConvert.ToString(reader["StorageFileName"]); m_FileName = DbConvert.ToString(reader["FileName"]); m_DateReceived = DbConvert.ToDateTime(reader["DateReceived"]); m_DocumentDate = DbConvert.ToDateTime(reader["DocumentDate"]); m_IncomingNumber = DbConvert.ToString(reader["IncomingNumber"]); m_OutgoingNumber = DbConvert.ToString(reader["OutgoingNumber"]); m_Subject = DbConvert.ToString(reader["Subject"]); m_Header = DbConvert.ToString(reader["Header"]); m_ArchiveFileNames = DbConvert.ToString(reader["ArchiveFileNames"]); m_DocTypeId = DbConvert.ToInt32(reader["DocTypeId"]); m_DocSourceId = DbConvert.ToInt32(reader["DocSourceId"]); m_DocCategoryId = DbConvert.ToInt32(reader["DocCategoryId"]); m_ParentId = DbConvert.ToInt32(reader["ParentId"]); m_PreviousVersionId = DbConvert.ToInt32(reader["PreviousVersionId"]); m_OwnerUserId = DbConvert.ToInt32(reader["OwnerUserId"]); m_IsPublic = DbConvert.ToBoolean(reader["IsPublic"]); m_IsRead = DbConvert.ToBoolean(reader["IsRead"]); m_IsFavorite = DbConvert.ToBoolean(reader["IsFavorite"]); reader.Close(); cmd.Dispose(); if (!CanRead(m_ParentId)) { m_ParentId = 0; } if (!CanRead(m_PreviousVersionId)) { m_PreviousVersionId = 0; } m_RefDocuments = CanRead(LoadDocRefs("DocRefRelated", "RelatedDocId")); m_Groups = LoadDocRefs("DocGroups", "GroupId"); m_SavedFileTypeId = m_FileTypeId; if (!m_IsRead) { MarkAsRead(); } }