12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091 |
- 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));
- //}
- ;
- }
- }
- }
|