小说网(c#)版源程序,学习还是不错滴,大家可以下载下来看看.
源代码在线查看: pagetop.ascx.cs
using System;
using System.IO;
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;
public partial class _pagetop : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(_pagetop));
//Cookie登陆
if (Session.Contents["username"] == null && Request.Cookies["Qiezi"] != null)
{
Session.Contents["username"] = Request.Cookies["Qiezi"].Value;
Response.Cookies["Qiezi"].Value = Request.Cookies["Qiezi"].Value;
Response.Cookies["Qiezi"].HttpOnly = false;
Response.Cookies["Qiezi"].Expires = DateTime.Now.AddYears(1);
}
}
///
/// 用户登陆
///
///
///
protected void Button_Submit_Click(object sender, EventArgs e)
{
if (Session.Contents["validate"] == null)
{
Response.Write("alert('抱歉,页面停留时间过长,请重新填写!');");
return;
}
string username = Request.Form["Text_User"].ToString();
string password = Request.Form["Text_Password"].ToString();
string validate = Request.Form["Text_Validate"].ToString();
Md5Pw md5 = new Md5Pw();
if (validate == Session.Contents["validate"].ToString() && SqlStore.SqlUserLogin(username, md5.Md5(password)))
{
if (Request.Form["Check_Box"] != null)
{
Response.Cookies["Qiezi"].Value = username;
Response.Cookies["Qiezi"].HttpOnly = false;
Response.Cookies["Qiezi"].Expires = DateTime.Now.AddYears(1);
}
Session.Contents["username"] = username;
}
else
Response.Write("alert('抱歉,登陆失败!');");
}
///
/// 推荐小说
///
/// 小说id
///
[AjaxPro.AjaxMethod]
public string Commend(int topicid)
{
SqlStore.SqlAjax(topicid, 1, "");
return "true";
}
///
/// 添加Cookie书库
///
/// 小说id
/// 标题
///
[AjaxPro.AjaxMethod]
public string AddCookie(int topicid,string title)
{
SqlStore.SqlAjax(topicid, 5, "");
System.Web.HttpCookie newcookie = HttpContext.Current.Request.Cookies["topicid"];
if (newcookie == null) newcookie = HttpContext.Current.Response.Cookies["topicid"];
if (newcookie.Values.Count >= 50)
return "false";
newcookie.Values[topicid.ToString()] = HttpContext.Current.Server.UrlEncode(title);
newcookie.Expires = DateTime.Now.AddYears(1);
HttpContext.Current.Response.AppendCookie(newcookie);
return "true";
}
///
/// 添加书窝
///
/// 小说id
///
[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)]
public string AddSql(int topicid)
{
if (System.Web.HttpContext.Current.Session["username"] == null)
return "nologin";
else
{//值=101,超出100本; 值=111,该书已收藏; 值=1,添加成功
int mark = SqlStore.SqlLikeAdd(System.Web.HttpContext.Current.Session["username"].ToString(), topicid);
if (mark == 1)
return "success";
else if (mark == 101)
return "repeate";
else
return "sql>100";
}
}
///
/// 判断书窝是否有更新
///
///
[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)]
public string AddLikeUpdate()
{
if (System.Web.HttpContext.Current.Session["username"] != null && SqlStore.SqlLikeUpdate(System.Web.HttpContext.Current.Session["username"].ToString()))
return "true";
else
return "false";
}
///
/// 清空Cookie书库
///
///
[AjaxPro.AjaxMethod]
public void ClearCookie()
{
HttpContext.Current.Response.Cookies["topicid"].Expires = DateTime.Now.AddDays(-1);
}
///
/// 添加收藏夹,收藏数加一
///
/// 小说id
///
[AjaxPro.AjaxMethod]
public void Collection(int topicid)
{
SqlStore.SqlAjax(topicid, 5, "");
}
///
/// 返回章节内容
///
/// 小说id
/// 章节id
///
[AjaxPro.AjaxMethod]
public string Chapter(int topicid, int chapterid)
{
string title = "", author = "", content = "";
DataTable table = SqlStore.SqlChapterList(topicid, out title, out author);
for (int i = 0; i < table.Rows.Count; i++)
if (chapterid.ToString() == table.Rows[i]["chapterid"].ToString())
{
if (File.Exists(HttpContext.Current.Server.MapPath("chapter/" + table.Rows[i]["path"].ToString()).Replace(@"ajaxpro\", "")))
{
content = "" + table.Rows[i]["chapter"].ToString() + "" + File.ReadAllText(HttpContext.Current.Server.MapPath("chapter/" + table.Rows[i]["path"].ToString()).Replace(@"ajaxpro\", ""), System.Text.Encoding.Default)
+ "" + (i == 0 ? "上一章" : "上一章") + " 目录 " + (i + 1 == table.Rows.Count ? "下一章" : "下一章");
}
break;
}
if (content == "") content = "抱歉,未找到该章节!";
return content;
}
///
/// 返回所有章节内容
///
/// 小说id
///
[AjaxPro.AjaxMethod]
public string ChapterAll(int topicid)
{
string title = "", author = "", content = "";
DataTable table = SqlStore.SqlChapterList(topicid, out title, out author);
for (int i = 0; i < table.Rows.Count; i++)
if (File.Exists(HttpContext.Current.Server.MapPath("chapter/" + table.Rows[i]["path"].ToString()).Replace(@"ajaxpro\", "")))
content += "" + table.Rows[i]["chapter"].ToString() + "" + File.ReadAllText(HttpContext.Current.Server.MapPath("chapter/" + table.Rows[i]["path"].ToString()).Replace(@"ajaxpro\", ""), System.Text.Encoding.Default);
if (content == "") content = "抱歉,未找到该小说!";
return content;
}
///
/// 搜索
///
/// 搜索关键字
/// 搜索类别
///
[AjaxPro.AjaxMethod]
public string Search(string key, string type)
{
string content = "";
if (key != "" && (type == "novel" || type == "author"))
{
DataTable table = SqlStore.SqlSearch(key, type == "novel" ? true : false);
if (table.Rows.Count == 0)
content = "没有任何搜索结果";
for (int i = 0; i < table.Rows.Count; i++)
content += "" + table.Rows[i]["title"].ToString() + " [ "
+ table.Rows[i]["author"].ToString() + " | "
+ "" + table.Rows[i]["name"].ToString() + " | "
+ "" + table.Rows[i]["newchapter"].ToString().Split('|')[0] + " | "
+ table.Rows[i]["updatetime"].ToString() + "更新 "
+ "]"
+ table.Rows[i]["intro"].ToString()
+ "";
}
else
content = "抱歉,您输入有误!";
return content;
}
}