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

📄 333dlg.cpp

📁 vc+access+ado编写的名片管理程序. 适合初学者学习.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		else
			sql=sql+"AND beizhu='"+m_beizhu+"'";
		k=1;
	}
	m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText); 
}


void CMy333Dlg::show()//将数据库中内容显示到CListCtrl中
{
	i=0;
	m_listTest.DeleteAllItems(); 
	reconnect();
	m_pRecordset->MoveFirst();
	while(!m_pRecordset->adoEOF)//当表还未结束                                                     			
	{			                
		vname="";vcompany="";vlocation="";vphone="";vcellphone="";vfax="";vwebsite="";vdate="";vbeizhu="";
		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);
		var = m_pRecordset->GetCollect("location");
		if(var.vt!=VT_NULL)vlocation=(LPCSTR)_bstr_t(var);
		var = m_pRecordset->GetCollect("phone");
		if(var.vt!=VT_NULL)vphone=(LPCSTR)_bstr_t(var);
		var = m_pRecordset->GetCollect("cellphone");
		if(var.vt!=VT_NULL)vcellphone=(LPCSTR)_bstr_t(var);
		var = m_pRecordset->GetCollect("fax");
		if(var.vt!=VT_NULL)vfax=(LPCSTR)_bstr_t(var);
		var = m_pRecordset->GetCollect("website");
		if(var.vt!=VT_NULL)vwebsite=(LPCSTR)_bstr_t(var);
		var = m_pRecordset->GetCollect("date");
		if(var.vt!=VT_NULL)vdate=(LPCSTR)_bstr_t(var);
		var = m_pRecordset->GetCollect("beizhu");
		if(var.vt!=VT_NULL)vbeizhu=(LPCSTR)_bstr_t(var);
		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_pRecordset->MoveNext();//指向下一个数据
		i++;
	}
}

void CMy333Dlg::Onclear() //清空EDIT控件中的内容
{
	m_name="";m_company="";m_location="";m_phone="";m_cellphone="";m_fax="";m_website="";m_date="";m_beizhu="";
	UpdateData(false);
}



void CMy333Dlg::OnDblclkList2(NMHDR* pNMHDR, LRESULT* pResult) //显示双击的CListCtrl的信息
{
    int iOption;
    iOption=m_listTest.GetSelectedCount(); //得到当前选中的行
    POSITION pos=m_listTest.GetFirstSelectedItemPosition(); //如果选中一行
    if(pos)
    {        
        nItem = m_listTest.GetNextSelectedItem(pos);
        m_name=m_listTest.GetItemText(nItem,0); 
        m_company=m_listTest.GetItemText(nItem,1);
		m_location=m_listTest.GetItemText(nItem,2); 
        m_phone=m_listTest.GetItemText(nItem,3);
		m_cellphone=m_listTest.GetItemText(nItem,4); 
        m_fax=m_listTest.GetItemText(nItem,5);
		m_website=m_listTest.GetItemText(nItem,6);
		m_date=m_listTest.GetItemText(nItem,7);
		m_beizhu=m_listTest.GetItemText(nItem,8);
		
		m_shuru=new shuru(this);
		m_shuru->Create(IDD_DIALOG2,this);
		m_shuru->MoveWindow(100,100,750,300);
		m_shuru->SendMessage(WM_Change,0,(long)0);
		m_shuru->ShowWindow(SW_SHOW);
		
        //*pResult = 0;  
    }
}

void CMy333Dlg::OnRdblclkList2(NMHDR* pNMHDR, LRESULT* pResult) //显示双击的CListCtrl的信息
{
	CString a,b,c,d,e,f,g; //定义获得的信息名称
    int iOption;

    iOption = m_listTest.GetSelectedCount(); //得到当前选中的行
    POSITION pos = m_listTest.GetFirstSelectedItemPosition(); //如果选中一行
    if(pos)
    {        
        nItem = m_listTest.GetNextSelectedItem(pos);
        m_name=m_listTest.GetItemText(nItem,0); 
        m_company=m_listTest.GetItemText(nItem,1);
		m_location=m_listTest.GetItemText(nItem,2); 
        m_phone=m_listTest.GetItemText(nItem,3);
		m_cellphone=m_listTest.GetItemText(nItem,4); 
        m_fax=m_listTest.GetItemText(nItem,5);
		m_website=m_listTest.GetItemText(nItem,6);
		m_date=m_listTest.GetItemText(nItem,7);
		m_beizhu=m_listTest.GetItemText(nItem,8);
		MessageBox("Name:  "+m_name+"                              "+"\n\nCompany:  "+m_company+"\n\nLocation:  "+m_location+"\n\nPhone:  "+m_phone
						+"\n\nCellphone:  "+m_cellphone+"\n\nFax:  "+m_fax+"\n\nWebsite:  "+m_website+"\n\nDate:  "+m_date+"\n\nComment:  "+m_beizhu,"个人信息");
		
        *pResult = 0;  
    }
}

void CMy333Dlg::Onexit() //退出按钮
{
	m_pRecordset->Close();
	m_pConnection->Close();
	exit(0);
}


BOOL CMy333Dlg::PreTranslateMessage(MSG* pMsg)//当按ESC时程序不退出
{
	if(pMsg->wParam==VK_ESCAPE) 
		return TRUE;    // 封掉ESC按键的消息
	return CDialog::PreTranslateMessage(pMsg);
} 




 void CMy333Dlg::shownum()
 {
	m_shuzi.Format("您的名片簿里有%d人",totalnum);
	UpdateData(false);
 }



void CMy333Dlg::OnChangeOut(WPARAM wParam, LPARAM lParam)
{
		try
		{
			reconnect();
			m_pRecordset->MoveFirst();
			m_pRecordset->Move(nItem);
			m_pRecordset->PutCollect("name", _variant_t(m_shuru->m_nam));
			m_pRecordset->PutCollect("company",_variant_t(m_shuru->m_com));
			m_pRecordset->PutCollect("location", _variant_t(m_shuru->m_ad));
			m_pRecordset->PutCollect("phone",_variant_t(m_shuru->m_tel));
			m_pRecordset->PutCollect("cellphone", _variant_t(m_shuru->m_cphone));
			m_pRecordset->PutCollect("fax",_variant_t(m_shuru->m_fa));
			m_pRecordset->PutCollect("website", _variant_t(m_shuru->m_web));
			m_pRecordset->PutCollect("date", _variant_t(m_shuru->m_dat));
			m_pRecordset->PutCollect("beizhu", _variant_t(m_shuru->m_bei));
			m_pRecordset->Update();
			m_listTest.SetItemText(nItem,0,m_shuru->m_nam);
			m_listTest.SetItemText(nItem,1,m_shuru->m_com);
			m_listTest.SetItemText(nItem,2,m_shuru->m_ad);
			m_listTest.SetItemText(nItem,3,m_shuru->m_tel);
			m_listTest.SetItemText(nItem,4,m_shuru->m_cphone);
			m_listTest.SetItemText(nItem,5,m_shuru->m_fa);
			m_listTest.SetItemText(nItem,6,m_shuru->m_web);
			m_listTest.SetItemText(nItem,7,m_shuru->m_dat);
			m_listTest.SetItemText(nItem,8,m_shuru->m_bei);
		}
		catch(_com_error *e)
		{
			MessageBox("出现了意外错误!","警告!!!");
		}      
}

