![]() |
#2
Maick2014-07-30 09:41
|
只有本站会员才能查看附件,请 登录

后台代码using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
namespace tengfeikeji.admin
{
/// <summary>
/// Insert 的摘要说明
/// </summary>
public class Insert : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
//获取Action是否是发布新闻还是编辑新闻
string Action = context.Request["Action"];
if (Action=="fabu")
{
//在发布新闻里面,如果tijiao不为空的话 就是添加信息
if (!string.IsNullOrEmpty(context.Request["tijiao"]))
{
string Name = context.Request["Name"];
int Category = Convert.ToInt32(context.Request["Category"]);
string Content = context.Request["content"];
Sqlhelper.ExecuteNonQuery("insert into T_xinwen(Name,Content,DataTime,categoryID) values(@Name,@Content,@DataTime,@Category)", new SqlParameter("@Name", Name), new SqlParameter("@Content", Content), new SqlParameter("@DataTime", DateTime.Now.ToString()), new SqlParameter("@Category", Category));
context.Response.Redirect("Index.ashx");
}
else
{
DataTable dt = Sqlhelper.ExecuteDataTable("select * from T_category");
var data = new { post = dt.Rows, Action = "fabu", title = new { Name="发布新闻"} };
string html = CommHelper.ReqHtml("Admin/Insert.htm", data);
context.Response.Write(html);
}
}
else if (Action == "xiugai")
{
if (string.IsNullOrEmpty(context.Request["tijiao"]))
{
string Id = context.Request["Id"];
DataTable dt = Sqlhelper.ExecuteDataTable(@"select p.Id as Id, p.Name as Name,k.Name as leibie,
p.Content as Content from T_xinwen p left join T_category k
on p.categoryId=k.Id where p.Id=@Id"
, new SqlParameter("@Id", Id));
DataTable leibie = Sqlhelper.ExecuteDataTable("select * from T_category");
DataRow dr = dt.Rows[0];
var data = new { shuju = dr, Action = "xiugai", post = leibie.Rows, title = new { Name = "修改新闻" } };
string Html = CommHelper.ReqHtml("Admin/Insert.htm", data);
context.Response.Write(Html);
}
else
{
}
}
else
{
context.Response.Write("<srcript>alert('动作不能为空!')</script>");
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}前台代码#parse("/Admin/Head.htm")
<script type="text/javascript" src="../CSS/ckeditor/ckeditor.js"></script>
<form action="/admin/insert.ashx" method="post" enctype="multipart/form-data">
<input type="hidden" name="Action" value="$Data.Action"/>
<p>新闻标题:<input type=text name="Name" value="$Data.shuju.Name" /> </p>
<p>新闻类别:<select name="Category">
#foreach($leibie in $Data.post)
<!--#if(Data.shuju.leibie==$leibie.Name)-->
<option value="$leibie.Id" selected>$leibie.Name</option>
<!--#else-->
#end
</select>
</p>
<p>新闻内容:<textarea id="Mgs" name="content">$Data.shuju.Content</textarea></p>
<script type="text/javascript">
var msg = document.getElementById("Mgs");
CKEDITOR.replace(msg);
</script>
<p><input type="submit" name="tijiao" value="发布" /></p>
</form>
#parse("/Admin/Foot.htm")
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
namespace tengfeikeji.admin
{
/// <summary>
/// Insert 的摘要说明
/// </summary>
public class Insert : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
//获取Action是否是发布新闻还是编辑新闻
string Action = context.Request["Action"];
if (Action=="fabu")
{
//在发布新闻里面,如果tijiao不为空的话 就是添加信息
if (!string.IsNullOrEmpty(context.Request["tijiao"]))
{
string Name = context.Request["Name"];
int Category = Convert.ToInt32(context.Request["Category"]);
string Content = context.Request["content"];
Sqlhelper.ExecuteNonQuery("insert into T_xinwen(Name,Content,DataTime,categoryID) values(@Name,@Content,@DataTime,@Category)", new SqlParameter("@Name", Name), new SqlParameter("@Content", Content), new SqlParameter("@DataTime", DateTime.Now.ToString()), new SqlParameter("@Category", Category));
context.Response.Redirect("Index.ashx");
}
else
{
DataTable dt = Sqlhelper.ExecuteDataTable("select * from T_category");
var data = new { post = dt.Rows, Action = "fabu", title = new { Name="发布新闻"} };
string html = CommHelper.ReqHtml("Admin/Insert.htm", data);
context.Response.Write(html);
}
}
else if (Action == "xiugai")
{
if (string.IsNullOrEmpty(context.Request["tijiao"]))
{
string Id = context.Request["Id"];
DataTable dt = Sqlhelper.ExecuteDataTable(@"select p.Id as Id, p.Name as Name,k.Name as leibie,
p.Content as Content from T_xinwen p left join T_category k
on p.categoryId=k.Id where p.Id=@Id"
, new SqlParameter("@Id", Id));
DataTable leibie = Sqlhelper.ExecuteDataTable("select * from T_category");
DataRow dr = dt.Rows[0];
var data = new { shuju = dr, Action = "xiugai", post = leibie.Rows, title = new { Name = "修改新闻" } };
string Html = CommHelper.ReqHtml("Admin/Insert.htm", data);
context.Response.Write(Html);
}
else
{
}
}
else
{
context.Response.Write("<srcript>alert('动作不能为空!')</script>");
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}前台代码#parse("/Admin/Head.htm")
<script type="text/javascript" src="../CSS/ckeditor/ckeditor.js"></script>
<form action="/admin/insert.ashx" method="post" enctype="multipart/form-data">
<input type="hidden" name="Action" value="$Data.Action"/>
<p>新闻标题:<input type=text name="Name" value="$Data.shuju.Name" /> </p>
<p>新闻类别:<select name="Category">
#foreach($leibie in $Data.post)
<!--#if(Data.shuju.leibie==$leibie.Name)-->
<option value="$leibie.Id" selected>$leibie.Name</option>
<!--#else-->
#end
</select>
</p>
<p>新闻内容:<textarea id="Mgs" name="content">$Data.shuju.Content</textarea></p>
<script type="text/javascript">
var msg = document.getElementById("Mgs");
CKEDITOR.replace(msg);
</script>
<p><input type="submit" name="tijiao" value="发布" /></p>
</form>
#parse("/Admin/Foot.htm")