<% @ Page Language = "C #" autoeventwireup = "true" codefile = "backdata. aspx. cs" inherits = "admin_backdata" %>
<% @ Register src = "../usercontrol/checkadmin. ascx" tagname = "checkadmin" tagprefix = "uc1" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
<Link href = "INC/css.css" rel = "stylesheet" type = "text/CSS"/>
<SCRIPT type = "text/JavaScript">
Function checkform ()
{
If ($ ("textbox1"). value. Length = 0)
{
Alert ('Enter the backup name ');
Return false;
}
}
Function $ (ID)
{
Return document. getelementbyid (ID );
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Table width = "90%" border = "0" align = "center" cellpadding = "2" cellspacing = "1" class = "table_southidc">
<Tr>
<TD Height = "30" colspan = "2" align = "center" class = "textbold back_southidc"> Database Backup </TD>
</Tr>
<Tr>
<TD width = "28%" Height = "30" style = "text-align: right;" class = "tr_southidc"> Backup Database Name: </TD>
<TD width = "72%" class = "text_td_item"> <asp: textbox id = "textbox1" runat = "server"/> </TD>
</Tr>
<Tr>
<TD Height = "30" colspan = "2" class = "tr_southidc"> <asp: button id = "button1" runat = "server" onclick = "button#click" text = "backup database"/> </TD>
</Tr>
</Table>
<Br>
<Br>
<Table width = "90%" border = "0" align = "center" cellpadding = "2" cellspacing = "1" class = "table_southidc">
<Tr>
<TD Height = "30" colspan = "3" align = "center" class = "textbold back_southidc"> database restoration <asp: literal id = "literal" runat = "server"> </ASP: literal> </TD>
</Tr>
<Tr>
<TD width = "40%" Height = "30" class = "tr_southidc"> backup database Date: </TD>
<TD width = "27%" class = "tr_southidc"> restore </TD>
<TD width = "33%" class = "tr_southidc"> Delete </TD>
</Tr>
<Asp: repeater id = "repeater1" runat = "server" onitemcommand = "repeater1_command">
<Itemtemplate>
<Tr>
<TD width = "40%" Height = "30" class = "tr_southidc">
<Asp: literal id = "literal1" runat = "server" text = '<% # getdataitem () %>'> </ASP: literal> </TD>
<TD width = "27%" class = "tr_southidc">
<Asp: linkbutton id = "linkbutton1" runat = "server" text = "Restore" commandname = 'huanyuany' commandargument = '<% # getdataitem () %> '> </ASP: linkbutton> </TD>
<TD width = "33%" class = "tr_southidc">
<Asp: linkbutton id = "linkbutton2" runat = "server" text = "delete" commandname = 'shanchu' commandargument = '<% # getdataitem () %> '> </ASP: linkbutton> </TD>
</Tr>
</Itemtemplate>
</ASP: repeater>
</Table>
</Form>
</Body>
</Html>
Using system;
Using system. IO;
Using system. Web. UI. webcontrols;
Public partial class admin_backdata: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
Button1.attributes. Add ("onclick", "Return checkform ();");
Textbox1.text = datetime. Now. tow.datestring ();
Databind ();
}
}
Protected void button#click (Object sender, eventargs E)
{
File. copy (server. mappath (".. /app_data/site. mdb "), server. mappath (".. /app_data/"+ textbox1.text. trim () + ". mdb "), true );
Common. Message ("<SCRIPT> alert ('backup succeeded '); location. href = 'backdata. aspx' </SCRIPT> ");
}
Protected void repeaterinclucommand (Object sender, repeatercommandeventargs E)
{
If (E. Item. itemtype = listitemtype. alternatingitem | E. Item. itemtype = listitemtype. item)
{
String strdate = E. commandargument. tostring ();
String strcom = E. commandname;
Switch (strcom)
{
Case "huanyuan ":
File. copy (server. mappath (".. /app_data/"+ strdate + ". mdb "), server. mappath (".. /app_data/site. mdb "), true );
Break;
Case "shanchu ":
File. Delete (server. mappath ("../app_data/" + strdate + ". mdb "));
Break;
}
Common. Message ("<SCRIPT> alert ('Operation completed '); location. href = 'backdata. aspx' </SCRIPT> ");
}
}
Protected void databind ()
{
String [] S = directory. getfiles (server. mappath ("../app_data /"));
String fullname = string. empty;
For (INT I = 0; I <S. length; I ++)
{
String filename = s [I]. substring (s [I]. lastindexof ("\") + 1 );
String noexfile = filename. substring (0, filename. lastindexof ("."));
Noexfile = noexfile. Replace ("Site ","");
If (noexfile! = String. Empty)
{
If (fullname! = String. Empty)
Fullname = fullname + "," + noexfile;
Else
Fullname = noexfile;
}
}
If (fullname! = String. Empty)
{
String [] B = fullname. Split (New char [] {','});
Repeater1.datasource = B;
Repeater1.databind ();
}
}
}