123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Collections;
- namespace IControls_FireManager
- {
- // 정렬에 관련된 인터페이스를 구현하는 것은 여기서 전담한다
- public class _Sort
- {
- // 문자열을 비교하려면 보통 1,2,3,4,5,6,7,8,9,10 -> 1,10,2,3,4,5,6,7,8,9 이런식으로 변경되는 경우가 있어서
- // 인터페이스를 제공하여 이 클래스를 해당 인터페이스에 넣으면 된다
- public class StringNumbering : IComparer
- {
- int IComparer.Compare(object a, object b)
- {
- // 첫번째 데이타 검사
- int data1 = Int32.Parse(a.ToString());
- int data2 = Int32.Parse(b.ToString());
- // 비교
- if (data1 > data2)
- return 1;
- else if (data1 < data2)
- return -1;
- else
- return 0;
- }
- }
- // cyim 2016.04.01 : 입력 및 출력회로 정렬 기능
- public class CircuitStringNumbering : IComparer
- {
- int IComparer.Compare(object a, object b)
- {
- string tmp1 = ((_OrderByCircuitNo)a).CircuitNo.Replace("-", "");
- tmp1 = tmp1.Replace("M", "");
- tmp1 = tmp1.Replace("I", "");
- tmp1 = tmp1.Replace("O", "");
- string tmp2 = ((_OrderByCircuitNo)b).CircuitNo.Replace("-", "");
- tmp2 = tmp2.Replace("M", "");
- tmp2 = tmp2.Replace("I", "");
- tmp2 = tmp2.Replace("O", "");
-
- // 첫번째 데이타 검사
- int data1 = Int32.Parse(tmp1);
- int data2 = Int32.Parse(tmp2);
- // 비교
- if (data1 > data2)
- return 1;
- else if (data1 < data2)
- return -1;
- else
- return 0;
- }
- }
- // 서브키 정렬 전용
- // 서브 포트 키의 경우 61.33.215.151-DR1 61.33.215.151-DR2 과 같이 정보가 들어오지만
- // 일반카드리더 포트의 경우 61.33.215.151-CR1_1, 61.33.215.151-CR1_2 .. 데이타가 들어오므로 분리해서 정렬해야함
- // 일반 서브포트용
- public class SubPortNum : IComparer
- {
- int IComparer.Compare(object a, object b)
- {
- // 아이피와 포트넘버를 분리한다
- string[] SubKey1 = a.ToString().Split('-');
- string[] SubKey2 = b.ToString().Split('-');
- // 포트넘버중에 앞두글자를 제외한다
- SubKey1[1] = SubKey1[1].Remove(0, 2);
- SubKey2[1] = SubKey2[1].Remove(0, 2);
- // 첫번째 데이타 검사
- int data1 = Int32.Parse(SubKey1[1]);
- int data2 = Int32.Parse(SubKey2[1]);
- // 비교
- if (data1 > data2)
- return 1;
- else if (data1 < data2)
- return -1;
- else
- return 0;
- }
- }
- // 일반 카드리더포트용
- public class CRPortNum : IComparer
- {
- int IComparer.Compare(object a, object b)
- {
- // 아이피와 포트넘버를 분리한다
- string[] SubKey1 = a.ToString().Split('-');
- string[] SubKey2 = b.ToString().Split('-');
- // 포트넘버중에 앞두글자를 제외한다
- SubKey1[1] = SubKey1[1].Remove(0, 2);
- SubKey2[1] = SubKey2[1].Remove(0, 2);
- // 일반카드리더기의 경우 한번더 분리해야한다
- string[] Data1 = SubKey1[1].Split('_');
- string[] Data2 = SubKey2[1].Split('_');
- // 첫번째 데이타 검사
- int data1 = Int32.Parse(Data1[0]);
- int data2 = Int32.Parse(Data2[0]);
- // 비교
- if (data1 > data2)
- return 1;
- else if (data1 < data2)
- return -1;
- else
- {
- // 처음이 동일하면 두번째 데이타를 비교해야한다, 단 일반카드리더기중에는 X_X 포맷이 아닐수도 있으므로..
- if (Data1.Length > 1 && Data2.Length > 1)
- {
- int datasub1 = Int32.Parse(Data1[1]);
- int datasub2 = Int32.Parse(Data2[1]);
- // 비교
- if (datasub1 > datasub2)
- return 1;
- else if (datasub1 < datasub2)
- return -1;
- else
- return 0;
- }
- else
- return 0;
- }
- }
- }
- // 하단 미사용 (참고용이므로 삭제 금지)
- //public class TestClassCompare : IComparer, IComparer<TestClass>
- //{
- // public int Compare(TestClass x, TestClass y)
- // {
- // return x.Data.CompareTo(y.Data);
- // }
- // public int Compare(object x, object y)
- // {
- // return Compare((TestClass)x, (TestClass)y);
- // }
- //}
- //public class TestClass
- //{
- // public string Data;
- //}
- //// Nested class to do ascending sort on year property.
- //private class sortYearAscendingHelper : IComparer
- //{
- // int IComparer.Compare(object a, object b)
- // {
- // car c1 = (car)a;
- // car c2 = (car)b;
- // if (c1.year > c2.year)
- // return 1;
- // if (c1.year < c2.year)
- // return -1;
- // else
- // return 0;
- // }
- //}
- //// Nested class to do descending sort on year property.
- //private class sortYearDescendingHelper : IComparer
- //{
- // int IComparer.Compare(object a, object b)
- // {
- // car c1 = (car)a;
- // car c2 = (car)b;
- // if (c1.year < c2.year)
- // return 1;
- // if (c1.year > c2.year)
- // return -1;
- // else
- // return 0;
- // }
- //}
- }
- // 이벤트 정렬 인터페이스 구현
- //public class _EventDataSort : IComparer<CEventLogData>
- //{
- // public int Compare(CEventLogData Data1, CEventLogData Data2)
- // {
- // try
- // {
- // if (Data1.eventTime == null || Data1.eventTime.Length == 0 || Data1.eventTime.Length < 14) return 0;
- // if (Data2.eventTime == null || Data2.eventTime.Length == 0 || Data2.eventTime.Length < 14) return 0;
- // string tData1 = Data1.eventTime.Substring(0, 14);
- // string tData2 = Data2.eventTime.Substring(0, 14);
- // int TempData1 = Int32.Parse(tData1);
- // int TempData2 = Int32.Parse(tData2);
- // // 비교
- // if (TempData1 > TempData2)
- // return 1;
- // else if (TempData1 < TempData2)
- // return -1;
- // else
- // return 0;
- // }
- // catch
- // {
- // return 0;
- // }
- // }
- //}
- }
|