123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776 |
- // lyfzCheckBackupDlg.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "lyfzCheckBackup.h"
- #include "lyfzCheckBackupDlg.h"
- #include <string>
- #include "DataBaseOpt.h"
- #include "Global.h"
- #include "OrderDirMgr.h"
- #include "BackupPhoto.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- typedef enum _MSGCMD_ENUM
- {
- MSG_SHOWREALTIMELOG = WM_USER + 100, //实时显示
- MSG_SHOWPROMPTING = WM_USER + 101, //提示信息
- MSG_DISCONNECT = WM_USER + 102,
- MSG_TRAY_NOTIFICATION = WM_USER + 103
- }MSGCMD_ENUM;
- #define DB_STARTYEAR 2012 //启始年份数据库名
- TCHAR g_strDefaultTip[] = _T("备份检测程序");
- // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
- ClyfzCheckBackupDlg* g_This = NULL;
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // 对话框数据
- enum { IDD = IDD_ABOUTBOX };
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
- // 实现
- protected:
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- END_MESSAGE_MAP()
- // ClyfzCheckBackupDlg 对话框
- ClyfzCheckBackupDlg::ClyfzCheckBackupDlg(CWnd* pParent /*=NULL*/)
- : CDialog(ClyfzCheckBackupDlg::IDD, pParent)
- , m_trayIcon(IDR_MAINFRAME)
- {
- m_nCountTime = 3;
- m_strDays = _T("");
- m_isNotify = TRUE;
- m_bNoticeTray = TRUE;
- m_pDBOpt = NULL;
- memset(m_szDBConnect, 0, sizeof(TCHAR)*MAX_PATH);
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- m_bAutoRuning = AfxGetApp()->GetProfileInt(_T("lyfzCheckBackup"), _T("autoruning"), 0);
- }
- void ClyfzCheckBackupDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(ClyfzCheckBackupDlg, CDialog)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_WM_TIMER()
- ON_WM_DESTROY()
- ON_WM_CLOSE()
- //}}AFX_MSG_MAP
- ON_COMMAND(ID_Menu_Show, &ClyfzCheckBackupDlg::OnShowWnd)
- ON_COMMAND(ID_Menu_Exit, &ClyfzCheckBackupDlg::OnExit)
- ON_BN_CLICKED(IDC_MODIFY_BTN, &ClyfzCheckBackupDlg::OnBnClickedModifyBtn)
- ON_BN_CLICKED(IDC_ADD_BTN, &ClyfzCheckBackupDlg::OnBnClickedAddBtn)
- ON_BN_CLICKED(IDC_DEL_BTN, &ClyfzCheckBackupDlg::OnBnClickedDelBtn)
- ON_BN_CLICKED(IDC_CHECK_BTN, &ClyfzCheckBackupDlg::OnBnClickedCheckBtn)
- // ON_MESSAGE(MSG_SHOWPROMPTING, &ClyfzCheckBackupDlg::ShowPrompting)
- ON_MESSAGE(MSG_TRAY_NOTIFICATION, OnTrayNotification)
- ON_BN_CLICKED(IDC_CANCEL_BTN, &ClyfzCheckBackupDlg::OnBnClickedCancelBtn)
- END_MESSAGE_MAP()
- // ClyfzCheckBackupDlg 消息处理程序
- BOOL ClyfzCheckBackupDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // 将“关于...”菜单项添加到系统菜单中。
- // IDM_ABOUTBOX 必须在系统命令范围内。
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- BOOL bNameValid;
- CString strAboutMenu;
- bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
- ASSERT(bNameValid);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
- // 执行此操作
- SetIcon(m_hIcon, TRUE); // 设置大图标
- SetIcon(m_hIcon, FALSE); // 设置小图标
- ShowWindow(SW_MINIMIZE);
- // TODO: 在此添加额外的初始化代码
- InitTrayIcon();
- //默认检测前120天
- ((CEdit*)GetDlgItem(IDC_DAY_EDIT))->SetWindowText(_T("120"));
- //读取.ini数据库配文件
- TCHAR szPath[MAX_PATH+1] = {0};
- #ifdef _UNICODE
- wsprintf(szPath, _T("%sServiceInfo.ini"), g_szModuleFilePath);
- #else
- sprintf(szPath, _T("%sServiceInfo.ini"), g_szModuleFilePath);
- #endif
- LoadConnect(szPath);
- if(m_pDBOpt == NULL)
- m_pDBOpt = new DataBaseOpt;
- if(!m_pDBOpt->OpenDB(m_szDBConnect))
- {
- CString strError = _T("");
- strError.Format(_T("打开数据库:%s失败"), m_szDBConnect);
- WriteLogin(strError);
- return FALSE;
- }
-
- TCHAR szDllPath[MAX_PATH+1] = {0};
- #ifdef _UNICODE
- wsprintf(szDllPath, _T("%slyfzBackupModle.dll"), g_szModuleFilePath);
- #else
- sprintf(szDllPath, _T("%slyfzBackupModle.dll"), g_szModuleFilePath);
- #endif
- BackupPhoto::GetInstance()->LoadBakModule(szDllPath);
- //获取增量备份的记录
- GetBackupLogs(m_BackupLogsArr);
- //从数据库获取备份目录
- OrderDirMgr::GetInstance()->InitShareDir(m_pDBOpt, g_szDomain);
- //初始化共享目录
- std::vector<LPTblNetShareInfo>* pVShare = OrderDirMgr::GetInstance()->GetShareDirs();
- std::vector<LPTblNetShareInfo>::iterator it = pVShare->begin();
- for(;it != pVShare->end();++it)
- {
- LPTblNetShareInfo lp = (*it);
- if(lp == NULL)
- continue;
- BackupPhoto::GetInstance()->InitShareDirData(lp);
- }
- //获取订单目录
- CString strStart(_T("")), strEnd(_T("")), strFilter(_T(""));
- GetDateRangeFilter(strStart, strEnd, strFilter);
- OrderDirMgr::GetInstance()->GetOrderOfDir(strStart, strEnd, g_szDomain);
- //筛选订单目录
- OrderDirMgr::GetInstance()->ScreeningOrderDir(m_BackupLogsArr, g_szDomain);
-
- //test 调试输出要备份的目录
- std::vector<LPSORDERDIRINFO>* pV = OrderDirMgr::GetInstance()->GetOrderDirs();
- std::vector<LPSORDERDIRINFO>::iterator iter = pV->begin();
- for(;iter != pV->end(); ++iter)
- {
- LPSORDERDIRINFO lp = (*iter);
- if(lp != NULL)
- {
- CString strMsg = _T("");
- strMsg.Format(_T("%s\n"), lp->szPath);
- WriteLogin(strMsg);
- }
- }
- memset(szPath, 0, sizeof(TCHAR)*(MAX_PATH + 1));
- #ifdef _UNICODE
- wsprintf(szPath, _T("%slyfzBackupModle.dll"), g_szModuleFilePath);
- #else
- sprintf(szPath, _T("%slyfzBackupModle.dll"), g_szModuleFilePath);
- #endif
- g_This = this;
- CString strName = _T("");
- strName.Format(_T("检测(%d)"), m_nCountTime);
- SetDlgItemText(IDC_CHECK_BTN, strName);
- --m_nCountTime;
- OnShowWnd();
- SetTimer(2, 1000, 0);
- return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
- }
- void ClyfzCheckBackupDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // 如果向对话框添加最小化按钮,则需要下面的代码
- // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
- // 这将由框架自动完成。
- void ClyfzCheckBackupDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // 用于绘制的设备上下文
- SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
- // 使图标在工作区矩形中居中
- 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;
- // 绘制图标
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- //当用户拖动最小化窗口时系统调用此函数取得光标
- //显示。
- HCURSOR ClyfzCheckBackupDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- void ClyfzCheckBackupDlg::InitTrayIcon()
- {
- m_trayIcon.SetNotificationWnd(this, MSG_TRAY_NOTIFICATION);
- m_trayIcon.SetIcon(IDR_MAINFRAME, g_strDefaultTip);
- m_trayIcon.SetIconInfos((INT)IDR_MAINFRAME, (INT)IDI_WARNING, (UINT)IDI_TRANSPARENT);
- m_trayIcon.SetDefaultTip(g_strDefaultTip);
- }
- LRESULT ClyfzCheckBackupDlg::OnTrayNotification(WPARAM wp, LPARAM lp)
- {
- if(wp != IDR_MAINFRAME)
- return m_trayIcon.OnTrayNotification(wp, lp);
- switch(lp)
- {
- case WM_RBUTTONUP:
- TrayRight();
- break;
- case WM_LBUTTONUP:
- TaskNotifyIcon();
- break;
- default:
- break;
- }
- return 0;
- }
- void ClyfzCheckBackupDlg::TaskNotifyIcon()
- {
- if ( !m_bNoticeTray )
- {
- m_trayIcon.SetIcon(IDR_MAINFRAME, g_strDefaultTip);
- ShowWindow(SW_SHOWNORMAL);
- m_bNoticeTray = TRUE;
- }
- else
- {
- m_trayIcon.SetIcon(IDR_MAINFRAME, g_strDefaultTip);
- ShowWindow(SW_HIDE);
- m_bNoticeTray = FALSE;
- }
- }
- void ClyfzCheckBackupDlg::TrayRight()
- {
- CMenu menu;
- if (!menu.LoadMenu(IDR_MENU1))
- return ;
- CMenu* pSubMenu = menu.GetSubMenu(0);
- if (!pSubMenu)
- return ;
- /*
- //开机自动运行菜单
- if(m_bAutoRuning)
- pSubMenu->CheckMenuItem(Menu_AutoRun, MF_BYCOMMAND | MF_CHECKED);
- else
- pSubMenu->CheckMenuItem(Menu_AutoRun, MF_BYCOMMAND | MF_UNCHECKED);
- */
- CPoint point;
- GetCursorPos(&point);
- ::SetForegroundWindow(m_hWnd);
- pSubMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this);
- }
- BOOL ClyfzCheckBackupDlg::PreTranslateMessage(MSG* pMsg)
- {
- if (pMsg->message == WM_KEYDOWN)
- {
- CWnd *pWnd = GetFocus(); //获得当前光标所在控件
- if (pWnd != NULL && pWnd == GetDlgItem(IDC_DAY_EDIT))
- {
- int nNum = (int)pMsg->wParam;
- if(nNum == 8) //VK_Backspace
- return FALSE;
- CString str = _T("");
- ((CEdit*)GetDlgItem(IDC_DAY_EDIT))->GetWindowText(str);
- if(str.GetLength() >= 3)
- return TRUE;
- if(nNum < 48 || nNum > 57) //VK_(0~9)
- return TRUE;
- }
- }
- return CDialog::PreTranslateMessage(pMsg);
- }
- //修改
- void ClyfzCheckBackupDlg::OnBnClickedModifyBtn()
- {
- // TODO: 在此添加控件通知处理程序代码
- }
- //添加
- void ClyfzCheckBackupDlg::OnBnClickedAddBtn()
- {
- // TODO: 在此添加控件通知处理程序代码
- }
- //删除
- void ClyfzCheckBackupDlg::OnBnClickedDelBtn()
- {
- // TODO: 在此添加控件通知处理程序代码
- }
- //检测
- void ClyfzCheckBackupDlg::OnBnClickedCheckBtn()
- {
- if(BackupPhoto::GetInstance()->IsBackupping())
- return;
-
- SetTimer(1, 2000, 0);
- ((CButton*)GetDlgItem(IDC_CHECK_BTN))->EnableWindow(FALSE);
- ((CButton*)GetDlgItem(IDC_CANCEL_BTN))->EnableWindow(FALSE);
- // TODO: 在此添加控件通知处理程序代码
- std::vector<LPSORDERDIRINFO>* pV = OrderDirMgr::GetInstance()->GetOrderDirs();
- std::vector<LPSORDERDIRINFO>::iterator it = pV->begin();
- for(;it != pV->end(); ++it)
- {
- LPSORDERDIRINFO lp = (*it);
- if(lp == NULL)
- continue;
- //查找可用的备份目录
- CString strDir = _T("");
- if(!OrderDirMgr::GetInstance()->FindEnableBakDir(lp->byPhotoType + 4, strDir))
- continue;
- BackupPhoto::GetInstance()->InitBackupInfo(lp->szDomain, lp->szOrder, strDir, lp->byPhotoType, FALSE);
- }
- BackupPhoto::GetInstance()->StartBackup(g_szDomain, BackupCallBack);
- WriteLogin(_T("备份完成"));
- }
- //提示信息
- LRESULT ClyfzCheckBackupDlg::ShowPrompting(WPARAM wParam, LPARAM lParam)
- {
- /*
- int nShowType = lParam;
- CString strMSG = *(CString*)wParam;
- static CHARFORMAT cf;
- cf.cbSize = sizeof(CHARFORMAT);
- static COleDateTime oletime;
- oletime=COleDateTime::GetCurrentTime();
- strMSG.Format(_T("%s: #%s.\r"),oletime.Format(_T("%Y/%m/%d %H:%M:%S")),strMSG);
- //strMSG += ".\r";
- if ( nShowType == 1) // 错误信息提示
- {
- // 显示前,设置字体颜色;
- //m_EditShow.GetDefaultCharFormat(cf);
- m_BakMsgCtrl.GetDefaultCharFormat(cf);
- cf.dwMask=CFM_COLOR|CFM_FACE|CFM_SIZE|CFM_BOLD;
- cf.dwEffects = (unsigned long)~(CFE_UNDERLINE | CFE_BOLD | CFE_AUTOCOLOR);
- //cf.dwEffects ^= CFE_AUTOCOLOR;
- cf.crTextColor = RGB(255, 0, 0);
- cf.yHeight = 180;
- memset(cf.szFaceName, 0, LF_FACESIZE);
- // memcpy(cf.szFaceName, "楷体_GB2312", sizeof("楷体_GB2312"));
- memcpy(cf.szFaceName, _T("宋体"), sizeof(_T("宋体")));
- m_BakMsgCtrl.SetSelectionCharFormat(cf);
- m_BakMsgCtrl.SetSel(-1,-1);
- m_BakMsgCtrl.ReplaceSel(strMSG);
- }
- else // 成功信息提示;
- {
- m_BakMsgCtrl.GetDefaultCharFormat(cf);
- cf.dwMask=CFM_COLOR|CFM_FACE|CFM_SIZE|CFM_BOLD;
- cf.dwEffects = (unsigned long)~(CFE_UNDERLINE | CFE_BOLD | CFE_AUTOCOLOR);
- //cf.dwEffects ^= CFE_AUTOCOLOR;
- cf.crTextColor = RGB(0, 0, 255);
- cf.yHeight = 180;
- memset(cf.szFaceName, 0, LF_FACESIZE);
- // memcpy(cf.szFaceName, "楷体_GB2312", sizeof("楷体_GB2312"));
- memcpy(cf.szFaceName, _T("宋体"), sizeof(_T("宋体")));
- m_BakMsgCtrl.SetSelectionCharFormat(cf);
- m_BakMsgCtrl.SetSel(-1,-1);
- m_BakMsgCtrl.ReplaceSel(strMSG);
- }
- m_BakMsgCtrl.PostMessage(WM_VSCROLL, SB_BOTTOM,0);
- */
- return 0;
- }
- void ClyfzCheckBackupDlg::OnDestroy()
- {
- std::vector<TCHAR*>::iterator it = m_vDBConnect.begin();
- for(;it != m_vDBConnect.end();)
- {
- if((*it) != NULL)
- delete [] (*it);
- ++it;
- }
- m_vDBConnect.clear();
- if(m_pDBOpt !=NULL)
- delete m_pDBOpt;
- m_pDBOpt = NULL;
- CDialog::OnDestroy();
- }
- /************************************************************************/
- /*
- 函数: LoadConnect
- 描述: 加载连接数据
- 参数:
- LPCTSTR lpPath 路径
- 返回: 1成功,0失败
- */
- /************************************************************************/
- int ClyfzCheckBackupDlg::LoadConnect(LPCTSTR lpPath)
- {
- if(!PathFileExists(lpPath))
- {
- CString strError = _T("");
- strError.Format(_T("文件%s不存在,加载失败!"), lpPath);
- // SendMessage(MSG_SHOWPROMPTING,(WPARAM)&strError, 1);
- return 0;
- }
- TCHAR szDBServer[MAX_PATH] = {0}; // 服务器名
- DWORD dwDBServerPort = 0; // 端口
- TCHAR szDBAccount[MAX_PATH] = {0}; // 帐号
- TCHAR szDBPassWord[MAX_PATH] = {0}; // 密码
- TCHAR szDBName[MAX_PATH] = {0}; // 数据库名
- GetPrivateProfileString(_T("DatabaseInfo"), _T("dbSource"), _T(""), szDBServer, MAX_PATH, lpPath);
- dwDBServerPort = GetPrivateProfileInt(_T("DatabaseInfo"), _T("dbServerPort"), 0, lpPath);
- GetPrivateProfileString(_T("DatabaseInfo"), _T("dbAccount"), _T(""), szDBAccount, MAX_PATH, lpPath);
- GetPrivateProfileString(_T("DatabaseInfo"), _T("dbPassWord"), _T(""), szDBPassWord, MAX_PATH, lpPath);
- GetPrivateProfileString(_T("DatabaseInfo"), _T("dbName"), _T(""), szDBName, MAX_PATH, lpPath);
- //当前数据库db连接
- if (dwDBServerPort != 0)
- wsprintf(m_szDBConnect, _T("driver={SQL Server};Server=%s,%d;database=%s;uid=%s;pwd=%s"),
- szDBServer, dwDBServerPort, szDBName, szDBAccount, szDBPassWord);
- else
- wsprintf(m_szDBConnect, _T("driver={SQL Server};Server=%s;database=%s;uid=%s;pwd=%s"),
- szDBServer, szDBName, szDBAccount, szDBPassWord);
- /*多个数据库连接
- CTime ct = CTime::GetCurrentTime();
- int nStartYear = DB_STARTYEAR;
- while(nStartYear <= ct.GetYear())
- {
- TCHAR* p = new TCHAR[sizeof(TCHAR)*MAX_PATH + 1];
- memset(p, 0, sizeof(sizeof(TCHAR)*MAX_PATH + 1));
- if(nStartYear == ct.GetYear())
- {
- //当前数据库db连接
- if (dwDBServerPort != 0)
- wsprintf(p, _T("driver={SQL Server};Server=%s,%d;database=%s;uid=%s;pwd=%s"),
- szDBServer, dwDBServerPort, szDBName, szDBAccount, szDBPassWord);
- else
- wsprintf(p, _T("driver={SQL Server};Server=%s;database=%s;uid=%s;pwd=%s"),
- szDBServer, szDBName, szDBAccount, szDBPassWord);
- }
- else
- {
- //历史数据库连接从2012开始
- TCHAR szDate[8] = {0};
- #ifdef _UNICODE
- wsprintf(szDate, _T("%d"), nStartYear);
- #else
- sprintf(szDate, _T("%d"), nStartYear);
- #endif //#ifdef _UNICODE
- if (dwDBServerPort != 0)
- wsprintf(p, _T("driver={SQL Server};Server=%s,%d;database=%s;uid=%s;pwd=%s"),
- szDBServer, dwDBServerPort, szDate, szDBAccount, szDBPassWord);
- else
- wsprintf(p, _T("driver={SQL Server};Server=%s;database=%s;uid=%s;pwd=%s"),
- szDBServer, szDate, szDBAccount, szDBPassWord);
- }
- m_vDBConnect.push_back(p);
- ++nStartYear;
- }
- */
- return 1;
- }
- /************************************************************************/
- /*
- 函数: GetBackupLogs
- 描述: 获取备份记录
- 参数:
- OUT CString& strStart, 返回开始时间
- OUT CString& strEnd, 返回截止时间
- OUT CString& strFilter 返回sql语句:字段 between date1 and date2
- 返回: 1成功,0失败
- */
- /************************************************************************/
- void ClyfzCheckBackupDlg::GetDateRangeFilter(OUT CString& strStart, OUT CString& strEnd, OUT CString& strFilter)
- {
- CTime ct = CTime::GetCurrentTime();
- CString strDay = _T("");
- ((CEdit*)GetDlgItem(IDC_DAY_EDIT))->GetWindowText(strDay);
- if(strDay == _T(""))
- {
- MessageBox(_T("请输入天数!"));
- return;
- }
- int nDay = _ttoi(strDay);
- CTimeSpan sp(nDay, 0, 0, 0);
- CTime oldct = ct - sp;
- strStart.Format(_T("%04d-%02d-%02d"), oldct.GetYear(), oldct.GetMonth(), oldct.GetDay());
- strEnd.Format(_T("%04d-%02d-%02d"), ct.GetYear(), ct.GetMonth(), ct.GetDay());
- strFilter.Format(_T("opttime between '%s' and '%s'"), strStart, strEnd);
- }
- /************************************************************************/
- /*
- 函数: GetBackupLogs
- 描述: 获取备份记录
- 参数:
- OUT CArray<CStringArray,CStringArray>& logsArr 返回记录集合
- 返回: 1成功,0失败
- */
- /************************************************************************/
- void ClyfzCheckBackupDlg::GetBackupLogs(OUT CArray<CStringArray,CStringArray>& logsArr)
- {
- if(m_pDBOpt == NULL)
- return;
- if(m_pDBOpt->IsOpenDB())
- m_pDBOpt->CloseDB();
- if(m_pDBOpt->OpenDB(m_szDBConnect))
- {
- CString strStart(_T("")), strEnd(_T("")), strFilter(_T(""));
- GetDateRangeFilter(strStart, strEnd, strFilter);
- std::vector<CString> vFields;
- vFields.push_back(_T("isbackup"));
- vFields.push_back(_T("branchid"));
- vFields.push_back(_T("opttime"));
- vFields.push_back(_T("[order]"));
- vFields.push_back(_T("photoType"));
- vFields.push_back(_T("[content]"));
- vFields.push_back(_T("userid"));
- vFields.push_back(_T("username"));
- vFields.push_back(_T("baktime"));
- if(strFilter == _T(""))
- m_pDBOpt->Select(logsArr, _T("IncrementalBackup"), vFields);
- else
- m_pDBOpt->Select(logsArr, _T("IncrementalBackup"), vFields, strFilter);
- }
- }
- /************************************************************************/
- /*
- 函数: CheckTheStringIsNum
- 描述: 检测是否为数字
- 参数:
- const CString& strNum 数字字符
- 返回: 1是数字,0不是纯数字
- */
- /************************************************************************/
- int ClyfzCheckBackupDlg::CheckTheStringIsNum(const CString& strNum)
- {
- CString strTemp = strNum;
- int nIdx = 0;
- while(nIdx < strTemp.GetLength())
- {
- if(strTemp.GetAt(nIdx) < 48 || strTemp.GetAt(nIdx) > 57)
- return 0;
- ++nIdx;
- }
- return 1;
- }
- void ClyfzCheckBackupDlg::OnTimer(UINT_PTR nIDEvent)
- {
- if(nIDEvent == 1)
- {
- if(!BackupPhoto::GetInstance()->IsBackupping())
- {
- KillTimer(nIDEvent);
- WriteLogin(_T("备份完成"));
- OnExit();
- }
- }
- if(nIDEvent == 2)
- {
- CString strName = _T("");
- strName.Format(_T("检测(%d)"), m_nCountTime);
- SetDlgItemText(IDC_CHECK_BTN, strName);
- if(m_nCountTime == 0)
- {
- KillTimer(2);
- OnClose();
- OnBnClickedCheckBtn();
- }
- else
- --m_nCountTime;
- }
- CDialog::OnTimer(nIDEvent);
- }
- /************************************************************************/
- /*
- 函数:BackupFinish
- 描述:增量备份完成回调
- 参数:
- LPVOID, 回调传回值
- LPVOID,
- LPVOID,
- LPVOID,
- LPVOID,
- LPVOID
- 返回:1成功,0失败
- */
- /************************************************************************/
- int WINAPI ClyfzCheckBackupDlg::BackupCallBack(IN LPVOID lpParam1, IN LPVOID lpParam2, IN LPVOID lpParam3, IN LPVOID lpParam4, IN LPVOID lpParam5, IN LPVOID lpParam6)
- {
- return g_This->BackupCallBackPro(lpParam1, lpParam2, lpParam3, lpParam4, lpParam5, lpParam6);
- }
- /************************************************************************/
- /*
- 函数:BackupFinish
- 描述:增量备份完成回调
- 参数:
- LPVOID, 回调传回值
- LPVOID,
- LPVOID,
- LPVOID,
- LPVOID,
- LPVOID
- 返回:1成功,0失败
- */
- /************************************************************************/
- int ClyfzCheckBackupDlg::BackupCallBackPro(IN LPVOID lpParam1, IN LPVOID lpParam2, IN LPVOID lpParam3, IN LPVOID lpParam4, IN LPVOID lpParam5, IN LPVOID lpParam6)
- {
- int nPercent = *((int*)lpParam1);
- CString strMsg = _T("");
- strMsg.Format(_T("完成:%d\n"), nPercent);
- WriteLogin(strMsg);
- if ( nPercent == 100 )
- {
- if(m_pDBOpt == NULL)
- return 0;
- try
- {
- TCHAR szDate[32] = {0};
- CTime ct = CTime::GetCurrentTime();
- _tcscpy(szDate, ct.Format(_T("%Y-%m-%d %H:%M:%S.000")));
- CString strSql = _T("");
- strSql.Format(INSERT_INCREMENT, 1, (TCHAR*)lpParam2, (TCHAR*)lpParam3, (TCHAR*)lpParam4, *((BYTE*)lpParam5), (TCHAR*)lpParam6, _T("admin"), _T("管理员"), szDate);
- m_pDBOpt->Execute(strSql);
- }
- catch (CException *e)
- {
- TCHAR szError[1024] = { 0 };
- e->GetErrorMessage(szError, 1024);
- CString strErrorMsg = _T("");
- strErrorMsg.Format(_T("增量备份回调错误:%s\n"), szError);
- WriteLogin(strErrorMsg);
- e->Delete();
- }
- }
- return 1;
- }
- void ClyfzCheckBackupDlg::OnClose()
- {
- ShowWindow(SW_HIDE);
- }
- void ClyfzCheckBackupDlg::OnExit()
- {
- CDialog::OnOK();
- }
- void ClyfzCheckBackupDlg::OnShowWnd()
- {
- ShowWindow(SW_SHOWDEFAULT);
- }
- void ClyfzCheckBackupDlg::OnBnClickedCancelBtn()
- {
- // TODO: 在此添加控件通知处理程序代码
- OnExit();
- }
|