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

📄 inm.cpp

📁 一个很好的VC源代码
💻 CPP
字号:
// In.cpp : implementation file
//

#include "stdafx.h"
#include "aoManage.h"
#include "InM.h"
#include "MainFrm.h"
#include "SearchI.h"
#include "SearchM.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CInM dialog


CInM::CInM(CWnd* pParent /*=NULL*/)
	: CParentDlg(CInM::IDD, pParent)
{
	//{{AFX_DATA_INIT(CInM)
	m_nCount = 0;
	m_dtDate = COleDateTime::GetCurrentTime();
	m_dtTime = COleDateTime::GetCurrentTime();
	m_strWorker = _T("");
	m_nRadio = 0;
	m_strCode = _T("");
	//}}AFX_DATA_INIT
	m_pStorage=new CDaoRecordset(&((CMainFrame*)AfxGetMainWnd())->m_db);
	m_strOperator=((CMainFrame*)AfxGetMainWnd())->m_strOperator;
}


void CInM::DoDataExchange(CDataExchange* pDX)
{
	CParentDlg::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CInM)
	DDX_Text(pDX, IDC_EDIT2, m_nCount);
	DDX_Text(pDX, IDC_EDIT7, m_dtDate);
	DDX_Text(pDX, IDC_EDIT8, m_dtTime);
	DDX_Text(pDX, IDC_EDIT9, m_strWorker);
	DDX_Text(pDX, IDC_EDIT10, m_strOperator);
	DDX_Radio(pDX, IDC_RADIO1, m_nRadio);
	DDX_Text(pDX, IDC_EDIT1, m_strCode);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CInM, CParentDlg)
	//{{AFX_MSG_MAP(CInM)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInM message handlers

BOOL CInM::OnInitDialog() 
{
	CParentDlg::OnInitDialog();
	
	m_pStorage->Open(AFX_DAO_USE_DEFAULT_TYPE,"select * from storage");
	/*m_pMaterial->Open(AFX_DAO_USE_DEFAULT_TYPE,"select * from material");
	CString strTemp;
	COleVariant vCode,vName,vType;
	while (!m_pMaterial->IsEOF())
	{
		m_pMaterial->GetFieldValue("pcode",vCode);
		m_pMaterial->GetFieldValue("pname",vName);
		m_pMaterial->GetFieldValue("ptype",vType);
		strTemp=(LPCTSTR)vCode.bstrVal;
		strTemp+="   ";
		strTemp+=(LPCTSTR)vName.bstrVal;
		strTemp+=" ";
		strTemp+=(LPCTSTR)vType.bstrVal;
		m_ctlCbCode.AddString(strTemp);
		m_pMaterial->MoveNext();
	}*/
	m_dtDate.ParseDateTime(m_dtDate.Format(VAR_DATEVALUEONLY),VAR_DATEVALUEONLY);
	m_dtTime.ParseDateTime(m_dtTime.Format(VAR_TIMEVALUEONLY),VAR_TIMEVALUEONLY);
	UpdateData(FALSE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CInM::OnButton3() 
{
	UpdateData(TRUE);
	if (!m_strCode.GetLength())
	{
		MessageBox("品号不能为空");
		return;
	}
	if (!(m_nCount>0))
	{
		MessageBox("数量应大于零");
		return;
	}
	int nCount=0;
	if (m_nRadio)
	{
		if (m_pStorage->FindFirst("code='"+m_strCode.Left(9)+"'"))
		{
			COleVariant vVal;
			CDaoQueryDef *pQDef=new CDaoQueryDef(&((CMainFrame*)AfxGetMainWnd())->m_db);
			CDaoRecordset *pSet=new CDaoRecordset();
			pQDef->Open();
			pQDef->SetSQL("select sum(count) as count0 from storage where code='"+m_strCode.Left(9)+"' and ifin=true");
			pSet->Open(pQDef);
			pSet->GetFieldValue("count0",vVal);
			nCount=(int)vVal.dblVal;
			pSet->Close();
			pQDef->SetSQL("select sum(count) as count0 from storage where code='"+m_strCode.Left(9)+"' and ifin=false");
			pSet->Open(pQDef);
			if (pSet->GetRecordCount())
			{
				pSet->GetFieldValue("count0",vVal);
				if (vVal.vt!=VT_NULL&&vVal.vt!=VT_EMPTY)
					nCount-=(int)vVal.dblVal;
			}
			pSet->Close();
			pQDef->Close();
			if (nCount<m_nCount)
			{
				MessageBox("库存数不够");
				return;
			}
		}
		else
		{
			MessageBox("库存数不够");
			return;
		}
	}
	m_pStorage->AddNew();
	m_pStorage->SetFieldValue("code",(LPCTSTR)m_strCode.Left(9));
	m_pStorage->SetFieldValue("count",(short)m_nCount);
	m_pStorage->SetFieldValue("ifin",BYTE(!m_nRadio));
	m_pStorage->SetFieldValue("sdate",m_dtDate);
	m_pStorage->SetFieldValue("stime",m_dtTime);
	m_pStorage->SetFieldValue("worker",(LPCTSTR)m_strWorker);
	m_pStorage->SetFieldValue("operator",(LPCTSTR)m_strOperator);
	m_pStorage->Update();
	MessageBox("记录已成功添加");
	m_nCount=0;
	COleDateTime dtCur=COleDateTime::GetCurrentTime();
	m_dtDate.ParseDateTime(dtCur.Format(VAR_DATEVALUEONLY),VAR_DATEVALUEONLY);
	m_dtTime.ParseDateTime(dtCur.Format(VAR_TIMEVALUEONLY),VAR_TIMEVALUEONLY);
	m_strWorker="";
	UpdateData(FALSE);
}	

void CInM::OnButton4() 
{
	OnCancel();
}

void CInM::OnClose() 
{
	if (m_pStorage->IsOpen())
		m_pStorage->Close();
	CParentDlg::OnClose();
}

void CInM::OnButton8() 
{
	OnCancel();
	CSearchI dlg;
	dlg.DoModal();
}

void CInM::OnButton6() 
{
	CSearchM dlg(this,1);
	dlg.DoModal();
}

⌨️ 快捷键说明

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