680ed59870e81c1bf82d02e2be453dcb93048da8.svn-base 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 DataGateWayProject
  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()); //UI 폼 열기
  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. LogFileCreate LFC = new LogFileCreate();
  64. System.Timers.Timer timer2 = new System.Timers.Timer();
  65. public static bool check = false;
  66. //public My_TimerThread()
  67. //{
  68. // timer2.Elapsed += new ElapsedEventHandler(timer2_Elapsed);
  69. //}
  70. //~My_TimerThread()
  71. //{
  72. // timer2.Elapsed -= new ElapsedEventHandler(timer2_Elapsed);
  73. //}
  74. public void timer2start()
  75. {
  76. timer2.Elapsed -= new ElapsedEventHandler(timer2_Elapsed);
  77. timer2.Elapsed += new ElapsedEventHandler(timer2_Elapsed);
  78. timer2.Interval = 2000; // 20sec 간격
  79. //timer2.Enabled = true;
  80. timer2.Start();
  81. LFC.Log("timer 시작");
  82. }
  83. public void timer2Stop()
  84. {
  85. timer2.Elapsed -= new ElapsedEventHandler(timer2_Elapsed);
  86. //System.Timers.Timer timer1 = new System.Timers.Timer();
  87. timer2.Stop();
  88. timer2.Close();
  89. //timer2.Enabled = false;
  90. //timer2.Dispose();
  91. LFC.Log("timer 중단");
  92. }
  93. public void timer2_Elapsed(object sender, ElapsedEventArgs e) // 1분마다 실행되는 데이터 수집 로직
  94. {
  95. string tmpMin = DateTime.Now.Minute.ToString(); // 현재의 '분' , if 51이라고했을때.
  96. if ((TimeCheck != tmpMin) && check == false)
  97. {
  98. check = true;
  99. CPG.Control_Group();
  100. CPG.Control_Point();
  101. TimeCheck = PS.SettingFileParsing();
  102. check = false;
  103. }
  104. }
  105. }
  106. /// <summary>
  107. /// 결과 값을 DB에 Insert시키기 위한 클래스
  108. /// </summary>
  109. class My_SqlDBInsert
  110. {
  111. SqlConnection conn; //sql 접속
  112. LogFileCreate LFC = new LogFileCreate();
  113. Readini Ri = new Readini();
  114. Form1 SF = new Form1();
  115. static private bool InsertOK = false;
  116. /// <summary>
  117. /// DB에 INSERT하기 위한 함수.
  118. /// </summary>
  119. /// <param name="FacilityTypeId"></param>
  120. /// <param name="FacilityCode"></param>
  121. /// <param name="PropertyId"></param>
  122. /// <param name="Value"></param>
  123. /// <returns></returns>
  124. public bool INsert(string FacilityTypeId, string FacilityCode, string PropertyId, object Value)
  125. {
  126. try
  127. {
  128. Ri.ReadData(); // ini의 설정값을 불러옴.
  129. string strcon = @"Data Source = " + Ri.UserIP + "," + Ri.UserPort + "; Initial Catalog =" + Ri.UserDB + ";Persist Security Info=True; User ID =" + Ri.UserID + "; Password =" + Ri.UserPW + "";
  130. conn = new SqlConnection(strcon);
  131. conn.Open();
  132. string query = "INSERT INTO BemsMonitoringPointHistory15min(SiteId,FacilityTypeId,FacilityCode,PropertyId,CreatedDateTime,CurrentValue) " +
  133. "VALUES('1','" + FacilityTypeId + "','" + FacilityCode + "','" + PropertyId + "','2016-09-08 08:43:00.000','" + Value + "')"; // INSERT 쿼리문.
  134. SqlCommand cmd = new SqlCommand(query, conn);
  135. cmd.ExecuteNonQuery();
  136. LFC.Log(query);
  137. SF.DBAddressTxt.Text = "연결";
  138. InsertOK = true;
  139. }
  140. catch
  141. {
  142. SF.DBAddressTxt.Text = "연결오류";
  143. InsertOK = false;
  144. }
  145. finally
  146. {
  147. conn.Dispose();
  148. conn.Close();
  149. }
  150. return InsertOK;
  151. }
  152. }
  153. }