ensure the tests files are in sync; see run-mono-tests.bat diff
[mono.git] / mcs / class / System.Web / System.Web.UI / DataSourceSelectArguments.cs
1 //
2 // System.Web.UI.DataSourceSelectArguments.cs
3 //
4 // Author:
5 //   Sanjay Gupta <gsanjay@novell.com>
6 //
7 // (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if NET_2_0
32 using System;
33
34 namespace System.Web.UI
35 {
36         public sealed class DataSourceSelectArguments
37         {
38                 string sortExpression;
39                 int startingRowIndex;
40                 int maxRows;
41                 bool getTotalRowCount;
42                 int totalRowCount = -1;
43                 DataSourceCapabilities dsc = DataSourceCapabilities.None;
44
45                 // MSDN: Gets a DataSourceSelectArguments object with the sort expression set to Empty. 
46                 public static DataSourceSelectArguments Empty {
47                         get {
48                                 return new DataSourceSelectArguments ();
49                         }
50                 }
51
52                 public DataSourceSelectArguments ()
53                 {
54                 }
55
56                 public DataSourceSelectArguments (string sortExpression)
57                 {
58                         this.sortExpression = sortExpression;
59                 }
60
61                 public DataSourceSelectArguments (int startingRowIndex, int maxRows)
62                 {
63                         this.startingRowIndex = startingRowIndex;
64                         this.maxRows = maxRows;
65                 }
66
67                 public DataSourceSelectArguments (string sortExpression, int startingRowIndex, int maxRows)
68                 {
69                         this.sortExpression = sortExpression; 
70                         this.startingRowIndex = startingRowIndex;
71                         this.maxRows = maxRows;
72                 }
73
74                 public void AddSupportedCapabilities (DataSourceCapabilities srcCapabilities)
75                 {
76                         this.dsc = this.dsc | srcCapabilities;
77                 }
78
79                 // MSDN: The DataSourceSelectArguments class overrides the Object.Equals method to test 
80                 // equality using the various properties of the objects. If the MaximumRows, 
81                 // RetrieveTotalRowCount, SortExpression, StartRowIndex, and TotalRowCount properties 
82                 // are all equal in value, the Equals(Object) method returns true.
83                 public override bool Equals (object obj)
84                 {
85                         DataSourceSelectArguments args = obj as DataSourceSelectArguments;
86                         if (args == null)
87                                 return false;
88
89                         return (this.SortExpression == args.SortExpression &&
90                                 this.StartRowIndex == args.StartRowIndex &&
91                                 this.MaximumRows == args.MaximumRows &&
92                                 this.RetrieveTotalRowCount == args.RetrieveTotalRowCount &&
93                                 this.TotalRowCount == args.TotalRowCount);
94                 }
95
96                 public override int GetHashCode ()
97                 {
98                         int hash = SortExpression != null ? SortExpression.GetHashCode() : 0;
99                         return hash ^ StartRowIndex ^ MaximumRows ^ RetrieveTotalRowCount.GetHashCode() ^ TotalRowCount;
100                 }
101
102                 // The RaiseUnsupportedCapabilitiesError method is used by data-bound controls 
103                 // to compare additional requested capabilities represented by the properties 
104                 // of the DataSourceSelectArguments class, such as the ability to sort or page 
105                 // through a result set, with the capabilities supported by the data source view. 
106                 // The view calls its own RaiseUnsupportedCapabilityError method for each possible 
107                 // capability defined in the DataSourceCapabilities enumeration. 
108                 public void RaiseUnsupportedCapabilitiesError (DataSourceView view)
109                 {
110                         DataSourceCapabilities requestedCaps = RequestedCapabilities;
111                         DataSourceCapabilities notSupportedCaps = (requestedCaps ^ dsc) & requestedCaps;
112                         if (notSupportedCaps == DataSourceCapabilities.None)
113                                 return;
114
115                         if ((notSupportedCaps & DataSourceCapabilities.RetrieveTotalRowCount) > 0)
116                                 notSupportedCaps = DataSourceCapabilities.RetrieveTotalRowCount;
117                         else if ((notSupportedCaps & DataSourceCapabilities.Page) > 0)
118                                 notSupportedCaps = DataSourceCapabilities.Page;
119
120                         view.RaiseUnsupportedCapabilityError (notSupportedCaps);
121                 }
122
123                 DataSourceCapabilities RequestedCapabilities {
124                         get {
125                                 DataSourceCapabilities caps = DataSourceCapabilities.None;
126                                 if (!String.IsNullOrEmpty (SortExpression))
127                                         caps |= DataSourceCapabilities.Sort;
128                                 if (RetrieveTotalRowCount)
129                                         caps |= DataSourceCapabilities.RetrieveTotalRowCount;
130                                 if (StartRowIndex > 0 || MaximumRows > 0)
131                                         caps |= DataSourceCapabilities.Page;
132                                 return caps;
133                         }
134                 }
135
136                 public int MaximumRows {
137                         get { return this.maxRows; }
138                         set { this.maxRows = value; }
139                 }
140
141                 public bool RetrieveTotalRowCount  {
142                         get { return this.getTotalRowCount; }
143                         set { this.getTotalRowCount = value; }
144                 }
145
146                 public string SortExpression {
147                         get {
148                                 if (sortExpression == null)
149                                         return String.Empty;
150                                 return this.sortExpression;
151                         }
152                         set { this.sortExpression = value; }
153                 }
154
155                 public int StartRowIndex {
156                         get { return this.startingRowIndex; }
157                         set { this.startingRowIndex = value; }
158                 }
159
160                 public int TotalRowCount {
161                         get { return this.totalRowCount; }
162                         set { this.totalRowCount = value; }
163                 }
164         }
165 }
166 #endif