lyfzCheckBackupDlg.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. // lyfzCheckBackupDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "lyfzCheckBackup.h"
  5. #include "lyfzCheckBackupDlg.h"
  6. #include <string>
  7. #include "DataBaseOpt.h"
  8. #include "Global.h"
  9. #include "OrderDirMgr.h"
  10. #include "BackupPhoto.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. typedef enum _MSGCMD_ENUM
  17. {
  18. MSG_SHOWREALTIMELOG = WM_USER + 100, //实时显示
  19. MSG_SHOWPROMPTING = WM_USER + 101, //提示信息
  20. MSG_DISCONNECT = WM_USER + 102,
  21. MSG_TRAY_NOTIFICATION = WM_USER + 103
  22. }MSGCMD_ENUM;
  23. #define DB_STARTYEAR 2012 //启始年份数据库名
  24. TCHAR g_strDefaultTip[] = _T("备份检测程序");
  25. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  26. ClyfzCheckBackupDlg* g_This = NULL;
  27. class CAboutDlg : public CDialog
  28. {
  29. public:
  30. CAboutDlg();
  31. // 对话框数据
  32. enum { IDD = IDD_ABOUTBOX };
  33. protected:
  34. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
  35. // 实现
  36. protected:
  37. DECLARE_MESSAGE_MAP()
  38. };
  39. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  40. {
  41. }
  42. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  43. {
  44. CDialog::DoDataExchange(pDX);
  45. }
  46. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  47. END_MESSAGE_MAP()
  48. // ClyfzCheckBackupDlg 对话框
  49. ClyfzCheckBackupDlg::ClyfzCheckBackupDlg(CWnd* pParent /*=NULL*/)
  50. : CDialog(ClyfzCheckBackupDlg::IDD, pParent)
  51. , m_trayIcon(IDR_MAINFRAME)
  52. {
  53. m_nCountTime = 3;
  54. m_strDays = _T("");
  55. m_isNotify = TRUE;
  56. m_bNoticeTray = TRUE;
  57. m_pDBOpt = NULL;
  58. memset(m_szDBConnect, 0, sizeof(TCHAR)*MAX_PATH);
  59. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  60. m_bAutoRuning = AfxGetApp()->GetProfileInt(_T("lyfzCheckBackup"), _T("autoruning"), 0);
  61. }
  62. void ClyfzCheckBackupDlg::DoDataExchange(CDataExchange* pDX)
  63. {
  64. CDialog::DoDataExchange(pDX);
  65. }
  66. BEGIN_MESSAGE_MAP(ClyfzCheckBackupDlg, CDialog)
  67. ON_WM_SYSCOMMAND()
  68. ON_WM_PAINT()
  69. ON_WM_QUERYDRAGICON()
  70. ON_WM_TIMER()
  71. ON_WM_DESTROY()
  72. ON_WM_CLOSE()
  73. //}}AFX_MSG_MAP
  74. ON_COMMAND(ID_Menu_Show, &ClyfzCheckBackupDlg::OnShowWnd)
  75. ON_COMMAND(ID_Menu_Exit, &ClyfzCheckBackupDlg::OnExit)
  76. ON_BN_CLICKED(IDC_MODIFY_BTN, &ClyfzCheckBackupDlg::OnBnClickedModifyBtn)
  77. ON_BN_CLICKED(IDC_ADD_BTN, &ClyfzCheckBackupDlg::OnBnClickedAddBtn)
  78. ON_BN_CLICKED(IDC_DEL_BTN, &ClyfzCheckBackupDlg::OnBnClickedDelBtn)
  79. ON_BN_CLICKED(IDC_CHECK_BTN, &ClyfzCheckBackupDlg::OnBnClickedCheckBtn)
  80. // ON_MESSAGE(MSG_SHOWPROMPTING, &ClyfzCheckBackupDlg::ShowPrompting)
  81. ON_MESSAGE(MSG_TRAY_NOTIFICATION, OnTrayNotification)
  82. ON_BN_CLICKED(IDC_CANCEL_BTN, &ClyfzCheckBackupDlg::OnBnClickedCancelBtn)
  83. END_MESSAGE_MAP()
  84. // ClyfzCheckBackupDlg 消息处理程序
  85. BOOL ClyfzCheckBackupDlg::OnInitDialog()
  86. {
  87. CDialog::OnInitDialog();
  88. // 将“关于...”菜单项添加到系统菜单中。
  89. // IDM_ABOUTBOX 必须在系统命令范围内。
  90. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  91. ASSERT(IDM_ABOUTBOX < 0xF000);
  92. CMenu* pSysMenu = GetSystemMenu(FALSE);
  93. if (pSysMenu != NULL)
  94. {
  95. BOOL bNameValid;
  96. CString strAboutMenu;
  97. bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
  98. ASSERT(bNameValid);
  99. if (!strAboutMenu.IsEmpty())
  100. {
  101. pSysMenu->AppendMenu(MF_SEPARATOR);
  102. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  103. }
  104. }
  105. // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  106. // 执行此操作
  107. SetIcon(m_hIcon, TRUE); // 设置大图标
  108. SetIcon(m_hIcon, FALSE); // 设置小图标
  109. ShowWindow(SW_MINIMIZE);
  110. // TODO: 在此添加额外的初始化代码
  111. InitTrayIcon();
  112. //默认检测前120天
  113. ((CEdit*)GetDlgItem(IDC_DAY_EDIT))->SetWindowText(_T("120"));
  114. //读取.ini数据库配文件
  115. TCHAR szPath[MAX_PATH+1] = {0};
  116. #ifdef _UNICODE
  117. wsprintf(szPath, _T("%sServiceInfo.ini"), g_szModuleFilePath);
  118. #else
  119. sprintf(szPath, _T("%sServiceInfo.ini"), g_szModuleFilePath);
  120. #endif
  121. LoadConnect(szPath);
  122. if(m_pDBOpt == NULL)
  123. m_pDBOpt = new DataBaseOpt;
  124. if(!m_pDBOpt->OpenDB(m_szDBConnect))
  125. {
  126. CString strError = _T("");
  127. strError.Format(_T("打开数据库:%s失败"), m_szDBConnect);
  128. WriteLogin(strError);
  129. return FALSE;
  130. }
  131. TCHAR szDllPath[MAX_PATH+1] = {0};
  132. #ifdef _UNICODE
  133. wsprintf(szDllPath, _T("%slyfzBackupModle.dll"), g_szModuleFilePath);
  134. #else
  135. sprintf(szDllPath, _T("%slyfzBackupModle.dll"), g_szModuleFilePath);
  136. #endif
  137. BackupPhoto::GetInstance()->LoadBakModule(szDllPath);
  138. //获取增量备份的记录
  139. GetBackupLogs(m_BackupLogsArr);
  140. //从数据库获取备份目录
  141. OrderDirMgr::GetInstance()->InitShareDir(m_pDBOpt, g_szDomain);
  142. //初始化共享目录
  143. std::vector<LPTblNetShareInfo>* pVShare = OrderDirMgr::GetInstance()->GetShareDirs();
  144. std::vector<LPTblNetShareInfo>::iterator it = pVShare->begin();
  145. for(;it != pVShare->end();++it)
  146. {
  147. LPTblNetShareInfo lp = (*it);
  148. if(lp == NULL)
  149. continue;
  150. BackupPhoto::GetInstance()->InitShareDirData(lp);
  151. }
  152. //获取订单目录
  153. CString strStart(_T("")), strEnd(_T("")), strFilter(_T(""));
  154. GetDateRangeFilter(strStart, strEnd, strFilter);
  155. OrderDirMgr::GetInstance()->GetOrderOfDir(strStart, strEnd, g_szDomain);
  156. //筛选订单目录
  157. OrderDirMgr::GetInstance()->ScreeningOrderDir(m_BackupLogsArr, g_szDomain);
  158. //test 调试输出要备份的目录
  159. std::vector<LPSORDERDIRINFO>* pV = OrderDirMgr::GetInstance()->GetOrderDirs();
  160. std::vector<LPSORDERDIRINFO>::iterator iter = pV->begin();
  161. for(;iter != pV->end(); ++iter)
  162. {
  163. LPSORDERDIRINFO lp = (*iter);
  164. if(lp != NULL)
  165. {
  166. CString strMsg = _T("");
  167. strMsg.Format(_T("%s\n"), lp->szPath);
  168. WriteLogin(strMsg);
  169. }
  170. }
  171. memset(szPath, 0, sizeof(TCHAR)*(MAX_PATH + 1));
  172. #ifdef _UNICODE
  173. wsprintf(szPath, _T("%slyfzBackupModle.dll"), g_szModuleFilePath);
  174. #else
  175. sprintf(szPath, _T("%slyfzBackupModle.dll"), g_szModuleFilePath);
  176. #endif
  177. g_This = this;
  178. CString strName = _T("");
  179. strName.Format(_T("检测(%d)"), m_nCountTime);
  180. SetDlgItemText(IDC_CHECK_BTN, strName);
  181. --m_nCountTime;
  182. OnShowWnd();
  183. SetTimer(2, 1000, 0);
  184. return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
  185. }
  186. void ClyfzCheckBackupDlg::OnSysCommand(UINT nID, LPARAM lParam)
  187. {
  188. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  189. {
  190. CAboutDlg dlgAbout;
  191. dlgAbout.DoModal();
  192. }
  193. else
  194. {
  195. CDialog::OnSysCommand(nID, lParam);
  196. }
  197. }
  198. // 如果向对话框添加最小化按钮,则需要下面的代码
  199. // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  200. // 这将由框架自动完成。
  201. void ClyfzCheckBackupDlg::OnPaint()
  202. {
  203. if (IsIconic())
  204. {
  205. CPaintDC dc(this); // 用于绘制的设备上下文
  206. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  207. // 使图标在工作区矩形中居中
  208. int cxIcon = GetSystemMetrics(SM_CXICON);
  209. int cyIcon = GetSystemMetrics(SM_CYICON);
  210. CRect rect;
  211. GetClientRect(&rect);
  212. int x = (rect.Width() - cxIcon + 1) / 2;
  213. int y = (rect.Height() - cyIcon + 1) / 2;
  214. // 绘制图标
  215. dc.DrawIcon(x, y, m_hIcon);
  216. }
  217. else
  218. {
  219. CDialog::OnPaint();
  220. }
  221. }
  222. //当用户拖动最小化窗口时系统调用此函数取得光标
  223. //显示。
  224. HCURSOR ClyfzCheckBackupDlg::OnQueryDragIcon()
  225. {
  226. return static_cast<HCURSOR>(m_hIcon);
  227. }
  228. void ClyfzCheckBackupDlg::InitTrayIcon()
  229. {
  230. m_trayIcon.SetNotificationWnd(this, MSG_TRAY_NOTIFICATION);
  231. m_trayIcon.SetIcon(IDR_MAINFRAME, g_strDefaultTip);
  232. m_trayIcon.SetIconInfos((INT)IDR_MAINFRAME, (INT)IDI_WARNING, (UINT)IDI_TRANSPARENT);
  233. m_trayIcon.SetDefaultTip(g_strDefaultTip);
  234. }
  235. LRESULT ClyfzCheckBackupDlg::OnTrayNotification(WPARAM wp, LPARAM lp)
  236. {
  237. if(wp != IDR_MAINFRAME)
  238. return m_trayIcon.OnTrayNotification(wp, lp);
  239. switch(lp)
  240. {
  241. case WM_RBUTTONUP:
  242. TrayRight();
  243. break;
  244. case WM_LBUTTONUP:
  245. TaskNotifyIcon();
  246. break;
  247. default:
  248. break;
  249. }
  250. return 0;
  251. }
  252. void ClyfzCheckBackupDlg::TaskNotifyIcon()
  253. {
  254. if ( !m_bNoticeTray )
  255. {
  256. m_trayIcon.SetIcon(IDR_MAINFRAME, g_strDefaultTip);
  257. ShowWindow(SW_SHOWNORMAL);
  258. m_bNoticeTray = TRUE;
  259. }
  260. else
  261. {
  262. m_trayIcon.SetIcon(IDR_MAINFRAME, g_strDefaultTip);
  263. ShowWindow(SW_HIDE);
  264. m_bNoticeTray = FALSE;
  265. }
  266. }
  267. void ClyfzCheckBackupDlg::TrayRight()
  268. {
  269. CMenu menu;
  270. if (!menu.LoadMenu(IDR_MENU1))
  271. return ;
  272. CMenu* pSubMenu = menu.GetSubMenu(0);
  273. if (!pSubMenu)
  274. return ;
  275. /*
  276. //开机自动运行菜单
  277. if(m_bAutoRuning)
  278. pSubMenu->CheckMenuItem(Menu_AutoRun, MF_BYCOMMAND | MF_CHECKED);
  279. else
  280. pSubMenu->CheckMenuItem(Menu_AutoRun, MF_BYCOMMAND | MF_UNCHECKED);
  281. */
  282. CPoint point;
  283. GetCursorPos(&point);
  284. ::SetForegroundWindow(m_hWnd);
  285. pSubMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this);
  286. }
  287. BOOL ClyfzCheckBackupDlg::PreTranslateMessage(MSG* pMsg)
  288. {
  289. if (pMsg->message == WM_KEYDOWN)
  290. {
  291. CWnd *pWnd = GetFocus(); //获得当前光标所在控件
  292. if (pWnd != NULL && pWnd == GetDlgItem(IDC_DAY_EDIT))
  293. {
  294. int nNum = (int)pMsg->wParam;
  295. if(nNum == 8) //VK_Backspace
  296. return FALSE;
  297. CString str = _T("");
  298. ((CEdit*)GetDlgItem(IDC_DAY_EDIT))->GetWindowText(str);
  299. if(str.GetLength() >= 3)
  300. return TRUE;
  301. if(nNum < 48 || nNum > 57) //VK_(0~9)
  302. return TRUE;
  303. }
  304. }
  305. return CDialog::PreTranslateMessage(pMsg);
  306. }
  307. //修改
  308. void ClyfzCheckBackupDlg::OnBnClickedModifyBtn()
  309. {
  310. // TODO: 在此添加控件通知处理程序代码
  311. }
  312. //添加
  313. void ClyfzCheckBackupDlg::OnBnClickedAddBtn()
  314. {
  315. // TODO: 在此添加控件通知处理程序代码
  316. }
  317. //删除
  318. void ClyfzCheckBackupDlg::OnBnClickedDelBtn()
  319. {
  320. // TODO: 在此添加控件通知处理程序代码
  321. }
  322. //检测
  323. void ClyfzCheckBackupDlg::OnBnClickedCheckBtn()
  324. {
  325. if(BackupPhoto::GetInstance()->IsBackupping())
  326. return;
  327. SetTimer(1, 2000, 0);
  328. ((CButton*)GetDlgItem(IDC_CHECK_BTN))->EnableWindow(FALSE);
  329. ((CButton*)GetDlgItem(IDC_CANCEL_BTN))->EnableWindow(FALSE);
  330. // TODO: 在此添加控件通知处理程序代码
  331. std::vector<LPSORDERDIRINFO>* pV = OrderDirMgr::GetInstance()->GetOrderDirs();
  332. std::vector<LPSORDERDIRINFO>::iterator it = pV->begin();
  333. for(;it != pV->end(); ++it)
  334. {
  335. LPSORDERDIRINFO lp = (*it);
  336. if(lp == NULL)
  337. continue;
  338. //查找可用的备份目录
  339. CString strDir = _T("");
  340. if(!OrderDirMgr::GetInstance()->FindEnableBakDir(lp->byPhotoType + 4, strDir))
  341. continue;
  342. BackupPhoto::GetInstance()->InitBackupInfo(lp->szDomain, lp->szOrder, strDir, lp->byPhotoType, FALSE);
  343. }
  344. BackupPhoto::GetInstance()->StartBackup(g_szDomain, BackupCallBack);
  345. WriteLogin(_T("备份完成"));
  346. }
  347. //提示信息
  348. LRESULT ClyfzCheckBackupDlg::ShowPrompting(WPARAM wParam, LPARAM lParam)
  349. {
  350. /*
  351. int nShowType = lParam;
  352. CString strMSG = *(CString*)wParam;
  353. static CHARFORMAT cf;
  354. cf.cbSize = sizeof(CHARFORMAT);
  355. static COleDateTime oletime;
  356. oletime=COleDateTime::GetCurrentTime();
  357. strMSG.Format(_T("%s: #%s.\r"),oletime.Format(_T("%Y/%m/%d %H:%M:%S")),strMSG);
  358. //strMSG += ".\r";
  359. if ( nShowType == 1) // 错误信息提示
  360. {
  361. // 显示前,设置字体颜色;
  362. //m_EditShow.GetDefaultCharFormat(cf);
  363. m_BakMsgCtrl.GetDefaultCharFormat(cf);
  364. cf.dwMask=CFM_COLOR|CFM_FACE|CFM_SIZE|CFM_BOLD;
  365. cf.dwEffects = (unsigned long)~(CFE_UNDERLINE | CFE_BOLD | CFE_AUTOCOLOR);
  366. //cf.dwEffects ^= CFE_AUTOCOLOR;
  367. cf.crTextColor = RGB(255, 0, 0);
  368. cf.yHeight = 180;
  369. memset(cf.szFaceName, 0, LF_FACESIZE);
  370. // memcpy(cf.szFaceName, "楷体_GB2312", sizeof("楷体_GB2312"));
  371. memcpy(cf.szFaceName, _T("宋体"), sizeof(_T("宋体")));
  372. m_BakMsgCtrl.SetSelectionCharFormat(cf);
  373. m_BakMsgCtrl.SetSel(-1,-1);
  374. m_BakMsgCtrl.ReplaceSel(strMSG);
  375. }
  376. else // 成功信息提示;
  377. {
  378. m_BakMsgCtrl.GetDefaultCharFormat(cf);
  379. cf.dwMask=CFM_COLOR|CFM_FACE|CFM_SIZE|CFM_BOLD;
  380. cf.dwEffects = (unsigned long)~(CFE_UNDERLINE | CFE_BOLD | CFE_AUTOCOLOR);
  381. //cf.dwEffects ^= CFE_AUTOCOLOR;
  382. cf.crTextColor = RGB(0, 0, 255);
  383. cf.yHeight = 180;
  384. memset(cf.szFaceName, 0, LF_FACESIZE);
  385. // memcpy(cf.szFaceName, "楷体_GB2312", sizeof("楷体_GB2312"));
  386. memcpy(cf.szFaceName, _T("宋体"), sizeof(_T("宋体")));
  387. m_BakMsgCtrl.SetSelectionCharFormat(cf);
  388. m_BakMsgCtrl.SetSel(-1,-1);
  389. m_BakMsgCtrl.ReplaceSel(strMSG);
  390. }
  391. m_BakMsgCtrl.PostMessage(WM_VSCROLL, SB_BOTTOM,0);
  392. */
  393. return 0;
  394. }
  395. void ClyfzCheckBackupDlg::OnDestroy()
  396. {
  397. std::vector<TCHAR*>::iterator it = m_vDBConnect.begin();
  398. for(;it != m_vDBConnect.end();)
  399. {
  400. if((*it) != NULL)
  401. delete [] (*it);
  402. ++it;
  403. }
  404. m_vDBConnect.clear();
  405. if(m_pDBOpt !=NULL)
  406. delete m_pDBOpt;
  407. m_pDBOpt = NULL;
  408. CDialog::OnDestroy();
  409. }
  410. /************************************************************************/
  411. /*
  412. 函数: LoadConnect
  413. 描述: 加载连接数据
  414. 参数:
  415. LPCTSTR lpPath 路径
  416. 返回: 1成功,0失败
  417. */
  418. /************************************************************************/
  419. int ClyfzCheckBackupDlg::LoadConnect(LPCTSTR lpPath)
  420. {
  421. if(!PathFileExists(lpPath))
  422. {
  423. CString strError = _T("");
  424. strError.Format(_T("文件%s不存在,加载失败!"), lpPath);
  425. // SendMessage(MSG_SHOWPROMPTING,(WPARAM)&strError, 1);
  426. return 0;
  427. }
  428. TCHAR szDBServer[MAX_PATH] = {0}; // 服务器名
  429. DWORD dwDBServerPort = 0; // 端口
  430. TCHAR szDBAccount[MAX_PATH] = {0}; // 帐号
  431. TCHAR szDBPassWord[MAX_PATH] = {0}; // 密码
  432. TCHAR szDBName[MAX_PATH] = {0}; // 数据库名
  433. GetPrivateProfileString(_T("DatabaseInfo"), _T("dbSource"), _T(""), szDBServer, MAX_PATH, lpPath);
  434. dwDBServerPort = GetPrivateProfileInt(_T("DatabaseInfo"), _T("dbServerPort"), 0, lpPath);
  435. GetPrivateProfileString(_T("DatabaseInfo"), _T("dbAccount"), _T(""), szDBAccount, MAX_PATH, lpPath);
  436. GetPrivateProfileString(_T("DatabaseInfo"), _T("dbPassWord"), _T(""), szDBPassWord, MAX_PATH, lpPath);
  437. GetPrivateProfileString(_T("DatabaseInfo"), _T("dbName"), _T(""), szDBName, MAX_PATH, lpPath);
  438. //当前数据库db连接
  439. if (dwDBServerPort != 0)
  440. wsprintf(m_szDBConnect, _T("driver={SQL Server};Server=%s,%d;database=%s;uid=%s;pwd=%s"),
  441. szDBServer, dwDBServerPort, szDBName, szDBAccount, szDBPassWord);
  442. else
  443. wsprintf(m_szDBConnect, _T("driver={SQL Server};Server=%s;database=%s;uid=%s;pwd=%s"),
  444. szDBServer, szDBName, szDBAccount, szDBPassWord);
  445. /*多个数据库连接
  446. CTime ct = CTime::GetCurrentTime();
  447. int nStartYear = DB_STARTYEAR;
  448. while(nStartYear <= ct.GetYear())
  449. {
  450. TCHAR* p = new TCHAR[sizeof(TCHAR)*MAX_PATH + 1];
  451. memset(p, 0, sizeof(sizeof(TCHAR)*MAX_PATH + 1));
  452. if(nStartYear == ct.GetYear())
  453. {
  454. //当前数据库db连接
  455. if (dwDBServerPort != 0)
  456. wsprintf(p, _T("driver={SQL Server};Server=%s,%d;database=%s;uid=%s;pwd=%s"),
  457. szDBServer, dwDBServerPort, szDBName, szDBAccount, szDBPassWord);
  458. else
  459. wsprintf(p, _T("driver={SQL Server};Server=%s;database=%s;uid=%s;pwd=%s"),
  460. szDBServer, szDBName, szDBAccount, szDBPassWord);
  461. }
  462. else
  463. {
  464. //历史数据库连接从2012开始
  465. TCHAR szDate[8] = {0};
  466. #ifdef _UNICODE
  467. wsprintf(szDate, _T("%d"), nStartYear);
  468. #else
  469. sprintf(szDate, _T("%d"), nStartYear);
  470. #endif //#ifdef _UNICODE
  471. if (dwDBServerPort != 0)
  472. wsprintf(p, _T("driver={SQL Server};Server=%s,%d;database=%s;uid=%s;pwd=%s"),
  473. szDBServer, dwDBServerPort, szDate, szDBAccount, szDBPassWord);
  474. else
  475. wsprintf(p, _T("driver={SQL Server};Server=%s;database=%s;uid=%s;pwd=%s"),
  476. szDBServer, szDate, szDBAccount, szDBPassWord);
  477. }
  478. m_vDBConnect.push_back(p);
  479. ++nStartYear;
  480. }
  481. */
  482. return 1;
  483. }
  484. /************************************************************************/
  485. /*
  486. 函数: GetBackupLogs
  487. 描述: 获取备份记录
  488. 参数:
  489. OUT CString& strStart, 返回开始时间
  490. OUT CString& strEnd, 返回截止时间
  491. OUT CString& strFilter 返回sql语句:字段 between date1 and date2
  492. 返回: 1成功,0失败
  493. */
  494. /************************************************************************/
  495. void ClyfzCheckBackupDlg::GetDateRangeFilter(OUT CString& strStart, OUT CString& strEnd, OUT CString& strFilter)
  496. {
  497. CTime ct = CTime::GetCurrentTime();
  498. CString strDay = _T("");
  499. ((CEdit*)GetDlgItem(IDC_DAY_EDIT))->GetWindowText(strDay);
  500. if(strDay == _T(""))
  501. {
  502. MessageBox(_T("请输入天数!"));
  503. return;
  504. }
  505. int nDay = _ttoi(strDay);
  506. CTimeSpan sp(nDay, 0, 0, 0);
  507. CTime oldct = ct - sp;
  508. strStart.Format(_T("%04d-%02d-%02d"), oldct.GetYear(), oldct.GetMonth(), oldct.GetDay());
  509. strEnd.Format(_T("%04d-%02d-%02d"), ct.GetYear(), ct.GetMonth(), ct.GetDay());
  510. strFilter.Format(_T("opttime between '%s' and '%s'"), strStart, strEnd);
  511. }
  512. /************************************************************************/
  513. /*
  514. 函数: GetBackupLogs
  515. 描述: 获取备份记录
  516. 参数:
  517. OUT CArray<CStringArray,CStringArray>& logsArr 返回记录集合
  518. 返回: 1成功,0失败
  519. */
  520. /************************************************************************/
  521. void ClyfzCheckBackupDlg::GetBackupLogs(OUT CArray<CStringArray,CStringArray>& logsArr)
  522. {
  523. if(m_pDBOpt == NULL)
  524. return;
  525. if(m_pDBOpt->IsOpenDB())
  526. m_pDBOpt->CloseDB();
  527. if(m_pDBOpt->OpenDB(m_szDBConnect))
  528. {
  529. CString strStart(_T("")), strEnd(_T("")), strFilter(_T(""));
  530. GetDateRangeFilter(strStart, strEnd, strFilter);
  531. std::vector<CString> vFields;
  532. vFields.push_back(_T("isbackup"));
  533. vFields.push_back(_T("branchid"));
  534. vFields.push_back(_T("opttime"));
  535. vFields.push_back(_T("[order]"));
  536. vFields.push_back(_T("photoType"));
  537. vFields.push_back(_T("[content]"));
  538. vFields.push_back(_T("userid"));
  539. vFields.push_back(_T("username"));
  540. vFields.push_back(_T("baktime"));
  541. if(strFilter == _T(""))
  542. m_pDBOpt->Select(logsArr, _T("IncrementalBackup"), vFields);
  543. else
  544. m_pDBOpt->Select(logsArr, _T("IncrementalBackup"), vFields, strFilter);
  545. }
  546. }
  547. /************************************************************************/
  548. /*
  549. 函数: CheckTheStringIsNum
  550. 描述: 检测是否为数字
  551. 参数:
  552. const CString& strNum 数字字符
  553. 返回: 1是数字,0不是纯数字
  554. */
  555. /************************************************************************/
  556. int ClyfzCheckBackupDlg::CheckTheStringIsNum(const CString& strNum)
  557. {
  558. CString strTemp = strNum;
  559. int nIdx = 0;
  560. while(nIdx < strTemp.GetLength())
  561. {
  562. if(strTemp.GetAt(nIdx) < 48 || strTemp.GetAt(nIdx) > 57)
  563. return 0;
  564. ++nIdx;
  565. }
  566. return 1;
  567. }
  568. void ClyfzCheckBackupDlg::OnTimer(UINT_PTR nIDEvent)
  569. {
  570. if(nIDEvent == 1)
  571. {
  572. if(!BackupPhoto::GetInstance()->IsBackupping())
  573. {
  574. KillTimer(nIDEvent);
  575. WriteLogin(_T("备份完成"));
  576. OnExit();
  577. }
  578. }
  579. if(nIDEvent == 2)
  580. {
  581. CString strName = _T("");
  582. strName.Format(_T("检测(%d)"), m_nCountTime);
  583. SetDlgItemText(IDC_CHECK_BTN, strName);
  584. if(m_nCountTime == 0)
  585. {
  586. KillTimer(2);
  587. OnClose();
  588. OnBnClickedCheckBtn();
  589. }
  590. else
  591. --m_nCountTime;
  592. }
  593. CDialog::OnTimer(nIDEvent);
  594. }
  595. /************************************************************************/
  596. /*
  597. 函数:BackupFinish
  598. 描述:增量备份完成回调
  599. 参数:
  600. LPVOID, 回调传回值
  601. LPVOID,
  602. LPVOID,
  603. LPVOID,
  604. LPVOID,
  605. LPVOID
  606. 返回:1成功,0失败
  607. */
  608. /************************************************************************/
  609. int WINAPI ClyfzCheckBackupDlg::BackupCallBack(IN LPVOID lpParam1, IN LPVOID lpParam2, IN LPVOID lpParam3, IN LPVOID lpParam4, IN LPVOID lpParam5, IN LPVOID lpParam6)
  610. {
  611. return g_This->BackupCallBackPro(lpParam1, lpParam2, lpParam3, lpParam4, lpParam5, lpParam6);
  612. }
  613. /************************************************************************/
  614. /*
  615. 函数:BackupFinish
  616. 描述:增量备份完成回调
  617. 参数:
  618. LPVOID, 回调传回值
  619. LPVOID,
  620. LPVOID,
  621. LPVOID,
  622. LPVOID,
  623. LPVOID
  624. 返回:1成功,0失败
  625. */
  626. /************************************************************************/
  627. int ClyfzCheckBackupDlg::BackupCallBackPro(IN LPVOID lpParam1, IN LPVOID lpParam2, IN LPVOID lpParam3, IN LPVOID lpParam4, IN LPVOID lpParam5, IN LPVOID lpParam6)
  628. {
  629. int nPercent = *((int*)lpParam1);
  630. CString strMsg = _T("");
  631. strMsg.Format(_T("完成:%d\n"), nPercent);
  632. WriteLogin(strMsg);
  633. if ( nPercent == 100 )
  634. {
  635. if(m_pDBOpt == NULL)
  636. return 0;
  637. try
  638. {
  639. TCHAR szDate[32] = {0};
  640. CTime ct = CTime::GetCurrentTime();
  641. _tcscpy(szDate, ct.Format(_T("%Y-%m-%d %H:%M:%S.000")));
  642. CString strSql = _T("");
  643. strSql.Format(INSERT_INCREMENT, 1, (TCHAR*)lpParam2, (TCHAR*)lpParam3, (TCHAR*)lpParam4, *((BYTE*)lpParam5), (TCHAR*)lpParam6, _T("admin"), _T("管理员"), szDate);
  644. m_pDBOpt->Execute(strSql);
  645. }
  646. catch (CException *e)
  647. {
  648. TCHAR szError[1024] = { 0 };
  649. e->GetErrorMessage(szError, 1024);
  650. CString strErrorMsg = _T("");
  651. strErrorMsg.Format(_T("增量备份回调错误:%s\n"), szError);
  652. WriteLogin(strErrorMsg);
  653. e->Delete();
  654. }
  655. }
  656. return 1;
  657. }
  658. void ClyfzCheckBackupDlg::OnClose()
  659. {
  660. ShowWindow(SW_HIDE);
  661. }
  662. void ClyfzCheckBackupDlg::OnExit()
  663. {
  664. CDialog::OnOK();
  665. }
  666. void ClyfzCheckBackupDlg::OnShowWnd()
  667. {
  668. ShowWindow(SW_SHOWDEFAULT);
  669. }
  670. void ClyfzCheckBackupDlg::OnBnClickedCancelBtn()
  671. {
  672. // TODO: 在此添加控件通知处理程序代码
  673. OnExit();
  674. }