📄 datawin.cpp
字号:
}
OnPrintEnd(); //结束打印
MemDC.EndDoc();
m_dataPn.clear();
m_RecordSet.Move((long)m_nPage);
//m_RecordSet.Move((long)0, CAdoRecordSet::adBookmarkFirst); //返回当前位置
err01:
m_dataPn.clear();
// m_bIsPrint = FALSE;
MemDC.DeleteDC();
//m_RecordSet.Move((long)0, CAdoRecordSet::adBookmarkFirst); //返回当前位置
m_RecordSet.Move((long)m_nPage);
return bReturn;;
}
//////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
BOOL CDataWin::OnPrintStart()
{
return TRUE;
}
void CDataWin::OnPrintEnd()
{
return ;
}
BOOL CDataWin::OnPageStart(BOOL bIsPrint)
{
return TRUE;
}
void CDataWin::OnPageEnd(BOOL bIsPrint)
{
return ;
}
BOOL CDataWin::OnCellStart(CDataCell *pData, BOOL bIsPrint)
{
return TRUE;
}
void CDataWin::OnCellEnd(CDataCell *pData, BOOL bIsPrint)
{
return ;
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
void CDataWin::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
if(m_pGraphic == m_pGraphic)
{
if(m_pGraphic) delete m_pGraphic;
}
else
{
if(m_pGraphic) delete m_pGraphic;
if(m_pGraphicPn) delete m_pGraphicPn;
}
m_bkBitmap.DeleteObject();
m_MemDC.DeleteDC();
m_Font.Detach();
ResetAll();
}
void CDataWin::ResetAll()
{
// fnDelClassChild();
m_data.clear();
m_dataHead.clear();
m_dataBody.clear();
m_dataEnd.clear();
m_dataFoot.clear();
}
//修改窗口为必要的风格
void CDataWin::InitBase()
{
ModifyStyle(WS_CAPTION,WS_CHILD);
CPaintDC dc(this); // device context for painting
int xP = dc.GetDeviceCaps(LOGPIXELSX);
int yP = dc.GetDeviceCaps(LOGPIXELSY);
m_xPix = (DOUBLE)xP*10/254; //每 mm 宽度的像素
m_yPix = (DOUBLE)yP*10/254; //每 mm 高度的像素
// m_xPix = 1;
// m_yPix = 1;
SetPage("A4", false); //显示尺寸
}
//从IDE窗口创建结构
BOOL CDataWin::Init4Control()
{
CRect Rect[4], rect;
CRect rtClient;
CString strSQL;
int nPoint;
CPreDialog dlg;
//标题是默认SQL
GetWindowText(m_strDefSQL);
//取出三条进度条
dlg.Enum(this);
PDATAWINDOWVIEW pData = dlg.GetControl();
GetClientRect(&rtClient);
for (nPoint = 1;pData && nPoint <= 3; nPoint++)
{
pData = dlg.fnGetClassChild(pData, 0, "msctls_progress32");
if(!pData) break;
::SendMessage(pData->hWnd,WM_CLOSE,FALSE,0);//隐藏
Rect[nPoint] = pData->Rect;
pData = pData->pNext;
// ::SendMessage(pData->hWnd,WM_SETREDRAW,FALSE,0);//隐藏
}
if(nPoint != 4)
{
//AfxMessageBox("注意:数据窗口格式错误!!!");
//return FALSE;
m_bSimple = true; //简单表格,一行一页
}
else
{
m_bSimple = false; //类似CListCtrl
}
//排序
for (int i = 1; i < 3 ; i++)
{
for(int j = i+1; j <= 3; j++)
if(Rect[i].top > Rect[j].top)
{
Rect[0] = Rect[i];
Rect[i] = Rect[j];
Rect[j] = Rect[0];
}
}
ScreenToClient(&Rect[1]);
ScreenToClient(&Rect[2]);
ScreenToClient(&Rect[3]);
//计算各区域的高度
if(m_bSimple == false)
{
m_nHead = Rect[1].top;
m_nCellHeight = Rect[2].top - Rect[1].bottom;
m_nEnd = Rect[3].top- Rect[2].bottom;
m_nFoot = rtClient.bottom-Rect[3].bottom;
}
else
{
m_nHead = 0;
m_nCellHeight = rtClient.Height();
m_nEnd = 0;
m_nFoot = 0;
}
//清空
m_dataHead.clear();
m_dataBody.clear();
m_dataEnd.clear();
m_dataFoot.clear();
//转换窗口结构
CDataCell Cell; //临时结构
// pData = m_pDataWindow;
pData = dlg.GetControl();
//初始化表格构
for (;pData != NULL;pData = pData->pNext)
{
Cell.Reset();
if(!lstrcmpi(pData->szType, "msctls_progress32")) continue;
rect = pData->Rect;
ScreenToClient(&rect);
Cell.Rect = rect;
Cell.dwStyle = pData->dwStyle;
Cell.strType = pData->szType;
Cell.nID = pData->nID;
Cell.strName = pData->szName;
Cell.strText = Cell.strName;
Cell.hWnd = pData->hWnd;
Cell.strType = pData->szType;
Cell.dwStyleEx = pData->dwStyleEx;
if(m_Font.m_hObject == NULL)
Cell.pFont = GetFont();
else
Cell.pFont = &m_Font;
if(pData->szName && pData->szName[0] == '=')
Construe(&Cell, pData->szName); //语法分析
// ::SendMessage(pData->hWnd,WM_SETREDRAW,FALSE,0);//隐藏
::SendMessage(pData->hWnd,WM_CLOSE, 0, 0);//关闭
if(m_bSimple== TRUE) //简单表体
{
//Cell.Rect.top -= Rect[1].Height();
//Cell.Rect.bottom -= Rect[1].Height();
m_dataBody.push_back(Cell);
}
else if(rect.top < Rect[1].top) //页头
{
m_dataHead.push_back(Cell);
}
else if(rect.top >= Rect[2].bottom &&
rect.top <= Rect[3].top) //表尾
{
int nHeight = rect.bottom-rect.top;
Cell.Rect.top = rect.top-Rect[2].bottom+m_nHead;
Cell.Rect.bottom = Cell.Rect.top + nHeight;
m_dataEnd.push_back(Cell);
}
else if(rect.top >= Rect[3].bottom)//页尾
{//位置转换
Cell.Rect.bottom=rtClient.bottom-rect.bottom;
Cell.Rect.top=Cell.Rect.bottom-rect.Height();
m_dataFoot.push_back(Cell);
}
else //表体
{
Cell.Rect.top -= Rect[1].Height();
Cell.Rect.bottom -= Rect[1].Height();
m_dataBody.push_back(Cell);
}
}
return TRUE;
}
/*
///////////////////////////////////////////////////////////
//打印数据表
BOOL CDataWin::Open(CString &strSQL)
{
m_RecordSet.SetAdoConnection(m_pConnection); //连结数据库
m_RecordSet.SetCursorLocation(); //作者例程,不知有什么用
return m_RecordSet.Open(strSQL,adCmdText, //SQL为TXT
adOpenStatic, //静态游标
adLockReadOnly); //只读
// return m_RecordSet.Open(strSQL, adCmdText);
}
*/
///////////////////////////////////////////////////////////
//从数据库导入一页数据
BOOL CDataWin::UpdateRecord(BOOL bIsPrint)
{
if(bIsPrint)
m_dataPn.clear();
else
m_data.clear(); //清空
// m_RecordSet.SetSQLText(m_strDefSQL);
// if(!m_RecordSet.Update()) return FALSE;
CDataCell data;
CString str;
CString strName;
//m_RecordSet.MoveFirst();
// for(int i = 0; i < m_RecordSet.GetRecordCount() &&
// i < m_nCellMax ; i++)//所有记录
for(int i = 0; m_RecordSet.IsEOF() == FALSE &&
i < m_nCellMax ; i++)//所有记录
{
if(i == 0) m_nCell = 0; //统计单行的列项数目
for (int k = 0; k < m_dataBody.size(); k++)
{//所有窗口设定
data = m_dataBody.at(k);
if(data.dwCommand & PNS_DATABASE)
{
m_RecordSet.GetCollect(data.strName, data.strText);
if(bIsPrint)
m_dataPn.push_back(data);
else
m_data.push_back(data);
if(i == 0) m_nCell++; //统计单行的列项数目
}//end if
/*data = m_dataBody.at(k);
strName = data.strName;
strName.TrimLeft();
if(strName.GetLength()>0 && strName.GetAt(0)=='=')
{//第一个为=等号,去除等号和空格
strName = strName.Right(strName.GetLength()-1);
strName.TrimLeft(); strName.TrimRight();
for (int j = 0; j < m_RecordSet.GetFieldsCount(); j++)
{//所有项目
str = m_RecordSet.GetFieldName(j);
if(str == strName) //正确
{
if(i==0)
{
m_nCell++; //计算一行内有多少个数据项目
m_dataBody.at(k).dwCommand = PNS_DATABASE; //标志为数据库项目
data.dwCommand = PNS_DATABASE;
}
data.strName = strName;
data.strText = _T("");;
if(m_RecordSet.GetCollect(strName, str))
data.strText = str;
m_data.push_back(data);
break;
}//end if
}//end for
}//end if
*/
}//end for
m_RecordSet.MoveNext();
}//end for
//CalSize(m_RectPage, m_xPix, m_yPix); //重新计算页面
return TRUE;
}
//////////////////////////////////////////////
//1)计算每页可显示的表体项目
//2)设置VSCROLL,HSCROLL是固定的
void CDataWin::CalSize(CRect rect,DOUBLE xPix, DOUBLE yPix, BOOL bIsPrint)
{
int nMaxPage =1, nMaxCell = 0;
int nCount = m_RecordSet.GetRecordCount();
if(m_bSimple == TRUE) //简单模式
{
nMaxPage = nCount; //总页数为总项目数
nMaxCell = 1; //每页项目数1
goto exit01;
}
if (!bIsPrint && !GetPrintView()) //非模似显示
{
nMaxPage = 1; //总页数为1
nMaxCell = nCount; //每页总项目数
goto exit01;
}
//除去页头、页尾高度
rect.top += CalMulInt(m_nHead,yPix);
rect.bottom-=CalMulInt(m_nFoot,yPix);
if(m_nCellHeight > 0) //行高
{
nMaxCell = rect.Height()/CalMulInt(m_nCellHeight, yPix);
if(nMaxCell > 0) //每页最大项目数
{
nMaxPage = nCount/nMaxCell; //总页数
int less = nCount%nMaxCell; //有除下项目,总页数加1
if(less) nMaxPage++;
//项目余下的空位不足显示表脚,总页数加1
less = less * CalMulInt(m_nCellHeight,yPix);
if(less + m_nEnd > rect.Height()) nMaxPage++;
}
}
exit01:
if(bIsPrint)
{
m_nPageMaxPn = nMaxPage;
m_nCellMaxPn = nMaxCell;
if(m_nPagePn>nMaxPage-1)m_nPagePn=nMaxPage-1;
}
else
{
m_nPageMax = nMaxPage;
m_nCellMax = nMaxCell;
if(m_nPage>nMaxPage-1)m_nPage=nMaxPage-1;
CalScrollbar(); //设置滚动条,只对显示有效
}
}
////////////////////////////////////////////////////////////////
//设置滚动条
void CDataWin::CalScrollbar(void)
{
//设定滚动条垂直滚动范围及页面大小
int nTotal=0, nMax = 0;
SCROLLINFO si;
CRect rtClient;
GetClientRect(rtClient);
if(m_bIsPrintView)
{//模拟显示,上+1行
nTotal ++; //总行数
if(rtClient.bottom>rtClient.top)
{
nMax ++; //可显示最大行数
rtClient.top += m_nFrameH;
}
}
if(m_nHead>0)
{//有页头
nTotal ++;
if(rtClient.bottom>rtClient.top)
{
nMax++; //有页头+1
rtClient.top += m_nHead;
}
}
nTotal += m_nCellMax; //+每页最大行数
if (rtClient.Height() > m_nCellMax*m_nCellHeight)
{
nMax += m_nCellMax;
rtClient.top += m_nCellMax*m_nCellHeight;
}
else
{
nMax += rtClient.Height()/m_nCellHeight;
if(rtClient.Height()%m_nCellHeight) nMax--;
rtClient.top = rtClient.bottom;
}
if(m_nFoot>0)
{
nTotal ++;
if(rtClient.bottom>rtClient.top)
{
nMax++; //有页尾+1
rtClient.top += m_nFoot;
}
}
if(m_bIsPrintView)
{//模拟显示,下+1行
nTotal ++; //总行数
if(rtClient.bottom>rtClient.top)
{
nMax ++; //可显示最大行数
rtClient.top += m_nFrameH;
}
}
si.cbSize = sizeof (si) ;
si.fMask = SIF_ALL ;
GetScrollInfo(SB_VERT, &si);
if(si.nMax != nTotal-nMax)
{
if(m_bSimple == TRUE)
si.nMax = 100; //内容的高度
else
si.nMax = nTotal-nMax; //内容的高度
si.cbSize = sizeof (si) ;
si.fMask = SIF_RANGE | SIF_PAGE ;
si.nMin = 0;
SetScrollInfo(SB_VERT, &si, TRUE);
}
}
////////////////////////////////////////////////////////////////
//取V相对滚动位置
int CDataWin::GetScrollV(int yPos)
{
//设定滚动条垂直滚动范围及页面大小
if(m_bSimple == TRUE)
{
CRect rtClient;
GetClientRect(&rtClient);
if(m_bIsPrintView) //模似显示
return yPos*(m_RectPage.Height()-rtClient.Height()+m_nFrameH*2)/100;
else
return yPos*(m_RectPage.Height()-rtClient.Height())/100;
return yPos;
}
int yScroll = 0;
if(yPos <= 0) return yScroll;
if(m_bIsPrintView && yPos>0)
{
yPos--; //可显示最大行数
yScroll += (m_nFrameH - 3);
}
if(yPos <= 0) return yScroll;
if(m_nHead>0 && yPos>0)
{
yPos--; //有页头+1
yScroll += m_nHead;
if(m_bIsPrintView) yScroll += 3;
}
if(yPos <= 0) return yScroll;
for (int i = 0; i < m_nCellMax && yPos > 0; i++, yPos--)
{
yScroll += m_nCellHeight;
}
if(yPos <= 0) return yScroll;
if(m_nFoot>0 && yPos > 0)
{
yPos--; //有页尾+1
yScroll += m_nFoot;
}
if(yPos <= 0) return yScroll;
if(m_bIsPrintView && yPos>0)
{
yPos--; //可显示最大行数
yScroll += m_nFrameH;
}
return yScroll;
}
////////////////////////////////////////////////////////////////
//取H相对滚动位置
int CDataWin::GetScrollH(int xPos)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -