⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test2dlg.cpp

📁 VC++ 6.0开发。之中打印部分可能对您有值得参考的地方。其他的部分还不是很完善
💻 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("数据库连接失败!");
	}
	
	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("更新失败,请正确填写相应的信息!");
		}
	}

	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() 
{
	//连接数据表
    BOOL isor = m_adoRecordSet.Open("业绩表", adCmdTable);
	if(isor)
	{
		//MessageBox("OK",NULL,MB_OK);
        //计算业绩(先搜索以改人为介绍人的个数)
		/*for(int i=1,i++,i<=m_icount)
		  {
		     //该人的业绩+=select 销售业绩 from 会员表 where 层次=(层次+"i")

		  }
         写入业绩表 

		*/
		CGridDlgYJGL dlg;
    	dlg.m_adoRecordSet = &m_adoRecordSet;
		dlg.DoModal ();
		isor = FALSE;


	}
	if(!isor)
    m_adoRecordSet.Close();
	//如何在其不用时关闭

}

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("销售业绩", m_XSYJ)
		 || !m_adoRecordSet.GetCollect("备注", m_BZ)
		 || !m_adoRecordSet.GetCollect("介绍人", m_JSR)
		 //|| !m_adoRecordSet.GetCollect("层次", m_CC)
		 )
		{
			;
		}
		//如果介绍人改变了,那他的层次也要发生变化;否则,直接返回
		//CengciJS(m_JSR);
		//该函数返回值为当前用户的层次
		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("销售业绩", 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,"请确保介绍人已经存在","提醒",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()
{
	//获取打印机的设备属性
	CPrintDialog dlgPrint(FALSE); 
	// 得到当前系统缺省打印机设置 
	if(!dlgPrint.GetDefaults()) 
		return FALSE; 
	LPDEVMODE pDM=dlgPrint.GetDevMode(); 
    if(pDM==NULL) return FALSE; 
	::GlobalUnlock(pDM); 
	// 联结打印DC,m_hDC是定义为	HDC m_hDC;//的类成员变量 
	m_hDC=dlgPrint.CreatePrinterDC(); 
	//m_DC是定义为	CDC m_DC;//的类成员变量 
	if(!m_DC.Attach(m_hDC)) return FALSE; 
	// 设置打印标志 
    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; 
		// 将打印字体选进设备场景 
		CFont* pOldFont=m_DC.SelectObject(&m_fontPrint); 
		m_DC.StartDoc(&di); 
	    m_DC.StartPage();
	    // 输出报表,建议用CDC::DrawText()函数便于控制打印范围 


		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="会员业绩"; 
		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()函数便于控制打印范围 

     	// 终止打印作业 
		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 );

}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -