Skip to content

Commit 419c4e0

Browse files
author
tanushah
committed
Refactor export query generation and persistence logic
Rewrite CreateQueryWithWhereList to use LINQ for column selection, simplify WHERE clause construction with a switch statement, and return queries in the expected format. Update DataSourceExportToExcelPage to persist ExportQueryValue for both action and non-action table elements. Clean up code and improve maintainability.
1 parent ab1b3ae commit 419c4e0

2 files changed

Lines changed: 65 additions & 76 deletions

File tree

Ginger/Ginger/DataSource/DataSourceExportToExcelPage.xaml.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,17 @@ private void SetDataTable()
216216

217217
private void ExcelExportQuery_ValueTextBox_TextChanged(object sender, TextChangedEventArgs e)
218218
{
219+
219220
if (mActDSTableElement != null)
220221
{
221222
mActDSTableElement.ExcelConfig.ExportQueryValue = xExcelExportQuery.ValueTextBox.Text;
222223
}
224+
else
225+
{
226+
// Add this line to persist in standalone page mode
227+
mExcelConfig.ExportQueryValue = xExcelExportQuery.ValueTextBox.Text;
228+
}
229+
223230
}
224231

225232
private void InitColumnListGrid(DataColumnCollection columns)
@@ -417,12 +424,24 @@ private void xRdoByQueryExport_Checked(object sender, RoutedEventArgs e)
417424

418425
if (mActDSTableElement != null)
419426
{
420-
mActDSTableElement.ExcelConfig.IsCustomExport = Convert.ToBoolean(xRdoByCustomExport.IsChecked);
421-
xExcelExportQuery.ValueTextBox.Text = mExcelConfig.CreateQueryWithWhereList(mActDSTableElement.ExcelConfig.ColumnList.ToList().FindAll(x => x.IsSelected), mActDSTableElement.ExcelConfig.WhereConditionStringList, mDataTable.TableName, mDataSourceTable.DSC.DSType);
427+
428+
xExcelExportQuery.ValueTextBox.Text =
429+
mExcelConfig.CreateQueryWithWhereList(mActDSTableElement.ExcelConfig.ColumnList.Where(x => x.IsSelected).ToList(),
430+
mActDSTableElement.ExcelConfig.WhereConditionStringList,
431+
mDataTable.TableName,
432+
mDataSourceTable.DSC.DSType);
422433
}
423434
else
424435
{
425-
xExcelExportQuery.ValueTextBox.Text = mExcelConfig.CreateQueryWithWhereList(mExcelConfig.ColumnList.ToList().FindAll(x => x.IsSelected), mExcelConfig.WhereConditionStringList, mDataTable.TableName, mDataSourceTable.DSC.DSType);
436+
// Generate query for non-action table element
437+
xExcelExportQuery.ValueTextBox.Text =
438+
mExcelConfig.CreateQueryWithWhereList(
439+
mExcelConfig.ColumnList
440+
.Where(x => x.IsSelected)
441+
.ToList(),
442+
mExcelConfig.WhereConditionStringList,
443+
mDataTable.TableName,
444+
mDataSourceTable.DSC.DSType);
426445
}
427446
}
428447

Ginger/GingerCoreCommon/DataBaseLib/ExportToExcelConfig.cs

Lines changed: 43 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ limitations under the License.
1616
*/
1717
#endregion
1818

19-
using System;
20-
using System.Collections.Generic;
21-
using System.Text;
2219
using Amdocs.Ginger.Common;
2320
using Amdocs.Ginger.Repository;
2421
using GingerCore.DataSource;
22+
using System;
23+
using System.Collections.Generic;
24+
using System.Linq;
25+
using System.Text;
2526

2627
namespace 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

Comments
 (0)