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.OleDb;
using System.Configuration;
namespace baoge
{
	/// <summary>
	/// backup 的摘要说明。
	/// </summary>
	public class backup : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox txtName;
		protected System.Web.UI.WebControls.TextBox txtPath;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Button btnBackup;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["AdminName"]==null)
			{
				Response.Redirect("admin/Admin_Login.aspx");
			}
			if( !IsPostBack )
			{
				txtName.Text = "baoge";
				txtPath.Text = "backup/";
			}
		}


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

		}
		#endregion

		private void btnBackup_Click(object sender, System.EventArgs e)
		{
			string strDBName = txtName.Text.Trim();
			string strPath = Server.MapPath(txtPath.Text.Trim());

			if( strDBName == String.Empty )
			{
				Response.Write("<script>");
				Response.Write("alert('请输入数据库名!!!');");
				Response.Write("</script>");
				return;
			}
			if( strPath == String.Empty )
			{
				Response.Write("<script>");
				Response.Write("alert('请输入要备份到的路径!!!');");
				Response.Write("</script>");
				return;
			}

			DateTime myTime=System.DateTime.Now;
			string strDTime = myTime.ToLongDateString();
			strDTime += "(";
			strDTime += myTime.Hour.ToString("00");
			strDTime += myTime.Minute.ToString("00");
			strDTime += myTime.Second.ToString("00");
			strDTime += ")";
			strPath += strDBName + "." + strDTime + ".bak";

			System.IO.File.Copy(Server.MapPath("DataBase/DataBase.mdb"),strPath,false);
           
//				Response.Write("<script>");
//				Response.Write("alert('数据备份成功!!!');");
//				Response.Write("</script>");
			Response.Write("备份数据库成功,路径为："+strPath+"(注意：请记住这个路径，还原时需要它)");

		
		}

		private void Button1_Click(object sender, System.EventArgs e)
		{
			string strDBName = txtName.Text.Trim();
			string strPath = Server.MapPath(txtPath.Text.Trim());
			if( strDBName == String.Empty )
			{
				Response.Write("<script>");
				Response.Write("alert('请输入数据库名!!!');");
				Response.Write("</script>");
				return;
			}
			if( strPath == String.Empty )
			{
				Response.Write("<script>");
				Response.Write("alert('请输入要备份到的路径!!!');");
				Response.Write("</script>");
				return;
			}
			strPath += strDBName;
           System.IO.File.Copy(strPath,Server.MapPath("DataBase/DataBase1.mdb"),true);
							Response.Write("<script>");
							Response.Write("alert('数据还原成功!!!');");
							Response.Write("</script>");
		}
	}
}
