?? computview.cpp
字號:
// ComputView.cpp : implementation file
//
#include "stdafx.h"
#include "pitc.h"
#include "ComputView.h"
#include "ListCtrlArea.h"
#include "MainFrm.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CComputView
IMPLEMENT_DYNCREATE(CComputView, CFormView)
CComputView::CComputView()
: CFormView(CComputView::IDD)
{
//{{AFX_DATA_INIT(CComputView)
m_strArea = _T("");
m_dStart = 0.0;
m_dTotal = 0.0;
m_dTax = 0.0;
m_dDeduct = 0.0;
m_dAll = 0.0;
m_dGet = 0.0;
//}}AFX_DATA_INIT
}
CComputView::~CComputView()
{
}
void CComputView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CComputView)
DDX_Control(pDX, IDC_EDIT_TATOL, m_wndTatol);
DDX_Text(pDX, IDC_EDIT_AREA, m_strArea);
DDX_Text(pDX, IDC_EDIT_START, m_dStart);
DDX_Text(pDX, IDC_EDIT_TOTAL, m_dTotal);
DDX_Text(pDX, IDC_EDIT_TAX, m_dTax);
DDX_Text(pDX, IDC_EDIT_DEDUCT, m_dDeduct);
DDX_Text(pDX, IDC_EDIT_ALL, m_dAll);
DDX_Text(pDX, IDC_EDIT_GET, m_dGet);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CComputView, CFormView)
//{{AFX_MSG_MAP(CComputView)
ON_WM_CREATE()
ON_EN_CHANGE(IDC_EDIT_ALL, OnChangeEditAll)
ON_EN_CHANGE(IDC_EDIT_DEDUCT, OnChangeEditDeduct)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_UPDATE_AREA,OnUpdateArea)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CComputView diagnostics
#ifdef _DEBUG
void CComputView::AssertValid() const
{
CFormView::AssertValid();
}
void CComputView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CComputView message handlers
int CComputView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFormView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
return 0;
}
//響應(yīng)自定義的消息,用來更新顯示,有點麻煩,先不用它
void CComputView::OnUpdateArea(WPARAM wParam,LPARAM lParam)
{
//AfxMessageBox("receive!");
AREA_T *area_t;
area_t=(AREA_T*)lParam;
m_strArea=area_t->area;
m_dStart=area_t->start;
//UpdateData(FALSE);
GetDlgItem(IDC_EDIT_AREA)->SetWindowText(m_strArea);
CString str;
str.Format("%.2f",m_dStart);
GetDlgItem(IDC_EDIT_START)->SetWindowText(str);
}
void CComputView::Comput()
{
UpdateData(TRUE);
CString temp;
if(m_strArea=="")
{
AfxMessageBox("請選擇所在地!");
GetDlgItem(IDC_EDIT_AREA)->SetFocus();
return;
}
if(m_dStart<0)
{
AfxMessageBox("起征點應(yīng)>=0!");
GetDlgItem(IDC_EDIT_FROM)->SetFocus();
return;
}
if(m_dAll<0)
{
AfxMessageBox("代扣前工資薪金總額應(yīng)>=0!");
GetDlgItem(IDC_EDIT_ALL)->SetFocus();
return;
}
if(m_dDeduct<0)
{
AfxMessageBox("代扣金額應(yīng)>=0!");
GetDlgItem(IDC_EDIT_DEDUCT)->SetFocus();
return;
}
if(m_dTotal<0)
{
AfxMessageBox("稅前工資薪金總額應(yīng)>=0!");
GetDlgItem(IDC_EDIT_TOTAL)->SetFocus();
return;
}
double dAll;
dAll=((CPITCApp*)AfxGetApp())->Sswr(m_dAll,2);//保留2位小數(shù)
double dDeduct;
dDeduct=((CPITCApp*)AfxGetApp())->Sswr(m_dDeduct,2);//保留2位小數(shù)
double dTotal;
m_dTotal=dAll - dDeduct;
dTotal=((CPITCApp*)AfxGetApp())->Sswr(m_dTotal,2);
temp.Format("%.2f",dTotal);
GetDlgItem(IDC_EDIT_TOTAL)->SetWindowText(temp);
double dForTax,dStart;
dStart=((CPITCApp*)AfxGetApp())->Sswr(m_dStart,2);
dForTax=dTotal - dStart;//應(yīng)納稅所得額
dForTax=((CPITCApp*)AfxGetApp())->Sswr(dForTax,2);
m_dTax=0;
if(dForTax<=0)
{
GetDlgItem(IDC_EDIT_TAX)->SetWindowText("0.00");
return;
}
CMainFrame *pMain;
pMain=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
CListCtrlCess *pListCtrlCess;
pListCtrlCess=&(pMain->m_pConfigViewCess->m_wndListCtrlCess);
int count;
CString strFrom,strTo;
if(!(pMain->m_pConfigDoc->Exam()))//通過檢查后才能計算
{
return;
}
double dCess,dSub;
int i=0;
count=pMain->m_pConfigDoc->m_arrFrom.GetSize();
while(i<count && dForTax>pMain->m_pConfigDoc->m_arrFrom.GetAt(i))
{
i++;
}
dCess=(pMain->m_pConfigDoc->m_arrCess.GetAt(i-1))*0.01;
dSub=pMain->m_pConfigDoc->m_arrSub.GetAt(i-1);
//temp.Format("dTax=%f,dForTax=%f,dSub=%f",dCess,dForTax,dSub);
//AfxMessageBox(temp);
double dTax;
m_dTax=dForTax * dCess - dSub;
dTax=((CPITCApp*)AfxGetApp())->Sswr(m_dTax,2);////保留2位小數(shù)
temp.Format("%.2f",dTax);
GetDlgItem(IDC_EDIT_TAX)->SetWindowText(temp);
m_dGet=dTotal - dTax;
m_dGet=((CPITCApp*)AfxGetApp())->Sswr(m_dGet,2);////保留2位小數(shù)
temp.Format("%.2f",m_dGet);
GetDlgItem(IDC_EDIT_GET)->SetWindowText(temp);
///////////////
}
BOOL CComputView::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )
{
CMainFrame *pMainFrame;
pMainFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
////
CString temp;
CWnd *pWnd=this->GetFocus();
if (pWnd->GetDlgCtrlID()==IDC_EDIT_ALL)
{
//AfxMessageBox("OK!");
::SendMessage(pMainFrame->GetSafeHwnd(),WM_COMMAND,ID_COMPUT,NULL);
GetDlgItem(IDC_EDIT_DEDUCT)->SetFocus();
}
if(pWnd==GetDlgItem(IDC_EDIT_DEDUCT))
{
//AfxMessageBox("OK!");
::SendMessage(pMainFrame->GetSafeHwnd(),WM_COMMAND,ID_COMPUT,NULL);
GetDlgItem(IDC_EDIT_GET)->SetFocus();
}
}
return CFormView::PreTranslateMessage(pMsg);
}
void CComputView::UpdateDisplay()//更新顯示
{
CMainFrame *pMain;
CListCtrlArea *pList;
pMain=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pList=(CListCtrlArea *)(&(pMain->m_pConfigViewArea->m_wndListCtrlArea));
int count;
count=pList->GetSelectedCount();
if(count==0)
{
m_strArea="";
m_dStart=0.0;
m_dTax=0.0;
UpdateData(FALSE);
}
else
{
int m;
POSITION pos=pList->GetFirstSelectedItemPosition();
m=pList->GetNextSelectedItem(pos);
m_strArea=pList->GetItemText(m,0);
m_dStart=atof(pList->GetItemText(m,1));
m_dTax=0.0;
}
CString temp;
GetDlgItem(IDC_EDIT_AREA)->SetWindowText(m_strArea);
temp.Format("%.2f",m_dStart);
GetDlgItem(IDC_EDIT_START)->SetWindowText(temp);
GetDlgItem(IDC_EDIT_TAX)->SetWindowText("0.00");
GetDlgItem(IDC_EDIT_GET)->SetWindowText("0.00");
}
void CComputView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
GetDlgItem(IDC_EDIT_ALL)->SetWindowText("0.00");
GetDlgItem(IDC_EDIT_AREA)->SetWindowText("");
GetDlgItem(IDC_EDIT_START)->SetWindowText("0.00");
GetDlgItem(IDC_EDIT_TATOL)->SetWindowText("0.00");
GetDlgItem(IDC_EDIT_DEDUCT)->SetWindowText("0.00");
GetDlgItem(IDC_EDIT_TAX)->SetWindowText("0.00");
GetDlgItem(IDC_EDIT_GET)->SetWindowText("0.00");
}
void CComputView::OnChangeEditAll()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CFormView::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
// if(Examine(m_dAll,2)!=TRUE)
//return;
CString temp;
double dAll,dDeduct,dTotal;
GetDlgItem(IDC_EDIT_ALL)->GetWindowText(temp);
dAll=atof(temp);
dAll=((CPITCApp*)AfxGetApp())->Sswr(dAll,2);
//temp.Format("%.2f",dAll);
//dAll=atof(temp);//取2位小數(shù)
GetDlgItem(IDC_EDIT_DEDUCT)->GetWindowText(temp);
dDeduct=atof(temp);
dDeduct=((CPITCApp*)AfxGetApp())->Sswr(dDeduct,2);
//temp.Format("%.2f",dDeduct);
//dDeduct=atof(temp);
dTotal=dAll - dDeduct;
dTotal=((CPITCApp*)AfxGetApp())->Sswr(dTotal,2);
temp.Format("%.2f",dTotal);
GetDlgItem(IDC_EDIT_TOTAL)->SetWindowText(temp);
}
void CComputView::OnChangeEditDeduct()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CFormView::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString temp;
double dAll,dDeduct,dTotal;
GetDlgItem(IDC_EDIT_ALL)->GetWindowText(temp);
dAll=atof(temp);
temp.Format("%.2f",dAll);
dAll=atof(temp);//取2位小數(shù)
GetDlgItem(IDC_EDIT_DEDUCT)->GetWindowText(temp);
dDeduct=atof(temp);
temp.Format("%.2f",dDeduct);
dDeduct=atof(temp);
dTotal=dAll - dDeduct;
temp.Format("%.2f",dTotal);
GetDlgItem(IDC_EDIT_TOTAL)->SetWindowText(temp);
}
//檢查一個double是否滿足小于n位小數(shù)
BOOL CComputView::Examine(double d,int n)
{
CString str;
str.Format("%f",d);
int len;
len=str.GetLength();
if(str.Find(".")==-1)
{
return TRUE;
}
int i;
for(i=1;i<=n;i++)
{
if(str.Mid(len-i,1)==".")
{
return TRUE;
}
}
return FALSE;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -