📄 material.cpp
字号:
// Material.cpp : implementation file
//
#include "stdafx.h"
#include "aoManage.h"
#include "Material.h"
#include "MainFrm.h"
#include "SearchM.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMaterial dialog
CMaterial::CMaterial(CWnd* pParent /*=NULL*/)
: CParentDlg(CMaterial::IDD, pParent)
{
//{{AFX_DATA_INIT(CMaterial)
m_strSerial = _T("");
m_strPName = _T("");
m_strPCode = _T("");
m_strUnit = _T("");
m_strDemo = _T("");
m_strCClass = _T("");
m_strSupply = _T("");
m_strPType = _T("");
//}}AFX_DATA_INIT
m_pCClass=new CDaoRecordset(&((CMainFrame*)AfxGetMainWnd())->m_db);
m_pMaterial=new CDaoRecordset(&((CMainFrame*)AfxGetMainWnd())->m_db);
m_pSupply=new CDaoRecordset(&((CMainFrame*)AfxGetMainWnd())->m_db);
}
void CMaterial::DoDataExchange(CDataExchange* pDX)
{
CParentDlg::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMaterial)
DDX_Control(pDX, IDC_COMBO1, m_ctlCbCClass);
DDX_Control(pDX, IDC_COMBO2, m_ctlCbSupply);
DDX_Text(pDX, IDC_EDIT1, m_strSerial);
DDX_Text(pDX, IDC_EDIT2, m_strPName);
DDX_Text(pDX, IDC_EDIT3, m_strPCode);
DDX_Text(pDX, IDC_EDIT4, m_strUnit);
DDX_Text(pDX, IDC_EDIT5, m_strDemo);
DDX_CBString(pDX, IDC_COMBO1, m_strCClass);
DDX_CBString(pDX, IDC_COMBO2, m_strSupply);
DDX_Text(pDX, IDC_EDIT6, m_strPType);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMaterial, CParentDlg)
//{{AFX_MSG_MAP(CMaterial)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_WM_CLOSE()
ON_CBN_KILLFOCUS(IDC_COMBO1, OnKillfocusCombo1)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMaterial message handlers
BOOL CMaterial::OnInitDialog()
{
CParentDlg::OnInitDialog();
m_pCClass->Open(AFX_DAO_USE_DEFAULT_TYPE,"select * from cclass");
m_pMaterial->Open(AFX_DAO_USE_DEFAULT_TYPE,"select * from material");
m_pSupply->Open(AFX_DAO_USE_DEFAULT_TYPE,"select * from supply");
COleVariant vCode,vName;
CString strTemp;
while (!m_pCClass->IsEOF())
{
m_pCClass->GetFieldValue("code",vCode);
m_pCClass->GetFieldValue("name",vName);
strTemp=(LPCTSTR)vCode.bstrVal;
strTemp+=" ";
strTemp+=(LPCTSTR)vName.bstrVal;
m_ctlCbCClass.AddString(strTemp);
m_pCClass->MoveNext();
}
while (!m_pSupply->IsEOF())
{
m_pSupply->GetFieldValue("scode",vCode);
m_pSupply->GetFieldValue("sname",vName);
strTemp=(LPCTSTR)vCode.bstrVal;
strTemp+=" ";
strTemp+=(LPCTSTR)vName.bstrVal;
m_ctlCbSupply.AddString(strTemp);
m_pSupply->MoveNext();
}
char *lpBuf=new char[64];
FILE *f=fopen("data\\serial.txt","r");
while (fgetc(f)!=':');
fread(lpBuf,4,1,f);
fseek(f,-4,SEEK_CUR);
fclose(f);
lpBuf[4]='\0';
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 CMaterial::OnButton1()
{
UpdateData(TRUE);
if (!m_strCClass.GetLength()||!m_strPName.GetLength()||!m_strPCode.GetLength())
{
MessageBox("分类号,品名或品号不能为空");
return;
}
if (m_pMaterial->FindFirst("pcode='"+m_strPCode+"'"))
{
MessageBox("此品号已存在,请重新选择");
return;
}
m_pMaterial->AddNew();
m_pMaterial->SetFieldValue("serial",(LPCTSTR)m_strSerial);
m_pMaterial->SetFieldValue("cclass",(LPCTSTR)m_strCClass.Left(2));
m_pMaterial->SetFieldValue("pname",(LPCTSTR)m_strPName);
m_pMaterial->SetFieldValue("pcode",(LPCTSTR)m_strPCode);
m_pMaterial->SetFieldValue("ptype",(LPCTSTR)m_strPType);
m_pMaterial->SetFieldValue("unit",(LPCTSTR)m_strUnit);
m_pMaterial->SetFieldValue("supplycode",(LPCTSTR)m_strSupply.Left(7));
m_pMaterial->SetFieldValue("demo",(LPCTSTR)m_strDemo);
m_pMaterial->Update();
MessageBox("记录已成功添加");
m_strSerial.Format("%04d",atoi(m_strSerial)+1);
//m_strCClass="";
m_strPName="";
m_strPCode="";
m_strPType="";
m_strUnit="";
//m_strSupply="";
m_strDemo="";
UpdateData(FALSE);
m_ctlCbCClass.SetCurSel(-1);
m_ctlCbSupply.SetCurSel(-1);
FILE *f=fopen("data\\serial.txt","r+");
while (fgetc(f)!=':');
fseek(f,0,SEEK_CUR);
fwrite(m_strSerial,4,1,f);
fclose(f);
}
void CMaterial::OnButton2()
{
OnCancel();
}
void CMaterial::OnClose()
{
if (m_pCClass->IsOpen())
m_pCClass->Close();
if (m_pMaterial->IsOpen())
m_pMaterial->Close();
if (m_pSupply->IsOpen())
m_pSupply->Close();
CParentDlg::OnClose();
}
void CMaterial::OnKillfocusCombo1()
{
UpdateData(TRUE);
CString strFltr="???"+m_strSerial+"??";
strFltr="pcode like '"+strFltr+"\'";
//if (m_pMaterial->FindFirst(strFltr))
if (m_pMaterial->FindLast(strFltr))
{
CString strTemp;
COleVariant vVal;
m_pMaterial->GetFieldValue("pcode",vVal);
strTemp=(LPCTSTR)vVal.bstrVal;
strTemp=strTemp.Right(2);
m_strPCode.Format("%02d",atoi(strTemp)+1);
}
else
m_strPCode="01";
m_strPCode="1"+m_strCClass.Left(2)+m_strSerial+m_strPCode;
UpdateData(FALSE);
}
void CMaterial::OnButton5()
{
OnCancel();
CSearchM dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -