123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- // AnalogPropertyDlg1.cpp : implementation file
- //
- #include "stdafx.h"
- #include "IDE.h"
- #include "DlgBit.h"
- #include "StringOperation.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDlgBit dialog
- CDlgBit::CDlgBit(CWnd* pParent /*=NULL*/)
- : CDialog(CDlgBit::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDlgBit)
- //}}AFX_DATA_INIT
- m_operation=EDIT;
- m_DDXFields.SetSize(4);
- }
- void CDlgBit::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDlgBit)
- //}}AFX_DATA_MAP
- m_DDXFields.DDX(pDX);
- }
- BEGIN_MESSAGE_MAP(CDlgBit, CDialog)
- //{{AFX_MSG_MAP(CDlgBit)
- //}}AFX_MSG_MAP
- ON_BN_CLICKED(IDC_BTN_CANCEL, OnBnClickedBtnCancel)
- ON_BN_CLICKED(IDC_BTN_SAVE, OnBnClickedBtnSave)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDlgBit message handlers
- BOOL CDlgBit::OnInitDialog()
- {
- CDialog::OnInitDialog();
- int i;
- m_DDXFields.m_pWnd=this;
- i=0;
- m_DDXFields.ElementAt(i).Set(_T("id"), IDC_EDT_ID);
- m_DDXFields.ElementAt(i).m_description=_T("ID");
- m_DDXFields.ElementAt(i).m_nDataType = DATA_NUM;
- i=1;
- m_DDXFields.ElementAt(i).Set(_T( "uid" ),IDC_EDT_VAR_UID) ;
- m_DDXFields.ElementAt(i).m_description=g_strVarUid1;
- m_DDXFields.ElementAt(i).m_nDataType = DATA_STR;
- i=2;
- m_DDXFields.ElementAt(i).Set(_T( "startbit" ),IDC_EDT_START_BIT) ;
- m_DDXFields.ElementAt(i).m_description=g_strStartBit;
- m_DDXFields.ElementAt(i).m_nDataType = DATA_NUM;
- i=3;
- m_DDXFields.ElementAt(i).Set(_T( "endbit" ),IDC_EDT_END_BIT) ;
- m_DDXFields.ElementAt(i).m_description=g_strEndBit;
- m_DDXFields.ElementAt(i).m_nDataType = DATA_NUM;
- UpdateData(TRUE);
- switch (m_operation)
- {
- case NEW:
- break;
- default:
- m_DDXFields.ReadData(m_pSet);
- break;
- }
- UpdateData(FALSE);
- //GetDlgItem(IDC_EDT_START_BIT)->SetWindowText(0);
- //GetDlgItem(IDC_EDT_END_BIT)->SetWindowText(0);
- GetDlgItem(IDC_EDT_VAR_UID)->SetWindowText(m_strUID);
- m_btnSave.SubclassDlgItem(IDC_BTN_SAVE, this);
- m_btnSave.SetBitmaps(IDB_SAVE, RGB(255, 0, 255));
- m_btnSave.SetFlat(FALSE);
- m_btnSave.SetAlign(CButtonST::ST_ALIGN_HORIZ);
- m_btnCancel.SubclassDlgItem(IDC_BTN_CANCEL, this);
- m_btnCancel.SetBitmaps(IDB_DEL, RGB(255, 0, 255));
- m_btnCancel.SetFlat(FALSE);
- m_btnCancel.SetAlign(CButtonST::ST_ALIGN_HORIZ);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CDlgBit::OnBnClickedBtnCancel()
- {
- // TODO: 在此添加控件通知处理程序代码
- OnCancel();
- }
- int CDlgBit::CheckDataValid()
- {
- CHAR szVarBitID[MAX_ID] = {0};
- int nRet = CDBInterface::GetInstancePtr()->GetVarBitID((char *)(LPCTSTR)m_DDXFields.GetAt(0).m_value,
- atoi(m_DDXFields.GetAt(1).m_value),
- atoi(m_DDXFields.GetAt(2).m_value),
- szVarBitID);
- return nRet;
- }
- void CDlgBit::OnBnClickedBtnSave()
- {
- // TODO: 在此添加控件通知处理程序代码
- // 存盘操作
- CExString strField;
- CHAR szMaxID[MAX_ID + 1] = {0};
- CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
- CString sStart,sEnd;
- GetDlgItem(IDC_EDT_START_BIT)->GetWindowText( sStart );
- GetDlgItem(IDC_EDT_END_BIT)->GetWindowText( sEnd );
-
- sStart = sStart.Trim();
- sEnd = sEnd.Trim();
- if( sStart.Compare("")==0 || sEnd.Compare("")==0 )
- {
- MessageBox(g_strInputIsBlank, g_strTip, MB_ICONINFORMATION);
- return;
- }
- CDBInterface::GetInstancePtr()->GetMaxID("t_dev_variant_item", "id", szMaxID);
- int nID;
- CString strID;
- try
- {
- switch (m_operation)
- {
- case EDIT:
- //nID = atoi(szMaxID);
- break;
- default:
- if( atoi(szMaxID) > 0 )
- {
- nID = atoi(szMaxID) + 1;
- }
- else if( atoi(szMaxID) == 0 )
- {
- nID = 1;
- }
- strID.Format("%d", nID);
- GetDlgItem(IDC_EDT_ID)->SetWindowText(strID);
- //m_pSet->AddNew();
- break;
- }
- UpdateData(TRUE);
- try
- {
- // 校验数据的正确性
- int nRet = CheckDataValid();
- if( nRet > 0 )
- {
- MessageBox(g_strVarBitExist, g_strTip, MB_ICONWARNING);
- //CDialog::OnOK();
- return;
- }
- sprintf(strSQLText, "insert into t_dev_variant_item(id, uid, startbit, endbit) values(");
- if( m_DDXFields.WriteData("t_dev_variant_item", strSQLText, m_operation) == -1 ) return;
- }
- catch(...)
- {
- ;
- }
- CDialog::OnOK();
- }//try
- catch( _com_error &e )
- {
- CString mes1,mes2,mes3,mes4;
- mes1.Format(_T("Error:%08lx.\n"), e.Error());
- mes2.Format(_T("ErrorMessage:%s.\n"), e.ErrorMessage());
- mes3.Format(_T("Source:%s.\n"), (LPCTSTR) _bstr_t(e.Source()));
- mes4.Format(_T("Description:%s.\n"), (LPCTSTR) _bstr_t(e.Description()));
- MessageBox(mes1+mes2+mes3+mes4,_T("Invalid field "),MB_ICONERROR);
- return;
- }
- catch(...)
- {
- MessageBox(_T("Unhandled Exception"),_T("Invalid field ")+strField,MB_ICONERROR);
- return;
- }
- UpdateData(FALSE);
- }
|