1 Star 3 Fork 0

Admin/MyWebSms

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mydatabase.aspx.cs 3.87 KB
一键复制 编辑 原始数据 按行查看 历史
Ai鹿子 提交于 2022-04-24 10:09 . 01
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();
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/huanghe_1_0/my-web-sms.git
git@gitee.com:huanghe_1_0/my-web-sms.git
huanghe_1_0
my-web-sms
MyWebSms
master

搜索帮助