?? test2dlg.cpp
字號:
// test2Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "test2.h"
#include "test2Dlg.h"
#include "printselect.h"
#include "GridDLGHYGL.h"
#include "GridDlgYJGL.h"
//#define FONTSIZE 14
#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()
/////////////////////////////////////////////////////////////////////////////
// CTest2Dlg dialog
CTest2Dlg::CTest2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CTest2Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTest2Dlg)
m_XSYJ = 0.0f;
m_XM = _T("");
m_SFZ = _T("");
m_JSR = _T("");
m_DH = _T("");
m_BZ = _T("");
m_lPosition = 0;
m_CC = _T("");
m_strOther = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTest2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTest2Dlg)
DDX_Text(pDX, IDC_EDIT_XSYJ, m_XSYJ);
DDX_Text(pDX, IDC_EDIT_XM, m_XM);
DDV_MaxChars(pDX, m_XM, 20);
DDX_Text(pDX, IDC_EDIT_SFZ, m_SFZ);
DDV_MaxChars(pDX, m_SFZ, 18);
DDX_Text(pDX, IDC_EDIT_JSR, m_JSR);
DDV_MaxChars(pDX, m_JSR, 20);
DDX_Text(pDX, IDC_EDIT_DH, m_DH);
DDV_MaxChars(pDX, m_DH, 12);
DDX_Text(pDX, IDC_EDIT_BZ, m_BZ);
DDX_Text(pDX, IDC_EDIT_CURJLS, m_lPosition);
DDX_Text(pDX, IDC_EDIT_OTHER, m_strOther);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTest2Dlg, CDialog)
//{{AFX_MSG_MAP(CTest2Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
ON_BN_CLICKED(IDC_BUTTON_UPDATE, OnButtonUpdate)
ON_BN_CLICKED(IDC_BUTTON_CANCELUPDATE, OnButtonCancelupdate)
ON_BN_CLICKED(IDC_BUTTON_PRINT, OnButtonPrint)
ON_BN_CLICKED(IDC_BUTTON_REFRESH, OnButtonRefresh)
ON_BN_CLICKED(IDC_BUTTON_LAST, OnButtonLast)
ON_BN_CLICKED(IDC_BUTTON_NEXT, OnButtonNext)
ON_BN_CLICKED(IDC_BUTTON_PREV, OnButtonPrev)
ON_BN_CLICKED(IDC_BUTTON_FIRST, OnButtonFirst)
ON_BN_CLICKED(IDC_BUTTON_LLWG, OnButtonLlwg)
ON_BN_CLICKED(IDC_BUTTON_BB_XSYJ, OnButtonBbXsyj)
ON_BN_CLICKED(IDC_BUTTON_BB_HYDA, OnButtonBbHyda)
ON_EN_KILLFOCUS(IDC_EDIT_JSR, OnKillfocusEditJsr)
ON_BN_CLICKED(IDC_PASS, OnPass)
ON_BN_CLICKED(IDC_SORT, OnSort)
ON_BN_CLICKED(IDC_FIND, OnFind)
ON_BN_CLICKED(IDC_FINDNEXT, OnFindnext)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTest2Dlg message handlers
BOOL CTest2Dlg::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
if (m_adoConnection.ConnectAccess("renshi.mdb"))
{
m_adoRecordSet.SetAdoConnection(&m_adoConnection);
m_adoRecordSet.SetCursorLocation();
m_adoRecordSet.Open("會員表", adCmdTable);
m_adoConnection.BeginTrans();
UpdateRecord(TRUE);
}
else
{
MessageBox("數(shù)據(jù)庫連接失敗!");
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CTest2Dlg::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 CTest2Dlg::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 CTest2Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTest2Dlg::OnButtonAdd()
{
CAdoCommand cmd;
m_adoRecordSet.AddNew();
UpdateRecord();
}
void CTest2Dlg::OnButtonDel()
{
m_adoRecordSet.Delete();
OnButtonNext();
}
void CTest2Dlg::OnButtonUpdate()
{
if (UpdateRecord(FALSE))
{
m_strPathName = "";
if (!m_adoRecordSet.Update())
{
AfxMessageBox("更新失敗,請正確填寫相應(yīng)的信息!");
}
}
m_adoConnection.CommitTrans();
}
void CTest2Dlg::OnButtonCancelupdate()
{
m_adoRecordSet.CancelUpdate();
}
void CTest2Dlg::OnButtonSearch()
{
// TODO: Add your control notification handler code here
}
void CTest2Dlg::OnButtonPrint()
{
CPrintSelect dlgsel;
dlgsel.DoModal ();
}
void CTest2Dlg::OnButtonRefresh()
{
if (!m_adoRecordSet.Resync())
{
//AfxMessageBox("_adoRecordSet");
m_adoRecordSet.Open("會員表", adCmdTable);
}
m_strPathName = "";
UpdateRecord();
}
void CTest2Dlg::OnButtonLast()
{
if (m_adoRecordSet.IsEOF() && m_adoRecordSet.IsBOF()) return;
m_adoRecordSet.MoveLast();
m_strPathName = "";
UpdateRecord();
}
void CTest2Dlg::OnButtonNext()
{
if (m_adoRecordSet.IsEOF()) return;
m_adoRecordSet.MoveNext();
if (m_adoRecordSet.IsEOF())
{
if (!m_adoRecordSet.IsBOF())
{
m_adoRecordSet.MoveFirst();
}
}
m_strPathName = "";
UpdateRecord();
}
void CTest2Dlg::OnButtonPrev()
{
try
{
if (m_adoRecordSet.IsBOF()) return;
m_adoRecordSet.MovePrevious();
if (m_adoRecordSet.IsBOF())
{
if (!m_adoRecordSet.IsEOF())
{
m_adoRecordSet.MoveLast();
}
}
m_strPathName = "";
UpdateRecord();
}
catch (...)
{
}
}
void CTest2Dlg::OnButtonFirst()
{
if (m_adoRecordSet.IsEOF() && m_adoRecordSet.IsBOF()) return;
m_adoRecordSet.MoveFirst();
m_strPathName = "";
UpdateRecord();
}
void CTest2Dlg::OnButtonLlwg()
{
CGridDLGHYGL dlg;
dlg.m_adoRecordSet = &m_adoRecordSet;
dlg.DoModal();
}
void CTest2Dlg::OnButtonBbXsyj()
{
//連接數(shù)據(jù)表
BOOL isor = m_adoRecordSet.Open("業(yè)績表", adCmdTable);
if(isor)
{
//MessageBox("OK",NULL,MB_OK);
//計算業(yè)績(先搜索以改人為介紹人的個數(shù))
/*for(int i=1,i++,i<=m_icount)
{
//該人的業(yè)績+=select 銷售業(yè)績 from 會員表 where 層次=(層次+"i")
}
寫入業(yè)績表
*/
CGridDlgYJGL dlg;
dlg.m_adoRecordSet = &m_adoRecordSet;
dlg.DoModal ();
isor = FALSE;
}
if(!isor)
m_adoRecordSet.Close();
//如何在其不用時關(guān)閉
}
void CTest2Dlg::OnButtonBbHyda()
{
//增加序號字段,其值為自動增值
/*long m_iCount=1;
CString sqlstr;
while(!m_adoRecordSet.IsEOF())
{
m_iCount++;
if(m_iCount % 2 ==0)
{
sqlstr = "select 姓名,身份證號,電話,備注 from 會員表";
m_adoRecordSet.Open (sqlstr);
//TextOut();
//MessageBox("插入介紹人信息",NULL,MB_OK);
//指針下移
OnButtonNext();
}
else
{
MessageBox("插入本人信息",NULL,MB_OK);
//指針下移
}
}*/
}
BOOL CTest2Dlg::UpdateRecord(BOOL bLoad)
{
CString strSql;
if (m_adoRecordSet.GetRecordCount() < 1) return FALSE;
if (bLoad)
{
if (!m_adoRecordSet.GetCollect("姓名", m_XM)
|| !m_adoRecordSet.GetCollect("身份證號", m_SFZ)
|| !m_adoRecordSet.GetCollect("電話", m_DH)
|| !m_adoRecordSet.GetCollect("銷售業(yè)績", m_XSYJ)
|| !m_adoRecordSet.GetCollect("備注", m_BZ)
|| !m_adoRecordSet.GetCollect("介紹人", m_JSR)
//|| !m_adoRecordSet.GetCollect("層次", m_CC)
)
{
;
}
//如果介紹人改變了,那他的層次也要發(fā)生變化;否則,直接返回
//CengciJS(m_JSR);
//該函數(shù)返回值為當(dāng)前用戶的層次
CRect rect(370, 100, 500, 260);
InvalidateRect(rect);
m_lPosition = m_adoRecordSet.GetAbsolutePosition();
UpdateData(FALSE);
return TRUE;
}
else
{
if (!UpdateData()) return FALSE;
//
strSql.Format("");
if (
!m_adoRecordSet.PutCollect("姓名", m_XM)
|| !m_adoRecordSet.PutCollect("身份證號", m_SFZ)
|| !m_adoRecordSet.PutCollect("電話", m_DH)
|| !m_adoRecordSet.PutCollect("銷售業(yè)績", m_XSYJ)
|| !m_adoRecordSet.PutCollect("備注", m_BZ)
|| !m_adoRecordSet.PutCollect("介紹人", m_JSR)
//|| !m_adoRecordSet.PutCollect("層次", m_CC)
)
{
AfxMessageBox("Error!");
}
return TRUE;
}
}
void CTest2Dlg::OnKillfocusEditJsr()
{
::MessageBox(NULL,"請確保介紹人已經(jīng)存在","提醒",MB_OKCANCEL|MB_ICONINFORMATION);
//確保介紹人在“信息表”中已存在
//若不存在提醒用戶
//如果用戶想添加這兩個用戶則先添加介紹人
//
}
void CTest2Dlg::OnOK()
{
//m_adoConnection.CommitTrans();
CDialog::OnOK();
}
void CTest2Dlg::OnPass()
{
UpdateData();
m_adoRecordSet.SetFilter(LPCTSTR(m_strOther));
}
void CTest2Dlg::OnSort()
{
UpdateData();
m_adoRecordSet.SetSort(LPCTSTR(m_strOther));
}
void CTest2Dlg::OnFind()
{
UpdateData();
if (m_adoRecordSet.Find(LPCTSTR(m_strOther)))
UpdateRecord();
}
void CTest2Dlg::OnFindnext()
{
UpdateData();
if (m_adoRecordSet.FindNext())
UpdateRecord();
}
/*BOOL CTest2Dlg::DoPreparePrintDC()
{
//獲取打印機的設(shè)備屬性
CPrintDialog dlgPrint(FALSE);
// 得到當(dāng)前系統(tǒng)缺省打印機設(shè)置
if(!dlgPrint.GetDefaults())
return FALSE;
LPDEVMODE pDM=dlgPrint.GetDevMode();
if(pDM==NULL) return FALSE;
::GlobalUnlock(pDM);
// 聯(lián)結(jié)打印DC,m_hDC是定義為 HDC m_hDC;//的類成員變量
m_hDC=dlgPrint.CreatePrinterDC();
//m_DC是定義為 CDC m_DC;//的類成員變量
if(!m_DC.Attach(m_hDC)) return FALSE;
// 設(shè)置打印標(biāo)志
m_DC.m_bPrinting=TRUE;
short cxInch=m_DC.GetDeviceCaps(LOGPIXELSX);
short cyInch=m_DC.GetDeviceCaps(LOGPIXELSY);
// 建立打印字體,m—fontPrint 是定義為 CFont m_fontPrint;//的類成員變量
// if(!m_fontPrint.CreateFont(MulDiv(FONTSIZE, -cyInch, 72),0,0,0,FW_NORMAL,0,0,0,GB2312_CHARSET,OUT_CHARACTER_PRECIS,CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,HFONTNAME))
// return FALSE;
return TRUE;
}
/*void CTest2Dlg::DoPrint(int sel)
{
if(DoPreparePrintDC()==FALSE) return;
if(sel==0)
{
CString str;
str="會員檔案";
DOCINFO di;
::ZeroMemory (&di, sizeof (DOCINFO));
di.cbSize=sizeof (DOCINFO);
di.lpszDocName=str;
// 將打印字體選進設(shè)備場景
CFont* pOldFont=m_DC.SelectObject(&m_fontPrint);
m_DC.StartDoc(&di);
m_DC.StartPage();
// 輸出報表,建議用CDC::DrawText()函數(shù)便于控制打印范圍
m_DC.EndPage();
m_DC.EndDoc();
m_DC.SelectObject(pOldFont);
//清除打印場景
DoClearPrintDC();
//::MessageBox(NULL,"DAYIN 1",NULL,MB_ICONASTERISK|MB_OK);
}
if(sel==1)
{
CString str;
str="會員業(yè)績";
DOCINFO di;
::ZeroMemory (&di, sizeof (DOCINFO));
di.cbSize=sizeof (DOCINFO);
di.lpszDocName=str;
CFont* pOldFont=m_DC.SelectObject(&m_fontPrint);
m_DC.StartDoc(&di);
m_DC.StartPage();
// 輸出報表,建議用CDC::DrawText()函數(shù)便于控制打印范圍
// 終止打印作業(yè)
m_DC.EndPage();
m_DC.EndDoc();
//MessageBox("DAYIN 2",NULL,MB_OK);
m_DC.SelectObject(pOldFont);
//清除打印場景
DoClearPrintDC();
}
/*else
{
CString str;
str.Format ("%i",sel);
MessageBox(str,NULL,MB_OK);
}
}*/
/*
void CTest2Dlg::DoClearPrintDC()
{
m_fontPrint.DeleteObject();
m_DC.Detach();
::DeleteDC( m_hDC );
}*/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -