⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 web.cpp

📁 记录工作日志方面的信息
💻 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("请选择一条记录进行删除!");
		return;
	}

	CString strSQL;
	strSQL.Format("select * from 网站信息 where ID= %s ",m_ListCtrl.GetItemText(i,0));
	if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		MessageBox("打开数据库失败!","数据库错误",MB_OK);
		return ;
	}
	//删除该用户
	m_recordset.Delete();
	database.Close();
//	m_recordset.Close();

	//更新用户列表

	strSQL="select * from 网站信息";
	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 网站信息 where WebName like '%s'",FindName);	
	//显示全部信息
//	if(m_strContent=="")
//		strSQL = "select * from 网站信息";
	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("网名"));
	m_ListCtrl.InsertColumn(2,_T("网址"));
//	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 网站信息";
	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 网站信息 where ID= %s",m_strID);
	if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		MessageBox("打开数据库失败!","数据库错误",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 网站信息";
	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("打开数据库失败!","数据库错误",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 网站信息 where ID=%s",m_strID);
	if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		MessageBox("打开数据库失败!","数据库错误",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;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -