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

📄 weblogsqldataprovider.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
📖 第 1 页 / 共 3 页
字号:

                // Get the permissions
                //
                if (dr.NextResult()) 
                {

                    while (dr.Read()) 
                    {
                        // Get the forum
                        //
                        string appKey = dr["ApplicationKey"] as string;

						// Specific permissions
						if (appKey != null) {
							w = weblogs[appKey.ToLower()] as Weblog;
							if(w != null) {
								WeblogPermission bp = new WeblogPermission();
								CommonDataProvider.PopulatePermissionFromIDataReader( bp, dr );
								w.PermissionSet.Add(bp.Name, bp);
							}
						} else {

							// Global permissions
							WeblogPermission bp = new WeblogPermission();
							CommonDataProvider.PopulatePermissionFromIDataReader( bp, dr );

							foreach (Weblog wb in weblogs.Values) {
								if(!wb.PermissionSet.ContainsKey(bp.Name))
								wb.PermissionSet.Add(bp.Name,bp);
							}

						}

                    }


                }

             
            
                // Done with the reader and the connection
                //
                dr.Close();
                myConnection.Close();

            }
            return weblogs;
	    }
        #endregion

        #region GetBlogPermissions

        /// <summary>
        /// Returns the permissions for a specific Weblog
        /// </summary>
	    public override ArrayList GetBlogPermissions(int weblogID)
	    {
            // Create Instance of Connection and Command Object
            using( SqlConnection myConnection = GetSqlConnection() ) 
            {
                SqlCommand myCommand = new SqlCommand(databaseOwner + ".cs_Section_Permissions_Get", myConnection);
                Hashtable blogPermissions = new Hashtable();
                SqlDataReader reader;

                // Mark the Command as a SPROC
                myCommand.CommandType = CommandType.StoredProcedure;

                // Add Parameters to SPROC
                myCommand.Parameters.Add("@SectionID", SqlDbType.Int, 4).Value = weblogID;
                myCommand.Parameters.Add("@ApplicationType", SqlDbType.TinyInt).Value = ApplicationType.Weblog;
                myCommand.Parameters.Add(this.SettingsIDParameter());
                

                myConnection.Open();

                using(reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection | CommandBehavior.SingleResult))
                {


                    while(reader.Read()) 
                    {
                        WeblogPermission bp = new WeblogPermission();
                        CommonDataProvider.PopulatePermissionFromIDataReader(bp,reader);

                        // Merge the permission
                        if (blogPermissions[bp.RoleID] != null) 
                        {

                        } 
                        else 
                        {
                            blogPermissions.Add(bp.RoleID, bp);
                        }

                    }
                }

                myConnection.Close();


				return new ArrayList(blogPermissions.Values);

			}
	    }
        #endregion

        #region GetFeedback
        /// <summary>
        /// Returns blog comments/trackbacks
        /// </summary>
        public override ArrayList GetFeedback(int forumID, int pageIndex, int pageSize, out int totalRecords)
        {
            ArrayList feedback = new ArrayList();

            using ( SqlConnection cn = GetSqlConnection() )
            using ( SqlCommand cmd = new SqlCommand( databaseOwner + ".cs_weblog_Feedback_Get", cn ) ) 
            {
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@SectionID", SqlDbType.Int).Value = forumID;
                cmd.Parameters.Add(this.SettingsIDParameter());
                cmd.Parameters.Add("@TotalRecords", SqlDbType.Int ).Direction = ParameterDirection.Output;
                if ( pageSize > 0 ) 
                {
                    cmd.Parameters.Add( "@UsePaging", SqlDbType.Bit ).Value = true;
                    cmd.Parameters.Add( "@PageSize", SqlDbType.Int ).Value = pageSize;
                    cmd.Parameters.Add( "@PageIndex", SqlDbType.Int ).Value = pageIndex;
                }
				
                cn.Open();
                using(SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                {

                    // PostID, PostAuthor, Subject, PostDate, IsApproved, PostName, TitleUrl
                    while ( dr.Read() ) 
                    {
                        BlogFeedbackItem item = new BlogFeedbackItem();
					
                        item.PostID = (Int32)dr[ "PostID" ];
                        item.PostAuthor = (String)dr[ "PostAuthor" ];
                        item.Subject = (String)dr[ "Subject" ];
                        item.IsApproved = (Boolean)dr[ "IsApproved" ];
                        item.TitleUrl = dr[ "TitleUrl" ] as String;
                        item.PostDate = (DateTime)dr[ "PostDate" ];
                        item.Body = dr[ "Body" ] as String;

                        feedback.Add( item );
                    }

                    dr.Close();
                }
                cn.Close();
                totalRecords = (Int32)cmd.Parameters[ "@TotalRecords" ].Value;

               
            }

            return feedback;
        }
        #endregion

        #region Search

        public override PostSet SearchReindexPosts (int setsize, int settingsID) 
        {
            PostSet postSet = new PostSet();

            using(SqlConnection myConnection = GetSqlConnection()) 
            {
                SqlCommand myCommand = new SqlCommand(databaseOwner + ".cs_weblog_Search_PostReindex", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.Parameters.Add("@RowCount", SqlDbType.Int).Value = setsize;
                myCommand.Parameters.Add("@SettingsID",SqlDbType.Int,4).Value = settingsID;
                
                myConnection.Open();
                using(SqlDataReader dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection | CommandBehavior.SingleResult)) 
                {
                    
                    while(dr.Read())
                    {
                        WeblogPost wp = PopulateWeblogEntryFromIDataReader(dr);
                        //PopulateWeblogEntryFromIDataReader(dr,wp);
                        postSet.Posts.Add(wp);
                    }
                    dr.Close();
                }

                // Close the connection
                myConnection.Close();
                return postSet;
            }
        }



        public override SearchResultSet GetSearchResults(SearchQuery query, SearchTerms terms) 
        {
			//            string searchSQL = null;
			//            string recordCount = null;

			// Modified by backend@gmail.com
			//string searchSQL = SqlGenerator.SearchText(query,terms,GetSettingsID(),ApplicationType.Weblog);//,out searchSQL,out recordCount);
			// Modified by backend@gmail.com
			string searchSQL;

			int settingsID = GetSettingsID();
			ApplicationType appType = CSContext.Current.ApplicationType;
			if (appType == ApplicationType.Unknown)
				appType = ApplicationType.Forum; // Trick: Search forums by default?
			SearchMode searchMode = SiteSettingsManager.GetSiteSettings().SearchMode;

			switch (searchMode)
			{
				case SearchMode.ForumsIndexer:
					searchSQL = SqlGenerator.GetSearchCSIndexerSQL(query, terms, settingsID, appType);
					break;
				case SearchMode.SqlServerFullText:
					searchSQL = SqlGenerator.GetSearchFullTextSQL(query, terms, settingsID, appType);
					break;
				case SearchMode.Simple:
				default:
					searchSQL = SqlGenerator.GetSearchSimpleSQL(query, terms, settingsID, appType);
					break;
			}

            SearchResultSet result = new SearchResultSet();
            DateTime searchDuration;
            using( SqlConnection connection = GetSqlConnection() ) 
            {
                SqlCommand command = new SqlCommand("cs_weblog_Search", connection);
                SqlDataReader reader;

                // Mark as stored procedure
                command.CommandType = CommandType.StoredProcedure;

                // Add parameters
                command.Parameters.Add("@SearchSQL", SqlDbType.NText).Value = searchSQL;
                //command.Parameters.Add("@RecordCountSQL", SqlDbType.NVarChar, 4000).Value = recordCount;
                command.Parameters.Add("@PageIndex", SqlDbType.Int).Value = query.PageIndex;
                command.Parameters.Add("@PageSize", SqlDbType.Int).Value = query.PageSize;
                command.Parameters.Add(this.SettingsIDParameter());

                connection.Open();
                using(reader = command.ExecuteReader(CommandBehavior.CloseConnection))
                {

                    // Process first record set 
                    //
                    while (reader.Read()) 
                    {
                        WeblogPost p = PopulateWeblogEntryFromIDataReader(reader);

                        //PopulateWeblogSingleEntryFromIDataReader(reader,p);
                        result.Posts.Add(p);

                    }

                    // Move to the next result
                    //
                    if (reader.NextResult()) 
                    {
                        reader.Read();
                        result.TotalRecords = Convert.ToInt32(reader[0]);
                    }

                    // Get the duration of the search?
                    //
                    if (reader.NextResult()) 
                    {
                        reader.Read();

                        searchDuration = (DateTime) reader["Duration"];

                        // Calculate the number of seconds it took the search to execute
                        //
                        int ms = Convert.ToInt32(searchDuration.ToString("ff"));
                        result.SearchDuration = (double) ms / 1000;
                    }
                    reader.Close();
                }

                connection.Close();

                return result;
            }
        }



        #endregion

        public override void UpdateRecentContent(int SettingsID)
        {
            using(SqlConnection conn = GetSqlConnection())
            {
                using(SqlCommand command = new SqlCommand(databaseOwner + ".cs_weblog_UpdateWeblogRecentContent_Job", conn))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add("@SettingsID", SqlDbType.Int,4).Value = SettingsID;
                    conn.Open();
                    command.ExecuteNonQuery();
                    conn.Close();
                    command.Dispose();
                }
            }
        }
        private static object DBValue(string text)
        {
            if(!Globals.IsNullorEmpty(text))
                return text;
            else
                return DBNull.Value;
        }
	}
}

⌨️ 快捷键说明

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