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;

namespace norke.admin
{
	/// <summary>
	/// backup 的摘要说明。
	/// </summary>
	public partial class backup : System.Web.UI.Page
	{
    
		protected void Page_Load(object sender, System.EventArgs e)
		{
            //权限检查
            if( Session["adminName"]==null || Session["adminName"].ToString() == String.Empty )
            {
                Response.Write("<font color=#ff0000 style='FONT-SIZE: 12px'>对不起,您没足够权限访问此页!!</font><br>");
                Response.Write("<a href=Default.aspx target=_top style='FONT-SIZE: 12px'>重新登陆</a><br>");
                Response.End();
                return;
            }

            if( !IsPostBack )
            {
                txtName.Text = "norkeDB";
                txtPath.Text = "C:\\";
            }
		}

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

        }
		#endregion

        protected void btnBackup_Click(object sender, System.EventArgs e)
        {
            string strDBName = txtName.Text.Trim();
            string strPath = 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 += "norkeDB." + strDTime + ".bak";

            DBConn myDB = new DBConn();
            string mySql = "backup database " + strDBName + " to disk = '" + strPath + "'";
            int i = myDB.Update( mySql );
            myDB.Close();

            if( i == -1 )
            {
                Response.Write("<script>");
                Response.Write("alert('数据备份成功!!!');");
                Response.Write("</script>");
            }
        }
	}
}
