Wednesday, January 27, 2010

Default.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Mobile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Spaces;
using System.Web.Caching;
using System.Text;
using System.Collections.Generic;
public partial class _Default : System.Web.UI.MobileControls.MobilePage
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Browser["IsMobileDevice"] != "true")
{
// Response.Redirect("http://www.bfor.cn");
}


listNewTopics.ItemDataBind += new ListDataBindEventHandler(listNewTopics_ItemDataBind);
if (!IsPostBack)
{
// Response.Write(Config.GetConfig().Providers[Config.GetConfig().DefaultProvider].Attributes["connectionString"]);
// Response.End();
string key = "wap_index";
List list = IFCache.Get(key) as List;
if (list == null)
{
WeblogQuery q = new WeblogQuery();
q.Order = SortOrder.Descending;
q.PostType = PostType.BlogPost;
q.SortBy = WeblogsBy.DateUpdated;
q.PageIndex = 1;
q.PageSize = 12;
list = Blogs.SearchWeblogs(q);
IFCache.Insert(key, list, 6000);
}
// listNewTopics.Decoration = ListDecoration.Bulleted;
// listNewTopics.CustomAttributes.Add("align","left");
listNewTopics.DataSource = list; //GetNewTopics(6);
listNewTopics.DataBind();

StringBuilder sb = new StringBuilder();

sb.AppendFormat(SiteHelp.NavAFormat, "[4] 日志列表", "webloglist.aspx", "4");
sb.AppendFormat(SiteHelp.NavAFormat, "[6] 用户列表", "userlist.aspx", "6");
sb.AppendFormat(SiteHelp.NavAFormat, "[5] 中英词典", "dict.aspx", "5");
pnlNav.Controls.Add(new LiteralControl(sb.ToString()));
pnlOfPage.Controls.Add(new LiteralControl(SiteHelp.BottomNav()));
}
}

void listNewTopics_ItemDataBind(object sender, ListDataBindEventArgs e)
{
WeblogPost post = e.DataItem as WeblogPost;
if (post != null)
{
string title = post.Title ;
if (title.Length > 10)
{
e.ListItem.Text = title.Substring(0, 10) + "(" + post.FeedBackCount + ")" + "..";
}
else
{
e.ListItem.Text = title + "(" + post.FeedBackCount + ")";
}

e.ListItem.Value = GetPostURL(post.Account, post.ID);
}
}






void listTopics_ItemDataBind(object sender, ListDataBindEventArgs e)
{
WeblogPost post = e.DataItem as WeblogPost;
if (post != null)
{
string title = post.Title;
if (title.Length > 10)
{
e.ListItem.Text = title.Substring(0, 10) + "(" + post.FeedBackCount + ")" + "..";
}
else
{
e.ListItem.Text = title+ "(" + post.FeedBackCount + ")";
}

e.ListItem.Value = GetPostURL(post.Account,post.ID);
}

}

string GetPostURL(string account, int postID)
{
// string url =string.Format("{0}/users/viewpost.aspx?account={1}&postID={2}",Globals.ApplicationPath,account,postID);
string url = Globals.GetWapSiteUrls().BlogView(account,postID);
return url;

}
/*
#region 热门文章
public static DataView GetNewTopics(int count)
{

string key = string.Format("bfor_{0}_tt_HitTopic", count);
DataView dv = HttpRuntime.Cache[key] as DataView;
if (dv == null)
{
string sql = "";
switch (Config.GetConfig().DefaultProvider)
{
case "MySql":
sql = string.Format(@"SELECT t.FeedBackCount*3+t.WebCount as hits,t.ID,t.title,u.Account,u.NickName
FROM Blog_Content t
inner join blog_Config c on (t.BlogID=c.BlogID)
inner join Users u on (u.Account=c.Account)
order by hits desc limit 0,{0}", count);
break;
case "SqlServer":
sql = string.Format(@"select top {0} t.*,c.Account,u.NickName from blog_Content t inner join blog_Config c on(c.blogID=t.BlogID) inner join [Users] u on (u.Account=c.Account) where t.postType=1 and t.hiding<>1 and t.Author<>'系统' order by t.[DateAdded] desc", count);
break;
case "Access":
sql = string.Format(@"SELECT top {0} t.[FeedBackCount]*3+t.[WebCount] as hits,t.ID,t.title,u.Account,u.NickName
FROM ([Blog_Content] t
inner join [blog_Config] c on (t.BlogID=c.BlogID))
inner join [Users] u on (u.Account=c.Account)
order by t.[FeedBackCount]*3+t.[WebCount] desc", count);
break;

}

dv = SpacesDataProvider.Instance().GetDataView(string.Format(sql, count));
HttpRuntime.Cache.Add(key, dv, null, DateTime.Now.AddHours(3), TimeSpan.Zero, CacheItemPriority.Default, null);

}
return dv;

}
public static DataView GetHitTopicTop(int count)
{
string baseUrl = "Users/viewPost.aspx?account=";
string key = string.Format("bfor_{0}_tt_HitTopic", count);
DataView dv = HttpRuntime.Cache[key] as DataView;
if (dv == null)
{
string sql = "";
switch (Config.GetConfig().DefaultProvider)
{
case "MySql":
sql = string.Format(@"SELECT t.FeedBackCount*3+t.WebCount as hits,t.ID,t.title,u.Account,u.NickName
FROM Blog_Content t
inner join blog_Config c on (t.BlogID=c.BlogID)
inner join Users u on (u.Account=c.Account)
order by hits desc limit 0,{0}", count);
break;
case "SqlServer":
sql = string.Format(@"SELECT top {0} t.[FeedBackCount]*3+t.[WebCount] as hits,t.ID,t.title,u.Account,u.NickName
FROM [Blog_Content] t
inner join [blog_Config] c on (t.BlogID=c.BlogID)
inner join [Users] u on (u.Account=c.Account)
order by hits desc", count );
break;
case "Access":
sql = string.Format(@"SELECT top {0} t.[FeedBackCount]*3+t.[WebCount] as hits,t.ID,t.title,u.Account,u.NickName
FROM ([Blog_Content] t
inner join [blog_Config] c on (t.BlogID=c.BlogID))
inner join [Users] u on (u.Account=c.Account)
order by t.[FeedBackCount]*3+t.[WebCount] desc", count);
break;

}

dv = SpacesDataProvider.Instance().GetDataView(string.Format(sql, count));
HttpRuntime.Cache.Add(key, dv, null, DateTime.Now.AddHours(3), TimeSpan.Zero, CacheItemPriority.Default, null);

}
return dv;

}
#endregion
*/
}

No comments:

Post a Comment