123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Forms;
- using System.IO;
- using System.Text;
- using System.Diagnostics;
- using System.Collections;
- using System.Data.SqlClient;
- using System.Timers;
- using System.Threading;
- using System.Runtime.InteropServices;
- namespace DataGateWayProject
- {
- static class Program
- {
- /// <summary>
- /// 해당 응용 프로그램의 주 진입점입니다.
- /// </summary>
- ///
- [STAThread]
- static void Main()
- {
- //string mtxName = "DGW";
- //Mutex mtx = new Mutex(true, mtxName);
- ////1초 동안 뮤텍스를 획득하려 대기
- //TimeSpan tsWait = new TimeSpan(0, 0, 1);
- //bool success = mtx.WaitOne(tsWait);
- //if (!success)
- //{
- // MessageBox.Show("프로그램이 이미 실행중입니다.");
- // return;
- //}
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1()); //UI 폼 열기
- }
- }
- /// <summary>
- /// 타이머 스레드 클래스
- /// </summary>
- class My_TimerThread
- {
- static string TimeCheck = "";
- Parsing PS = new Parsing();
- Control_Point_Group CPG = new Control_Point_Group();
- LogFileCreate LFC = new LogFileCreate();
- System.Timers.Timer timer2 = new System.Timers.Timer();
- public static bool check = false;
- public void timer2start()
- {
- timer2.Elapsed -= new ElapsedEventHandler(timer2_Elapsed);
- timer2.Elapsed += new ElapsedEventHandler(timer2_Elapsed);
- timer2.Interval = 2000; // 20sec 간격
- timer2.Start();
- LFC.Log("timer 시작");
- }
- public void timer2Stop()
- {
- timer2.Elapsed -= new ElapsedEventHandler(timer2_Elapsed);
- timer2.Stop();
- timer2.Close();
- LFC.Log("timer 중단");
- }
- public void timer2_Elapsed(object sender, ElapsedEventArgs e) // 1분마다 실행되는 데이터 수집 로직
- {
- string tmpMin = DateTime.Now.Minute.ToString(); // 현재의 '분' , if 51이라고했을때.
- if ((TimeCheck != tmpMin) && check == false)
- {
- check = true;
- CPG.Control_Group();
- CPG.Control_Point();
- TimeCheck = PS.SettingFileParsing();
- check = false;
- }
- }
- }
- /// <summary>
- /// 결과 값을 DB에 Insert시키기 위한 클래스
- /// </summary>
- class My_SqlDBInsert
- {
- SqlConnection conn; //sql 접속
- LogFileCreate LFC = new LogFileCreate();
- Readini Ri = new Readini();
- Form1 SF = new Form1();
- static private bool InsertOK = false;
- /// <summary>
- /// DB에 INSERT하기 위한 함수.
- /// </summary>
- /// <param name="FacilityTypeId"></param>
- /// <param name="FacilityCode"></param>
- /// <param name="PropertyId"></param>
- /// <param name="Value"></param>
- /// <returns></returns>
- public bool INsert(string FacilityTypeId, string FacilityCode, string PropertyId, object Value)
- {
- try
- {
- Ri.ReadData(); // ini의 설정값을 불러옴.
- string strcon = @"Data Source = " + Ri.UserIP + "," + Ri.UserPort + "; Initial Catalog =" + Ri.UserDB + ";Persist Security Info=True; User ID =" + Ri.UserID + "; Password =" + Ri.UserPW + "";
- conn = new SqlConnection(strcon);
- conn.Open();
- string query = "INSERT INTO BemsMonitoringPointHistory15min(SiteId,FacilityTypeId,FacilityCode,PropertyId,CreatedDateTime,CurrentValue) " +
- "VALUES('1','" + FacilityTypeId + "','" + FacilityCode + "','" + PropertyId + "','2016-09-08 08:43:00.000','" + Value + "')"; // INSERT 쿼리문.
- SqlCommand cmd = new SqlCommand(query, conn);
- cmd.ExecuteNonQuery();
- cmd.Dispose();
- LFC.Log(query);
- SF.DBAddressTxt.Text = "연결";
- InsertOK = true;
- }
- catch (Exception e)
- {
- SF.DBAddressTxt.Text = "연결오류";
- InsertOK = false;
- LFC.Log("프로그램 연결 오류 : " + e);
- }
- finally
- {
- conn.Close();
- conn.Dispose();
- }
- return InsertOK;
- }
- }
- }
|