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

📄 bak.cpp

📁 一个有关人事系统的所有代码和有关文件包括里面小量数据库。
💻 CPP
字号:
// BAK.cpp : implementation file
//

#include "stdafx.h"
#include "Rsglxt.h"
#include "BAK.h"
#include "ExternDllHeader.h"
#include "DMain.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CRsglxtApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CBAK dialog


CBAK::CBAK(CWnd* pParent /*=NULL*/)
	: CDialog(CBAK::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBAK)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CBAK::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBAK)
	DDX_Control(pDX, IDC_STATIT, m_StaTit);
	DDX_Control(pDX, IDC_STATIP, m_StaTip);
	DDX_Control(pDX, IDC_STAFRAM, m_ButFram);
	DDX_Control(pDX, IDC_EDTPATH, m_EdtPach);
	DDX_Control(pDX, IDC_BUTTON2, m_Button);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBAK, CDialog)
	//{{AFX_MSG_MAP(CBAK)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_WM_PAINT()
	ON_WM_CANCELMODE()
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBAK message handlers

BOOL CBAK::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_EdtPach.SetColour(RGB(0,0,0));//设置编辑框边框颜色
	this->SetWindowText(m_sCaption);
	CString tooltiptext;
	tooltiptext=m_sCaption.Right(4);
	this->m_ButFram.SetWindowText("数据"+tooltiptext);
	this->m_StaTip.SetWindowText(tooltiptext+"路径:");
	this->m_Button.SetWindowText("开始"+tooltiptext);
	this->m_StaTit.SetWindowText("正在"+tooltiptext+"数据,请稍后...");

//	m_ButFram.LoadPic(IDB_BIT_DOWN,IDB_BIT_DOWN,IDB_BIT_DOWN);
	if(m_sCaption=="数据备份")  //载入图片
	{
		m_Button.LoadPic(IDB_BIT_XTBF,IDB_BIT_XTBF,IDB_BIT_XTBF);
	}
	else
	{
		m_Button.LoadPic(IDB_BIT_XTHY,IDB_BIT_XTHY,IDB_BIT_XTHY);
	}
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CBAK::OnButton2() //数据备份和还原按钮
{
	// TODO: Add your control notification handler code here
	CString sPach,sSQL,sName;
	m_EdtPach.GetWindowText(sPach);
	if(sPach.IsEmpty())
	{
		MessageBox("请输入备份文件的路径和名称!","系统提示",MB_OK|MB_ICONSTOP);
		m_EdtPach.SetFocus();
	}
	m_StaTit.ShowWindow(SW_SHOW);
	this->UpdateWindow();
	if(m_sCaption=="数据备份")
	{
		
		sSQL.Format("BACKUP DATABASE RSGLXT TO DISK='%s'",sPach);	//备份语句格式化
		if(rst.Open(sSQL,adCmdText)==false)
		{
			MessageBox("您输入路径不完整或文件夹不存在!请输入完整的路径及文件名!","系统提示",MB_OK|MB_ICONSTOP);
			return;
		}
	}
	else
	{	
		ado.Close();
		cnn=NULL;
		if(ado.SetConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=(local)")==false)	
			return;  //打开数据库连接
		cnn=ado.GetConnection();
		sSQL.Format( "RESTORE DATABASE RSGLXT FROM DISK = '%s'",sPach);//还原语句格式化
    	if(rst.Open(sSQL,adCmdText)==false)
			return;
		ado.Close();
		cnn=NULL;
		this->UpdateWindow();
		if(ado.SetConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=RSGLXT;Data Source=(local)")==false)
		{
			this->m_StaTit.SetWindowText("恢复失败!请重新运行系统!");
			return ;//打开数据库连接
		}
		cnn=ado.GetConnection();
	}
	this->UpdateWindow();
	this->m_StaTit.ShowWindow(SW_HIDE);
	CString sMsg;
	if(m_sCaption=="数据备份")
	{
		sMsg.Format("%s成功!",m_sCaption.Right(4));
		MessageBox(sMsg,"系统提示",MB_OK|MB_ICONINFORMATION);			
	}
	else
	{
		sMsg.Format("%s成功!需要重新启动才可以生效!",m_sCaption.Right(4));
		MessageBox(sMsg,"系统提示",MB_OK|MB_ICONINFORMATION);			
		CDMain * Parent =(CDMain*)this->GetParent();
		this->OnCancel();
		try{
			Parent->Close();
			theApp.m_pMainWnd->DestroyWindow();
		}
		catch(...)
		{
		}
	}
}

void CBAK::OnButton1() //文件选择按钮 
{
	// TODO: Add your control notification handler code here
	CString sPach,sDate;
	CTime ttime;
	ttime=ttime.GetCurrentTime();
	sDate=CTimeToCString(ttime);
	if(m_sCaption=="数据备份")
	{
		sPach=ShowPath();
	int b=sPach.GetLength();
	if(sPach.GetLength()<=3)
		sPach=sPach+sDate+"人事管理系统.bak";
	else
		sPach=sPach+"\\"+sDate+"人事管理系统备份文件.bak";//BAK.DB";  //备份文件路径
	}
	else
	{
		char szFile[]="人事管理系统(*.bak)|*.bak||";
		CFileDialog dlg(true,"DB","",OFN_HIDEREADONLY,szFile,this);  //文件格式
		dlg.DoModal();
		sPach=dlg.GetPathName();
	}
	m_EdtPach.SetWindowText(sPach);
}

void CBAK::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
        CRect rect;
		CBitmap bit;
		CDC memDC;
		this->GetClientRect(&rect);
		bit.LoadBitmap(IDB_BIT_BJ);
		memDC.CreateCompatibleDC(&dc);
		memDC.SelectObject(&bit);
		dc.BitBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);
		memDC.DeleteDC();
		::DeleteObject(&bit);	
		CDialog::OnPaint();
	// Do not call CDialog::OnPaint() for painting messages
}


HBRUSH CBAK::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) //界面背景颜色设置
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	if(nCtlColor==CTLCOLOR_STATIC)
	{
		pDC->SetBkColor(RGB(255,255,255));
		pDC->SetTextColor(RGB(0,0,0));

	}
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

⌨️ 快捷键说明

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