加为好友
发送私信
在线聊天
发表于:2008-05-17 21:22:56 楼主
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Data.SqlClient; namespace news.NewsAdmin { /// <summary> /// AddNews 的摘要说明。 /// </summary> public class AddNews : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox title; protected System.Web.UI.WebControls.TextBox smalltitle; protected System.Web.UI.WebControls.TextBox comeinfo; protected System.Web.UI.WebControls.TextBox keywords; protected System.Web.UI.WebControls.DropDownList colortitle; protected System.Web.UI.WebControls.TextBox readtimes; protected System.Web.UI.WebControls.DropDownList classid; protected System.Web.UI.WebControls.Button enter; protected DXControls.DXTB DXT; private int newid; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if(!Page.IsPostBack) GetClassName(); } private void GetClassName() { SqlConnection conn=null; SqlCommand cmd=null; SqlDataReader dr=null; string sql=string.Empty; try { sql=string.Format("select classname from [className] order by classid desc"); conn=news.Classes.DataBase.GetConn(); conn.Open(); cmd=new SqlCommand(sql,conn); dr=cmd.ExecuteReader(); if(dr.Read()) { do { ListItem ls=new ListItem(dr.GetString(0).Trim(),dr.GetString(0).ToString()); this.classid.Items.Add(ls); }while(dr.Read()); } } catch(Exception ex) { Response.Write(ex); } finally { if(conn!=null) conn.Close(); if(cmd!=null) cmd.Dispose(); if(dr!=null) dr.Close(); } } private void enter_Click(object sender, System.EventArgs e) { SaveNews(); string info="新闻添加成功,你可以做以下操作: <br> <br>1. <a href='AddNews.aspx'>继续添加新闻 </a> <br>2. <a href='AdminNews.aspx'>返回新闻列表页面 </a> <br>3. <a href='EditNews.aspx?id="+newid+"'>编辑刚才发布的新闻 </a>"; Response.Write(info); Response.End(); } private void SaveNews() { string sql=string.Empty; sql=string.Format("insert into [NewInfo] (title,content,smalltitle,frominfo,keywords,titlecolor,readtimes,classname) values ('{0}','{1}','{2}','{3}','{4}','{5}',{6},'{7}') SELECT @@ IDENTITY AS 'newid'",Classes.HtmlCodes.HtmlEncode(title.Text.Trim()),this.DXT.Text.ToString(),Classes.HtmlCodes.HtmlEncode(this.smalltitle.Text.ToString()),Classes.HtmlCodes.HtmlEncode(this.comeinfo.Text.ToString()),Classes.HtmlCodes.HtmlEncode(this.keywords.Text.ToString()),Classes.HtmlCodes.HtmlEncode(this.colortitle.SelectedValue.ToString()), Convert.ToInt32(this.readtimes.Text.ToString()),this.classid.SelectedValue.ToString()); newid=Convert.ToInt32(Classes.DataBase.GetResult(sql)); } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); this.enter.Click+=new System.EventHandler(this.enter_Click); } #endregion <%@ Register TagPrefix="cc1" Namespace="DXControls" Assembly="DXControls" %> <%@ Page language="c#" Codebehind="AddNews.aspx.cs" AutoEventWireup="false" Inherits="news.NewsAdmin.AddNews" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>AddNews </title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <table cellpadding="0" cellspacing="0" width="94%" align="center" border="0"> <tr> <td colspan="4" height="24"> <span style="COLOR:#ff0000"> <b>新闻管理 ->添加新闻 </b> </span> <hr noshade size="1"> </td> </tr> <tr> <td width="13%" height="27"> <div align="center">新闻标题 </div> </td> <td colspan="3"> <asp:TextBox ID="title" Runat="server" Width="344px"> </asp:TextBox> </td> </tr> <tr> <td height="24"> <div align="center">副标题 </div> </td> <td colspan="3"> <asp:TextBox ID="smalltitle" Runat="server" Width="344px"> </asp:TextBox> </td> </tr> <tr> <td height="22"> <div align="center">新闻来源 </div> </td> <td width="27%" height="22"> <asp:TextBox ID="comeinfo" Runat="server" Width="176px"> </asp:TextBox> </td> <td width="47%" height="22"> <div align="center">关键字 </div> </td> <td width="47%" height="22"> <asp:TextBox ID="keywords" Runat="server" Width="176px"> </asp:TextBox> </td> </tr> <tr> <td height="29"> <div align="center">标题色彩 </div> </td> <td height="29"> <asp:DropDownList ID="colortitle" Runat="server" Width="176px"> <asp:ListItem Value="#000000" Selected="True">黑色 </asp:ListItem> <asp:ListItem Value="#ff0000" Selected="True">红色 </asp:ListItem> <asp:ListItem Value="#0000ff" Selected="True">蓝色 </asp:ListItem> </asp:DropDownList> </td> <td height="29"> <div align="center">阅读次数 </div> </td> <td height="29"> <asp:TextBox ID="readtimes" Runat="server" Width="176px"> </asp:TextBox> </td> </tr> <tr> <td height="29"> <div align="center">新闻类别 </div> </td> <td height="29"> <asp:DropDownList ID="classid" Runat="server" Width="176px"> <asp:ListItem Value="国内新闻">国内新闻 </asp:ListItem> </asp:DropDownList> </td> <td height="29"> </td> <td height="29"> </td> </tr> <tr> <td valign="top" align="left" colspan="4" height="300"> <cc1:dxtb id="DXT" runat="server"> </cc1:dxtb> </td> </tr> <tr> <td align="left" colspan="4" height="40"> <p align="center"> <asp:Button ID="enter" Runat="server" Text="发布"> </asp:Button> </p> </td> </tr> </table> </form> </body> </HTML>
问题点数: 20 回复次数:5
显示所有回复 显示星级回复 显示楼主回复
修改
删除
举报
引用
回复