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
*/
}

denglu.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Data.SqlClient;

//源码下载 www.51aspx.com
public partial class denglu : System.Web.UI.Page
{
IRCModel._IRCModel allUsers = new IRCModel._IRCModel();
IRCBLL._IRCBLL oneUsers = new IRCBLL._IRCBLL();
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
Label3.Visible = false;
Label4.Visible = false;
allUsers.ID = TextBox1.Text;
oneUsers.Log(allUsers);
try
{
Session["ID"] = Convert.ToString(oneUsers.Log(allUsers).Tables[0].Rows[0][0]);
}
catch
{
Label3.Visible = true;

}
allUsers.ID = Convert.ToString(Session["ID"]);

try
{
Session["name"] = Convert.ToString(oneUsers.Log(allUsers).Tables[0].Rows[0][2]);

}
catch
{
Label3.Visible = true;
}
allUsers.Pwd = TextBox2.Text;
if (oneUsers.password(allUsers))
{
allUsers.ID = TextBox1.Text;
if (oneUsers.update1(allUsers))
{
Application.Set("jilu", Application["jilu"] + "
" + "欢迎" + Convert.ToString(Session["name"]) + "进入聊天室");
Response.Redirect("Default.aspx");
}


else
{
Label4.Visible = true;
}



}
}
}

Default.aspx.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
HttpPostedFile hpf = uploadImage.PostedFile;
//取得文件名,不含路径
char[] splitChar = { '\\' };
string[] FilenameArray = hpf.FileName.Split(splitChar);
string Filename = FilenameArray[FilenameArray.Length - 1].ToLower();
//将用户输入的水印文字处理
//string sMessage = lineStr(TextBox3.Text.Trim().ToString(), 20);

if (hpf.FileName.Length < 1)
{
Response.Write("请选择你要上传的图片文件");
return;
}
if (hpf.ContentType != "image/pjpeg" && hpf.ContentType != "image/gif")//5~1-a-s-p-x
{
Response.Write("只允许上传JPEG GIF文件");
return;
}
else
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(DateTime.Now.Year.ToString());
sb.Append(DateTime.Now.Month.ToString());
sb.Append(DateTime.Now.Day.ToString());
sb.Append(DateTime.Now.Hour.ToString());
sb.Append(DateTime.Now.Minute.ToString());
sb.Append(DateTime.Now.Second.ToString());

if (Filename.ToLower().EndsWith("gif"))
sb.Append(".gif");
else if (Filename.ToLower().EndsWith("jpg"))
sb.Append(".jpg");
else if (Filename.ToLower().EndsWith("jpeg"))
sb.Append(".jpeg");
Filename = sb.ToString();

//保存图片到服务器上
try
{
hpf.SaveAs(Server.MapPath("~") + "/Image/" + Filename);
}
catch (Exception ee)
{
Response.Write("上传图片失败,原因:" + ee.Message);
return;
}

//生成缩略图
//原始图片名称
string originalFilename = hpf.FileName;
//生成高质量图片名称
string strFile = Server.MapPath("~") + "/Image/Small_" + Filename;

//从文件获取图片对象
System.Drawing.Image image = System.Drawing.Image.FromStream(hpf.InputStream, true);

Double Width = Double.Parse(TextBox1.Text.Trim());
Double Height = Double.Parse(TextBox2.Text.Trim());
System.Double newWidth, newHeight;
if (image.Width > image.Height)
{
newWidth = Width;
newHeight = image.Height * (newWidth / image.Width);
}
else
{
newHeight = Height;
newWidth = image.Width * (newHeight / image.Height);
}
if (newWidth > Width)
newWidth = Width;
if (newHeight > Height)
newHeight = Height;
System.Drawing.Size size = new System.Drawing.Size((int)newWidth, (int)newHeight); //设置图片的宽度和高度
System.Drawing.Image bitmap = new System.Drawing.Bitmap(size.Width, size.Height); //新建bmp图片
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); //新建画板
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //制定高质量插值法
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //设置高质量、低速度呈现平滑程度
g.Clear(System.Drawing.Color.White); //清空画布
//在制定位置画图
g.DrawImage(image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), new System.Drawing.Rectangle(0, 0, image.Width, image.Height), System.Drawing.GraphicsUnit.Pixel);


