📄 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()
{
//打开报表式样
//通过报表式样方式打开报表,这样就省去了通过代码制作报表式样的麻烦了
//并且可以在程序编译后,修改报表式样,以便于达到修改程序的目的
//报表式样一般用WinTable制表工具方便的制作
EtCell1.OpenDoc("Alias.et");
//不显示标尺
EtCell1.SetRuler(false);
//让按钮使能
m_btnAddAlias.EnableWindow(true);
}
void CVC_AliasDlg::OnAddAlias()
{
//通过代码动态产生EtCell别名,便于和数据库绑定
//通过别名技术可以方便的进行报表的存取
//如果设置了别名,那么就不用关心报表的行列关系了
//其实代码产生别名完全可以通过WinTable制表工具可视化设置,不用写一行代码
EtCell1.AddCellAlias("D4","事故编号","");
EtCell1.AddCellAlias("D5","报案人","");
EtCell1.AddCellAlias("D6","报案时间","");
EtCell1.AddCellAlias("D8","牌照号","");
EtCell1.AddCellAlias("D9","肇事时间","");
EtCell1.AddCellAlias("D10","肇事地点","");
EtCell1.AddCellAlias("D11","司机姓名","");
EtCell1.AddCellAlias("D12","伤人数","");
EtCell1.AddCellAlias("D13","事故简况","");
EtCell1.AddCellAlias("D14","事故现象","");
//有关别名的使用方法,会在"上一条" "下一条" 按钮中体现出来
//让按钮使能
m_btnOpenDabase.EnableWindow(true);
}
void CVC_AliasDlg::OnOpenDatabase()
{
CString strConn,strSQL;
//设置数据库的连接串
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);
}
/*
//设置数据库的查询SQL语句
strSQL = "SELECT 报案人,牌照号,伤人数,肇事地点 from 报案登记表 ";
EtCell1.SetDatabaseTableName(strSQL);
//激活数据库填写报表
ADOTable1.Active := true;
*/
//让按钮使能
m_btnNext.EnableWindow(true);
m_btnPrev.EnableWindow(true);
}
void CVC_AliasDlg::OnNextRecord()
{
//在这里通过Delphi的数据库控件,在EtCell中利用别名
//逐条在EtCell控件中显示数据库的数据
//if not ADOTable1.Active then
// Exit;
//让ASO记录移动到下一条记录
dbset.MoveNext();
//通过别名技术填写报表
//这种方式就免去了用 D4,D5的方式对单元格进行赋值了
//一般的方式是:EtCell1.SetCell(4,4,ADOTable1.FieldValues['事故编号']);
//别名技术在报表式样变化后,程序也不需要改动,并且使程序更直观
//别名增加了对报表操作的灵活性
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("伤人数",strValue);
strValue = dbset.m_column17;
EtCell1.SetAliasCell("事故简况",strValue);
strValue = dbset.m_column18;
EtCell1.SetAliasCell("事故现象",strValue);
}
void CVC_AliasDlg::OnPrevRecord()
{
//在这里通过Delphi的数据库控件,在EtCell中利用别名
//逐条在EtCell控件中显示数据库的数据
//if not ADOTable1.Active then
// Exit;
//让ASO记录移动到上一条记录
dbset.MovePrev();
//通过别名技术填写报表
//这种方式就免去了用 D4,D5的方式对单元格进行赋值了
//一般的方式是:EtCell1.SetCell(4,4,ADOTable1.FieldValues['事故编号']);
//别名技术在报表式样变化后,程序也不需要改动,并且使程序更直观
//别名增加了对报表操作的灵活性
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("伤人数",strValue);
strValue = dbset.m_column17;
EtCell1.SetAliasCell("事故简况",strValue);
strValue = dbset.m_column18;
EtCell1.SetAliasCell("事故现象",strValue);
}
void CVC_AliasDlg::OnPrintPreview()
{
//设置打印方向
EtCell1.SetPrintDirectH(false); //纵向打印
//根据纸张大小,自动放缩报表
EtCell1.SetPrintFullPage(true);
//打印预览
EtCell1.PrintPreview();
}
void CVC_AliasDlg::OnPrint()
{
//设置打印方向
EtCell1.SetPrintDirectH(false); //纵向打印
//根据纸张大小,自动放缩报表
EtCell1.SetPrintFullPage(true);
//打印前,显示打印对话框
EtCell1.Print(true);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -