?? vc_aliasdlg.cpp
字號:
// VC_AliasDlg.cpp : implementation file
//
#include "stdafx.h"
#include "VC_Alias.h"
#include "VC_AliasDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVC_AliasDlg dialog
CVC_AliasDlg::CVC_AliasDlg(CWnd* pParent /*=NULL*/)
: CDialog(CVC_AliasDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CVC_AliasDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CVC_AliasDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVC_AliasDlg)
DDX_Control(pDX, IDC_OPEN_DATABASE, m_btnOpenDabase);
DDX_Control(pDX, IDC_ADD_ALIAS, m_btnAddAlias);
DDX_Control(pDX, IDC_PREV_RECORD, m_btnPrev);
DDX_Control(pDX, IDC_NEXT_RECORD, m_btnNext);
DDX_Control(pDX, IDC_ETCELLCTRL1, EtCell1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CVC_AliasDlg, CDialog)
//{{AFX_MSG_MAP(CVC_AliasDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_OPEN_DOC, OnOpenDoc)
ON_BN_CLICKED(IDC_ADD_ALIAS, OnAddAlias)
ON_BN_CLICKED(IDC_OPEN_DATABASE, OnOpenDatabase)
ON_BN_CLICKED(IDC_NEXT_RECORD, OnNextRecord)
ON_BN_CLICKED(IDC_PREV_RECORD, OnPrevRecord)
ON_BN_CLICKED(IDC_PRINT_PREVIEW, OnPrintPreview)
ON_BN_CLICKED(IDC_PRINT, OnPrint)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVC_AliasDlg message handlers
BOOL CVC_AliasDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CVC_AliasDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CVC_AliasDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CVC_AliasDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CVC_AliasDlg::OnOpenDoc()
{
//打開報表式樣
//通過報表式樣方式打開報表,這樣就省去了通過代碼制作報表式樣的麻煩了
//并且可以在程序編譯后,修改報表式樣,以便于達(dá)到修改程序的目的
//報表式樣一般用WinTable制表工具方便的制作
EtCell1.OpenDoc("Alias.et");
//不顯示標(biāo)尺
EtCell1.SetRuler(false);
//讓按鈕使能
m_btnAddAlias.EnableWindow(true);
}
void CVC_AliasDlg::OnAddAlias()
{
//通過代碼動態(tài)產(chǎn)生EtCell別名,便于和數(shù)據(jù)庫綁定
//通過別名技術(shù)可以方便的進行報表的存取
//如果設(shè)置了別名,那么就不用關(guān)心報表的行列關(guān)系了
//其實代碼產(chǎn)生別名完全可以通過WinTable制表工具可視化設(shè)置,不用寫一行代碼
EtCell1.AddCellAlias("D4","事故編號","");
EtCell1.AddCellAlias("D5","報案人","");
EtCell1.AddCellAlias("D6","報案時間","");
EtCell1.AddCellAlias("D8","牌照號","");
EtCell1.AddCellAlias("D9","肇事時間","");
EtCell1.AddCellAlias("D10","肇事地點","");
EtCell1.AddCellAlias("D11","司機姓名","");
EtCell1.AddCellAlias("D12","傷人數(shù)","");
EtCell1.AddCellAlias("D13","事故簡況","");
EtCell1.AddCellAlias("D14","事故現(xiàn)象","");
//有關(guān)別名的使用方法,會在"上一條" "下一條" 按鈕中體現(xiàn)出來
//讓按鈕使能
m_btnOpenDabase.EnableWindow(true);
}
void CVC_AliasDlg::OnOpenDatabase()
{
CString strConn,strSQL;
//設(shè)置數(shù)據(jù)庫的連接串
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
strConn = strConn + "bus.mdb";
strConn = strConn + ";Persist Security Info=False";
EtCell1.SetConnectionString(strConn);
CWaitCursor wait;
HRESULT hr = dbset.Open();
if (hr != S_OK)
{
AfxMessageBox(_T("Record set failed to open."), MB_OK);
}
/*
//設(shè)置數(shù)據(jù)庫的查詢SQL語句
strSQL = "SELECT 報案人,牌照號,傷人數(shù),肇事地點 from 報案登記表 ";
EtCell1.SetDatabaseTableName(strSQL);
//激活數(shù)據(jù)庫填寫報表
ADOTable1.Active := true;
*/
//讓按鈕使能
m_btnNext.EnableWindow(true);
m_btnPrev.EnableWindow(true);
}
void CVC_AliasDlg::OnNextRecord()
{
//在這里通過Delphi的數(shù)據(jù)庫控件,在EtCell中利用別名
//逐條在EtCell控件中顯示數(shù)據(jù)庫的數(shù)據(jù)
//if not ADOTable1.Active then
// Exit;
//讓ASO記錄移動到下一條記錄
dbset.MoveNext();
//通過別名技術(shù)填寫報表
//這種方式就免去了用 D4,D5的方式對單元格進行賦值了
//一般的方式是:EtCell1.SetCell(4,4,ADOTable1.FieldValues['事故編號']);
//別名技術(shù)在報表式樣變化后,程序也不需要改動,并且使程序更直觀
//別名增加了對報表操作的靈活性
CString strValue;
strValue = dbset.m_column15;
EtCell1.SetAliasCell("事故編號",strValue);
strValue = dbset.m_column0;
EtCell1.SetAliasCell("報案人",strValue);
strValue = dbset.m_column1;
EtCell1.SetAliasCell("報案時間",strValue);
strValue = dbset.m_column13;
EtCell1.SetAliasCell("牌照號",strValue);
strValue.Format("%s",dbset.m_column11);
EtCell1.SetAliasCell("肇事時間",strValue);
strValue = dbset.m_column26;
EtCell1.SetAliasCell("肇事地點",strValue);
strValue = dbset.m_column19;
EtCell1.SetAliasCell("司機姓名",strValue);
strValue.Format("%d",dbset.m_column14);
EtCell1.SetAliasCell("傷人數(shù)",strValue);
strValue = dbset.m_column17;
EtCell1.SetAliasCell("事故簡況",strValue);
strValue = dbset.m_column18;
EtCell1.SetAliasCell("事故現(xiàn)象",strValue);
}
void CVC_AliasDlg::OnPrevRecord()
{
//在這里通過Delphi的數(shù)據(jù)庫控件,在EtCell中利用別名
//逐條在EtCell控件中顯示數(shù)據(jù)庫的數(shù)據(jù)
//if not ADOTable1.Active then
// Exit;
//讓ASO記錄移動到上一條記錄
dbset.MovePrev();
//通過別名技術(shù)填寫報表
//這種方式就免去了用 D4,D5的方式對單元格進行賦值了
//一般的方式是:EtCell1.SetCell(4,4,ADOTable1.FieldValues['事故編號']);
//別名技術(shù)在報表式樣變化后,程序也不需要改動,并且使程序更直觀
//別名增加了對報表操作的靈活性
CString strValue;
strValue = dbset.m_column15;
EtCell1.SetAliasCell("事故編號",strValue);
strValue = dbset.m_column0;
EtCell1.SetAliasCell("報案人",strValue);
strValue = dbset.m_column1;
EtCell1.SetAliasCell("報案時間",strValue);
strValue = dbset.m_column13;
EtCell1.SetAliasCell("牌照號",strValue);
strValue.Format("%s",dbset.m_column11);
EtCell1.SetAliasCell("肇事時間",strValue);
strValue = dbset.m_column26;
EtCell1.SetAliasCell("肇事地點",strValue);
strValue = dbset.m_column19;
EtCell1.SetAliasCell("司機姓名",strValue);
strValue.Format("%d",dbset.m_column14);
EtCell1.SetAliasCell("傷人數(shù)",strValue);
strValue = dbset.m_column17;
EtCell1.SetAliasCell("事故簡況",strValue);
strValue = dbset.m_column18;
EtCell1.SetAliasCell("事故現(xiàn)象",strValue);
}
void CVC_AliasDlg::OnPrintPreview()
{
//設(shè)置打印方向
EtCell1.SetPrintDirectH(false); //縱向打印
//根據(jù)紙張大小,自動放縮報表
EtCell1.SetPrintFullPage(true);
//打印預(yù)覽
EtCell1.PrintPreview();
}
void CVC_AliasDlg::OnPrint()
{
//設(shè)置打印方向
EtCell1.SetPrintDirectH(false); //縱向打印
//根據(jù)紙張大小,自動放縮報表
EtCell1.SetPrintFullPage(true);
//打印前,顯示打印對話框
EtCell1.Print(true);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -