コメント |
@DIV
using System.Data.Odbc;
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
// ********************************************************
// * 実行
// ********************************************************
public class App
{
public static void Main() {
}
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// 処理クラス
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
public class lightbox
{
// 接続オブジェクト
private OdbcConnection myCon = new OdbcConnection();
// コマンドオブジェクト
private OdbcCommand myCommand = new OdbcCommand();
// 接続文字列
public String strCon = String.Empty;
// ********************************************************
// コンストラクタの定義( クラスと同名 )
// ********************************************************
public lightbox( String str ) {
strCon = str;
}
// ********************************************************
// 接続処理
// ********************************************************
public bool Connect() {
bool bRet = true;
// 接続文字列セット
myCon.ConnectionString = strCon;
// ====================================================
// 例外処理
// ====================================================
try {
// 接続
myCon.Open();
}
catch( Exception ex ) {
bRet = false;
MessageBox.Show( ex.Message );
}
// コマンドオブジェクトを接続に関係付ける
myCommand.Connection = myCon;
return bRet;
}
// ********************************************************
// 接続解除処理
// ********************************************************
public void Close() {
myCon.Close();
}
// ********************************************************
// 配列化関数
// ********************************************************
public String[] GetArray(String str,String d) {
// 区切り文字定義
String delimStr = d;
Char[] delimiter = delimStr.ToCharArray();
// 分解
String[] aRet = str.Split(delimiter);
return aRet;
}
// ********************************************************
// 存在チェック
// ********************************************************
public bool ExistData(String strQuery) {
OdbcDataReader myReader = null;
bool bRet = true;
// コマンドセット
myCommand.CommandText = strQuery;
// ====================================================
// 例外処理
// ====================================================
try {
// リーダーオブジェクト取得
myReader = myCommand.ExecuteReader();
}
catch( Exception ex ) {
myCon.Close();
MessageBox.Show( ex.Message );
System.Environment.Exit( 0 );
}
bRet = myReader.HasRows;
myReader.Close();
return bRet;
}
// ********************************************************
// 更新関数
// ********************************************************
public bool UpdateDB(String strExec) {
myCommand.CommandText = strExec;
// ====================================================
// 例外処理
// ====================================================
try {
// 実行
myCommand.ExecuteNonQuery();
}
catch( Exception ex ) {
myCon.Close();
MessageBox.Show( ex.Message );
System.Environment.Exit( 0 );
}
return true;
}
// ********************************************************
// プログラムが実行されているディレクトリを取得
// ********************************************************
String GetProgramDir( ) {
System.Reflection.Assembly ab = System.Reflection.Assembly.GetExecutingAssembly();
System.Reflection.Module md = ab.GetModules()[0];
// **************************************************************
// ディレクトリ部分を取得( System.IO.Path.GetDirectoryName が簡単 )
// **************************************************************
String[] aDataDir = GetArray( md.FullyQualifiedName, @"\" );
String pgDir = String.Join( @"\", aDataDir, 0, aDataDir.Length - 1 );
return pgDir;
}
}
@END
|