DataBackup.cpp
上传用户:latoyin
上传日期:2017-10-19
资源大小:2882k
文件大小:3k
源码类别:

数据库系统

开发平台:

Visual C++

  1. // DataBackup.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Equipment.h"
  5. #include "DataBackup.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. extern CEquipmentApp theApp;
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CDataBackup dialog
  14. CDataBackup::CDataBackup(CWnd* pParent /*=NULL*/)
  15. : CDialog(CDataBackup::IDD, pParent)
  16. {
  17. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINTITLE);
  18. }
  19. void CDataBackup::DoDataExchange(CDataExchange* pDX)
  20. {
  21. CDialog::DoDataExchange(pDX);
  22. //{{AFX_DATA_MAP(CDataBackup)
  23. DDX_Control(pDX, IDC_EDIT1, datafile);
  24. //}}AFX_DATA_MAP
  25. }
  26. BEGIN_MESSAGE_MAP(CDataBackup, CDialog)
  27. //{{AFX_MSG_MAP(CDataBackup)
  28. ON_COMMAND(ID_BUTTONCLOSE, OnButtonclose)
  29. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  30. ON_COMMAND(ID_BUTTONREFRESH, OnButtonrefresh)
  31. //}}AFX_MSG_MAP
  32. END_MESSAGE_MAP()
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CDataBackup message handlers
  35. void CDataBackup::OnCancel() 
  36. {
  37. // TODO: Add extra cleanup here
  38. CDialog::OnCancel();
  39. }
  40. void CDataBackup::OnOK() 
  41. {
  42. // TODO: Add extra validation here
  43. // CDialog::OnOK();
  44. }
  45. BOOL CDataBackup::OnInitDialog() 
  46. {
  47. CDialog::OnInitDialog();
  48. SetIcon(m_hIcon,true);
  49. toolbar.Create(TBSTYLE_FLAT|CCS_TOP|WS_CHILD|WS_VISIBLE|WS_BORDER|CCS_ADJUSTABLE|TBSTYLE_WRAPABLE,CRect(0,0,0,0),this,IDR_TOOLBAR2);
  50. toolbar.SetBitmapSize(CSize(32,32));
  51. imagelist.Create(32,32,ILC_COLOR32|ILC_MASK,0,0);
  52. for (int n =0;n<5;n++)
  53. {
  54. imagelist.Add(theApp.LoadIcon(n+IDI_ICON1));
  55. }
  56. toolbar.SetImageList(&imagelist);
  57. TBBUTTON  buttons[3];
  58. for (int i =0; i<3;i++)
  59. {
  60. CString str;
  61. int strlength;
  62. CCHAR *temp;
  63. if (i<1)
  64. buttons[i].fsStyle =TBSTYLE_SEP;
  65. else
  66. {
  67. buttons[i].fsStyle =TBSTYLE_BUTTON;
  68. }
  69. buttons[i].fsState =TBSTATE_ENABLED;
  70. buttons[i].dwData =0;
  71. if (i == 1) 
  72. {
  73. buttons[i].idCommand = ID_BUTTONADD+3; //对应于刷新
  74. buttons[i].iBitmap = 3;
  75. str.LoadString(IDS_BACKUP);
  76. }
  77. else
  78. {
  79. buttons[i].idCommand = ID_BUTTONADD+4;//退出
  80. buttons[i].iBitmap = 4;
  81. str.LoadString(ID_BUTTONADD+4);
  82. }
  83. strlength = str.GetLength()+1;
  84. temp = str.GetBufferSetLength(strlength);
  85. temp[strlength]= '';
  86. temp[strlength-1]= '';
  87. buttons[i].iString = toolbar.AddStrings(temp);
  88. str.ReleaseBuffer();
  89. }
  90. toolbar.AutoSize();
  91. toolbar.AddButtons(3,buttons);
  92. toolbar.ShowWindow(SW_SHOW);
  93. return TRUE;  
  94. }
  95. void CDataBackup::OnButtonclose() 
  96. {
  97. EndDialog(0);
  98. }
  99. void CDataBackup::OnButton1() 
  100. {
  101. CFileDialog* filedialog;
  102. filedialog = new CFileDialog(true,"bak");
  103. if (filedialog->DoModal()==IDOK )
  104. {
  105. CString str;
  106. str = filedialog->GetPathName();
  107. datafile.SetWindowText(str);
  108. }
  109. delete (filedialog);
  110. //filedialog.Create();
  111. //
  112. }
  113. void CDataBackup::OnButtonrefresh() 
  114. {
  115. CString str;
  116. datafile.GetWindowText(str);
  117. if (!str.IsEmpty())
  118. {
  119. try
  120. {
  121. CString sql;
  122. sql.Format("backup database equipmentmanage to disk = '%s'",str);
  123. theApp.datamanage->ExecSQL(sql);
  124. MessageBox("备份成功.","提示",64);
  125. }
  126. catch(...)
  127. {
  128. MessageBox("备份失败.","提示",64);
  129. }
  130. }
  131. else
  132. {
  133. MessageBox("请指定备份文件.","提示",64);
  134. }
  135. }