@@ -14,6 +14,14 @@ public partial class ObjectExecutionSummary : UserControl, ISetContext, IRefresh
1414 public ObjectExecutionSummary ( )
1515 {
1616 InitializeComponent ( ) ;
17+ dgv . RegisterClearFilter ( tsClearFilter ) ;
18+ dgv . GridFilterChanged += ( sender , args ) =>
19+ {
20+ if ( dgv . RowFilter == string . Empty )
21+ {
22+ txtSearch . Text = string . Empty ;
23+ }
24+ } ;
1725 }
1826
1927 private string Instance => _context . InstanceName ;
@@ -187,6 +195,7 @@ public void RefreshData()
187195 {
188196 splitContainer1 . Panel1Collapsed = true ;
189197 }
198+ var filter = dgv . RowFilter ;
190199 dgv . DataSource = null ;
191200
192201 var dt = GetObjectExecutionStatsSummary ( ) ;
@@ -198,7 +207,7 @@ public void RefreshData()
198207 dgv . Columns . Clear ( ) ;
199208 dgv . AutoGenerateColumns = false ;
200209 tsCompare . Font = new Font ( tsCompare . Font , HasCompare ? FontStyle . Bold : FontStyle . Regular ) ;
201- SetDataSourceWithFilter ( ) ;
210+ dgv . DataSource = new DataView ( dt , filter , "total_duration_sec DESC" , DataViewRowState . CurrentRows ) ;
202211 dgv . Columns . AddRange ( Columns . ToArray ( ) ) ;
203212 dgv . AutoResizeColumns ( DataGridViewAutoSizeColumnsMode . DisplayedCells ) ;
204213 dgv . ApplyTheme ( ) ;
@@ -256,44 +265,21 @@ private DataTable GetObjectExecutionStatsSummary()
256265 cmd . Parameters . AddWithValue ( "FromDate" , DateRange . FromUTC ) ;
257266 cmd . Parameters . AddWithValue ( "ToDate" , DateRange . ToUTC ) ;
258267 cmd . Parameters . AddWithValue ( "UTCOffset" , DateHelper . UtcOffset ) ;
259- cmd . Parameters . AddWithValue ( "InstanceIDs" , _context . InstanceIDs . AsDataTable ( ) ) ;
268+ cmd . Parameters . AddWithValue ( "InstanceIDs" , _context . InstanceIDs . AsDataTable ( ) ) ;
260269 dt = new DataTable ( ) ;
261270 da . Fill ( dt ) ;
262271 return dt ;
263272 }
264273 }
265274
266- private void SetDataSourceWithFilter ( )
267- {
268- if ( string . IsNullOrEmpty ( txtSearch . Text . Trim ( ) ) )
269- {
270- dgv . DataSource = new DataView ( dt , null , "total_duration_sec DESC" , DataViewRowState . CurrentRows ) ;
271- lblSearch . Font = new Font ( lblSearch . Font , FontStyle . Regular ) ;
272- }
273- else
274- {
275- lblSearch . Font = new Font ( lblSearch . Font , FontStyle . Bold ) ;
276- try
277- {
278- dgv . DataSource = new DataView ( dt , string . Format ( "SchemaName LIKE '%{0}%' OR ObjectName LIKE '%{0}%'" , txtSearch . Text . Replace ( "'" , "''" ) ) , "total_duration_sec DESC" , DataViewRowState . CurrentRows ) ;
279- }
280- catch ( Exception ex )
281- {
282- MessageBox . Show ( ex . Message , "Filter Error" , MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
283- dgv . DataSource = new DataView ( dt , null , "total_duration_sec DESC" , DataViewRowState . CurrentRows ) ;
284- }
285- }
286- dgv . AutoResizeColumns ( DataGridViewAutoSizeColumnsMode . DisplayedCells ) ;
287- }
288-
289275 private void TsRefresh_Click ( object sender , EventArgs e )
290276 {
291277 RefreshData ( ) ;
292278 }
293279
294280 private void TsCopy_Click ( object sender , EventArgs e )
295281 {
296- Common . CopyDataGridViewToClipboard ( dgv ) ;
282+ dgv . CopyGrid ( ) ;
297283 }
298284
299285 private void TsSetOffset_Click ( object sender , EventArgs e )
@@ -426,7 +412,7 @@ private void Dgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
426412
427413 private void TsExcel_Click ( object sender , EventArgs e )
428414 {
429- Common . PromptSaveDataGridView ( ref dgv ) ;
415+ dgv . ExportToExcel ( ) ;
430416 }
431417
432418 private void TxtSearch_TextChanged ( object sender , EventArgs e )
@@ -438,7 +424,24 @@ private void TxtSearch_TextChanged(object sender, EventArgs e)
438424
439425 private void TmrSearch_Tick ( object sender , EventArgs e )
440426 {
441- SetDataSourceWithFilter ( ) ;
427+ if ( string . IsNullOrEmpty ( txtSearch . Text . Trim ( ) ) )
428+ {
429+ dgv . ClearFilter ( ) ;
430+ lblSearch . Font = new Font ( lblSearch . Font , FontStyle . Regular ) ;
431+ }
432+ else
433+ {
434+ lblSearch . Font = new Font ( lblSearch . Font , FontStyle . Bold ) ;
435+ try
436+ {
437+ dgv . SetFilter ( $ "([SchemaName] LIKE '%{ 0 } %' OR [ObjectName] LIKE '%{ txtSearch . Text . SqlSingleQuote ( ) } %'\n )") ;
438+ }
439+ catch ( Exception ex )
440+ {
441+ MessageBox . Show ( ex . Message , "Filter Error" , MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
442+ dgv . DataSource = new DataView ( dt , null , "total_duration_sec DESC" , DataViewRowState . CurrentRows ) ;
443+ }
444+ }
442445 tmrSearch . Enabled = false ;
443446 }
444447
0 commit comments