16,471
社区成员
发帖
与我相关
我的任务
分享
void CPropPage1::OnButton1()
{
//CStaticName::a--;
if (CStaticName::a==0)
{
MessageBox("这是首页!");
GetDlgItem(IDC_BUTTON1)->EnableWindow(false);
CStaticName::a=1;
}else{
try
{
m_pConnection.CreateInstance("ADODB.Connection");
CString strConnect="Provider=Microsoft.Jet.OLEDB.4.0;\
Data Source=Database\\City.mdb;Persist Security Info=False";
m_pConnection->Open((_bstr_t)strConnect,"","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接",0,0);
}
CStaticName::a--;
int n=13*CStaticName::a;
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset_count.CreateInstance(__uuidof(Recordset));
CString sql1;
sql1.Format("select count(*) as num from Zu where name = '%s' ",TreeCurrent);
_variant_t vt1;
vt1.vt = sql1.IsEmpty() ? VT_NULL:VT_BSTR;
vt1.bstrVal = sql1.AllocSysString();
CString num;
m_pRecordset_count->Open(vt1,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_pRecordset_count->adoEOF){
num=(LPCTSTR)(_bstr_t)m_pRecordset_count->GetCollect("num");
}
if (1==CStaticName::a)
{
MessageBox("到首页!");
GetDlgItem(IDC_BUTTON1)->EnableWindow(false);
}else{
GetDlgItem(IDC_BUTTON1)->EnableWindow(true);
GetDlgItem(IDC_BUTTON2)->EnableWindow(true);
CString sql;
sql.Format("select top 13 ID,Name,ParentItem,SecNum,tel from Zu where ID1 not in (select top %d ID1 from Zu where name = '%s' order by ID1 desc) and name = '%s' order by ID1 desc",n,TreeCurrent,TreeCurrent);
_variant_t vt;
vt.vt = sql.IsEmpty() ? VT_NULL:VT_BSTR;
vt.bstrVal = sql.AllocSysString();
m_pRecordset->Open(vt,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
//删除所有列
m_ctrllist.DeleteAllItems();
int nIndex=0;
while(!m_pRecordset->adoEOF && nIndex<13)
{
CString id=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("ID");
CString name=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Name");
vt = m_pRecordset->GetCollect("ParentItem");
CString parentitem=(vt.vt!=VT_NULL)?(LPCTSTR)(_bstr_t)vt:"";
vt = m_pRecordset->GetCollect("SecNum");
CString secnum=(vt.vt!=VT_NULL)?(LPCTSTR)(_bstr_t)vt:"";
vt = m_pRecordset->GetCollect("tel");
CString tel=(vt.vt!=VT_NULL)?(LPCTSTR)(_bstr_t)vt:"";
m_ctrllist.InsertItem(nIndex,id);
m_ctrllist.SetItemText(nIndex,1,name);
m_ctrllist.SetItemText(nIndex,2,parentitem);
m_ctrllist.SetItemText(nIndex,3,secnum);
m_ctrllist.SetItemText(nIndex,4,tel);
nIndex++;
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
}
}
}
void CPropPage1::OnButton2()
{
try
{
m_pConnection.CreateInstance("ADODB.Connection");
CString strConnect="Provider=Microsoft.Jet.OLEDB.4.0;\
Data Source=Database\\City.mdb;Persist Security Info=False";
m_pConnection->Open((_bstr_t)strConnect,"","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox("数据库连接",0,0);
}
int n=13*CStaticName::a;
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset_count.CreateInstance(__uuidof(Recordset));
CString sql1;
sql1.Format("select count(*) as num from Zu where name = '%s' ",TreeCurrent);
_variant_t vt1;
vt1.vt = sql1.IsEmpty() ? VT_NULL:VT_BSTR;
vt1.bstrVal = sql1.AllocSysString();
// CStaticName::a++;
CString num;
m_pRecordset_count->Open(vt1,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_pRecordset_count->adoEOF){
num=(LPCTSTR)(_bstr_t)m_pRecordset_count->GetCollect("num");
}
int value;
sscanf((LPCTSTR)num, "%d", &value);
int temp=value%13;
int page=value/13;
if(temp!=0)
{
page=page+1;
}
if (page==CStaticName::a)
{
MessageBox("到末页!");
GetDlgItem(IDC_BUTTON2)->EnableWindow(false);
}else{
GetDlgItem(IDC_BUTTON1)->EnableWindow(true);
GetDlgItem(IDC_BUTTON2)->EnableWindow(true);
CString sql;
sql.Format("select top 13 ID,Name,ParentItem,SecNum,tel from Zu where ID1 not in (select top %d ID1 from Zu where name = '%s' order by ID1 desc) and name = '%s' order by ID1 desc",n,TreeCurrent,TreeCurrent);
_variant_t vt;
vt.vt = sql.IsEmpty() ? VT_NULL:VT_BSTR;
vt.bstrVal = sql.AllocSysString();
// CStaticName::a++;
m_pRecordset->Open(vt,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
//删除所有列
m_ctrllist.DeleteAllItems();
int nIndex=0;
while(!m_pRecordset->adoEOF && nIndex<13)
{
CString id=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("ID");
CString name=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Name");
vt = m_pRecordset->GetCollect("ParentItem");
CString parentitem=(vt.vt!=VT_NULL)?(LPCTSTR)(_bstr_t)vt:"";
vt = m_pRecordset->GetCollect("SecNum");
CString secnum=(vt.vt!=VT_NULL)?(LPCTSTR)(_bstr_t)vt:"";
vt = m_pRecordset->GetCollect("tel");
CString tel=(vt.vt!=VT_NULL)?(LPCTSTR)(_bstr_t)vt:"";
m_ctrllist.InsertItem(nIndex,id);
m_ctrllist.SetItemText(nIndex,1,name);
m_ctrllist.SetItemText(nIndex,2,parentitem);
m_ctrllist.SetItemText(nIndex,3,secnum);
m_ctrllist.SetItemText(nIndex,4,tel);
nIndex++;
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
CStaticName::a++;
}
}