_Sort.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Collections;
  6. namespace IControls_FireManager
  7. {
  8. // 정렬에 관련된 인터페이스를 구현하는 것은 여기서 전담한다
  9. public class _Sort
  10. {
  11. // 문자열을 비교하려면 보통 1,2,3,4,5,6,7,8,9,10 -> 1,10,2,3,4,5,6,7,8,9 이런식으로 변경되는 경우가 있어서
  12. // 인터페이스를 제공하여 이 클래스를 해당 인터페이스에 넣으면 된다
  13. public class StringNumbering : IComparer
  14. {
  15. int IComparer.Compare(object a, object b)
  16. {
  17. // 첫번째 데이타 검사
  18. int data1 = Int32.Parse(a.ToString());
  19. int data2 = Int32.Parse(b.ToString());
  20. // 비교
  21. if (data1 > data2)
  22. return 1;
  23. else if (data1 < data2)
  24. return -1;
  25. else
  26. return 0;
  27. }
  28. }
  29. // cyim 2016.04.01 : 입력 및 출력회로 정렬 기능
  30. public class CircuitStringNumbering : IComparer
  31. {
  32. int IComparer.Compare(object a, object b)
  33. {
  34. string tmp1 = ((_OrderByCircuitNo)a).CircuitNo.Replace("-", "");
  35. tmp1 = tmp1.Replace("M", "");
  36. tmp1 = tmp1.Replace("I", "");
  37. tmp1 = tmp1.Replace("O", "");
  38. string tmp2 = ((_OrderByCircuitNo)b).CircuitNo.Replace("-", "");
  39. tmp2 = tmp2.Replace("M", "");
  40. tmp2 = tmp2.Replace("I", "");
  41. tmp2 = tmp2.Replace("O", "");
  42. // 첫번째 데이타 검사
  43. int data1 = Int32.Parse(tmp1);
  44. int data2 = Int32.Parse(tmp2);
  45. // 비교
  46. if (data1 > data2)
  47. return 1;
  48. else if (data1 < data2)
  49. return -1;
  50. else
  51. return 0;
  52. }
  53. }
  54. // 서브키 정렬 전용
  55. // 서브 포트 키의 경우 61.33.215.151-DR1 61.33.215.151-DR2 과 같이 정보가 들어오지만
  56. // 일반카드리더 포트의 경우 61.33.215.151-CR1_1, 61.33.215.151-CR1_2 .. 데이타가 들어오므로 분리해서 정렬해야함
  57. // 일반 서브포트용
  58. public class SubPortNum : IComparer
  59. {
  60. int IComparer.Compare(object a, object b)
  61. {
  62. // 아이피와 포트넘버를 분리한다
  63. string[] SubKey1 = a.ToString().Split('-');
  64. string[] SubKey2 = b.ToString().Split('-');
  65. // 포트넘버중에 앞두글자를 제외한다
  66. SubKey1[1] = SubKey1[1].Remove(0, 2);
  67. SubKey2[1] = SubKey2[1].Remove(0, 2);
  68. // 첫번째 데이타 검사
  69. int data1 = Int32.Parse(SubKey1[1]);
  70. int data2 = Int32.Parse(SubKey2[1]);
  71. // 비교
  72. if (data1 > data2)
  73. return 1;
  74. else if (data1 < data2)
  75. return -1;
  76. else
  77. return 0;
  78. }
  79. }
  80. // 일반 카드리더포트용
  81. public class CRPortNum : IComparer
  82. {
  83. int IComparer.Compare(object a, object b)
  84. {
  85. // 아이피와 포트넘버를 분리한다
  86. string[] SubKey1 = a.ToString().Split('-');
  87. string[] SubKey2 = b.ToString().Split('-');
  88. // 포트넘버중에 앞두글자를 제외한다
  89. SubKey1[1] = SubKey1[1].Remove(0, 2);
  90. SubKey2[1] = SubKey2[1].Remove(0, 2);
  91. // 일반카드리더기의 경우 한번더 분리해야한다
  92. string[] Data1 = SubKey1[1].Split('_');
  93. string[] Data2 = SubKey2[1].Split('_');
  94. // 첫번째 데이타 검사
  95. int data1 = Int32.Parse(Data1[0]);
  96. int data2 = Int32.Parse(Data2[0]);
  97. // 비교
  98. if (data1 > data2)
  99. return 1;
  100. else if (data1 < data2)
  101. return -1;
  102. else
  103. {
  104. // 처음이 동일하면 두번째 데이타를 비교해야한다, 단 일반카드리더기중에는 X_X 포맷이 아닐수도 있으므로..
  105. if (Data1.Length > 1 && Data2.Length > 1)
  106. {
  107. int datasub1 = Int32.Parse(Data1[1]);
  108. int datasub2 = Int32.Parse(Data2[1]);
  109. // 비교
  110. if (datasub1 > datasub2)
  111. return 1;
  112. else if (datasub1 < datasub2)
  113. return -1;
  114. else
  115. return 0;
  116. }
  117. else
  118. return 0;
  119. }
  120. }
  121. }
  122. // 하단 미사용 (참고용이므로 삭제 금지)
  123. //public class TestClassCompare : IComparer, IComparer<TestClass>
  124. //{
  125. // public int Compare(TestClass x, TestClass y)
  126. // {
  127. // return x.Data.CompareTo(y.Data);
  128. // }
  129. // public int Compare(object x, object y)
  130. // {
  131. // return Compare((TestClass)x, (TestClass)y);
  132. // }
  133. //}
  134. //public class TestClass
  135. //{
  136. // public string Data;
  137. //}
  138. //// Nested class to do ascending sort on year property.
  139. //private class sortYearAscendingHelper : IComparer
  140. //{
  141. // int IComparer.Compare(object a, object b)
  142. // {
  143. // car c1 = (car)a;
  144. // car c2 = (car)b;
  145. // if (c1.year > c2.year)
  146. // return 1;
  147. // if (c1.year < c2.year)
  148. // return -1;
  149. // else
  150. // return 0;
  151. // }
  152. //}
  153. //// Nested class to do descending sort on year property.
  154. //private class sortYearDescendingHelper : IComparer
  155. //{
  156. // int IComparer.Compare(object a, object b)
  157. // {
  158. // car c1 = (car)a;
  159. // car c2 = (car)b;
  160. // if (c1.year < c2.year)
  161. // return 1;
  162. // if (c1.year > c2.year)
  163. // return -1;
  164. // else
  165. // return 0;
  166. // }
  167. //}
  168. }
  169. // 이벤트 정렬 인터페이스 구현
  170. //public class _EventDataSort : IComparer<CEventLogData>
  171. //{
  172. // public int Compare(CEventLogData Data1, CEventLogData Data2)
  173. // {
  174. // try
  175. // {
  176. // if (Data1.eventTime == null || Data1.eventTime.Length == 0 || Data1.eventTime.Length < 14) return 0;
  177. // if (Data2.eventTime == null || Data2.eventTime.Length == 0 || Data2.eventTime.Length < 14) return 0;
  178. // string tData1 = Data1.eventTime.Substring(0, 14);
  179. // string tData2 = Data2.eventTime.Substring(0, 14);
  180. // int TempData1 = Int32.Parse(tData1);
  181. // int TempData2 = Int32.Parse(tData2);
  182. // // 비교
  183. // if (TempData1 > TempData2)
  184. // return 1;
  185. // else if (TempData1 < TempData2)
  186. // return -1;
  187. // else
  188. // return 0;
  189. // }
  190. // catch
  191. // {
  192. // return 0;
  193. // }
  194. // }
  195. //}
  196. }