123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Collections;
- namespace IControls_FireManager
- {
- // 데이터를 변환하는 것은 여기 클래스에서 전담한다.
- public static class _Convert
- {
- // 구분자 (데이터 구분)
- public static char[] Split_Key = { ';' };
- // 구분자 (데이터 내부 구분)
- public static char[] Split_Data = { '=' };
- // 구분자 (데이터 결과 구분)
- public static char[] Result_Char = { ',' };
- // 구분자 (데이터 결과 구분)
- public static string Result_String = ",";
- // 구분자 (IP Address 구분)
- public static char[] Split_IPAddress = { '.' };
- // 구분자 (PortNum 구분)
- public static char[] Split_PortNum = { '-' };
- // 구분자 (일정 구분)
- public static char Split_Time = '|' ;
- public static char[] Split_Times = { '|' };
- public static char UI_Split_Time = '\n';
- public static char[] UI_Split_Times = { '\n' };
- //// 데이터를 입력하면 분리해서 변환
- //// 예시 : "test1,test2" -> test1 과 test2 로
- //public static string[] String_to_ArrayString(ArrayList Datas)
- //{
- // string[] not = { };
- // if (Datas == null || Datas.Count == 0) return not;
- // string Temp = null;
- // foreach (string Data in Datas)
- // {
- // Temp = Temp + Data + _Text.SemiColon;
- // }
- // Temp = Temp.TrimEnd(Split_Key);
- // string[] Temps = Temp.Split(Split_Key);
- // return Temps;
- //}
- // 데이터를 입력하면 분리해서 변환
- // 예시 : "test1,test2" -> test1 과 test2 로
- public static string[] String_to_ArrayString(string Datas)
- {
- string[] not = { };
- if (Datas == null || Datas.Length == 0) return not;
- string Temp = Datas.Trim();
- string[] Temps = Temp.Split(Split_Key);
- return Temps;
- }
- // 데이터를 입력하면 분리해서 변환 (단, 구분자를 직접 지정할수 있음)
- // 예시 : "test1,test2" -> test1 과 test2 로
- public static string[] String_to_ArrayString(char [] spilt, string Datas)
- {
- string[] not = { };
- if (Datas == null || Datas.Length == 0) return not;
- string Temp = Datas.Trim();
- string[] Temps = Temp.Split(spilt);
- return Temps;
- }
- // 데이터를 입력하면 분리해서 변환 (단, 구분자를 직접 지정할수 있음)
- // 예시 : "test1,test2" -> test1 과 test2 로
- public static ArrayList String_to_ArrayLIst(char[] spilt, string Datas)
- {
- ArrayList Result = new ArrayList();
-
- if (Datas == null || Datas.Length == 0) return Result;
- string Temp = Datas.Trim();
- string[] Temps = Temp.Split(spilt);
- foreach (string Item in Temps)
- Result.Add(Item);
- return Result;
- }
- // 맨처음 문자를 추출한다
- // 예시 : "test1;test2" -> test1
- //public static string Get_First_ArrayString(string Datas)
- //{
- // if (Datas == null || Datas.Length == 0) return _Text.Null;
- // string Temp = Datas.Trim();
- // string[] Temps = Temp.Split(Split_Key);
- // return Temps[0];
- //}
-
- // 데이터를 입력하면 분리해서 변환
- // 예시 : "Key1=Data1;Key2=Data2", true -> "Key1,Key2"
- // 예시 : "Key1=Data1;Key2=Data2", false -> "Data1,Data2"
- // NullValueEnable : false 면 널값은 포함하지 않는다
- public static string String_to_Key_Data(string KeyDatas, bool Key, bool NullValueEnable)
- {
- string Temp = KeyDatas.Trim();
- string[] Temps = Temp.Split(Split_Key);
- string result = null;
- foreach (string data in Temps)
- {
- string[] temps = data.Split(Split_Data);
- if (NullValueEnable == false)// 데이터가 널값인 경우도 포함할지 여부
- {
- if (temps[0].Length != 0 && temps[1].Length != 0) // 키 혹은 데이타가 널값이라면 추가하지 못한다
- {
- // 키
- if (Key == true)
- {
- result = result + temps[0] + Result_String;
- }
- // 데이타
- else
- {
- result = result + temps[1] + Result_String;
- }
- }
- }
- else
- {
- // 키
- if (Key == true)
- {
- result = result + temps[0] + Result_String;
- }
- // 데이타
- else
- {
- result = result + temps[1] + Result_String;
- }
- }
- }
- if(result != null) result = result.TrimEnd(Result_Char);
- return result;
- }
-
- // 데이타베이스에 삽입하는 경우 int 자료값이 0이라면 삽입 코드 혹은 갱신 코드로 들어가지 않도록 강제로 null 로 변환
- public static string IntZero_to_Null(int Data)
- {
- string result = null;
- if (Data == 0) result = null;
- else result = Data.ToString();
- return result;
- }
- // 데이타베이스에 읽어오는 경우 string 자료값이 null 이라면 Convert 에러가 나오지 않도록 강제로 0 로 변환
- public static int Null_to_IntZero(object Data)
- {
- try
- {
- int result = 0;
- string Temp = Data.ToString();
- if (Temp != null) Temp = Temp.Trim();
- if (Temp == null || Temp.Length == 0) result = 0;
- else result = Convert.ToInt32(Temp);
- return result;
- }
- catch
- {
- return 0;
- }
- }
- public static bool Exception_Into_object(object Data1, object Data2, object Data3, object Data4, object Data5)
- {
- try
- {
- if ((Data1 == null || Data1.ToString().Trim().Length == 0)
- && (Data2 == null || Data2.ToString().Trim().Length == 0)
- && (Data3 == null || Data3.ToString().Trim().Length == 0)
- && (Data4 == null || Data4.ToString().Trim().Length == 0)
- && (Data5 == null || Data5.ToString().Trim().Length == 0))
- return false;
- else
- {
- int t1 = Int32.Parse(Data1.ToString().Trim());
- int t2 = Int32.Parse(Data2.ToString().Trim());
- int t3 = Int32.Parse(Data3.ToString().Trim());
- int t4 = Int32.Parse(Data4.ToString().Trim());
- int t5 = Int32.Parse(Data5.ToString().Trim());
- }
- return true;
- }
- catch
- {
- return false;
- }
- }
- // 스트링 자료가 널값이라면 None 으로 치환하는 경우
- //public static string Null_to_None(string Data)
- //{
- // string result = Data;
- // if (result == null || result.Length == 0)
- // result = _Text.None;
- // return result;
- //}
- //// 스트링 자료가 널값이라면 Blank 으로 치환하는 경우
- //public static string Null_to_Blank(string Data)
- //{
- // string result = Data;
- // if (result == null || result.Length == 0)
- // result = _Text.Blank;
- // return result;
- //}
- // 스트링으로 된 데이타를 두자리 스트링으로 변환
- public static string String_to_Int_TwoType(string Data)
- {
- string result = null;
- if (Data == null || Data.Length == 0 || Data.Length > 4) return "00";
- int IntData = Int32.Parse(Data);
-
- // 3자리 이상으로 데이타가 넘어오면 앞3자리 삭제
- if (IntData > 999)
- result = IntData.ToString().Remove(3);
- // 2자리 이상으로 데이타가 넘어오면 앞2자리 삭제
- else if (IntData > 99)
- result = IntData.ToString().Remove(2);
- else if (IntData == 0)
- result = "00";
- else if (IntData > 9 )
- result = IntData.ToString();
- else
- result = "0" + IntData.ToString();
-
- return result;
- }
- // 스트링으로 된 데이타를 세자리 스트링으로 변환
- public static string String_to_Int_ThreeType(string Data)
- {
- string result = null;
- if (Data == null || Data.Length == 0 || Data.Length > 4) return "000";
- int IntData = Int32.Parse(Data);
- // 3자리 이상으로 데이타가 넘어오면 앞3자리 삭제
- if (IntData > 999)
- result = IntData.ToString().Remove(1);
- else if (IntData == 0)
- result = "000";
- else if (IntData > 9)
- result = IntData.ToString();
- else
- result = "00" + IntData.ToString();
- return result;
- }
- // 스트링 데이터 -> 바이트 배열로 변환
- public static byte[] String_to_Byte(string Data)
- {
- byte[] ByteData = new byte[Data.Length];
- for (int i = 0; i < Data.Length; i++)
- {
- ByteData[i] = Convert.ToByte(Data[i]);
- }
- return ByteData;
- }
- // 정수 -> 2byte 변환
- public static byte Int_to_Byte(int Data, bool Head)
- {
- byte result1 = 0x00;
- byte result2 = 0x00;
- // 한자리 혹은 두자리
- if (Data <= 255)
- {
- result1 = 0x00;
- result2 = Convert.ToByte(Data); // int -> byte
- }
- else
- {
- // Ex :2748 -> 0xABC
- string temp = Data.ToString("X");
- // 세자리
- if (temp.Length == 3)
- {
- string temp1 = temp[0].ToString();
- string temp2 = temp[1].ToString() + temp[2].ToString() ;
- result1 = Convert.ToByte(temp1, 16); // string -> byte
- result2 = Convert.ToByte(temp2, 16); // string -> byte
- }
- // 4자리
- else if (temp.Length == 4)
- {
- string temp1 = temp[0].ToString() + temp[1].ToString();
- string temp2 = temp[2].ToString() + temp[3].ToString();
- result1 = Convert.ToByte(temp1, 16); // string -> byte
- result2 = Convert.ToByte(temp2, 16); // string -> byte
- }
- }
- // 앞자리
- if (Head == true)
- {
- return result1;
- }
- // 뒷자리
- else
- {
- return result2;
- }
- }
- // 바이트 -> 정수
- public static string GetBytesInt32(long argument)
- {
- byte[] byteArray = BitConverter.GetBytes(argument);
- string result = "";
- for (int i = byteArray.Length - 1; i >= 0; i--)
- {
- result = result + byteArray[i].ToString("X");
- }
- result = "0x" + result;
- return result;
- }
- // 4자리수 만들기
- public static string To_4byte(string Data)
- {
- try
- {
- string result = null;
- if (Data == null || Data.Length == 0 || Data == "0" || Data == "00" || Data == "000" || Data == "0000")
- return "0000";
- int temp_result = Int32.Parse(Data);
- if (temp_result > 0 && temp_result <= 9999)
- {
- if (temp_result < 10)
- {
- result = "000" + temp_result.ToString();
- }
- else if (temp_result < 100)
- {
- result = "00" + temp_result.ToString();
- }
- else if (temp_result < 1000)
- {
- result = "0" + temp_result.ToString();
- }
- else
- result = temp_result.ToString();
- }
- return result;
- }
- catch
- {
- return "0000";
- }
- }
- // 2자리수로 만들기
- public static string To_2byte(string Data)
- {
- try
- {
- string result = null;
- if (Data == null || Data.Length == 0 || Data == "0" || Data == "00" || Data == "000" || Data == "0000")
- return "00";
- int temp_result = Int32.Parse(Data);
- if (temp_result >= 0 && temp_result <= 99)
- {
- if (temp_result == 0)
- {
- result = "00";
- }
- else if (temp_result < 10)
- {
- result = "0" + temp_result.ToString();
- }
- else
- result = temp_result.ToString();
- }
- return result;
- }
- catch
- {
- return "00";
- }
- }
- // 인코딩
- //public static byte[] EncodingData(Coding coding, string Data)
- //{
- // byte[] data = null;
- // switch (coding)
- // {
- // case Coding.Default:
- // data = Encoding.Default.GetBytes(Data);
- // break;
- // case Coding.UTF8:
- // data = Encoding.UTF8.GetBytes(Data);
- // break;
- // case Coding.ASCII:
- // data = Encoding.ASCII.GetBytes(Data);
- // break;
- // }
- // return data;
- //}
- //// 디코딩
- //public static string DecodingData(Coding coding, byte[] Data)
- //{
- // string data = null;
- // switch (coding)
- // {
- // case Coding.Default:
- // data = Encoding.Default.GetString(Data);
- // break;
- // case Coding.UTF8:
- // data = Encoding.UTF8.GetString(Data);
- // break;
- // case Coding.ASCII:
- // data = Encoding.ASCII.GetString(Data);
- // break;
- // }
- // return data;
- //}
-
- // 초를 분 / 초 단위로 표시한다
- // 초를 시간/ 분 / 초 단위로 표시한다
- public static string Second_To_TimeInfo(int Second)
- {
- string result = null;
- int temp_second = 0;
- int temp_minute = 0;
- int temp_hour = 0;
- // 잘못된 정보
- if(Second < 0)
- return null;
- // 60 초 미만이라면
- if (Second >= 0 && Second < 60)
- {
- result = string.Format("{0}초", Second);
- }
- // 1시간 미만이라면
- else if (Second >= 60 && Second < 3600)
- {
- temp_minute = Second / 60;
- temp_second = Second - (temp_minute * 60);
- result = string.Format("{0}분 {1}초", temp_minute, temp_second);
- }
- else
- {
- temp_hour = Second / 3600;
- temp_minute = (Second - (temp_hour * 3600)) / 60;
- temp_second = (Second - (temp_hour * 3600) - (temp_minute * 60));
- result = string.Format("{0}시간 {1}분 {2}초", temp_hour, temp_minute, temp_second);
- }
- return result;
- }
- // 리스트내에 동일한 데이타만 존재하면 true 리턴
- public static bool Check_ArrayList_SameValue(ArrayList arraylist)
- {
- string Compare = (string)arraylist[0];
- foreach (string Data in arraylist)
- {
- if (Data != Compare)
- return false;
- }
- return true;
- }
- // 시간정보를 콤마로 구분하도록 변환
- public static string SplitTime_To_Comma(string Data)
- {
- if (Data == null || Data.Length == 0)
- return "";
- else
- {
- return Data.Replace(Split_Time.ToString(), Result_String);
- }
- }
-
- }
- }
|