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

📄 333dlg.cpp

📁 vc+access+ado编写的名片管理程序. 适合初学者学习.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 333Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "333.h"
#include "333Dlg.h"
#include "SkinPlusPlus.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy333Dlg dialog

CMy333Dlg::CMy333Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMy333Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMy333Dlg)
	m_name = _T("");
	m_cellphone = _T("");
	m_company = _T("");
	m_fax = _T("");
	m_phone = _T("");
	m_website = _T("");
	m_location = _T("");
	m_shuzi = _T("");
	m_beizhu = _T("");
	m_date = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_flag=FALSE;
	
}

void CMy333Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMy333Dlg)
	DDX_Control(pDX, IDC_LIST2, m_listTest);
	DDX_Text(pDX, IDC_name, m_name);
	DDX_Text(pDX, IDC_cellphone, m_cellphone);
	DDX_Text(pDX, IDC_company, m_company);
	DDX_Text(pDX, IDC_fax, m_fax);
	DDX_Text(pDX, IDC_phone, m_phone);
	DDX_Text(pDX, IDC_website, m_website);
	DDX_Text(pDX, IDC_location, m_location);
	DDX_Text(pDX, IDC_number, m_shuzi);
	DDX_Text(pDX, IDC_beizhu, m_beizhu);
	DDV_MaxChars(pDX, m_beizhu, 200);
	DDX_Text(pDX, IDC_date, m_date);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMy333Dlg, CDialog)
	//{{AFX_MSG_MAP(CMy333Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_add, Onadd)
	ON_BN_CLICKED(IDC_delete, Ondelete)
	ON_BN_CLICKED(IDC_search, Onsearch)
	ON_BN_CLICKED(IDC_clear, Onclear)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST2, OnDblclkList2)
	ON_BN_CLICKED(IDC_exit, Onexit)
	ON_BN_CLICKED(IDC_search2, Onsearch2)
	ON_BN_CLICKED(IDC_uporder, Onuporder)
	ON_NOTIFY(NM_RDBLCLK, IDC_LIST2, OnRdblclkList2)
	ON_BN_CLICKED(IDC_transfer, Ontransfer)
	ON_BN_CLICKED(IDC_skin1, Onskin1)
	ON_BN_CLICKED(IDC_skin2, Onskin2)
	ON_MESSAGE(WM_ITEM_CHANGE,OnChangeOut)
	ON_MESSAGE(WM_ORDER,combo)
	ON_BN_CLICKED(IDC_skin3, Onskin3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy333Dlg message handlers
int i,totalnum=0,nItem;
CString     vname,vage,vcompany,vlocation,vphone,vcellphone,vfax,vwebsite,vdate,vbeizhu,CurrentDate;
_variant_t  var;

BOOL CMy333Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	SetWindowText("名片夹");
	DWORD dw=m_listTest.GetExtendedStyle();
	dw|=LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP;//|LVS_EX_CHECKBOXES;
	m_listTest.SetExtendedStyle(dw); 
	m_pConnection.CreateInstance(__uuidof(Connection));
	try                 
	{	
		m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb","","",adModeUnknown);
	}
	catch(_com_error e)
	{
		MessageBox("数据库连接失败!","警告!!!");
	} 

	m_listTest.InsertColumn(0,"姓名");
	m_listTest.InsertColumn(1,"工作单位");
	m_listTest.InsertColumn(2,"地址");
	m_listTest.InsertColumn(3,"电话");
	m_listTest.InsertColumn(4,"手机");
	m_listTest.InsertColumn(5,"传真");
	m_listTest.InsertColumn(6,"网址");
	m_listTest.InsertColumn(7,"日期");
	m_listTest.InsertColumn(8,"备注");
	m_listTest.SetColumnWidth(0,127);
	m_listTest.SetColumnWidth(1,127);
	m_listTest.SetColumnWidth(2,127);
	m_listTest.SetColumnWidth(3,127);
	m_listTest.SetColumnWidth(4,127);
	m_listTest.SetColumnWidth(5,127);
	m_listTest.SetColumnWidth(6,127);
	m_listTest.SetColumnWidth(7,127);
	m_listTest.SetColumnWidth(8,127);
		
	m_pRecordset.CreateInstance(__uuidof(Recordset));	
	m_pRecordset->Open("SELECT * FROM Images",               
		m_pConnection.GetInterfacePtr(),
		adOpenDynamic,
		adLockOptimistic,
		adCmdText);
	
	show();
	totalnum=i;
	shownum();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMy333Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMy333Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMy333Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}




