OSDN Git Service

スレ一覧に勢いカラム追加。
[gikonavigoeson/gikonavi.git] / Sort.pas
1 unit Sort;
2
3 interface
4 uses
5         Windows, Messages, SysUtils, Classes, Controls, Forms,
6         BoardGroup,DateUtils,
7         Setting, Math;
8
9         function CategorySortProc(Item1, Item2: Pointer): integer;
10         function BoardSortProc(List: TStringList; Item1, Item2: Integer): integer;
11         function ThreadItemSortProc(List: TStringList; Item1, Item2: Integer): integer;
12         function CompareBool(Item1, Item2: Boolean): integer;
13         function CompareInt(Item1, Item2: Integer): Integer;
14         function CompareDate(Item1, Item2: TDateTime): Integer;
15
16 var
17         SortOrder: Boolean;
18         SortIndex: Integer;
19         SortNoFlag: Boolean;
20
21 implementation
22
23 function CategorySortProc(Item1, Item2: Pointer): integer;
24 var
25         CategoryItem1: TCategory;
26         CategoryItem2: TCategory;
27 begin
28         CategoryItem1 := TCategory(Item1);
29         CategoryItem2 := TCategory(Item2);
30
31         case TGikoBBSColumnID( SortIndex ) of
32         gbbscTitle:
33                 if SortNoFlag then
34                         Result := CompareInt(CategoryItem1.No, CategoryItem2.No)
35                 else
36                         Result := AnsiCompareText(CategoryItem1.Title, CategoryItem2.Title);
37         else
38                 Result := CompareInt(CategoryItem1.No, CategoryItem2.No)
39         end;
40
41         if not SortOrder then
42                 Result := Result * -1;
43 end;
44
45 function BoardSortProc(List: TStringList; Item1, Item2: Integer): integer;
46 var
47         BoardItem1: TBoard;
48         BoardItem2: TBoard;
49 begin
50         BoardItem1 := TBoard(List.Objects[Item1]);
51         BoardItem2 := TBoard(List.Objects[Item2]);
52         case TGikoCategoryColumnID( SortIndex ) of
53         gccTitle:
54                 if SortNoFlag then
55                         Result := CompareInt(BoardItem1.No, BoardItem2.No)
56                 else
57                         Result := AnsiCompareText(BoardItem1.Title, BoardItem2.Title);
58
59         gccRoundName:
60                 Result := CompareInt(BoardItem1.Count, BoardItem2.Count);
61
62         gccLastModified:
63                 Result := CompareDate(BoardItem1.RoundDate, BoardItem2.RoundDate);
64         else
65                 Result := CompareInt(BoardItem1.No, BoardItem2.No)
66         end;
67
68         if not SortOrder then
69                 Result := Result * -1;
70 end;
71
72 function ThreadItemSortProc(List: TStringList; Item1, Item2: Integer): integer;
73 var
74         ThreadItem1: TThreadItem;
75         ThreadItem2: TThreadItem;
76         SpanDay1, SpanDay2: Double;
77         NowDateTime: TDateTime;
78 begin
79         ThreadItem1 := TThreadItem(List.Objects[ Item1 ]);
80         ThreadItem2 := TThreadItem(List.Objects[ Item2 ]);
81         case TGikoBoardColumnID( SortIndex ) of
82                 gbcTitle:
83                         begin
84                                 if SortNoFlag then
85                                         Result := CompareInt(ThreadItem1.No, ThreadItem2.No)
86                                 else
87                                         Result := AnsiCompareText(ThreadItem1.Title, ThreadItem2.Title)
88                         end;
89
90                 gbcAllCount:                    Result := CompareInt(ThreadItem1.AllResCount, ThreadItem2.AllResCount);
91                 gbcLocalCount:          Result := CompareInt(ThreadItem1.Count, ThreadItem2.Count);
92                 gbcNonAcqCount:
93                         begin
94                                 if ThreadItem1.IsLogFile and ThreadItem2.IsLogFile then
95                                         Result := CompareInt(ThreadItem1.AllResCount - ThreadItem1.Count, ThreadItem2.AllResCount - ThreadItem2.Count)
96                                 else if ThreadItem1.IsLogFile then
97                                         Result := 1
98                                 else if ThreadItem2.IsLogFile then
99                                         Result := -1
100                                 else
101                                         Result := 0;
102                         end;
103
104                 gbcNewCount:                    Result := CompareInt(ThreadItem1.NewResCount, ThreadItem2.NewResCount);
105                 gbcUnReadCount:         Result := 0;
106                 gbcRoundName:           Result := AnsiCompareText(ThreadItem1.RoundName, ThreadItem2.RoundName);
107                 gbcRoundDate:   Result := CompareDateTime(ThreadItem1.RoundDate, ThreadItem2.RoundDate); {gbcLastModified:}
108                 gbcCreated:                             Result := CompareDateTime(ThreadItem1.CreateDate, ThreadItem2.CreateDate);
109                 gbcLastModified:        Result := CompareDateTime(ThreadItem1.LastModified, ThreadItem2.LastModified); {gbcLastModified:}
110                 gbcVigor:
111                         begin
112                                 NowDateTime := Now();
113                                 SpanDay1 := DaySpan(NowDateTime, ThreadItem1.CreateDate);
114                                 SpanDay2 := DaySpan(NowDateTime, ThreadItem2.CreateDate);
115                                 if (SpanDay1 > 0) and (SpanDay2 > 0) then begin
116                                         Result := CompareValue(
117                                                                 ThreadItem1.AllResCount / SpanDay1,
118                                                                 ThreadItem2.AllResCount / SpanDay2);
119                                 end else if (SpanDay1 > 0) then begin
120                                         Result := 1;
121                                 end else if (SpanDay2 > 0) then begin
122                                         Result := -1;
123                                 end else begin
124                                         Result := 0;
125                                 end;
126                         end;
127         else
128                 Result := 0;
129         end;
130
131 {       if SortIndex = 0 then
132                 if SortNoFlag then
133                         Result := CompareInt(ThreadItem1.No, ThreadItem2.No)
134                 else
135                         Result := CompareText(ThreadItem1.Title, ThreadItem2.Title)
136         else if SortIndex = 1 then
137                 Result := CompareInt(ThreadItem1.Count, ThreadItem2.Count)
138         else if SortIndex = 2 then
139 //              Result := CompareInt(ThreadItem1.RoundNo, ThreadItem2.RoundNo)
140                 Result := CompareText(ThreadItem1.RoundName, ThreadItem2.RoundName)
141         else
142                 Result := CompareDate(ThreadItem1.LastModified, ThreadItem2.LastModified);
143 }
144         if not SortOrder then
145                 Result := Result * -1;
146
147         // \83\\81[\83g\95]\89¿\82ª\93¯\82\8fê\8d\87\82Í\81A\91æ1\83J\83\89\83\80\82Ì\8f¸\8f\87\82É\83\\81[\83g
148         if Result = 0 then begin
149                 if SortNoFlag then
150                         Result := CompareInt(ThreadItem1.No, ThreadItem2.No)
151                 else
152                         Result := AnsiCompareText(ThreadItem1.Title, ThreadItem2.Title)
153         end;
154 end;
155
156 function CompareBool(Item1, Item2: Boolean): Integer;
157 begin
158         if (Item1 = True) and (Item2 = False) then
159                 Result := 1
160         else if (Item2 = False) and (Item2 = True) then
161                 Result := -1
162         else
163                 Result := 0;
164 end;
165
166 function CompareInt(Item1, Item2: Integer): Integer;
167 begin
168         if Item1 > Item2 then
169                 Result := 1
170         else if Item1 < Item2 then
171                 Result := -1
172         else
173                 Result := 0;
174 end;
175
176 function CompareDate(Item1, Item2: TDateTime): Integer;
177 begin
178         if Item1 > Item2 then
179                 Result := 1
180         else if Item1 < Item2 then
181                 Result := -1
182         else
183                 Result := 0;
184 end;
185
186 end.