void CMy333Dlg::Onsearch2() 
{
	reconnect();
	CString sql="DELETE *FROM show";
	m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText);
	
	UpdateData(true);
	m_pRecordset->MoveFirst();
 	int k=0;
	sql="INSERT INTO show SELECT *FROM Images";
	if(m_name!=""){sql=sql+" WHERE name like '%"+m_name+"%'";k=1;}
	if(m_company!="")
	{
		if(!k)
			sql=sql+" WHERE company like '%"+m_company+"%'";
		else
			sql=sql+"AND company like '%"+m_company+"%'";
		k=1;
	}
	if(m_location!="")
	{
		if(!k)
			sql=sql+" WHERE location like '%"+m_location+"%'";
		else
			sql=sql+"AND location like '%"+m_location+"%'";
			k=1;
	}
	if(m_phone!="")
	{
		if(!k)
			sql=sql+" WHERE phone like '%"+m_phone+"%'";
		else
			sql=sql+"AND phone like '%"+m_phone+"%'";
		k=1;
	}
	if(m_cellphone!="")
	{
		if(!k)
			sql=sql+" WHERE cellphone like '%"+m_cellphone+"%'";
		else
			sql=sql+"AND cellphone like '%"+m_cellphone+"%'";
		k=1;
	}
	if(m_fax!="")
	{
		if(!k)
			sql=sql+" WHERE fax like '%"+m_fax+"%'";
		else
			sql=sql+"AND fax like '%"+m_fax+"%'";
		k=1;
	}
	if(m_website!="")
	{
		if(!k)
			sql=sql+" WHERE website like '%"+m_website+"%'";
		else
			sql=sql+"AND website like '%"+m_website+"%'";
		k=1;
	}
	if(m_date!="")
	{
		if(!k)
			sql=sql+" WHERE date like '%"+m_date+"%'";
		else
			sql=sql+"AND date like '%"+m_date+"%'";
		k=1;
	}
	if(m_beizhu!="")
	{
		if(!k)
			sql=sql+" WHERE beizhu like '%"+m_beizhu+"%'";
		else
			sql=sql+"AND beizhu like '%"+m_beizhu+"%'";
		k=1;
	}
	m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText); 
	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::Onuporder() 
{
	m_order=new order(this);
	m_order->Create(IDD_DIALOG3,this);
	m_order->MoveWindow(100,100,400,230);
	m_order->m_combo1.SetWindowText("name");
	m_order->m_combo2.SetWindowText("company");
	m_order->m_combo3.SetWindowText("location");
	m_order->m_combo4.SetWindowText("升序");
	m_order->ShowWindow(SW_SHOW);
}


void CMy333Dlg::combo(WPARAM wParam, LPARAM lParam)
{
		reconnect();
		CString sql="",str;int flag=0;
		sql="DELETE *FROM show";
		m_order->m_combo4.GetWindowText(str);
		if(str=="降序")	{flag=1;}
		m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText); 
		sql="INSERT INTO show SELECT *FROM Images ORDER BY ";
		m_order->m_combo1.GetWindowText(str);
		if(!flag)
			sql=sql+str;
		else
			sql=sql+str+" DESC";
		m_order->m_combo2.GetWindowText(str);
		if(!flag)
			sql=sql+","+str+",";
		else
			sql=sql+","+str+" DESC,";
		m_order->m_combo3.GetWindowText(str);
		if(!flag)
			sql=sql+str;
		else
			sql=sql+str+" DESC";
		m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText); 
		sql="DELETE *FROM Images";
		m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText); 
		sql="INSERT INTO Images SELECT *FROM show";
		m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText); 
		sql="DELETE *FROM show";
		m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText); 
		show();
}




void CMy333Dlg::Ontransfer() 
{
	if(MessageBox("请确定您要添加的数据库文件在程序运行的目录下,并起名为exdb.mdb","提示", MB_OKCANCEL|MB_DEFBUTTON1)==1)
	{
		reconnect();
		m_pConnection3.CreateInstance(__uuidof(Connection));
		try                 
		{	
			m_pConnection3->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=exdb.mdb","","",adModeUnknown);
		}
		catch(_com_error e)
		{
			MessageBox("数据库连接失败!","警告!!!");
		} 
		m_pRecordset1.CreateInstance(__uuidof(Recordset));	
		m_pRecordset1->Open("SELECT * FROM Images",               
			m_pConnection3.GetInterfacePtr(),
			adOpenDynamic,
			adLockOptimistic,
			adCmdText);

		m_pRecordset1->MoveFirst();
	while(!m_pRecordset1->adoEOF)
	{
		vname="";vcompany="";vlocation="";vphone="";vcellphone="";vfax="";vwebsite="";vdate="";vbeizhu="";
		var = m_pRecordset1->GetCollect("name");                                                                            
		vname=(LPCSTR)_bstr_t(var);
		var = m_pRecordset1->GetCollect("company");
		if(var.vt!=VT_NULL)vcompany=(LPCSTR)_bstr_t(var);
		var = m_pRecordset1->GetCollect("location");
		if(var.vt!=VT_NULL)vlocation=(LPCSTR)_bstr_t(var);
		var = m_pRecordset1->GetCollect("phone");
		if(var.vt!=VT_NULL)vphone=(LPCSTR)_bstr_t(var);
		var = m_pRecordset1->GetCollect("cellphone");
		if(var.vt!=VT_NULL)vcellphone=(LPCSTR)_bstr_t(var);
		var = m_pRecordset1->GetCollect("fax");
		if(var.vt!=VT_NULL)vfax=(LPCSTR)_bstr_t(var);
		var = m_pRecordset1->GetCollect("website");
		if(var.vt!=VT_NULL)vwebsite=(LPCSTR)_bstr_t(var);
		var = m_pRecordset1->GetCollect("date");
		if(var.vt!=VT_NULL)vdate=(LPCSTR)_bstr_t(var);
		var = m_pRecordset1->GetCollect("beizhu");
		if(var.vt!=VT_NULL)vbeizhu=(LPCSTR)_bstr_t(var);

		m_pRecordset->AddNew();
		m_pRecordset->PutCollect("name", _variant_t(vname));
		m_pRecordset->PutCollect("company",_variant_t(vcompany));
		m_pRecordset->PutCollect("location", _variant_t(vlocation));
		m_pRecordset->PutCollect("phone",_variant_t(vphone));
		m_pRecordset->PutCollect("cellphone", _variant_t(vcellphone));
		m_pRecordset->PutCollect("fax",_variant_t(vfax));
		m_pRecordset->PutCollect("website", _variant_t(vwebsite));
		m_pRecordset->PutCollect("date", _variant_t(vdate));
		m_pRecordset->PutCollect("beizhu", _variant_t(vbeizhu));
		m_pRecordset->Update();

		m_pRecordset1->MoveNext();
	}
		CString sql;
		sql="DELETE *FROM show";
		m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText); 
		sql="INSERT INTO show SELECT DISTINCT name,company,location,phone,cellphone,fax,website,date,beizhu FROM Images";
		m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText); 
		sql="DELETE *FROM Images";
		m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText); 
		sql="INSERT INTO Images SELECT *FROM show";
		m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText); 
		sql="DELETE *FROM show";
		m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText); 
		show();
		m_pRecordset1->Close();
		m_pConnection3->Close();
	}
}

void CMy333Dlg::reconnect()
{
	m_pRecordset->Close();m_pConnection->Close();
	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_pRecordset.CreateInstance(__uuidof(Recordset));	
	m_pRecordset->Open("SELECT * FROM Images",               
		m_pConnection.GetInterfacePtr(),
		adOpenDynamic,
		adLockOptimistic,
		adCmdText);
}

void CMy333Dlg::Onskin1() 
{
	// TODO: Add your control notification handler code here
	LoadSkin(_T("XPCorona.ssk"));
}

void CMy333Dlg::Onskin2() 
{
	// TODO: Add your control notification handler code here
	LoadSkin(_T("SoftCrystal.ssk"));
}

void CMy333Dlg::Onskin3() 
{
	// TODO: Add your control notification handler code here
	LoadSkin(_T("Minimized.ssk"));
}

⌨️ 快捷键说明

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