代码拉取完成,页面将自动刷新
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Wuqi.Webdiyer;
using System.Data.SqlClient;
using System.IO;
using System.Text;
public partial class mydatabase : WebPage
{
public string CurUrl = HttpContext.Current.Request.RawUrl.Replace("/","");
protected void Page_Load(object sender, EventArgs e)
{
this.VerifyPage();
if (CheckCurUser())
{
if (!Page.IsPostBack)
{
DataBindlist();
}
}
}
public bool CheckCurUser()
{
bool ret = false;
if (CurrentUser.UserPID == -1)
ret = true;
else
ret = false;
return ret;
}
protected void DataBindlist()
{
this.from_datafile.Value = System.Configuration.ConfigurationManager.AppSettings["dataname"].ToString();
this.new_datafile.Value = System.Configuration.ConfigurationManager.AppSettings["dataname"].ToString();
this.to_datafile.Value = this.from_datafile.Value + "_" + DateTime.Now.ToString().Replace(":", "-").Replace(" ", "-");
string path = Server.MapPath("~" + this.folder_datafile.Value);//获取文件夹的路径
string[] files = Directory.GetFiles(path);//获取文件下面的所有文件
ddl_backfile.DataSource = files;//绑定
ddl_backfile.DataBind();
}
protected void BtnBack_ServerClick(object sender, EventArgs e)
{
string SavePath = System.Web.HttpContext.Current.Server.MapPath(folder_datafile.Value); //得到上传目录
if (!System.IO.Directory.Exists(SavePath))
{
System.IO.Directory.CreateDirectory(SavePath);
}
string newfiles = this.to_datafile.Value + ".bak";
string newpaths = Server.MapPath(folder_datafile.Value) + newfiles;
string backsql = "BACKUP DATABASE " + this.from_datafile.Value + " to DISK ='" + newpaths + "'";
SqlConnection Con = new SqlConnection(GetData.strConn);
SqlCommand Com = new SqlCommand(backsql, Con);
try
{
if (File.Exists(to_datafile.Value))
{
Response.Write("<script language=javascript>alert('此文件已存在,请从新输入!');location='"+CurUrl+"'</script>");
return;
}
Con.Open();
Com.ExecuteNonQuery();
Response.Write("<script language=javascript>alert('备份数据成功!');location='"+CurUrl+"'</script>");
}
catch(Exception ms)
{
Response.Write(ms.Message);
Response.Write("<script language=javascript>alert('备份数据失败!')</script>");
}
finally
{
Con.Close();
}
}
protected void BtnStore_ServerClick(object sender, EventArgs e)
{
string dbname = this.new_datafile.Value;
string path = this.ddl_backfile.SelectedValue;
string storesql = "use master restore database " + dbname + " from DISK='" + dbname + "'";
SqlConnection Con = new SqlConnection(GetData.strConn);
SqlCommand Com = new SqlCommand(storesql, Con);
try
{
Con.Open();
Com.ExecuteNonQuery();
Response.Write("<script language=javascript>alert('还原数据库成功!');location='"+CurUrl+"'</script>");
}
catch (Exception ms)
{
Response.Write(ms.Message);
Response.Write("<script language=javascript>alert('还原数据库失败!')</script>");
}
finally
{
Con.Close();
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。