📄 lfswdlg.cpp
字号:
m_yys = atof(m_list.GetItemText(id,2));
m_grsds = atof(m_list.GetItemText(id,5));
UpdateData(false);
CString m_sl = m_list.GetItemText(id,8);
m_sl.Insert(0,'0');
((CComboBox*)GetDlgItem(IDC_SL))->SelectString(0,m_sl);
GetDlgItem(IDC_ADD)->EnableWindow(false);
*pResult = 0;
}
void ClfswDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CString m_sl;
GetDlgItem(IDC_SL)->GetWindowText(m_sl);
UpdateData(true);
if(m_sl != "0")
{
m_yyye = m_yys / atof(m_sl);
CString stryyye;
stryyye.Format("%0.2f",m_yyye);
m_yyye = atof(stryyye);
}
m_nyye = m_yyye*12;
if(m_grsds > 895.83)
m_ynse = (m_grsds*12+6750)/0.35;
if(m_grsds <= 895.83 && m_grsds > 395.83)
m_ynse = (m_grsds*12+4250)/0.3;
if(m_grsds <= 395.83 && m_grsds > 62.5)
m_ynse = (m_grsds*12+1250)/0.2;
if(m_grsds <= 62.5 && m_grsds > 20.83)
m_ynse = (m_grsds*12+250)/0.1;
if(m_grsds <= 20.83)
m_ynse = m_grsds*12/0.05;
if(m_grsds == 0)
m_ynse = 0;
CString strnnse;
strnnse.Format("%0.2f",m_ynse);
m_ynse = atof(strnnse);
m_nnse = m_ynse * 12;
UpdateData(false);
CDialog::OnMouseMove(nFlags, point);
}
void ClfswDlg::OnBnClickedPrintbj()
{
// TODO: 在此添加控件通知处理程序代码
if(m_list.GetItemCount()<= 0)
{
MessageBox("没有可打印的内容!","警告...",MB_ICONSTOP);
return;
}
PRNINFO PrnInfo = {0};
PrnInfo.hListView = m_list.m_hWnd;
PrnInfo.hWnd = this->m_hWnd;
PrnInfo.IsPrint = FALSE;
PrnInfo.nCurPage = 1;
PrnInfo.nMaxLine = m_list.GetItemCount();
PrnInfo.nCountPage = 0;
while(PrnInfo.nMaxLine>0)
{
PrnInfo.nCountPage++;
PrnInfo.nMaxLine -= A4_ONELINE;
}
memcpy(&PrnInfo, &PrnInfo, sizeof(PRNINFO));
// pDrawInfo = DrawInfo;
m_CountPage = PrnInfo.nCountPage; //共多少页
m_CurPage = PrnInfo.nCurPage; //当前页
if(MessageBox("决定打印当前报表吗?", "打印提示", MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) !=IDYES)
return;
HDC hdcPrint = GetDefaultPrinterDC();
if(hdcPrint == NULL)
{
MessageBox("打印机初始化失败!", "错误", MB_ICONSTOP);
return;
}
CDC MemDc;
MemDc.Attach(hdcPrint);
// if(DrawInfo!= NULL)
// {
PrnInfo.IsPrint = TRUE;
PrnInfo.nCurPage = m_CurPage;
PrnInfo.nMaxLine = m_CountPage;
// pDrawInfo(MemDc, PrnInfo);
// }
DrawInfo(MemDc,PrnInfo);
MemDc.DeleteDC();
}
HDC ClfswDlg::GetDefaultPrinterDC(void)
{
HDC hDC;
LPTSTR lpszPrinterName;
// Initialize variables
hDC = NULL;
lpszPrinterName = GetDefaultPrinterName();
if (lpszPrinterName != NULL)
{
hDC = GetPrinterDC(lpszPrinterName, NULL);
GlobalFree(lpszPrinterName);
}
else
{
DebugMsg(__TEXT("GetDefaultPrinterDC: Could not obtain default printer name.\r\n"));
}
return hDC;
}
LPTSTR ClfswDlg::GetDefaultPrinterName(void)
{
LPTSTR lpszDefaultPrinter = NULL;
if(IS_WIN95)
{
lpszDefaultPrinter = GetRegistryString(HKEY_CURRENT_CONFIG,
__TEXT("SYSTEM\\CurrentControlSet\\Control\\Print\\Printers"),
__TEXT("Default"));
}
else if (IS_NT)
{
TCHAR szTemp[MAX_PATH];
LPTSTR lpszTemp;
// Get Default printer name.
GetProfileString(__TEXT("windows"), __TEXT("device"), __TEXT(""),
szTemp, sizeof(szTemp));
if (lstrlen(szTemp) == 0)
{
// INVARIANT: no default printer.
return(NULL);
}
// Terminate at first comma, just want printer name.
lpszTemp = _tcschr(szTemp, ',');
if (lpszTemp != NULL)
{
*lpszTemp = '\x0';
}
lpszDefaultPrinter = CopyString((LPTSTR)szTemp);
}
return LPTSTR(lpszDefaultPrinter);
}
LPTSTR ClfswDlg::GetRegistryString(HKEY hKeyClass, LPTSTR lpszSubKey, LPTSTR lpszValueName)
{
// Local variables
HKEY hKey; // Registry key
LPTSTR lpszKeyValue; // Buffer for key name
DWORD dwKeySize; // Size of key value
DWORD dwKeyDataType; // Type of data stored in key
LONG lRC; // Return code
// Initialize variables
dwKeyDataType = 0;
dwKeySize = 0;
hKey = NULL;
lRC = RegOpenKey(hKeyClass, lpszSubKey, &hKey);
if (lRC != ERROR_SUCCESS)
{
return(NULL);
}
// Got key, get value. First, get the size of the key.
lRC = RegQueryValueEx(hKey, lpszValueName, NULL, NULL, NULL, &dwKeySize);
if (lRC != ERROR_SUCCESS)
{
return(NULL);
}
if (dwKeySize <= 1) // Registry will return "" if no printers installed
{
return(NULL);
}
lpszKeyValue = (LPTSTR)GlobalAlloc(GPTR, (++dwKeySize));
if (lpszKeyValue == NULL)
{
return(NULL);
}
lRC = RegQueryValueEx(hKey, lpszValueName, NULL, &dwKeyDataType, (LPBYTE)lpszKeyValue, &dwKeySize);
return LPTSTR(lpszKeyValue);
}
LPTSTR ClfswDlg::CopyString(LPTSTR lpszSrc)
{
LPTSTR lpszDest;
int iStrLen;
// Initialize variables
lpszDest = NULL;
if (lpszSrc == NULL)
{
DebugMsg(__TEXT("ICMVIEW.C : CopyString : lpszSrc == NULL\r\n"));
return(NULL);
}
iStrLen = ((int)(lstrlen(lpszSrc) +1) * sizeof(TCHAR));
lpszDest = (LPTSTR)GlobalAlloc(GPTR, iStrLen);
_tcscpy(lpszDest, lpszSrc);
return LPTSTR(lpszDest);
}
HDC ClfswDlg::GetPrinterDC(LPTSTR lpszFriendlyName, PDEVMODE pDevMode)
{
HDC hDC;
BOOL bFreeDevMode = FALSE;
// Initialize variables
hDC = NULL;
if (lpszFriendlyName != NULL)
{
// Make sure that we have a devmode.
if (NULL == pDevMode)
{
pDevMode = GetDefaultPrinterDevMode(lpszFriendlyName);
bFreeDevMode = TRUE;
}
// Now get a DC for the printer
hDC = CreateDC(NULL, lpszFriendlyName, NULL, pDevMode);
// Free devmode if created in routine.
if (bFreeDevMode)
{
GlobalFree((HANDLE)pDevMode);
}
}
else
{
DebugMsg(__TEXT("GetPrinterDC: lpszFriendlyName == NULL"));
}
return hDC;
// return HDC();
}
void ClfswDlg::DrawInfo(CDC &memDC, PRNINFO PrnInfo)
{
if(memDC.m_hDC == NULL)
return ;
int nCurPage = PrnInfo.nCurPage; //当前页
BOOL IsPrint = PrnInfo.IsPrint; //是否打印
int nMaxPage = PrnInfo.nCountPage; //最大页码
HWND hWnd = PrnInfo.hWnd;
HWND hList = PrnInfo.hListView;
CString csLFinality, csRFinality;
CTime time;
time=CTime::GetCurrentTime();
csLFinality = time.Format("报表日期:%Y-%m-%d");
csRFinality.Format("第 %i 页/共 %i 页", nCurPage, nMaxPage);
TCHAR szTitle[] = TEXT("报表");///打印标题
CRect rt[9];
CRect rc;
CPen cPen;
CFont TitleFont, DetailFont, *oldfont;
//标题字体
TitleFont.CreateFont(-MulDiv(14,memDC.GetDeviceCaps(LOGPIXELSY),48),
0,0,0,FW_NORMAL,0,0,0,GB2312_CHARSET,
OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,DRAFT_QUALITY,
VARIABLE_PITCH|FF_SWISS,_T("黑体"));
//细节字体
DetailFont.CreateFont(-MulDiv(10,memDC.GetDeviceCaps(LOGPIXELSY),72),
0,0,0,FW_NORMAL,0,0,0,GB2312_CHARSET,
OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,DRAFT_QUALITY,
VARIABLE_PITCH|FF_SWISS,_T("宋体"));
//粗笔
cPen.CreatePen(PS_SOLID, 2, RGB(0, 0, 0));
int xP = GetDeviceCaps(memDC.m_hDC, LOGPIXELSX); //x方向每英寸像素点数
int yP = GetDeviceCaps(memDC.m_hDC, LOGPIXELSY); //y方向每英寸像素点数
int xPix = (int)xP*10/254; //每 mm 宽度的像素
int yPix = (int)yP*10/254; //每 mm 高度的像素
int fAdd = 7*yPix; //每格递增量
int nTop = 25*yPix; //第一页最上线
int iStart = 0; //从第几行开始读取
int nBottom = nTop+A4_ONELINE*fAdd;
if(nCurPage != 1)
nTop = nTop-fAdd; //非第一页最上线
if(nCurPage == 2)
iStart = A4_ONELINE;//总行数
if(nCurPage>2)
iStart = A4_ONELINE+(nCurPage - 2)*A4_OTHERLINE;
int nLeft = 15*xPix; //最左线
int nRight = 1.88*xPix*(A4_W-20); //最右线
int nTextAdd = 2*xPix;
if(IsPrint)
{
//真正打印部分
static DOCINFO di = {sizeof (DOCINFO), szTitle} ;
//开始文档打印
if(memDC.StartDoc(&di)<0)
::MessageBox(hWnd, "连接到打印机化败!", "错误", MB_ICONSTOP);
else
{
iStart = 0;
nTop = 25*yPix; //第一页最上线
for(int iTotalPages = 1; iTotalPages<=nMaxPage; iTotalPages++)
{
int nCurPage = iTotalPages;
csRFinality.Format("第 %i 页/共 %i 页", nCurPage, nMaxPage);
time=CTime::GetCurrentTime();
csLFinality = time.Format("填报日期:%Y-%m-%d 填表人:");
csLFinality = csLFinality + theApp.realname;
// if(nCurPage != 1)
// nTop = 40*yPix-fAdd; //非第一页最上线
if(nCurPage == 2)
iStart = A4_ONELINE;
if(nCurPage>2)
iStart = A4_ONELINE+(nCurPage - 2)*A4_OTHERLINE;
//开始页
if(memDC.StartPage() < 0)
{
::MessageBox(hWnd, _T("打印失败!"), "错误", MB_ICONSTOP);
memDC.AbortDoc();
return;
}
else
{
//打印标题
oldfont = memDC.SelectObject(&TitleFont);
int nItem = A4_OTHERLINE;
// if(nCurPage == 1)
// {
nItem = A4_ONELINE;
rc.SetRect(0, yPix*10, A4_W*xPix*1.8, yPix*25);
memDC.DrawText(szTitle, &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
// }
//细节
memDC.SelectObject(&DetailFont);
rc.SetRect(nLeft, nTop, nRight, nTop+fAdd);
//上横线
memDC.MoveTo(rc.left, rc.top);
memDC.LineTo(rc.right, rc.top);
rt[0].SetRect(nLeft, nTop, nLeft+42*xPix, nTop+fAdd);
rt[1].SetRect(rt[0].right, rt[0].top, rt[0].right + 80*xPix, rt[0].bottom);
rt[2].SetRect(rt[1].right, rt[0].top, rt[1].right + 13*xPix, rt[0].bottom);
rt[3].SetRect(rt[2].right, rt[0].top, rt[2].right + 23*xPix, rt[0].bottom);
rt[4].SetRect(rt[3].right, rt[0].top, rt[3].right + 23*xPix, rt[0].bottom);
rt[5].SetRect(rt[4].right, rt[0].top, rt[4].right + 20*xPix, rt[0].bottom);
rt[6].SetRect(rt[5].right, rt[0].top, rt[5].right + 34*xPix, rt[0].bottom);
rt[7].SetRect(rt[6].right, rt[0].top, rt[6].right + 34*xPix, rt[0].bottom);
rt[8].SetRect(rt[7].right, rt[0].top, rc.right, rt[0].bottom);
memDC.DrawText("纳税人编号", &rt[0], DT_CENTER | DT_VCENTER | DT_SINGLELINE);
memDC.DrawText("纳税人名称", &rt[1], DT_CENTER | DT_VCENTER | DT_SINGLELINE);
memDC.DrawText("营业税", &rt[2], DT_CENTER | DT_VCENTER | DT_SINGLELINE);
memDC.DrawText("月营业额", &rt[3], DT_CENTER | DT_VCENTER | DT_SINGLELINE);
memDC.DrawText("年营业额", &rt[4], DT_CENTER | DT_VCENTER | DT_SINGLELINE);
memDC.DrawText("个人所得税", &rt[5], DT_CENTER | DT_VCENTER | DT_SINGLELINE);
memDC.DrawText("月应纳个人所得税", &rt[6], DT_CENTER | DT_VCENTER | DT_SINGLELINE);
memDC.DrawText("年应纳个人所得税", &rt[7], DT_CENTER | DT_VCENTER | DT_SINGLELINE);
memDC.DrawText("营业税率", &rt[8], DT_CENTER | DT_VCENTER | DT_SINGLELINE);
int i;
for(i=0;i<9;i++)
{
memDC.MoveTo(rt[i].right, rt[i].top);
memDC.LineTo(rt[i].right, rt[i].bottom);
}
memDC.MoveTo(rc.left, rt[0].bottom);
memDC.LineTo(rc.right, rt[0].bottom);
CString sz[9]={0};
rc.SetRect(nLeft, nTop+fAdd, nRight, nTop+2*fAdd);
rt[0].SetRect(nLeft+nTextAdd, rc.top, nLeft+42*xPix, rc.bottom);
rt[1].SetRect(rt[0].right+nTextAdd, rt[0].top, rt[0].right + 80*xPix, rt[0].bottom);
rt[2].SetRect(rt[1].right+nTextAdd, rt[0].top, rt[1].right + 13*xPix, rt[0].bottom);
rt[3].SetRect(rt[2].right+nTextAdd, rt[0].top, rt[2].right + 23*xPix, rt[0].bottom);
rt[4].SetRect(rt[3].right+nTextAdd, rt[0].top, rt[3].right + 23*xPix, rt[0].bottom);
rt[5].SetRect(rt[4].right+nTextAdd, rt[0].top, rt[4].right + 20*xPix, rt[0].bottom);
rt[6].SetRect(rt[5].right+nTextAdd, rt[0].top, rt[5].right + 34*xPix, rt[0].bottom);
rt[7].SetRect(rt[6].right+nTextAdd, rt[0].top, rt[6].right + 34*xPix, rt[0].bottom);
rt[8].SetRect(rt[7].right+nTextAdd, rt[0].top, rc.right + 29*xPix, rt[0].bottom);
int nCountItem = ListView_GetItemCount(hList);
for(int i=0;i<nItem; i++)
{
int j;
for(j=0;j<9;j++)
{
sz[j] = m_list.GetItemText(i+iStart,j);
}
for(j=0;j<9;j++)
memDC.DrawText(sz[j], &rt[j], DT_LEFT | DT_VCENTER | DT_SINGLELINE);
memDC.MoveTo(rc.left, rc.bottom);//下横线
memDC.LineTo(rc.right, rc.bottom);
for(j=0;j<9;j++)
{
memDC.MoveTo(rt[j].right, rt[j].top);
memDC.LineTo(rt[j].right, rt[j].bottom);
}
rc.top += fAdd;
rc.bottom += fAdd;
for(j=0;j<9;j++)
{
rt[j].top = rc.top;
rt[j].bottom = rc.bottom;
}
if((i+iStart+1)>=nCountItem)
break;
}
//结尾
memDC.MoveTo(rc.left, nTop);
memDC.LineTo(rc.left, rc.top);
memDC.MoveTo(rc.right, nTop);
memDC.LineTo(rc.right, rc.top);
memDC.DrawText(csLFinality, &rc, DT_LEFT| DT_VCENTER | DT_SINGLELINE);
memDC.DrawText(csRFinality, &rc, DT_RIGHT| DT_VCENTER | DT_SINGLELINE);
memDC.EndPage();
memDC.SelectObject(oldfont);
}
}
memDC.EndDoc();
}
}
TitleFont.DeleteObject();
DetailFont.DeleteObject();
cPen.DeleteObject();
}
PDEVMODE ClfswDlg::GetDefaultPrinterDevMode(LPTSTR lpszPrinterName)
{
LONG lDevModeSize;
HANDLE hDevMode;
PDEVMODE pDevMode = NULL;
lDevModeSize = DocumentProperties(NULL, NULL, lpszPrinterName, NULL, NULL, 0);
if (lDevModeSize > 0)
{
hDevMode = GlobalAlloc(GHND, lDevModeSize);
pDevMode = (PDEVMODE) GlobalLock(hDevMode);
DocumentProperties(NULL, NULL, lpszPrinterName, pDevMode, NULL, DM_OUT_BUFFER);
}
else
{
DebugMsg(__TEXT("GetDefaultPrinterDevMode: Could not obtain printer's devmode.\r\n"));
}
return pDevMode;
}
void ClfswDlg::DebugMsg(LPTSTR lpszMessage,...)
{
#ifdef _DEBUG
va_list VAList;
TCHAR szMsgBuf[256];
// Pass the variable parameters to wvsprintf to be formated.
va_start(VAList, lpszMessage);
wvsprintf(szMsgBuf, lpszMessage, VAList);
va_end(VAList);
ASSERT(lstrlen((LPTSTR)szMsgBuf) < MAX_DEBUG_STRING);
OutputDebugString(szMsgBuf);
#endif
lpszMessage = lpszMessage; // Eliminates 'unused formal parameter' warning
}
void ClfswDlg::OnBnClickedAboutLfsw()
{
// TODO: 在此添加控件通知处理程序代码
CAboutDlg dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -