?? web.cpp
字號:
// Web.cpp : implementation file
//
#include "stdafx.h"
#include "Papaz.h"
#include "Web.h"
#include "WebKeyBox.h"
#include "WebFind.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWeb property page
IMPLEMENT_DYNCREATE(CWeb, CPropertyPage)
CWeb::CWeb() : CPropertyPage(CWeb::IDD)
{
//{{AFX_DATA_INIT(CWeb)
m_Key = _T("");
m_Name = _T("");
m_Address = _T("");
m_WebName = _T("");
//}}AFX_DATA_INIT
sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";
sFile = "Papaz.mdb";
sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile);
m_strID = "-1";
}
CWeb::~CWeb()
{
}
void CWeb::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWeb)
DDX_Control(pDX, IDC_OK, m_OK);
DDX_Control(pDX, IDC_CANCEL, m_Cancel);
DDX_Control(pDX, IDC_ADD, m_Add);
DDX_Control(pDX, IDC_DEL, m_Del);
DDX_Control(pDX, IDC_FIND, m_Find);
DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
DDX_Text(pDX, IDC_KEY, m_Key);
DDX_Text(pDX, IDC_NAME, m_Name);
DDX_Text(pDX, IDC_ADDRESS, m_Address);
DDX_Text(pDX, IDC_WEBNAME, m_WebName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWeb, CPropertyPage)
//{{AFX_MSG_MAP(CWeb)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_DEL, OnDel)
ON_BN_CLICKED(IDC_FIND, OnFind)
ON_BN_CLICKED(IDC_OK, OnOk)
ON_BN_CLICKED(IDC_CANCEL, OnCancel)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWeb message handlers
void CWeb::OnAdd()
{
// TODO: Add your control notification handler code here
m_Key="";
m_Name="";
m_Address="";
m_strID="-1";
m_WebName="";
m_OK.EnableWindow();
m_Cancel.EnableWindow();
UpdateData(FALSE);
}
void CWeb::OnDel()
{
// TODO: Add your control notification handler code here
database.Open(NULL,false ,false ,sDsn);
CWebSet m_recordset(&database);
int i=m_ListCtrl.GetSelectionMark();
if(0>i)
{
MessageBox("請選擇一條記錄進(jìn)行刪除!");
return;
}
CString strSQL;
strSQL.Format("select * from 網(wǎng)站信息 where ID= %s ",m_ListCtrl.GetItemText(i,0));
if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
MessageBox("打開數(shù)據(jù)庫失敗!","數(shù)據(jù)庫錯(cuò)誤",MB_OK);
return ;
}
//刪除該用戶
m_recordset.Delete();
database.Close();
// m_recordset.Close();
//更新用戶列表
strSQL="select * from 網(wǎng)站信息";
Show(strSQL);
m_Key="";
m_Name="";
m_Address="";
// m_strID = "-1";
m_WebName="";
UpdateData(FALSE);
m_OK.EnableWindow(FALSE);
m_Cancel.EnableWindow(FALSE);
}
void CWeb::OnFind()
{
// TODO: Add your control notification handler code here
CWebFind f;
CString FindName;
UpdateData();
CString strSQL;
if(f.DoModal()==IDOK)
{
FindName.Format("%%%s%%",f.m_FindName);
// MessageBox(FindName);
strSQL.Format("select * from 網(wǎng)站信息 where WebName like '%s'",FindName);
//顯示全部信息
// if(m_strContent=="")
// strSQL = "select * from 網(wǎng)站信息";
this->Show(strSQL);
}
}
BOOL CWeb::OnInitDialog()
{
CPropertyPage::OnInitDialog();
m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_ListCtrl.InsertColumn(0,_T("編號"),LVCFMT_IMAGE|LVCFMT_LEFT);
m_ListCtrl.InsertColumn(1,_T("網(wǎng)名"));
m_ListCtrl.InsertColumn(2,_T("網(wǎng)址"));
// m_ListCtrl.InsertColumn(3,_T("用戶名"));
// m_ListCtrl.InsertColumn(4,_T("密碼"));
m_ListCtrl.SetColumnWidth(0 ,45);
m_ListCtrl.SetColumnWidth(1 ,90);
m_ListCtrl.SetColumnWidth(2 ,150);
// m_ListCtrl.SetColumnWidth(3 ,90);
// m_ListCtrl.SetColumnWidth(4 ,90);
//顯示所有記錄
CString strSQL;
strSQL="select * from 網(wǎng)站信息";
this->Show(strSQL);
m_OK.EnableWindow(FALSE);
m_Cancel.EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CWeb::OnOk()
{
database.Open(NULL,false ,false ,sDsn);
CWebSet m_recordset(&database);
UpdateData();
CString strSQL;
strSQL.Format("select * from 網(wǎng)站信息 where ID= %s",m_strID);
if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
MessageBox("打開數(shù)據(jù)庫失敗!","數(shù)據(jù)庫錯(cuò)誤",MB_OK);
return ;
}
if(m_recordset.GetRecordCount()==0)
{//判斷用戶是否存在
m_recordset.AddNew();
m_recordset.m_Address=m_Address;
m_recordset.m_Key=m_Key;
m_recordset.m_UserName=m_Name;
m_recordset.m_WebName=m_WebName;
m_recordset.Update();
}
else
{//修改用戶信息
m_recordset.Edit();
m_recordset.m_Address=m_Address ;
m_recordset.m_Key=m_Key ;
m_recordset.m_UserName=m_Name ;
m_recordset.m_WebName=m_WebName;
m_recordset.Update();
}
// m_recordset.Close();
database.Close();
strSQL="select * from 網(wǎng)站信息";
this->Show(strSQL);
m_OK.EnableWindow(FALSE);
m_Cancel.EnableWindow(FALSE);
m_Key="";
m_Name="";
m_Address="";
m_WebName="";
}
void CWeb::OnCancel()
{
// TODO: Add your control notification handler code here
m_OK.EnableWindow(FALSE);
m_Cancel.EnableWindow(FALSE);
m_Key="";
m_Name="";
m_Address="";
m_WebName="";
}
void CWeb::Show(CString str)
{
m_ListCtrl.SetFocus();
m_ListCtrl.DeleteAllItems();
m_ListCtrl.SetRedraw(FALSE);
database.Open(NULL,false ,false ,sDsn);
CWebSet m_recordset(&database);
char buffer[20];
UpdateData(TRUE);
if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,str))
{
MessageBox("打開數(shù)據(jù)庫失敗!","數(shù)據(jù)庫錯(cuò)誤",MB_OK);
return ;
}
int i=0;
while(!m_recordset.IsEOF())
{
ltoa(m_recordset.m_ID,buffer,10);
m_ListCtrl.InsertItem(i,buffer);
//
m_ListCtrl.SetItemText(i,1,m_recordset.m_WebName);
m_ListCtrl.SetItemText(i,2,m_recordset.m_Address);
m_ListCtrl.SetItemText(i,3,m_recordset.m_UserName);
m_ListCtrl.SetItemText(i,4,m_recordset.m_Key);
i++;
m_recordset.MoveNext();
}
// m_recordset.Close();
database.Close();
m_ListCtrl.SetRedraw(TRUE);
}
void CWeb::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
m_OK.EnableWindow(FALSE);
m_Cancel.EnableWindow(FALSE);
CWebKeyBox f;
CString strSQL;
UpdateData(TRUE);
int i=m_ListCtrl.GetSelectionMark();
f.DoModal();
if(f.m_LoadKey!="1234")
return;
// MessageBox("kkkk");
database.Open(NULL,false ,false ,sDsn);
CWebSet m_recordset(&database);
m_strID=m_ListCtrl.GetItemText(i,0);
strSQL.Format("select * from 網(wǎng)站信息 where ID=%s",m_strID);
if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
MessageBox("打開數(shù)據(jù)庫失敗!","數(shù)據(jù)庫錯(cuò)誤",MB_OK);
return ;
}
m_Address=m_recordset.m_Address;
m_Key=m_recordset.m_Key;
m_Name=m_recordset.m_UserName;
m_WebName=m_recordset.m_WebName;
// m_recordset.Close();
database.Close();
UpdateData(FALSE);
*pResult = 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -