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

📄 addressbrowse.cpp

📁 Pim文件夹中为一简单的个人信息管理的程序源码
💻 CPP
字号:
// AddressBrowse.cpp : implementation file
//

#include "stdafx.h"
#include "PIM.h"
#include "AddressBrowse.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAddressBrowse dialog
#include "AmendData.h"

CAddressBrowse::CAddressBrowse(CWnd* pParent /*=NULL*/)
	: CDialog(CAddressBrowse::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAddressBrowse)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CAddressBrowse::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAddressBrowse)
	DDX_Control(pDX, IDC_ADDRESSLIST, m_cListAddress);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAddressBrowse, CDialog)
	//{{AFX_MSG_MAP(CAddressBrowse)
	ON_BN_CLICKED(IDC_AMENDDATA, OnAmenddata)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_BN_CLICKED(IDC_REFURBISH, OnRefurbish)
	ON_NOTIFY(NM_CLICK, IDC_ADDRESSLIST, OnClickAddresslist)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddressBrowse message handlers

BOOL CAddressBrowse::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	m_cListAddress.SetBkColor(RGB(177, 151, 240));
	m_cListAddress.SetTextColor(RGB(0,0,0));
	m_cListAddress.SetTextBkColor(RGB(177, 151, 240));
	
	m_cListAddress.SetExtendedStyle(LVS_EX_FULLROWSELECT|\
		LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP);

    m_cListAddress.InsertColumn(0,"ID",LVCFMT_LEFT,60,-1);
	m_cListAddress.InsertColumn(1,"姓名",LVCFMT_LEFT,60,-1);
	m_cListAddress.InsertColumn(2,"性别",LVCFMT_LEFT,60,-1);
	m_cListAddress.InsertColumn(3,"出生年月",LVCFMT_LEFT,80,-1);
	m_cListAddress.InsertColumn(4,"移动电话",LVCFMT_LEFT,80,-1);
	m_cListAddress.InsertColumn(5,"固定电话",LVCFMT_LEFT,80,-1);
	m_cListAddress.InsertColumn(6,"省/市/自治区",LVCFMT_LEFT,80,-1);
	m_cListAddress.InsertColumn(7,"市/县",LVCFMT_LEFT,80,-1);
	m_cListAddress.InsertColumn(8,"地址",LVCFMT_LEFT,200,-1);
	m_cListAddress.InsertColumn(9,"邮政编码",LVCFMT_LEFT,80,-1);
	m_cListAddress.InsertColumn(10,"电子邮件地址",LVCFMT_LEFT,120,-1);
   
	_variant_t Holder, strQuery;
	int ilistrow;	
//	int j;
//	float k;
//	int iFinished;
	CString sFinishedText;
    strQuery = "select * from 通讯录";
	theApp.ADOExecute(theApp.m_pADOSet, strQuery);
	int iCount=theApp.m_pADOSet->GetRecordCount();	
	if(iCount>0)
	{
		theApp.m_pADOSet->MoveFirst();
	}
	for(int i=0;i<iCount;i++)
	{
		Holder = theApp.m_pADOSet->GetCollect("ID");
		ilistrow = m_cListAddress.InsertItem(0,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("名字");
		m_cListAddress.SetItemText(ilistrow,1,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("性别");
		m_cListAddress.SetItemText(ilistrow,2,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("地址");
		m_cListAddress.SetItemText(ilistrow,8,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("市\/县");
		m_cListAddress.SetItemText(ilistrow,7,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("移动电话");
		m_cListAddress.SetItemText(ilistrow,4,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("省\/市\/自治区");
		m_cListAddress.SetItemText(ilistrow,6,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("邮政编码");
		m_cListAddress.SetItemText(ilistrow,9,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("电子邮件地址");
		m_cListAddress.SetItemText(ilistrow,10,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("固定电话");
		m_cListAddress.SetItemText(ilistrow,5,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("生日");
		m_cListAddress.SetItemText(ilistrow,3,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		theApp.m_pADOSet->MoveNext();
	}
	theApp.m_pADOSet->Close();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CAddressBrowse::OnAmenddata() 
{
	// TODO: Add your control notification handler code here

	CString amendId;
	CString amendName;
	ObjectData amenddata;
	_variant_t strQuery;
	_variant_t holder;
	amendId = m_cListAddress.GetItemText(m_IndexInFieldList,0);
	amendName = m_cListAddress.GetItemText(m_IndexInFieldList,1);
	strQuery = "select * from 通讯录 where ID="+amendId;
	theApp.ADOExecute(theApp.m_pADOSet,strQuery);
	int iCount=theApp.m_pADOSet->GetRecordCount();	
	if(iCount==0)
	{
		AfxMessageBox("数据库里不存在该数据");
		m_cListAddress.DeleteItem( m_IndexInFieldList );
		return;
	}
 
	amenddata.m_sId = amendId;
	amenddata.m_sName = amendName;
	CString aa;
//	aa.Format("%f",m_pAmenddata->firstwave);
//	m_sfirstwave=aa;
//	m_sinstrument=m_pAmenddata->
  //  aa.Format("%f",m_pAmenddata->lastwave);
//	m_slastwave=aa;

    amenddata.m_sSex = m_cListAddress.GetItemText(m_IndexInFieldList,2);
	amenddata.m_cBirthday = m_cListAddress.GetItemText(m_IndexInFieldList,3);
	amenddata.m_sCellphone = m_cListAddress.GetItemText(m_IndexInFieldList,4);
	
	amenddata.m_sTelphone = m_cListAddress.GetItemText(m_IndexInFieldList,5);
	amenddata.m_sProvince = m_cListAddress.GetItemText(m_IndexInFieldList,6);
	amenddata.m_sCounty = m_cListAddress.GetItemText(m_IndexInFieldList,7);
	amenddata.m_sAddress = m_cListAddress.GetItemText(m_IndexInFieldList,8);
	amenddata.m_sPostcode = m_cListAddress.GetItemText(m_IndexInFieldList,9);
	amenddata.m_sEmail = m_cListAddress.GetItemText(m_IndexInFieldList,10);

	CAmendData dlg;
	dlg.GetObjectData(&amenddata);
	_variant_t vt;
	if(dlg.DoModal()==IDOK)
	{
		m_cListAddress.SetItemText(m_IndexInFieldList,1,amenddata.m_sName);
		vt.vt = amenddata.m_sName.IsEmpty() ? VT_NULL : VT_BSTR;
		vt.bstrVal = amenddata.m_sName.AllocSysString();
		theApp.m_pADOSet->PutCollect("名字",vt);

		m_cListAddress.SetItemText(m_IndexInFieldList,3,amenddata.m_cBirthday);
		vt.vt = amenddata.m_cBirthday.IsEmpty() ? VT_NULL : VT_BSTR;
		vt.bstrVal = amenddata.m_cBirthday.AllocSysString();
		theApp.m_pADOSet->PutCollect("生日",vt);

		m_cListAddress.SetItemText(m_IndexInFieldList,2,amenddata.m_sSex);
		vt.vt = amenddata.m_sSex.IsEmpty() ? VT_NULL : VT_BSTR;
		vt.bstrVal = amenddata.m_sSex.AllocSysString();
		theApp.m_pADOSet->PutCollect("性别",vt);

		m_cListAddress.SetItemText(m_IndexInFieldList,4,amenddata.m_sCellphone);
		vt.vt = amenddata.m_sCellphone.IsEmpty() ? VT_NULL : VT_BSTR;
		vt.bstrVal = amenddata.m_sCellphone.AllocSysString();
		theApp.m_pADOSet->PutCollect("移动电话",vt);

		m_cListAddress.SetItemText(m_IndexInFieldList,5,amenddata.m_sTelphone);
		vt.vt = amenddata.m_sTelphone.IsEmpty() ? VT_NULL : VT_BSTR;
		vt.bstrVal = amenddata.m_sTelphone.AllocSysString();
		theApp.m_pADOSet->PutCollect("固定电话",vt);

		m_cListAddress.SetItemText(m_IndexInFieldList,6,amenddata.m_sProvince);
		vt.vt = amenddata.m_sProvince.IsEmpty() ? VT_NULL : VT_BSTR;
		vt.bstrVal = amenddata.m_sProvince.AllocSysString();
		theApp.m_pADOSet->PutCollect("省\/市\/自治区",vt);

		m_cListAddress.SetItemText(m_IndexInFieldList,7,amenddata.m_sCounty);
		vt.vt = amenddata.m_sCounty.IsEmpty() ? VT_NULL : VT_BSTR;
		vt.bstrVal = amenddata.m_sCounty.AllocSysString();
		theApp.m_pADOSet->PutCollect("市\/县",vt);

		m_cListAddress.SetItemText(m_IndexInFieldList,8,amenddata.m_sAddress);
		vt.vt = amenddata.m_sAddress.IsEmpty() ? VT_NULL : VT_BSTR;
		vt.bstrVal = amenddata.m_sAddress.AllocSysString();
		theApp.m_pADOSet->PutCollect("地址",vt);

		m_cListAddress.SetItemText(m_IndexInFieldList,9,amenddata.m_sPostcode);
		vt.vt = amenddata.m_sPostcode.IsEmpty() ? VT_NULL : VT_BSTR;
		vt.bstrVal = amenddata.m_sPostcode.AllocSysString();
		theApp.m_pADOSet->PutCollect("邮政编码",vt);
	
		m_cListAddress.SetItemText(m_IndexInFieldList,10,amenddata.m_sEmail);
		vt.vt = amenddata.m_sEmail.IsEmpty() ? VT_NULL : VT_BSTR;
		vt.bstrVal = amenddata.m_sEmail.AllocSysString();
		theApp.m_pADOSet->PutCollect("电子邮件地址",vt);

		theApp.m_pADOSet->Update();
		AfxMessageBox("修改成功",MB_ICONINFORMATION );

	}
	theApp.m_pADOSet->Close();
	
}

void CAddressBrowse::OnDelete() 
{
	// TODO: Add your control notification handler code here
	CString delId;
	CString delName;
	_variant_t strQuery;
	_variant_t holder;
	delId=m_cListAddress.GetItemText(m_IndexInFieldList,0);
	delName=m_cListAddress.GetItemText(m_IndexInFieldList,1);
	strQuery="select * from 通讯录 where ID="+delId;
	theApp.ADOExecute(theApp.m_pADOSet,strQuery);
	int iCount=theApp.m_pADOSet->GetRecordCount();	
	if(iCount==0)
	{
		AfxMessageBox("数据库里不存在该数据");
		m_cListAddress.DeleteItem( m_IndexInFieldList );
	}
	else
	{
		if(AfxMessageBox("你真要删除纪录:"+delName+"吗 ?",\
			MB_YESNO|MB_ICONQUESTION)!=IDYES)
		{
			theApp.m_pADOSet->Close();
			return;
		}

		if(theApp.m_pADOSet->Delete(adAffectCurrent) == S_OK)
		{
			m_cListAddress.DeleteItem( m_IndexInFieldList );
			AfxMessageBox(delName+"已经删除");
		}
	}
	theApp.m_pADOSet->Close();
	
}

void CAddressBrowse::OnRefurbish() 
{
	// TODO: Add your control notification handler code here
	m_cListAddress.DeleteAllItems();

	_variant_t Holder, strQuery;
	int ilistrow;	
//	int j;
//	float k;
//	int iFinished;
	CString sFinishedText;
    strQuery = "select * from 通讯录";
	theApp.ADOExecute(theApp.m_pADOSet, strQuery);
	int iCount=theApp.m_pADOSet->GetRecordCount();	
	if(iCount>0)
	{
		theApp.m_pADOSet->MoveFirst();
	}
	for(int i=0;i<iCount;i++)
	{
		Holder = theApp.m_pADOSet->GetCollect("ID");
		ilistrow = m_cListAddress.InsertItem(0,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("名字");
		m_cListAddress.SetItemText(ilistrow,1,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("性别");
		m_cListAddress.SetItemText(ilistrow,2,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("地址");
		m_cListAddress.SetItemText(ilistrow,8,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("市\/县");
		m_cListAddress.SetItemText(ilistrow,7,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("移动电话");
		m_cListAddress.SetItemText(ilistrow,4,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("省\/市\/自治区");
		m_cListAddress.SetItemText(ilistrow,6,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("邮政编码");
		m_cListAddress.SetItemText(ilistrow,9,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("电子邮件地址");
		m_cListAddress.SetItemText(ilistrow,10,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("固定电话");
		m_cListAddress.SetItemText(ilistrow,5,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		Holder = theApp.m_pADOSet->GetCollect("生日");
		m_cListAddress.SetItemText(ilistrow,3,\
				Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
		theApp.m_pADOSet->MoveNext();
	}
	theApp.m_pADOSet->Close();
	
}

void CAddressBrowse::OnClickAddresslist(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	POSITION pos;
	pos = m_cListAddress.GetFirstSelectedItemPosition();
	m_IndexInFieldList = m_cListAddress.GetNextSelectedItem(pos);

	int iItemCount;
	iItemCount=m_cListAddress.GetItemCount();
	if(iItemCount==0)
	{
		return;
	}
	if(m_IndexInFieldList==-1)
	{
		return;
	}
	
	*pResult = 0;
}

⌨️ 快捷键说明

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