⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgrestore.cpp

📁 用VC编写的立体仓库的管理软件源程序和设计说明书。
💻 CPP
字号:
// DlgRestore.cpp : implementation file
//

#include "stdafx.h"
#include "Manage_WH.h"
#include "DlgRestore.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgRestore dialog


CDlgRestore::CDlgRestore(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgRestore::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgRestore)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDI_MYICON);
	m_Path = "D:\\Manage_WH\\管理系统数据库备份文件";
}


void CDlgRestore::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgRestore)
	DDX_Control(pDX, IDC_LIST, m_list);
	DDX_Control(pDX, IDC_STATEXT, m_StaText);
	DDX_Control(pDX, IDC_STATITLE, m_StaTitle);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgRestore, CDialog)
	//{{AFX_MSG_MAP(CDlgRestore)
	ON_BN_CLICKED(IDC_RESTORE, OnRestore)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgRestore message handlers

BOOL CDlgRestore::PreTranslateMessage(MSG* pMsg) 
{
	if (pMsg->message==WM_KEYDOWN && (pMsg->wParam==13 || pMsg->wParam==27))
		return TRUE;
	return CDialog::PreTranslateMessage(pMsg);
}

BOOL CDlgRestore::OnInitDialog() 
{
	CDialog::OnInitDialog();

	SetIcon(m_hIcon,TRUE);
	
	m_StaTitle.SetFont("Tohamo");    //字体
	m_StaTitle.SetFontSize(30);     //字体大小
	m_StaTitle.SetFontStyle(false,true,false);    //字体风格
	m_StaTitle.SetTextColor(RGB(255,200,200));    //字体颜色
	m_StaTitle.SetShadow(true,RGB(32,32,32),2,45);  //设置阴影

	m_list.InsertColumn(0,"备份文件",LVCFMT_LEFT,160,-1);
	m_list.InsertColumn(1,"创建时间",LVCFMT_LEFT,160,-1);
	m_list.InsertColumn(2,"修改时间",LVCFMT_LEFT,160,-1);
	m_list.InsertColumn(3,"访问时间",LVCFMT_LEFT,160,-1);
	m_list.InsertColumn(4,"文件大小(字节)",LVCFMT_LEFT,120,-1);
	m_list.SetExtendedStyle( LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT );
	
	SearchFile(m_Path);
	return TRUE;
}

void CDlgRestore::SearchFile(CString strDir)
{
	int row(0);
	CTime tCTime,tMTime,tATime;
	CFileFind ff;
	CFileStatus rStatus;
	CString sFileName,szDir,sCTime,sMTime,sATime,sFSize;
	szDir = strDir;

	if (szDir.Right(1) != "\\")
		szDir += "\\";

	szDir += "*.RDB";

	BOOL res = ff.FindFile(szDir);
	while (res)
	{
		res = ff.FindNextFile();
		if (ff.IsDirectory() && !ff.IsDots())
		{
			//如果是一个子目录,用递归继续往深一层查找
			this->SearchFile(ff.GetFilePath());
		}
		else if (!ff.IsDirectory() && !ff.IsDots())
		{
			//显示找到的文件
			sFileName = ff.GetFileName();
			ff.GetCreationTime(tCTime);
			ff.GetLastWriteTime(tMTime);
			ff.GetLastAccessTime(tATime);
			sFSize.Format("%d",ff.GetLength());
			
			sCTime = tCTime.Format("%Y-%m-%d %H:%M:%S");
			sMTime = tMTime.Format("%Y-%m-%d %H:%M:%S");
			sATime = tATime.Format("%Y-%m-%d %H:%M:%S");

			row = m_list.InsertItem(row,"");
			m_list.SetItemText(row,0,sFileName);
			m_list.SetItemText(row,1,sCTime);
			m_list.SetItemText(row,2,sMTime);
			m_list.SetItemText(row,3,sATime);
			m_list.SetItemText(row,4,sFSize);
			row++;
		}
	}
	ff.Close();
}

void CDlgRestore::OnRestore() 
{
	CString sFileName,sPath;
	//选择要恢复的文件
	for (int i=0;i<m_list.GetItemCount();i++)
	{
		if (m_list.GetItemState(i,LVIS_SELECTED) == LVIS_SELECTED)
		{
			sFileName = m_list.GetItemText(i,0);
			sPath = "D:\\Manage_WH\\管理系统数据库备份文件\\"+sFileName+"";
			break;
		}
	}
	
	if (sFileName.IsEmpty())
	{
		MessageBox("请在列表中选择要恢复的备份文件!","系统提示",MB_ICONSTOP|MB_OK);
		return;
	}

	if (MessageBox("确定要恢复["+sFileName+"]备份的数据吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION) != 1)
		return;
	//关闭定时器,恢复数据
	gpDoc->m_bTimeDealing  = TRUE;
	gpDoc->m_bTimeDealing1 = TRUE;
	gpDoc->m_bTimeDealing2 = TRUE;
	gpDoc->m_bTimeTaskManage = TRUE;
	this->m_StaText.SetWindowText("正在恢复数据,请稍后...");
	//连接mastr
	CAdoConnection cn;
	if (cn.OpenUDLFile(gstrConMaster))
	{
		cn.Execute("RESTORE DATABASE WuHan FROM DISK = '"+sPath+"'",adCmdText);
		cn.Close();
		AddLog("恢复文件"+sFileName+"备份的数据。");
		//打开定时器
		gpDoc->m_bTimeDealing  = FALSE;
		gpDoc->m_bTimeDealing1 = FALSE;
		gpDoc->m_bTimeDealing2 = FALSE;
		gpDoc->m_bTimeTaskManage = FALSE;
		Sleep(3000);
		this->m_StaText.SetWindowText("");
		MessageBox("数据恢复成功!","系统提示",MB_ICONINFORMATION|MB_OK);
	}
	else
	{
		MessageBox("数据恢复失败!","系统提示",MB_ICONSTOP|MB_OK);
	}	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -