Beispiel #1
0
        /// <summary>
        /// Create and populate a DataView using the specified view. The object type is automatically
        /// determined from the contents of the data parameter (which must not be null or empty).
        /// </summary>
        /// <param name="viewName">The name of the view</param>
        /// <param name="data">The list of objects to include in the view</param>
        /// <returns>The new DataView instance</returns>
        public static DataView GetDataView(string viewName, IList data)
        {
            Check.Verify(data != null && data.Count > 0, Error.NullParameter, "data");
            Type type = data[0].GetType();
            // construct the named view for the type found in the supplied data
            ObjectView view = GetObjectView(type, viewName);

            return(view.PopulateDataView(data));
        }
Beispiel #2
0
        private static ObjectView GetObjectView(PersistenceBroker broker, Type type, string viewName)
        {
            ObjectMap map = ObjectFactory.GetMap(broker, type);

            Check.VerifyNotNull(viewName, Error.NullParameter, "viewName");
            ObjectView view = map.Views[viewName] as ObjectView;

            Check.VerifyNotNull(view, Error.NoSuchView, viewName, type);
            return(view);
        }
Beispiel #3
0
        /// <summary>
        /// Create and populate a DataView with the given name. Use this method when you need
        /// to specify the object type manually (which is the case when the view is specified
        /// on a base class and the list may contain various subclasses).
        /// </summary>
        /// <param name="type">The type associated with the given view name</param>
        /// <param name="viewName">The name of the view</param>
        /// <param name="data">The list of objects to include in the view</param>
        /// <returns>The new DataView instance</returns>
        public static DataView GetDataView(Type type, string viewName, IList data)
        {
            if (type == null)
            {
                type = data[0].GetType();
            }
            // construct the named view for the type found in the supplied data
            ObjectView view = GetObjectView(type, viewName);

            return(view.PopulateDataView(data));
        }
Beispiel #4
0
 /// <summary>
 /// Obtain a DataTable for the specified type using the "default" view.
 /// </summary>
 /// <returns>The new DataTable instance</returns>
 public static DataTable GetDataTable(Type type)
 {
     try
     {
         ObjectView view = GetObjectView(type, "default");
         return(view.GetDataTable());
     }
     catch (Exception e)
     {
         Check.Fail(e, Error.ViewError, "default", type);
         throw;
     }
 }
Beispiel #5
0
 /// <summary>
 /// Obtain a DataTable for the specified type and view.
 /// </summary>
 /// <returns>The new DataTable instance</returns>
 public static DataTable GetDataTable(Type type, string viewName)
 {
     try
     {
         ObjectView view = GetObjectView(type, viewName);
         return(view.GetDataTable());
     }
     catch (Exception e)
     {
         Check.Fail(e, Error.ViewError, viewName, type);
         throw;
     }
 }
Beispiel #6
0
        /// <summary>
        /// Adds a column to the specified named DataView. The ViewMap is a small helper class
        /// used to connect DataView columns with object properties.
        /// </summary>
        /// <param name="viewName">The name of the DataView</param>
        /// <param name="viewMap">The ViewMap instance to add to this view</param>
        public void AddViewColumn(string viewName, ViewMap viewMap)
        {
            ObjectView view;

            if (!views.ContainsKey(viewName))
            {
                view            = new ObjectView(this, viewName);
                views[viewName] = view;
            }
            else
            {
                view = (ObjectView)views[viewName];
            }
            view.AddColumn(viewMap);
        }
Beispiel #7
0
        public static void PopulateDataGrid(Type type, DataGrid dg, string viewName, IList data, string linkFieldName)
        {
            if (type == null)
            {
                type = data[0].GetType();
            }
            ObjectView ov = GetObjectView(type, viewName);

            dg.AutoGenerateColumns = false;
            dg.Columns.Clear();
            foreach (DataGridColumn column in ov.GetGridColumns(linkFieldName))
            {
                dg.Columns.Add(column);
            }
            dg.DataSource = data;
            dg.DataBind();
        }
Beispiel #8
0
		/// <summary>
		/// Adds a column to the specified named DataView. The ViewMap is a small helper class
		/// used to connect DataView columns with object properties.
		/// </summary>
		/// <param name="viewName">The name of the DataView</param>
		/// <param name="viewMap">The ViewMap instance to add to this view</param>
		public void AddViewColumn( string viewName, ViewMap viewMap )
		{
			ObjectView view;
			if( ! views.ContainsKey( viewName ) )
			{
				view = new ObjectView( this, viewName );
				views[ viewName ] = view;
			}
			else
			{
				view = (ObjectView) views[ viewName ];
			}
			view.AddColumn( viewMap );
		}