DlgBit.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // AnalogPropertyDlg1.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "IDE.h"
  5. #include "DlgBit.h"
  6. #include "StringOperation.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CDlgBit dialog
  14. CDlgBit::CDlgBit(CWnd* pParent /*=NULL*/)
  15. : CDialog(CDlgBit::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CDlgBit)
  18. //}}AFX_DATA_INIT
  19. m_operation=EDIT;
  20. m_DDXFields.SetSize(4);
  21. }
  22. void CDlgBit::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CDlgBit)
  26. //}}AFX_DATA_MAP
  27. m_DDXFields.DDX(pDX);
  28. }
  29. BEGIN_MESSAGE_MAP(CDlgBit, CDialog)
  30. //{{AFX_MSG_MAP(CDlgBit)
  31. //}}AFX_MSG_MAP
  32. ON_BN_CLICKED(IDC_BTN_CANCEL, OnBnClickedBtnCancel)
  33. ON_BN_CLICKED(IDC_BTN_SAVE, OnBnClickedBtnSave)
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CDlgBit message handlers
  37. BOOL CDlgBit::OnInitDialog()
  38. {
  39. CDialog::OnInitDialog();
  40. int i;
  41. m_DDXFields.m_pWnd=this;
  42. i=0;
  43. m_DDXFields.ElementAt(i).Set(_T("id"), IDC_EDT_ID);
  44. m_DDXFields.ElementAt(i).m_description=_T("ID");
  45. m_DDXFields.ElementAt(i).m_nDataType = DATA_NUM;
  46. i=1;
  47. m_DDXFields.ElementAt(i).Set(_T( "uid" ),IDC_EDT_VAR_UID) ;
  48. m_DDXFields.ElementAt(i).m_description=g_strVarUid1;
  49. m_DDXFields.ElementAt(i).m_nDataType = DATA_STR;
  50. i=2;
  51. m_DDXFields.ElementAt(i).Set(_T( "startbit" ),IDC_EDT_START_BIT) ;
  52. m_DDXFields.ElementAt(i).m_description=g_strStartBit;
  53. m_DDXFields.ElementAt(i).m_nDataType = DATA_NUM;
  54. i=3;
  55. m_DDXFields.ElementAt(i).Set(_T( "endbit" ),IDC_EDT_END_BIT) ;
  56. m_DDXFields.ElementAt(i).m_description=g_strEndBit;
  57. m_DDXFields.ElementAt(i).m_nDataType = DATA_NUM;
  58. UpdateData(TRUE);
  59. switch (m_operation)
  60. {
  61. case NEW:
  62. break;
  63. default:
  64. m_DDXFields.ReadData(m_pSet);
  65. break;
  66. }
  67. UpdateData(FALSE);
  68. //GetDlgItem(IDC_EDT_START_BIT)->SetWindowText(0);
  69. //GetDlgItem(IDC_EDT_END_BIT)->SetWindowText(0);
  70. GetDlgItem(IDC_EDT_VAR_UID)->SetWindowText(m_strUID);
  71. m_btnSave.SubclassDlgItem(IDC_BTN_SAVE, this);
  72. m_btnSave.SetBitmaps(IDB_SAVE, RGB(255, 0, 255));
  73. m_btnSave.SetFlat(FALSE);
  74. m_btnSave.SetAlign(CButtonST::ST_ALIGN_HORIZ);
  75. m_btnCancel.SubclassDlgItem(IDC_BTN_CANCEL, this);
  76. m_btnCancel.SetBitmaps(IDB_DEL, RGB(255, 0, 255));
  77. m_btnCancel.SetFlat(FALSE);
  78. m_btnCancel.SetAlign(CButtonST::ST_ALIGN_HORIZ);
  79. return TRUE; // return TRUE unless you set the focus to a control
  80. // EXCEPTION: OCX Property Pages should return FALSE
  81. }
  82. void CDlgBit::OnBnClickedBtnCancel()
  83. {
  84. // TODO: 在此添加控件通知处理程序代码
  85. OnCancel();
  86. }
  87. int CDlgBit::CheckDataValid()
  88. {
  89. CHAR szVarBitID[MAX_ID] = {0};
  90. int nRet = CDBInterface::GetInstancePtr()->GetVarBitID((char *)(LPCTSTR)m_DDXFields.GetAt(0).m_value,
  91. atoi(m_DDXFields.GetAt(1).m_value),
  92. atoi(m_DDXFields.GetAt(2).m_value),
  93. szVarBitID);
  94. return nRet;
  95. }
  96. void CDlgBit::OnBnClickedBtnSave()
  97. {
  98. // TODO: 在此添加控件通知处理程序代码
  99. // 存盘操作
  100. CExString strField;
  101. CHAR szMaxID[MAX_ID + 1] = {0};
  102. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  103. CString sStart,sEnd;
  104. GetDlgItem(IDC_EDT_START_BIT)->GetWindowText( sStart );
  105. GetDlgItem(IDC_EDT_END_BIT)->GetWindowText( sEnd );
  106. sStart = sStart.Trim();
  107. sEnd = sEnd.Trim();
  108. if( sStart.Compare("")==0 || sEnd.Compare("")==0 )
  109. {
  110. MessageBox(g_strInputIsBlank, g_strTip, MB_ICONINFORMATION);
  111. return;
  112. }
  113. CDBInterface::GetInstancePtr()->GetMaxID("t_dev_variant_item", "id", szMaxID);
  114. int nID;
  115. CString strID;
  116. try
  117. {
  118. switch (m_operation)
  119. {
  120. case EDIT:
  121. //nID = atoi(szMaxID);
  122. break;
  123. default:
  124. if( atoi(szMaxID) > 0 )
  125. {
  126. nID = atoi(szMaxID) + 1;
  127. }
  128. else if( atoi(szMaxID) == 0 )
  129. {
  130. nID = 1;
  131. }
  132. strID.Format("%d", nID);
  133. GetDlgItem(IDC_EDT_ID)->SetWindowText(strID);
  134. //m_pSet->AddNew();
  135. break;
  136. }
  137. UpdateData(TRUE);
  138. try
  139. {
  140. // 校验数据的正确性
  141. int nRet = CheckDataValid();
  142. if( nRet > 0 )
  143. {
  144. MessageBox(g_strVarBitExist, g_strTip, MB_ICONWARNING);
  145. //CDialog::OnOK();
  146. return;
  147. }
  148. sprintf(strSQLText, "insert into t_dev_variant_item(id, uid, startbit, endbit) values(");
  149. if( m_DDXFields.WriteData("t_dev_variant_item", strSQLText, m_operation) == -1 ) return;
  150. }
  151. catch(...)
  152. {
  153. ;
  154. }
  155. CDialog::OnOK();
  156. }//try
  157. catch( _com_error &e )
  158. {
  159. CString mes1,mes2,mes3,mes4;
  160. mes1.Format(_T("Error:%08lx.\n"), e.Error());
  161. mes2.Format(_T("ErrorMessage:%s.\n"), e.ErrorMessage());
  162. mes3.Format(_T("Source:%s.\n"), (LPCTSTR) _bstr_t(e.Source()));
  163. mes4.Format(_T("Description:%s.\n"), (LPCTSTR) _bstr_t(e.Description()));
  164. MessageBox(mes1+mes2+mes3+mes4,_T("Invalid field "),MB_ICONERROR);
  165. return;
  166. }
  167. catch(...)
  168. {
  169. MessageBox(_T("Unhandled Exception"),_T("Invalid field ")+strField,MB_ICONERROR);
  170. return;
  171. }
  172. UpdateData(FALSE);
  173. }