問合せ結果を印刷

  マクロ



  
#define DOC_NAME "商品分類一覧"

#define LOAD_SQL(DB,LVIEW,QUERY) \
{ \
	int nRet; \
	LVIEW->Hide(); \
	this->StatusSetText( "" ); \
	nRet = DB.LoadSqlData( LVIEW, 0, &QUERY ); \
	switch( nRet ) { \
	case -1: \
		this->StatusSetText( &(DB.ErrMessage) ); \
		break; \
	case 0: \
		this->StatusSetText( "対象データが存在しません" ); \
		break; \
	default: \
		this->StatusPrintf( "%d 件のデータが選択されました", nRet ); \
		break; \
	} \
	LVIEW->Fit(); \
	LVIEW->Show(); \
}

#define CONNECT_DB \
if ( !CurDb.Connect() ) { \
	MsgOk("接続に失敗しました \n%s", CurDb.ErrMessage.szLboxString); \
	return; \
}
  



  MyDlg.h



  
#include "CLClass.h"
#include <LboxDatabase.h>

class MyDlg : public CLDlg  
{
public:
	void GetData();
	void ProcOperator();
	void ProcEnd();
	void WMInitdialog();
	MyDlg();
	virtual ~MyDlg();

	LboxDatabase CurDb;
	LboxListview *LView;
	LboxDTPicker *From;
	LboxDTPicker *To;

	LboxString Query;
	LboxString Cond;
	LboxIEPrint *IEPrt;
	int nRow;
	int nRowMax;
	void PrtData( void );
	void PrtHead( void );
	void PrtDetail( void );

};
  



  MyDlg.cpp

  
// *********************************************************
// ダイアログ初期化イベント
// *********************************************************
void MyDlg::WMInitdialog()
{
	this->CenterWindow();

	// ダイアログのプロパティでシステムメニューの
	// チェックボックスを外して下さい
	this->ChangeStyle( WS_MINIMIZEBOX | WS_SYSMENU, 0 );
	this->ChangeExStyle( WS_EX_APPWINDOW, 0 );
	this->ChangeIcon( IDI_HR010 );
	this->StatusCreate( 0 );

	LboxString Buff;

	int nType = 3;
	switch( nType ) {
	case 0:		// Excel
		Buff.operator = ("d:\\temp\\販売管理.xls");
		CurDb.SetConnectString( nType, &Buff );
		break;
	case 1:		// MDB
		Buff.operator = ("d:\\temp\\販売管理.mdb");
		CurDb.SetConnectString( nType, &Buff );
		break;
	case 2:		// SQLServer
		Buff.operator = ("localhost,lightbox2,sa,");
		CurDb.SetConnectString( nType, &Buff );
		break;
	case 3:		// MySQL
		Buff.operator = ("MySQL,lightbox,root,");
		CurDb.SetConnectString( nType, &Buff );
		break;
	case 4:		// Oracle
		Buff.operator = ("ORA,lightbox,lightbox");
		CurDb.SetConnectString( nType, &Buff );
		break;
	case 5:		// PostgreSQL
		Buff.operator = ("PostgreSQL,lightbox,lightbox,");
		CurDb.SetConnectString( nType, &Buff );
		break;
	}

	// リストビューインスタンス作成
	LView = new LboxListview( ::GetDlgItem( hDlg, IDC_LIST1 ), 0 );
	LView->Grid();

	this->EditFocus( IDC_EDIT1 );

	From = new LboxDTPicker(
		this->hDlg,
		this->GetHandle( IDC_EDIT2 ),
		false
	);
	To = new LboxDTPicker(
		this->hDlg,
		this->GetHandle( IDC_EDIT3 ),
		false
	);
	::EnableWindow( From->hWnd, false );
	::EnableWindow( To->hWnd, false );

	// IE 印刷オブジェクト作成
	IEPrt = new LboxIEPrint();
	// ページあたりの行数
	this->nRowMax = 30;
	// 初期 SQL
	this->Query.operator = ("select * from 商品分類マスタ");
}

// *********************************************************
// ダイアログ終了処理
// *********************************************************
void MyDlg::ProcEnd()
{
	delete IEPrt;
	delete From;
	delete To;
	delete this->LView;
}

// *********************************************************
// オペレータイベント
// *********************************************************
void MyDlg::ProcOperator()
{
	switch( ControlId ) {
		// 印刷プレビュー
		case IDM_PRTVIEW:
			PrtData();
			break;
		// 問合せ
		case IDOK:
			GetData();
			break;
		// 終了
		case IDM_EXIT:
			this->PostCommand( IDCANCEL );
			break;
		// 開始日付用チェック
		case IDC_CHECK1:
			::EnableWindow(
				From->hWnd,
				this->ButtonIsCheck( IDC_CHECK1 )
			);
			break;
		// 終了日付用チェック
		case IDC_CHECK2:
			::EnableWindow(
				To->hWnd,
				this->ButtonIsCheck( IDC_CHECK2 )
			);
			break;

		// リストビュー
		case IDM_EDIT0:
			LView->CopyClipboard( false, true, 0 );
			break;
		case IDM_EDIT1:
			LView->CopyClipboard( false, true, 1 );
			break;
		case IDM_EDIT3:
			LView->CopyClipboard( false, true, 3 );
			break;
	}
}

// *********************************************************
// 問合せ処理
// *********************************************************
void MyDlg::GetData()
{
	// DB 接続マクロ
	CONNECT_DB

	// SQL 用文字列オブジェクト
	this->Query.operator = ("select * from 商品分類マスタ");
	this->Cond.operator = ("");

	LboxString Buff;

	// 名称条件
	this->EditGetText( IDC_EDIT1, &Buff );
	Buff.Trim( "  " );
	if ( Buff.operator != ( ""  ) ) {
		if ( Cond.operator == ( "" ) ) {
			Cond.operator += (" where ");
		}
		else {
			Cond.operator += (" and ");
		}
		Cond.operator += (" 名称 like ");
		Buff.Enclose( "%" );
		Buff.Enclose( "'" );
		Cond.operator += ( &Buff );
	}

	// 日付条件(開始)
	if ( this->ButtonIsCheck( IDC_CHECK1 ) ) {
		From->GetDateString( &Buff );
		if ( Cond.operator == ( "" ) ) {
			Cond.operator += (" where ");
		}
		else {
			Cond.operator += (" and ");
		}
		Cond.operator += (" 作成日 >= ");
		Buff.operator +=( " 0:00:00" );
		Buff.Enclose( "'" );
		Cond.operator += ( &Buff );
	}
	// 日付条件(終了)
	if ( this->ButtonIsCheck( IDC_CHECK2 ) ) {
		To->GetDateString( &Buff );
		if ( Cond.operator == ( "" ) ) {
			Cond.operator += (" where ");
		}
		else {
			Cond.operator += (" and ");
		}
		Cond.operator += (" 作成日 <= ");
		Buff.operator +=( " 23:59:59" );
		Buff.Enclose( "'" );
		Cond.operator += ( &Buff );
	}

	// 条件決定
	Query.operator += ( &Cond );

	// 問合せマクロ
	LOAD_SQL(CurDb,LView,Query)

	// DB 接続解除
	CurDb.DisConnect();	
}

// *********************************************************
// 出力実行
// *********************************************************
void MyDlg::PrtData( void )
{
	// DB 接続マクロ
	CONNECT_DB

	// ドキュメント名(HTML) を指定して印字開始
	IEPrt->StartDoc( DOC_NAME );

	BOOL bRet;
	BOOL bFirst;

	// 印字データ作成
	bRet = CurDb.Query( &Query );
	bFirst = true;
	while( bRet ) {
		if ( bFirst ) {
			bFirst = false;
			this->PrtHead();
		}
		if ( this->nRow > this->nRowMax ) {
			IEPrt->NextPage();	// 改ページ
			this->PrtHead();
		}

		this->PrtDetail();

		bRet = CurDb.Query( );
	}

	// 印字終了
	IEPrt->EndDoc();

	// DB 接続解除
	CurDb.DisConnect();	

	// ドキュメント名(HTML) を指定して印刷プレビュー
	IEPrt->ReportPreview( DOC_NAME );

}

// *********************************************************
// タイトル部出力
// *********************************************************
void MyDlg::PrtHead( void )
{
	LboxString Buff;
	LboxString Work(300);

	// 1行目
	Work.Repeat( " ", 26 );
	Buff.operator = (Work);
	Buff.operator += ("** 商品分類一覧 **");
	Buff.operator += ("\n");
	IEPrt->Write( &Buff );	// 出力

	// 2行目
	Buff.operator = ("\n");
	IEPrt->Write( &Buff );	// 出力

	// 3行目
	Buff.operator = ("商品分類   名 称");
	Buff.operator += ("\n");
	IEPrt->Write( &Buff );	// 出力

	// 4行目
	Work.Repeat( "-", 53 );
	Buff.operator = (Work);
	Buff.operator += ("\n");
	IEPrt->Write( &Buff );	// 出力

	// 次に出力する行
	this->nRow = 5;

}

// *********************************************************
// 明細部出力
// *********************************************************
void MyDlg::PrtDetail( void )
{
	LboxString Buff;
	LboxString Work(300);
	LboxString Item;

	CurDb.GetText( "商品分類", &Item );
	Buff.operator = (&Item);
	Work.Repeat( " ", 8 );
	Buff.operator += (&Work);

	CurDb.GetText( "名称", &Item );
	Buff.operator += (&Item);
	Buff.operator += ("\n");
	IEPrt->Write( &Buff );	// 出力

	(this->nRow)++;

}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