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

📄 dlgyj.cpp

📁 我自己整理的一些VC源代码
💻 CPP
字号:
// DlgYJ.cpp : implementation file
//

#include "stdafx.h"
#include "SellMan.h"
#include "DlgYJ.h"
#include "TabYJ.h"
#include "TabDL.h"
#include "TabSP.h"
#include "TabCS.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgYJ dialog

extern _ConnectionPtr connection;
extern BOOL bConnected;

CDlgYJ::CDlgYJ(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgYJ::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgYJ)
	//}}AFX_DATA_INIT
	m_nOperType = MODE_APPEND;
}


void CDlgYJ::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgYJ)
	DDX_Control(pDX, IDC_CB_YJJHKH, m_cb_yjjhkh);
	DDX_Control(pDX, IDC_CB_YJJDID, m_cb_yjjdid);
	DDX_Control(pDX, IDC_CB_YJSPID, m_cb_yjspid);
	DDX_Control(pDX, IDC_CB_YJCDID, m_cb_yjcdid);
	DDX_Control(pDX, IDC_ED_YJYJID, m_ed_yjyjid);
	DDX_Control(pDX, IDC_ED_YJJHSL, m_ed_yjjhsl);
	DDX_Control(pDX, IDC_ED_YJJHJG, m_ed_yjjhjg);
	DDX_Control(pDX, IDC_ED_YJJHJE, m_ed_yjjhje);
	DDX_Control(pDX, IDC_ED_YJBZXX, m_ed_yjbzxx);
	DDX_Control(pDX, IDC_DT_YJJHSJ, m_dt_yjjhsj);
	DDX_Control(pDX, IDC_CB_YJLSPH, m_cb_yjlsph);
	DDX_Control(pDX, IDC_CB_YJJSBZ, m_cb_yjjsbz);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgYJ, CDialog)
	//{{AFX_MSG_MAP(CDlgYJ)
	ON_BN_CLICKED(IDC_BT_SAVE, OnBtSave)
	ON_EN_CHANGE(IDC_ED_YJJHSL, OnChangeEdYjjhsl)
	ON_EN_CHANGE(IDC_ED_YJJHJG, OnChangeEdYjjhjg)
	ON_BN_CLICKED(IDC_BT_DEFAULT, OnBtDefault)
	ON_CBN_SELCHANGE(IDC_CB_YJLSPH, OnSelchangeCbYjlsph)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgYJ message handlers

