123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Collections;
- using System.Text.RegularExpressions;
- using System.Data.SqlClient;
- using System.Collections.Concurrent;
- namespace BEMSDataGateway
- {
- class Expression_Process
- {
- private string[] temp;
- LogFileCreate LFC = new LogFileCreate();
-
- public void ReadCSV_Passing_Expression(IDictionary<string, float[]> AllDic, int NowMin, string Table_Type, IDictionary<string, string> MatchingDic)
- {
- StreamReader sr = new StreamReader("Expression.csv", Encoding.GetEncoding("euc-kr"));
- Parsing Ps = new Parsing();
- My_DB_DML MDD = new My_DB_DML();
- string[] tempId = new string[4];
- string strcon = MDD.ConnDBInfo();
- string query = "";
- string TempExp = "";
- string ResultValue = "";
- string[] Store_Type = new string[3];
- int Count = 0;
- while (!sr.EndOfStream)
- {
-
- string s = sr.ReadLine();
- temp = s.Split(',');
-
-
-
-
- tempId = temp[3].Split('.');
- string Virtual_SiteId = tempId[0];
- string Virtual_FacilityTypeId = tempId[1];
- string Virtual_FacilityCode = tempId[2];
- string Virtual_PropertyId = tempId[3];
- Store_Type = temp[1].Split('.');
- if (!("".Equals(s)))
- {
- object resultexp = 0;
- MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl();
- sc.Language = "VBScript";
- string Pattern = "Tag" + @"\d{1,5}";
- Regex regex = new Regex(Pattern);
-
- foreach (Match match in regex.Matches(temp[2]))
- {
- string Tag_Name = Convert.ToString(match);
- if (Table_Type == "Raw" && Store_Type[0] == "T")
- {
- temp[2] = temp[2].Replace(Tag_Name, AllDic[MatchingDic[Tag_Name]][0].ToString());
- Count++;
- }
- else if (Table_Type == "FiftMin" && Store_Type[1] == "T")
- {
- int Array_Value_Select = Ps.Select_MinTime_Data(NowMin);
- temp[2] = temp[2].Replace(Tag_Name, AllDic[MatchingDic[Tag_Name]][Array_Value_Select].ToString());
- Count++;
- }
- else if (Table_Type == "Hour" && Store_Type[2] == "T" && NowMin == 00)
- {
- temp[2] = temp[2].Replace(Tag_Name, AllDic[MatchingDic[Tag_Name]][12].ToString());
- Count++;
- }
- }
- if (Count > 0)
- {
- TempExp = temp[2];
- resultexp = sc.Eval(TempExp);
- ResultValue = Convert.ToString(Math.Round(Convert.ToDouble(resultexp), 4, MidpointRounding.AwayFromZero));
- using (SqlConnection conn = new SqlConnection(strcon))
- {
- conn.Open();
- string InsertDate = DateTime.Now.ToString("yyyy-MM-dd HH:" + NowMin + ":00.000");
- switch (Table_Type)
- {
- case "Raw":
- query = "INSERT INTO " + Table.RawT + "(SiteId,FacilityTypeId,FacilityCode,PropertyId,CreatedDateTime,CurrentValue) "
- + "VALUES(" + Virtual_SiteId + "," + Virtual_FacilityTypeId + "," + Virtual_FacilityCode + "," + Virtual_PropertyId + ",'" + InsertDate + "'," + ResultValue + ")";
- break;
- case "FiftMin":
- query = "INSERT INTO " + Table.FiFt + "(SiteId,FacilityTypeId,FacilityCode,PropertyId,CreatedDateTime,CurrentValue) "
- + "VALUES(" + Virtual_SiteId + "," + Virtual_FacilityTypeId + "," + Virtual_FacilityCode + "," + Virtual_PropertyId + ",'" + InsertDate + "'," + ResultValue + ")";
- break;
- case "Hour":
- query = "INSERT INTO " + Table.Hourly + "(SiteId,FacilityTypeId,FacilityCode,PropertyId,CreatedDateTime,CurrentValue) "
- + "VALUES(" + Virtual_SiteId + "," + Virtual_FacilityTypeId + "," + Virtual_FacilityCode + "," + Virtual_PropertyId + ",'" + InsertDate + "'," + ResultValue + ")";
- break;
- }
- SqlCommand cmd = new SqlCommand(query, conn);
- LFC.Log("[Expression_Process.cs] Query : "+query + Environment.NewLine);
- cmd.ExecuteNonQuery();
- conn.Close();
- }
- }
- Count = 0;
- }
- }
- }
- }
- }
|