117 lines
4.0 KiB
C#
117 lines
4.0 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.IO;
|
||
using System.Web;
|
||
using System.Web.UI;
|
||
using System.Web.UI.WebControls;
|
||
|
||
namespace FineUIPro.Web.common.SysManage
|
||
{
|
||
public partial class DataBak : PageBase
|
||
{
|
||
/// <summary>
|
||
/// 数据库名称
|
||
/// </summary>
|
||
public string DataName
|
||
{
|
||
get
|
||
{
|
||
return (string)ViewState["DataName"];
|
||
}
|
||
set
|
||
{
|
||
ViewState["DataName"] = value;
|
||
}
|
||
}
|
||
|
||
public string FilePath
|
||
{
|
||
get
|
||
{
|
||
return (string)ViewState["FilePath"];
|
||
}
|
||
set
|
||
{
|
||
ViewState["FilePath"] = value;
|
||
}
|
||
}
|
||
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
|
||
if (!IsPostBack)
|
||
{
|
||
this.LbtnDownLoad.Hidden = true;
|
||
string str = BLL.Funs.ConnString;
|
||
string[] group = str.Split(';');
|
||
|
||
foreach (string s in group)
|
||
{
|
||
if (s.Contains("Database"))
|
||
{
|
||
string[] bak = s.Split('=');
|
||
DataName = bak[1];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
protected void btnSave_Click(object sender, EventArgs e)
|
||
{
|
||
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId,this.CurrUser.UserId, BLL.Const.DataBakMenuId, BLL.Const.BtnDataBak))
|
||
{
|
||
string newname = DataName + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + ".bak";
|
||
|
||
string nepath = Server.MapPath("../../App_Data/") + newname;
|
||
FilePath = "App_Data\\" + newname;
|
||
string sql = "BACKUP DATABASE " + DataName + " to DISK ='" + nepath + "'";
|
||
try
|
||
{
|
||
if (!File.Exists(nepath))
|
||
{
|
||
BLL.SQLHelper.ExecutSql(sql);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ScriptManager.RegisterStartupScript(this, typeof(string), "_alert", "alert('数据库备份失败,原因:" + ex.Message.ToString() + "')", true);
|
||
}
|
||
|
||
string path = "../../App_Data/" + newname;
|
||
this.LbtnDownLoad.Text = "文件" + newname + "已成功备份到服务器, 请点击下载到本地!";
|
||
LbtnDownLoad.Hidden = false;
|
||
}
|
||
else
|
||
{
|
||
ShowNotify("您没有这个权限,请与管理员联系!");
|
||
}
|
||
}
|
||
|
||
protected void LbtnDownLoad_Click(object sender, EventArgs e)
|
||
{
|
||
//string url = BLL.Funs.RootPath + FilePath;
|
||
|
||
//FileInfo info = new FileInfo(url);
|
||
|
||
//string fileName = Path.GetFileName(url);
|
||
//long fileSize = info.Length;
|
||
//if (fileSize < 102400000)
|
||
//{
|
||
// System.Web.HttpContext.Current.Response.Clear();
|
||
// System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
|
||
// System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
|
||
// System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
|
||
// System.Web.HttpContext.Current.Response.TransmitFile(url, 0, fileSize);
|
||
// System.Web.HttpContext.Current.Response.Flush();
|
||
// System.Web.HttpContext.Current.Response.Close();
|
||
//}
|
||
//else
|
||
//{
|
||
// ShowNotify("文件太大(超过100M),请写管理员联系!");
|
||
//}
|
||
|
||
ShowFile(FilePath);
|
||
}
|
||
}
|
||
} |