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

📄 loaddlg.cpp

📁 一个利率计算问题
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		else if( n>1)
			a = (n-1)*A/N;
		else
			AfxMessageBox("parameter error!");
	}
}

void CLoadDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	if(m_ctrlEdit3.GetStyle() & ES_READONLY)
		m_ctrlEdit3.SetReadOnly(FALSE);
	else
	{
		CString str;
		m_ctrlEdit3.GetWindowText(str);
		if(str == "")
		{
			AfxMessageBox("Interest data error!");
			return;
		}
		m_fcurInterest = atof(str.GetBuffer(str.GetLength()));

		m_ctrlEdit3.SetReadOnly();
	}
}

void CLoadDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
	HANDLE h = ::GetCurrentProcess();
	::TerminateProcess(h, 1);		
}

void CLoadDlg::OnCheck1() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
}

void CLoadDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	CString strTemp;
	m_ctrlEdit3.GetWindowText(strTemp);
	if(strTemp == "")
	{
		AfxMessageBox("Current interest data error!");
		return;
	}
	
	m_ctrlEdit4.GetWindowText(strTemp);
	if(strTemp == "")
	{
		AfxMessageBox("Current date data error!");
		return;
	}

	Record r;
	r.currDate = atoi(strTemp.GetBuffer(strTemp.GetLength()));
	if((r.currDate%100 > 12) || (r.currDate%100 < 0))
	{
		AfxMessageBox("Current date data error!");
		return;		
	}

	if(m_arrRecords.GetSize() == 0)
	{
		r.startDate = m_nStartDate;
		if((r.startDate%100 > 12) || (r.startDate%100 < 0))
		{
			AfxMessageBox("Current date data error!");
			return;		
		}

		r.interest = m_fcurInterest;
		r.corpus = m_fAmount;
		r.tolalMonth = 20*12;
//		r.tolalMonth = 10*12;

		int n = (r.currDate/100-r.startDate/100)*12 + (r.currDate%100-r.startDate%100+1);
		if((n>r.tolalMonth) || (n<0))
		{
			AfxMessageBox("Current date data error!");
			return;	
		}

		for(int i=0;i<n;++i)
		{
			Compute(r.corpus, r.interest*0.01, r.tolalMonth, i+1, r.pay, r.passCorpus);

			int Y = r.startDate/100;
			int M = r.startDate%100+i;
			if(M > 12)
			{
				Y += M/12;
				M = M%12;

				if(M == 0)
				{	Y -= 1;
					M = 12;
				}
			}

			r.currDate = Y*100+M;
			m_arrRecords.Add(r);
		}

		count = m_arrRecords.GetSize();
	}
	else
	{
		if(r.currDate <= m_arrRecords[m_arrRecords.GetSize()-1].currDate)
		{
			count = 0;
			for(int i=0;i<m_arrRecords.GetSize();++i)
			{
				if(r.currDate == m_arrRecords[i].currDate)
				{
					count = i+1;
					break;
				}
			}
			
			if(count <= 0)
			{
				AfxMessageBox("Current date data error!");
				return;				
			}
		}
		else
		{
			if(m_arrRecords[m_arrRecords.GetSize()-1].interest == m_fcurInterest)
			{
				r.interest = m_fcurInterest;
				r.corpus = m_arrRecords[m_arrRecords.GetSize()-1].corpus;
				r.tolalMonth = m_arrRecords[m_arrRecords.GetSize()-1].tolalMonth;
				r.startDate = m_arrRecords[m_arrRecords.GetSize()-1].startDate;

				if((r.startDate%100 > 12) || (r.startDate%100 < 0))
				{
					AfxMessageBox("Current date data error!");
					return;		
				}

				int n = (r.currDate/100-r.startDate/100)*12 + (r.currDate%100-r.startDate%100+1);
				if((n>r.tolalMonth) || (n<0))
				{
					AfxMessageBox("Current date data error!");
					return;	
				}

				int startY = m_arrRecords[m_arrRecords.GetSize()-1].currDate/100;
				int startM = m_arrRecords[m_arrRecords.GetSize()-1].currDate%100;

				int n1 = (startY-r.startDate/100)*12 + (startM-r.startDate%100+1);
				if((n1>r.tolalMonth) || (n1<0))
				{
					AfxMessageBox("date data error!");
					return;	
				}

				for(int i=n1;i<n;++i)
				{
					Compute(r.corpus, r.interest*0.01, r.tolalMonth, i+1, r.pay, r.passCorpus);

					int Y = r.startDate/100;
					int M = r.startDate%100+i;
					if(M > 12)
					{
						Y += M/12;
						M = M%12;
						if(M == 0)
						{	Y -= 1;
							M = 12;
						}
					}

					r.currDate = Y*100+M;
					m_arrRecords.Add(r);
				}
			}
			else
			{
				r.interest = m_fcurInterest;			
				r.corpus = m_arrRecords[m_arrRecords.GetSize()-1].corpus-m_arrRecords[m_arrRecords.GetSize()-1].passCorpus;
				r.tolalMonth = m_arrRecords[m_arrRecords.GetSize()-1].tolalMonth - m_arrRecords.GetSize();

				int Y = m_arrRecords[m_arrRecords.GetSize()-1].currDate/100;
				int M = m_arrRecords[m_arrRecords.GetSize()-1].currDate%100+1;
				if(M>12)
				{
					Y += M/12;
					M = M%12;
					if(M == 0)
					{	Y -= 1;
						M = 12;
					}

				}
				r.startDate = Y*100+M;

				if((r.startDate%100 > 12) || (r.startDate%100 < 0))
				{
					AfxMessageBox("Current date data error!");
					return;		
				}
				
				int n = (r.currDate/100-r.startDate/100)*12 + (r.currDate%100-r.startDate%100+1);
				if((n>r.tolalMonth) || (n<0))
				{
					AfxMessageBox("Current date data error!");
					return;	
				}

				for(int i=0;i<n;++i)
				{
					Compute(r.corpus, r.interest*0.01, r.tolalMonth, i+1, r.pay, r.passCorpus);

					int Y = r.startDate/100;
					int M = r.startDate%100+i;
					if(M > 12)
					{
						Y += M/12;
						M = M%12;
						if(M == 0)
						{	Y -= 1;
							M = 12;
						}
					}

					r.currDate = Y*100+M;
					m_arrRecords.Add(r);
				}		
			}

			count = m_arrRecords.GetSize();
		}
	}
	
	strTemp.Format("%.2f", m_arrRecords[count-1].pay);
	m_ctrlEdit5.SetWindowText(strTemp);

	strTemp.Format("%.2f", m_arrRecords[count-1].passCorpus);
	m_ctrlEdit6.SetWindowText(strTemp);

	if(m_arrRecords.GetSize() > 1)
		strTemp.Format("%.2f", m_arrRecords[count-2].pay-m_arrRecords[count-1].pay);
	else 
		strTemp.Format("%.2f", 0.0);
	m_ctrlEdit7.SetWindowText(strTemp);

////////////////////////////////////////////////////
////write the file
	char* pFileName = "load.txt";
	CStdioFile f;
	if(!f.Open(pFileName, CFile::modeCreate|CFile::modeWrite|CFile::typeText)) 
	{
	   #ifdef _DEBUG
		  AfxMessageBox("Unable to open file");
	   #endif

	   exit( 1 );
	}

	for(int i=0;i<m_arrRecords.GetSize();++i)
	{
		CString s;
		StruStr(s, m_arrRecords[i], 1);
		f.WriteString(s);
	}
	f.Close();

/////////////////////////////////////////////////////////
/////Update UI
	m_ctrlTarget.DeleteAllItems();

	for(i=0;i<count;++i)
	{
		CString strTemp;

		strTemp.Format("%d", m_arrRecords[i].startDate);
		int ret = m_ctrlTarget.InsertItem(i,strTemp,0);

		strTemp.Format("%.d", m_arrRecords[i].currDate);
		m_ctrlTarget.SetItemText(ret, 1, strTemp);		

		strTemp.Format("%.2f", m_arrRecords[i].corpus);
		m_ctrlTarget.SetItemText(ret, 2, strTemp);		

		strTemp.Format("%.2f", m_arrRecords[i].passCorpus);
		m_ctrlTarget.SetItemText(ret, 3, strTemp);

		strTemp.Format("%d", m_arrRecords[i].tolalMonth);
		m_ctrlTarget.SetItemText(ret, 4, strTemp);

		strTemp.Format("%.2f", m_arrRecords[i].interest);
		m_ctrlTarget.SetItemText(ret, 5, strTemp);		

		strTemp.Format("%.2f", m_arrRecords[i].pay);
		m_ctrlTarget.SetItemText(ret, 6, strTemp);

		if(i>0)
			strTemp.Format("%.2f", m_arrRecords[i-1].pay-m_arrRecords[i].pay);
		else
			strTemp.Format("%.2f", 0.0);
		m_ctrlTarget.SetItemText(ret, 7, strTemp);

		strTemp.Format("%d", i+1);
		m_ctrlTarget.SetItemText(ret, 8, strTemp);
	}

	m_ctrlTarget.SetFocus();
	m_ctrlTarget.SetItem(count-1, 0, LVIF_STATE, NULL, 0, LVIS_SELECTED, 
      LVIS_SELECTED, 0);
}

⌨️ 快捷键说明

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