BOOL CDlgYJ::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	if ( m_nOperType == MODE_APPEND )
	{
		if( !InitData() )
		{
			AfxMessageBox( "信息初始化失败!" );
			return FALSE;
		}
	}
	else if ( m_nOperType == MODE_MODIFY )
	{
		if ( !InitMod() )
		{
			AfxMessageBox( "信息初始化失败!" );
		}
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgYJ::OnBtSave() 
{
	
	SYSTEMTIME sysTime;
	CTabYJ tabyj;
	CTabDL tabdl;
	CString strSQL;
	long ltmp;

	memset( &sysTime,0,sizeof(SYSTEMTIME) );
	UpdateData();

	m_ed_yjyjid.GetWindowText( strYJYJID );
	strYJCDID.Format( "%d", m_cb_yjcdid.GetItemData( m_cb_yjcdid.GetCurSel() ) ); //代理号码(取DL表的DLDLBH)
	strYJJDID.Format( "%d", m_cb_yjjdid.GetItemData( m_cb_yjjdid.GetCurSel() ) ); //进代理号(进货代理商号码)
	strYJSPID.Format( "%d", m_cb_yjspid.GetItemData( m_cb_yjspid.GetCurSel() ) ); //货物ID(取SP表的SPSPID)
	m_dt_yjjhsj.GetTime( &sysTime );
	strYJJHSJ.Format( "%04d%02d%02d",sysTime.wYear,sysTime.wMonth,sysTime.wDay ); //进货时间
	
	m_ed_yjjhjg.GetWindowText( strYJJHJG );
	m_ed_yjjhje.GetWindowText( strYJJHJE );
	m_ed_yjjhsl.GetWindowText( strYJJHSL );

	strYJLSPH.Format( "%d",m_cb_yjlsph.GetItemData( m_cb_yjlsph.GetCurSel() ) );
	strYJJSBZ.Format( "%d",m_cb_yjjsbz.GetItemData( m_cb_yjjsbz.GetCurSel() ) );
	strYJJHKH.Format( "%d",m_cb_yjjhkh.GetItemData( m_cb_yjjhkh.GetCurSel() ) );
	m_ed_yjbzxx.GetWindowText( strYJBZXX );
	
	if ( strYJYJID.IsEmpty() )
	{
		AfxMessageBox("进货ID不能为空!");
		return;
	}
	else if (strYJJHJG.IsEmpty())
	{
		AfxMessageBox("进货价格不能为空!");
		m_ed_yjjhjg.SetFocus();
		return;
	}
	else if(strYJJHJE.IsEmpty())
	{
		AfxMessageBox("进货金额不能为空!");
		m_ed_yjjhje.SetFocus();
		return;
	}
	else if( strYJJHSL.IsEmpty() )
	{
		AfxMessageBox( "进货数量不能为空!" );
		m_ed_yjjhsl.SetFocus();
		return;
	}
	else if ( strYJLSPH == "0"  && strYJJDID == "0" )
	{
		AfxMessageBox( "业绩类型为批货,接货代理商不能为空,请选择接货代理商!" );
		return;
	}

	try
	{
		strYJJLZT = "1";	//记录状态在刚录入的时候是有效的
		
		ltmp = atol( strYJJHJE.GetBuffer(0) );
		ltmp = ltmp * 100;					//金额要放大一百倍在保存
		strYJJHJE.Format( "%d", ltmp );
		ltmp = atol( strYJJHJG.GetBuffer(0) );
		ltmp = ltmp * 100;
		strYJJHJG.Format( "%d", ltmp );

		tabyj.YJYJID.strValue = strYJYJID;	//业绩ID                        Number( 10 )
		tabyj.YJCDID.strValue = strYJCDID;	//出代理号(出货代理商号码)      Number (10 )
		tabyj.YJJDID.strValue = strYJJDID;	//进代理号(进货代理商号码)      Number (10)
		tabyj.YJSPID.strValue = strYJSPID;	//商品ID(取SP表的SPSPID)        Number(10)
		tabyj.YJJHSJ.strValue = strYJJHSJ;	//销售时间                      Varchar2(8)
		tabyj.YJJHSL.strValue = strYJJHSL;	//销售数量                      Number(10)
		tabyj.YJJHJG.strValue = strYJJHJG;	//销售价格                      Number(10)
		tabyj.YJJHJE.strValue = strYJJHJE;	//销售金额                      Number(15)
		tabyj.YJJHKH.strValue = strYJJHKH;	//进货卡号(金、银、优惠)        Number(1)
		tabyj.YJLSPH.strValue = strYJLSPH;	//零售批货(1-零售,0为批货)    Number(1)
		tabyj.YJJSBZ.strValue = strYJJSBZ;	//结算标志(1-已结算,0-未结算)Number( 1 ) 
		tabyj.YJJLZT.strValue = strYJJLZT;	//记录状态(1-可用,0-不可用)  Number(1)
		tabyj.YJBZXX.strValue = strYJBZXX;	//备注信息                      Varchar2(64)

		tabyj.AppendRecord();
	}
	catch ( _com_error &e )
	{
		AfxMessageBox( e.ErrorMessage() );
		return;
	}

	AfxMessageBox( "数据保存成功!" );
	CDlgYJ::OnOK();
}


BOOL CDlgYJ::InitData()
{
	
	CTabYJ tabyj;
	CTabDL tabdl;
	CTabSP tabsp;
	CTabCS tabcs;
	_RecordsetPtr recordset;
	long count = 0;
	VARIANT var_value;
	CString strTmp;
	CString strDlid,strDlmc,strDlbh;
	CString strSpId,strSpmc,strSphm;
	HRESULT hr;
	Fields *fields = NULL;
	
	try
	{
		hr = recordset.CreateInstance( _uuidof(Recordset) );
		if(SUCCEEDED(hr))
		{
			_bstr_t query("select max( yjyjid ) + 1 from yj" );
			hr = recordset->Open(query,_variant_t((IDispatch*)connection,true),
				adOpenForwardOnly, adLockUnspecified/*adLockPessimistic*/,adCmdText );
			if(SUCCEEDED(hr))
			{
				recordset->get_Fields( &fields );
				count = fields->GetCount();
				
				if( count > 0 )
				{
					fields->Item[ long(0) ]->get_Value( &var_value );
					strTmp = VariantToString( var_value );
					if ( strTmp.IsEmpty() ) strTmp.Format( "%d",1);
					m_ed_yjyjid.SetWindowText( strTmp );
				}
			}
		}	
	}
	catch( _com_error &e)
	{
		AfxMessageBox( e.ErrorMessage() );
	}

	try
	{
		tabdl.Open( " WHERE DLJLZT <> 0 " );
		while( tabdl.IsOpen() && !tabdl.IsEOF() )
		{
			strDlid = tabdl.DLDLID.strValue;
			strDlmc = tabdl.DLDLMC.strValue;
			strDlbh = tabdl.DLDLBH.strValue;
			m_cb_yjcdid.SetItemData( m_cb_yjcdid.AddString( strDlbh + " " + strDlmc ),
				atol(strDlid.GetBuffer(0)) );
			m_cb_yjjdid.SetItemData( m_cb_yjjdid.AddString( strDlbh + " " + strDlmc ),
				atol(strDlid.GetBuffer(0)) );
			tabdl.MoveNext();
		}
		tabdl.Close();

		tabsp.Open(" WHERE SPJLZT <> 0 ");
		while( tabsp.IsOpen() && !tabsp.IsEOF() )
		{
			strSpId = tabsp.SPSPID.strValue;
			strSpmc = tabsp.SPSPMC.strValue;
			strSphm = tabsp.SPSPHM.strValue;
			m_cb_yjspid.SetItemData( m_cb_yjspid.AddString( strSphm + " " + strSpmc ),atol(strSpId.GetBuffer(0)) );

			tabsp.MoveNext();
		}
		tabsp.Close();

		tabcs.Open( " WHERE CSBMBM = 'XC' AND CSZDMC = 'XCTZKH' " );
		while( tabcs.IsOpen() && !tabcs.IsEOF() )
		{
			m_cb_yjjhkh.SetItemData( m_cb_yjjhkh.AddString( tabcs.CSQZMS.strValue ),
				atol( tabcs.CSZFQZ.GetValue() ) );
			tabcs.MoveNext();
		}
		tabcs.Close();
	}
	catch( _com_error &e )
	{
		AfxMessageBox( e.ErrorMessage() );
		return FALSE;
	}
	
	m_cb_yjlsph.SetItemData(m_cb_yjlsph.AddString("批货"),0 );
	m_cb_yjlsph.SetItemData(m_cb_yjlsph.AddString("零售"),1);
	m_cb_yjjsbz.SetItemData(m_cb_yjjsbz.AddString("未结算"),0);
	m_cb_yjjsbz.SetItemData(m_cb_yjjsbz.AddString("已结算"),1);
	m_cb_yjlsph.SetCurSel(0);
	m_cb_yjjsbz.SetCurSel(0);
	m_cb_yjspid.SetCurSel(0);
	m_cb_yjcdid.SetCurSel(0);
	m_cb_yjjdid.SetCurSel(1);
	m_cb_yjjhkh.SetCurSel(0);

	return TRUE;
}

void CDlgYJ::OnChangeEdYjjhsl() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	long   lJhsl  = 0;
	double fJhjg  = 0.00;
	double fJhje  = 0.00;
	CString strJhsl;
	CString strJhjg;
	CString strJhje;

	m_ed_yjjhsl.GetWindowText( strJhsl );
	m_ed_yjjhjg.GetWindowText( strJhjg );
	
	if ( strJhsl.IsEmpty() ) strJhsl = "0";
	if ( strJhjg.IsEmpty() ) strJhje = "0.00";

	lJhsl = atol( strJhsl.GetBuffer(0) );
	fJhjg = atof( strJhjg.GetBuffer(0) );
	fJhje = fJhjg * lJhsl;
	strJhje.Format( "%f", fJhje );
	m_ed_yjjhje.SetWindowText( strJhje );
	UpdateData();
	
}

void CDlgYJ::OnChangeEdYjjhjg() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	long lJhsl	  = 0;
	double fJhjg  = 0.00;
	double fJhje  = 0.00;
	CString strJhsl;
	CString strJhjg;
	CString strJhje;
	
	m_ed_yjjhsl.GetWindowText( strJhsl );
	m_ed_yjjhjg.GetWindowText( strJhjg );

	if ( strJhsl.IsEmpty() ) strJhsl = "0";
	if ( strJhjg.IsEmpty() ) strJhje = "0.00";

	lJhsl = atol( strJhsl.GetBuffer(0) );
	fJhjg = atof( strJhjg.GetBuffer(0) );
	fJhje = fJhjg * lJhsl;
	strJhje.Format( "%03f", fJhje );
	m_ed_yjjhje.SetWindowText( strJhje );
	
	UpdateData();	
}

void CDlgYJ::OnBtDefault() 
{
	keybd_event(9,0,0,0);	
}


void CDlgYJ::OnSelchangeCbYjlsph() 
{
	CString strTmp;
	int nIndex = 0;
	
	m_cb_yjlsph.GetWindowText( strTmp );
	
	//如果是零售的就把接货的代理商置为请选择
	if ( strTmp.Compare( "零售 " ) )
	{
		m_cb_yjjdid.SetItemData( m_cb_yjjdid.AddString("  "),0);
		nIndex = m_cb_yjjdid.GetCount();
		m_cb_yjjdid.SetCurSel(nIndex-1);
	}
}

BOOL CDlgYJ::InitMod()
{
	return FALSE;
}

⌨️ 快捷键说明

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