DbSettingDlg.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // DbSettingDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "YAServer.h"
  5. #include "DbSettingDlg.h"
  6. #include "afxdialogex.h"
  7. #include "def.h"
  8. #include "INIFILE.h"
  9. #include "Functions/Functions.h"
  10. // CDbSettingDlg 对话框
  11. IMPLEMENT_DYNAMIC(CDbSettingDlg, CDialogEx)
  12. CDbSettingDlg::CDbSettingDlg(CWnd* pParent /*=NULL*/)
  13. : CDialogEx(CDbSettingDlg::IDD, pParent)
  14. , m_host_master(_T(""))
  15. , m_port_master(0)
  16. , m_pwd_master(_T(""))
  17. , m_user_master(_T(""))
  18. , m_db_master(_T(""))
  19. , m_use_slave(FALSE)
  20. , m_host_slave(_T(""))
  21. , m_port_slave(0)
  22. , m_user_slave(_T(""))
  23. , m_pwd_slave(_T(""))
  24. , m_db_slave(_T(""))
  25. {
  26. }
  27. CDbSettingDlg::~CDbSettingDlg()
  28. {
  29. }
  30. void CDbSettingDlg::DoDataExchange(CDataExchange* pDX)
  31. {
  32. CDialogEx::DoDataExchange(pDX);
  33. DDX_Text(pDX, IDC_EDIT1, m_host_master);
  34. DDX_Text(pDX, IDC_EDIT4, m_port_master);
  35. DDX_Text(pDX, IDC_EDIT6, m_pwd_master);
  36. DDX_Text(pDX, IDC_EDIT3, m_user_master);
  37. DDX_Text(pDX, IDC_EDIT2, m_db_master);
  38. DDX_Control(pDX, IDC_ENCODE_MASTER, m_encode_master);
  39. DDX_Check(pDX, IDC_CHECK1, m_use_slave);
  40. DDX_Text(pDX, IDC_HOST_SLAVE, m_host_slave);
  41. DDX_Text(pDX, IDC_PORT_SLAVE, m_port_slave);
  42. DDX_Text(pDX, IDC_USER_SLAVE, m_user_slave);
  43. DDX_Text(pDX, IDC_PWD_SLAVE, m_pwd_slave);
  44. DDX_Text(pDX, IDC_DB_SLAVE, m_db_slave);
  45. DDX_Control(pDX, IDC_ENCODE_SLAVE, m_encode_slave);
  46. }
  47. BEGIN_MESSAGE_MAP(CDbSettingDlg, CDialogEx)
  48. ON_BN_CLICKED(IDOK, &CDbSettingDlg::OnBnClickedOk)
  49. ON_BN_CLICKED(IDC_CHECK1, &CDbSettingDlg::OnBnClickedCheck1)
  50. END_MESSAGE_MAP()
  51. void CDbSettingDlg::OnBnClickedOk()
  52. {
  53. UpdateData();
  54. CString strCBText;
  55. theApp.dbhost = CFunctions::wc2c(m_host_master.GetBuffer(0));
  56. theApp.dbuser = CFunctions::wc2c(m_user_master.GetBuffer(0));
  57. theApp.dbpwd = CFunctions::wc2c(m_pwd_master.GetBuffer(0));
  58. theApp.dbname = CFunctions::wc2c(m_db_master.GetBuffer(0));
  59. int nIndex = m_encode_master.GetCurSel();
  60. m_encode_master.GetLBText( nIndex, strCBText);
  61. theApp.dbencoding = CFunctions::wc2c(strCBText.GetBuffer(0));
  62. theApp.dbport = m_port_master;
  63. theApp.dbbackup = m_use_slave ? "1" : "0";
  64. theApp.dbhost_bk = CFunctions::wc2c(m_host_slave.GetBuffer(0));
  65. theApp.dbuser_bk = CFunctions::wc2c(m_user_slave.GetBuffer(0));
  66. theApp.dbpwd_bk = CFunctions::wc2c(m_pwd_slave.GetBuffer(0));
  67. theApp.dbname_bk = CFunctions::wc2c(m_db_slave.GetBuffer(0));
  68. nIndex = m_encode_slave.GetCurSel();
  69. if(nIndex == -1) {
  70. nIndex = 0;
  71. }
  72. m_encode_master.GetLBText( nIndex, strCBText);
  73. theApp.dbencoding_bk = CFunctions::wc2c(strCBText.GetBuffer(0));
  74. theApp.dbport_bk = m_port_slave;
  75. theApp.save_db_conf();
  76. CDialogEx::OnOK();
  77. }
  78. BOOL CDbSettingDlg::OnInitDialog()
  79. {
  80. CDialog::OnInitDialog();
  81. CString strTemp;
  82. strTemp.Format(_T("gb2312"));
  83. m_encode_slave.AddString(strTemp);
  84. m_encode_master.AddString(_T("gb2312"));
  85. strTemp.Format(_T("utf8"));
  86. m_encode_slave.AddString(strTemp);
  87. m_encode_master.AddString(strTemp);
  88. init_ui();
  89. return TRUE;
  90. }
  91. void CDbSettingDlg::init_ui()
  92. {
  93. m_host_master = CFunctions::c2wc(theApp.dbhost.c_str());
  94. m_user_master = CFunctions::c2wc(theApp.dbuser.c_str());
  95. m_pwd_master = CFunctions::c2wc(theApp.dbpwd.c_str());
  96. m_db_master = CFunctions::c2wc(theApp.dbname.c_str());
  97. int nIndex = m_encode_master.FindString(0, CFunctions::c2wc(theApp.dbencoding.c_str()));
  98. m_encode_master.SetCurSel(nIndex); //设置第nIndex项为显示的内容
  99. m_port_master = theApp.dbport;
  100. m_use_slave = (theApp.dbbackup == "1");
  101. m_host_slave = CFunctions::c2wc(theApp.dbhost_bk.c_str());
  102. m_user_slave = CFunctions::c2wc(theApp.dbuser_bk.c_str());
  103. m_pwd_slave = CFunctions::c2wc(theApp.dbpwd_bk.c_str());
  104. m_db_slave = CFunctions::c2wc(theApp.dbname_bk.c_str());
  105. nIndex = m_encode_slave.FindString(0, CFunctions::c2wc(theApp.dbencoding_bk.c_str()));
  106. m_encode_slave.SetCurSel(nIndex); //设置第nIndex项为显示的内容
  107. //m_encode_slave.SetWindowTextW(CFunctions::c2wc(theApp.dbencoding_bk.c_str()));
  108. m_port_slave = theApp.dbport_bk;
  109. EnableCtrl(m_use_slave);
  110. UpdateData(FALSE);
  111. }
  112. void CDbSettingDlg::OnBnClickedCheck1()
  113. {
  114. m_encode_slave.EnableWindow(!m_use_slave);
  115. (CComboBox*)GetDlgItem(IDC_HOST_SLAVE)->EnableWindow(!m_use_slave);
  116. (CComboBox*)GetDlgItem(IDC_PORT_SLAVE)->EnableWindow(!m_use_slave);
  117. (CComboBox*)GetDlgItem(IDC_USER_SLAVE)->EnableWindow(!m_use_slave);
  118. (CComboBox*)GetDlgItem(IDC_PWD_SLAVE)->EnableWindow(!m_use_slave);
  119. (CComboBox*)GetDlgItem(IDC_DB_SLAVE)->EnableWindow(!m_use_slave);
  120. UpdateData();
  121. }
  122. void CDbSettingDlg::EnableCtrl(BOOL status)
  123. {
  124. (CComboBox*)GetDlgItem(IDC_HOST_SLAVE)->EnableWindow(status);
  125. (CComboBox*)GetDlgItem(IDC_PORT_SLAVE)->EnableWindow(status);
  126. (CComboBox*)GetDlgItem(IDC_USER_SLAVE)->EnableWindow(status);
  127. (CComboBox*)GetDlgItem(IDC_PWD_SLAVE)->EnableWindow(status);
  128. (CComboBox*)GetDlgItem(IDC_DB_SLAVE)->EnableWindow(status);
  129. m_encode_slave.EnableWindow(status);
  130. }