問合せを DLL に


  DlgSyain クラスを作成



DlgSyain.h

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

class DlgSyain : public CLDlg  
{
public:
	void LVDblclick();
	void WMAll();
	void GetData();
	void ProcOperator();
	void ProcEnd();
	void WMInitdialog();

	DlgSyain();
	virtual ~DlgSyain();

	LboxDatabase CurDb;	// データベースオブジェクト(実体型)
	LboxListview *LView;	// リストビューオブジェクト(ポインタ型)

	LboxString Key;
	LboxString Name;
};
  

DlgSyain.cpp

※ 基本的に HM040 プロジェクトの MyDlg2.cpp と同じです

  
#include "stdafx.h"
#include "resource.h"
#include "DlgSyain.h"

//////////////////////////////////////////////////////////////////////
// 構築/消滅
//////////////////////////////////////////////////////////////////////

DlgSyain::DlgSyain()
{

}

DlgSyain::~DlgSyain()
{

}

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

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

	LboxString Buff;

	// MySQL 接続文字列
	Buff.operator = ("MySQL,lightbox,root,");
	CurDb.SetConnectString( 3, &Buff );

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

	GetData();

	this->MoveWindow( 0, 0 );
}

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

// *********************************************************
// オペレータイベント
// *********************************************************
void DlgSyain::ProcOperator()
{
	switch( ControlId ) {
		case IDOK:
			GetData();
			break;
	}
}

// *********************************************************
// 問合せ処理
// *********************************************************
void DlgSyain::GetData()
{
	if ( !CurDb.Connect() ) {
		MsgOk("接続に失敗しました \n%s", CurDb.ErrMessage.szLboxString);
		return;
	}

	LboxString Query;

	Query.operator = ("select * from 社員マスタ");

	LboxString Cond( "" );
	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 );
	}

	Query.operator += ( &Cond );

	int nRet;

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

	CurDb.DisConnect();	
}

// *********************************************************
// 初期化とオペレータイベント以外の処理
// *********************************************************
void DlgSyain::WMAll()
{
	USE_LVIEW(LView)
}

// *********************************************************
// ダブルクリックイベント
// *********************************************************
void DlgSyain::LVDblclick()
{
	LboxString LWork;

	if ( LView->IsHandle( this->hTargetWindow ) ) {
		LView->GetColumnText( 0, &Key );
		LView->GetColumnText( 1, &Name );
		this->ProcEnd();
		::EndDialog( this->hDlg, IDOK );
	}
}
  










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





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

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