DBConfig.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // DBConfig.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "AutoRun.h"
  5. #include "DBConfig.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // DBConfig dialo
  13. /////////////////////////////////////////////////////////////////////////////
  14. // DBConfig dialog
  15. DBConfig::DBConfig(CWnd* pParent /*=NULL*/)
  16. : CDialog(DBConfig::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(DBConfig)
  19. m_bSql = 1;
  20. m_server = _T("");
  21. m_user = _T("");
  22. m_psw = _T("");
  23. //}}AFX_DATA_INIT
  24. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  25. }
  26. void DBConfig::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(DBConfig)
  30. DDX_Radio(pDX, IDC_RADIO1, m_bSql);
  31. DDX_Text(pDX, IDC_EDIT1, m_server);
  32. DDX_Text(pDX, IDC_EDIT2, m_user);
  33. DDX_Text(pDX, IDC_EDIT3, m_psw);
  34. //}}AFX_DATA_MAP
  35. }
  36. BEGIN_MESSAGE_MAP(DBConfig, CDialog)
  37. //{{AFX_MSG_MAP(DBConfig)
  38. ON_WM_PAINT()
  39. ON_WM_QUERYDRAGICON()
  40. ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
  41. ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // DBConfig message handlers
  46. BOOL DBConfig::OnInitDialog()
  47. {
  48. CDialog::OnInitDialog();
  49. // TODO: Add extra initialization here
  50. CString configpath=g_mainpath+"\\dbconfig.dat";
  51. CFile fp;
  52. if(fp.Open (configpath, CFile::modeRead))
  53. {
  54. DBSAVE db;
  55. memset(&db, 0, sizeof(db));
  56. fp.Read (&db, sizeof(db));
  57. fp.Close ();
  58. char server[50];
  59. char user[50];
  60. char psw[50];
  61. memset(server, 0, sizeof(char)*50);
  62. memset(user, 0, sizeof(char)*50);
  63. memset(psw, 0, sizeof(char)*50);
  64. for(int i=0; i<50; i++)
  65. {
  66. if(db.server [i])
  67. server[i]=500-db.server [i];
  68. if(db.user [i])
  69. user[i]=500-db.user [i];
  70. if(db.psw [i])
  71. psw[i]=500-db.psw [i];
  72. }
  73. m_server=server ;
  74. m_user=user ;
  75. m_psw=psw ;
  76. UpdateData(false);
  77. }
  78. EnableCtrl();
  79. GetDlgItem(IDC_EDIT1)->SetFocus();
  80. return false; // return TRUE unless you set the focus to a control
  81. }
  82. void DBConfig::OnRadio1()
  83. {
  84. // TODO: Add your control notification handler code here
  85. EnableCtrl();
  86. }
  87. void DBConfig::OnRadio2()
  88. {
  89. // TODO: Add your control notification handler code here
  90. EnableCtrl();
  91. }
  92. void DBConfig::EnableCtrl()
  93. {
  94. UpdateData();
  95. GetDlgItem(IDC_EDIT1)->EnableWindow(m_bSql);
  96. GetDlgItem(IDC_EDIT2)->EnableWindow(m_bSql);
  97. GetDlgItem(IDC_EDIT3)->EnableWindow(m_bSql);
  98. }
  99. void DBConfig::OnOK()
  100. {
  101. // TODO: Add extra validation here
  102. UpdateData();
  103. if(m_server.GetLength ()>50)
  104. m_server=m_server.Left (50);
  105. if(m_user.GetLength ()>50)
  106. m_user=m_user.Left (50);
  107. if(m_psw.GetLength ()>50)
  108. m_psw=m_psw.Left (50);
  109. DBSAVE db;
  110. memset(&db, 0, sizeof(db));
  111. for(int i=0; i<50; i++)
  112. {
  113. if(m_server.GetLength ()>i)
  114. db.server [i]=500-m_server.GetAt (i);
  115. if(m_user.GetLength ()>i)
  116. db.user [i]=500-m_user.GetAt (i);
  117. if(m_psw.GetLength ()>i)
  118. db.psw [i]=500-m_psw.GetAt (i);
  119. }
  120. db.bsql=m_bSql;
  121. CString path=g_mainpath+"\\dbconfig.dat";
  122. CFile fp;
  123. fp.Open (path, CFile::modeCreate|CFile::modeWrite);
  124. fp.Write (&db, sizeof(db));
  125. fp.Close ();
  126. AfxMessageBox("±£´æ³É¹¦! ÖØÆôÈí¼þÉúЧ.", MB_ICONINFORMATION);
  127. CDialog::OnOK();
  128. }