_DacFireDesk.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using FirebirdSql.Data.FirebirdClient;
  5. using System.Data;
  6. using System.Collections;
  7. using System.IO;
  8. using System.Data.Common;
  9. using System.Diagnostics;
  10. namespace FPER
  11. {
  12. // 수신반의 경우 외부 DB 에 각각 접속해야된다.
  13. // DAC 로 시작하는 접두사로 구현된 나머지 클래스파일들은
  14. // MDIParent 기반에서 동작을 하기 때문에 수신기 아이디가 필수 였지만
  15. // DacFireDesk 에서는 오직 수신기 아이디를 기반으로 동작하게 만들어진다
  16. // 여기에서는 수신기 아이디가 0으로 들어오는 경우가 거의 없다고 가정한다
  17. public class _DacFireDesk
  18. {
  19. // 데이타베이스 아이피
  20. string DB_IP = null;
  21. // 데이타베이스 파일경로
  22. string DB_PATH = null;
  23. // 수신기아이디
  24. public string ReceiverID = null;
  25. // 데이타베이스 세션
  26. public FbConnection connection = null;
  27. public static int iOpenCount = 0;
  28. public static int iAccessCount = 0;
  29. public _DacFireDesk(string ID)
  30. {
  31. // 수신기 아이디
  32. ReceiverID = ID;
  33. _FireDesk_Receiver FireDesk_Receiver = (_FireDesk_Receiver)_Data.Hash_Receiver[ReceiverID];
  34. DB_IP = FireDesk_Receiver.DATABASE_NAME_IP;
  35. DB_PATH = FireDesk_Receiver.DATABASE_NAME_PATH;
  36. }
  37. ~_DacFireDesk()
  38. {
  39. }
  40. //
  41. // Read (Select)
  42. //
  43. //입출력 회로 타입조회
  44. public DataTable TB_DEVICE_TYPE_From_SelectAll()
  45. {
  46. DataTable dt = null;
  47. try
  48. {
  49. String SQL = "";
  50. SQL += "SELECT SYMBOL_TYPE,DEVICE_TYPE,DEVICE_TYPE_NAME,USE_FLAG,SEQ_NO ";
  51. SQL += "FROM TB_DEVICE_TYPE ";
  52. SQL += "WHERE SYMBOL_TYPE = 'O'";
  53. DataSet dao = Select(SQL);
  54. dt = dao.Tables[0];
  55. }
  56. catch (Exception ex)
  57. {
  58. Util.UErrorMessage(ex, 0, 0);
  59. }
  60. return dt;
  61. }
  62. //
  63. // Write (ExecuteNonQuery)
  64. //
  65. public void Receiver_Clear()
  66. {
  67. try
  68. {
  69. String SQL = "DELETE FROM TB_RECEIVER ";
  70. ExecuteNonQuery(SQL);
  71. }
  72. catch (Exception ex)
  73. {
  74. Util.UErrorMessage(ex, 0, 0);
  75. }
  76. }
  77. //
  78. // 데이타베이스
  79. //
  80. // 접속시작
  81. public bool Connect()
  82. {
  83. bool ret = false;
  84. try
  85. {
  86. // 사용자와 암호는 고정시킨다
  87. String strConnection = string.Format("Server={0};User={1};Password={2};Database={3};Charset={4};ServerType={5}",
  88. DB_IP, // IP ex)192.168.63.22
  89. "SYSDBA", // 사용자
  90. "masterkey", // 암호
  91. DB_PATH, // 절대위치.. ex) C:\TEST\TEST.FDB
  92. "KSC_5601", // KSC_5601 같은 문자셋을 지정
  93. "0"); // 0이면 Classic/Super Server, 1이면 Embedded Server를 지정하신다음...
  94. connection = new FbConnection(strConnection);
  95. connection.Open();
  96. iOpenCount++;
  97. iAccessCount++;
  98. if (iAccessCount > 100000)
  99. {
  100. iAccessCount = 0;
  101. }
  102. ret = (this.connection.State == ConnectionState.Open);
  103. }
  104. catch (Exception ex)
  105. {
  106. Util.UErrorMessage(ex, 0, 0);
  107. }
  108. return ret;
  109. }
  110. // 접속종료
  111. public void DisConnect()
  112. {
  113. try
  114. {
  115. if (connection != null)
  116. connection.Close();
  117. iOpenCount--;
  118. }
  119. catch (Exception ex)
  120. {
  121. Util.UErrorMessage(ex, 0, 0);
  122. }
  123. }
  124. // 쿼리요청-응답
  125. public DataSet Select(String sqlSyntax)
  126. {
  127. DataSet data = null;
  128. if (this.Connect())
  129. {
  130. try
  131. {
  132. FbCommand command = new FbCommand(sqlSyntax, connection);
  133. command.CommandType = CommandType.Text;
  134. command.CommandTimeout = 2147483647;
  135. data = new DataSet();
  136. FbDataAdapter adapter = new FbDataAdapter(command);
  137. adapter.Fill(data);
  138. adapter.Dispose();
  139. command.Dispose();
  140. }
  141. catch (Exception ex)
  142. {
  143. Util.UErrorMessage(ex, 0, 0);
  144. throw ex;
  145. }
  146. finally
  147. {
  148. this.DisConnect();
  149. }
  150. }
  151. return data;
  152. }
  153. // 쿼리명령
  154. public void ExecuteNonQuery(String sqlSyntax)
  155. {
  156. if (this.Connect())
  157. {
  158. FbTransaction transaction = connection.BeginTransaction();
  159. try
  160. {
  161. FbCommand command = new FbCommand(sqlSyntax, connection, transaction);
  162. command.CommandType = CommandType.Text;
  163. command.CommandTimeout = 2147483647;
  164. command.ExecuteNonQuery();
  165. transaction.Commit();
  166. command.Dispose();
  167. }
  168. catch (Exception ex)
  169. {
  170. Util.UErrorMessage(ex, 0, 0);
  171. transaction.Rollback();
  172. throw ex;
  173. }
  174. finally
  175. {
  176. this.DisConnect();
  177. }
  178. }
  179. }
  180. }
  181. }