?? printselect.cpp
字號:
// PrintSelect.cpp : implementation file
//
#include "stdafx.h"
#include "test2.h"
#include "PrintSelect.h"
#include "test2dlg.h"
//print
#include "PrintRX.h"
//ado
#include "AdoRecordSet.h"
#include "AdoCommand.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPrintSelect dialog
CPrintSelect::CPrintSelect(CWnd* pParent /*=NULL*/)
: CDialog(CPrintSelect::IDD, pParent)
{
//{{AFX_DATA_INIT(CPrintSelect)
m_iPrtSel = -1;
//}}AFX_DATA_INIT
}
void CPrintSelect::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPrintSelect)
DDX_Radio(pDX, IDC_RADIO1, m_iPrtSel);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPrintSelect, CDialog)
//{{AFX_MSG_MAP(CPrintSelect)
ON_BN_CLICKED(IDC_BUTTON_PRINT, OnButtonPrint)
ON_BN_CLICKED(IDC_BUTTON_Cancel, OnBUTTONCancel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPrintSelect message handlers
void CPrintSelect::OnButtonPrint()
{
CDialog::OnOK();
//
//CString strSql;
//數(shù)據(jù)庫字段變量
CString m_XM;
CString m_SFZ;
CString m_DH;
CString m_JSR;
double m_JE;
CString m_cJE;
CString m_BZ;
//編號或序號
long lcount=0;
CString ccount;
int ipageNum=1;
CString cipageNum;
CString dijiye;
//
bool isNewPag = FALSE;
//
CAdoRecordSet m_adoRecordSet;
CAdoRecordSet m_padoRecordSet;
CAdoConnection m_adoConnection;
_ConnectionPtr m_pConnection;
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ù)庫連接失敗!");
}
if(m_iPrtSel==0)
{
CPrintRX m_Print;
if(m_Print.InitToPrint(NULL,1)==-1)
return;
m_Print.StartPrint();
m_Print.StartPage();
// start printing the lines
//二維點(diǎn)陣
int x_pos[7];
int y_pos[27];
int i;
//設(shè)置橫坐標(biāo)
for (i=0; i<27; i++)
y_pos[i] = 80 + (20 * i);
//設(shè)置縱坐標(biāo)
x_pos[0] = 59;
x_pos[1] = x_pos[0] + 32;
x_pos[2] = x_pos[1] + 57;
x_pos[3] = x_pos[2] + 115;
x_pos[4] = x_pos[3] + 83;
x_pos[5] = x_pos[4] + 57;
x_pos[6] = x_pos[5] + 50;
CPen newPen;
newPen.CreatePen (PS_SOLID, 3, RGB(0,0,0));
//打印26行
for (i=0; i<27; i++)
{
m_Print.DrawHLine(x_pos[0], y_pos[i], x_pos[6], y_pos[i], newPen);
}
//打印7列,其中0和6還有中間的要單獨(dú)打
for (i=0; i<7; i++)
{
m_Print.DrawVLine(x_pos[i], y_pos[0], x_pos[i], y_pos[26], newPen);
}
CSize Size;
char m_str[6][10];
CRect StrRect; //Draw text in Rect
strcpy(m_str[0], "編號");
strcpy(m_str[1], "姓名");
strcpy(m_str[2], "身份證號");
strcpy(m_str[3], "電話");
strcpy(m_str[4], "金額");
strcpy(m_str[5], "備注");
m_Print.SetFontFace(0, 0);
for (i=0; i<6; i++)
{
StrRect.SetRect(x_pos[i], y_pos[0], x_pos[i+1], y_pos[1]);
m_Print.DrawText(m_str[i], StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);
}
// now end the page
CString Title; //標(biāo)題
CString HeaderRight; //BIOSBF NO.
CString BLeftXSRS;//報(bào)銷售人數(shù)
CString BCenterHJJE;//月合計(jì)金額
CString BLeftLXDH;//聯(lián)系電話
CString BCenterDJL;//店經(jīng)理
CString BRightGZQZ;//蓋章簽字
CString BLine1;
CString BLine2;
CString BLine3;
//標(biāo)題
Title.Format(" 店 月銷售匯總表");
m_Print.SetFontFace(0, 3);
StrRect.SetRect(x_pos[0] + 1, 20, x_pos[6], 56);//void SetRect( int x1, int y1, int x2, int y2 );
m_Print.DrawText((LPTSTR)(LPCTSTR)Title, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);
//BIOSBF NO.
m_Print.SetFontFace(0, 0);
HeaderRight.Format("BIOSTBF NO. ");
StrRect.SetRect(x_pos[0] - 1, 56, x_pos[6], 80);
m_Print.DrawText((LPTSTR)(LPCTSTR)HeaderRight, StrRect, 0, 0, FORMAT_RIGHT | FORMAT_VCENTER);
//打印數(shù)據(jù)庫內(nèi)容
m_adoRecordSet.MoveFirst();
while(!m_adoRecordSet.IsEOF())
{
++lcount;
//MessageBox(ccount,NULL,MB_OK);
if(lcount!=0 && lcount % 26 ==0)
{
lcount=lcount-26+1;
m_Print.NewPage();
ipageNum+=1;
isNewPag = TRUE;
//
//打印26行
for (i=0; i<27; i++)
{
m_Print.DrawHLine(x_pos[0], y_pos[i], x_pos[6], y_pos[i], newPen);
}
//打印7列,其中0和6還有中間的要單獨(dú)打
for (i=0; i<7; i++)
{
m_Print.DrawVLine(x_pos[i], y_pos[0], x_pos[i], y_pos[25], newPen);
}
//
m_Print.SetFontFace(0, 0);
for (i=0; i<6; i++)
{
StrRect.SetRect(x_pos[i], y_pos[0], x_pos[i+1], y_pos[1]);
m_Print.DrawText(m_str[i], StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);
}
//
Title.Format(" 店 月銷售匯總表");
m_Print.SetFontFace(0, 3);
StrRect.SetRect(x_pos[0] + 1, 20, x_pos[6], 56);//void SetRect( int x1, int y1, int x2, int y2 );
m_Print.DrawText((LPTSTR)(LPCTSTR)Title, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);
//BIOSBF NO.
m_Print.SetFontFace(0, 0);
HeaderRight.Format("BIOSTBF NO. ");
StrRect.SetRect(x_pos[0] - 1, 56, x_pos[6], 80);
m_Print.DrawText((LPTSTR)(LPCTSTR)HeaderRight, StrRect, 0, 0, FORMAT_RIGHT | FORMAT_VCENTER);
//
}
//
ccount.Format("%i",lcount);
if(ipageNum ==1 || isNewPag)
{
cipageNum.Format("%i",ipageNum);
dijiye="第"+cipageNum+"頁";
m_Print.SetFontFace(0, 0);
StrRect.SetRect(x_pos[0], y_pos[26]+30, x_pos[6], y_pos[26]+30);
m_Print.DrawText((LPTSTR)(LPCTSTR)dijiye, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);
isNewPag = FALSE;
}
m_adoRecordSet.GetFieldValue("姓名",m_XM);
m_adoRecordSet.GetFieldValue("身份證號",m_SFZ);
m_adoRecordSet.GetFieldValue("電話",m_DH);
m_adoRecordSet.GetFieldValue("銷售業(yè)績",m_JE);
m_adoRecordSet.GetFieldValue("備注",m_BZ);
m_Print.SetFontFace(0, 0);
for(int i=0;i<6;i++)
{
StrRect.SetRect(x_pos[i], y_pos[lcount]+3, x_pos[i+1], y_pos[lcount]+3);
switch(i)
{
case 0: m_Print.DrawText((LPTSTR)(LPCTSTR)ccount, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);break;
case 1: m_Print.DrawText((LPTSTR)(LPCTSTR)m_XM, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);break;
case 2: m_Print.DrawText((LPTSTR)(LPCTSTR)m_SFZ, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);break;
case 3: m_Print.DrawText((LPTSTR)(LPCTSTR)m_DH, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);break;
case 4: m_cJE.Format("%.2f",m_JE);
m_Print.DrawText((LPTSTR)(LPCTSTR)m_cJE, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);break;
case 5: m_Print.DrawText((LPTSTR)(LPCTSTR)m_BZ, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);break;
//default: break;
}
}
m_adoRecordSet.MoveNext();
}
//結(jié)束打印
m_Print.EndPage();
m_Print.EndPrint();
}
if(m_iPrtSel==1)
{
CPrintRX m_Print;
if(m_Print.InitToPrint(NULL,1)==-1)
return;
m_Print.StartPrint();
m_Print.StartPage();
// start printing the lines
//二維點(diǎn)陣
int x_pos[7];
int y_pos[32];
int i;
//設(shè)置橫坐標(biāo)
for (i=0; i<32; i++)
y_pos[i] = 80 + (20 * i);
//設(shè)置縱坐標(biāo)
x_pos[0] = 59;
x_pos[1] = x_pos[0] + 32;
x_pos[2] = x_pos[1] + 62;
x_pos[3] = x_pos[2] + 117;
x_pos[4] = x_pos[3] + 83;
x_pos[5] = x_pos[4] + 50;
x_pos[6] = x_pos[5] + 58;
CPen newPen;
newPen.CreatePen (PS_SOLID, 3, RGB(0,0,0));
//打印31行
for (i=0; i<32; i++)
{
m_Print.DrawHLine(x_pos[0], y_pos[i], x_pos[6], y_pos[i], newPen);
}
//打印6列,其中0和6還有中間的要單獨(dú)打
for (i=0; i<7; i++)
{
m_Print.DrawVLine(x_pos[i], y_pos[0], x_pos[i], y_pos[31], newPen);
}
CSize Size;
char m_str[6][10];
CRect StrRect; //Draw text in Rect
strcpy(m_str[0], "編號");
strcpy(m_str[1], "姓名");
strcpy(m_str[2], "身份證號");
strcpy(m_str[3], "電話");
strcpy(m_str[4], " ");
strcpy(m_str[5], "備注");
m_Print.SetFontFace(0, 0);
for (i=0; i<6; i++)
{
StrRect.SetRect(x_pos[i], y_pos[0], x_pos[i+1], y_pos[1]);
m_Print.DrawText(m_str[i], StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);
}
// now end the page
CString Title; //標(biāo)題
CString HeaderRight; //日期
CString HeaderCenter; //經(jīng)理
CString HeaderLeft; //店號
CString BLine1;
CString BLine2;
CString BLine3;
//標(biāo)題
Title.Format("檔 案 匯 總 表");
m_Print.SetFontFace(0, 3);
StrRect.SetRect(x_pos[0] + 1, 20, x_pos[6], 56);//void SetRect( int x1, int y1, int x2, int y2 );
m_Print.DrawText((LPTSTR)(LPCTSTR)Title, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);
//日期
m_Print.SetFontFace(0, 0);
HeaderRight.Format("日期: ");
StrRect.SetRect(x_pos[0] - 1, 56, x_pos[6], 80);
m_Print.DrawText((LPTSTR)(LPCTSTR)HeaderRight, StrRect, 0, 0, FORMAT_RIGHT | FORMAT_VCENTER);
//經(jīng)理
m_Print.SetFontFace(0, 0);
HeaderRight.Format("經(jīng)理: (簽字) ");
StrRect.SetRect(x_pos[0] - 1, 56, x_pos[6], 80);
m_Print.DrawText((LPTSTR)(LPCTSTR)HeaderRight, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);
//店號
m_Print.SetFontFace(0, 0);
HeaderRight.Format("店號: ");
StrRect.SetRect(x_pos[0] - 1, 56, x_pos[6], 80);
m_Print.DrawText((LPTSTR)(LPCTSTR)HeaderRight, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);
//打印數(shù)據(jù)庫內(nèi)容
m_adoRecordSet.MoveFirst();
while(!m_adoRecordSet.IsEOF())
{
++lcount;
//MessageBox(ccount,NULL,MB_OK);
if(lcount!=0 && lcount % 31 ==0)
{
lcount=lcount-31+1;
m_Print.NewPage();
ipageNum+=1;
isNewPag = TRUE;
//
//打印31行
for (i=0; i<32; i++)
{
m_Print.DrawHLine(x_pos[0], y_pos[i], x_pos[6], y_pos[i], newPen);
}
//打印6列,其中0和6還有中間的要單獨(dú)打
for (i=0; i<7; i++)
{
m_Print.DrawVLine(x_pos[i], y_pos[0], x_pos[i], y_pos[31], newPen);
}
//
m_Print.SetFontFace(0, 0);
for (i=0; i<6; i++)
{
StrRect.SetRect(x_pos[i], y_pos[0], x_pos[i+1], y_pos[1]);
m_Print.DrawText(m_str[i], StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);
}
//
Title.Format("檔 案 匯 總 表");
m_Print.SetFontFace(0, 3);
StrRect.SetRect(x_pos[0] + 1, 20, x_pos[6], 56);//void SetRect( int x1, int y1, int x2, int y2 );
m_Print.DrawText((LPTSTR)(LPCTSTR)Title, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);
//日期
m_Print.SetFontFace(0, 0);
HeaderRight.Format("日期: ");
StrRect.SetRect(x_pos[0] - 1, 56, x_pos[6], 80);
m_Print.DrawText((LPTSTR)(LPCTSTR)HeaderRight, StrRect, 0, 0, FORMAT_RIGHT | FORMAT_VCENTER);
//經(jīng)理
m_Print.SetFontFace(0, 0);
HeaderRight.Format("經(jīng)理: (簽字) ");
StrRect.SetRect(x_pos[0] - 1, 56, x_pos[6], 80);
m_Print.DrawText((LPTSTR)(LPCTSTR)HeaderRight, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);
//店號
m_Print.SetFontFace(0, 0);
HeaderRight.Format("店號: ");
StrRect.SetRect(x_pos[0] - 1, 56, x_pos[6], 80);
m_Print.DrawText((LPTSTR)(LPCTSTR)HeaderRight, StrRect, 0, 0, FORMAT_LEFT | FORMAT_VCENTER);
//
}
//
ccount.Format("%i",lcount);
if(ipageNum ==1 || isNewPag)
{
cipageNum.Format("%i",ipageNum);
dijiye="第"+cipageNum+"頁";
m_Print.SetFontFace(0, 0);
StrRect.SetRect(x_pos[0], y_pos[31]+30, x_pos[6], y_pos[31]+30);
m_Print.DrawText((LPTSTR)(LPCTSTR)dijiye, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);
isNewPag = FALSE;
}
if(lcount % 2 != 0)
{
m_adoRecordSet.GetFieldValue("姓名",m_XM);
m_adoRecordSet.GetFieldValue("身份證號",m_SFZ);
m_adoRecordSet.GetFieldValue("電話",m_DH);
m_adoRecordSet.GetFieldValue("備注",m_BZ);
m_adoRecordSet.GetFieldValue("介紹人",m_JSR);
m_adoRecordSet.MoveNext();
}
//below for circle may have problem
if(lcount % 2 == 0)
{
m_adoRecordSet.Clone(m_padoRecordSet);
CString temp;
m_padoRecordSet.MoveFirst();
m_padoRecordSet.GetFieldValue ("姓名",temp);
while((temp!=m_JSR) && !m_JSR.IsEmpty())
{
m_padoRecordSet.MoveNext ();
m_padoRecordSet.GetFieldValue ("姓名",temp);
//if(temp==m_JSR)
// MessageBox(temp,NULL,MB_OK);
// if(!m_padoRecordSet.IsEOF())
// {
// m_padoRecordSet.MoveFirst();
// }
}
if(!m_JSR.IsEmpty() && (temp==m_JSR) )
{
//m_padoRecordSet.MovePrevious();
m_padoRecordSet.GetFieldValue("姓名",m_XM);
m_padoRecordSet.GetFieldValue("身份證號",m_SFZ);
m_padoRecordSet.GetFieldValue("電話",m_DH);
m_padoRecordSet.GetFieldValue("備注",m_BZ);
}
else //if(m_JSR.IsEmpty())
{
m_XM=" ";
m_SFZ=" ";
m_DH=" ";
m_BZ=" ";
}
// m_padoRecordSet.Open(strSql,adCmdText,adOpenDynamic);
}
m_Print.SetFontFace(0, 0);
for(int i=0;i<6;i++)
{
StrRect.SetRect(x_pos[i], y_pos[lcount]+3, x_pos[i+1], y_pos[lcount]+3);
switch(i)
{
case 0: m_Print.DrawText((LPTSTR)(LPCTSTR)ccount, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);break;
case 1: m_Print.DrawText((LPTSTR)(LPCTSTR)m_XM, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);break;
case 2: m_Print.DrawText((LPTSTR)(LPCTSTR)m_SFZ, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);break;
case 3: m_Print.DrawText((LPTSTR)(LPCTSTR)m_DH, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);break;
case 4: break;
case 5: m_Print.DrawText((LPTSTR)(LPCTSTR)m_BZ, StrRect, 0, 0, FORMAT_HCENTER | FORMAT_VCENTER);break;
//default: break;
}
}
//m_adoRecordSet.MoveNext();
}
//結(jié)束打印
m_Print.EndPage();
m_Print.EndPrint();
}
// CTest2Dlg dlg;
// dlg.DoPreparePrintDC();
// dlg.DoPrint(m_iPrtSel);
/*CString str;
str.Format("%i",m_iPrtSel);
MessageBox(str,NULL,MB_OK);*/
}
void CPrintSelect::OnBUTTONCancel()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -