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

📄 addtopnews.aspx.cs

📁 一个电子商务网源码
💻 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 web.Code;
//该源码下载自www.51aspx.com(51aspx.com)

namespace web.Admin
{
	/// <summary>
	/// AddTopNews 的摘要说明。
	/// </summary>
	public partial class AddTopNews : System.Web.UI.Page
	{
		protected System.Web.UI.HtmlControls.HtmlImage IMG1;
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			
//				updown updown1;
//				updown1=(updown)Context.Handler;
//				TextBox2.Text = TextBox2.Text + updown1.ImgUrl;
			ImageButton1.Attributes.Add("onclick", "return btnOpen_Click();");
			btnAdd.Attributes.Add("onclick", "return checkEmpty(TextBox1)&&checkEmpty(TextBox2);");
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		private string getCategoryName()
		{
			string categoryname = null;
			switch( DropDownList1.SelectedValue.ToString() )
			{
				case "1":
					categoryname = "电脑";
					break;
				case "2":
					categoryname = "手机";
					break;
				case "3":
					categoryname = "数码相机";
					break;
				case "4":
					categoryname = "MP3";
					break;
				case "5":
					categoryname = "办公外设";
					break;
			}
			return categoryname;
		}


		protected void btnAdd_Click(object sender, System.EventArgs e)
		{
			TopNewsVO topNewsVO = new TopNewsVO();
			topNewsVO.Title = TextBox1.Text.Trim();
			topNewsVO.Content = TextBox2.Text.Replace("\n","<br>");
			topNewsVO.AddDate = DateTime.Now.ToString();
			if(CheckBox1.Checked)
			{
				topNewsVO.IsAtIndex = 1;
				topNewsVO.IsFirst = 1;
			}
			else if(CheckBox2.Checked)
			{
				topNewsVO.IsAtIndex = 1;
				topNewsVO.IsFirst = 0;
			}
			else
			{
				topNewsVO.IsAtIndex = 0;
				topNewsVO.IsFirst = 0;
			}
			topNewsVO.CategoryName = getCategoryName();
			TopNewsDAO topNewDAO = new TopNewsDAO();
			if( topNewDAO.AddTopNewsArticle( topNewsVO ) != 0 )
			{
				TextBox1.Text=null;
				TextBox2.Text=null;
				DropDownList1.SelectedIndex=0;
				CheckBox2.Checked=false;
				CheckBox1.Checked=false;
				Response.Write("<script>alert('新闻已经添加!')</script>");
			}
		}

		protected void Button1_Click(object sender, System.EventArgs e)
		{
			string fullFileName = up1.PostedFile.FileName;
			string FileName = fullFileName.Substring( fullFileName.LastIndexOf("\\")+1 );
			string FileType = fullFileName.Substring( fullFileName.LastIndexOf(".")+1 );
			if( FileType == "bmp" || FileType == "jpg" || FileType == "gif" )
			{
				up1.PostedFile.SaveAs( Server.MapPath("../TopNews/UpDownImg/Home"+"\\"+FileName) );
				Response.Write("<script>alert('上传成功!')</script>");
			}
			else
			{
				Response.Write("<script>alert('你上传的文件格式不对!')</script>");
			}
		}

		protected void CheckBox2_CheckedChanged(object sender, System.EventArgs e)
		{
			if(CheckBox2.Checked)
			{
				Panel1.Visible=true;
			}
			else
			{
				Panel1.Visible=false;
			}
		}

	}
}

⌨️ 快捷键说明

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