📄 calculatedlg.cpp
字号:
tempnum = m_pRecordset_Order->GetCollect("FoodPrice").lVal;
stemp.Format("%d",tempnum);
m_pRecordset_CalSignalInfo->PutCollect("money",_variant_t(stemp));
m_pRecordset_CalSignalInfo->Update();
}//if2
m_pRecordset_Order->MoveNext();
}//while1
}//if1
m_dbList.SetRefDataSource(NULL);
m_dbList.SetRefDataSource((LPUNKNOWN)m_pRecordset_CalSignalInfo);
m_dbList.SetColumnHeaders(2) ;
m_dbList.Refresh();
}
UpdateData(FALSE);
}
BOOL CCalculateDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_editStart.SetWindowText("00:00:00");
m_editEnd.SetWindowText("59:59:59");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCalculateDlg::OnCalPringBtn()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString startdate,enddate,starttime,endtime,sstart,send;
//获取日期/时间:转化为时间/日期格式
m_timectrlStart.GetWindowText(startdate);
startdate = Dateformat(startdate);
m_timectrlEnd.GetWindowText(enddate);
enddate = Dateformat(enddate);
m_editStart.GetWindowText(starttime);
m_editEnd.GetWindowText(endtime);
sstart = startdate +" "+ starttime;
send = enddate +" "+ endtime;
CDC dc;
//把打印设备环境附加到DC对象
CPrintDialog pdlg(FALSE,PD_NOPAGENUMS|PD_NOSELECTION,this);
BOOL bFindPrinter=pdlg.GetDefaults();
if(!bFindPrinter)
return ;
dc.Attach(pdlg.GetPrinterDC());
//取打印机的横方向和纵方向的分辨率
//即每英寸点数
short cxInch = dc.GetDeviceCaps(LOGPIXELSX);
short cyInch = dc.GetDeviceCaps(LOGPIXELSY);
//字体
CFont font;
VERIFY(font.CreatePointFont(96, "宋体", &dc));//为DC创建字体
CFont* def_font = dc.SelectObject(&font);//保存现在的字体
//根据字体宽度、高度计算每行最大字数及每页最大行数
//取打印纸张高度和宽度
int nPageHeight, nPageWidth;
nPageHeight = dc.GetDeviceCaps(VERTRES);
nPageWidth = dc.GetDeviceCaps(HORZRES);
TEXTMETRIC TextM;
dc.GetTextMetrics(&TextM);
//字体高度 //字体平均宽度
int nCharHeight = (unsigned short)TextM.tmHeight;
int nCharWidth=(unsigned short)TextM.tmAveCharWidth;
//每行最大字数 //每页最大行数
int m_MaxLineChar = nPageWidth / nCharWidth - 8;
int m_LinesPerPage = nPageHeight/ nCharHeight;
//页边距
int nXMargin = 2;
int nYMargin = 2;
//获得行数
int i;
//设置所需打印纸张数目
DOCINFO di;
di.cbSize = sizeof(DOCINFO);
if(m_nListSelect == 0)
di.lpszDocName = "CalTotal printing";
else if(m_nListSelect == 1)
di.lpszDocName = "CalSignal printing";
di.lpszOutput = (LPTSTR) NULL;
di.lpszDatatype = (LPTSTR) NULL;
di.fwType = 0;
dc.StartDoc(&di);
dc.StartPage();
if(m_nListSelect == 0)
{
//输出报表名称
CString stitle,sftitle,space="";
stitle="销售报表";
int n=(36-stitle.GetLength())/2;
for(i=0;i<n;i++)
space=space+" ";
sftitle=space+stitle;
dc.TextOut(2, nYMargin+nCharHeight,sftitle, strlen(sftitle));
//输出统计时间段
sstart= "开始时间:"+sstart;
send= "结束时间:"+send;
dc.TextOut( 2, nYMargin+nCharHeight*3, sstart, strlen(sstart));
dc.TextOut( 2, nYMargin+nCharHeight*4, send, strlen(send));
stitle="------------------------------------";
dc.TextOut( 2, nYMargin+nCharHeight*5, stitle, strlen(stitle));
//输出列表的列标题
CString slisttitle;
slisttitle="付款方式 数量 金额(元)";
dc.TextOut( 2, nYMargin+nCharHeight*6,slisttitle, strlen(slisttitle));
int nMaxLinePerPage = nPageHeight/nCharHeight -3;//每页最大行数
int nCurPage =1;
//输出各列的数据
//-------------------------//
CString sql;
sql = "SELECT * FROM CalInfo ";
m_pRecordset_CalInfo.CreateInstance("ADODB.Recordset");
m_pRecordset_CalInfo->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
int m_nLineCount = m_pRecordset_CalInfo->GetRecordCount();
//-------------------------//
CString name,acount,price,totalprice;//各种支付方式的综合
int totalacount=0;
i=0;
while(!m_pRecordset_CalInfo->adoEOF)
{
if(m_nLineCount+7-(nCurPage-1)*nMaxLinePerPage > nMaxLinePerPage)
{
//新的一页
dc.EndPage();
dc.StartPage();
nCurPage ++;
}
name = m_pRecordset_CalInfo->GetCollect("mode").bstrVal;
acount.Format("%d",m_pRecordset_CalInfo->GetCollect("checknum").lVal) ;
price.Format("%d",m_pRecordset_CalInfo->GetCollect("money").lVal);
totalacount += m_pRecordset_CalInfo->GetCollect("money").lVal;
totalprice.Format("%d",totalacount);
dc.TextOut( 2, nYMargin+(i+8-(nCurPage-1)*nMaxLinePerPage)*nCharHeight,
name, strlen(name));
dc.TextOut( 2+nCharWidth*15, nYMargin+(i+8-(nCurPage-1)*nMaxLinePerPage)*nCharHeight,
acount, strlen(acount));
dc.TextOut( 2+nCharWidth*23, nYMargin+(i+8-(nCurPage-1)*nMaxLinePerPage)*nCharHeight,
price, strlen(price));
m_pRecordset_CalInfo->MoveNext();
i++;
}
stitle="------------------------------------";
dc.TextOut( 2, nYMargin+(m_nLineCount+8-(nCurPage-1)*nMaxLinePerPage)*nCharHeight,
stitle, strlen(stitle));
totalprice = "总计:"+totalprice;
dc.TextOut( 2, nYMargin+(m_nLineCount+9-(nCurPage-1)*nMaxLinePerPage)*nCharHeight,
totalprice, strlen(totalprice));
}
else
{
//输出报表名称
CString stitle,sftitle,space="";
stitle="单品报表";
int n=(36-stitle.GetLength())/2;
for(i=0;i<n;i++)
space=space+" ";
sftitle=space+stitle;
dc.TextOut(2, nYMargin+nCharHeight,sftitle, strlen(sftitle));
//输出统计时间段
sstart= "开始时间:"+sstart;
send= "结束时间:"+send;
dc.TextOut( 2, nYMargin+nCharHeight*3, sstart, strlen(sstart));
dc.TextOut( 2, nYMargin+nCharHeight*4, send, strlen(send));
stitle="------------------------------------";
dc.TextOut( 2, nYMargin+nCharHeight*5, stitle, strlen(stitle));
//输出列表的列标题
CString slisttitle;
slisttitle="名称 数量 金额(元)";
dc.TextOut( 2, nYMargin+nCharHeight*7,slisttitle, strlen(slisttitle));
int nMaxLinePerPage = nPageHeight/nCharHeight -3;//每页最大行数
int nCurPage =1;
//输出各列的数据
//-------------------------//
CString sql;
sql = "SELECT * FROM CalSignalInfo ";
m_pRecordset_CalSignalInfo.CreateInstance("ADODB.Recordset");
m_pRecordset_CalSignalInfo->Open((_variant_t)sql,_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
int m_nLineCount = m_pRecordset_CalSignalInfo->GetRecordCount();
//-------------------------//
CString name,acount,price,totalprice;//各种支付方式的综合
int totalacount=0;
i=0;
while(!m_pRecordset_CalSignalInfo->adoEOF)
{
if(m_nLineCount+7-(nCurPage-1)*nMaxLinePerPage > nMaxLinePerPage)
{
//新的一页
dc.EndPage();
dc.StartPage();
nCurPage ++;
}
name = m_pRecordset_CalSignalInfo->GetCollect("name").bstrVal;
acount.Format("%d",m_pRecordset_CalSignalInfo->GetCollect("acount").lVal) ;
price.Format("%d",m_pRecordset_CalSignalInfo->GetCollect("money").lVal);
totalacount += m_pRecordset_CalSignalInfo->GetCollect("money").lVal;
totalprice.Format("%d",totalacount);
dc.TextOut( 2, nYMargin+(i+8-(nCurPage-1)*nMaxLinePerPage)*nCharHeight,
name, strlen(name));
dc.TextOut( 2+nCharWidth*15, nYMargin+(i+8-(nCurPage-1)*nMaxLinePerPage)*nCharHeight,
acount, strlen(acount));
dc.TextOut( 2+nCharWidth*23, nYMargin+(i+8-(nCurPage-1)*nMaxLinePerPage)*nCharHeight,
price, strlen(price));
m_pRecordset_CalSignalInfo->MoveNext();
i++;
}
stitle="------------------------------------";
dc.TextOut( 2, nYMargin+(m_nLineCount+8-(nCurPage-1)*nMaxLinePerPage)*nCharHeight,
stitle, strlen(stitle));
totalprice = "总计:"+totalprice;
dc.TextOut( 2, nYMargin+(m_nLineCount+9-(nCurPage-1)*nMaxLinePerPage)*nCharHeight,
totalprice, strlen(totalprice));
}
dc.EndPage();
dc.EndDoc();
//打印结束
//最后不要忘记将字体还原,这一句是必需的
dc.SelectObject(def_font); //恢复原来的字体
font.DeleteObject();
DeleteDC(dc.Detach());
return;// TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -