// FormDJ.cpp : implementation file
//
#include "stdafx.h"
#include "WQJXC.h"
#include "FormDJ.h"
#include "

PTooltip.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFormDJ
class CDJReportEvent :public CGridppReportEventImpl
{
public:
virtual void Initialize(void)
{
m_pMain->

rogramDefineReport();
}
IGridppReportPtr m_pGridppReport;
CFormDJ *m_pMain;
};
IMPLEMENT_DYNCREATE(CFormDJ, CFormView)
CFormDJ::CFormDJ()
: CFormView(CFormDJ::IDD)
{
//{{AFX_DATA_INIT(CFormDJ)
m_kind = _T("进货单");
//}}AFX_DATA_INIT
m_dHeaderHight=1;
m_dFooterHight=0.5;
m_lStyle=0;
m_lIndex=0;
m_lAdapt=0;
}
CFormDJ::~CFormDJ()
{
((CMainFrame*)AfxGetMainWnd())->m_bDJ=1;
((CMainFrame*)AfxGetMainWnd())->Frame_DJ=NULL;
((CMainFrame*)AfxGetMainWnd())->m_ViewManager.RemoveView(this);
}
void CFormDJ:

oDataExchange(CDataExchange* pDX)
{
CFormView:

oDataExchange(pDX);
//{{AFX_DATA_MAP(CFormDJ)
DDX_Text(pDX, IDC_STATIC_KIND, m_kind);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFormDJ, CFormView)
//{{AFX_MSG_MAP(CFormDJ)
ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnButtonCancel)
ON_BN_CLICKED(IDC_BUTTON_PRINT, OnButtonPrint)
ON_WM_SIZE()
ON_BN_CLICKED(IDC_BUTTON_CONFIG, OnButtonConfig)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFormDJ diagnostics
#ifdef _DEBUG
void CFormDJ::AssertValid() const
{
CFormView::AssertValid();
}
void CFormDJ:

ump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFormDJ message handlers
void CFormDJ::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
// TODO: Add your specialized code here and/or call the base class
((CMainFrame*)AfxGetMainWnd())->m_ViewManager.OnActivateView(bActivate, this);
CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
void CFormDJ::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->SetWindowText(_T("单据")); // 设置标题
CString cs;
GetParentFrame()->GetWindowText(cs);//获得窗口标题
((CMainFrame*)AfxGetMainWnd())->m_ViewManager.AddView(cs,this);//显示顶部Tab标题
// TODO: Add your specialized code here and/or call the base class
InitialData();
m_pGridppReport.CreateInstance( __uuidof(GridppReport) );
ATLASSERT(m_pGridppReport != NULL);
//取得查询显示器控件的接口指针
CWnd *pDispalyViewerWnd = GetDlgItem(IDC_GRDISPLAYVIEWER1);
LPUNKNOWN spUnk = pDispalyViewerWnd->GetControlUnknown();
spUnk->QueryInterface(__uuidof(IGRDisplayViewer), (void**)(&m_pDisplayViewer));
ATLASSERT(m_pDisplayViewer != NULL);
//从文件中载入报表模板数据到报表主对象
// m_pGridppReport->LoadFromFile("D:\\Frame1\\WQJXC\\Report\\单据.grf");
//设置与数据源的连接串,因为在设计时指定的数据库路径是绝对路径。
//m_pGridppReport->DetailGrid->Recordset->C

" border=0 smilieid="3">atabase Password=123";
//m_pGridppReport->DetailGrid->Recordset->QuerySQL ="select * from 单据查询 where 引索=10";
//创建事件响应对象
CComObject<CDJReportEvent> *pEvent;
CComObject<CDJReportEvent>::CreateInstance( &pEvent );
m_pReportEvents = pEvent;
m_pReportEvents->AddRef();
pEvent->m_pGridppReport = m_pGridppReport;
pEvent->m_pMain = this;
HRESULT hr = m_pReportEvents->DispEventAdvise(m_pGridppReport, &__uuidof(_IGridppReportEvents)) ;
hr;
ATLASSERT( SUCCEEDED(hr) );
AdjustViewerSize();
//查询显示器控件关联报表主对象
m_pDisplayViewer->Report = m_pGridppReport;
//启动查询显示器的运行
m_pDisplayViewer->Start();
this->UpdateData(0);
}
BOOL CFormDJ:

reTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
HWND hwnd;
if(pMsg->hwnd!=NULL)
hwnd=pMsg->hwnd;
if(hwnd==GetDlgItem(IDC_GRDISPLAYVIEWER1)->GetSafeHwnd()&&pMsg->message==WM_MOUSEWHEEL)
{
int zDelta = (int)(pMsg->wParam);
if(zDelta<0)
{
pMsg->wParam=VK_DOWN;
}
else
{
pMsg->wParam=VK_UP;
}
pMsg->message=WM_KEYDOWN;
}
m_TipSubject.RelayEvent(pMsg);
return CFormView:

reTranslateMessage(pMsg);
}
void CFormDJ::OnButtonCancel()
{
// TODO: Add your control notification handler code here
::SendMessage(this->GetParent()->GetSafeHwnd(),WM_CLOSE,0,0);
}
void CFormDJ::OnButtonPrint()
{
// TODO: Add your control notification handler code here
m_pDisplayViewer->

ostColumnLayout();
m_pGridppReport->;Printer->LeftMargin=0.2;
m_pGridppReport->;Printer->RightMargin=0.2;
m_pGridppReport->DetailGrid->;PrintAdaptMethod = grcpamDiscard;
CPrint m_DlgPrint;
m_DlgPrint.DoModal();
for(;;)
{
if(m_DlgPrint.m_lExport)
{
OnExportWay(m_DlgPrint.m_lExport);
m_DlgPrint.DoModal();
}
else
break;
}
}
void CFormDJ::AdjustViewerSize()
{
/* CWnd *pDispalyViewerWnd = GetDlgItem(IDC_GRDISPLAYVIEWER1);
if (pDispalyViewerWnd)
{
RECT ClientRect;
GetClientRect( &ClientRect );
ClientRect.top+=60;
pDispalyViewerWnd->MoveWindow(&ClientRect, FALSE);
}*/
}
void CFormDJ::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
AdjustViewerSize();
}
void CFormDJ:

rogramDefineReport()
{
//清除报表已有的定义
m_pGridppReport->Clear();
//定义报表主对象的属性
m_pGridppReport->Font->;Point = 9;
DefineReportHeader();
DefineDetailGrid();
DefineReportFoot();
}
void CFormDJ::DefineReportHeader()
{
IGRReportHeaderPtr Reportheader = m_pGridppReport->InsertReportHeader();
//表头
IGRStaticBoxPtr StaticBox = Reportheader->Controls->Add(grctStaticBox)->AsStaticBox;
StaticBox->Center = grcsHorizontal;//使部件框在节中水平方向上居中对齐
StaticBox->TextAlign = grtaMiddleCenter ;//文字中中对齐
StaticBox->Font->;Point = 18;
StaticBox->Font->Bold = true;
StaticBox->Top = 0.10;
StaticBox->Width = 15.00;
StaticBox->Height = 1.68;
sql.Format("select * from 查帐设置 where 单据类型='%s' and 单据结构='表头' order by 列序",m_kind);
if(m_DataRun.CheckSQLResult1(sql))
StaticBox->Text = m_DataRun._GetCollect1("重名列名");
CString m_FieldName="";
bool m_bLeft=1;double m_dTop=1.0;
sql.Format("select * from 查帐设置 where 单据类型='%s' and 单据结构='上头' order by 列序",m_kind);
if(m_DataRun.CheckSQLResult1(sql))
{
sql.Format("select * from 单据头查询 where 引索=%d and 红字冲帐=%d",m_lIndex,m_lRed);
m_DataRun.RunSQL2(sql);
m_DataRun.m_DATARecordset1->MoveFirst();
while(!m_DataRun.m_DATARecordset1->adoEOF)
{
if(m_DataRun.BoolGetCollect1("是否显示"))
{
IGRMemoBoxPtr MemoBox = Reportheader->Controls->Add(grctMemoBox)->AsMemoBox;
if(m_bLeft)//左
{
MemoBox->Text = m_DataRun._GetCollect1("重名列名");
m_FieldName=m_DataRun.GetCollect1("列名");
MemoBox->Text +=m_DataRun._GetCollect2((_variant_t)m_FieldName);
MemoBox->Left = 0.5; //使部件框在节中水平方向上居中对齐
MemoBox->Font->;Point = 12;
MemoBox->Font->Bold = 0;
//MemoBox->TextAlign = grtaMiddleLeft ;//文字中左对齐
m_dTop+=0.6;
MemoBox->Top = m_dTop;
MemoBox->Width =7.5;
MemoBox->Height = 0.5;
MemoBox->Anchor=grasLeft;
m_bLeft=0;
}
else//右
{
MemoBox->Text = m_DataRun._GetCollect1("重名列名");
m_FieldName=m_DataRun.GetCollect1("列名");
MemoBox->Text +=m_DataRun._GetCollect2((_variant_t)m_FieldName);
MemoBox->Left = 9.0; //使部件框在节中水平方向上居中对齐
MemoBox->Font->;Point = 12;
MemoBox->Font->Bold = 0;
//MemoBox->TextAlign = grtaMiddleLeft ;//文字中左对齐
MemoBox->Top = m_dTop;
MemoBox->Width =12;
MemoBox->Height = 0.5;
MemoBox->Anchor=grasRight;
m_bLeft=1;
}
}
m_DataRun.m_DATARecordset1->MoveNext();
}
}
m_dHeaderHight+=m_dTop;
Reportheader->Height = m_dHeaderHight;
}
[
本帖最后由 w1984721 于 2008-3-12 21:05 编辑 ]