@@ -16,12 +16,13 @@ limitations under the License.
1616*/
1717#endregion
1818
19- using System ;
20- using System . Collections . Generic ;
21- using System . Text ;
2219using Amdocs . Ginger . Common ;
2320using Amdocs . Ginger . Repository ;
2421using GingerCore . DataSource ;
22+ using System ;
23+ using System . Collections . Generic ;
24+ using System . Linq ;
25+ using System . Text ;
2526
2627namespace Amdocs . Ginger . CoreNET . DataSource
2728{
@@ -101,7 +102,7 @@ public string CreateQueryWithColumnList(List<ColumnCheckListItem> selectedColumn
101102 }
102103 foreach ( var column in selectedColumnList )
103104 {
104- selectedColumn . Append ( column . ColumnText . ToLower ( ) ) ;
105+ selectedColumn . Append ( column . ColumnText ) ;
105106 if ( selectedColumnList . Count > 1 )
106107 {
107108 selectedColumn . Append ( "," ) ;
@@ -127,92 +128,61 @@ public string CreateQueryWithColumnList(List<ColumnCheckListItem> selectedColumn
127128 return query ;
128129 }
129130
130-
131- public string CreateQueryWithWhereList ( List < ColumnCheckListItem > mColumnList , ObservableList < WhereConditionItem > whereConditionList , string tableName , DataSourceBase . eDSType dSType )
131+ public string CreateQueryWithWhereList ( List < ColumnCheckListItem > mColumnList , ObservableList < WhereConditionItem > whereConditionList , string tableName , DataSourceBase . eDSType dSType )
132132 {
133- var query = CreateQueryWithColumnList ( mColumnList , tableName , dSType ) ;
133+ // Build column list (NO SQL, just col1,col2,col3)
134+ string columnList = string . Join ( "," ,
135+ mColumnList . Where ( x => x . IsSelected ) . Select ( x => x . ColumnText ) ) ;
134136
135- if ( whereConditionList == null )
137+ // No conditions → return column list only
138+ if ( whereConditionList == null || whereConditionList . Count == 0 )
136139 {
137- return query ;
140+ return columnList ;
138141 }
139- var whereQuery = string . Empty ;
140142
143+ // Build WHERE clause in Ginger format
144+ string whereClause = "" ;
141145 for ( int i = 0 ; i < whereConditionList . Count ; i ++ )
142146 {
143- var wQuery = "" ;
144- var wCond = whereConditionList [ i ] . Condition . ToLower ( ) ;
145- var wColVal = whereConditionList [ i ] . TableColumn . Trim ( ) ;
146- var wOpr = whereConditionList [ i ] . Opertor ;
147- var wRowVal = whereConditionList [ i ] . RowValue ;
147+ var item = whereConditionList [ i ] ;
148148
149- if ( string . IsNullOrEmpty ( wRowVal ) )
150- {
149+ if ( string . IsNullOrEmpty ( item . TableColumn ) ||
150+ string . IsNullOrEmpty ( item . RowValue ) )
151151 continue ;
152- }
153152
154- if ( wCond == "empty" )
155- {
156- wCond = "" ;
157- }
153+ string predicate = "" ;
158154
159- if ( wOpr == "Equals" )
160- {
161- if ( wColVal == "GINGER_ID" )
162- {
163- wQuery = string . Concat ( wQuery , " " , wCond , " " , wColVal , " = " , wRowVal ) ;
164- }
165- else
166- {
167- wQuery = string . Concat ( wQuery , " " , wCond , " " , wColVal , " = \" " , wRowVal , "\" " ) ;
168- }
169- }
170- else if ( wOpr == "NotEquals" )
171- {
172- if ( wColVal == "GINGER_ID" )
173- {
174- wQuery = string . Concat ( wQuery , " " , wCond , " " , wColVal , " <> " , wRowVal ) ;
175- }
176- else
177- {
178- wQuery = string . Concat ( wQuery , " " , wCond , " " , wColVal , " <> \" " , wRowVal , "\" " ) ;
179- }
180- }
181- else if ( wOpr == "Contains" )
182- {
183- wQuery = string . Concat ( wQuery , " " , wCond , " " , wColVal , " Like " , "\" %" , wRowVal , "%\" " ) ;
184- }
185- else if ( wOpr == "NotContains" )
186- {
187- wQuery = string . Concat ( wQuery , " " , wCond , " " , wColVal , " Not Like " , "\" %" , wRowVal , "%\" " ) ;
188- }
189- else if ( wOpr == "StartsWith" )
190- {
191- wQuery = string . Concat ( wQuery , " " , wCond , " " , wColVal , " like " , "\" " , wRowVal , "%\" " ) ;
192- }
193- else if ( wOpr == "NotStartsWith" )
194- {
195- wQuery = string . Concat ( wQuery , " " , wCond , " " , wColVal , " Not Like " , "\" " , wRowVal , "%\" " ) ;
196- }
197- else if ( wOpr == "EndsWith" )
198- {
199- wQuery = string . Concat ( wQuery , " " , wCond , " " , wColVal , " like " , "\" %" , wRowVal , "\" " ) ;
200- }
201- else if ( wOpr == "NotEndsWith" )
155+ switch ( item . Opertor )
202156 {
203- wQuery = string . Concat ( wQuery , " " , wCond , " " , wColVal , " not like " , "\" %" , wRowVal , "\" " ) ;
157+ case "Equals" :
158+ predicate = $ "{ item . TableColumn } = \" { item . RowValue } \" ";
159+ break ;
160+ case "NotEquals" :
161+ predicate = $ "{ item . TableColumn } <> \" { item . RowValue } \" ";
162+ break ;
163+ case "Contains" :
164+ predicate = $ "{ item . TableColumn } Like \" %{ item . RowValue } %\" ";
165+ break ;
166+ case "NotContains" :
167+ predicate = $ "{ item . TableColumn } Not Like \" %{ item . RowValue } %\" ";
168+ break ;
169+ case "StartsWith" :
170+ predicate = $ "{ item . TableColumn } Like \" { item . RowValue } %\" ";
171+ break ;
172+ case "EndsWith" :
173+ predicate = $ "{ item . TableColumn } Like \" %{ item . RowValue } \" ";
174+ break ;
204175 }
205176
177+ if ( i > 0 )
178+ whereClause += " AND " ;
206179
207- whereQuery = string . Concat ( whereQuery , wQuery ) ;
180+ whereClause += predicate ;
208181 }
209- if ( whereQuery != string . Empty )
210- {
211- query += " Where " + whereQuery ;
212- }
213- return query ;
214- }
215182
183+ // Return Ginger expected string: "col1,col2 where condition"
184+ return $ "{ columnList } where { whereClause } ";
185+ }
216186 public ObservableList < GingerCore . DataSource . ActDSConditon > GetConditons ( ObservableList < WhereConditionItem > conditonStringList , System . Data . DataTable mDataTable )
217187 {
218188 var dsConditionList = new ObservableList < GingerCore . DataSource . ActDSConditon > ( ) ;
0 commit comments