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

📄 useage.cpp

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

#include "stdafx.h"
#include "aomanage.h"
#include "Useage.h"
#include "SearchPs.h"
#include "MainFrm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CUseage dialog


CUseage::CUseage(CWnd* pParent /*=NULL*/)
	: CParentDlg(CUseage::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUseage)
	m_strPCode = _T("");
	m_nCount = 0;
	//}}AFX_DATA_INIT
	m_pMaterial=new CDaoRecordset(&((CMainFrame*)AfxGetMainWnd())->m_db);
	m_pGoods=new CDaoRecordset(&((CMainFrame*)AfxGetMainWnd())->m_db);
}


void CUseage::DoDataExchange(CDataExchange* pDX)
{
	CParentDlg::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUseage)
	DDX_Control(pDX, IDC_LIST2, m_ctlListTo);
	DDX_Control(pDX, IDC_LIST1, m_ctlListFrm);
	DDX_Text(pDX, IDC_EDIT1, m_strPCode);
	DDX_Text(pDX, IDC_EDIT2, m_nCount);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CUseage, CParentDlg)
	//{{AFX_MSG_MAP(CUseage)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
	ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUseage message handlers

BOOL CUseage::OnInitDialog() 
{
	CParentDlg::OnInitDialog();
	
	m_pMaterial->Open(AFX_DAO_USE_DEFAULT_TYPE,"select * from material");
	COleVariant vVal;
	CString strCode;
	while (!m_pMaterial->IsEOF())
	{
		m_pMaterial->GetFieldValue("pcode",vVal);
		strCode=(LPCTSTR)vVal.bstrVal;
		strCode+="   ";
		m_pMaterial->GetFieldValue("pname",vVal);
		strCode+=(LPCTSTR)vVal.bstrVal;
		strCode+="   ";
		m_pMaterial->GetFieldValue("ptype",vVal);
		strCode+=(LPCTSTR)vVal.bstrVal;
		m_ctlListFrm.AddString(strCode);
		m_pMaterial->MoveNext();
	}
		
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CUseage::OnButton1() 
{
	CSearchPs dlg(this);
	if (dlg.DoModal()==IDOK)
	{
		CString strSQL="select pcount,b.pcode,pname,ptype from "+m_strPCode.Left(9)+" as a,material as b where a.pcode=b.pcode";
		m_pGoods->Open(AFX_DAO_USE_DEFAULT_TYPE,strSQL);
		CString strCode;
		COleVariant vVal;
		m_ctlListTo.ResetContent();
		int nCount;
		while (!m_pGoods->IsEOF())
		{
			m_pGoods->GetFieldValue("pcode",vVal);
			strCode=(LPCTSTR)vVal.bstrVal;
			strCode+="   ";
			m_pGoods->GetFieldValue("pname",vVal);
			strCode+=(LPCTSTR)vVal.bstrVal;
			strCode+="   ";
			m_pGoods->GetFieldValue("ptype",vVal);
			strCode+=(LPCTSTR)vVal.bstrVal;
			m_ctlListFrm.DeleteString(m_ctlListFrm.FindString(0,strCode));
			m_pGoods->GetFieldValue("pcount",vVal);
			nCount=vVal.iVal;
			strCode.Format(strCode+"%9d",nCount);
			m_ctlListTo.AddString(strCode);
			m_pGoods->MoveNext();
		}
		if (m_pGoods->IsOpen())
			m_pGoods->Close();
	}
}

void CUseage::OnButton2() 
{
	UpdateData(TRUE);
	if (m_strPCode.GetLength())
	{
		CDaoDatabase *pDb=&((CMainFrame*)AfxGetMainWnd())->m_db;
		pDb->Execute("delete from "+m_strPCode.Left(9));
		int nCount=m_ctlListTo.GetCount();
		if (nCount>0)
		{
			m_pGoods->Open(AFX_DAO_USE_DEFAULT_TYPE,"select * from "+m_strPCode.Left(9));
			CString strCode;
			for (int i=0;i<nCount;i++)
			{
				m_ctlListTo.GetText(i,strCode);
				m_pGoods->AddNew();
				m_pGoods->SetFieldValue("pcode",(LPCTSTR)strCode.Left(9));
				m_pGoods->SetFieldValue("pcount",(long)atoi(strCode.Right(9)));
				m_pGoods->Update();
			}
			if (m_pGoods->IsOpen())
				m_pGoods->Close();
			MessageBox("已成功修改");
		}
	}
}

void CUseage::OnButton3() 
{
	OnCancel();
}

void CUseage::OnClose() 
{
	if (m_pMaterial->IsOpen())
		m_pMaterial->Close();
	if (m_pGoods->IsOpen())
		m_pGoods->Close();
	CParentDlg::OnClose();
}

void CUseage::OnButton7() 
{
	int nCount=m_ctlListFrm.GetSelCount();
	if (nCount>0)
	{
		LPINT lpIndex;
		m_ctlListFrm.GetSelItems(100,lpIndex);
		CString strCode;
		for (int i=nCount-1;i>=0;i--)
		{
			m_ctlListFrm.GetText(lpIndex[i],strCode);
			strCode.Format(strCode+"%9d",1);
			m_ctlListTo.AddString(strCode);
			m_ctlListFrm.DeleteString(lpIndex[i]);
		}
	}
}

void CUseage::OnButton9() 
{
	/*int nCount=m_ctlListTo.GetSelCount();
	if (nCount>0)
	{
		LPINT lpIndex;
		m_ctlListTo.GetSelItems(100,lpIndex);
		CString strCode;
		for (int i=nCount-1;i>=0;i--)
		{
			m_ctlListTo.GetText(lpIndex[i],strCode);
			strCode=strCode.Left(strCode.GetLength()-9);
			m_ctlListFrm.AddString(strCode);
			m_ctlListTo.DeleteString(lpIndex[i]);
		}
	}*/
	int nIndex=m_ctlListTo.GetCurSel();
	if (nIndex>=0)
	{
		CString strCode;
		m_ctlListTo.GetText(nIndex,strCode);
		strCode=strCode.Left(strCode.GetLength()-9);
		m_ctlListFrm.AddString(strCode);
		m_ctlListTo.DeleteString(nIndex);
	}
}

void CUseage::OnButton4() 
{
	UpdateData(TRUE);
	if (m_nCount>0)
	{
		int nIndex=m_ctlListTo.GetCurSel();
		if (nIndex>=0)
		{
			CString strCode;
			m_ctlListTo.GetText(nIndex,strCode);
			strCode=strCode.Left(strCode.GetLength()-9);
			strCode.Format(strCode+"%9d",m_nCount);
			m_ctlListTo.DeleteString(nIndex);
			m_ctlListTo.InsertString(nIndex,strCode);
		}
		m_nCount=0;
		UpdateData(FALSE);
	}
}

⌨️ 快捷键说明

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