📄 drestore.cpp
字号:
// DRestore.cpp : implementation file
//
#include "stdafx.h"
#include "MyProject.h"
#include "DRestore.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDRestore dialog
CDRestore::CDRestore(CWnd* pParent /*=NULL*/)
: CDialog(CDRestore::IDD, pParent)
{
//{{AFX_DATA_INIT(CDRestore)
//}}AFX_DATA_INIT
}
void CDRestore::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDRestore)
DDX_Control(pDX, IDC_LIST1, m_Grid);
DDX_Control(pDX, IDC_EDTPATH, m_EdtPath);
DDX_Control(pDX, IDC_STATEXT, m_StaText);
DDX_Control(pDX, IDC_STATITLE, m_StaTitle);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDRestore, CDialog)
//{{AFX_MSG_MAP(CDRestore)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTRESTORE, OnButrestore)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
ON_BN_CLICKED(IDC_BUTEXIT, OnButexit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDRestore message handlers
void CDRestore::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
void CDRestore::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CDRestore::OnButton2()
{
m_Grid.DeleteAllItems();
CFileDialog dlg(true,"","",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"物流综合管理系统备份文件|*.RDB|");
dlg.DoModal();
CString sPath;
sPath=dlg.GetPathName();
this->m_EdtPath.SetWindowText(sPath);
CString sSQL;
sSQL.Format("RESTORE HEADERONLY FROM DISK='%s'",sPath);
RxRecordset rst;
rst.Open(sSQL,adCmdText);
CString sNum,sDate;
for(int i=0;i<rst.GetRecordCount();i++)
{
rst.Move(i);
sNum=rst.GetFieldValue("Position");
sDate=rst.GetFieldValue("BackupStartDate");
m_Grid.InsertItem(i,"");
m_Grid.SetItemText(i,0,sNum);
m_Grid.SetItemText(i,1,sDate);
}
}
BOOL CDRestore::OnInitDialog()
{
CDialog::OnInitDialog();
this->m_Grid.InsertColumn(0,"备份次数");
this->m_Grid.InsertColumn(1,"备份日期");
this->m_Grid.SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
this->m_Grid.SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);
m_Grid.m_bReadOnly=true;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDRestore::OnButrestore()
{
CString sPosition,sPath;
m_EdtPath.GetWindowText(sPath);
int nPos;
nPos=m_Grid.GetSelectionMark();
if(nPos<0)
nPos=0;
sPosition=m_Grid.GetItemText(nPos,0);
if(m_Grid.GetItemText(nPos,1).IsEmpty()==true)
return;
// TODO: Add your control notification handler code here
if(MessageBox("确定要恢复["+m_Grid.GetItemText(nPos,1)+"]备份的数据吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
return;
this->m_StaText.SetWindowText("正在恢复,请稍后...");
//关闭数据连接
ado.Close();
cnn=NULL;
//重新连接一个数据源
if(ado.SetConnection("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master;")==false)
{
MessageBox("数据恢复失败!","系统提示",MB_OK|MB_ICONSTOP);
if(ado.SetConnection("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=WLZHGLXT;")==false)
{
MessageBox("无法恢复数据连接,系统需要重新运行!","系统提示",MB_OK|MB_ICONSTOP);
::AfxGetApp()->m_pMainWnd->CloseWindow();
}
return;
}
cnn=ado.GetConnection();
CString sSQL;
//执行备份
sSQL.Format("RESTORE DATABASE WLZHGLXT FROM DISK='%s' WITH FILE=%d",sPath,atoi(sPosition));
RxRecordset rst;
if(rst.Open(sSQL,adCmdText)==false)
MessageBox("数据恢复失败!一个应用程序已打开了数据库,请先将其关闭!","系统提示",MB_OK|MB_ICONSTOP);
else
{
MessageBox("数据恢复成功!","系统提示",MB_OK|MB_ICONEXCLAMATION);
this->m_StaText.SetWindowText("正在恢复数据连接....");
}
//恢复数据连接
ado.Close();
cnn=NULL;
cnn=ado.GetConnection();
if(ado.SetConnection("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=WLZHGLXT;")==false)
{
MessageBox("无法恢复数据连接,系统需要重新运行!","系统提示",MB_OK|MB_ICONSTOP);
::AfxGetApp()->m_pMainWnd->CloseWindow();
}
cnn=ado.GetConnection();
this->m_StaText.SetWindowText("");
}
void CDRestore::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
OnButrestore();
*pResult = 0;
}
void CDRestore::OnButexit()
{
this->OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -