5a10ce5d6fadd6b72bdf1bf9926572b917834367.svn-base 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5. using System.IO;
  6. using System.Text;
  7. using System.Diagnostics;
  8. using System.Collections;
  9. using System.Data.SqlClient;
  10. using System.Timers;
  11. using System.Threading;
  12. using System.Runtime.InteropServices;
  13. //Stopwatch SW = new Stopwatch();
  14. //string sTemp1;
  15. //SW.Reset();
  16. //SW.Start();
  17. //SW.Stop(); // 현재 인스턴스가 측정한 총 경과 시간을 가져옵니다.
  18. //sTemp1 = SW.Elapsed.ToString();
  19. //MessageBox.Show(sTemp1);
  20. namespace BEMSDataGateway
  21. {
  22. static class Program
  23. {
  24. /// <summary>
  25. /// 해당 응용 프로그램의 주 진입점입니다.
  26. /// </summary>
  27. ///
  28. [STAThread]
  29. static void Main()
  30. {
  31. //// GUID를 뮤텍스명으로 사용
  32. ////string mtxName = "4AD31D94-659B-44A7-9277-1DD793E415D1";
  33. //// GUID 대신 사용자 임의대로 뮤텍스 이름 사용
  34. //string mtxName = "DGW";
  35. //Mutex mtx = new Mutex(true, mtxName);
  36. //// 1초 동안 뮤텍스를 획득하려 대기
  37. //TimeSpan tsWait = new TimeSpan(0, 0, 1);
  38. //bool success = mtx.WaitOne(tsWait);
  39. //if (!success)
  40. //{
  41. // MessageBox.Show("프로그램이 이미 실행중입니다.");
  42. // return;
  43. //}
  44. //Parsing ps = new Parsing();
  45. //ps.SettingFileParsing();
  46. Application.EnableVisualStyles();
  47. Application.SetCompatibleTextRenderingDefault(false);
  48. //Application.Run(new Loading_Form()); // Splash window 띄우기
  49. Application.Run(new Form1());
  50. }
  51. }
  52. //------------------------------------------------------------------------------------------------------
  53. //------------------------------------------------------------------------------------------------------
  54. //------------------------------------------------------------------------------------------------------
  55. /// <summary>
  56. /// 타이머 스레드 클래스
  57. /// </summary>
  58. class My_TimerThread
  59. {
  60. static string TimeCheck = "";
  61. Parsing PS = new Parsing();
  62. Control_Point_Group CPG = new Control_Point_Group();
  63. System.Timers.Timer timer2 = new System.Timers.Timer();
  64. public static bool check = false;
  65. public void timer2start()
  66. {
  67. timer2.Interval = 2000; // 2sec 간격
  68. timer2.Elapsed += new ElapsedEventHandler(timer2_Elapsed);
  69. timer2.Start();
  70. }
  71. public void timer2Stop()
  72. {
  73. //System.Timers.Timer timer1 = new System.Timers.Timer();
  74. timer2.Stop();
  75. timer2.Enabled = false;
  76. timer2.Dispose();
  77. }
  78. public void timer2_Elapsed(object sender, ElapsedEventArgs e) // 1분마다 실행되는 데이터 수집 로직
  79. {
  80. string tmpMin = DateTime.Now.Minute.ToString(); // 현재의 '분' , if 51이라고했을때.
  81. if ((TimeCheck != tmpMin) && check == false)
  82. {
  83. check = true;
  84. CPG.Control_Group();
  85. CPG.Control_Point();
  86. TimeCheck = PS.SettingFileParsing();
  87. check = false;
  88. }
  89. }
  90. }
  91. /// <summary>
  92. /// 결과 값을 DB에 Insert시키기 위한 클래스
  93. /// </summary>
  94. class My_SqlDBInsert
  95. {
  96. SqlConnection conn; //sql 접속
  97. LogFileCreate LFC = new LogFileCreate();
  98. Readini Ri = new Readini();
  99. Form1 SF = new Form1();
  100. static private bool InsertOK = false;
  101. /// <summary>
  102. /// DB에 INSERT하기 위한 함수.
  103. /// </summary>
  104. /// <param name="FacilityTypeId"></param>
  105. /// <param name="FacilityCode"></param>
  106. /// <param name="PropertyId"></param>
  107. /// <param name="Value"></param>
  108. /// <returns></returns>
  109. public bool INsert(string FacilityTypeId, string FacilityCode, string PropertyId, object Value)
  110. {
  111. try
  112. {
  113. Ri.ReadData(); // ini의 설정값을 불러옴.
  114. string strcon = @"Data Source = " + Ri.UserIP + "," + Ri.UserPort + "; Initial Catalog =" + Ri.UserDB + ";Persist Security Info=True; User ID =" + Ri.UserID + "; Password =" + Ri.UserPW + "";
  115. conn = new SqlConnection(strcon);
  116. conn.Open();
  117. string query = "INSERT INTO BemsMonitoringPointHistory15min(SiteId,FacilityTypeId,FacilityCode,PropertyId,CreatedDateTime,CurrentValue) " +
  118. "VALUES('1','" + FacilityTypeId + "','" + FacilityCode + "','" + PropertyId + "','2016-09-08 08:43:00.000','" + Value + "')"; // INSERT 쿼리문.
  119. SqlCommand cmd = new SqlCommand(query, conn);
  120. cmd.ExecuteNonQuery();
  121. LFC.Log(query);
  122. SF.DBAddressTxt.Text = "연결";
  123. InsertOK = true;
  124. }
  125. catch
  126. {
  127. SF.DBAddressTxt.Text = "연결오류";
  128. InsertOK = false;
  129. }
  130. finally
  131. {
  132. conn.Dispose();
  133. conn.Close();
  134. }
  135. return InsertOK;
  136. }
  137. }
  138. }