📄 searchps.cpp
字号:
// SearchP.cpp : implementation file
//
#include "stdafx.h"
#include "aomanage.h"
#include "SearchPs.h"
#include "MainFrm.h"
#include "Useage.h"
#include "Detail.h"
#include "InP.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSearchPs dialog
CSearchPs::CSearchPs(CWnd* pParent /*=NULL*/,int nParent)
: CParentDlg(CSearchPs::IDD, pParent)
{
//{{AFX_DATA_INIT(CSearchPs)
m_strPCode = _T("");
m_strPName = _T("");
m_strSerial = _T("");
//}}AFX_DATA_INIT
m_pProduct=new CDaoRecordset(&((CMainFrame*)AfxGetMainWnd())->m_db);
m_pCallDlg=(CParentDlg*)pParent;
m_nParent=nParent;
}
void CSearchPs::DoDataExchange(CDataExchange* pDX)
{
CParentDlg::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSearchPs)
DDX_Control(pDX, IDC_LIST1, m_ctlList);
DDX_Text(pDX, IDC_EDIT1, m_strPCode);
DDX_Text(pDX, IDC_EDIT2, m_strPName);
DDX_Text(pDX, IDC_EDIT9, m_strSerial);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSearchPs, CParentDlg)
//{{AFX_MSG_MAP(CSearchPs)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_WM_CLOSE()
ON_MESSAGE(WM_LIST2DBLCLICK,OnList2DblClick)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSearchPs message handlers
BOOL CSearchPs::OnInitDialog()
{
CParentDlg::OnInitDialog();
m_pProduct->Open(AFX_DAO_USE_DEFAULT_TYPE,"select * from product");
FIELD2 fdValue[4]={{"品号","pcode"},\
{"品名","pname"},\
{"单位","unit"},{"备注","demo"}
};
m_ctlList.SetField(4,fdValue,m_pProduct);
m_ctlList.Init();
//double nWidth[5]={1,0.7,1,1.3,1};
//m_ctlList.SetWidth(nWidth);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSearchPs::OnButton1()
{
UpdateData(TRUE);
CString strFltr;
if (m_strPCode.GetLength())
strFltr+=" and pcode='"+m_strPCode+"'";
if (m_strPName.GetLength())
strFltr+=" and pname='"+m_strPName+"'";
if (m_strSerial.GetLength())
strFltr+=" and serial='"+m_strSerial+"'";
if (!strcmp(strFltr.Left(5)," and "))
strFltr.Right(strFltr.GetLength()-5);
m_pProduct->m_strFilter=strFltr;
m_ctlList.Refresh();
}
void CSearchPs::OnButton2()
{
OnCancel();
}
void CSearchPs::OnClose()
{
if (m_pProduct->IsOpen())
m_pProduct->Close();
CParentDlg::OnClose();
}
void CSearchPs::OnList2DblClick(WPARAM wParam,LPARAM lParam)
{
if (m_nParent==1)
{
CDetail *pDlg=(CDetail*)m_pCallDlg;
pDlg->m_strPCode.Format("%09d",wParam);
if (m_pProduct->FindFirst("pcode='"+pDlg->m_strPCode+"'"))
{
COleVariant vVal;
m_pProduct->GetFieldValue("pname",vVal);
pDlg->m_strPCode+=" ";
pDlg->m_strPCode+=(LPCTSTR)vVal.bstrVal;
pDlg->UpdateData(FALSE);
OnOK();
}
}
else if (m_nParent==2)
{
CInP *pDlg=(CInP*)m_pCallDlg;
pDlg->m_strCode.Format("%09d",wParam);
if (m_pProduct->FindFirst("pcode='"+pDlg->m_strCode+"'"))
{
COleVariant vVal;
m_pProduct->GetFieldValue("pname",vVal);
pDlg->m_strCode+=" ";
pDlg->m_strCode+=(LPCTSTR)vVal.bstrVal;
pDlg->UpdateData(FALSE);
OnOK();
}
}
else
{
CUseage *pDlg=(CUseage*)m_pCallDlg;
pDlg->m_strPCode.Format("%09d",wParam);
if (m_pProduct->FindFirst("pcode='"+pDlg->m_strPCode+"'"))
{
COleVariant vVal;
m_pProduct->GetFieldValue("pname",vVal);
pDlg->m_strPCode+=" ";
pDlg->m_strPCode+=(LPCTSTR)vVal.bstrVal;
pDlg->UpdateData(FALSE);
OnOK();
}
}
}
void CSearchPs::OnButton7()
{
POSITION pos=m_ctlList.GetFirstSelectedItemPosition();
if (pos)
{
int nItem=m_ctlList.GetNextSelectedItem(pos);
if (m_nParent==1)
{
CDetail *pDlg=(CDetail*)m_pCallDlg;
pDlg->m_strPCode=m_ctlList.GetItemText(nItem,0);
m_pProduct->FindFirst("pcode='"+pDlg->m_strPCode+"'");
COleVariant vVal;
m_pProduct->GetFieldValue("pname",vVal);
pDlg->m_strPCode+=" ";
pDlg->m_strPCode+=(LPCTSTR)vVal.bstrVal;
pDlg->UpdateData(FALSE);
OnOK();
}
else if (m_nParent==2)
{
CInP *pDlg=(CInP*)m_pCallDlg;
pDlg->m_strCode=m_ctlList.GetItemText(nItem,0);
m_pProduct->FindFirst("pcode='"+pDlg->m_strCode+"'");
COleVariant vVal;
m_pProduct->GetFieldValue("pname",vVal);
pDlg->m_strCode+=" ";
pDlg->m_strCode+=(LPCTSTR)vVal.bstrVal;
pDlg->UpdateData(FALSE);
OnOK();
}
else
{
CUseage *pDlg=(CUseage*)m_pCallDlg;
pDlg->m_strPCode=m_ctlList.GetItemText(nItem,0);
m_pProduct->FindFirst("pcode='"+pDlg->m_strPCode+"'");
COleVariant vVal;
m_pProduct->GetFieldValue("pname",vVal);
pDlg->m_strPCode+=" ";
pDlg->m_strPCode+=(LPCTSTR)vVal.bstrVal;
pDlg->UpdateData(FALSE);
OnOK();
}
}
else
MessageBox("请选中该记录");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -