📄 adddepart.cpp
字号:
// AddDepart.cpp : 实现文件
//
#include "stdafx.h"
#include "AddDepart.h"
extern _ConnectionPtr pMyConnect;
// CAddDepart 对话框
IMPLEMENT_DYNAMIC(CAddDepart, CDialog)
CAddDepart::CAddDepart(CWnd* pParent /*=NULL*/)
: CDialog(CAddDepart::IDD, pParent)
{
}
CAddDepart::~CAddDepart()
{
}
void CAddDepart::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAddDepart, CDialog)
ON_BN_CLICKED(IDOK, &CAddDepart::OnBnClickedOk)
END_MESSAGE_MAP()
// CAddDepart 消息处理程序
BOOL CAddDepart::OnInitDialog()
{
CDialog::OnInitDialog();
_RecordsetPtr m_pRs;
CString m_strSql;
int number = 0;
bool bHad = FALSE;
CComboBox* pWnd;
pWnd = (CComboBox*)GetDlgItem(IDC_COMBO_FLAG);
pWnd->ResetContent();
for ( char ch = 'A'; ch <= 'Z';ch++ )
{
bHad = FALSE;
CString str_temp(ch);
m_strSql.Format(_T("select SN from DEPART_TABLE where ( FLAG='") +str_temp+ _T("')") );
m_pRs.CreateInstance( __uuidof(Recordset) );
m_pRs->Open( _bstr_t(m_strSql), _variant_t((IDispatch *)pMyConnect,true), adOpenKeyset, adLockOptimistic, adCmdText);
try
{
if ( m_pRs->GetRecordCount() > 0 )
{
_variant_t TheValue;
_bstr_t tmp;
m_pRs->MoveFirst();
while(m_pRs->adoEOF==VARIANT_FALSE)
{
//Retrieve column's value:
TheValue = m_pRs->Fields->GetItem(_variant_t("SN"))->Value;
if( TheValue.vt != VT_NULL )
{
tmp=(_bstr_t)TheValue;
bHad = TRUE;
}
//Do something what you want to do: ......
m_pRs->MoveNext();
}
}
}
catch (_com_error &e)
{
::MessageBox(NULL,e.Description(),(LPCTSTR)(_T("警告")),MB_OK);
}
m_pRs->Close();
if (!bHad)
{
pWnd->AddString(str_temp);
}
}
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
void CAddDepart::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
CString str0;
CString str1;
CString str2;
CWnd* pWnd;
//BRAND
pWnd = GetDlgItem(IDC_EDIT_DEPART);
pWnd->GetWindowText(str0);
if ( str0.GetLength() == 0 )
{
AfxMessageBox(_T("部门名称不能为空!"));
return;
}
if ( str0.GetLength() > 20 )
{
AfxMessageBox(_T("部门名称长度超出限制!"));
return;
}
_RecordsetPtr m_pRs;
CString m_strSql;
bool bHad = FALSE;
m_strSql.Format(_T("select SN from DEPART_TABLE where ( DEPART='") +str0+ _T("')") );
m_pRs.CreateInstance( __uuidof(Recordset) );
m_pRs->Open( _bstr_t(m_strSql), _variant_t((IDispatch *)pMyConnect,true), adOpenKeyset, adLockOptimistic, adCmdText);
try
{
if ( m_pRs->GetRecordCount() > 0 )
{
_variant_t TheValue;
m_pRs->MoveFirst();
while(m_pRs->adoEOF==VARIANT_FALSE)
{
//Retrieve column's value:
TheValue = m_pRs->Fields->GetItem(_variant_t("SN"))->Value;
if(TheValue.vt != VT_NULL)
{
_bstr_t s1=(_bstr_t)TheValue;
CString sn = s1;
bHad = TRUE;
}
//Do something what you want to do: ......
m_pRs->MoveNext();
}
}
}
catch (_com_error &e)
{
::MessageBox(NULL,e.Description(),(LPCTSTR)(_T("警告")),MB_OK);
}
m_pRs->Close();
if ( bHad )
{
AfxMessageBox(_T("此部门已存在!"));
return;
}
//NOTE
pWnd = GetDlgItem(IDC_COMBO_FLAG);
pWnd->GetWindowText(str1);
if ( str1.GetLength() == 0 )
{
AfxMessageBox(_T("请选择部门代码!"));
return;
}
//NOTE
pWnd = GetDlgItem(IDC_EDIT_NOTE);
pWnd->GetWindowText(str2);
if ( str2.GetLength() > 50 )
{
AfxMessageBox(_T("注释长度超出限制!"));
return;
}
//goto the last page, and then add a item
//CString m_strSql;
//_RecordsetPtr m_pRecordset;
_variant_t RecordsAffected;
m_strSql.Format(_T("INSERT INTO DEPART_TABLE(DEPART,NOTE,FLAG) VALUES ('") +str0+ _T("','") +str2+ _T("','") +str1+ _T("')"));
bool bSuccess = pMyConnect->Execute(_bstr_t(m_strSql),&RecordsAffected,adCmdText);
if( !bSuccess )
{
AfxMessageBox(_T("增加部门失败,请重启系统!"));
return;
}
AfxMessageBox(_T("增加部门成功!"));
OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -