b9b82b3b3d89570c87fb4173235d3495e5295367.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Collections;
  5. namespace IControls_FireManager
  6. {
  7. // 데이터를 변환하는 것은 여기 클래스에서 전담한다.
  8. public static class _Convert
  9. {
  10. // 구분자 (데이터 구분)
  11. public static char[] Split_Key = { ';' };
  12. // 구분자 (데이터 내부 구분)
  13. public static char[] Split_Data = { '=' };
  14. // 구분자 (데이터 결과 구분)
  15. public static char[] Result_Char = { ',' };
  16. // 구분자 (데이터 결과 구분)
  17. public static string Result_String = ",";
  18. // 구분자 (IP Address 구분)
  19. public static char[] Split_IPAddress = { '.' };
  20. // 구분자 (PortNum 구분)
  21. public static char[] Split_PortNum = { '-' };
  22. // 구분자 (일정 구분)
  23. public static char Split_Time = '|' ;
  24. public static char[] Split_Times = { '|' };
  25. public static char UI_Split_Time = '\n';
  26. public static char[] UI_Split_Times = { '\n' };
  27. //// 데이터를 입력하면 분리해서 변환
  28. //// 예시 : "test1,test2" -> test1 과 test2 로
  29. //public static string[] String_to_ArrayString(ArrayList Datas)
  30. //{
  31. // string[] not = { };
  32. // if (Datas == null || Datas.Count == 0) return not;
  33. // string Temp = null;
  34. // foreach (string Data in Datas)
  35. // {
  36. // Temp = Temp + Data + _Text.SemiColon;
  37. // }
  38. // Temp = Temp.TrimEnd(Split_Key);
  39. // string[] Temps = Temp.Split(Split_Key);
  40. // return Temps;
  41. //}
  42. // 데이터를 입력하면 분리해서 변환
  43. // 예시 : "test1,test2" -> test1 과 test2 로
  44. public static string[] String_to_ArrayString(string Datas)
  45. {
  46. string[] not = { };
  47. if (Datas == null || Datas.Length == 0) return not;
  48. string Temp = Datas.Trim();
  49. string[] Temps = Temp.Split(Split_Key);
  50. return Temps;
  51. }
  52. // 데이터를 입력하면 분리해서 변환 (단, 구분자를 직접 지정할수 있음)
  53. // 예시 : "test1,test2" -> test1 과 test2 로
  54. public static string[] String_to_ArrayString(char [] spilt, string Datas)
  55. {
  56. string[] not = { };
  57. if (Datas == null || Datas.Length == 0) return not;
  58. string Temp = Datas.Trim();
  59. string[] Temps = Temp.Split(spilt);
  60. return Temps;
  61. }
  62. // 데이터를 입력하면 분리해서 변환 (단, 구분자를 직접 지정할수 있음)
  63. // 예시 : "test1,test2" -> test1 과 test2 로
  64. public static ArrayList String_to_ArrayLIst(char[] spilt, string Datas)
  65. {
  66. ArrayList Result = new ArrayList();
  67. if (Datas == null || Datas.Length == 0) return Result;
  68. string Temp = Datas.Trim();
  69. string[] Temps = Temp.Split(spilt);
  70. foreach (string Item in Temps)
  71. Result.Add(Item);
  72. return Result;
  73. }
  74. // 맨처음 문자를 추출한다
  75. // 예시 : "test1;test2" -> test1
  76. //public static string Get_First_ArrayString(string Datas)
  77. //{
  78. // if (Datas == null || Datas.Length == 0) return _Text.Null;
  79. // string Temp = Datas.Trim();
  80. // string[] Temps = Temp.Split(Split_Key);
  81. // return Temps[0];
  82. //}
  83. // 데이터를 입력하면 분리해서 변환
  84. // 예시 : "Key1=Data1;Key2=Data2", true -> "Key1,Key2"
  85. // 예시 : "Key1=Data1;Key2=Data2", false -> "Data1,Data2"
  86. // NullValueEnable : false 면 널값은 포함하지 않는다
  87. public static string String_to_Key_Data(string KeyDatas, bool Key, bool NullValueEnable)
  88. {
  89. string Temp = KeyDatas.Trim();
  90. string[] Temps = Temp.Split(Split_Key);
  91. string result = null;
  92. foreach (string data in Temps)
  93. {
  94. string[] temps = data.Split(Split_Data);
  95. if (NullValueEnable == false)// 데이터가 널값인 경우도 포함할지 여부
  96. {
  97. if (temps[0].Length != 0 && temps[1].Length != 0) // 키 혹은 데이타가 널값이라면 추가하지 못한다
  98. {
  99. // 키
  100. if (Key == true)
  101. {
  102. result = result + temps[0] + Result_String;
  103. }
  104. // 데이타
  105. else
  106. {
  107. result = result + temps[1] + Result_String;
  108. }
  109. }
  110. }
  111. else
  112. {
  113. // 키
  114. if (Key == true)
  115. {
  116. result = result + temps[0] + Result_String;
  117. }
  118. // 데이타
  119. else
  120. {
  121. result = result + temps[1] + Result_String;
  122. }
  123. }
  124. }
  125. if(result != null) result = result.TrimEnd(Result_Char);
  126. return result;
  127. }
  128. // 데이타베이스에 삽입하는 경우 int 자료값이 0이라면 삽입 코드 혹은 갱신 코드로 들어가지 않도록 강제로 null 로 변환
  129. public static string IntZero_to_Null(int Data)
  130. {
  131. string result = null;
  132. if (Data == 0) result = null;
  133. else result = Data.ToString();
  134. return result;
  135. }
  136. // 데이타베이스에 읽어오는 경우 string 자료값이 null 이라면 Convert 에러가 나오지 않도록 강제로 0 로 변환
  137. public static int Null_to_IntZero(object Data)
  138. {
  139. try
  140. {
  141. int result = 0;
  142. string Temp = Data.ToString();
  143. if (Temp != null) Temp = Temp.Trim();
  144. if (Temp == null || Temp.Length == 0) result = 0;
  145. else result = Convert.ToInt32(Temp);
  146. return result;
  147. }
  148. catch
  149. {
  150. return 0;
  151. }
  152. }
  153. public static bool Exception_Into_object(object Data1, object Data2, object Data3, object Data4, object Data5)
  154. {
  155. try
  156. {
  157. if ((Data1 == null || Data1.ToString().Trim().Length == 0)
  158. && (Data2 == null || Data2.ToString().Trim().Length == 0)
  159. && (Data3 == null || Data3.ToString().Trim().Length == 0)
  160. && (Data4 == null || Data4.ToString().Trim().Length == 0)
  161. && (Data5 == null || Data5.ToString().Trim().Length == 0))
  162. return false;
  163. else
  164. {
  165. int t1 = Int32.Parse(Data1.ToString().Trim());
  166. int t2 = Int32.Parse(Data2.ToString().Trim());
  167. int t3 = Int32.Parse(Data3.ToString().Trim());
  168. int t4 = Int32.Parse(Data4.ToString().Trim());
  169. int t5 = Int32.Parse(Data5.ToString().Trim());
  170. }
  171. return true;
  172. }
  173. catch
  174. {
  175. return false;
  176. }
  177. }
  178. // 스트링 자료가 널값이라면 None 으로 치환하는 경우
  179. //public static string Null_to_None(string Data)
  180. //{
  181. // string result = Data;
  182. // if (result == null || result.Length == 0)
  183. // result = _Text.None;
  184. // return result;
  185. //}
  186. //// 스트링 자료가 널값이라면 Blank 으로 치환하는 경우
  187. //public static string Null_to_Blank(string Data)
  188. //{
  189. // string result = Data;
  190. // if (result == null || result.Length == 0)
  191. // result = _Text.Blank;
  192. // return result;
  193. //}
  194. // 스트링으로 된 데이타를 두자리 스트링으로 변환
  195. public static string String_to_Int_TwoType(string Data)
  196. {
  197. string result = null;
  198. if (Data == null || Data.Length == 0 || Data.Length > 4) return "00";
  199. int IntData = Int32.Parse(Data);
  200. // 3자리 이상으로 데이타가 넘어오면 앞3자리 삭제
  201. if (IntData > 999)
  202. result = IntData.ToString().Remove(3);
  203. // 2자리 이상으로 데이타가 넘어오면 앞2자리 삭제
  204. else if (IntData > 99)
  205. result = IntData.ToString().Remove(2);
  206. else if (IntData == 0)
  207. result = "00";
  208. else if (IntData > 9 )
  209. result = IntData.ToString();
  210. else
  211. result = "0" + IntData.ToString();
  212. return result;
  213. }
  214. // 스트링으로 된 데이타를 세자리 스트링으로 변환
  215. public static string String_to_Int_ThreeType(string Data)
  216. {
  217. string result = null;
  218. if (Data == null || Data.Length == 0 || Data.Length > 4) return "000";
  219. int IntData = Int32.Parse(Data);
  220. // 3자리 이상으로 데이타가 넘어오면 앞3자리 삭제
  221. if (IntData > 999)
  222. result = IntData.ToString().Remove(1);
  223. else if (IntData == 0)
  224. result = "000";
  225. else if (IntData > 9)
  226. result = IntData.ToString();
  227. else
  228. result = "00" + IntData.ToString();
  229. return result;
  230. }
  231. // 스트링 데이터 -> 바이트 배열로 변환
  232. public static byte[] String_to_Byte(string Data)
  233. {
  234. byte[] ByteData = new byte[Data.Length];
  235. for (int i = 0; i < Data.Length; i++)
  236. {
  237. ByteData[i] = Convert.ToByte(Data[i]);
  238. }
  239. return ByteData;
  240. }
  241. // 정수 -> 2byte 변환
  242. public static byte Int_to_Byte(int Data, bool Head)
  243. {
  244. byte result1 = 0x00;
  245. byte result2 = 0x00;
  246. // 한자리 혹은 두자리
  247. if (Data <= 255)
  248. {
  249. result1 = 0x00;
  250. result2 = Convert.ToByte(Data); // int -> byte
  251. }
  252. else
  253. {
  254. // Ex :2748 -> 0xABC
  255. string temp = Data.ToString("X");
  256. // 세자리
  257. if (temp.Length == 3)
  258. {
  259. string temp1 = temp[0].ToString();
  260. string temp2 = temp[1].ToString() + temp[2].ToString() ;
  261. result1 = Convert.ToByte(temp1, 16); // string -> byte
  262. result2 = Convert.ToByte(temp2, 16); // string -> byte
  263. }
  264. // 4자리
  265. else if (temp.Length == 4)
  266. {
  267. string temp1 = temp[0].ToString() + temp[1].ToString();
  268. string temp2 = temp[2].ToString() + temp[3].ToString();
  269. result1 = Convert.ToByte(temp1, 16); // string -> byte
  270. result2 = Convert.ToByte(temp2, 16); // string -> byte
  271. }
  272. }
  273. // 앞자리
  274. if (Head == true)
  275. {
  276. return result1;
  277. }
  278. // 뒷자리
  279. else
  280. {
  281. return result2;
  282. }
  283. }
  284. // 바이트 -> 정수
  285. public static string GetBytesInt32(long argument)
  286. {
  287. byte[] byteArray = BitConverter.GetBytes(argument);
  288. string result = "";
  289. for (int i = byteArray.Length - 1; i >= 0; i--)
  290. {
  291. result = result + byteArray[i].ToString("X");
  292. }
  293. result = "0x" + result;
  294. return result;
  295. }
  296. // 4자리수 만들기
  297. public static string To_4byte(string Data)
  298. {
  299. try
  300. {
  301. string result = null;
  302. if (Data == null || Data.Length == 0 || Data == "0" || Data == "00" || Data == "000" || Data == "0000")
  303. return "0000";
  304. int temp_result = Int32.Parse(Data);
  305. if (temp_result > 0 && temp_result <= 9999)
  306. {
  307. if (temp_result < 10)
  308. {
  309. result = "000" + temp_result.ToString();
  310. }
  311. else if (temp_result < 100)
  312. {
  313. result = "00" + temp_result.ToString();
  314. }
  315. else if (temp_result < 1000)
  316. {
  317. result = "0" + temp_result.ToString();
  318. }
  319. else
  320. result = temp_result.ToString();
  321. }
  322. return result;
  323. }
  324. catch
  325. {
  326. return "0000";
  327. }
  328. }
  329. // 2자리수로 만들기
  330. public static string To_2byte(string Data)
  331. {
  332. try
  333. {
  334. string result = null;
  335. if (Data == null || Data.Length == 0 || Data == "0" || Data == "00" || Data == "000" || Data == "0000")
  336. return "00";
  337. int temp_result = Int32.Parse(Data);
  338. if (temp_result >= 0 && temp_result <= 99)
  339. {
  340. if (temp_result == 0)
  341. {
  342. result = "00";
  343. }
  344. else if (temp_result < 10)
  345. {
  346. result = "0" + temp_result.ToString();
  347. }
  348. else
  349. result = temp_result.ToString();
  350. }
  351. return result;
  352. }
  353. catch
  354. {
  355. return "00";
  356. }
  357. }
  358. // 인코딩
  359. //public static byte[] EncodingData(Coding coding, string Data)
  360. //{
  361. // byte[] data = null;
  362. // switch (coding)
  363. // {
  364. // case Coding.Default:
  365. // data = Encoding.Default.GetBytes(Data);
  366. // break;
  367. // case Coding.UTF8:
  368. // data = Encoding.UTF8.GetBytes(Data);
  369. // break;
  370. // case Coding.ASCII:
  371. // data = Encoding.ASCII.GetBytes(Data);
  372. // break;
  373. // }
  374. // return data;
  375. //}
  376. //// 디코딩
  377. //public static string DecodingData(Coding coding, byte[] Data)
  378. //{
  379. // string data = null;
  380. // switch (coding)
  381. // {
  382. // case Coding.Default:
  383. // data = Encoding.Default.GetString(Data);
  384. // break;
  385. // case Coding.UTF8:
  386. // data = Encoding.UTF8.GetString(Data);
  387. // break;
  388. // case Coding.ASCII:
  389. // data = Encoding.ASCII.GetString(Data);
  390. // break;
  391. // }
  392. // return data;
  393. //}
  394. // 초를 분 / 초 단위로 표시한다
  395. // 초를 시간/ 분 / 초 단위로 표시한다
  396. public static string Second_To_TimeInfo(int Second)
  397. {
  398. string result = null;
  399. int temp_second = 0;
  400. int temp_minute = 0;
  401. int temp_hour = 0;
  402. // 잘못된 정보
  403. if(Second < 0)
  404. return null;
  405. // 60 초 미만이라면
  406. if (Second >= 0 && Second < 60)
  407. {
  408. result = string.Format("{0}초", Second);
  409. }
  410. // 1시간 미만이라면
  411. else if (Second >= 60 && Second < 3600)
  412. {
  413. temp_minute = Second / 60;
  414. temp_second = Second - (temp_minute * 60);
  415. result = string.Format("{0}분 {1}초", temp_minute, temp_second);
  416. }
  417. else
  418. {
  419. temp_hour = Second / 3600;
  420. temp_minute = (Second - (temp_hour * 3600)) / 60;
  421. temp_second = (Second - (temp_hour * 3600) - (temp_minute * 60));
  422. result = string.Format("{0}시간 {1}분 {2}초", temp_hour, temp_minute, temp_second);
  423. }
  424. return result;
  425. }
  426. // 리스트내에 동일한 데이타만 존재하면 true 리턴
  427. public static bool Check_ArrayList_SameValue(ArrayList arraylist)
  428. {
  429. string Compare = (string)arraylist[0];
  430. foreach (string Data in arraylist)
  431. {
  432. if (Data != Compare)
  433. return false;
  434. }
  435. return true;
  436. }
  437. // 시간정보를 콤마로 구분하도록 변환
  438. public static string SplitTime_To_Comma(string Data)
  439. {
  440. if (Data == null || Data.Length == 0)
  441. return "";
  442. else
  443. {
  444. return Data.Replace(Split_Time.ToString(), Result_String);
  445. }
  446. }
  447. }
  448. }