⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sectionutility.cs

📁 一个ASP.NET下的中文内容管理和社区系统
💻 CS
📖 第 1 页 / 共 4 页
字号:
            // Setup db objects
            SqlConnection con = new SqlConnection(CommunityGlobals.ConnectionString);

            SqlCommand cmdDelete = new SqlCommand( "Community_SectionsDeleteSectionRoles", con);
            cmdDelete.CommandType = CommandType.StoredProcedure;
            cmdDelete.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
            cmdDelete.Parameters.Add("@sectionID", sectionID);
            cmdDelete.Parameters.Add("@roleType", sectionRoleType);

            SqlCommand cmdAdd = new SqlCommand( "Community_SectionsAddSectionRole", con);
            cmdAdd.CommandType = CommandType.StoredProcedure;
            cmdAdd.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
            cmdAdd.Parameters.Add("@sectionID", sectionID);
            cmdAdd.Parameters.Add("@roleType", sectionRoleType);
            cmdAdd.Parameters.Add("@role", SqlDbType.NVarChar);
           
            // Open connection
            con.Open();
            
            // Delete all roles from section of specified type
            cmdDelete.ExecuteNonQuery();
            
            // Add new roles
            foreach (string role in roles) {
                cmdAdd.Parameters["@role"].Value = role;
                cmdAdd.ExecuteNonQuery();
            }
            
            // close connection
            con.Close();
        }


        //*********************************************************************
        //
        // AddSectionWebBoxes Method
        //
        // Adds new web boxes to the Community_SectionWebBoxes table.
        //
        //*********************************************************************
        public static void AddSectionWebBoxes(int sectionID, string[] webBoxes) {
            // Setup db objects
            SqlConnection con = new SqlConnection(CommunityGlobals.ConnectionString);

            SqlCommand cmdDelete = new SqlCommand( "Community_SectionsDeleteSectionWebBoxes", con);
            cmdDelete.CommandType = CommandType.StoredProcedure;
            cmdDelete.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
            cmdDelete.Parameters.Add("@sectionID", sectionID);

            SqlCommand cmdAdd = new SqlCommand( "Community_SectionsAddSectionWebBox", con);
            cmdAdd.CommandType = CommandType.StoredProcedure;
            cmdAdd.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
            cmdAdd.Parameters.Add("@sectionID", sectionID);
            cmdAdd.Parameters.Add("@webBox", SqlDbType.NVarChar);
           
            // Open connection
            con.Open();
            
            // Delete all web boxes from section
            cmdDelete.ExecuteNonQuery();
            
            // Add new boxes
            foreach (string webBox in webBoxes) {
                cmdAdd.Parameters["@webBox"].Value = webBox;
                cmdAdd.ExecuteNonQuery();
            }
            
            // close connection
            con.Close();
        }




        //*********************************************************************
        //
        // AddSectionWebServiceBoxes Method
        //
        // Adds new web service boxes to the Community_SectionWebServiceBoxes table.
        //
        //*********************************************************************
        public static void AddSectionWebServiceBoxes(int sectionID, string[] webServiceBoxes) {
            // Setup db objects
            SqlConnection con = new SqlConnection(CommunityGlobals.ConnectionString);

            SqlCommand cmdDelete = new SqlCommand( "Community_SectionsDeleteSectionWebServiceBoxes", con);
            cmdDelete.CommandType = CommandType.StoredProcedure;
            cmdDelete.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
            cmdDelete.Parameters.Add("@sectionID", sectionID);

            SqlCommand cmdAdd = new SqlCommand( "Community_SectionsAddSectionWebServiceBox", con);
            cmdAdd.CommandType = CommandType.StoredProcedure;
            cmdAdd.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
            cmdAdd.Parameters.Add("@sectionID", sectionID);
            cmdAdd.Parameters.Add("@webServiceBox", SqlDbType.NVarChar);
           
            // Open connection
            con.Open();
            
            // Delete all roles from section of specified type
            cmdDelete.ExecuteNonQuery();
            
            // Add new roles
            foreach (string webServiceBox in webServiceBoxes) {
                cmdAdd.Parameters["@webServiceBox"].Value = webServiceBox;
                cmdAdd.ExecuteNonQuery();
            }
            
            // close connection
            con.Close();
        }



        //*********************************************************************
        //
        // AddSectionServiceSubscriptions Method
        //
        // Adds new services to the Community_SectionServiceSubscriptions table.
        //
        //*********************************************************************
        public static void AddSectionServiceSubscriptions(int sectionID, string[] serviceNames) {
            // Setup db objects
            SqlConnection con = new SqlConnection(CommunityGlobals.ConnectionString);

            SqlCommand cmdDelete = new SqlCommand( "Community_ServicesDeleteServiceSubscriptions", con);
            cmdDelete.CommandType = CommandType.StoredProcedure;
            cmdDelete.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
            cmdDelete.Parameters.Add("@sectionID", sectionID);

            SqlCommand cmdAdd = new SqlCommand( "Community_ServicesAddServiceSubscription", con);
            cmdAdd.CommandType = CommandType.StoredProcedure;
            cmdAdd.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
            cmdAdd.Parameters.Add("@sectionID", sectionID);
            cmdAdd.Parameters.Add("@serviceName", SqlDbType.NVarChar);
           
            // Open connection
            con.Open();
            
            // Delete all roles from section of specified type
            cmdDelete.ExecuteNonQuery();
            
            // Add new roles
            foreach (string name in serviceNames) {
                cmdAdd.Parameters["@serviceName"].Value = name;
                cmdAdd.ExecuteNonQuery();
            }
            
            // close connection
            con.Close();
        }



        //*********************************************************************
        //
        // GetSectionServiceSubscriptions Method
        //
        // Retrieves list of subscribed services to remote communities.
        //
        //*********************************************************************
        public static string[] GetSectionServiceSubscriptions(int sectionID) {
            ArrayList colSubscriptions = new ArrayList();
            
            // Setup db objects
            SqlConnection con = new SqlConnection(CommunityGlobals.ConnectionString);

            SqlCommand cmd = new SqlCommand( "Community_SectionsGetSectionServiceSubscriptions", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@sectionID", sectionID);
            
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            
            while (dr.Read())
                colSubscriptions.Add(dr["ss_name"]);
            con.Close();
            
            return (string[])colSubscriptions.ToArray(typeof(string));
        }




        //*********************************************************************
        //
        // GetAllEnabledSections Method
        //
        // Gets all enabled sections from the cache, or if that fails,
        // from the database. 
        //
        //*********************************************************************
        

        public static SectionCollection GetAllEnabledSections() {
            HttpContext Context = HttpContext.Current;

            SectionCollection sectionCollection = (SectionCollection)Context.Cache[ CommunityGlobals.CacheKey("Sections") ];
            if (sectionCollection == null) {
                sectionCollection = GetAllEnabledSectionsFromDB();
                Context.Cache[ CommunityGlobals.CacheKey("Sections") ] = sectionCollection;
            }
            return sectionCollection;
        }



        //*********************************************************************
        //
        // GetAllSectionsFromDB Method
        //
        // Returns all sections from the database.
        //
        //*********************************************************************
        
        public static DataSet GetAllSectionsFromDB() {
            SqlDataAdapter dadSections = new SqlDataAdapter( "Community_SectionsGetAllSections", CommunityGlobals.ConnectionString );
            dadSections.SelectCommand.CommandType = CommandType.StoredProcedure;
            dadSections.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );
            DataSet dstSections = new DataSet();
            dadSections.Fill( dstSections );
            DataTable dtblSections = dstSections.Tables[0];
            
            // Add section_path column to Section DataSet
            dtblSections.Columns.Add( "section_path" );
            
            // Calculate path for each section
            foreach (DataRow drowSection in dtblSections.Rows)
                drowSection["section_path"] = CalculateSectionPath( drowSection, dstSections );
            
            return dstSections;
        }





        //*********************************************************************
        //
        // GetAllEnabledSectionsFromDB Method
        //
        // Gets all enabled sections from the database.
        //
        //*********************************************************************
        
        public static SectionCollection GetAllEnabledSectionsFromDB() {
            SqlDataAdapter dadSections = new SqlDataAdapter( "Community_SectionsGetAllEnabledSections", CommunityGlobals.ConnectionString );
            dadSections.SelectCommand.CommandType = CommandType.StoredProcedure;
            dadSections.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );

            SqlDataAdapter dadSectionSecurity = new SqlDataAdapter( "Community_SectionsGetAllSectionRoles", CommunityGlobals.ConnectionString );
            dadSectionSecurity.SelectCommand.CommandType = CommandType.StoredProcedure;
            dadSectionSecurity.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );

            SqlDataAdapter dadSectionWebBoxes = new SqlDataAdapter( "Community_SectionsGetAllSectionWebBoxes", CommunityGlobals.ConnectionString );
            dadSectionWebBoxes.SelectCommand.CommandType = CommandType.StoredProcedure;
            dadSectionWebBoxes.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );

            SqlDataAdapter dadSectionWebServiceBoxes = new SqlDataAdapter( "Community_SectionsGetAllSectionWebServiceBoxes", CommunityGlobals.ConnectionString );
            dadSectionWebServiceBoxes.SelectCommand.CommandType = CommandType.StoredProcedure;
            dadSectionWebServiceBoxes.SelectCommand.Parameters.Add( "@communityID", CommunityGlobals.CommunityID );

            DataSet dstSections = new DataSet();
            dadSections.Fill( dstSections, "Sections" );
            dadSectionSecurity.Fill( dstSections, "SectionSecurity" );
            dadSectionWebBoxes.Fill( dstSections, "SectionWebBoxes" );
            dadSectionWebServiceBoxes.Fill( dstSections, "SectionWebServiceBoxes" );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -