📄 filemasysdlg.cpp
字号:
// FileMaSysDlg.cpp : implementation file
//
#include "stdafx.h"
#include "FileMaSys.h"
#include "FileMaSysDlg.h"
#include "DlgProxy.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CFileMaSysApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
//数据库自动备份函数
UINT MyBackupDB(LPVOID pParam)
{
CFileMaSysApp * pApp=(CFileMaSysApp *)pParam;
_RecordsetPtr RecordDate;
CString sql;
sql="Select * From DBBackupTable";
RecordDate.CreateInstance("ADODB.Recordset");
RecordDate->Open((_variant_t)sql,_variant_t((IDispatch *)pApp->m_pConnection,true),adOpenDynamic,
adLockPessimistic,adCmdText);
COleDateTime before=RecordDate->GetCollect("BackupDate").date;
COleDateTime now=COleDateTime::GetCurrentTime();
COleDateTimeSpan timelenth=now-before;
long dayTime=timelenth.GetDays();
if (dayTime>30)
{
CString DBPathFrom,DBPathTo;
CHAR exePath[MAX_PATH];
GetModuleFileName(NULL,exePath,MAX_PATH);
CString StartPath;
StartPath=exePath;
int index=StartPath.ReverseFind('\\');
index++;
StartPath=StartPath.Left(index);
DBPathFrom=StartPath+"ProjectManageSys.mdb";
//导出的绝对路径
CTime now1=CTime::GetCurrentTime();
CString strName=now1.Format("%Y%m%d");
strName=strName+".mdb";
DBPathTo="D:\\DBbackup";
CFileFind dirfind;
if (!dirfind.FindFile(DBPathTo))
{
CreateDirectory(DBPathTo,NULL);
}
DBPathTo+=strName;
if (CopyFile(DBPathFrom,DBPathTo,FALSE))
{
RecordDate->PutCollect("BackupDate",_variant_t((DATE)now));
RecordDate->Update();
}
}
return 0;
}
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileMaSysDlg dialog
IMPLEMENT_DYNAMIC(CFileMaSysDlg, CDialog);
CFileMaSysDlg::CFileMaSysDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFileMaSysDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFileMaSysDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pAutoProxy = NULL;
}
CFileMaSysDlg::~CFileMaSysDlg()
{
// If there is an automation proxy for this dialog, set
// its back pointer to this dialog to NULL, so it knows
// the dialog has been deleted.
if (m_pAutoProxy != NULL)
m_pAutoProxy->m_pDialog = NULL;
}
void CFileMaSysDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFileMaSysDlg)
DDX_Control(pDX, IDC_BTN_BACKUP, m_BackupControl);
DDX_Control(pDX, IDCANCEL, m_ExitControl);
DDX_Control(pDX, IDC_BTN_FMANAGE, m_FManageControl);
DDX_Control(pDX, IDC_BTN_USER, m_UserControl);
DDX_Control(pDX, IDC_BTN_QUERY, m_ProQueryControl);
DDX_Control(pDX, IDC_BTN_PMANAGE, m_ProManControl);
DDX_Control(pDX, IDC_PICTURE, m_PictureControl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFileMaSysDlg, CDialog)
//{{AFX_MSG_MAP(CFileMaSysDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_BTN_PMANAGE, OnBtnPmanage)
ON_BN_CLICKED(IDC_BTN_QUERY, OnBtnQuery)
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_BTN_USER, OnBtnUser)
ON_BN_CLICKED(IDC_BTN_FMANAGE, OnBtnFmanage)
ON_BN_CLICKED(IDC_BTN_BACKUP, OnBtnBackup)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileMaSysDlg message handlers
BOOL CFileMaSysDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//获取显示设备大小
int cx, cy;
HDC dc = ::GetDC(NULL);
cx = GetDeviceCaps(dc,HORZRES) + GetSystemMetrics(SM_CXBORDER);
cy = GetDeviceCaps(dc,VERTRES) + GetSystemMetrics(SM_CYBORDER);
::ReleaseDC(0,dc);
//去除标题和边框
SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE) & (~(WS_CAPTION | WS_BORDER)));
//置对话框为最顶端并扩充到整个屏幕
::SetWindowPos(m_hWnd, HWND_TOPMOST,
-(GetSystemMetrics(SM_CXBORDER)+1),
-(GetSystemMetrics(SM_CYBORDER)+1),
cx+1,cy+1, SWP_NOZORDER);
//调整图片控件的位置
CRect rectDialog;
GetClientRect(&rectDialog);
ClientToScreen(&rectDialog);
m_PictureControl.MoveWindow(&rectDialog,TRUE);
//调整按钮的位置
CRect rectBtn;
m_ProManControl.GetWindowRect(&rectBtn);
int btnWidth=rectBtn.Width();
int btnHeignt=rectBtn.Height();
//项目管理按钮的位置
rectBtn.left=cx/2-btnWidth/2;
rectBtn.top=cy/4-btnHeignt/2;
rectBtn.right=rectBtn.left+btnWidth;
rectBtn.bottom=rectBtn.top+btnHeignt;
m_ProManControl.MoveWindow(&rectBtn,TRUE);
//项目查询按钮的位置
rectBtn.left=cx/4-btnWidth/2;
rectBtn.top=cy/2-btnHeignt/2;
rectBtn.right=rectBtn.left+btnWidth;
rectBtn.bottom=rectBtn.top+btnHeignt;
m_ProQueryControl.MoveWindow(&rectBtn,TRUE);
//人员信息按钮的位置
rectBtn.left=cx/2-btnWidth/2;
rectBtn.top=cy/2-btnHeignt/2;
rectBtn.right=rectBtn.left+btnWidth;
rectBtn.bottom=rectBtn.top+btnHeignt;
m_UserControl.MoveWindow(&rectBtn,TRUE);
//档案管理按钮的位置
rectBtn.left=cx*3/4-btnWidth/2;
rectBtn.top=cy/2-btnHeignt/2;
rectBtn.right=rectBtn.left+btnWidth;
rectBtn.bottom=rectBtn.top+btnHeignt;
m_FManageControl.MoveWindow(&rectBtn,TRUE);
//设置数据库备份按钮的位置
rectBtn.left=cx/2-btnWidth/2;
rectBtn.top=cy*3/4-btnHeignt/2;
rectBtn.right=rectBtn.left+btnWidth;
rectBtn.bottom=rectBtn.top+btnHeignt;
m_BackupControl.MoveWindow(&rectBtn,TRUE);
//退出菜单的位置
m_ExitControl.GetWindowRect(&rectBtn);
btnWidth=rectBtn.Width();
btnHeignt=rectBtn.Height();
rectBtn.left=cx*9/10-btnWidth;
rectBtn.top=cy*9/10-btnHeignt;
rectBtn.right=rectBtn.left+btnWidth;
rectBtn.bottom=rectBtn.top+btnHeignt;
m_ExitControl.MoveWindow(&rectBtn,TRUE);
//加载图像
if (!m_bmpBK.LoadBitmap(IDB_BITMAP_BK))
{
MessageBox("加载图片失败");
}
// DIBSECTION ds;
// BITMAPINFOHEADER &bminfo=ds.dsBmih;
// int i=bitmapinfo.bmWidth;
//添加背景图
/* CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP_BK);
bmp.SetBitmapDimension(cx,cy);
m_brBK.CreatePatternBrush(&bmp);
bmp.DeleteObject();*/
//设置项目管理按钮
m_ProManControl.SetIcon(IDI_ICON_PROMANAGE);
m_ProManControl.DrawTransparent(TRUE);
m_ProManControl.SetColor(CButtonST::BTNST_COLOR_FG_IN,RGB(255,0,0));
m_ProManControl.SetAlign(CButtonST::ST_ALIGN_HORIZ);
m_ProManControl.SetTooltipText("可以添加项目到数据库\n可以修改数据库中已有项目\n可以删除项目");
//设置项目查询按钮
m_ProQueryControl.SetIcon(IDI_ICON_PROQUERY);
m_ProQueryControl.DrawTransparent(TRUE);
m_ProQueryControl.SetColor(CButtonST::BTNST_COLOR_FG_IN,RGB(255,0,0));
// m_ProQueryControl.OffsetColor(CButtonST::BTNST_COLOR_FG_IN,128);
m_ProQueryControl.SetAlign(CButtonST::ST_ALIGN_HORIZ);
m_ProQueryControl.SetTooltipText("可以按照各种方式查询\n数据库中已经存在的项目");
//设置人员信息按钮
m_UserControl.SetIcon(IDI_ICON_USER);
m_UserControl.DrawTransparent(TRUE);
m_UserControl.SetColor(CButtonST::BTNST_COLOR_FG_IN,RGB(255,0,0));
m_UserControl.OffsetColor(CButtonST::BTNST_COLOR_FG_IN,128);
m_UserControl.SetAlign(CButtonST::ST_ALIGN_HORIZ);
m_UserControl.SetTooltipText("可以添加修改人员信息");
//设置档案管理按钮
m_FManageControl.SetIcon(IDI_ICON_FMANAGE);
m_FManageControl.DrawTransparent(TRUE);
m_FManageControl.SetColor(CButtonST::BTNST_COLOR_FG_IN,RGB(255,0,0));
m_FManageControl.SetAlign(CButtonST::ST_ALIGN_HORIZ);
m_FManageControl.SetTooltipText("可以管理档案文件借阅、文件归还等");
//设置备份按钮
m_BackupControl.SetIcon(IDI_ICON_BACKUP);
m_BackupControl.DrawTransparent(TRUE);
m_BackupControl.SetColor(CButtonST::BTNST_COLOR_FG_IN,RGB(255,0,0));
m_BackupControl.SetAlign(CButtonST::ST_ALIGN_HORIZ);
m_BackupControl.SetTooltipText("手动备份数据库");
//设置退出按钮
m_ExitControl.SetIcon(IDI_ICON_EXIT);
m_ExitControl.DrawTransparent(TRUE);
m_ExitControl.SetColor(CButtonST::BTNST_COLOR_FG_IN,RGB(255,0,0));
m_ExitControl.SetAlign(CButtonST::ST_ALIGN_HORIZ);
m_ExitControl.SetTooltipText("退出系统");
//开启线程自动备份数据库
AfxBeginThread(MyBackupDB,&theApp);
return TRUE; // return TRUE unless you set the focus to a control
}
void CFileMaSysDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CFileMaSysDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
//动态显示图片
BITMAP bitmapinfo;
m_bmpBK.GetObject(sizeof(BITMAP),&bitmapinfo);
CRect rectPicture;
m_PictureControl.GetWindowRect(&rectPicture);
CPaintDC dcPic(&m_PictureControl);
// CPaintDC dcPic(this);
//创建兼容DC
CDC memdc;
memdc.CreateCompatibleDC(&dcPic);
if (memdc.SelectObject(&m_bmpBK)==NULL)
{
MessageBox("error");
}
/* CBitmap bitmap;
bitmap.CreateCompatibleBitmap(&dcPic,rectPicture.Width(),rectPicture.Height());
memdc.SelectObject(&bitmap);
CBrush brush;
brush.CreatePatternBrush(&m_bmpBK);
dcPic.FillRect(rectPicture,&brush);*/
dcPic.StretchBlt(0,0,rectPicture.Width(),rectPicture.Height(),&memdc,0,0,
bitmapinfo.bmWidth,bitmapinfo.bmHeight,SRCCOPY);
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFileMaSysDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
// Automation servers should not exit when a user closes the UI
// if a controller still holds on to one of its objects. These
// message handlers make sure that if the proxy is still in use,
// then the UI is hidden but the dialog remains around if it
// is dismissed.
void CFileMaSysDlg::OnClose()
{
if (CanExit())
CDialog::OnClose();
}
void CFileMaSysDlg::OnOK()
{
if (CanExit())
CDialog::OnOK();
}
void CFileMaSysDlg::OnCancel()
{
if (CanExit())
CDialog::OnCancel();
}
BOOL CFileMaSysDlg::CanExit()
{
// If the proxy object is still around, then the automation
// controller is still holding on to this application. Leave
// the dialog around, but hide its UI.
if (m_pAutoProxy != NULL)
{
ShowWindow(SW_HIDE);
return FALSE;
}
return TRUE;
}
void CFileMaSysDlg::OnBtnPmanage()
{
// TODO: Add your control notification handler code here
CProManegeMode dlg;
dlg.DoModal();
/*
// CAddSheet m_addsheet("添加项目");
// m_addsheet.SetWizardMode();
// if (m_addsheet.DoModal()==ID_WIZFINISH)
// {
// MessageBox("test");
// }
*/
}
void CFileMaSysDlg::OnBtnQuery()
{
// TODO: Add your control notification handler code here
CQueryDlg dlg;
if (dlg.DoModal()==IDOK)
{
}
}
HBRUSH CFileMaSysDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
/* if (pWnd == this)
{
return m_brBK;
}*/
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CFileMaSysDlg::OnBtnUser()
{
// TODO: Add your control notification handler code here
CUserInfoDlg dlg;
if (dlg.DoModal()==IDOK)
{
}
}
void CFileMaSysDlg::OnBtnFmanage()
{
// TODO: Add your control notification handler code here
CLendInfoDlg dlg;
if (dlg.DoModal()==IDCANCEL)
{
// GetParent()->Invalidate(TRUE);
}
}
//DEL void CFileMaSysDlg::CreateIDList(CWnd *pWnd, CListBox &IDList)
//DEL {
//DEL
//DEL }
//手动备份数据库
void CFileMaSysDlg::OnBtnBackup()
{
// TODO: Add your control notification handler code here
CBackupModeDlg dlg;
if (dlg.DoModal()==IDOK)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -