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

📄 admindown.aspx.cs

📁 中国海洋大学211工程网站的全部源码
💻 CS
字号:
using System;
using System.IO;
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;

namespace _211
{
	/// <summary>
	/// AdminDown 的摘要说明。
	/// </summary>
	public partial class AdminDown : System.Web.UI.Page
	{
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["name"]==null)
			{
				Response.Write("<script>top.location='AdminLogin.aspx'</script>");
				return;
			}

			if(!Page.IsPostBack)
			{
				BindDown();
				BindDownType();
				DownList2Text();
			}

			Button3.Attributes["onclick"]="return confirm('确定要删除么?')";
		}

		private void BindDown()
		{
			d.DataSource=TableQuery.DownQuery();
			d.DataTextField="DownName";
			d.DataValueField="DownId";
			d.DataBind();
		}

		private void BindDownType()
		{
			DataTable dt=TableQuery.DownTypeQuery();
			ty.Text="";
			for(int i=0;i<dt.Rows.Count;i++)
			{
				ty.Text+=dt.Rows[i][1].ToString()+" ";
			}
		}

		private void DownList2Text()
		{
			if(d.SelectedItem!=null)
			{
				ename.Text=d.SelectedItem.Text;
				intro.Text="<a href=\""+TableQuery.DownUrlQuery(d.SelectedValue)+"\">下载地址</a> <font color=red>下载文件如不需要修改文件浏览框请留空</font>";
			}
		}

		private void CreateStaticWeb()
		{
			using(CreateDown cd=new CreateDown())
			{
				cd.Add();
			}
		}

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

		}
		#endregion

		protected void Button2_Click(object sender, System.EventArgs e)
		{
			if(name.Text==""||upfile.Value=="")
			{
				Response.Write("<script>alert('添加未成功');</script>");
				return;
			}

			using(Down dw=new Down())
			{
				try
				{
					dw.setDownName(name.Text);
					dw.setDownUrl(FileOperate.UpLoadFile(upfile));
					dw.Add();
					//upfile.Value="";
					name.Text="";
					
					Response.Write("<script>alert('添加成功');</script>");
				}
				catch(Exception ex)
				{
					Response.Write("<script>alert('"+ex.Message.ToString()+"');</script>");
				}
			}

			CreateStaticWeb();
			BindDown();
			DownList2Text();
		}

		protected void Button1_Click(object sender, System.EventArgs e)
		{
			
			if(ename.Text==""||d.SelectedItem==null)
			{
				return;
			}

			using(Down dw=new Down(Convert.ToUInt32(d.SelectedValue)))
			{
				try
				{
					dw.setDownName(ename.Text);
					if(up.Value!="")
					{
						FileOperate.DelFile(dw.getDownUrl());
						dw.setDownUrl(FileOperate.UpLoadFile(up));
					}
					dw.Update();
					//up.Value="";
					
					Response.Write("<script>alert('修改成功');</script>");
				}
				catch(Exception ex)
				{
					Response.Write("<script>alert('"+ex.Message.ToString()+"');</script>");
				}
			}

			CreateStaticWeb();
			BindDown();
			DownList2Text();
		}

		protected void Button3_Click(object sender, System.EventArgs e)
		{
			if(d.SelectedItem==null)
			{
				return;
			}

			using(Down dw=new Down(Convert.ToUInt32(d.SelectedValue)))
			{
				try
				{
					FileOperate.DelFile(dw.getDownUrl());

					dw.Del();
					Response.Write("<script>alert('删除成功');</script>");
				}
				catch(Exception ex)
				{
					Response.Write("<script>alert('"+ex.Message.ToString()+"');</script>");
				}
			}

			CreateStaticWeb();
			BindDown();
			DownList2Text();

			int temp=(int)DBQuery.ExecuteScalar("select count(*) from down");
			if(temp%10==0)
			{
				FileInfo fi=new FileInfo(Request.ServerVariables["APPL_PHYSICAL_PATH"].ToString()+"Down_"+(temp/10)+".htm");
				if(fi.Exists)fi.Delete();
			}
		}

		protected void d_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			DownList2Text();
		}
	}
}

⌨️ 快捷键说明

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