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

📄 dmessage.cpp

📁 功能描述: 1、快速添加、修改、删除客户信息。 2、直观方便的地域信息管理功能
💻 CPP
字号:
// DMessage.cpp : implementation file
//

#include "stdafx.h"
#include "源程序.h"
#include "DMessage.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "RainFunction.h"
extern _ConnectionPtr cnn;
/////////////////////////////////////////////////////////////////////////////
// CDMessage dialog


CDMessage::CDMessage(CWnd* pParent /*=NULL*/)
	: CDialog(CDMessage::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDMessage)
	//}}AFX_DATA_INIT
}


void CDMessage::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDMessage)
	DDX_Control(pDX, IDC_ComDuty, m_ComDuty);
	DDX_Control(pDX, IDC_COMUnit, m_ComUnit);
	DDX_Control(pDX, IDC_SLIDER, m_Slider);
	DDX_Control(pDX, IDC_EDTPhone, m_EdtPhone);
	DDX_Control(pDX, IDC_EDTName, m_EdtName);
	DDX_Control(pDX, IDC_EDTIDCard, m_EdtCard);
	DDX_Control(pDX, IDC_EdtID, m_EdtID);
	DDX_Control(pDX, IDC_EDTAddr, m_EdtAddr);
	DDX_Control(pDX, IDC_COMTown, m_ComTown);
	DDX_Control(pDX, IDC_COMSex, m_ComSex);
	DDX_Control(pDX, IDC_COMProvince, m_ComProvince);
	DDX_Control(pDX, IDC_COMCity, m_ComCity);
	DDX_Control(pDX, IDC_BUTUnDo, m_ButUndo);
	DDX_Control(pDX, IDC_BUTSave, m_ButSave);
	DDX_Control(pDX, IDC_BUTEXIT, m_ButExit);
	DDX_Control(pDX, IDC_BUTDELETE, m_ButDele);
	DDX_Control(pDX, IDC_BUTChange, m_ButChange);
	DDX_Control(pDX, IDC_BUTADD, m_ButAdd);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDMessage, CDialog)
	//{{AFX_MSG_MAP(CDMessage)
	ON_BN_CLICKED(IDC_BUTADD, OnButadd)
	ON_CBN_KILLFOCUS(IDC_COMUnit, OnKillfocusCOMUnit)
	ON_CBN_KILLFOCUS(IDC_COMProvince, OnKillfocusCOMProvince)
	ON_CBN_KILLFOCUS(IDC_COMCity, OnKillfocusCOMCity)
	ON_BN_CLICKED(IDC_BUTChange, OnBUTChange)
	ON_BN_CLICKED(IDC_BUTDELETE, OnButdelete)
	ON_BN_CLICKED(IDC_BUTSave, OnBUTSave)
	ON_BN_CLICKED(IDC_BUTUnDo, OnBUTUnDo)
	ON_BN_CLICKED(IDC_BUTEXIT, OnButexit)
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER, OnReleasedcaptureSlider)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDMessage message handlers

void CDMessage::OnOK() 
{
	// TODO: Add extra validation here
	
	//CDialog::OnOK();
}

void CDMessage::ClearForm()
{
	m_ComUnit.SetWindowText("");
	m_EdtPhone.SetWindowText("");
	m_EdtName.SetWindowText("");
	m_EdtCard.SetWindowText("");
	m_EdtID.SetWindowText("");
	m_ComDuty.SetWindowText("");
	m_EdtAddr.SetWindowText("");
	m_ComTown.SetWindowText("");
	m_ComSex.SetWindowText("");
	m_ComProvince.SetWindowText("");
	m_ComCity.SetWindowText("");
}
int CDMessage::Clime(int Number)
{
	_RecordsetPtr ClimeRst;
	ClimeRst.CreateInstance(__uuidof(Recordset));
	CString sSQL,Style,Name,ParentID;
	int ReturnNumber;
	sSQL.Format("Select * from 地域信息表 Where 编号=%d",Number);
	ClimeRst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
	if(function.RecordCount(ClimeRst)>0)
	{
		ClimeRst->MoveFirst();
		Style=(char*)(_bstr_t)ClimeRst->GetCollect("类型");
		Name=(char*)(_bstr_t)ClimeRst->GetCollect("名称");
		ParentID=(char*)(_bstr_t)ClimeRst->GetCollect("上级编号");
		if(Style=="3")
			this->m_ComTown.SetWindowText(Name);
		if(Style=="2")
			this->m_ComCity.SetWindowText(Name);
		if(Style=="1")
			this->m_ComProvince.SetWindowText(Name);
		if(ParentID!="0")
		{
			ReturnNumber=atoi(ParentID);
			this->Clime(ReturnNumber);
		}
		else
		{
			ReturnNumber=0;
		}
	}
	return ReturnNumber;
}


void CDMessage::Enabled(bool bstyle)
{
	m_ComUnit.EnableWindow(!bstyle);
	m_EdtPhone.EnableWindow(!bstyle);
	m_EdtName.EnableWindow(!bstyle);
	m_EdtCard.EnableWindow(!bstyle);
	m_ComDuty.EnableWindow(!bstyle);
	m_EdtAddr.EnableWindow(!bstyle);
	m_ComTown.EnableWindow(!bstyle);
	m_ComSex.EnableWindow(!bstyle);
	m_ComProvince.EnableWindow(!bstyle);
	m_ComCity.EnableWindow(!bstyle);
	m_ButUndo.EnableWindow(!bstyle);
	m_ButSave.EnableWindow(!bstyle);
	m_ButExit.EnableWindow(bstyle);
	m_ButDele.EnableWindow(bstyle);
	m_ButChange.EnableWindow(bstyle);
	m_ButAdd.EnableWindow(bstyle);	
	m_Slider.EnableWindow(bstyle);
}

void CDMessage::Display()
{
	_variant_t ID,Name,Unit,Town,Duty,Sex,Phone,Addr,IDCard;
	ID=rst->GetCollect("编号");
	if(ID.vt==VT_EMPTY)
		sID="";
	else
		sID=(char*)(_bstr_t)ID;
	Name=rst->GetCollect("姓名");
	if(Name.vt==VT_EMPTY)
		sName="";
	else
		sName=(char*)(_bstr_t)Name;
	Unit=rst->GetCollect("单位");
	if(Unit.vt==VT_EMPTY)
		sUnit="";
	else
		sUnit=(char*)(_bstr_t)Unit;
	Town=rst->GetCollect("地域");
	if(Town.vt==VT_EMPTY)
		sTown="";
	else
		sTown=(char*)(_bstr_t)Town;
	Duty=rst->GetCollect("职务");
	if(Duty.vt==VT_EMPTY)
		sDuty="";
	else
		sDuty=(char*)(_bstr_t)Duty;
	Sex=rst->GetCollect("性别");
	if(Sex.vt==VT_EMPTY)
		sSex="";
	else
		sSex=(char*)(_bstr_t)Sex;
	Phone=rst->GetCollect("联系电话");
	if(Phone.vt==VT_EMPTY)
		sPhone="";
	else
		sPhone=(char*)(_bstr_t)Phone;
	Addr=rst->GetCollect("家庭住址");
	if(Addr.vt==VT_EMPTY)
		sAddr="";
	else
		sAddr=(char*)(_bstr_t)Addr;
	IDCard=rst->GetCollect("身份证号");
	if(IDCard.vt==VT_EMPTY)
		sIDCard="";
	else
		sIDCard=(char*)(_bstr_t)IDCard;
	
	m_EdtID.SetWindowText(sID);
	m_EdtName.SetWindowText(sName);
	m_ComUnit.SetWindowText(sUnit);
	m_ComDuty.SetWindowText(sDuty);
	m_ComSex.SetWindowText(sSex);
	m_EdtPhone.SetWindowText(sPhone);
	m_EdtAddr.SetWindowText(sAddr);
	m_EdtCard.SetWindowText(sIDCard);
	int nTown=function.NumberTOName("地域信息表","名称",sTown);
	this->Clime(nTown);

}

BOOL CDMessage::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CString sSQL;
	rst.CreateInstance(__uuidof(Recordset));

	sSQL.Format("SELECT * From 地域信息表  WHERE 类型=1");
	rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
	this->m_ComProvince.record=rst;
	m_ComProvince.DateBaseName="地域信息表";
	m_ComProvince.IDStyle=1;
	m_ComProvince.Init("名称");
	rst->Close();

	sSQL.Format("SELECT * From 地域信息表  WHERE 类型=2");
	rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
	this->m_ComCity.record=rst;
	m_ComCity.DateBaseName="地域信息表";
	m_ComCity.IDStyle=1;
	m_ComCity.Init("名称");
	rst->Close();

	sSQL.Format("SELECT * From 地域信息表  WHERE 类型=3");
	rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
	this->m_ComTown.record=rst;			
	m_ComTown.DateBaseName="地域信息表";
	m_ComTown.IDStyle=1;
	m_ComTown.Init("名称");
	rst->Close();
	
	rst=cnn->Execute((_bstr_t)"客户职务表",NULL,adCmdTable);
	this->m_ComDuty.record=rst;			
	m_ComDuty.DateBaseName="客户职务表";
	m_ComDuty.IDStyle=1;
	m_ComDuty.Init("名称");
	rst->Close();

	rst=cnn->Execute((_bstr_t)"客户单位信息表",NULL,adCmdTable);
	this->m_ComUnit.record=rst;			
	m_ComUnit.DateBaseName="客户单位信息表";
	m_ComUnit.IDStyle=2;
	m_ComUnit.Init("名称");
	rst->Close();

	rst=cnn->Execute((_bstr_t)"客户通讯查询",NULL,adCmdTable);
	
	if(function.RecordCount(rst)>0)
	{
		this->m_Slider.Recordset=rst;
		this->m_Slider.Init();
	}
	
	//设置文本框验证
	m_ComUnit.EmptyValidate=true;
	m_EdtName.EmptyValidate=true;
	m_EdtCard.EmptyValidate=true;
	m_ComDuty.EmptyValidate=true;
	m_EdtAddr.EmptyValidate=true;
	m_ComTown.EmptyValidate=true;
	if(function.RecordCount(rst)>0)
	{
		rst->MoveFirst();
		this->Display();
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDMessage::OnButadd() 
{
	CString ID;
	this->ClearForm();
	ID=function.AutoNumber("客户通讯表","TX",1);
	this->m_EdtID.SetWindowText(ID);
	this->Enabled(false);
	this->AddOrChange=true;
	this->m_EdtName.SetFocus();
}



void CDMessage::OnKillfocusCOMUnit() 
{
	_RecordsetPtr UnitRst,DutyRst;
	CString sSQL,Name,Sort;
	UnitRst.CreateInstance(__uuidof(Recordset));
	DutyRst.CreateInstance(__uuidof(Recordset));
	m_ComDuty.ResetContent();
	m_ComUnit.GetWindowText(Name);
	sSQL.Format("SELECT * From 客户单位信息表  WHERE 名称='%s'",Name);
	UnitRst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
	if(function.RecordCount(UnitRst)>0)
	{
		UnitRst->MoveFirst();
		Sort=(char*)(_bstr_t)UnitRst->GetCollect("客户类别");
		sSQL.Format("SELECT * From 客户职务表  WHERE 客户类别=%s",Sort);
		DutyRst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
		this->m_ComDuty.record=DutyRst;
		m_ComDuty.DateBaseName="客户职务表";	
		m_ComDuty.Init("名称");
		if(this->OK==false)
		{
			this->OK=true;
			m_ComUnit.SetFocus();		
			m_ComDuty.SetFocus();
		}
		else
			this->OK=false;
		DutyRst->Close();
		UnitRst->Close();
	}
}

void CDMessage::OnKillfocusCOMProvince() 
{
	_RecordsetPtr CityRst;
	CString sSQL;
	CityRst.CreateInstance(__uuidof(Recordset));
	m_ComCity.ResetContent();
	sSQL.Format("SELECT * From 地域信息表  WHERE 上级编号=%d",m_ComProvince.Recno);
	CityRst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
	this->m_ComCity.record=CityRst;
	m_ComCity.DateBaseName="地域信息表";	
	m_ComCity.Init("名称");
	CityRst->Close();
	if(this->OK==false)
	{
		this->OK=true;
		m_ComProvince.SetFocus();		
		m_ComCity.SetFocus();
	}
	else
		this->OK=false;
	
}

void CDMessage::OnKillfocusCOMCity() 
{
	_RecordsetPtr TownRst;
	CString sSQL;
	TownRst.CreateInstance(__uuidof(Recordset));
	m_ComTown.ResetContent();
	sSQL.Format("SELECT * From 地域信息表  WHERE 上级编号=%d",m_ComCity.Recno);
	TownRst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
	this->m_ComTown.record=TownRst;
	m_ComTown.DateBaseName="地域信息表";	
	m_ComTown.Init("名称");
	TownRst->Close();
	if(this->OK==false)
	{
		this->OK=true;
		m_ComCity.SetFocus();		
		m_ComTown.SetFocus();
	}
	else
		this->OK=false;	
}

void CDMessage::OnBUTChange() 
{
	this->AddOrChange=false;
	this->Enabled(false);
	this->m_EdtName.SetFocus();
	this->m_ComTown.SetWindowText("");
	this->m_ComDuty.SetWindowText("");
	this->m_ComUnit.SetWindowText("");	
}

void CDMessage::OnButdelete() 
{
	CString sSQL,ID;
	this->m_EdtID.GetWindowText(ID);
	int a=MessageBox("确定要删除此条记录?","系统提示",MB_OKCANCEL|MB_ICONQUESTION);
	if(a==1)
	{
		sSQL.Format("Delete from 客户通讯表 Where 编号='%s'",ID);
		cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
		m_Slider.Init();
		this->Enabled(true);
	}
}

void CDMessage::OnBUTSave() 
{
	CString ID,Name,Unit,Town,Duty,Sex,Phone,Addr,IDCard,sSQL;
	int nDuty,nTown;
	int a=MessageBox("确定要保存记录吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION);
	if(a==1)
	{
		m_EdtID.GetWindowText(ID);
		m_EdtName.GetWindowText(Name);
		m_EdtPhone.GetWindowText(Phone);
		m_EdtAddr.GetWindowText(Addr);
		m_EdtCard.GetWindowText(IDCard);
		m_ComSex.GetWindowText(Sex);
		Unit=m_ComUnit.sID;
		if(Unit=="" ||Unit=="--")
		{
			MessageBox("请选择所在单位!","系统提示",MB_OK|MB_ICONSTOP);
			m_ComUnit.SetFocus();
			return;
		}
		m_ComDuty.GetWindowText(Duty);
		if(Duty=="" ||Duty=="--")
		{
			MessageBox("请选择所在职务!","系统提示",MB_OK|MB_ICONSTOP);
			m_ComDuty.SetFocus();
			return;
		}
		m_ComTown.GetWindowText(Town);
		if(Town=="" || Town=="--")
		{
			MessageBox("请添入所在区/镇!","系统提示",MB_OK|MB_ICONSTOP);
			m_ComTown.SetFocus();
			return;
		}
		nDuty=m_ComDuty.Recno;
		nTown=m_ComTown.Recno;
		if(this->AddOrChange==true)
			sSQL.Format("Insert into 客户通讯表 values('%s','%s','%s','%s',%d,'%s',%d,'%s','%s')",ID,Unit,Name,Sex,nDuty,Phone,nTown,Addr,IDCard);
		else
			sSQL.Format("Update 客户通讯表 SET 单位编号='%s',姓名='%s',性别='%s',职务编号=%d,联系电话='%s',地域编号=%d,家庭住址='%s',身份证号='%s' Where 编号='%s'",Unit,Name,Sex,nDuty,Phone,nTown,Addr,IDCard,ID);
		cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
		m_Slider.Init();
		this->Enabled(true);
	}
	
}

BOOL CDMessage::PreTranslateMessage(MSG* pMsg) 
{
	function.CMessage(this,pMsg,&m_ComSex,&m_ComDuty);
	function.CMessage(this,pMsg,&m_ComDuty,&m_ComProvince);
	return CDialog::PreTranslateMessage(pMsg);
}




void CDMessage::OnBUTUnDo() 
{
	int a=MessageBox("确定要撤消操作吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION);
	if(a==1)
	{
		rst->MoveFirst();
		this->Display();
		this->Enabled(true);
	}
}

void CDMessage::OnButexit() 
{
	this->OnCancel();	
}

void CDMessage::OnReleasedcaptureSlider(NMHDR* pNMHDR, LRESULT* pResult) 
{
	if(function.RecordCount(rst)>0)
	{
		rst->MoveFirst();
		rst->Move(this->m_Slider.GetPos()-1);
		this->Display();
	}
	
	*pResult = 0;
}

⌨️ 快捷键说明

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