forked from webgrid/WebGrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GridServerEvents.cs
1269 lines (1098 loc) · 49.4 KB
/
GridServerEvents.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright © Olav Christian Botterli.
Dual licensed under the MIT or GPL Version 2 licenses.
Date: 30.08.2011, Norway.
http://www.webgrid.com
*/
#region Header
/*
Copyright © Olav Christian Botterli.
Dual licensed under the MIT or GPL Version 2 licenses.
Date: 30.08.2011, Norway.
http://www.webgrid.com
*/
#endregion Header
namespace WebGrid
{
using System;
using System.ComponentModel;
using System.Text;
using System.Web;
using Data;
using Design;
using Enums;
using Events;
using Util;
using Data.Database;
public partial class Grid
{
#region Fields
/// <summary>
/// indicates creates a new record and using an already existing record in the data source as template.
/// </summary>
internal bool m_IsCopyClick;
private bool m_DoExcelExport;
private bool? m_GetColumnsPostBackData;
/// <summary>
/// indicates if one record has been deleted from data source successfully. (Only true when no error message generated)
/// </summary>
private bool m_IsRecordDelete;
/// <summary>
/// indicates if one record has been inserted into data source successfully. (Only true when no error message generated)
/// </summary>
private bool m_IsRecordNew;
/// <summary>
/// indicates if one record has been updated successfully. (Only true when no error message generated)
/// </summary>
private bool m_IsRecordUpdate;
/// <summary>
/// indicates if records has been updated in grid view without generating any error messages.
/// </summary>
private bool m_IsRecordUpdateRows;
/// <summary>
/// indicates editIndex should reset, required when updating one record in a row.
/// </summary>
private bool m_ResetEditIndex;
/// <summary>
/// indicates if one record has been updated in grid view.
/// </summary>
private string[] m_UpdateRow;
//Rows skipped when using ranged slider.
private int RangedSliderRowLoad;
//Rows skipped when grouping rows.
internal int GroupRowsLoad;
#endregion Fields
#region Events
/// <summary>
/// Event is raised after row delete.
/// </summary>
[Category("Data"),
Description(@"Event is raised after row delete.")]
public event AfterDeleteEventHandler AfterDelete;
/// <summary>
/// Event is raised after WebGrid has finished rendering rows, applies to grid view.
/// </summary>
[Category("Data"),
Description(@"Event is raised after WebGrid has finished rendering rows, applies to grid view.")]
public event AfterRowsEventHandler AfterRows;
/// <summary>
/// Event is raised after row update, applies to grid and detail view.
/// </summary>
[Category("Data"),
Description(@"Event is raised after row update, applies to grid and detail view.")]
public event AfterUpdateInsertEventHandler AfterUpdateInsert;
/// <summary>
/// Event is raised before row delete.
/// </summary>
[Category("Data"),
Description(@"Event is raised before row delete.")]
public event BeforeDeleteEventHandler BeforeDelete;
/// <summary>
/// Event is raised when WebGrid needs data.
/// </summary>
[Category("Data"),
Description(@"Event is raised when WebGrid needs data.")]
public event NeedDataHandler BeforeGetData;
/// <summary>
/// Event is raised before a row is being rendered.
/// </summary>
[Category("Data"),
Description(@"Event is raised before a row is being rendered.")]
public event BeforeRowRenderHandler BeforeRowRender;
/// <summary>
/// Event is raised before WebGrid starts rendering rows, applies to grid view.
/// </summary>
[Category("Data"),
Description(@"Event is raised before WebGrid starts rendering rows, applies to grid view.")]
public event BeforeRowsEventHandler BeforeRows;
/// <summary>
/// Event is raised before record insert/update, applies to grid and detail view.
/// </summary>
[Category("Data"),
Description(@"Event is raised before record insert/update, applies to grid and detail view.")]
public event BeforeUpdateInsertEventHandler BeforeUpdateInsert;
/// <summary>
/// Event is raised before row is validated for insert and update, applies to grid and detail view.
/// </summary>
[Category("Data"),
Description(@"Event is raised before row is validated, applies to grid and detail view.")]
public event BeforeValidateEventHandler BeforeValidate;
/// <summary>
/// Event is raised when column is post back in grid view.
/// </summary>
[Category("Data"),
Description(@"Event is raised when column is post back in grid view.")]
public event ColumnPostBackEventHandler ColumnPostBack;
/// <summary>
/// Event is raised when Grid has completed it's task. Applies to grid and detail view.
/// </summary>
[Category("Data"),
Description(@"Event is raised when WebGrid has completed it's task. Applies to grid and detail view.")]
public event DoneEventHandler Complete;
/// <summary>
/// Event is raised when copy row button is clicked in grid view.
/// </summary>
[Category("Data"),
Description(@"Event is raised when copy row button is clicked in grid view.")]
public event CopyRowEventHandler CopyRow;
/// <summary>
/// Event is raised when edit row button is clicked in grid view.
/// </summary>
[Category("Data"),
Description(@"Event is raised when edit row button is clicked in grid view.")]
public event EditRowEventHandler EditRow;
/// <summary>
/// Event is raised when export to excel button is clicked in grid view.
/// </summary>
[Category("Action"),
Description(@"Event is raised when export to excel button is clicked in grid view.")]
public event ExportClickEventHandler ExportClick;
/// <summary>
/// Event is raised when column is post back in grid view.
/// </summary>
[Category("Action"),
Description(@"Event is raised if any grid post back happens.")]
public event GridPostBackEventHandler GridPostBack;
/// <summary>
/// Event is raised for each row in grid view.
/// </summary>
[Category("Data"),
Description(@"Event is raised when a WebGrid row is bound against the data source.")]
public event GridRowBoundEventHandler GridRowBound;
/// <summary>
/// Event is raised for each row in grid view.
/// </summary>
[Category("Data"),
Description(@"Event is raised when a WebGrid row is bound against the data source.")]
public event RowGroupingEventHandler RowGrouping;
/// <summary>
/// Event is raised when header title (used by sorting) in grid view is clicked.
/// </summary>
[Category("Action"),
Description(@"Event is raised when header title (used by sorting) in grid view is clicked.")]
public event HeaderClickEventHandler HeaderClick;
/// <summary>
/// Event is raised when New Record is clicked in grid view.
/// </summary>
[Category("Action"),
Description(@"Event is raised when New Record is clicked in grid view.")]
public event NewRecordClickEventHandler NewRecordClick;
/// <summary>
/// Event is raised when pager is clicked in grid view.
/// </summary>
[Category("Action"),
Description(@"Event is raised when navigation pager is clicked in grid view")]
public event PagerClickEventHandler PagerClick;
// CLICK Edit
/// <summary>
/// Event is raised when Cancel button is clicked in detail view.
/// </summary>
[Category("Action"),
Description(@"Event is raised when Cancel button is clicked in detail view.")]
public event CancelClickEventHandler RecordCancelClick;
/// <summary>
/// Event is raised when Delete button is clicked in grid view.
/// </summary>
[Category("Action"),
Description(@"Event is raised when Delete button is clicked in grid view.")]
public event DeleteClickEventHandler RecordDeleteClick;
/// <summary>
/// Event is raised when Update button is clicked in detail view.
/// </summary>
[Category("Action"),
Description(@"Event is raised when Update button is clicked in detail view.")]
public event UpdateClickEventHandler RecordUpdateClick;
/// <summary>
/// Event is raised when row in grid view is clicked. ('UpdateRow' SystemColumn)
/// </summary>
[Category("Action"),
Description(@"Event is raised when row in grid view is clicked.")]
public event RowClickEventHandler RowClick;
/// <summary>
/// Event is raised when Search text has changed in grid view.
/// </summary>
[Category("Data"),
Description(@"Event is raised when Search text has changed in grid view.")]
public event SearchChangedEventHandler SearchChanged;
/// <summary>
/// Event is raised when 'Update row' is clicked in grid view.
/// </summary>
[Category("Action"),
Description(@"Event is raised when 'Update row' is clicked in grid view.")]
public event UpdateRowClickEventHandler UpdateRowClick;
// 16.10.2004, Jorn
/// <summary>
/// Event is raised when 'Update rows' is clicked in grid view (in toolbars).
/// </summary>
[Category("Action"),
Description(@"Event is raised when 'Update rows' is clicked in grid view.")]
public event UpdateRowsClickEventHandler UpdateRowsClick;
#endregion Events
#region Methods
/// <summary>
/// Adds a Row object to the grid row collection.
/// </summary>
/// <param name="row">The row to be added.</param>
/// <returns>
/// The Row that has been added to the grid row collection.
/// </returns>
public void AddRow(Row row)
{
MasterTable.Rows.Add(row);
}
/// <summary>
/// Creates the text button.
/// </summary>
/// <param name="displayText">The display text.</param>
/// <param name="eventName">Name of the event.</param>
/// <param name="arguments">The arguments.</param>
/// <param name="cssClass">The CSS class.</param>
/// <param name="confirmText">The confirm text.</param>
/// <returns></returns>
public string CreateTextButton(string displayText, string eventName, string[] arguments, string cssClass,
string confirmText)
{
return Buttons.TextButton(this, displayText, eventName, arguments, cssClass, confirmText);
}
/// <summary>
/// When implemented by a class, enables a server control to process an event raised when a form is posted to the server.
/// </summary>
/// <param name="eventArgument">A <see cref="T:System.String"></see> that represents an optional event argument to be passed to the event handler.</param>
/// <remarks>
/// Supported eventarguments are:
///
/// UpdateRowsClick, UpdateRowClick, RecordClick, RecordCopyClick, ExcelExportClick, CollapseGridClick, CollapseGridClick, ColumnHeaderClick
/// SlaveGridClick, RecordUpdateClick, RecordCancelClick, NewRecordClick, PagerClick, RecordDeleteClick, ElementPostBack. For further examples how to use these please
/// see WebGrid starter kit.
/// </remarks>
public void RaisePostBackEvent(string eventArgument)
{
// 16.10.2004, jorn - Added UpdateRowsClick, added support for autosave.
if (string.IsNullOrEmpty(eventArgument))
return;
if (EnableCallBack)
{
eventArgument = HttpUtility.UrlDecode(eventArgument, Encoding.Default);
eventArgument = eventArgument.Replace("%27", "'");
}
string[] eventArgs = eventArgument.Split('!');
// ColumnId of the event
string postBackEvent = eventArgs[0];
// If RaisePostBackEvent is raised programatically.
m_EventRanInit = true;
if (GridPostBack != null)
{
GridPostBackEventArgs ea = new GridPostBackEventArgs {EventName = postBackEvent};
ea.SetEventArguments(eventArgs);
GridPostBack(this, ea);
}
if (Trace.IsTracing)
Trace.Trace("{0} : Start CreatePostBackvent() Event: {1} Args length:{2}", ID, postBackEvent,
eventArgs.Length);
if (Debug)
m_DebugString.AppendFormat("<b>{0}: Post back-event '{1}' has value array '{2}'</b><br/>", ID,
postBackEvent, eventArgument);
postBackEvent = postBackEvent.ToLowerInvariant();
switch (postBackEvent)
{
case "refresh":
{
if (PagerSettings.PagerType == PagerType.Slider || PagerSettings.PagerType == PagerType.RangedSlider)
PagerSettings.updateSliderValues();
break;
}
case "columnpushup":
{
PushRowUp(eventArgs);
break;
}
case "columnpushdown":
{
PushRowDown(eventArgs);
break;
}
case "updaterowsclick":
{
m_IsRecordUpdateRows = true;
m_GetColumnsPostBackData = true;
break;
}
case "updaterowclick":
{
if (InternalId == null)
{
InternalId = eventArgs[1];
m_ResetEditIndex = true;
}
m_UpdateRow = eventArgs;
m_GetColumnsPostBackData = true;
break;
}
case "recordclick":
{
RecordClick(eventArgs);
break;
}
case "groupclick":
{
GroupClick(eventArgs);
break;
}
case "recordcopyclick":
{
m_IsCopyClick = true;
CopyRecordClick(eventArgs);
break;
}
case "excelexportclick":
{
ExcelExportClick();
break;
}
case "collapsegridclick":
{
CollapseGridClick();
break;
}
case "columnheaderclick":
{
ColumnHeaderClick(eventArgs);
break;
}
case "slavegridclick":
{
SlaveGridClick(eventArgs);
break;
}
case "recordupdateclick":
{
m_GetColumnsPostBackData = true;
RecordUpdateClickEvent(eventArgs);
break;
}
case "recordcancelclick":
{
RecordCancelClickEvent(eventArgs);
break;
}
case "newrecordclick":
{
NewRecordClickEvent();
break;
}
case "pagerclick":
{
PagerClickEvent(eventArgs);
break;
}
case "recorddeleteclick":
{
RecordDeleteClickEvent(eventArgs);
ReLoadData = true;
break;
}
case "elementpostback":
{
m_GetColumnsPostBackData = true;
ColumnPostBackEvent(eventArgs);
break;
}
case "searchclick":
{
UpdateGridSearch();
break;
}
}
if (Trace.IsTracing)
Trace.Trace("{0} : Finish CreatePostBackvent()", ClientID);
}
internal bool AddRow(ref Row row)
{
if (PagerSettings.PagerType == PagerType.RangedSlider && PagerSettings != null &&
(PagerSettings.GetSliderValues != null &&
(PagerSettings.GetSliderValues.Length == 2 &&
(PagerSettings.GetSliderValues[0] > row.RowIndex + RangedSliderRowLoad ||
PagerSettings.GetSliderValues[1] < row.RowIndex))))
{
RangedSliderRowLoad++;
return false;
}
if (DisplayView == DisplayView.Grid)
{
#region Grouping
if (!string.IsNullOrEmpty(GroupByExpression))
{
string[] columnGroups = GroupByExpression.Split(',');
int displayIndex = -10;
//First group column must have lowest displayindex.
displayIndex -= (10*columnGroups.Length) + 10;
//for (int i = columnGroups.Length; i > 0; i--)
foreach (string columnGroup in columnGroups)
{
if (row[columnGroup].Value == null)
continue;
string columnGroupId = row[columnGroup].Value.ToString();
if (!GroupState.ContainsKey(columnGroup))
GroupState.Add(columnGroup, new GroupInfo());
if (columnGroupId == GroupState[columnGroup].AciveGroupValue)
continue;
GroupState[columnGroup].AciveGroupValue = columnGroupId;
if (!GroupState[columnGroup].List.ContainsKey(columnGroupId))
GroupState[columnGroup].List.Add(columnGroupId, new GroupDetails());
bool IsExpanded = GroupState[columnGroup].List[columnGroupId].IsExpanded;
Row grouprow = new Row(row.m_Table)
{
RowType = RowType.Group,
GroupColumnID = columnGroup,
GroupIsExpanded = IsExpanded
};
grouprow[columnGroup].DataSourceValue = row[columnGroup].Value;
grouprow.PrimaryKeyValues = row.PrimaryKeyValues;
grouprow[columnGroup].Value = row.Columns[columnGroup].ColumnType == ColumnType.Foreignkey
? row[columnGroup].DisplayValue
: row[columnGroup].Value;
//;+" <hr style=\"vertical-align:middle;float:right;width:99%; margin: 0;\"/>";
int cellsToSpan = 0;
int index = displayIndex;
grouprow.m_Table.Columns.ForEach(delegate(Column column)
{
if (column.DisplayIndex > index &&
(column.Visibility == Visibility.Both ||
column.Visibility == Visibility.Grid))
cellsToSpan++;
});
grouprow[columnGroup].ExtraCellSpan = cellsToSpan;
if (RowGrouping != null)
{
RowGroupingEventArgs eagroup = new RowGroupingEventArgs
{
ColumnId = columnGroup,
IsExpanded = IsExpanded,
GroupingRow = grouprow,
GroupIdentifier = row[columnGroup].Value
};
if (grouprow[columnGroup].Value != null)
eagroup.Description = grouprow[columnGroup].Value.ToString();
RowGrouping(this, eagroup);
if (eagroup.AcceptChanges)
{
IsExpanded = eagroup.IsExpanded;
grouprow = eagroup.GroupingRow;
grouprow[columnGroup].Value = eagroup.Description;
}
}
displayIndex += 10;
row.m_Table.Columns[columnGroup + "_Group"].ColumnType = ColumnType.Text;
row.m_Table.Columns[columnGroup + "_Group"].Visibility = Visibility.Grid;
row.m_Table.Columns[columnGroup + "_Group"].Title = string.Empty;
row.m_Table.Columns[columnGroup + "_Group"].DisplayIndex = displayIndex - 10;
row.m_Table.Columns[columnGroup + "_Group"].HyperLinkColumn = true;
grouprow[columnGroup + "_Group"].Value = IsExpanded ? string.Format("<span class=\"ui-icon ui-icon-triangle-1-s\"/>") : string.Format("<span class=\"ui-icon ui-icon-triangle-1-e\"/>");
GroupState[columnGroup].List[columnGroupId].IsExpanded = IsExpanded;
row.m_Table.Rows.Add(grouprow);
if (!string.IsNullOrEmpty(columnGroupId) && !IsExpanded)
{
GroupRowsLoad++;
return false;
}
}
}
#endregion
if (GridRowBound == null)
return true;
GridRowBoundEventArgs ea = new GridRowBoundEventArgs {EditIndex = row.PrimaryKeyValues, Row = row};
try
{
GridRowBound(this, ea);
if (ea.AcceptChanges)
row = ea.Row;
}
catch (Exception ee)
{
throw new GridException(
string.Format("Error in 'GridRowBound' event. (Row identifier:{0})", ea.EditIndex), ee);
}
return ea.AcceptChanges;
}
else
{
if (EditRow == null)
return true;
EditRowEventArgs ea = new EditRowEventArgs { Row = row, EditIndex = InternalId };
EditRow(this, ea);
row = ea.Row;
if (ea.AcceptChanges == false)
{
InternalId = null;
DisplayView = DisplayView.Grid;
MasterTable.GetData(true);
return true;
}
return ea.AcceptChanges;
}
}
internal void AfterDeleteEvent(string columnID)
{
// Delete has happened! :-O
if (AfterDelete != null)
{
AfterDeleteEventArgs ea = new AfterDeleteEventArgs { EditIndex = columnID };
AfterDelete(this, ea);
}
if (SystemMessage.Count == 0)
m_IsRecordDelete = true;
}
internal string AfterRowsEvent()
{
return AfterRows != null ? AfterRows(this) : null;
}
internal bool BeforeDeleteEvent(string rowId)
{
// Delete is about to happen! Return false = cancel delete
if (BeforeDelete != null)
{
BeforeDeleteEventArgs ea = new BeforeDeleteEventArgs { EditIndex = rowId, Row = MasterTable.Rows[rowId] };
BeforeDelete(this, ea);
if (ea.AcceptChanges == false) // Programmer doesn't want to delete...! :-O
return false;
}
return true;
}
internal BeforeGetDataEventArgs BeforeGetDataEvent(Table table)
{
if (BeforeGetData != null)
{
BeforeGetDataEventArgs ea = new BeforeGetDataEventArgs {Table = table};
BeforeGetData(this, ea);
return ea;
}
return null;
}
internal string BeforeRowsEvent()
{
return BeforeRows != null ? BeforeRows(this) : null;
}
internal void BeforeUpdateInsertEvent(BeforeUpdateInsertEventArgs ea)
{
if (BeforeUpdateInsert != null)
BeforeUpdateInsert(this, ea);
}
internal void BeforeValidateEvent(ref Row row)
{
if (BeforeValidate == null)
return;
BeforeValidateEventArgs ea = new BeforeValidateEventArgs { Row = row, EditIndex = InternalId };
if (Trace.IsTracing)
Trace.Trace("{0} : Launch BeforeValidate();", ID);
BeforeValidate(this, ea);
row = ea.Row;
}
private void ColumnPostBackEvent(string[] eventArguments)
{
if (ColumnPostBack == null) return;
ColumnPostBackEventArgs ea = new ColumnPostBackEventArgs
{
ColumnName = eventArguments[1],
EditIndex =
(eventArguments.Length > 2 ? eventArguments[2] : InternalId)
};
if (ea.EditIndex != null)
ea.Row = MasterTable.Rows[ea.EditIndex];
if (ea.Row == null)
ea.Row = MasterTable.Rows[0];
ColumnPostBack(this, ea);
}
private void CollapseGridClick()
{
if (ViewState["CollapseGrid"] == null || (bool)ViewState["CollapseGrid"] == false)
ViewState["CollapseGrid"] = true;
else
ViewState["CollapseGrid"] = false;
}
private void ColumnHeaderClick(string[] eventArguments)
{
// Happens when the user clicks a column title in grid-mode.
if (HeaderClick != null)
{
HeaderClickEventArgs ea = new HeaderClickEventArgs { ColumnName = eventArguments[1] };
HeaderClick(this, ea);
if (!ea.AcceptChanges) // The programmer can abort further actions.
return;
}
MasterTable.OrderByAdd = eventArguments[1];
}
private void CopyRecordClick(string[] eventArguments)
{
// Happens when the user clicks "Copy record" inside grid view.
InternalId = eventArguments[2];
Row CopiedRow = MasterTable.Rows[InternalId];
if (CopyRow != null)
{
CopyRowEventArgs ea = new CopyRowEventArgs { CopiedId = eventArguments[2], Row = CopiedRow };
CopyRow(this, ea);
if (!ea.AcceptChanges)
return;
CopiedRow = ea.Row;
}
//Set detail view
InternalId = null;
DisplayView = DisplayView.Detail;
MasterTable.GetData(true);
//Copy the row
MasterTable.Rows[0] = CopiedRow;
//Make sure we don't receive any postback data or load any data.
MasterTable.m_GotPostBackData = true;
MasterTable.m_GotData = true;
return;
}
private void ExcelExportClick()
{
if (Equals(m_DoExcelExport, true))
return;
ExcelExportClickEventArgs ea = new ExcelExportClickEventArgs { FileName = ExportFileName };
// Happens when the user clicks a link in grid-mode.
if (ExportClick != null)
{
ExportClick(this, ea);
if (ea.AcceptChanges == false) // The programmer can abort further actions.
{
return;
}
}
ExportFileName = ea.FileName;
m_DoExcelExport = true;
if (Trace.IsTracing)
Trace.Trace(string.Format("{0} : ExcelExportClick!", ID));
}
private void NewRecordClickEvent()
{
m_GetColumnsPostBackData = false;
// Happens when the user clicks "New record" inside grid view.
DisplayView oldMode = DisplayView;
string oldEditIndex = InternalId;
DisplayView = DisplayView.Detail;
InternalId = null;
MasterTable.m_GotData = false;
if (NewRecordClick == null) return;
NewRecordClickEventArgs ea = new NewRecordClickEventArgs();
NewRecordClick(this, ea);
if (ea.AcceptChanges) return;
DisplayView = oldMode;
InternalId = oldEditIndex;
return;
}
private void PagerClickEvent(string[] eventArguments)
{
int newPage;
if (eventArguments[1].Equals("all", StringComparison.OrdinalIgnoreCase))
newPage = 0;
else
{
if (!int.TryParse(eventArguments[1], out newPage))
throw new GridException(
string.Format(
"Failed on 'PagerClick' event. Excepted number value as second eventArgument, got: {0}",
eventArguments[1]));
newPage = int.Parse(eventArguments[1]);
if (newPage < 1) newPage = 1;
}
// Happens when the user clicks on the pager thingy
if (PagerClick != null)
{
PagerClickEventArgs ea = new PagerClickEventArgs
{
OldCurrentPage = PageIndex,
NewCurrentPage = newPage
};
PagerClick(this, ea);
if (ea.AcceptChanges == false) // The programmer can abort further actions.
return;
newPage = ea.NewCurrentPage;
}
if (PagerSettings.PagerType == PagerType.Slider)
PagerSettings.SliderValue = newPage.ToString();
PageIndex = newPage;
}
private void PushRowDown(string[] eventArgs)
{
if (eventArgs.Length != 6)
throw new GridException(
string.Format("Invalid number of parameters for PushRowDown method, excepted 7 arguments was {0}.",
eventArgs.Length));
string columnId = eventArgs[3];
string orginalrowId = eventArgs[1];
string swaprowId = eventArgs[2];
int orgValue, swapValue;
bool res = int.TryParse(eventArgs[4], out orgValue);
if (!res)
{
SystemMessage.Add(string.Format("Unable to parse orginal values from '{0}' column (Value:'{1}').",
Columns[columnId].Title, eventArgs[4]));
return;
}
res = int.TryParse(eventArgs[5], out swapValue);
if (!res)
{
SystemMessage.Add(string.Format("Unable to parse orginal values from '{0}' column (Value:'{1}').",
Columns[columnId].Title, eventArgs[5]));
return;
}
if (orgValue == swapValue)
orgValue -= 1;
MasterTable.Rows[orginalrowId][columnId].Value = swapValue;
MasterTable.Rows[swaprowId][columnId].Value = orgValue;
res = MasterTable.InsertUpdate(ref orginalrowId, MasterTable.Rows[orginalrowId]);
if (!res)
SystemMessage.Add("Failed to push rows down 1.");
MasterTable.InsertUpdate(ref swaprowId, MasterTable.Rows[swaprowId]);
if (!res)
SystemMessage.Add("Failed to push rows down 2.");
ReLoadData = true;
}
private void PushRowUp(string[] eventArgs)
{
if (eventArgs.Length != 6)
throw new GridException(
string.Format("Invalid number of parameters for PushRowDown method, excepted 7 arguments was {0}.",
eventArgs.Length));
string columnId = eventArgs[3];
string orginalrowId = eventArgs[1];
string swaprowId = eventArgs[2];
int orgValue, swapValue;
bool res = int.TryParse(eventArgs[4], out orgValue);
if (!res)
{
SystemMessage.Add(string.Format("Unable to parse orginal values from '{0}' column (Value:'{1}').",
Columns[columnId].Title, eventArgs[4]));
return;
}
res = int.TryParse(eventArgs[5], out swapValue);
if (!res)
{
SystemMessage.Add(string.Format("Unable to parse orginal values from '{0}' column (Value:'{1}').",
Columns[columnId].Title, eventArgs[5]));
return;
}
if (orgValue == swapValue)
orgValue += 1;
MasterTable[orginalrowId][columnId].Value = swapValue;
MasterTable[swaprowId][columnId].Value = orgValue;
res = MasterTable.InsertUpdate(ref orginalrowId, MasterTable.Rows[orginalrowId]);
if (!res)
SystemMessage.Add("Failed to push row up");
MasterTable.InsertUpdate(ref swaprowId, MasterTable.Rows[swaprowId]);
if (!res)
SystemMessage.Add("Failed to push row down");
ReLoadData = true;
}
private void RecordCancelClickEvent(string[] eventArguments)
{
// Happens when the user clicks a "CANCELWINDOW" inside detail view.
if (RecordCancelClick != null)
{
CancelClickEventArgs ea = new CancelClickEventArgs {EditIndex = eventArguments[1]};
RecordCancelClick(this, ea);
if (ea.AcceptChanges == false) // The programmer can abort further actions.
return;
}
MasterTable.Cancel();
if (((
m_MasterWebGrid != null && m_MasterWebGrid.ActiveMenuSlaveGrid == this &&
string.IsNullOrEmpty(eventArguments[1]) && DisplayView == DisplayView.Grid)
|| AllowCancel == false ||
(eventArguments.Length > 2 &&
Equals(eventArguments[2].Equals("true", StringComparison.OrdinalIgnoreCase), true))) &&
m_MasterWebGrid != null)
m_MasterWebGrid.ActiveMenuSlaveGrid = null;
// else
// {
EditIndex = null;
MasterTable.m_GotData = false;
DisplayView = DisplayView.Grid;
// }
}
private void GroupClick(string[] eventArguments)
{
/*
1:GroupColumnID
2:DataSourceValue
3:PrimaryKeyValues
4:IsExpanded
*/
string columnGroup = eventArguments[1];
string columnGroupId = eventArguments[2];
string columnKeys = eventArguments[3];
bool IsExpanded = !(eventArguments[4].ToLower() == "true" || eventArguments[4].ToLower() == "1");
if (!GroupState.ContainsKey(columnGroup))
GroupState.Add(columnGroup, new GroupInfo());
if (!GroupState[columnGroup].List.ContainsKey(columnGroupId))
GroupState[columnGroup].List.Add(columnGroupId, new GroupDetails());
GroupState[columnGroup].List[columnGroupId].IsExpanded = IsExpanded;
if (!GroupState[columnGroup].List[columnGroupId].IsExpanded)
{
string t = Interface.BuildFilterElement(true, DataSourceId, MasterTable.Columns[columnGroup], columnGroupId
);
t = t.Replace(" = ", " <> ");
GroupState[columnGroup].List[columnGroupId].GroupSqlFilter = string.Format("({0} OR {1})", t,
Interface.BuildPKFilter(MasterTable,columnKeys
,
true));
}
else
GroupState[columnGroup].List[columnGroupId].GroupSqlFilter = null;
}
private void RecordClick(string[] eventArguments)
{
DisplayView oldMode = DisplayView;
string oldEditIndex = InternalId;
DisplayView = DisplayView.Detail;
MasterTable.m_GotPostBackData = true;
MasterTable.m_GotData = false;
InternalId = eventArguments[2];
// Happens when the user clicks a link in grid-mode.
if (RowClick != null)
{
RowClickEventArgs ea = new RowClickEventArgs
{
ColumnName = eventArguments[1],
EditIndex = eventArguments[2],
Row = MasterTable.Rows[InternalId]
};
if (ea.Row == null)
return;// throw new GridException("Row was not found.");
RowClick(this, ea);
if (ea.AcceptChanges == false) // The programmer can abort further actions.
{