📄 product.cpp
字号:
// Product.cpp : implementation file
//
#include "stdafx.h"
#include "aoManage.h"
#include "Product.h"
#include "MainFrm.h"
#include "SearchP.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CProduct dialog
CProduct::CProduct(CWnd* pParent /*=NULL*/)
: CParentDlg(CProduct::IDD, pParent)
{
//{{AFX_DATA_INIT(CProduct)
m_nRadio = 0;
m_strSerial = _T("");
m_strPName = _T("");
m_strPCode = _T("");
m_strUnit = _T("");
m_strDemo = _T("");
//}}AFX_DATA_INIT
m_pProduct=new CDaoRecordset(&((CMainFrame*)AfxGetMainWnd())->m_db);
}
void CProduct::DoDataExchange(CDataExchange* pDX)
{
CParentDlg::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CProduct)
DDX_Radio(pDX, IDC_RADIO1, m_nRadio);
DDX_Text(pDX, IDC_EDIT1, m_strSerial);
DDX_Text(pDX, IDC_EDIT2, m_strPName);
DDX_Text(pDX, IDC_EDIT7, m_strPCode);
DDX_Text(pDX, IDC_EDIT8, m_strUnit);
DDX_Text(pDX, IDC_EDIT9, m_strDemo);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CProduct, CParentDlg)
//{{AFX_MSG_MAP(CProduct)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_WM_CLOSE()
ON_EN_KILLFOCUS(IDC_EDIT1, OnKillfocusEdit1)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProduct message handlers
BOOL CProduct::OnInitDialog()
{
CParentDlg::OnInitDialog();
m_pProduct->Open(AFX_DAO_USE_DEFAULT_TYPE,"select * from product");
FILE *f=fopen("data\\serial.txt","r");
char *lpBuf=new char[5];
while (fgetc(f)!=':');
while (fgetc(f)!=':');
fread(lpBuf,4,1,f);
lpBuf[4]='\0';
fclose(f);
m_strSerial=lpBuf;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CProduct::OnButton3()
{
UpdateData(TRUE);
if (!m_strSerial.GetLength()||!m_strPCode.GetLength()||!m_strPName.GetLength())
{
MessageBox("序号,品号或品名不能为空,请重新输入");
return;
}
if (m_pProduct->FindFirst("pcode='"+m_strPCode+"'"))
{
MessageBox("此品号已存在,请重新选择");
return;
}
m_pProduct->AddNew();
m_pProduct->SetFieldValue("serial",(LPCTSTR)m_strSerial);
m_pProduct->SetFieldValue("pname",(LPCTSTR)m_strPName);
m_pProduct->SetFieldValue("pcode",(LPCTSTR)m_strPCode);
m_pProduct->SetFieldValue("unit",(LPCTSTR)m_strUnit);
m_pProduct->SetFieldValue("demo",(LPCTSTR)m_strDemo);
m_pProduct->Update();
MessageBox("记录已成功添加");
CDaoDatabase *pDb=&((CMainFrame*)AfxGetMainWnd())->m_db;
pDb->Execute("create table "+m_strPCode+" (pcode char(9),pcount int)");
m_strSerial.Format("%04d",atoi(m_strSerial)+1);
m_strPName="";
m_strPCode="";
m_strUnit="";
m_strDemo="";
UpdateData(FALSE);
FILE *f=fopen("data\\serial.txt","r+");
while (fgetc(f)!=':');
while (fgetc(f)!=':');
if (m_nRadio)
while (fgetc(f)!=':');
fseek(f,0,SEEK_CUR);
fwrite(m_strSerial,4,1,f);
fclose(f);
}
void CProduct::OnButton4()
{
OnCancel();
}
void CProduct::OnClose()
{
if (m_pProduct->IsOpen())
m_pProduct->Close();
CParentDlg::OnClose();
}
void CProduct::OnKillfocusEdit1()
{
UpdateData(TRUE);
if (!m_nRadio)
m_strPCode="2"+m_strSerial+"0000";
else
m_strPCode="3"+m_strSerial+"0000";
UpdateData(FALSE);
}
void CProduct::OnRadio1()
{
UpdateData(TRUE);
FILE *f=fopen("data\\serial.txt","r");
char *lpBuf=new char[5];
while (fgetc(f)!=':');
while (fgetc(f)!=':');
fread(lpBuf,4,1,f);
lpBuf[4]='\0';
fclose(f);
m_strSerial=lpBuf;
UpdateData(FALSE);
}
void CProduct::OnRadio2()
{
UpdateData(TRUE);
FILE *f=fopen("data\\serial.txt","r");
char *lpBuf=new char[5];
while (fgetc(f)!=':');
while (fgetc(f)!=':');
while (fgetc(f)!=':');
fread(lpBuf,4,1,f);
lpBuf[4]='\0';
fclose(f);
m_strSerial=lpBuf;
UpdateData(FALSE);
}
void CProduct::OnButton8()
{
OnCancel();
CSearchP dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -