⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admin_articleedit.aspx.cs

📁 这个是用vc编写的新闻管理系统
💻 CS
字号:
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;
using System.Configuration;
namespace WebNews.admin
{
	/// <summary>
	/// admin_articleEdit 的摘要说明。
	/// </summary>
	public class admin_articleEdit : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label myLabel;
		protected System.Web.UI.WebControls.DropDownList ClassName;
		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2;
		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator3;
		protected System.Web.UI.WebControls.CheckBox Headline;
		protected System.Web.UI.WebControls.CheckBox HighLight;
		protected System.Web.UI.WebControls.CustomValidator CustomValidator1;
		protected System.Web.UI.WebControls.Button Submit;
		protected System.Web.UI.HtmlControls.HtmlTextArea Summary;
		protected System.Web.UI.WebControls.TextBox Source;
		protected System.Web.UI.WebControls.TextBox Author;
		protected System.Web.UI.WebControls.TextBox Key;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.HtmlControls.HtmlTextArea Body;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Button upload;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.HtmlControls.HtmlInputFile FileUp;
		protected System.Web.UI.WebControls.TextBox Title;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(!Page.IsPostBack)
			{
					getArticle();
			  
				if((string)Session["userclass"]!="系统管理员"&&(int)Session["chgnews"]!=1)
				{
					Page.Visible=false;
				}

			}

		}
			
		private void Page_UnLoad(object sender, System.EventArgs e)
		{
		}

		private void getArticle()
		{
			string con=ConfigurationSettings.AppSettings["dsn"];	//取得DSN字符
			
			SqlConnection conn= new SqlConnection(con);//连接字符串
			conn.Open();
			try
			{
				SqlDataAdapter myCommand = new SqlDataAdapter();  //创建SqlDataAdapter 类
			 	   
				myCommand.SelectCommand=new SqlCommand("sp_selArticleById",conn);		 //调用存储过程
				myCommand.SelectCommand.CommandType=CommandType.StoredProcedure ;
				SqlParameter id=myCommand.SelectCommand.Parameters.Add("@articleid",SqlDbType.BigInt );	 //设置参数
				id.Value=Request["articleid"];
			
				//		myLabel.Text="用户"+Request["username"]+"的权限";					
				
				DataSet ds = new DataSet();			//建立并填充数据集
				myCommand.Fill(ds,"Article");
			
				DataRow dr;
				dr=ds.Tables["Article"].Rows[0]  ;  //取得内容 
				
				string	content=(string)dr["content"];					//内容
				Body.Value =content;
				
				string title=(string)dr["title"];					   //标题
				Title.Text=title;
				
				string classname=(string)dr["classname"];				  //分类
			
				int hl=(int)dr["headline"];								//是否头条新闻
				if(hl==1)
				{
					Headline.Checked=true;
				}

				int ht=(int)dr["highlight"];							   //是否高显
				if(ht==1)
				{
					HighLight.Checked=true;
				}

				string summary=(string)dr["summary"];					   //简写
				Summary.Value=summary;

				string key=(string)dr["Nkey"];						  //相关新闻
				Key.Text=key;

				string writer=(string)dr["writer"];					 //作者
				Author.Text =writer;

				string source=(string)dr["source"];					//来源
				Source.Text=source;

				string  da=(string)Session["userclass"]	;			  //根据管理权限来显示分类
				if(da.Trim()=="系统管理员")
				{
					SqlDataAdapter selClassAll = new SqlDataAdapter();  //设置分类名
			 	   
					selClassAll.SelectCommand=new SqlCommand("sp_selFclassAll",conn);		 //调用存储过程设置分类名
					selClassAll.SelectCommand.CommandType=CommandType.StoredProcedure ;
		   
					DataSet dt = new DataSet();
					selClassAll.Fill(dt,"ClassName");

					ClassName.DataSource=dt;
					ClassName.DataTextField="classname";
					ClassName.DataValueField="classname";
					ClassName.DataBind();
					int i = 0;
					foreach(ListItem li in ClassName.Items)					 //选中分类名
					{
						if(li.Text.Trim() ==classname.Trim())
						{
							li.Selected = true; 
					
						}
						i += 1;
					}
				}	
				else 
				{
					ListItem d=new ListItem(classname,classname);
					
					ClassName.Items.Add(d);
				}

				//ListItem d=	ClassName.Items.FindByText(classname);
				//	d.Selected=true;
				conn.Close();
			}
			catch(SqlException e)
			{
				Response.Write("Exception in Main: " + e.Message);	//出错处理

			}

		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.upload.Click += new System.EventHandler(this.upload_Click);
			this.Submit.Click += new System.EventHandler(this.Submit_Click);
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Submit_Click(object sender, System.EventArgs e)
		{
			
			if(Page.IsValid)
			{
				updateArticle(); 
			}

		}

		private void updateArticle()
		{
			int hl=0;
			int HL=0;
			string classname=ClassName.SelectedItem.Text ;		 //获得分类名
			if(Headline.Checked)								 //获得是否是头条新闻
			{
				hl=1;

			}
			else  hl=0;

			if(HighLight.Checked)							  //获得是否新闻醒目
			{
				HL=1;
			}
			else HL=0;

			string title=Title.Text;					 //获得新闻标题
			string content=Body.Value;	//获得新闻内容
			content=Server.HtmlDecode(content);
			string summary=Summary.Value;				 //获得新闻简介
			string nk=Key.Text;						 //获得相关新闻
			string at=Author.Text;						 //获得作者名
			string sr=Source.Text;		
			try
			{
				string conn=ConfigurationSettings.AppSettings["dsn"];	//取得DSN字符
			
				SqlConnection con = new SqlConnection(conn);//连接字符串
				con.Open();
			
				SqlCommand cmd=new SqlCommand("sp_updateArticle",con);			//建立命令
				cmd.CommandType=CommandType.StoredProcedure;
				SqlParameter id1=cmd.Parameters.Add("@articleid",SqlDbType.BigInt);
				id1.Value=Request["articleid"];
					
				SqlParameter cl=cmd.Parameters.Add("@classname",SqlDbType.Char,200);	 //调用并设置存储过程参数
				cl.Value =classname;
				SqlParameter tl=cmd.Parameters.Add("@title",SqlDbType.Char,200);
				tl.Value=title;
				SqlParameter cn=cmd.Parameters.Add("@content",SqlDbType.NText);
				cn.Value=content;
				SqlParameter hd=cmd.Parameters.Add("@headline",SqlDbType.Int );
				hd.Value=hl;
				SqlParameter hil=cmd.Parameters.Add("@highlight",SqlDbType.Int );
				hil.Value=HL;
				SqlParameter sm=cmd.Parameters.Add("@summary",SqlDbType.Char,400);
				sm.Value=summary;
				SqlParameter key=cmd.Parameters.Add("@Nkey",SqlDbType.Char,100);
				key.Value=nk;
				SqlParameter author=cmd.Parameters.Add("@writer",SqlDbType.Char,400);
				author.Value=at;
				SqlParameter source=cmd.Parameters.Add("@source",SqlDbType.Char,400);
				source.Value=sr;
				

				int d=cmd.ExecuteNonQuery();			   //添加新闻
				if(d>0)
				{
					myLabel.Text="修改新闻成功";
					con.Close();
				}
				else 
				{
					myLabel.Text="修改新闻错误";
					con.Close();
				}
			}
			catch(Exception e)
			{
				Response.Write("Exception in Main: " + e.Message);	//出错处理
				 
			}
		}

		private void Button1_Click(object sender, System.EventArgs e)
		{
			Session["Title"]=Title.Text;
			Session["Body"]=Body.Value;
			Session["Summary"]=Summary.Value;
			Session["Key"]=Key.Text ;
			Session["Author"]=Author.Text ;
			Session["Source"]=Source.Text ;
		
}

		private void upload_Click(object sender, System.EventArgs e)
		{
			
			if(FileUp.PostedFile.ContentLength!=0)
			{
				
				if(FileUp.PostedFile.ContentType!="image/pjpeg" || FileUp.PostedFile.ContentType!="image/gif"||FileUp.PostedFile.ContentType!="image/bmp")	   //设置上传文件类型
				{  
					string filename=FileUp.PostedFile.FileName;				 //取得文件名
					int i=filename.Length;
					filename=filename.Remove(0,i-4);
					string s=DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+DateTime.Now.Millisecond.ToString();
					string  d=Server.MapPath("../upfiles/")+s+filename ;	   //设置文件名
				
				      
					FileUp.PostedFile.SaveAs(d);								 //保存文件
					Body.Value+="<img src=../upfiles/"+s+filename+">";			//更改新闻内容
					Label1.Text="上传成功";
					
				}	
					
				else Label1.Text="只能上传图形文件";


			}
			else Label1.Text="请选择上传文件";	

	}
	}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -