/// <summary> /// Used to determine a Users Highest Privilege Authority /// </summary> /// <param name="UserID"></param> /// <returns></returns> internal SectionType GetUsersHighestAuthorityLevel(int UserID) { try { SectionType Temp = new SectionType(); int PreviousSectionType = 2147483645; SectionTypes UST = new SectionTypes(); //Users Section Types string sSQL = "SELECT * FROM tblSectionSectionRel WHERE SectionId = PrevSectionId"; DataTable DT = GetDataTable(sSQL); DataRow DR = DT.Rows[0]; int SysSectionID = Convert.ToInt32(DR[0]); Section SysSection = GetSection(SysSectionID); Sections SSS = null; if(SysSection.OwnerID != UserID) { SSS = GetAllContainingSections(UserID); } else { return SysSection.CreatedBySectionType; } //SqlDataAdapter DA = new SqlDataAdapter(sSQL,MC); //DataTable DT = new DataTable(); //DA.Fill(DT); //DA.Dispose(); foreach(Section S in SSS) { if(S.CreatedBySectionType.ID == SysSection.CreatedBySectionType.ID) { SectionType SST = SysSection.CreatedBySectionType.NextSectionType; UST.Add(SST); } else { int SectionTypeId = S.CreatedBySectionType.NextSectionTypeID; // int SectionTypeId = S.CreatedBySectionType.ID; if(SectionTypeId != -99) { SectionType ST = GetSectionType(SectionTypeId); UST.Add(ST); } } } //Compare the Section Types and return the Highest Ranking Type foreach(SectionType S in UST) { if(PreviousSectionType > S.PreviousSectionTypeID) { if(S.PreviousSectionTypeID == -99) { PreviousSectionType = S.ID; Temp = S; break; } else { PreviousSectionType = S.PreviousSectionTypeID; Temp = S; } } } //DT.Dispose(); return Temp; } catch(Exception Err) { throw new ApplicationException(Err.Message); } }
public void Add(SectionType X) { List.Add(X); }
/// <summary> /// Used by other functions to fill a SectionTypes object /// </summary> /// <param name="AST"></param> /// <returns></returns> internal bool FillSectionTypes(ref SectionTypes AST) { try { AST = new SectionTypes(); string sSQL = "Select ID, Name, Created, UniqueIdentifier, NextSectionTypeId," + " CreatesSectionTypeDescription, CreatesRootSection, PreviousSectionTypeId "+ "from tblSectionType ORDER BY PreviousSectionTypeId"; DataTable DT = GetDataTable(sSQL); if(DT.Rows.Count > 0) { foreach(DataRow R in DT.Rows) { SectionType ST = new SectionType(); ST.mvarID = Convert.ToInt32((object)R[0]); ST.mvarDescription = Convert.ToString((object)R[1]); ST.mvarCreatedDate = Convert.ToDateTime((object)R[2]); ST.mvarUniqueIdentifier = R[3].ToString(); ST.mvarNextSectionTypeID = Convert.ToInt32((object)R[4]); ST.mvarCreatesSectionTypeDescription = Convert.ToString((object)R[5]); ST.mvarCreatesRootSection = Convert.ToBoolean((object)R[6]); ST.mvarPreviousSectionTypeID = Convert.ToInt32((object)R[7]); FillPermissions(ref ST); AST.Add(ST); } } DT.Dispose(); } catch(Exception Err) { throw new ApplicationException(Err.Message); } return true; }
/// <summary> /// Used by other functions to fill the permissions of a SectionType object /// </summary> /// <param name="ST"></param> /// <returns></returns> internal bool FillPermissions(ref SectionType ST) { try { string sSQL = "Select * from tblSectionTypePermissionRel WHERE SectionTypeID = " + ST.mvarID.ToString(); DataTable DT = GetDataTable(sSQL); if(DT.Rows.Count > 0) { foreach(DataRow R in DT.Rows) { Permission P = new Permission(); P.mvarSectionTypeId = Convert.ToInt32((object)R[0]); P.mvarPermissionId = Convert.ToInt32((object)R[1]); P.mvarCanOperateOn = Convert.ToInt32((object)R[2]); P.mvarTargetSectionTypeId = Convert.ToInt32((object)R[2]); P.mvarDescription = GetPermissionDescription(P.mvarPermissionId); switch(P.mvarPermissionId) { case 1: ST.mvarCanCreateSectionTypes.Add(P); break; case 2: ST.mvarCanEditSectionTypes.Add(P); break; case 3: ST.mvarCanMoveSectionTypes.Add(P); break; case 4: ST.mvarCanRemoveSectionTypes.Add(P); break; case 5: ST.mvarCanCopyRecordings.Add(P); break; case 6: ST.mvarCanMoveRecordings.Add(P); break; case 7: ST.mvarCanDestroyRecordings.Add(P); break; case 8: ST.mvarCanDestroyAnyUsers.Add(P); break; case 9: ST.CanViewUnassignedRecordings.Add(P); break; } } } DT.Dispose(); } catch(Exception Err) { throw new ApplicationException(Err.Message); //return false; } return true; }
internal void CreateRootSection(int OwnerID) { //Create this new User a Default Section to house all new recordings //First Grab the System Section ID string sSQL = "SELECT DISTINCT tblSection.Id FROM tblSection LEFT OUTER JOIN tblSectionType ON tblSection.CreatedBySectionTypeId = " + "tblSectionType.Id WHERE PreviousSectionTypeId = -99 AND IsDefault = 0"; DataSet dsSection = GetDataSet(sSQL); DataRow r = dsSection.Tables[0].Rows[0]; int PrevSectionId = Convert.ToInt32(r[0]); dsSection.Dispose(); //Now Grab the lowest SectionType and Assign it as the default section type sSQL = "SELECT * FROM tblSectionType WHERE NextSectionTypeId = -99"; try { dsSection = GetDataSet(sSQL); } catch(Exception Err) { string error = Err.Message; } r = dsSection.Tables[0].Rows[0]; int LowestSectionTypeId = Convert.ToInt32(r[0]); dsSection.Dispose(); Section PrevS = GetSection(PrevSectionId); SectionType PrevST =new SectionType(); if(PrevS.CreatedBySectionType.NextSectionTypeID != -99) PrevST = GetSectionType(PrevS.CreatedBySectionType.NextSectionTypeID); else throw new ApplicationException("Last Section in Hierarchy cannot create new sections!"); SqlCommand sqlInsert = new SqlCommand(); // // sqlInsertCommand1 // Functions.RFConnection RF = this.GetAvailableConnection(); sqlInsert.CommandText = @"INSERT INTO tblSection(Name, OwnerId, IsRoot, CreatedBySectionTypeId, IsDefault) VALUES (@Name, @OwnerId, @IsRoot, @CreatedBySectionTypeId, @IsDefault); SELECT Name, OwnerId, IsRoot, CreatedBySectionTypeId, IsDefault, Id FROM tblSection WHERE (Id = @@IDENTITY)"; sqlInsert.Connection = RF.Connection; sqlInsert.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Name", System.Data.SqlDbType.VarChar, 255, "Name")); sqlInsert.Parameters.Add(new System.Data.SqlClient.SqlParameter("@OwnerId", System.Data.SqlDbType.Int, 4, "OwnerId")); sqlInsert.Parameters.Add(new System.Data.SqlClient.SqlParameter("@IsRoot", System.Data.SqlDbType.Bit, 1, "IsRoot")); sqlInsert.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CreatedBySectionTypeId", System.Data.SqlDbType.Int, 4, "CreatedBySectionTypeId")); sqlInsert.Parameters.Add(new System.Data.SqlClient.SqlParameter("@IsDefault", System.Data.SqlDbType.Bit, 1, "IsDefault")); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM tblSection",RF.Connection); da.InsertCommand = sqlInsert; da.Fill(ds); r = ds.Tables[0].NewRow(); r[1] = "System Generated"; r[2] = OwnerID; r[3] = DateTime.Now; r[4] = 0; r[6] = LowestSectionTypeId; r[7] = 1; ds.Tables[0].Rows.Add(r); da.Update(ds); int SectionId = Convert.ToInt32(r[0]); da.Dispose(); ds.Dispose(); RF.Release(); //Place NewSection in Hierarchy sSQL = "INSERT INTO tblSectionSectionRel(SectionId,PrevSectionId) VALUES(" + SectionId + ", " + PrevSectionId + "); SELECT * FROM tblSectionSectionRel"; int numrecs = ExecuteNonQuery(sSQL); }
public SectionType GetSectionType(int ID) { try { SectionType X = null; string sSQL = "Select * FROM tblSectionType WHERE ID = " + ID; DataTable DT = GetDataTable(sSQL); if(DT.Rows.Count > 0) { X = new SectionType(); DataRow r = DT.Rows[0]; X.mvarID = Convert.ToInt32((object)r[0]); X.mvarDescription = Convert.ToString((object)r[1]); X.mvarCreatedDate = Convert.ToDateTime((object)r[2]); X.mvarUniqueIdentifier = r[3].ToString(); X.mvarNextSectionTypeID = Convert.ToInt32((object)r[4]); X.mvarCreatesSectionTypeDescription = Convert.ToString((object)r[5]); X.mvarCreatesRootSection = Convert.ToBoolean((object)r[6]); X.mvarPreviousSectionTypeID = Convert.ToInt32((object)r[7]); //FillPermissions(ref X); } DT.Dispose(); return X; } catch(Exception Err) { throw new ApplicationException(Err.Message); } }
public int CreateSection(string Description, int OwnerID, int PrevSectionId) { Section PrevS = GetSection(PrevSectionId); SectionType PrevST =new SectionType(); if(PrevS.CreatedBySectionType.NextSectionTypeID != -99) PrevST = GetSectionType(PrevS.CreatedBySectionType.NextSectionTypeID); else throw new ApplicationException("Last Section in Hierarchy cannot create new sections!"); SqlCommand sqlInsert = new SqlCommand(); // // sqlInsertCommand1 // Functions.RFConnection RF = this.GetAvailableConnection(); sqlInsert.CommandText = @"INSERT INTO tblSection(Name, OwnerId, IsRoot, CreatedBySectionTypeId, IsDefault) VALUES (@Name, @OwnerId, @IsRoot, @CreatedBySectionTypeId, @IsDefault); SELECT Name, OwnerId, IsRoot, CreatedBySectionTypeId, IsDefault, Id FROM tblSection WHERE (Id = @@IDENTITY)"; sqlInsert.Connection = RF.Connection; sqlInsert.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Name", System.Data.SqlDbType.VarChar, 255, "Name")); sqlInsert.Parameters.Add(new System.Data.SqlClient.SqlParameter("@OwnerId", System.Data.SqlDbType.Int, 4, "OwnerId")); sqlInsert.Parameters.Add(new System.Data.SqlClient.SqlParameter("@IsRoot", System.Data.SqlDbType.Bit, 1, "IsRoot")); sqlInsert.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CreatedBySectionTypeId", System.Data.SqlDbType.Int, 4, "CreatedBySectionTypeId")); sqlInsert.Parameters.Add(new System.Data.SqlClient.SqlParameter("@IsDefault", System.Data.SqlDbType.Bit, 1, "IsDefault")); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM tblSection",RF.Connection); da.InsertCommand = sqlInsert; da.Fill(ds); DataRow r = ds.Tables[0].NewRow(); r[1] = Description; r[2] = OwnerID; r[3] = DateTime.Now; r[4] = 1; r[6] = PrevST.mvarID; r[7] = 0; ds.Tables[0].Rows.Add(r); da.Update(ds); da.Dispose(); ds.Dispose(); int SectionId = Convert.ToInt32(r[0]); RF.Release(); //Place NewSection in Hierarchy string sSQL = "INSERT INTO tblSectionSectionRel(SectionId,PrevSectionId) VALUES(" + SectionId + ", " + PrevSectionId + "); SELECT * FROM tblSectionSectionRel"; int numrecs = ExecuteNonQuery(sSQL); //Check to see if User needs to be added to PrevSection sSQL = "Select * FROM tblUserSectionRel WHERE UserId = " + OwnerID + " AND " + " SectionId = " + PrevSectionId; ds = GetDataSet(sSQL); if(ds.Tables[0].Rows.Count == 0) { try { sSQL = "INSERT INTO tblUserSectionRel(UserId,SectionId) VALUES(" + OwnerID + "," + PrevSectionId + ")"; numrecs = ExecuteNonQuery(sSQL); } catch(Exception Err) { string peekerror = Err.Message; } } return SectionId; }