📄 brandsetdlg.cpp
字号:
int last_item = index * 10;
if ( last_item > num_of_brand )
{
last_item = num_of_brand;
}
CString str2;
str2 = str_sn_num[last_item -1];
_RecordsetPtr m_pRs;
CString m_strSql;
m_strSql.Format(_T("select BRAND,COMPANY,TEL,FAX,EMAIL,WEBSITE,SN from BRAND_TABLE where ( SN>=") +str1+ _T(" and SN<=") +str2+ _T(")"));
m_pRs.CreateInstance( __uuidof(Recordset) );
m_pRs->Open( _bstr_t(m_strSql), _variant_t((IDispatch *)pMyConnect,true), adOpenKeyset, adLockOptimistic, adCmdText);
int i=0;
the_last = 0;
try
{
m_pRs->MoveFirst();
while(m_pRs->adoEOF==VARIANT_FALSE)
{
//Retrieve column's value:
_variant_t TheValue;
_bstr_t tmp;
//此处要加上对查询的字段获取为空的情况。
TheValue = m_pRs->Fields->GetItem(_variant_t("BRAND"))->Value;
tmp=(_bstr_t)TheValue;
CString str_tmp0 = tmp;
str_data[i][0] = str_tmp0;
CString temp = _T("");
str_tmp0.TrimLeft(temp);
TheValue = m_pRs->Fields->GetItem(_variant_t("COMPANY"))->Value;
tmp=(_bstr_t)TheValue;
CString str_tmp1 = tmp;
str_data[i][1] = str_tmp1;
TheValue = m_pRs->Fields->GetItem(_variant_t("TEL"))->Value;
tmp=(_bstr_t)TheValue;
CString str_tmp2 = tmp;
str_data[i][2] = str_tmp2;
TheValue = m_pRs->Fields->GetItem(_variant_t("FAX"))->Value;
tmp=(_bstr_t)TheValue;
CString str_tmp3 = tmp;
str_data[i][3] = str_tmp3;
TheValue = m_pRs->Fields->GetItem(_variant_t("EMAIL"))->Value;
tmp=(_bstr_t)TheValue;
CString str_tmp4 = tmp;
str_data[i][4] = str_tmp4;
TheValue = m_pRs->Fields->GetItem(_variant_t("WEBSITE"))->Value;
tmp=(_bstr_t)TheValue;
CString str_tmp5 = tmp;
str_data[i][5] = str_tmp5;
TheValue = m_pRs->Fields->GetItem(_variant_t("SN"))->Value;
tmp=(_bstr_t)TheValue;
CString str_tmp6 = tmp;
str_data[i][6] = str_tmp6;
str_data[i][7] = _T("B");
UpdateData(FALSE);
i++;
//Do something what you want to do: ......
m_pRs->MoveNext();
the_last++;
}
}
catch (_com_error &e)
{
//::MessageBox(NULL,e.Description(),(LPCTSTR)(_T("警告")),MB_OK);
}
m_pRs->Close();
//display the page
CString str3;
str3.Format( _T("%d"),total_page );
CString str4;
str4.Format( _T("%d"),cur_page );
CString str5 = str4 +_T("/")+ str3;
m_page.SetWindowText(str5);
SetUpDown();
DisableCheckBox();
CButton * pSome[10];
for ( int j = 0; j < i; j++ )
{
pSome[j] = (CButton *)GetDlgItem(CheckBoxId[j]);
pSome[j]->EnableWindow(TRUE);
}
}
void CBrandsetDlg::OnBnClickedButtonUp()
{
// TODO: Add your control notification handler code here
if ( cur_page == 1 )
{
return;
}
cur_page--;
DisplayBrand( cur_page );
ClearSelected(0);
}
void CBrandsetDlg::OnBnClickedButtonDown()
{
// TODO: Add your control notification handler code here
if ( cur_page == total_page )
{
return;
}
cur_page++;
DisplayBrand( cur_page );
ClearSelected(0);
}
void CBrandsetDlg::ClearDisplay()
{
for( int i = 0; i < 10; i++ )
{
for ( int j = 0; j < 8; j++ )
{
str_data[i][j] = _T("");
}
}
UpdateData(FALSE);
}
void CBrandsetDlg::ClearSelected( int ID )
{
CButton * pSome;
for ( int i = 0; i < 10; i++ )
{
if ( ID != CheckBoxId[i] )
{
pSome = (CButton *)GetDlgItem(CheckBoxId[i]);
pSome->SetCheck(BST_UNCHECKED);
}
}
EnableItem( ID );
}
void CBrandsetDlg::OnBnClickedCheck1()
{
// TODO: Add your control notification handler code here
ClearSelected(IDC_CHECK1);
}
void CBrandsetDlg::OnBnClickedCheck2()
{
// TODO: Add your control notification handler code here
ClearSelected(IDC_CHECK2);
}
void CBrandsetDlg::OnBnClickedCheck3()
{
// TODO: Add your control notification handler code here
ClearSelected(IDC_CHECK3);
}
void CBrandsetDlg::OnBnClickedCheck4()
{
// TODO: Add your control notification handler code here
ClearSelected(IDC_CHECK4);
}
void CBrandsetDlg::OnBnClickedCheck5()
{
// TODO: Add your control notification handler code here
ClearSelected(IDC_CHECK5);
}
void CBrandsetDlg::OnBnClickedCheck6()
{
// TODO: Add your control notification handler code here
ClearSelected(IDC_CHECK6);
}
void CBrandsetDlg::OnBnClickedCheck7()
{
// TODO: Add your control notification handler code here
ClearSelected(IDC_CHECK7);
}
void CBrandsetDlg::OnBnClickedCheck8()
{
// TODO: Add your control notification handler code here
ClearSelected(IDC_CHECK8);
}
void CBrandsetDlg::OnBnClickedCheck9()
{
// TODO: Add your control notification handler code here
ClearSelected(IDC_CHECK9);
}
void CBrandsetDlg::OnBnClickedCheck10()
{
// TODO: Add your control notification handler code here
ClearSelected(IDC_CHECK10);
}
void CBrandsetDlg::EnableItem( int ID )
{
CEdit * pSome[10][6];
CButton * pTemp;
DisableItem();
for ( int i = 0; i < 10; i++ )
{
if ( ID == CheckBoxId[i] )
{
for ( int j = 0; j < 6; j++ )
{
pSome[i][j] = (CEdit *)GetDlgItem(Item[i][j]);
pTemp = (CButton *)GetDlgItem(ID);
if ( pTemp->GetCheck() == BST_CHECKED )
{
pSome[i][j]->EnableWindow(TRUE);
}
}
}
}
}
void CBrandsetDlg::DisableItem()
{
CEdit * pSome[10][6];
for ( int i = 0; i < 10; i++ )
{
for ( int j = 0; j < 6; j++ )
{
pSome[i][j] = (CEdit *)GetDlgItem(Item[i][j]);
pSome[i][j]->EnableWindow(FALSE);
}
}
}
void CBrandsetDlg::OnBnClickedButtonDelete()
{
// TODO: Add your control notification handler code here
CButton * pSome[10];
for ( int i = 0; i < 10; i++ )
{
pSome[i] = (CButton *)GetDlgItem(CheckBoxId[i]);
if ( pSome[i]->GetCheck() == BST_CHECKED )
{
ClearSelected(0);
CString m_strSql;
_RecordsetPtr m_pRecordset;
_variant_t RecordsAffected;
m_strSql.Format(_T("delete from BRAND_TABLE where(BRAND='") +str_data[i][0]+ _T("')"));
bool bSuccess = pMyConnect->Execute(_bstr_t(m_strSql),&RecordsAffected,adCmdText);
if( !bSuccess )
{
AfxMessageBox(_T("删除品牌失败,请重启系统!"));
return;
}
AfxMessageBox(_T("删除品牌成功!"));
if ( !ReadDB())
{
return;
}
cur_page= 1;
DisplayBrand( cur_page );
}
}
}
void CBrandsetDlg::DisableCheckBox()
{
CButton * pTemp[10];
for ( int k = 0; k < 10; k++ )
{
pTemp[k] = (CButton *)GetDlgItem(CheckBoxId[k]);
pTemp[k]->EnableWindow( FALSE );
}
}
void CBrandsetDlg::DisableUpDown()
{
CButton * pTemp;
pTemp = (CButton *)GetDlgItem(IDC_BUTTON_UP);
pTemp->EnableWindow( FALSE );
pTemp = (CButton *)GetDlgItem(IDC_BUTTON_DOWN);
pTemp->EnableWindow( FALSE );
}
void CBrandsetDlg::SetUpDown()
{
CButton * pTemp;
if ( total_page == 1 )
{
pTemp = (CButton *)GetDlgItem(IDC_BUTTON_UP);
pTemp->EnableWindow( FALSE );
pTemp = (CButton *)GetDlgItem(IDC_BUTTON_DOWN);
pTemp->EnableWindow( FALSE );
}
else
{
if ( cur_page == 1 )
{
pTemp = (CButton *)GetDlgItem(IDC_BUTTON_UP);
pTemp->EnableWindow( FALSE );
pTemp = (CButton *)GetDlgItem(IDC_BUTTON_DOWN);
pTemp->EnableWindow( TRUE );
}
else if( cur_page == total_page )
{
pTemp = (CButton *)GetDlgItem(IDC_BUTTON_UP);
pTemp->EnableWindow( TRUE );
pTemp = (CButton *)GetDlgItem(IDC_BUTTON_DOWN);
pTemp->EnableWindow( FALSE );
}
else
{
pTemp = (CButton *)GetDlgItem(IDC_BUTTON_UP);
pTemp->EnableWindow( TRUE );
pTemp = (CButton *)GetDlgItem(IDC_BUTTON_DOWN);
pTemp->EnableWindow( TRUE );
}
}
}
void CBrandsetDlg::OnBnClickedButtonModify()
{
// TODO: Add your control notification handler code here
//ClearSelected(0);
CButton * pTemp;
bool bHad = FALSE;
for ( int k = 0; k < 10; k++ )
{
pTemp = (CButton *)GetDlgItem(CheckBoxId[k]);
if ( pTemp->GetCheck( ) == BST_CHECKED )
{
bHad = TRUE;
index = k;
bAdd = FALSE;
CChangeBrand changebrand;
INT_PTR nResponse = changebrand.DoModal();
if (nResponse == IDOK)
{
// TODO: 在此处放置处理何时用“确定”来关闭
// 对话框的代码
}
else if (nResponse == IDCANCEL)
{
// TODO: 在此放置处理何时用“取消”来关闭
// 对话框的代码
}
}
}
//refresh current page
DisplayBrand( cur_page );
if ( !bHad )
{
AfxMessageBox(_T("请选择您要修改的品牌!"));
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -