📄 unit.cpp
字号:
// Unit.cpp : implementation file
//
#include "stdafx.h"
#include "源程序.h"
#include "Unit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr cnn;
/////////////////////////////////////////////////////////////////////////////
// CUnit dialog
CUnit::CUnit(CWnd* pParent /*=NULL*/)
: CDialog(CUnit::IDD, pParent)
{
//{{AFX_DATA_INIT(CUnit)
//}}AFX_DATA_INIT
}
void CUnit::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUnit)
DDX_Control(pDX, IDC_SLIDER1, m_Slider);
DDX_Control(pDX, IDC_BUTDele, m_ButDele);
DDX_Control(pDX, IDC_BUTChange, m_ButChange);
DDX_Control(pDX, IDC_COMSort, m_ComSort);
DDX_Control(pDX, IDC_EDTPhone, m_EdtPhone);
DDX_Control(pDX, IDC_EDTName, m_EdtName);
DDX_Control(pDX, IDC_EDTLetterName, m_EdtLetterName);
DDX_Control(pDX, IDC_EdtID, m_EdtID);
DDX_Control(pDX, IDC_EDTFax, m_EdtFax);
DDX_Control(pDX, IDC_EDTAddr, m_EdtAddr);
DDX_Control(pDX, IDC_COMTown, m_ComTown);
DDX_Control(pDX, IDC_COMProvince, m_ComProvince);
DDX_Control(pDX, IDC_COMCity, m_ComCity);
DDX_Control(pDX, IDC_BUTSave, m_ButSave);
DDX_Control(pDX, IDC_BUTEXIT, m_ButExit);
DDX_Control(pDX, IDC_ButCencel, m_ButCencel);
DDX_Control(pDX, IDC_BUTADD, m_ButAdd);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUnit, CDialog)
//{{AFX_MSG_MAP(CUnit)
ON_BN_CLICKED(IDC_BUTEXIT, OnButexit)
ON_CBN_KILLFOCUS(IDC_COMProvince, OnKillfocusCOMProvince)
ON_CBN_KILLFOCUS(IDC_COMCity, OnKillfocusCOMCity)
ON_BN_CLICKED(IDC_BUTADD, OnButadd)
ON_BN_CLICKED(IDC_BUTChange, OnBUTChange)
ON_BN_CLICKED(IDC_BUTSave, OnBUTSave)
ON_EN_CHANGE(IDC_EDTName, OnChangeEDTName)
ON_BN_CLICKED(IDC_ButCencel, OnButCencel)
ON_BN_CLICKED(IDC_BUTDele, OnBUTDele)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER1, OnReleasedcaptureSlider1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUnit message handlers
void CUnit::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
void CUnit::OnButexit()
{
this->OnCancel();
}
BOOL CUnit::OnInitDialog()
{
CDialog::OnInitDialog();
CString sSQL;
rst.CreateInstance(__uuidof(Recordset));
rst=cnn->Execute((_bstr_t)"客户单位查询",NULL,adCmdTable);
ProvinceRst.CreateInstance(__uuidof(Recordset));
sSQL.Format("SELECT * From 地域信息表 WHERE 类型=1");
ProvinceRst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
this->m_ComProvince.record=ProvinceRst;
m_ComProvince.DateBaseName="地域信息表";
m_ComProvince.IDStyle=1;
m_ComProvince.Init("名称");
ProvinceRst->Close();
CityRst.CreateInstance(__uuidof(Recordset));
sSQL.Format("SELECT * From 地域信息表 WHERE 类型=2");
CityRst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
this->m_ComCity.record=CityRst;
m_ComCity.DateBaseName="地域信息表";
m_ComCity.Init("名称");
m_ComCity.IDStyle=1;
CityRst->Close();
TownRst.CreateInstance(__uuidof(Recordset));
sSQL.Format("SELECT * From 地域信息表 WHERE 类型=3");
TownRst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
this->m_ComTown.record=TownRst;
m_ComTown.DateBaseName="地域信息表";
m_ComTown.IDStyle=1;
m_ComTown.Init("名称");
TownRst->Close();
ProvinceRst.CreateInstance(__uuidof(Recordset));;
ProvinceRst=cnn->Execute((_bstr_t)"客户类别表",NULL,adCmdTable);
this->m_ComSort.record=ProvinceRst;
m_ComSort.DateBaseName="客户类别表";
m_ComSort.IDStyle=1;
m_ComSort.Init("名称");
ProvinceRst->Close();
if(function.RecordCount(rst)>0)
{
this->m_Slider.Recordset=rst;
this->m_Slider.Init();
}
//设置文本框验证
m_EdtName.EmptyValidate=true;
m_EdtLetterName.EmptyValidate=true;
m_EdtAddr.EmptyValidate=true;
m_ComSort.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 CUnit::OnKillfocusCOMProvince()
{
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 CUnit::OnKillfocusCOMCity()
{
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 CUnit::OnButadd()
{
CString ID;
this->Enabled(false);
this->AddOrChange=true;
this->ClearFrom();
ID=function.AutoNumber("客户单位信息表","KH",1);
m_EdtID.SetWindowText(ID);
m_EdtName.SetFocus();
}
void CUnit::ClearFrom()
{
m_EdtName.SetWindowText("");
m_EdtLetterName.SetWindowText("");
m_EdtPhone.SetWindowText("");
m_EdtAddr.SetWindowText("");
m_EdtFax.SetWindowText("");
m_ComCity.SetWindowText("");
m_ComProvince.SetWindowText("");
m_ComTown.SetWindowText("");
m_ComSort.SetWindowText("");
}
void CUnit::Enabled(bool bStyle)
{
m_ButAdd.EnableWindow(bStyle);
m_ButDele.EnableWindow(bStyle);
m_ButChange.EnableWindow(bStyle);
m_ButSave.EnableWindow(!bStyle);
m_ButExit.EnableWindow(bStyle);
m_ButCencel.EnableWindow(!bStyle);
m_EdtName.EnableWindow(!bStyle);
m_EdtLetterName.EnableWindow(!bStyle);
m_EdtPhone.EnableWindow(!bStyle);
m_EdtAddr.EnableWindow(!bStyle);
m_EdtFax.EnableWindow(!bStyle);
m_ComCity.EnableWindow(!bStyle);
m_ComProvince.EnableWindow(!bStyle);
m_ComTown.EnableWindow(!bStyle);
m_ComSort.EnableWindow(!bStyle);
m_Slider.EnableWindow(bStyle);
}
void CUnit::OnBUTChange()
{
this->m_ComSort.SetWindowText("");
this->AddOrChange=false;
this->Enabled(false);
this->m_EdtName.SetFocus();
}
void CUnit::OnBUTSave()
{
CString ID,Name,LatterName,Addr,Phone,Fax,Sort,Town,sSQL;
int nSort,nTown;
int a=MessageBox("确定要保存记录吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION);
if(a==1)
{
m_EdtID.GetWindowText(ID);
m_EdtName.GetWindowText(Name);
m_EdtLetterName.GetWindowText(LatterName);
m_EdtPhone.GetWindowText(Phone);
m_EdtFax.GetWindowText(Fax);
m_EdtAddr.GetWindowText(Addr);
m_ComSort.GetWindowText(Sort);
m_ComTown.GetWindowText(Town);
if(Town=="" || Town=="--")
{
MessageBox("请添入所在区/镇!","系统提示",MB_OK|MB_ICONSTOP);
m_ComTown.SetFocus();
return;
}
nSort=m_ComSort.Recno;
nTown=m_ComTown.Recno;
if(this->AddOrChange==true)
sSQL.Format("Insert into 客户单位信息表 values('%s','%s','%s',%d,'%s','%s','%s',%d)",ID,Name,LatterName,nTown,Addr,Phone,Fax,nSort);
else
sSQL.Format("Update 客户单位信息表 SET 名称='%s',简称='%s',地域编号=%d,地址='%s',电话='%s',传真='%s',客户类别=%d Where 编号='%s'",Name,LatterName,nTown,Addr,Phone,Fax,nSort,ID);
cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
m_Slider.Init();
this->Enabled(true);
this->m_ButAdd.SetFocus();
}
}
BOOL CUnit::PreTranslateMessage(MSG* pMsg)
{
return CDialog::PreTranslateMessage(pMsg);
}
void CUnit::OnChangeEDTName()
{
CString LetterString,str;
m_EdtName.GetWindowText(str);
LetterString=function.CharToLetterCode(str);
this->m_EdtLetterName.SetWindowText(LetterString);
}
void CUnit::Display()
{
CString ID,Name,LatterName,Addr,Phone,Fax,Sort,Town;
_variant_t _Phone,_Fax;
int nTown;
ID=(char*)(_bstr_t)rst->GetCollect("编号");
this->m_EdtID.SetWindowText(ID);
Name=(char*)(_bstr_t)rst->GetCollect("名称");
this->m_EdtName.SetWindowText(Name);
LatterName=(char*)(_bstr_t)rst->GetCollect("简称");
this->m_EdtLetterName.SetWindowText(LatterName);
Addr=(char*)(_bstr_t)rst->GetCollect("地址");
this->m_EdtAddr.SetWindowText(Addr);
_Phone=rst->GetCollect("电话");
if(_Phone.vt==VT_EMPTY)
Phone="";
else
Phone=(char*)(_bstr_t)_Phone;
this->m_EdtPhone.SetWindowText(Phone);
_Fax=rst->GetCollect("传真");
if(_Fax.vt==VT_EMPTY)
Fax="";
else
Fax=(char*)(_bstr_t)_Fax;
this->m_EdtFax.SetWindowText(Fax);
Sort=(char*)(_bstr_t)rst->GetCollect("客户类别");
this->m_ComSort.SetWindowText(Sort);
Town=(char*)(_bstr_t)rst->GetCollect("地域");
nTown=atoi(Town);
this->Clime(nTown);
}
int CUnit::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 CUnit::OnButCencel()
{
int a=MessageBox("确定要撤消操作吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION);
if(a==1)
{
rst->MoveFirst();
this->Display();
this->Enabled(true);
this->m_ButAdd.SetFocus();
}
}
BOOL CUnit::DestroyWindow()
{
rst->Close();
return CDialog::DestroyWindow();
}
void CUnit::OnBUTDele()
{
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 CUnit::OnReleasedcaptureSlider1(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 + -