//文字水印
System.Drawing.Graphics testGrahpics = System.Drawing.Graphics.FromImage(bitmap);
System.Drawing.Font font = new System.Drawing.Font("宋体", 10);
System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);

//分行
string sInput = TextBox3.Text.Trim().ToString(); //获取输入的水印文字
int coloum = Convert.ToInt32(TextBox4.Text); //获取每行的字符数
//利用循环,来依次输出
for (int i = 0, j = 0; i < sInput.Length; i += coloum, j++)
{
//若要修改水印文字在照片上的位置,可将20修改成你想要的任何值
if (j != sInput.Length / coloum)
{
string s = sInput.Substring(i, coloum);
testGrahpics.DrawString(s, font, brush, 20, 20 * (i / coloum + 1));
}
else
{
string s = sInput.Substring(i, sInput.Length % coloum);
testGrahpics.DrawString(s, font, brush, 20, 20*(j+1));

}
}
testGrahpics.Dispose();
//保存缩略图c
try
{
bitmap.Save(strFile, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{
Response.Write("保存缩略图失败" + ex.Message);
}
//释放资源
g.Dispose();
bitmap.Dispose();
image.Dispose();

}
}
}

createThumbnails.sln

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "E:\...\WebSite1\", ".", "{4D38B06D-5A67-4599-B54D-CA67A79D10A7}"
ProjectSection(WebsiteProperties) = preProject
Debug.AspNetCompiler.VirtualPath = "/WebSite1"
Debug.AspNetCompiler.PhysicalPath = "E:\项目\未分类\WebSite1\"
Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\WebSite1\"
Debug.AspNetCompiler.Updateable = "true"
Debug.AspNetCompiler.ForceOverwrite = "true"
Debug.AspNetCompiler.FixedNames = "false"
Debug.AspNetCompiler.Debug = "True"
Release.AspNetCompiler.VirtualPath = "/WebSite1"
Release.AspNetCompiler.PhysicalPath = "E:\项目\未分类\WebSite1\"
Release.AspNetCompiler.TargetPath = "PrecompiledWeb\WebSite1\"
Release.AspNetCompiler.Updateable = "true"
Release.AspNetCompiler.ForceOverwrite = "true"
Release.AspNetCompiler.FixedNames = "false"
Release.AspNetCompiler.Debug = "False"
VWDPort = "4669"
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|.NET = Debug|.NET
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4D38B06D-5A67-4599-B54D-CA67A79D10A7}.Debug|.NET.ActiveCfg = Debug|.NET
{4D38B06D-5A67-4599-B54D-CA67A79D10A7}.Debug|.NET.Build.0 = Debug|.NET
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

DrawHelper.cs

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

///
///DrawHelper 的摘要说明
///

public class DrawHelper
{
public DrawHelper()
{

}
//生成缩略图
public void CreateThumbnailImage(string sFileSrcPath, string sFileDstPath, int iSizeLimit)
{
//检测源图片是否存在
if (File.Exists(sFileSrcPath))
{
//获取源图片图像
System.Drawing.Image image = System.Drawing.Image.FromFile(sFileSrcPath);
//定义一个大小结构
SizeF size = new SizeF(image.Width, image.Height);
//计算出符合要求的大小
while (size.Width > iSizeLimit || size.Height > iSizeLimit)//51+aspx
{
size.Width /= 1.1F;
size.Height /= 1.1F;
}
//创建缩略图图像
Bitmap bitmap = new Bitmap(Convert.ToInt16(size.Width), Convert.ToInt16(size.Height));
//创建缩略图绘画面
Graphics g = Graphics.FromImage(bitmap);
//清除整个绘画面并以透明色填充
g.Clear(Color.Transparent);
//定义源图像矩形区域
Rectangle Srcrect = new Rectangle(0, 0, image.Width, image.Height);
//定义缩略图矩形区域
Rectangle Dstrect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
//绘制缩略图
g.DrawImage(bitmap, Dstrect, Srcrect, GraphicsUnit.Pixel);
//保存为Jpeg图片
bitmap.Save(sFileDstPath, ImageFormat.Jpeg);
//释放对象
g.Dispose();
image.Dispose();
bitmap.Dispose();

}
}
}