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

📄 fvadratecalc.cpp

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

#include "stdafx.h"
#include "SellMan.h"
#include "FVAdRateCalc.h"

#include "TreeNode.h"

#include "TabXC.h"
#include "TabDL.h"
#include "TabSJ.h"
#include "TabSP.h"
#include "TabCS.h"
#include "TabJJ.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFVAdRateCalc

extern _ConnectionPtr connection;
extern BOOL bConnected;

IMPLEMENT_DYNCREATE(CFVAdRateCalc, CFormView)

CFVAdRateCalc::CFVAdRateCalc()
	: CFormView(CFVAdRateCalc::IDD)
{
	//{{AFX_DATA_INIT(CFVAdRateCalc)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CFVAdRateCalc::~CFVAdRateCalc()
{
}

void CFVAdRateCalc::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFVAdRateCalc)
	DDX_Control(pDX, IDC_BT_CLOSE, m_bt_close);
	DDX_Control(pDX, IDC_BT_CALC, m_bt_calc);
	DDX_Control(pDX, IDC_STATIC_START, m_static_start);
	DDX_Control(pDX, IDC_STATIC_END, m_static_end);
	DDX_Control(pDX, IDC_LIST_CHILD, m_list_child);
	DDX_Control(pDX, IDC_DT_START, m_dt_start);
	DDX_Control(pDX, IDC_DT_END, m_dt_end);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFVAdRateCalc, CFormView)
	//{{AFX_MSG_MAP(CFVAdRateCalc)
	ON_WM_DESTROY()
	ON_WM_SIZE()
	ON_BN_CLICKED(IDC_BT_CALC, OnBtCalc)
	ON_BN_CLICKED(IDC_BT_CLOSE, OnBtClose)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFVAdRateCalc diagnostics

#ifdef _DEBUG
void CFVAdRateCalc::AssertValid() const
{
	CFormView::AssertValid();
}

void CFVAdRateCalc::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFVAdRateCalc message handlers

void CFVAdRateCalc::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
	SetScrollSizes( MM_TEXT, CSize( 0, 0 ) );

	m_bt_calc.SetIcon( IDI_NEW );
	m_bt_close.SetIcon( IDI_EXIT16 );

	m_list_child.InsertColumn( 0, "编号", LVCFMT_LEFT, 70 );
	m_list_child.InsertColumn( 1, "姓名", LVCFMT_LEFT, 80 );
	m_list_child.InsertColumn( 2, "卡号", LVCFMT_LEFT, 80 );
	m_list_child.InsertColumn( 3, "单位数", LVCFMT_RIGHT, 70 );
	m_list_child.InsertColumn( 4, "宣传费", LVCFMT_RIGHT, 70 );
	m_list_child.InsertColumn( 5, "一部广告费", LVCFMT_RIGHT, 100 );
	m_list_child.InsertColumn( 6, "二部广告费", LVCFMT_RIGHT, 100 );
	m_list_child.InsertColumn( 7, "一部广告余额", LVCFMT_RIGHT, 100 );
	m_list_child.InsertColumn( 8, "二部广告余额", LVCFMT_RIGHT, 100 );

	HICON hIcon;
	m_imgList.Create (16, 16, true, 2, 1);
	hIcon= AfxGetApp()->LoadIcon ( IDI_MAN );
	m_imgList.Add (hIcon);
	m_list_child.SetImageList( &m_imgList, LVSIL_SMALL );
	m_list_child.SetExtendedStyle( LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES  );
	m_list_child.SetTextColor( RGB( 0, 0, 128 ) );

	SYSTEMTIME sysTime;
	memset( &sysTime, 0, sizeof( SYSTEMTIME ) );
	CTabCS tabcs;
	CString strTmp;

	try
	{
		if( tabcs.Open( "where csbmbm = 'TGJLJSRQ' and cszdmc = 'TGJLJSRQ'" ) )
		{
			strTmp = tabcs.CSZFQZ.GetValue();
			strTmp = DateAppendToString( strTmp, 1 );
			sysTime.wYear = atoi( strTmp.Left( 4 ) );
			strTmp.Delete( 0, 4 );
			sysTime.wMonth = atoi( strTmp.Left( 2 ) );
			strTmp.Delete( 0, 2 );
			sysTime.wDay = atoi( strTmp.Left( 2 ) );
			m_dt_start.SetTime( &sysTime );
		}
	}
	catch( _com_error &e )
	{
		AfxMessageBox( e.ErrorMessage() );
	}
	catch( ... )
	{
	}
	//m_dt_start.SetTime( &sysTime );
}

void CFVAdRateCalc::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
{
	AfxGetApp()->GetMainWnd()->SendMessage( WM_VIEW_ACTIVE, (WPARAM)this, (LPARAM)this );
	
	CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}

void CFVAdRateCalc::OnDestroy() 
{
	CFormView::OnDestroy();
	
	AfxGetApp()->GetMainWnd()->SendMessage( WM_VIEW_CLOSE, (WPARAM)this, (LPARAM)this );
}

void CFVAdRateCalc::OnSize(UINT nType, int cx, int cy) 
{
	CFormView::OnSize(nType, cx, cy);
	
	if( m_list_child.GetSafeHwnd() )
	{
		m_list_child.SetWindowPos( 0, 0, 0, cx, cy - 50, SWP_NOZORDER );
		m_static_start.SetWindowPos( 0, 10, cy - 30, 15, 20, SWP_NOZORDER );
		m_dt_start.SetWindowPos( 0, 35, cy - 35, 150, 20, SWP_NOZORDER );
		m_static_end.SetWindowPos( 0, 190, cy - 30, 15, 20, SWP_NOZORDER );
		m_dt_end.SetWindowPos( 0, 215, cy - 35, 150, 20, SWP_NOZORDER );
		m_bt_calc.SetWindowPos( 0, 375, cy - 40, 100, 30, SWP_NOZORDER );
		m_bt_close.SetWindowPos( 0, 485, cy - 40, 100, 30, SWP_NOZORDER );
	}
}

void CFVAdRateCalc::OnBtCalc() 
{
	int index = 0;
	long lAdRate1 = 0;
	long lAdRate2 = 0;
	long lRate1   = 0;
	long lRate2   = 0;
	long lRate    = 0;
	long lCount   = 0;
	long lTemp    = 0;
	long lBonus   = 0;

	char szSQL[ 255 ];
	CTwoForkTree twoTree;
	CTabXC tabxc;
	CTabJJ tabjj;
	CTabCS tabcs;
	CString strStartDate, strEndDate, strTmp;
	SYSTEMTIME sysTime;
	memset( &sysTime, 0, sizeof( SYSTEMTIME ) );

	m_dt_start.GetTime( &sysTime );
	strStartDate.Format( "%04d%02d%02d", sysTime.wYear, sysTime.wMonth, sysTime.wDay );
	m_dt_end.GetTime( &sysTime );
	strEndDate.Format( "%04d%02d%02d", sysTime.wYear, sysTime.wMonth, sysTime.wDay );

	if( DecDays( strEndDate, strStartDate ) != 10 )
	{
		if( AfxMessageBox( "日期范围不等于10天继续计算吗?", MB_YESNO | MB_ICONQUESTION ) == IDNO )
			return;
	}

	twoTree.ImportPlugger();

	try
	{
		m_list_child.DeleteAllItems();
		tabxc.Open( "order by xcygid" );
		while( tabxc.IsOpen() && !tabxc.IsEOF() )
		{
			index    = m_list_child.GetItemCount();
			lAdRate1 = twoTree.LeftDeptAccount( atol( tabxc.XCYGID.GetValue() ), strStartDate, strEndDate );
			lAdRate2 = twoTree.RightDeptAccount( atol( tabxc.XCYGID.GetValue() ), strStartDate, strEndDate );
			lRate	 = lAdRate1 > lAdRate2 ? lAdRate2 : lAdRate1;		// 按广告费小的部门算
			lCount	 = lRate / 200;			// 以200为单位的单位数
			lTemp    = lCount * 200;		// 
			lRate1   = lAdRate1 - lTemp;	// 一部广告余额
			lRate2   = lAdRate2 - lTemp;	// 二部广告余额
			lBonus   = lCount * 50;
			m_list_child.InsertItem( index, tabxc.XCYGBH.GetValue(), 0 );
			m_list_child.SetItemData( index, atol( tabxc.XCYGID.GetValue() ) );
			m_list_child.SetItemText( index, 1, tabxc.XCYGMC.GetValue() );
			m_list_child.SetItemText( index, 2, tabxc.XCTZKH.GetValue() );
			strTmp.Format( "%ld", lCount );
			m_list_child.SetItemText( index, 3, strTmp );
			strTmp.Format( "%ld", lBonus );
			m_list_child.SetItemText( index, 4, strTmp );
			strTmp.Format( "%ld", lAdRate1 );
			m_list_child.SetItemText( index, 5, strTmp );
			strTmp.Format( "%ld", lAdRate2 );
			m_list_child.SetItemText( index, 6, strTmp );
			strTmp.Format( "%ld", lRate1 );
			m_list_child.SetItemText( index, 7, strTmp );
			strTmp.Format( "%ld", lRate2 );
			m_list_child.SetItemText( index, 8, strTmp );
			tabxc.MoveNext();
		}

		lCount = m_list_child.GetItemCount();
		connection->BeginTrans();
		for( long i = 0; i < lCount; i ++ )
		{
			if( atol( m_list_child.GetItemText( i, 4 ) ) > 0 )
			{
				strTmp.Format( "%ld", tabjj.GetNextID( "JJLSID" ) );
				tabjj.JJLSID.strValue = strTmp;
				strTmp.Format( "%ld", (long)m_list_child.GetItemData( i ) );
				tabjj.JJYGBH.strValue = strTmp;
				tabjj.JJFFRQ.strValue = " ";
				tabjj.JJFFJE.strValue = m_list_child.GetItemText( i, 4 );
				tabjj.JJJJRX.strValue = "2";
				tabjj.JJHSDW.strValue = "200";
				tabjj.JJJLZT.strValue = "1";
				tabjj.JJJSDL.strValue = "0";
				tabjj.JJJSQR.strValue = strStartDate;
				tabjj.JJJSJR.strValue = strEndDate;
				tabjj.JJBZXX.strValue = " ";
				tabjj.AppendRecord();
			}
			sprintf( szSQL, "where xcygid = %ld", (long)m_list_child.GetItemData( i ) );
			if( tabxc.Open( szSQL ) )
			{
				tabxc.XCYBYE.strValue = m_list_child.GetItemText( i, 7 );
				tabxc.XCEBYE.strValue = m_list_child.GetItemText( i, 8 );
				tabxc.UpdateRecord();
			}
		}
		if( tabcs.Open( "where csbmbm = 'TGJLJSRQ' and cszdmc = 'TGJLJSRQ'" ) )
		{
			tabcs.CSZFQZ.strValue = strEndDate;
			tabcs.UpdateRecord();
		}
		connection->CommitTrans();
	}
	catch( _com_error &e )
	{
		connection->RollbackTrans();
		AfxMessageBox( e.ErrorMessage() );
	}
	catch( ... )
	{
	}
}

void CFVAdRateCalc::OnBtClose() 
{
	GetParentFrame()->SendMessage( WM_CLOSE );
}

⌨️ 快捷键说明

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