Tuesday, January 26, 2010

SiteHelp.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Spaces;
using System.IO;

///
/// SiteHelp 的摘要说明
///

public class SiteHelp
{
public SiteHelp()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region 图片路径的处理
public static string GetImgUrl(Photo p)
{
string imgName = string.Format("{0}{1}",p.PhotoID, Path.GetExtension(p.SmallPic));
string cacheImg = GetImageCacheFullPath(p.Account, imgName);
if (File.Exists(cacheImg))
{
return GetImageCacheUrl(p.Account, imgName);
}
return string.Format("{0}/photo.ashx?u={1}&p={2}", Globals.ApplicationPath, p.Account, Des.Encrypt(p.PhotoID + "", "xiaoxiao"));
}
public static string GetImageCacheUrl(string account, string pid)
{
return string.Format("{0}/{1}/{2}", WapConfig.Get().ImageCacheUrl, account, pid);
}
public static string GetImageCacheFullPath(string account, string pid)
{
return string.Format("{0}\\{1}\\{2}", WapConfig.Get().ImageCachePath, account, pid);
}
public static string GetMainImg(PhotoCategory c)
{
string img = "";
if (c.MainPhotoID < 1) return img;
string imgName = string.Format("{0}{1}", c.MainPhotoID, Path.GetExtension(c.Image));
string cacheImg = GetImageCacheFullPath(c.Account, imgName);
if (File.Exists(cacheImg))
{
return GetImageCacheUrl(c.Account, imgName);
}
return string.Format("{0}/photo.ashx?u={1}&p={2}", Globals.ApplicationPath, c.Account, Des.Encrypt(c.MainPhotoID.ToString(), "xiaoxiao"));
}
#endregion
public const string NavAFormat = "{0}
";
const string nextPageFormat="[3]下一页";
const string prvPageFormat="[1]上一页";
public static string MakePager(string baseUrl,int curPage, int pageSize, int count)
{
StringBuilder sb = new StringBuilder();
string c = "?";
if (baseUrl.IndexOf("?") != -1)
c = "&";
if (curPage <= 1 )
{
if(pageSize >= count)
return string.Empty;

sb.AppendFormat(nextPageFormat,baseUrl+c+"page=2");
return sb.ToString();
}
sb.AppendFormat(prvPageFormat, baseUrl+c+"page=" + (curPage - 1));

if (count > (curPage * pageSize))
{
sb.Append(" ");
sb.AppendFormat(nextPageFormat, baseUrl+c+"page=" + (curPage + 1));
}
int pageCount=0;
if((count%pageSize)>0)
{
pageCount=(count/pageSize)+1;
}else
pageCount=(count/pageSize);

sb.AppendFormat("({0}/{1})",curPage,pageCount);
return sb.ToString();
}
public static string BottomNav()
{
StringBuilder sb = new StringBuilder();

sb.Append("[*] 页首
");
sb.Append("[#] 页尾
");
sb.AppendFormat("[0] I-Favourite首页
", HttpContext.Current.Response.ApplyAppPathModifier(Globals.GetWapSiteUrls().HomePage()));
return sb.ToString();
}


}

No comments:

Post a Comment