| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 | using System;using System.Collections.Generic;using System.Text;using FirebirdSql.Data.FirebirdClient;using System.Data;using System.Collections;using System.IO;using System.Data.Common;using System.Diagnostics;namespace FPER{    // 수신반의 경우 외부 DB 에 각각 접속해야된다.    // DAC 로 시작하는 접두사로 구현된 나머지 클래스파일들은    // MDIParent 기반에서 동작을 하기 때문에 수신기 아이디가 필수 였지만    // DacFireDesk 에서는 오직 수신기 아이디를 기반으로 동작하게 만들어진다    // 여기에서는 수신기 아이디가 0으로 들어오는 경우가 거의 없다고 가정한다    public class _DacFireDesk    {        // 데이타베이스 아이피        string DB_IP = null;        // 데이타베이스 파일경로        string DB_PATH = null;        // 수신기아이디        public string ReceiverID = null;        // 데이타베이스 세션        public FbConnection connection = null;        public static int iOpenCount = 0;        public static int iAccessCount = 0;        public _DacFireDesk(string ID)        {            // 수신기 아이디            ReceiverID = ID;            _FireDesk_Receiver FireDesk_Receiver = (_FireDesk_Receiver)_Data.Hash_Receiver[ReceiverID];            DB_IP = FireDesk_Receiver.DATABASE_NAME_IP;            DB_PATH = FireDesk_Receiver.DATABASE_NAME_PATH;        }        ~_DacFireDesk()        {        }        //        // Read (Select)        //        //입출력 회로 타입조회        public DataTable TB_DEVICE_TYPE_From_SelectAll()        {            DataTable dt = null;            try            {                String SQL = "";                SQL += "SELECT SYMBOL_TYPE,DEVICE_TYPE,DEVICE_TYPE_NAME,USE_FLAG,SEQ_NO ";                SQL += "FROM TB_DEVICE_TYPE ";                SQL += "WHERE SYMBOL_TYPE = 'O'";                DataSet dao = Select(SQL);                dt = dao.Tables[0];            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }            return dt;        }        //        // Write (ExecuteNonQuery)        //        public void Receiver_Clear()        {            try            {                String SQL = "DELETE FROM TB_RECEIVER ";                ExecuteNonQuery(SQL);            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }        }        //        // 데이타베이스        //        // 접속시작        public bool Connect()        {            bool ret = false;            try            {                // 사용자와 암호는 고정시킨다                String strConnection = string.Format("Server={0};User={1};Password={2};Database={3};Charset={4};ServerType={5}",                                    DB_IP,              // IP ex)192.168.63.22                                     "SYSDBA",           // 사용자                                     "masterkey",        // 암호                                     DB_PATH,            // 절대위치.. ex) C:\TEST\TEST.FDB                                     "KSC_5601",         // KSC_5601 같은 문자셋을 지정                                     "0");               // 0이면 Classic/Super Server, 1이면 Embedded Server를 지정하신다음...                 connection = new FbConnection(strConnection);                connection.Open();                iOpenCount++;                iAccessCount++;                if (iAccessCount > 100000)                {                    iAccessCount = 0;                }                ret = (this.connection.State == ConnectionState.Open);            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }            return ret;        }        // 접속종료        public void DisConnect()        {            try            {                if (connection != null)                    connection.Close();                iOpenCount--;            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }        }        // 쿼리요청-응답        public DataSet Select(String sqlSyntax)        {            DataSet data = null;            if (this.Connect())            {                try                {                    FbCommand command = new FbCommand(sqlSyntax, connection);                    command.CommandType = CommandType.Text;                    command.CommandTimeout = 2147483647;                    data = new DataSet();                    FbDataAdapter adapter = new FbDataAdapter(command);                    adapter.Fill(data);                    adapter.Dispose();                    command.Dispose();                }                catch (Exception ex)                {                    Util.UErrorMessage(ex, 0, 0);                    throw ex;                }                finally                {                    this.DisConnect();                }            }            return data;        }        // 쿼리명령        public void ExecuteNonQuery(String sqlSyntax)        {            if (this.Connect())            {                FbTransaction transaction = connection.BeginTransaction();                try                {                    FbCommand command = new FbCommand(sqlSyntax, connection, transaction);                    command.CommandType = CommandType.Text;                    command.CommandTimeout = 2147483647;                    command.ExecuteNonQuery();                    transaction.Commit();                    command.Dispose();                }                catch (Exception ex)                {                    Util.UErrorMessage(ex, 0, 0);                    transaction.Rollback();                    throw ex;                }                finally                {                    this.DisConnect();                }            }        }    }}
 |