123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data.SqlClient;
- using System.Data;
- using System.IO;
- using System.Windows.Forms;
- using System.Drawing;
- using System.Threading;
- using FirebirdSql.Data.FirebirdClient;
- namespace IControls_FireManager
- {
-
- public static class _Db
- {
-
-
-
-
- public static string ConnectionString()
- {
- return string.Format("Server={0};User={1};Password={2};Database={3};Charset={4};ServerType={5}",
- _Data.DB_IP,
- _Data.DB_ID,
- _Data.DB_PassWord,
- _Data.DB_FullPath,
- "KSC_5601",
- "0");
- }
-
-
- public static bool OpenTest()
- {
- FbConnection CheckFbConnection = null;
- bool ret = false;
- try
- {
- string TestConnection = null;
- TestConnection = ConnectionString();
-
- if (CheckFbConnection != null) CheckFbConnection.Close();
- CheckFbConnection = new FbConnection(TestConnection);
- CheckFbConnection.Open();
- ret = (CheckFbConnection.State == ConnectionState.Open);
- if (ret == true)
- {
-
- if (_Data.DB_Connection_Open_Ok == false)
- {
-
- _Event.DebugView_SendMessage_Write(_Text.Blank + _Text.LeftBracket + TestConnection + _Text.RightBracket + _Text.Blank + _Text.LOG_DB_Connection_Ok);
-
-
-
-
- }
-
- _Data.DB_Connection_Open_Ok = true;
- }
- if (CheckFbConnection != null) CheckFbConnection.Dispose();
- return ret;
- }
- catch (Exception e)
- {
-
- if (_Data.DB_Connection_Open_Ok == true || _Data.DB_Connection_FailLogOnce == false)
- {
- _Event.DebugView_SendMessage_Write(e.ToString());
- _Data.DB_Connection_FailLogOnce = true;
- }
-
- _Data.DB_Connection_Open_Ok = false;
- if (CheckFbConnection != null) CheckFbConnection.Close();
- return false;
- }
- }
-
-
-
-
- public static void Execute(string SQL)
- {
-
- FbConnection session = null;
-
- FbCommand command = null;
-
- string address = null;
- try
- {
-
- address = ConnectionString();
-
-
- session = new FbConnection(address);
- session.Open();
- command = new FbCommand(SQL, session);
- command.ExecuteNonQuery();
- if (session != null) session.Close();
- if (command != null) command.Dispose();
- }
- catch (Exception e)
- {
-
- _Event.DebugView_SendMessage_Write(e.ToString() + "SQL:" + SQL);
- if (session != null) session.Close();
- if (command != null) command.Dispose();
- }
- }
-
-
-
-
-
- public static DataRowCollection ExecuteRead_SqlDataAdapter(string SQL)
- {
-
- FbConnection session = null;
-
- FbCommand command = null;
-
- string address = null;
-
- FbDataAdapter dataAdapter = null;
- DataSet dataSet = null;
- try
- {
-
- address = ConnectionString();
-
- session = new FbConnection(address);
- session.Open();
- command = new FbCommand(SQL, session);
- dataAdapter = new FbDataAdapter(SQL, session);
- dataAdapter.SelectCommand = command;
- dataSet = new DataSet();
- dataAdapter.Fill(dataSet, "GetData");
- if (dataAdapter != null) dataAdapter.Dispose();
- if (session != null) session.Close();
- if (command != null) command.Dispose();
- if (dataSet != null) dataSet.Dispose();
- return dataSet.Tables["GetData"].Rows;
- }
- catch (Exception e)
- {
-
- _Event.DebugView_SendMessage_Write(e.ToString());
- if (dataAdapter != null) dataAdapter.Dispose();
- if (session != null) session.Close();
- if (command != null) command.Dispose();
- if (dataSet != null) dataSet.Dispose();
- return null;
- }
- }
-
-
-
-
-
-
- public static int MAX_ColumnValue(string TableName, string Column)
- {
- DataRowCollection DB_Search_ColumnMaxValue = ExecuteRead_SqlDataAdapter(_Sql.Get_ColumnMaxValue(TableName, Column));
- int MaxValue = 0;
- try
- {
- foreach (DataRow Record in DB_Search_ColumnMaxValue)
- {
-
- if (Record[0].ToString().Length == 0)
- return 1;
-
- MaxValue = Int32.Parse(Record[0].ToString());
- }
- return MaxValue + 1;
- }
- catch (Exception e)
- {
-
- _Event.DebugView_SendMessage_Write(e.ToString());
- return 1;
- }
- }
-
-
-
-
- public static void ADD(string Table_Name, string Key_Data)
- {
- try
- {
-
- string strSQL = null;
- string tempSQL = null;
- strSQL = "insert into " + Table_Name + "(";
-
- string Temp_Names = _Convert.String_to_Key_Data(Key_Data, true, false);
-
- string[] Column_Names = Temp_Names.Split(_Convert.Result_Char);
-
- string Temp_Values = _Convert.String_to_Key_Data(Key_Data, false, false);
-
- string[] Column_Values = Temp_Values.Split(_Convert.Result_Char);
-
- tempSQL = null;
- for (int i = 0; i < Column_Names.Length; i++)
- tempSQL = tempSQL + Column_Names[i] + ",";
-
- strSQL = strSQL + tempSQL.TrimEnd(',') + ") values (";
-
- tempSQL = null;
- for (int i = 0; i < Column_Values.Length; i++)
- tempSQL = tempSQL + "'" + Column_Values[i] + "'" + ",";
-
- strSQL = strSQL + tempSQL.TrimEnd(',') + ")";
-
- _Db.Execute(strSQL);
- }
- catch (Exception e)
- {
-
- _Event.DebugView_SendMessage_Write(e.ToString());
- }
- }
-
-
-
- public static void UPDATE(string Table_Name, string Target_Key_Data, string Key_Data)
- {
- try
- {
-
- string strSQL = null;
- string tempSQL = null;
- strSQL = "update " + Table_Name + " set ";
-
- string Temp_Names = _Convert.String_to_Key_Data(Key_Data, true, false);
-
- string[] Column_Names = Temp_Names.Split(_Convert.Result_Char);
-
- string Temp_Values = _Convert.String_to_Key_Data(Key_Data, false, false);
-
- string[] Column_Values = Temp_Values.Split(_Convert.Result_Char);
-
- for (int i = 0; i < Column_Names.Length; i++)
- tempSQL = tempSQL + Column_Names[i] + "='" + Column_Values[i] + "'" + ",";
-
- strSQL = strSQL + tempSQL.TrimEnd(',');
-
- strSQL = strSQL + " where ";
-
-
-
-
- tempSQL = null;
-
- string Temp_Names_Target = _Convert.String_to_Key_Data(Target_Key_Data, true, false);
-
- string[] Column_Names_Target = Temp_Names_Target.Split(_Convert.Result_Char);
-
- string Temp_Values_Target = _Convert.String_to_Key_Data(Target_Key_Data, false, false);
-
- string[] Column_Values_Target = Temp_Values_Target.Split(_Convert.Result_Char);
-
- for (int i = 0; i < Column_Names_Target.Length; i++)
- tempSQL = tempSQL + Column_Names_Target[i] + "='" + Column_Values_Target[i] + "' and ";
-
- strSQL = strSQL + tempSQL.Remove(tempSQL.Length - 5);
-
- _Db.Execute(strSQL);
- }
- catch (Exception e)
- {
-
- _Event.DebugView_SendMessage_Write(e.ToString());
- }
- }
-
-
-
-
-
-
-
-
-
- }
- }
|