강기헌 강기헌 2023-02-24
..
@a58afefce92ef9ead4753bcac4d19d5edff00df5
KHSCALE_TP/Program.cs
--- KHSCALE_TP/Program.cs
+++ KHSCALE_TP/Program.cs
@@ -18,10 +18,14 @@
         {
             U3Config config = new U3Config();
 
+            U3Util.ErrorLog("프로그램 시작");
+
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
             Application.Run(new FormScale());
             m_ThreadRun = false;
+
+            U3Util.ErrorLog("프로그램 종료");
         }
     }
 }
ModbusTest/FormModbus.cs
--- ModbusTest/FormModbus.cs
+++ ModbusTest/FormModbus.cs
@@ -316,9 +316,18 @@
         public int RunState = 0;
         List<string[,]> lst = new List<string[,]>();
         string[,] array;
+
+
         private void timer_AutoInput_Tick(object sender, EventArgs e)
         {
-            switch(RunState)
+            DateTime dt = DateTime.Now;
+            if (dt.Hour == 2 && dt.Minute == 2 && dt.Second == 2)
+            {
+                this.Close();
+                return;
+            }
+
+            switch (RunState)
             {
                 case 0:
                     //U3Util.ErrorLog(textBox_State.Text);
@@ -983,6 +992,8 @@
 
             if (input_Mach_CD == "" || input_RealData == "") return;
 
+            U3Util.ErrorLog("void DB_Input(string[,]Data) --> HTSaveRealDataAll");
+
             if (DBConnectionSingleton.Instance().SetCommand("HTSaveRealDataAll",
                 DBConnectionSingleton.Instance().getParams("COMP_CD", "0001"),
                 DBConnectionSingleton.Instance().getParams("MACH_CD", input_Mach_CD),
@@ -1067,6 +1078,8 @@
 
             if (input_Mach_CD == "" || input_RealData == "") return;
 
+            U3Util.ErrorLog("All_Data_Insert --> HTSaveRealDataAll");
+
             if (DBConnectionSingleton.Instance().SetCommand("HTSaveRealDataAll",
                 DBConnectionSingleton.Instance().getParams("COMP_CD", "0001"),
                 DBConnectionSingleton.Instance().getParams("MACH_CD", input_Mach_CD),
@@ -1075,6 +1088,14 @@
                 textBox_State.Text += "DBInsert Complete : " + input_Mach_CD + "\r\n";
                 textBox_State.Text += "DBInsert Complete : " + input_RealData + "\r\n";
             }
+
+            if (CheckTemp() == false)
+            {
+                this.Close();
+                return;
+            }
+
+            U3Util.ErrorLog("온도 체크 완료. All_Data_Insert");
 
             UpdateHbtOnOff();
             UpdateBaseoilSwitch();
@@ -1247,6 +1268,7 @@
                 string strBaseoil = U3Util.toStr(drCurPV["REMARK04"]);
                 string strMachCD = U3Util.toStr(drCurPV["MACH_CD"]);
                 string strMachNM = U3Util.toStr(drCurPV["MACH_NM"]);
+                string strRealData = U3Util.toStr(drCurPV["REAL_DATA"]);
                 float fPV = U3Util.toFloat(drCurPV["PV_VAL"]);
 
                 if (m_dicPV.ContainsKey(strMachCD) == false)
@@ -1261,11 +1283,12 @@
                         U3Util.ErrorLog("### " + strBaseoil + " = 이전: " + fPrev.ToString() + " / 현재: " + fPV.ToString());
 
                         string sql3 = "";
-                        sql3 += " insert into T_HT_HIST_BASEOIL (COMP_CD,BASEOIL_CD,HBT_CD,ONOFF_YN,PV_VAL,MACH_NM,REG_DT) values (";
+                        sql3 += " insert into T_HT_HIST_BASEOIL (COMP_CD,BASEOIL_CD,HBT_CD,ONOFF_YN,REAL_DATA,PV_VAL,MACH_NM,REG_DT) values (";
                         sql3 += " '0001', ";
                         sql3 += " '" + strBaseoil + "', ";
                         sql3 += " '', ";
                         sql3 += " 'X', ";
+                        sql3 += " " + strRealData + ", ";
                         sql3 += " " + fPrev.ToString() + ", ";
                         sql3 += " '" + strMachNM + "', ";
                         sql3 += " getdate() ";
@@ -1290,9 +1313,10 @@
             }
 
             Dictionary<string, float> pvDic = new Dictionary<string, float>();
+            Dictionary<string, float> realDataDic = new Dictionary<string, float>();
             Dictionary<string, string> machNmDic = new Dictionary<string, string>();
             strSQL = "";
-            strSQL += " SELECT a.MACH_CD, (REAL_DATA * VALUE_RATIO) as PV_VAL, MACH_NM, REMARK04";
+            strSQL += " SELECT a.MACH_CD, a.REAL_DATA, (REAL_DATA * VALUE_RATIO) as PV_VAL, MACH_NM, REMARK04";
             strSQL += " FROM T_HT_REAL_DATA a";
             strSQL += " left join T_STD_MACH b on a.MACH_CD = b.MACH_CD";
             strSQL += " where b.REMARK04 is not null";
@@ -1301,9 +1325,13 @@
             {
                 string strKey = U3Util.toStr(drPv["REMARK04"]);
                 float fVal = U3Util.toFloat(drPv["PV_VAL"]);
+                float fRealData = U3Util.toFloat(drPv["REAL_DATA"]);
                 string strMachNm = U3Util.toStr(drPv["MACH_NM"]);
+
                 if (pvDic.ContainsKey(strKey) == false)
                     pvDic.Add(strKey, fVal);
+                if (realDataDic.ContainsKey(strKey) == false)
+                    realDataDic.Add(strKey, fRealData);
                 if (machNmDic.ContainsKey(strKey) == false)
                     machNmDic.Add(strKey, strMachNm);
             }
@@ -1350,6 +1378,12 @@
                         pvVal = pvDic[item.Key];
                     }
 
+                    float realDataVal = 0;
+                    if (realDataDic.ContainsKey(item.Key))
+                    {
+                        realDataVal = realDataDic[item.Key];
+                    }
+
                     string mach_nm = "";
                     if (machNmDic.ContainsKey(item.Key))
                     {
@@ -1360,11 +1394,13 @@
                     if (item.Value != oldValue)
                     {
                         float pvVal2 = 0;
+                        float realDataVal2 = 0;
+
                         if (item.Value.Length == 0)
                         {
                             // N인 경우 PV_VAL2 에 차이값을 저장한다
                             string sql4 = "";
-                            sql4 += " select* from T_HT_HIST_BASEOiL";
+                            sql4 += " select * from T_HT_HIST_BASEOiL";
                             sql4 += " where BASEOIL_CD = '" + item.Key + "' and HBT_CD = '" + oldValue + "'";
                             sql4 += " order by idx desc";
 
@@ -1373,15 +1409,20 @@
                             {
                                 float fPrev = U3Util.toFloat(dt4.Rows[0]["PV_VAL"]);
                                 pvVal2 = fPrev - pvVal;
+
+                                float rPrev = U3Util.toFloat(dt4.Rows[0]["REAL_DATA"]);
+                                realDataVal2 = rPrev - realDataVal;
                             }
                         }
 
                         string sql3 = "";
-                        sql3 += " insert into T_HT_HIST_BASEOIL (COMP_CD,BASEOIL_CD,HBT_CD,ONOFF_YN,PV_VAL,PV_VAL2,MACH_NM,REG_DT) values (";
+                        sql3 += " insert into T_HT_HIST_BASEOIL (COMP_CD,BASEOIL_CD,HBT_CD,ONOFF_YN,REAL_DATA,REAL_DATA2, PV_VAL,PV_VAL2,MACH_NM,REG_DT) values (";
                         sql3 += " '0001', ";
                         sql3 += " '" + item.Key + "', ";
                         sql3 += " '" + ((item.Value.Length > 0) ? item.Value : oldValue) + "', ";
                         sql3 += " '" + ((item.Value.Length > 0) ? "Y" : "N") + "', ";
+                        sql3 += " " + realDataVal.ToString() + ", ";
+                        sql3 += " " + realDataVal2.ToString() + ", ";
                         sql3 += " " + pvVal.ToString() + ", ";
                         sql3 += " " + pvVal2.ToString() + ", ";
                         sql3 += " '" + mach_nm + "', ";
@@ -1464,9 +1505,55 @@
             }
         }
 
+        // 온도값이 500이 넘는 오류가 발생하면 프로그램을 종료한다
+        private bool CheckTemp()
+        {
+            U3Database db = new U3Database();
+            string strSQL = "";
+
+            strSQL = "";
+            strSQL += " select r.MACH_CD,(r.REAL_DATA * m.VALUE_RATIO) REAL_DATA, m.MACH_NM, m.MACH_NO, c.WORK_ROUT_CD";
+            strSQL += " FROM T_HT_REAL_DATA r";
+            strSQL += " left join T_STD_MACH m on r.MACH_CD = m.MACH_CD and r.COMP_CD = m.COMP_CD";
+            strSQL += " left join T_STD_CODE c on c.NO_RMK = m.MACH_NO order by r.MACH_CD asc";
+            DataTable dtTemp = db.OpenSQL(strSQL);
+
+            if (dtTemp == null || dtTemp.Rows.Count == 0)
+                return true;
+
+            bool bResult = true;
+            int nZeroCount = 0;
+
+            foreach (DataRow dr in dtTemp.Rows)
+            {
+                string sName = U3Util.toStr(dr["MACH_NM"]);
+                float fVal = U3Util.toFloat(dr["REAL_DATA"]);
+
+                if (sName.IndexOf("온도") > 0)
+                {
+                    if (fVal >= 500)
+                    {
+                        bResult = false;
+                        U3Util.ErrorLog("온도이상 발생 " + sName + " = " + fVal.ToString());
+                    }
+                    if (fVal == 0)
+                    {
+                        nZeroCount++;
+                        if (nZeroCount > 5)
+                        {
+                            bResult = false;
+                            U3Util.ErrorLog("온도이상 발생 " + sName + " = " + fVal.ToString());
+                        }
+                    }
+                }
+            }
+            return bResult;
+        }
 
         private void timer_Log_Tick(object sender, EventArgs e)
         {
+            U3Util.ErrorLog("timer_Log_Tick --> HTInsertRealToLog");
+
             if (DBConnectionSingleton.Instance().SetCommand("HTInsertRealToLog"))
             {
                 //textBox_State.Text += "DBInsert Complete : Log Insert\r\n";
ModbusTest/Program.cs
--- ModbusTest/Program.cs
+++ ModbusTest/Program.cs
@@ -16,6 +16,8 @@
         {
             U3Config config = new U3Config();
 
+            U3Util.ErrorLog("프로그램 시작");
+
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
 
@@ -24,6 +26,8 @@
             //test();
 
             Application.Run(new FormModbus());
+
+            U3Util.ErrorLog("프로그램 종료");
         }
 
         static void test()
SignusKH/Form1.cs
--- SignusKH/Form1.cs
+++ SignusKH/Form1.cs
@@ -54,6 +54,14 @@
             else if (System.IO.File.Exists(strChrome3))
                 this.m_lstExe.Add(strChrome3);
 
+
+            // 크롬은 한번만 실행하고 재실행 안함
+            UpdateProgram(0);
+            this.m_lstExe.Clear();
+
+
+            this.m_lstExe.Add(AppPath + string.Format("\\KHSCALE-1.exe"));
+            this.m_lstExe.Add(AppPath + string.Format("\\KHSCALE-2.exe"));
             this.m_lstExe.Add(AppPath + string.Format("\\KHSCALE.exe"));
             //this.m_lstExe.Add(AppPath + string.Format("\\YdtechInTemp.exe"));
             //this.m_lstExe.Add(AppPath + string.Format("\\YdtechOutTemp.exe"));
@@ -81,12 +89,19 @@
 
         public void UpdateProgram(int index)
         {
+            U3Util.ErrorLog(index.ToString() + " Update");
+
             if (index < 0) return;
             if (index >= this.m_lstExe.Count()) return;
 
             string AppExe = this.m_lstExe[index];
+            U3Util.ErrorLog(AppExe);
+
             if (System.IO.File.Exists(AppExe) == false)
+            {
+                U3Util.ErrorLog(AppExe + " 찾을 수 없음");
                 return;
+            }
 
             string AppPath = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\\"));
 
@@ -124,6 +139,8 @@
                 return;
             }
 
+            U3Util.ErrorLog(AppExe + " 실행");
+
             m_ps[index].StartInfo.FileName = AppExe;
             m_ps[index].StartInfo.WorkingDirectory = AppPath;
             m_ps[index].StartInfo.Arguments = "";
SignusKH/Program.cs
--- SignusKH/Program.cs
+++ SignusKH/Program.cs
@@ -33,11 +33,15 @@
                 return;
             }
 
+            U3Util.ErrorLog("프로그램 시작");
+
             messageQuit = RegisterWindowMessage("MSG_SIGNUS_QUIT");
 
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
             Application.Run(new Form1());
+
+            U3Util.ErrorLog("프로그램 종료");
         }
 
         static public void DeleteOldFiles(string dirName, int nSec)
SignusKH/SignusKH.csproj
--- SignusKH/SignusKH.csproj
+++ SignusKH/SignusKH.csproj
@@ -56,6 +56,7 @@
     </Compile>
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="U3Util.cs" />
     <EmbeddedResource Include="Form1.resx">
       <DependentUpon>Form1.cs</DependentUpon>
     </EmbeddedResource>
 
SignusKH/U3Util.cs (added)
+++ SignusKH/U3Util.cs
@@ -0,0 +1,194 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using System.IO;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.Drawing.Drawing2D;
+
+namespace SignusKH
+{
+    public class U3Util
+    {
+        static public Random rnd = new Random(new System.DateTime().Millisecond);
+
+        static public string GetErrorLogFile(bool bFullPath)
+        {
+            string AppPath = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\\"));
+            string AppName = Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf("\\") + 1);
+            string AppTitle = AppName.Substring(0, AppName.LastIndexOf("."));
+
+            if (bFullPath)
+                return AppPath + "\\" + AppTitle + "Error.txt";
+            else
+                return AppTitle + "Error.txt";
+        }
+
+        static public string GetEventLogFile(bool bFullPath)
+        {
+            string AppPath = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\\"));
+            string AppName = Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf("\\") + 1);
+            string AppTitle = AppName.Substring(0, AppName.LastIndexOf("."));
+
+            if (bFullPath)
+                return AppPath + "\\" + AppTitle + "Event.txt";
+            else
+                return AppTitle + "Event.txt";
+        }
+
+        static public string GetImagePath()
+        {
+            string AppPath = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\\"));
+            return AppPath + "\\" + "Images";
+        }
+
+        public static Bitmap ResizeImage(Image image, int width, int height)
+        {
+            var destRect = new Rectangle(0, 0, width, height);
+            var destImage = new Bitmap(width, height);
+
+            destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
+
+            using (var graphics = Graphics.FromImage(destImage))
+            {
+                graphics.CompositingMode = CompositingMode.SourceCopy;
+                graphics.CompositingQuality = CompositingQuality.HighQuality;
+                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
+                graphics.SmoothingMode = SmoothingMode.HighQuality;
+                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
+
+                using (var wrapMode = new ImageAttributes())
+                {
+                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
+                    graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
+                }
+            }
+            return destImage;
+        }
+
+        public static void ErrorLog(string strLog)
+        {
+            try
+            {
+                FileLog(strLog, GetErrorLogFile(false));
+            }
+            catch
+            {
+            }
+        }
+
+        public static void EventLog(string strLog)
+        {
+            try
+            {
+                FileLog(strLog, GetEventLogFile(false));
+            }
+            catch
+            {
+            }
+        }
+
+        public static void FileLog(string strLog, string strFileName)
+        {
+            string str = "";
+
+            DateTime t = DateTime.Now;
+            str = t.ToString("(yyyy-MM-dd HH:mm:ss.fff) ");
+            str += strLog;
+
+            try
+            {
+                string AppPath = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\\"));
+                string strLogFile = AppPath + "\\" + strFileName;
+                FileBackup(strLogFile);
+                FileWrite(strLogFile, str);
+            }
+            catch (Exception ex)
+            {
+                throw new Exception("FileLog->:" + ex.Message);
+            }
+        }
+
+        public static void FileBackup(string strLogFile)
+        {
+            if (File.Exists(strLogFile))
+            {
+                try
+                {
+                    FileInfo f = new FileInfo(strLogFile);
+                    if (f.Length >= (2 * 1024 * 1024))
+                    {
+                        System.IO.File.Delete(strLogFile + ".bak");
+                        f.MoveTo(strLogFile + ".bak");
+                    }
+                }
+                catch (Exception ex)
+                {
+                    throw new Exception("FileBackup->:" + ex.Message);
+                }
+            }
+        }
+
+        public static void FileWrite(string strLogFile, string str)
+        {
+            try
+            {
+                FileStream fs = new FileStream(strLogFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
+                fs.Seek(0, SeekOrigin.End);
+                StreamWriter swFromFile = new StreamWriter(fs);
+                swFromFile.WriteLine(str);
+                swFromFile.Close();
+                fs.Close();
+            }
+            catch (Exception ex)
+            {
+                ErrorLog("FileWrite->:" + ex.Message);
+            }
+        }
+
+        public static string FileRead(string strFileName)
+        {
+            if (System.IO.File.Exists(strFileName) == false) return "";
+
+            string result = "";
+            try
+            {
+                FileStream fs = new FileStream(strFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
+                fs.Seek(0, SeekOrigin.Begin);
+                StreamReader srFile = new StreamReader(fs, Encoding.Default, true);
+                result = srFile.ReadToEnd();
+                srFile.Close();
+                fs.Close();
+            }
+            catch (Exception ex)
+            {
+                ErrorLog("FileRead->:" + ex.Message);
+            }
+            return result;
+        }
+
+        public static bool GetBit(byte b, int bitNumber)
+        {
+            return (b & (1 << bitNumber)) != 0;
+        }
+
+        public static bool GetBit(short s, int bitNumber)
+        {
+            return (s & (1 << bitNumber)) != 0;
+        }
+
+        static public DateTime FromUnixTime(long unixTime)
+        {
+            var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+            return epoch.AddSeconds(unixTime);
+        }
+
+        static public Int32 ToUnixTime(DateTime dt)
+        {
+            return (Int32)(dt.Subtract(new DateTime(1970, 1, 1, 0, 0, 0))).TotalSeconds;
+        }
+    }
+}
SignusKHSVR/Form1.cs
--- SignusKHSVR/Form1.cs
+++ SignusKHSVR/Form1.cs
@@ -54,7 +54,8 @@
             //else if (System.IO.File.Exists(strChrome3))
             //    this.m_lstExe.Add(strChrome3);
 
-            //this.m_lstExe.Add(AppPath + string.Format("\\KHSCALE.exe"));
+            this.m_lstExe.Add(AppPath + string.Format("\\SignusServer.exe"));
+            this.m_lstExe.Add(AppPath + string.Format("\\KHPANEL.exe"));
 
             timer1.Enabled = true;
             timer1.Interval = 500;
@@ -225,7 +226,8 @@
             m_ps[index].StartInfo.FileName = AppExe;
             m_ps[index].StartInfo.WorkingDirectory = AppPath;
             m_ps[index].StartInfo.Arguments = "";
-            m_ps[index].StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
+            //m_ps[index].StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
+            m_ps[index].StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
             m_ps[index].Start();
         }
 
Add a comment
List