?? remotedbdlg.cpp
字號:
_variant_t var;
int i = 0;
try
{
while(!m_pRecordset->adoEOF)
{
var=m_pRecordset->GetCollect("name");
if(var.vt!=VT_NULL)
strName = (LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("sex");
if(var.vt!=VT_NULL)
strSex = (LPCSTR)_bstr_t(var);
var=m_pRecordset->GetCollect("age");
if(var.vt!=VT_NULL)
strAge.Format("%d",var.intVal);
m_Data.InsertItem(i,strName);
m_Data.SetItemText(i,1,strSex);
m_Data.SetItemText(i,2,strAge);
m_pRecordset->MoveNext();
i++;
}
}
catch(_com_error &e)
{
AfxMessageBox("讀取個人信息表內數據失敗!");
AfxMessageBox(e.ErrorMessage());
}
}
BOOL CRemoteDBDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
//關閉記錄集
if (m_pRecordset->State)
m_pRecordset->Close();
m_pRecordset = NULL;
return CDialog::DestroyWindow();
}
void CRemoteDBDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
DestroyWindow();
CDialog::OnClose();
}
void CRemoteDBDlg::OnClickData(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
POSITION posUserSel = m_Data.GetFirstSelectedItemPosition();
if(posUserSel == NULL)
{
m_Name=m_Sex=m_Age="";
m_BDelData.EnableWindow(false);
m_BModifyData.EnableWindow(false);
UpdateData(false);
return;
}
m_BDelData.EnableWindow(true);
m_BModifyData.EnableWindow(true);
m_nItem = m_Data.GetNextSelectedItem(posUserSel);
m_Name=m_Data.GetItemText(m_nItem,0);
m_Sex=m_Data.GetItemText(m_nItem,1);
m_Age=m_Data.GetItemText(m_nItem,2);
UpdateData(false);
*pResult = 0;
}
void CRemoteDBDlg::OnDeldata()
{
// TODO: Add your control notification handler code here
if (MessageBox("確認刪除?","提示",MB_OKCANCEL | MB_ICONQUESTION) == IDCANCEL)
return;
CString strSQL;
strSQL = "DELETE FROM 個人信息 WHERE name='"+m_Name+"'";
theApp.ExcuteCommandADO(strSQL);
ListData();
m_BDelData.EnableWindow(false);
m_BModifyData.EnableWindow(false);
m_Name=m_Sex=m_Age="";
UpdateData(false);
MessageBox("刪除成功!");
}
void CRemoteDBDlg::OnInsertdata()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
//判斷所填信息是否完整
if ( (m_Name=="") || (m_Sex=="") || (m_Age=="") )
{
MessageBox("您填寫的信息不全,請檢查后重新輸入!");
m_Name=m_Sex=m_Age="";
UpdateData(FALSE);
return;
}
int i;
int ItemNum=m_Data.GetItemCount();
for (i=0;i<ItemNum;i++)
{
if (m_Name == m_Data.GetItemText(i,0))
{
AfxMessageBox("您填寫的用戶名已存在,請檢查后重新輸入!");
m_Name=m_Sex=m_Age="";
UpdateData(FALSE);
return;
}
}
//提示是否增加
if (MessageBox("確認增加?","提示",MB_OKCANCEL | MB_ICONQUESTION) == IDCANCEL)
{
m_Name=m_Sex=m_Age="";
UpdateData(FALSE);
return;
}
CString strSQL;
strSQL.Format("INSERT INTO 個人信息 (name,sex,age) VALUES ('"+m_Name+\
"','"+m_Sex+"',%d)",atoi(m_Age));
theApp.ExcuteCommandADO(strSQL);
m_Name=m_Sex=m_Age="";
UpdateData(false);
ListData();
MessageBox("插入成功!");
}
void CRemoteDBDlg::OnModifydata()
{
// TODO: Add your control notification handler code here
if (MessageBox("確認修改?","提示",MB_OKCANCEL | MB_ICONQUESTION) == IDCANCEL)
{
m_Name=m_Sex=m_Age="";
UpdateData(FALSE);
return;
}
//////////////////////////////////////////////////////////////////////////////
m_pRecordsetMod.CreateInstance(__uuidof(Recordset));
CString strSQLMod,strSelName;
strSelName=m_Data.GetItemText(m_nItem,0);
strSQLMod = "SELECT * FROM 個人信息 WHERE name = '"+strSelName+"'";
m_pRecordsetMod->Open(strSQLMod.AllocSysString(),
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
//////////////////////////////////////////////////////////
UpdateData();
try
{
// 修改當前記錄的字段值
m_pRecordsetMod->PutCollect("name", _variant_t(m_Name));
m_pRecordsetMod->PutCollect("sex", _variant_t(m_Sex));
m_pRecordsetMod->PutCollect("age", (long)atoi(m_Age));
m_pRecordsetMod->Update();
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
m_Name=m_Sex=m_Age="";
UpdateData(false);
ListData();
m_BDelData.EnableWindow(false);
m_BModifyData.EnableWindow(false);
MessageBox("修改成功!");
}
void CRemoteDBDlg::OnDelalldata()
{
// TODO: Add your control notification handler code here
if (MessageBox("刪除全部數據?","提示",MB_OKCANCEL | MB_ICONQUESTION) == IDCANCEL)
return;
CString strSQL;
strSQL = "DELETE * FROM 個人信息";
theApp.ExcuteCommandADO(strSQL);
m_Data.DeleteAllItems();
MessageBox("刪除成功!");
}
void CRemoteDBDlg::OnListdata()
{
// TODO: Add your control notification handler code here
ListData();
}
void CRemoteDBDlg::OnSelendokItem()
{
// TODO: Add your control notification handler code here
UpdateData();
if (m_Item == "年齡")
{
m_ctrOper.ShowWindow(true);
}
else
{
m_ctrOper.ShowWindow(false);
m_ctrTerm2.ShowWindow(false);
}
}
void CRemoteDBDlg::OnSelendokOper()
{
// TODO: Add your control notification handler code here
UpdateData();
if (m_Oper == "介于")
{
m_ctrTerm2.ShowWindow(true);
}
else
{
m_ctrTerm2.ShowWindow(false);
}
}
void CRemoteDBDlg::OnQuery()
{
// TODO: Add your control notification handler code here
CString strQuery;
UpdateData();
if (m_ctrOper.IsWindowVisible())
{
if ((m_Item == "") || (m_Oper == ""))
{
AfxMessageBox("請選擇查詢條件!");
return;
}
}
else
{
if (m_Item == "")
{
AfxMessageBox("請選擇查詢條件!");
return;
}
}
if (m_ctrTerm2.IsWindowVisible())
{
if ((m_Term == "")||(m_Term2 == ""))
{
AfxMessageBox("請選擇查詢內容!");
return;
}
}
else
{
if (m_Term == "")
{
AfxMessageBox("請選擇查詢內容!");
return;
}
}
if (m_Item == "姓名")
strQuery = "SELECT * FROM 個人信息 WHERE name = '"+m_Term+"' ";
else if (m_Item == "性別")
strQuery = "SELECT * FROM 個人信息 WHERE sex = '"+m_Term+"' ";
else
{
if (m_Oper != "介于")
strQuery.Format( "SELECT * FROM 個人信息 WHERE age "+m_Oper+" %s",m_Term);
else
strQuery.Format( "SELECT * FROM 個人信息 WHERE age BETWEEN %s AND %s",m_Term,m_Term2);
}
ListQueryData(strQuery);
m_ctrOper.ShowWindow(false);
m_ctrTerm2.ShowWindow(false);
m_Item=m_Term="";
UpdateData(false);
}
void CRemoteDBDlg::ListQueryData(CString str)
{
//////////////////////////////////////////////////////////////////////////////
m_pRecordsetQuery.CreateInstance(__uuidof(Recordset));
m_pRecordsetQuery->Open(str.AllocSysString(),
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
//////////////////////////////////////////////////////////
CString strName,strSex,strAge;
if(!m_pRecordsetQuery->BOF)
m_pRecordsetQuery->MoveFirst();
else
{
AfxMessageBox("表內數據為空");
return;
}
m_Data.DeleteAllItems();
_variant_t var;
int i = 0;
try
{
while(!m_pRecordsetQuery->adoEOF)
{
var=m_pRecordsetQuery->GetCollect("name");
if(var.vt!=VT_NULL)
strName = (LPCSTR)_bstr_t(var);
var=m_pRecordsetQuery->GetCollect("sex");
if(var.vt!=VT_NULL)
strSex = (LPCSTR)_bstr_t(var);
var=m_pRecordsetQuery->GetCollect("age");
if(var.vt!=VT_NULL)
strAge.Format("%d",var.intVal);
m_Data.InsertItem(i,strName);
m_Data.SetItemText(i,1,strSex);
m_Data.SetItemText(i,2,strAge);
m_pRecordsetQuery->MoveNext();
i++;
}
}
catch(_com_error &e)
{
AfxMessageBox("讀取用戶信息表內數據失敗!");
AfxMessageBox(e.ErrorMessage());
}
}
void CRemoteDBDlg::OnImport()
{
// TODO: Add your control notification handler code here
int loadtime=0;
UpdateData();
loadtime = atoi(m_Hour);
loadtime = 60 *loadtime;//分鐘
if (transferParam == NULL)
{
transferParam = new TransferParam; //定義一個結構體
}
TransferParam* transferParam = new TransferParam;
transferParam->accessODBC = "tanfen";
transferParam->oraODBC = "SecSourceData";//SecSourceData
transferParam->sampleID = "";
transferParam->timeInterval = loadtime;
transferParam->sampleType = 0;
transferParam->yuanYeSampleID = "269";
transferParam->cFenSampleID = "269";
transferParam->tableName = "原始數據";
transferParam->iGroup = 2;
transferParam->connectDelay = 1000;
transferParam->retryCount = 5;
transferParam->caller = this->GetSafeHwnd();
hThread = CreateOra2AccessThread(transferParam,hThread); //全局函數,用來創建線程
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -