Develop and Download Open Source Software

Browse Subversion Repository

Contents of /MainWindowListViewSorter.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (show annotations) (download)
Wed Feb 23 12:21:31 2011 UTC (13 years, 2 months ago) by aqua877
File size: 2692 byte(s)
バージョン情報ウィンドウへのロゴ追加
設定ウィンドウのイベントおよび初期化の実装すべて完了
コメント取得時のソーティングによるパフォーマンス低下を改善
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Collections;
6 using System.Windows.Forms;
7
8 namespace Aqua877.WinApp.IronLivetube
9 {
10 public class MainWindowListViewSorter : IComparer
11 {
12 private int _Column;
13 private SortOrder _Order;
14
15 public int Column
16 {
17 set
18 {
19 if (this._Column == value)
20 {
21 if (this._Order == SortOrder.Ascending)
22 {
23 this._Order = SortOrder.Descending;
24 }
25 else if (this._Order == SortOrder.Descending)
26 {
27 this._Order = SortOrder.Ascending;
28 }
29 }
30 this._Column = value;
31 }
32 get
33 {
34 return this._Column;
35 }
36 }
37
38 public SortOrder Order
39 {
40 set
41 {
42 this._Order = value;
43 }
44 get
45 {
46 return this._Order;
47 }
48 }
49
50 public MainWindowListViewSorter(int column, SortOrder order)
51 {
52 this._Column = column;
53 this._Order = order;
54 }
55
56 public MainWindowListViewSorter()
57 {
58 this._Column = 0;
59 this._Order = SortOrder.Ascending;
60 }
61
62 public int Compare(object x, object y)
63 {
64 int result = 0;
65
66 var itemx = x as ListViewItem;
67 var itemy = y as ListViewItem;
68
69 switch (this.Column)
70 {
71 case 0:
72 {
73 if (itemx.SubItems[this._Column].Text == "")
74 {
75 if (itemy.SubItems[this._Column].Text == "")
76 {
77 result = 0;
78 }
79 else
80 {
81 result = -1;
82 }
83 }
84 else if (itemy.SubItems[this._Column].Text == "")
85 {
86 result = 1;
87 }
88 else
89 {
90 result = int.Parse(itemx.SubItems[0].Text).CompareTo(int.Parse(itemy.SubItems[0].Text));
91 break;
92 }
93 break;
94 }
95
96 case 1:
97 {
98 result = 0;
99 break;
100 }
101
102 case 2:
103 case 3:
104 case 5:
105 case 6:
106 {
107 if (itemx.SubItems[this._Column].Text == "")
108 {
109 if (itemy.SubItems[this._Column].Text == "")
110 {
111 result = 0;
112 }
113 else
114 {
115 result = -1;
116 }
117 }
118 else if (itemy.SubItems[this._Column].Text == "")
119 {
120 result = 1;
121 }
122 else
123 {
124 result = string.Compare(itemx.SubItems[this._Column].Text, itemy.SubItems[this._Column].Text);
125 }
126 break;
127 }
128
129 case 4:
130 {
131 result = DateTime.Compare(
132 DateTime.ParseExact(itemx.SubItems[4].Text, "M/d H:m:s", null),
133 DateTime.ParseExact(itemy.SubItems[4].Text, "M/d H:m:s", null)
134 );
135 break;
136 }
137 }
138
139 if (this._Order == SortOrder.Descending)
140 {
141 result = -result;
142 }
143 else if (this._Order == SortOrder.None)
144 {
145 result = 0;
146 }
147 return result;
148 }
149 }
150 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26