File: ModelDataSource.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (162 lines) | stat: -rw-r--r-- 5,197 bytes parent folder | download | duplicates (7)
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
//------------------------------------------------------------------------------
// <copyright file="ModelDataSource.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

namespace System.Web.UI.WebControls {

    using System;
    using System.Collections;
    using System.Web.UI;


    /// <summary>
    /// The data source used by DataBoundControls like GridView/FormView to support data methods
    /// to perform the Delete, Insert, Select, and Update operations. 
    /// </summary>
    public class ModelDataSource : IDataSource, IStateManager {

        internal const string DefaultViewName = "DefaultView";
        private ModelDataSourceView _view;
        private ICollection _viewNames;
        private EventHandler DataSourceChanged;

        public ModelDataSource(Control dataControl) {
            if (dataControl == null) {
                throw new ArgumentNullException("dataControl");
            }
            DataControl = dataControl;
        }

        /// <summary>
        /// Updates the required properties for the one way data binding to work.
        /// </summary>
        public void UpdateProperties(string modelTypeName, string selectMethod) {
            UpdateProperties(modelTypeName, selectMethod, String.Empty, String.Empty, String.Empty, String.Empty);
        }

        /// <summary>
        /// Updates the required properties for the two way data binding to work.
        /// </summary>
        public void UpdateProperties(string modelTypeName, string selectMethod, string updateMethod, string insertMethod, string deleteMethod, string dataKeyName) {
            View.UpdateProperties(modelTypeName, selectMethod, updateMethod, insertMethod, deleteMethod, dataKeyName);
        }

        /// <summary>
        /// Control for which this is an internal data source to support the data methods for data operations.
        /// </summary>
        public Control DataControl {
            get;
            private set;
        }

        public event CallingDataMethodsEventHandler CallingDataMethods {
            add {
                View.CallingDataMethods += value;
            }
            remove {
                View.CallingDataMethods -= value;
            }
        }

        /// <summary>
        /// The default (and only) ModelDataSourceView for this ModelDataSource.
        /// Subclasses can override this method to return a different ModelDataSourceView.
        /// </summary>
        public virtual ModelDataSourceView View {
            get {
                if (_view == null) {
                    _view = new ModelDataSourceView(this);
                }

                return _view;
            }
        }

        protected virtual bool IsTrackingViewState() {
            return ((IStateManager)View).IsTrackingViewState;
        }

        protected virtual void LoadViewState(object savedState) {
            ((IStateManager)View).LoadViewState(savedState);
        }

        protected virtual object SaveViewState() {
            return ((IStateManager)View).SaveViewState();
        }

        protected virtual void TrackViewState() {
            ((IStateManager)View).TrackViewState();
        }

        /// <devdoc>
        /// Gets the view associated with this data source.
        /// </devdoc>
        private DataSourceView GetView(string viewName) {
            //Ignore the input viewName as there is only a single view.
            return View;
        }


        /// <devdoc>
        /// </devdoc>
        private ICollection GetViewNames() {
            if (_viewNames == null) {
                _viewNames = new string[1] { DefaultViewName };
            }
            return _viewNames;
        }
        
        #region Implementation of IDataSource
        /// <summary>
        ///   Raised when the underlying data source has changed. The
        ///   change may be due to a change in the control's properties,
        ///   or a change in the data due to an edit action performed by
        ///   the DataSourceControl.
        /// </summary>
        event EventHandler IDataSource.DataSourceChanged {
            add {
                DataSourceChanged += value;
            }
            remove {
                DataSourceChanged -= value;
            }
        }


        /// <internalonly/>
        DataSourceView IDataSource.GetView(string viewName) {
            return GetView(viewName);
        }


        /// <internalonly/>
        ICollection IDataSource.GetViewNames() {
            return GetViewNames();
        }
        #endregion

        #region Implementation of IStateManager

        bool IStateManager.IsTrackingViewState {
            get {
                return IsTrackingViewState();
            }
        }

        void IStateManager.LoadViewState(object savedState) {
            LoadViewState(savedState);
        }

        object IStateManager.SaveViewState() {
            return SaveViewState();
        }

        void IStateManager.TrackViewState() {
            TrackViewState();
        }
        #endregion
    }
}