void CMy333Dlg::Onadd() //往数据库中添加一个人的资料
{
	UpdateData();
	if(m_name!="")
		if(MessageBox("确定要添加 "+m_name+" 么?","提示", MB_OKCANCEL|MB_DEFBUTTON1)==1)
		{
			reconnect();
			m_pRecordset->AddNew();///添加新记录
			m_pRecordset->PutCollect("name",_variant_t(m_name));
			m_pRecordset->PutCollect("company",_variant_t(m_company));
			m_pRecordset->PutCollect("location",_variant_t(m_location));
			m_pRecordset->PutCollect("phone",_variant_t(m_phone));
			m_pRecordset->PutCollect("cellphone",_variant_t(m_cellphone));
			m_pRecordset->PutCollect("fax",_variant_t(m_fax));
			m_pRecordset->PutCollect("website",_variant_t(m_website));
			if(m_date!="") m_pRecordset->PutCollect("date",_variant_t(m_date));
			m_pRecordset->PutCollect("beizhu",_variant_t(m_beizhu));
			m_pRecordset->Update();
			var = m_pRecordset->GetCollect("name");                                                                            
			vname=(LPCSTR)_bstr_t(var);
			var = m_pRecordset->GetCollect("company");
			if(var.vt!=VT_NULL)vcompany=(LPCSTR)_bstr_t(var);//else vcompany="未知";
			var = m_pRecordset->GetCollect("location");
			if(var.vt!=VT_NULL)vlocation=(LPCSTR)_bstr_t(var);//else vlocation="未知";
			var = m_pRecordset->GetCollect("phone");
			if(var.vt!=VT_NULL)vphone=(LPCSTR)_bstr_t(var);//else vphone="未知";
			var = m_pRecordset->GetCollect("cellphone"); 
			if(var.vt!=VT_NULL)vcellphone=(LPCSTR)_bstr_t(var);//else vcellphone="未知";
			var = m_pRecordset->GetCollect("fax");
			if(var.vt!=VT_NULL)vfax=(LPCSTR)_bstr_t(var);//else vfax="未知";
			var = m_pRecordset->GetCollect("website");
			if(var.vt!=VT_NULL)vwebsite=(LPCSTR)_bstr_t(var);//else vwebsite="未知";
			var = m_pRecordset->GetCollect("date");
			if(var.vt!=VT_NULL)vdate=(LPCSTR)_bstr_t(var);//else vbeizhu="未知";
			var = m_pRecordset->GetCollect("beizhu");
			if(var.vt!=VT_NULL)vbeizhu=(LPCSTR)_bstr_t(var);//else vbeizhu="未知";
			m_listTest.InsertItem(i,vname);
			m_listTest.SetItemText(i,1,vcompany);
			m_listTest.SetItemText(i,2,vlocation);
			m_listTest.SetItemText(i,3,vphone);
			m_listTest.SetItemText(i,4,vcellphone);
			m_listTest.SetItemText(i,5,vfax);
			m_listTest.SetItemText(i,6,vwebsite);
			m_listTest.SetItemText(i,7,vdate);
			m_listTest.SetItemText(i,8,vbeizhu);
			m_listTest.Update(true);
			m_name="";m_company="";m_location="";m_phone="";m_cellphone="";m_fax="";m_website="";m_date="";m_beizhu="";
			totalnum++;
			shownum();
		}
		else;
	else
		MessageBox("您起码要填写姓名吧!","友情提醒");  
}

void CMy333Dlg::Ondelete() //删除鼠标选中的人的资料
{
	POSITION pos=m_listTest.GetFirstSelectedItemPosition();
    int index=m_listTest.GetNextSelectedItem(pos);
	CString a=m_listTest.GetItemText(index,0); 
	if(index>=0)
		if(MessageBox("确定要删除 "+a+" 么?",0, MB_OKCANCEL|MB_DEFBUTTON2)==1)
		{
			reconnect();
			m_pRecordset->MoveFirst();
			m_pRecordset->Move(index);
			m_pRecordset->Delete(adAffectCurrent);  // 参数adAffectCurrent为删除当前记录
			m_pRecordset->Update();
			m_listTest.DeleteItem(index);
			totalnum--;
			shownum();
		}
		else;
	else
	{
		MessageBox("请先选中一个人","警告!!!");
	}
}  

void CMy333Dlg::Onsearch() //根据姓名查询某人,找到了就显示,否则显示找不到
{
	search();
	reconnect();
	if(!m_pRecordset->adoEOF)
	{	
		m_tanchu=new tanchu(this);
		m_tanchu->Create(IDD_DIALOG1,this);
		m_tanchu->MoveWindow(100,100,800,470);
		m_tanchu->SendMessage(WM_INIT,0,(long)0);
		m_tanchu->ShowWindow(SW_SHOW);
	}
	else
	{
		MessageBox("没有这个人啊!","警告!!!");
	}
}

void CMy333Dlg::search()//根据姓名在数据库中查询,返回数据库指针
{
	reconnect();
	CString sql="DELETE *FROM show";
	m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText);
	//reconnect();
	UpdateData(true);
	m_pRecordset->MoveFirst();//int j=0;
	int k=0;
	sql="INSERT INTO show SELECT *FROM Images";
	if(m_name!=""){sql=sql+" WHERE name='"+m_name+"'";k=1;}
	if(m_company!="")
	{
		if(!k)
			sql=sql+" WHERE company='"+m_company+"'";
		else
			sql=sql+"AND company='"+m_company+"'";
		k=1;
	}
	if(m_location!="")
	{
		if(!k)
			sql=sql+" WHERE location='"+m_location+"'";
		else
			sql=sql+"AND location='"+m_location+"'";
			k=1;
	}
	if(m_phone!="")
	{
		if(!k)
			sql=sql+" WHERE phone='"+m_phone+"'";
		else
			sql=sql+"AND phone='"+m_phone+"'";
		k=1;
	}
	if(m_cellphone!="")
	{
		if(!k)
			sql=sql+" WHERE cellphone='"+m_cellphone+"'";
		else
			sql=sql+"AND cellphone='"+m_cellphone+"'";
		k=1;
	}
	if(m_fax!="")
	{
		if(!k)
			sql=sql+" WHERE fax='"+m_fax+"'";
		else
			sql=sql+"AND fax='"+m_fax+"'";
		k=1;
	}
	if(m_website!="")
	{
		if(!k)
			sql=sql+" WHERE website='"+m_website+"'";
		else
			sql=sql+"AND website='"+m_website+"'";
		k=1;
	}
	if(m_date!="")
	{
		if(!k)
			sql=sql+" WHERE date=#"+m_date+"#";
		else
			sql=sql+"AND date=#"+m_date+"#";
		k=1;
	}
	if(m_beizhu!="")
	{
		if(!k)
			sql=sql+" WHERE beizhu='"+m_beizhu+"'";

⌨️ 快捷键说明

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