新闻添加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;
namespace domain.UI.images.News
{
public partial class NewsEdit :domain.BLL.AdminPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.LoadType(this.DdlType, this.Db.GetTable("select * from NewsSort where Column_Depth=1"));
BindUpdateData();
}
}
public void LoadType(DropDownList ddl, DataTable dt)
{
if (dt != null)
{
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
ddl.Items.Add(new ListItem(GetSpace(Convert.ToInt32(dt.Rows[i]["Column_Depth"]) - 1) + Convert.ToString(dt.Rows[i]["Column_Name"]), Convert.ToString(dt.Rows[i]["Column_ID"])));
DataTable dtTemp = this.Db.GetTable("select * from NewsSort where Parent_ID=@Parent_ID",new System.Data.SqlClient.SqlParameter("@Parent_ID",Convert.ToString(dt.Rows[i]["Column_ID"])));
if (dtTemp != null)
{
if (dtTemp.Rows.Count > 0)
{
LoadType(DdlType,dtTemp);
}
}
}
}
}
}
public string GetSpace(int tempint)
{
string s = "";
for (int i = 0; i < tempint; i++)
{
s += "";
}
return s;
}
public void BindUpdateData()
{
string Gid = this.GetRequest("Gid");
if(Gid.Length>0)
{
domain.SQLDB.News news = new domain.SQLDB.News();
news.Gid = Gid;
news = news.SelectById();
this.DdlType.SelectedIndex = this.DdlType.Items.IndexOf(this.DdlType.Items.FindByValue(news.TypeId));
this.TbTitle.Text = news.Title;
this.TbKeyword.Text = news.Keyword;
this.TbComeFrom.Text = news.ComeFrom;
this.TbAuthor.Text = news.Author;
this.TbContent.Text = news.Content;
this.Cbcommand.Checked=news.IsCommand=="1"?(true):(false);
this.cbTop.Checked = news.IsTop=="1"?(true):(false);
this.idPic.ImageUrl = "/upload/admin/news/"+news.Pic;
}
}
protected void BtEdit_Click(object sender, EventArgs e)
{
domain.UI.cs.Util.UploadFile uf = new domain.UI.cs.Util.UploadFile();
domain.SQLDB.News news = new domain.SQLDB.News();
news.Gid = GetRequest("Gid").Length>0?(GetRequest("Gid")):("-1200");
news.TypeId = this.DdlType.SelectedValue.Trim();
news.Title = this.TbTitle.Text.Trim();
news.Keyword = this.TbKeyword.Text.Trim();
news.ComeFrom = this.TbComeFrom.Text.Trim();
news.Author = this.TbAuthor.Text.Trim();
news.Content = this.TbContent.Text.Trim();
news.Pic = uf.GetSqlFile("admin/news",120,240);
news.IsCommand=this.Cbcommand.Checked?("1"):("0");
news.commandTime = DateTime.Now.ToString("yyyy-MM-dd");
news.IsTop =this.cbTop.Checked?("1"):("0");
news.topTime = DateTime.Now.ToString("yyyy-MM-dd");
news.AddTime = DateTime.Now.ToString("yyyy-MM-dd");
if (news.Update())
{
this.ShowMessage("成功编辑新闻!","history.go(-1)");
}
else
{
this.ShowMessage("系统错误请联系管理员", "history.go(-1)");
}
}
}
}