GetBlogThreads

博客提到一个函数,其参数为BlogThreadQuery类型的自定义对象变量,返回值为ThreadSet类型的自定义对象变量,还给出了转载来源。

函数参数为BlogThreadQuery类型的自定义对象变量
函数返回为ThreadSet类型的自定义对象变量

ContractedBlock.gif ExpandedBlockStart.gif GetBlogThreads
None.gif    public override ThreadSet GetBlogThreads(BlogThreadQuery query)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif{
InBlock.gif        
using( SqlConnection connection = GetSqlConnection() ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
using(SqlCommand command = new SqlCommand(databaseOwner + ".cs_weblog_Posts_GetPostSet", connection))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                command.CommandType 
= CommandType.StoredProcedure;
InBlock.gif
InBlock.gif                
//以下各行代码下面的注释:第一行为例子时的值,第二行开始为个人注释
InBlock.gif
                command.Parameters.Add("@SectionID", SqlDbType.Int).Value = query.BlogID;
InBlock.gif                
// 14    
InBlock.gif                
//实际意义为:氯胺酮的Blog(自己建立的)
InBlock.gif                
//如果是论坛,则为版块的ID
InBlock.gif                
//ps:GroupID为版块集合区的ID,就是说,一个Group下面有多个Section
InBlock.gif
            
InBlock.gif                command.Parameters.Add(
"@PageIndex", SqlDbType.Int, 4).Value = query.PageIndex;
InBlock.gif                
//0
InBlock.gif

InBlock.gif                command.Parameters.Add(
"@PageSize", SqlDbType.Int, 4).Value = query.PageSize;
InBlock.gif                
//15
InBlock.gif

InBlock.gif                command.Parameters.Add(
"@sqlPopulate", SqlDbType.NText).Value = SqlGenerator.BuildBlogThreadQuery(query,databaseOwner);
InBlock.gif                
//SET Transaction Isolation Level Read UNCOMMITTED Select  top 15 P.PostID From dbo.cs_Posts P, dbo.cs_weblog_Posts B  where  P.SectionID = 14 and  B.PostID = P.PostID and P.PostLevel = 1 and B.BlogPostType & 1 <> 0    and P.SettingsID = 1000 and B.SettingsID = 1000  and B.PostConfig & 1 = 1  and P.IsApproved = 1 and P.PostDate <= getdate()   Order by P.PostDate desc
InBlock.gif

InBlock.gif                command.Parameters.Add(
"@UserID", SqlDbType.Int).Value = query.UserID;
InBlock.gif                
// 2105    
InBlock.gif                
//怎样从GUID换算成这么一个int?
InBlock.gif                
//是否每次不一样?经过第二次跟踪每次一样
InBlock.gif                
//好像不是经过换算,跟踪其他用户的ID,发现在我公司起的这个CS里,每个userid都是从21开头,4位整数
InBlock.gif                
//2101,2102,2105。。。
InBlock.gif

InBlock.gif                command.Parameters.Add(
"@IncludeCategories", SqlDbType.Bit).Value = query.IncludeCategories;
InBlock.gif                
//false
InBlock.gif

InBlock.gif                command.Parameters.Add(
"@TotalRecords", SqlDbType.Int).Direction = ParameterDirection.Output;
InBlock.gif                command.Parameters.Add(SettingsIDParameter());
InBlock.gif
InBlock.gif                ThreadSet ts 
= new ThreadSet();
InBlock.gif
InBlock.gif                
// Execute the command
InBlock.gif                
InBlock.gif                
//If we want to display the list of categories for the post, we will need to 
InBlock.gif                
//use a dataset so we can join the child records
InBlock.gif
                if(query.IncludeCategories)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    DataSet ds 
= new DataSet();
InBlock.gif                    SqlDataAdapter da 
= new SqlDataAdapter(command);
InBlock.gif
InBlock.gif                    
//wait as long as possible to open the conn
InBlock.gif
                    connection.Open();
InBlock.gif                    da.Fill(ds);
InBlock.gif                    connection.Close();
InBlock.gif
InBlock.gif                    
//keep a referece to the relation since it is used in the GetChildRows look up anyway
InBlock.gif
                    DataRelation relation = new DataRelation("Categories",ds.Tables[0].Columns["PostID"],ds.Tables[1].Columns["PostID"],false);
InBlock.gif                    ds.Relations.Add(relation);
InBlock.gif                    
InBlock.gif                    DataRowCollection posts 
= ds.Tables[0].Rows;
InBlock.gif                    
foreach(DataRow dr in posts)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        ts.Threads.Add(PopulateWeblogPostContentFromDataRow(dr,relation));
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    ds.Clear();
InBlock.gif                    ds.Dispose();
InBlock.gif
InBlock.gif                    ts.TotalRecords 
= (int) command.Parameters["@TotalRecords"].Value;
InBlock.gif
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//No categories needed, so we can use a datareader.
InBlock.gif

InBlock.gif                    connection.Open();
InBlock.gif                    
using(SqlDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection))
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                    
InBlock.gif                        
while(dr.Read())
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            ts.Threads.Add(PopulateWeblogPostContentFromIDataReader(dr));
ExpandedSubBlockEnd.gif                        }

InBlock.gif
InBlock.gif                        
//                            if(query.IncludeCategories)
InBlock.gif                        
//                                dr.NextResult();
InBlock.gif

InBlock.gif                        dr.NextResult();
InBlock.gif                        ts.TotalRecords 
= (int) command.Parameters["@TotalRecords"].Value;
InBlock.gif                
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                
return ts;
InBlock.gif
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

转载于:https://www.cnblogs.com/konimeter/archive/2005/10/19/257739.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值