温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:小区物业管理系统源码
当前文件:
SmallHouse/admin/backup.aspx.cs,打开代码结构图
SmallHouse/admin/backup.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.IO; 12
using System.Data.SqlClient; 13
14
public partial class Default2 : System.Web.UI.Page 15
{ 16
protected void Page_Load(object sender, EventArgs e) 17
{ 18
if (Convert.ToString(Session["UID"]) == "") 19
{ 20
Response.Redirect("login.aspx"); 21
22
} 23
if (!IsPostBack) 24
{ 25
this.TextBox1.Text = DateTime.Now.ToShortDateString() + "Backup";//初使备份数据库的备份名称 26
} 27
28
29
} 30
protected void Button1_Click(object sender, EventArgs e) 31
{ 32
string path = Server.MapPath("~/backup") + "\\"; 33
34
string backcmd = "backup database SmallHouse to disk='" + path + TextBox1.Text.Trim() + ".bak'"; 35
//Response.Write(backcmd); 36
//Response.End(); 37
string file = path + TextBox1.Text.Trim() + ".bak"; 38
39
try 40
{ 41
if (File.Exists( file)) 42
{ 43
Response.Write("<script language='javascript'>alert('此文件已存在,请选择其它文件名');</script>"); 44
return; 45
} 46
else 47
{ 48
BaseClass BC = new BaseClass(); 49
BC.ExecSql(backcmd); 50
Response.Write("<script language=javascript>alert('文件备份成功!');location='backup.aspx'</script>"); 51
} 52
} 53
catch (Exception ex) 54
{ 55
Response.Write("<scirpt language='javascript'>alert('文件备份失败!');location='default.aspx'</script>"); 56
Response.Write (ex.Message); 57
58
} 59
finally 60
{ 61
62
} 63
64
} 65
} 66





}
}