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

📄 configdoc.cpp

📁 一个简单的个人所得税计算器,可以编辑税率表和所在地列表.
💻 CPP
字号:
// ConfigDoc.cpp : implementation file
//

#include "stdafx.h"
#include "pitc.h"
#include "ConfigDoc.h"
#include "MainFrm.h"
#include "configViewCess.h"
#include "configViewArea.h"

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

//extern CString pathname;
/////////////////////////////////////////////////////////////////////////////
// CConfigDoc

IMPLEMENT_DYNCREATE(CConfigDoc, CDocument)

CConfigDoc::CConfigDoc()
{
}

BOOL CConfigDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;
	////
	static int count=1;
    char message[100];
	
    wsprintf (message,"%s%d","未命名的配置文件",count);
    SetTitle (message);
    count++;
	//////////////////////////
	m_arrArea.RemoveAll();
	m_arrStart.RemoveAll();
	m_arrFrom.RemoveAll();
	m_arrTo.RemoveAll();
	m_arrCess.RemoveAll();
	m_arrSub.RemoveAll();
	//pathname="";
    UpdateAllViews(NULL);
	return TRUE;
}

CConfigDoc::~CConfigDoc()
{
}


BEGIN_MESSAGE_MAP(CConfigDoc, CDocument)
	//{{AFX_MSG_MAP(CConfigDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConfigDoc diagnostics

#ifdef _DEBUG
void CConfigDoc::AssertValid() const
{
	CDocument::AssertValid();
}

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

/////////////////////////////////////////////////////////////////////////////
// CConfigDoc serialization

void CConfigDoc::Serialize(CArchive& ar)
{
	
	////
	int i,count_c,count_a;
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		////
		count_c=m_arrFrom.GetSize();
		ar<<count_c;
		for(i=0;i<count_c;i++)
		{
			ar<<m_arrFrom.GetAt(i);
			if (i<count_c-1)
			    ar<<m_arrTo.GetAt(i);
            ar<<m_arrCess.GetAt(i);
			ar<<m_arrSub.GetAt(i);
		}
		////
		count_a=m_arrArea.GetSize();
		ar<<count_a;
		for( i=0;i<count_a;i++)
		{
			ar<<m_arrArea.GetAt(i);
			ar<<m_arrStart.GetAt(i);
		}
	}
	else
	{
		// TODO: add loading code here
		m_arrFrom.RemoveAll();
		m_arrTo.RemoveAll();
		m_arrCess.RemoveAll();
		m_arrSub.RemoveAll();
		double d;
		CString str;
		ar>>count_c;
		for(i=0;i<count_c;i++)
		{
			ar>>d;
			m_arrFrom.Add(d);
			if (i<count_c-1)
			{
				ar>>d;
			    m_arrTo.Add(d);
			}
            ar>>d;
			m_arrCess.Add(d);
			ar>>d;
			m_arrSub.Add(d);
		}
		////
		m_arrArea.RemoveAll();
		m_arrStart.RemoveAll();
		ar>>count_a;
		for( i=0;i<count_a;i++)
		{
			ar>>str;
			m_arrArea.Add(str);
			ar>>d;
			m_arrStart.Add(d);
		}
		///

	}
}

/////////////////////////////////////////////////////////////////////////////
// CConfigDoc commands

BOOL CConfigDoc::Exam()
{

        CConfigViewCess *pViewCess;
		CConfigViewArea *pViewArea;
		CView *pView;
		POSITION pos=GetFirstViewPosition();
		while(pos)
		{
		    pView=GetNextView(pos);
			if(pView->IsKindOf(RUNTIME_CLASS(CConfigViewCess)))
			    pViewCess=(CConfigViewCess *)pView;
			else if(pView->IsKindOf(RUNTIME_CLASS(CConfigViewArea)))
			    pViewArea=(CConfigViewArea *)pView;
		}
		ASSERT(pViewArea!=NULL);
		ASSERT(pViewCess!=NULL);
        
		if( pViewCess->ExamCess() && pViewArea->ExamArea() )
		{
			return TRUE;
		}
		else
		{
			return FALSE;
		}

}

double CConfigDoc::ComputSub(int num)
{
	/*
	速算扣除数由系统根据税率表计算得到,方法如下:
设    N,表示级别数,N=1,2,3…
Vmin[N],表示第N级别的超过值
Vmax[N],表示第N级别的超过值
R[N],表示第N级别的税率
S[N],表示第N级别的速算扣除数

那么
                      i=1
S[N]=Vmin[N] * R[N] - Σ( ( Vmax[i]-Vmin[i] ) * R[i] )
                      i<N
*/
	//ASSERT(num>=2);
    double sub;
    if(num==1)
	{
		sub=0.00;
		return sub;
	}

	double temp=0.00;
	for(int i=0;i<num-1;i++)
	{ 
		temp=temp + ( (m_arrTo.GetAt(i)) - (m_arrFrom.GetAt(i)) ) * (m_arrCess.GetAt(i));
	}
	sub=(m_arrFrom.GetAt(num-1)) * (m_arrCess.GetAt(num-1)) - temp;

	return sub;

}



BOOL CConfigDoc::OnSaveDocument(LPCTSTR lpszPathName) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(!this->Exam())
		return FALSE;
	return CDocument::OnSaveDocument(lpszPathName);
}

BOOL CConfigDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	
	// TODO: Add your specialized creation code here
	//pathname=lpszPathName;
	SetPathName(lpszPathName,FALSE);
	UpdateAllViews(NULL);
	return TRUE;
}

⌨️ 快捷键说明

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