| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159 | using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;using System.Text.RegularExpressions;using System.Collections;using System.Diagnostics;using System.Data;using System.IO;using Microsoft.Win32;namespace FPER{    public class Util    {        /****************************************************************         *    String --> Int, 공백이나 NULL 인경우. 기본값으로 리턴한다.         ****************************************************************/        public static int StrToInt(object txt, int val)        {            int ret_val = val;            try            {                if (txt == null) return val;                if (txt.ToString().Trim() == "") return val;                ret_val = int.Parse(txt.ToString());            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }            finally            {            }            return ret_val;        }        /****************************************************************         *    공백이나 NULL 인경우. 기본값으로 리턴한다.         ****************************************************************/        public static string NullToStr(object txt)        {            string ret_val = "";            try            {                if (txt == null) return ret_val;                if (txt.ToString().Trim() == "") return ret_val;                ret_val = txt.ToString().Trim();            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }            finally            {            }            return ret_val;        }        /*******************************************         * control 숫자형 입력값 검사.         *******************************************/        public static Boolean ChkOnlyLiteralTextBox(TextBox txt, String txtboxName)        {            try            {                String input_value = txt.Text;                if (!onlyLiteral(input_value))                {                    txt.Text = "";                    txt.Focus();                    throw new Exception(String.Format("[{0}]  입력형식이 올바르지 않습니다. 숫자를 입력하여 주십시요.", txtboxName));                }            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }            return true;        }        /*******************************************         * TextBox 필수 입력 검사.         *******************************************/        public static Boolean ChkTxtBox(TextBox txt, String txtboxName)        {            try            {                if (txt.Text.Trim() == "")                {                    txt.Focus();                    throw new Exception(String.Format("[{0}] 입력값은 필수입니다.", txtboxName));                }                return true;            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);                throw ex;            }        }        /*******************************************         * MaskedTextBox 필수 입력 검사.         *******************************************/        public static Boolean ChkTxtBox(MaskedTextBox txt, String txtboxName)        {            try            {                if (txt.Text.Trim() == "")                {                    txt.Focus();                    throw new Exception(String.Format("[{0}] 입력값은 필수입니다.", txtboxName));                }                return true;            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);                throw ex;            }        }        /*******************************************         * ComboBox 필수 입력 검사.         *******************************************/        public static Boolean ChkComboBox(ComboBox cbo, String cboName)        {            try            {                if (cbo.SelectedValue == null)                {                    throw new Exception(String.Format("[{0}] 값을 선택하여 주십시요.", cboName));                }                return true;            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);                throw ex;            }        }        /**************************************************************************************         * GroupBox 컨트롤 상태 변경하기         * 수정,입력모드          * 입력불가모드         **************************************************************************************/        public static void GroupUIChange(Control gb, UIMode mode)        {            try            {                /** 화면 입력,수정 모드 **/                if (mode == UIMode.input)                {                    foreach (Control currentControl in gb.Controls)                    {                        if (currentControl is TextBox)                        {                            TextBox txt = (TextBox)currentControl;                            //txt.Enabled = true;                            txt.ReadOnly = false;                        }                        else if (currentControl is MaskedTextBox)                        {                            MaskedTextBox msktxt = (MaskedTextBox)currentControl;                            //msktxt.Enabled = true;                            msktxt.ReadOnly = false;                        }                        else if (currentControl is ComboBox)                        {                            ComboBox cbo = (ComboBox)currentControl;                            cbo.Enabled = true;                        }                        else if (currentControl is CheckBox)                        {                            CheckBox chk = (CheckBox)currentControl;                            chk.Enabled = true;                        }                        else if (currentControl is Button)                        {                            Button btn = (Button)currentControl;                            btn.Visible = true;                        }                        else if (currentControl is TabControl)                        {                            TabControl tc = (TabControl)currentControl;                            GroupUIChange(tc, mode);                        }                        else if (currentControl is TabPage)                        {                            TabPage pg = (TabPage)currentControl;                            GroupUIChange(pg, mode);                        }                    }                }                /** 화면 입력,수정 모드 여기까지**/                /** 화면 VIEW 모드 **/                else                {                    foreach (Control currentControl in gb.Controls)                    {                        if (currentControl is TextBox)                        {                            TextBox txt = (TextBox)currentControl;                            //txt.Enabled = false;                            txt.ReadOnly = true;                        }                        else if (currentControl is MaskedTextBox)                        {                            MaskedTextBox msktxt = (MaskedTextBox)currentControl;                            //msktxt.Enabled = false;                            msktxt.ReadOnly = true;                        }                        else if (currentControl is ComboBox)                        {                            ComboBox cbo = (ComboBox)currentControl;                            cbo.Enabled = false;                            cbo.ForeColor = System.Drawing.Color.Black;                        }                        else if (currentControl is CheckBox)                        {                            CheckBox btn = (CheckBox)currentControl;                            btn.Enabled = false;                            btn.ForeColor = System.Drawing.Color.Black;                        }                        else if (currentControl is Button)                        {                            Button btn = (Button)currentControl;                            btn.Visible = false;                        }                        else if (currentControl is TabControl)                        {                            TabControl tc = (TabControl)currentControl;                            GroupUIChange(tc, mode);                        }                        else if (currentControl is TabPage)                        {                            TabPage pg = (TabPage)currentControl;                            GroupUIChange(pg, mode);                        }                    }                }                /** 화면 VIEW 모드 여기까지 **/            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }        }        /**************************************************************************************         * GroupBox 컨트롤 상태 변경하기         * 수정,입력모드          * 입력불가모드         **************************************************************************************/        public static void GroupControlChange(Control gb, UIMode mode)        {            try            {                /** 화면 입력,수정 모드 **/                if (mode == UIMode.input)                {                    foreach (Control currentControl in gb.Controls)                    {                        if (currentControl is TextBox)                        {                            TextBox txt = (TextBox)currentControl;                            //txt.Enabled = true;                            txt.ReadOnly = false;                        }                        else if (currentControl is MaskedTextBox)                        {                            MaskedTextBox msktxt = (MaskedTextBox)currentControl;                            //msktxt.Enabled = true;                            msktxt.ReadOnly = false;                        }                        else if (currentControl is ComboBox)                        {                            ComboBox cbo = (ComboBox)currentControl;                            cbo.Enabled = true;                        }                        else if (currentControl is CheckBox)                        {                            CheckBox chk = (CheckBox)currentControl;                            chk.Enabled = true;                        }                        else if (currentControl is Button)                        {                            Button btn = (Button)currentControl;                            btn.Enabled = true;                        }                        else if (currentControl is TabControl)                        {                            TabControl tc = (TabControl)currentControl;                            GroupControlChange(tc, mode);                        }                        else if (currentControl is TabPage)                        {                            TabPage pg = (TabPage)currentControl;                            GroupControlChange(pg, mode);                        }                    }                }                /** 화면 입력,수정 모드 여기까지**/                /** 화면 VIEW 모드 **/                else                {                    foreach (Control currentControl in gb.Controls)                    {                        if (currentControl is TextBox)                        {                            TextBox txt = (TextBox)currentControl;                            //txt.Enabled = false;                            txt.ReadOnly = true;                        }                        else if (currentControl is MaskedTextBox)                        {                            MaskedTextBox msktxt = (MaskedTextBox)currentControl;                            //msktxt.Enabled = false;                            msktxt.ReadOnly = true;                        }                        else if (currentControl is ComboBox)                        {                            ComboBox cbo = (ComboBox)currentControl;                            cbo.Enabled = false;                            cbo.ForeColor = System.Drawing.Color.Black;                        }                        else if (currentControl is CheckBox)                        {                            CheckBox btn = (CheckBox)currentControl;                            btn.Enabled = false;                            btn.ForeColor = System.Drawing.Color.Black;                        }                        else if (currentControl is Button)                        {                            Button btn = (Button)currentControl;                            btn.Enabled = false;                        }                        else if (currentControl is TabControl)                        {                            TabControl tc = (TabControl)currentControl;                            GroupControlChange(tc, mode);                        }                        else if (currentControl is TabPage)                        {                            TabPage pg = (TabPage)currentControl;                            GroupControlChange(pg, mode);                        }                    }                }                /** 화면 VIEW 모드 여기까지 **/            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }        }        /*******************************************         * 우편번호조합 검사.         *******************************************/        public static Boolean chkZipCode(String intxt)        {            String ZipRegex = "[0-9]{3}-[0-9]{3}";            if (Regex.IsMatch(intxt, ZipRegex))            {                return true;            }            else            {                return false;            }        }        /*******************************************         * 숫자조합 검사.         *******************************************/        public static Boolean onlyLiteral(String intxt)        {            String patttern = "^[0-9]+$";     //정수:0-9숫자       실수:^[+-]?\d+(\.\d+)?$   또는 ^[+-]?\d*\.?\d*$            if (Regex.IsMatch(intxt, patttern))            {                return true;            }            else            {                return false;            }        }        /*******************************************         * 숫자영문조합 검사.         *******************************************/        public static Boolean onlyLiteralnAlpa(String intxt)        {            String patttern = "\\w+";  //[a-zA-Z0-9_] 영문숫자_            if (Regex.IsMatch(intxt, patttern))            {                return true;            }            else            {                return false;            }        }        /*******************************************         * 사용함/사용안함 ArrayList 생성         *******************************************/        public static ArrayList useFlagArray()        {            ArrayList ary = new ArrayList();            ary.Add(new cboitem("Y", "사용함"));            ary.Add(new cboitem("N", "사용안함"));            return ary;        }        /*******************************************         * ComInfo 응답 에러체크         *******************************************/        public static bool ComInfoErrProcess(CmdInfo cmd, bool connected)        {            bool CompleteOK = true;            try            {                if (cmd != null)                {                    if (cmd.ErrResponse)                    {                        if (connected)                        {                            RCVData_NACK nack = (RCVData_NACK)cmd.ErrResponseData;                        }                        CompleteOK = false;                    }                    else if (cmd.ResponseData == null)                    {                        CompleteOK = false;                    }                }            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);                CompleteOK = false;            }            return CompleteOK;        }        // cyim 2015.7.23 NACK 처리 부분 오류         // NACK 즉, 응답을 하지 않는 경우에 한해서 처리를 해야되는데도 불구하고, 다른 명령에 대한 응답이 들어오면        // 무조건 예외처리를 해버리는 것이 문제가 된다. 제대로 처리하려면 NACK 외 어떤 명령이 왔는지 파라미터로 전달하여 오버로딩 처리해야된다        public static bool ComInfoErrProcess(CmdInfo cmd, bool connected, string CmdType)        {            bool CompleteOK = true;            try            {                if (cmd != null)                {                    if (cmd.ErrResponseData.GetType().Name == CmdType)                    {                        ;// CmdType 이 제대로 맞았다면 이는 오류가 아니다                    }                    else if (cmd.ErrResponse)                    {                        if (connected)                        {                            RCVData_NACK nack = (RCVData_NACK)cmd.ErrResponseData;                        }                        CompleteOK = false;                    }                    else if (cmd.ResponseData == null)                    {                        CompleteOK = false;                    }                }            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);                CompleteOK = false;            }            return CompleteOK;        }        /*******************************************         * COMPORT ArrayList 생성         *******************************************/        public static ArrayList ArrayComport()        {            ////레지스트리에서 수신기ID정보 읽어오기 -- >변경 데몬과 동일한 PC가 아닐수 있으므로..            //RegistryKey rk = Registry.LocalMachine.OpenSubKey("HARDWARE\\DEVICEMAP\\SERIALCOMM", false);            //if (rk != null)            //{            //    String[] keys = rk.GetValueNames();            //    for (int i = 0; i < keys.Length; i++)            //    {            //        String value = rk.GetValue(keys[i]).ToString();            //        int no = int.Parse(value.Replace("COM", ""));            //        if (no > 9)            //            comport.Add(new cboitem(value, value));            //        else            //            comport.Add(new cboitem(value, value));            //    }            //}            ArrayList comport = new ArrayList();            // cyim 2013.7.10 디자인개선작업 : 수신기설정 - 통신설정 COM1~COM8 로 범위를 축소 : 20 -> 8            for (int i = 1; i <= 8; i++)            {                String value = "COM" + i.ToString();                comport.Add(new cboitem(value, value));            }            return comport;        }        /*******************************************         * 속도 ArrayList 생성         *******************************************/        public static ArrayList ArraySpeed()        {            ArrayList speed = new ArrayList();            //speed.Add(new cboitem("110","110"));            //speed.Add(new cboitem("300","300"));            //speed.Add(new cboitem("600","600"));            //speed.Add(new cboitem("1200","1200"));            speed.Add(new cboitem("2400", "2400"));            speed.Add(new cboitem("4800", "4800"));            speed.Add(new cboitem("9600", "9600"));            speed.Add(new cboitem("14400", "14400"));            speed.Add(new cboitem("19200", "19200"));            speed.Add(new cboitem("28800", "28800"));            speed.Add(new cboitem("38400", "38400"));            speed.Add(new cboitem("57600", "57600"));            speed.Add(new cboitem("115200", "115200")); //기본            //speed.Add(new cboitem("128000", "128000"));            //speed.Add(new cboitem("256000", "256000"));            return speed;        }        /*******************************************         * DATABIT ArrayList 생성         *******************************************/        public static ArrayList ArrayDatabit()        {            ArrayList databit = new ArrayList();            //databit.Add(new cboitem("4", "4"));            //databit.Add(new cboitem("5", "5"));            //databit.Add(new cboitem("6", "6"));            databit.Add(new cboitem("7", "7"));   //기본            databit.Add(new cboitem("8", "8"));            return databit;        }        /*******************************************         * PARITY ArrayList 생성         *******************************************/        public static ArrayList ArrayParity()        {            ArrayList parity = new ArrayList();            parity.Add(new cboitem("E", "E 짝수"));            //parity.Add(new cboitem("M", "M 표시"));            parity.Add(new cboitem("N", "N 없음"));    //기본            parity.Add(new cboitem("O", "O 홀수"));            //parity.Add(new cboitem("S", "S 공간"));            return parity;        }        /*******************************************         * STOPBIT ArrayList 생성         *******************************************/        public static ArrayList ArrayStopbit()        {            ArrayList stopbit = new ArrayList();            stopbit.Add(new cboitem("1", "1"));       //기본            //stopbit.Add(new cboitem("2", "1.5"));            stopbit.Add(new cboitem("2", "2"));            return stopbit;        }        /*******************************************         * Baud Rate ArrayList 생성         *******************************************/        public static ArrayList baudRateArray()        {            ArrayList ary = new ArrayList();            ary.Add(new cboitem("0", "2400"));            ary.Add(new cboitem("1", "4800"));            ary.Add(new cboitem("2", "9600"));            ary.Add(new cboitem("3", "19200"));            ary.Add(new cboitem("4", "38400"));            ary.Add(new cboitem("5", "57600"));            ary.Add(new cboitem("6", "76800"));            ary.Add(new cboitem("7", "115200"));            return ary;        }        /*******************************************         * Baud Code --> Baud Rate 리턴         *******************************************/        public static String baudCodeToRate(String code)        {            String baud = null;            switch (code)            {                case "0": baud = "2400"; break;                case "1": baud = "4800"; break;                case "2": baud = "9600"; break;                case "3": baud = "19200"; break;                case "4": baud = "38400"; break;                case "5": baud = "57600"; break;                case "6": baud = "76800"; break;                case "7": baud = "115200"; break;            }            return baud;        }        /*******************************************         * Baud Code --> Baud Rate 리턴         *******************************************/        public static String baudRateToCode(String rate)        {            String code = null;            switch (rate)            {                case "2400": code = "0"; break;                case "4800": code = "1"; break;                case "9600": code = "2"; break;                case "19200": code = "3"; break;                case "38400": code = "4"; break;                case "57600": code = "5"; break;                case "76800": code = "6"; break;                case "115200": code = "7"; break;            }            return code;        }        /*******************************************         * 콤보박스에 ArrayList 셋팅         *******************************************/        public static void ComboSetting(ComboBox co, ArrayList ary, String defaultvalue)        {            try            {                if (ary == null) { co.DataSource = null; return; }                if (co == null) return;                //co.Items.Clear();                co.DataSource = ary;                co.DisplayMember = "text";                co.ValueMember = "value";                if (defaultvalue != null) co.SelectedValue = defaultvalue;                //if (defaultvalue == null)                //    co.SelectedIndex = -1;                //else                //    co.SelectedValue = defaultvalue;            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);                //Debug.WriteLine(ex.Message);            }        }        /*******************************************        * 컨트롤 이름으로 검색        *******************************************/        public static Control FineControl(Control parent, String ContronlName)        {            //Control con = null;            //foreach (Control currentControl in parent.Controls)            //{            //    String cName = currentControl.Name;  //btnRepeater1            //    if (cName.Equals(ContronlName))            //    {            //        con = currentControl;            //    }            //}            Control con = null;            if (parent == null) return null;            Control[] controls = parent.Controls.Find(ContronlName, true);            if (controls.Length > 0)            {                con = controls[0];            }            return con;        }        /*******************************************       * chars -> String으로 변환       *******************************************/        public static String CharToStr(char[] chars)        {            String s = "";            foreach (Char c in chars)            {                s += string.Format("{0}", c);            }            return s;        }        /*******************************************       * bytes -> String으로 변환       *******************************************/        public static String ByteToStr(byte[] bytes, int start_idx, int length_idx)        {            ASCIIEncoding ascii = new ASCIIEncoding();            //회로 I/O타입            int charCount = ascii.GetCharCount(bytes, start_idx, length_idx);            Char[] iochar = new Char[charCount];            int charsDecodedCount = ascii.GetChars(bytes, start_idx, length_idx, iochar, 0);            return CharToStr(iochar);        }        /*******************************************         * byte -> hex 스트링으로 변환         *******************************************/        public static String ToHex(byte[] bin_data)        {            string result = "";            foreach (byte ch in bin_data)            {                result += string.Format("{0:x2} ", ch); // 2자리의 16진수로 출력, [참고] 링크 읽어볼 것             }            return result;        }        /*******************************************         * 스트링을 byte 배열로 변환         *******************************************/        public static byte[] ToBytes(String arg)        {            string arg2 = NullToStr(arg);            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();            return encoding.GetBytes(arg2);        }        /*******************************************         * byte + byte 배열로 변환         *******************************************/        public static byte[] ByteArrayCopyAdd(byte[] srcByte, byte[] addByte, int addLen)        {            int totalLen = srcByte.Length + addLen;            byte[] totalByte = new byte[totalLen];            try            {                Array.Copy(srcByte, 0, totalByte, 0, srcByte.Length);                Array.Copy(addByte, 0, totalByte, srcByte.Length, addLen);            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);                throw ex;                //Debug.WriteLine(ex.Message);            }            return totalByte;        }        /*******************************************         * Y,N String --> Bool로 변환         *******************************************/        public static bool StringToBool(String flg)        {            return flg == "Y" ? true : false;        }        /*******************************************         *  2010-1-1 이후 현재까지 간격         *******************************************/        public static double milisec()        {            DateTime stdDate = new DateTime(2010, 1, 1, 0, 0, 0);            TimeSpan ts = DateTime.Now - stdDate;            double intRtn = ts.TotalMilliseconds;            return intRtn;        }        /*******************************************       * 하위,상위 숫자로 float 볼트리턴       *******************************************/        public static float ToValtage(int vol_dn, int vol_up)        {            float voltage24 = 0;            //24V (상위*256 + 하위) / 100            voltage24 = (vol_up * 256) + vol_dn;            voltage24 = voltage24 / 100;            return voltage24;        }        /*******************************************       *  TextBox 입력을 대문자로 변경해줌       *******************************************/        public static void ToUpper(TextBox obj)        {            try            {                int caretPosition;                caretPosition = obj.SelectionStart;                obj.Text = obj.Text.ToUpper();                obj.Select(caretPosition, 0);            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }        }        public static void LogWrite(string logstr)        {            try            {                //Util.UDebugMessage("LogWrite " + logstr, 0, 0);             }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }            //	            try            //	            {            //	            //	                string fileName = string.Format("FTER_{0:yyyyMMdd}.txt", DateTime.Now);            //	                string dirPath = string.Format("{0}\\Logs",Application.StartupPath);            //	            //	                if (!System.IO.Directory.Exists(dirPath)) System.IO.Directory.CreateDirectory(dirPath);            //	            //	                string fullFileName = string.Format("{0}\\{1}", dirPath, fileName);            //	            //	                FileStream fs = new FileStream(fullFileName, FileMode.Append, FileAccess.Write, FileShare.Read);            //	                StreamWriter sw = new StreamWriter(fs);            //	                sw.WriteLine(string.Format("{0:yyyy-MM-dd HH:mm:ss} : {1}", DateTime.Now, logstr)); //내용쓰고            //	                sw.Flush();             //	                sw.Close();            //	            //	            }            //	            catch (Exception ex)            //	            {            //	              Util.UErrorMessage(ex,0,0);            //	             //Debug.WriteLine(ex.StackTrace);            //	            }        }        public static void LogBineryWrite(byte[] logstr, int offset)        {            try            {                string fileName = string.Format("FTER_PACKET_{0:yyyyMMdd}.dat", DateTime.Now);                string dirPath = string.Format("{0}\\Logs", Application.StartupPath);                if (!System.IO.Directory.Exists(dirPath)) System.IO.Directory.CreateDirectory(dirPath);                byte[] ReadBuffer = new byte[offset];                Array.Copy(logstr, ReadBuffer, offset);                string fullFileName = string.Format("{0}\\{1}", dirPath, fileName);                FileStream fs = new FileStream(fullFileName, FileMode.Append, FileAccess.Write);                BinaryWriter bw = new BinaryWriter(fs);                bw.Write(ReadBuffer);                bw.Close();                fs.Close();            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);                // Debug.WriteLine(ex.StackTrace);            }        }        //회로 표현 메세지        public static string device_message(string inout_type, int receiver_id, int comm_id, int board_id, int loop_no, int repeater_id, int device_id)        {            string message = "";            try            {                switch (inout_type)                {                    case "I":                    case "O":                        {                            DacUIProcess dacUIProcess = new DacUIProcess(receiver_id); // cyim 2015.7.30 데이타베이스 접속 루틴 변경                            MskDeviceIDString device_str = new MskDeviceIDString(comm_id, board_id, loop_no, repeater_id, device_id, inout_type);                            string device_name = "";                            string position_name = "";                            string device_type_name = "";                            DataTable dt = dacUIProcess.Device_Select(receiver_id, comm_id, board_id, loop_no, repeater_id, device_id, inout_type);                            if (dt.Rows.Count > 0)                            {                                DataRow dr = dt.Rows[0];                                device_name = Util.NullToStr(dr["DEVICE_NAME"]);                                position_name = Util.NullToStr(dr["POSITION_NAME"]);                                device_type_name = Util.NullToStr(dr["DEVICE_TYPE_NAME"]);                            }                            string inoutName = inout_type.Equals(code_InOutType.Output) ? "출력" : "입력";                            if (comm_id == 1 || comm_id == 3)                            {                                //message = string.Format("[{0}]-[{1}]-[{2}]-[{3}]"                                //    , device_str.MskId, device_name, position_name, device_type_name);                                //message = string.Format("{3}\r\n{2}  {1}\r\n[{0}]"                                //      , device_str.MskId, device_name, position_name, device_type_name);                                message = string.Format("{0} {1} [{2}]", position_name, device_name, device_str.MskId);                            }                            else if (comm_id == 4)                            {                                message = string.Format("키패드[{0}]", device_name);                            }                            break;                        }                    case "D":                        {                            if (comm_id == 1)                                message = string.Format("통신보드[{0}] LOOP번호[{1}] 중계기번호[{2}] 회로번호[{3}]"                                    , board_id, loop_no, repeater_id, device_id);                            else if (comm_id == 3)                                message = string.Format("I/O보드[{0}] 회로번호[{1}]", board_id, device_id);                            else if (comm_id == 4)                                message = string.Format("키패드번호[{0}] ", device_id);                            break;                        }                    case "R":                        {                            if (comm_id == 1)                                message = string.Format("통신보드[{0}] LOOP번호[{1}] 중계기번호[{2}]"                                    , board_id, loop_no, repeater_id);                            break;                        }                    case "L":                        {                            if (comm_id == 1) message = string.Format("통신보드[{0}] LOOP번호[{1}] ", board_id, loop_no);                            else if (comm_id == 2) message = string.Format("BACKLOOP 통신보드[{0}] LOOP번호[{1}] ", board_id, loop_no);                            else if (comm_id == 3) message = "IO보드";                            else if (comm_id == 4) message = "키패드";                            break;                        }                    case "B":                        {                            if (comm_id == 1)                                message = string.Format("통신보드[{0}] ", board_id);                            else if (comm_id == 3)                                message = string.Format("I/O보드[{0}] ", board_id);                            else if (comm_id == 4)                                message = string.Format("키패드[{0}] ", board_id);                            break;                        }                    case "C":                    case "A":                        {                            if (comm_id == 1)                                message = "Front";                            else if (comm_id == 2)                                message = "Back";                            else if (comm_id == 3)                                message = "I/O보드";                            else if (comm_id == 4)                                message = "키패드";                            else                                message = "수신기";                            break;                        }                }            }            catch (Exception ex)            {                message = "";//2010.11.11,k.s.d, db access bug fix.                Util.UErrorMessage(ex, 0, 0);            }            return message;        }        // cyim 2015.7.29 수신반 루틴을 위해 레지스트리값 이용은 최소화 : 프로그램 시작시에 이미 읽어들임        //public static string FirebirdPath()        //{        //    String filePath = "";        //    try        //    {        //        //레지스트리에서 DB접속정보 읽어오기        //        RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\I_FPER_COMM_DAEMON", false);        //        if (rk != null)        //        {        //            String DATABASE_NAME = rk.GetValue("DATABASE_NAME").ToString();        //            int pos = DATABASE_NAME.IndexOf(":");        //            if (pos != -1)        //            {        //                filePath = DATABASE_NAME.Substring(pos + 1);        //            }        //        }        //    }        //    catch (Exception ex)        //    {        //        Util.UErrorMessage(ex, 0, 0);        //    }        //    return filePath;        //}        public static DateTime getBackUpLastDateTime()        {            DateTime backup_dt = DateTime.Parse("1999-01-01");            try            {                //레지스트리에서 DB접속정보 읽어오기                RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\I_FPER_COMM_DAEMON", false);                if (rk != null)                {                    String backup_dt_str = rk.GetValue("BACKUP_DATETIME").ToString();                    if (backup_dt_str.Length == 19)                    {                        backup_dt = DateTime.Parse(backup_dt_str);                    }                }            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }            return backup_dt;        }        public static void setBackUpLastDateTime(DateTime backup_dt)        {            try            {                //레지스트리에서 DB접속정보 읽어오기                RegistryKey rk = Registry.LocalMachine.CreateSubKey("SOFTWARE").CreateSubKey("I_FPER_COMM_DAEMON");                if (rk != null)                {                    rk.SetValue("BACKUP_DATETIME", string.Format("{0:yyyy-MM-dd HH:mm:ss}", backup_dt));                }            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }        }        //2010.11.08, k.s.d , Debug message Function        //static int prt_dbg_level = -1;// dbg message level         public static void UDebugMessage(string msg, int dbg_category, int dbg_level)        {// dbg message             //if(dbg_level <= prt_dbg_level) {            //  Debug.WriteLine("[FPER]: "+msg);            //}            ;        }        public static void UDebugMessage(string msg, int dbg_category, int dbg_level, StackTrace st)        {// error message             //if(dbg_level <= prt_dbg_level) {            //  Debug.WriteLine(string.Format("[FPER][{0}]: {1} //+ {2} -//",dbg_category,msg,st.ToString()));            //}            ;        }        public static void UErrorMessage(Exception ex, int dbg_category, int dbg_level)        { // error message with stack            //if(dbg_level <= prt_dbg_level) {            //  Debug.WriteLine(string.Format("[FPER]:[ERR]: {0}, //+ {1} -// ", ex.Message, ex.StackTrace));            //}            ;        }    }}
 |