LookupAdapter.cs
上传用户:husern
上传日期:2022-03-24
资源大小:534k
文件大小:2k
- // -- FILE ------------------------------------------------------------------
- // name : LookupAdapter.cs
- // project : Itenso Web User Forms
- // created : Jani Giannoudis - 2008.10.30
- // language : c#
- // environment: .NET 2.0
- // copyright : (c) 2008 by Itenso GmbH, Switzerland
- // --------------------------------------------------------------------------
- using System;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Collections.Generic;
- using Itenso.WebUserForms.Controls;
- using Itenso.WebUserForms.Data.Lookup;
- namespace Itenso.WebUserForms.Runtime
- {
- // ------------------------------------------------------------------------
- public sealed class LookupAdapter
- {
- // ----------------------------------------------------------------------
- private LookupAdapter()
- {
- } // LookupAdapter
- // ----------------------------------------------------------------------
- public static void Apply( ILookupProvider lookupProvider, UserControl userForm )
- {
- if ( lookupProvider == null )
- {
- throw new ArgumentNullException( "lookupProvider" );
- }
- if ( userForm == null )
- {
- throw new ArgumentNullException( "userForm" );
- }
- LookupFieldCollector lookupFieldCollector = new LookupFieldCollector( userForm );
- lookupFieldCollector.Collect();
- foreach ( ILookupField lookupField in lookupFieldCollector.LookupFields )
- {
- lookupField.Items.Clear();
- ILookupValueCollection lookupValues = lookupProvider.GetLookup( lookupField.LookupName, null );
- if ( lookupValues == null )
- {
- continue;
- }
- Apply( lookupValues, lookupField );
- }
- } // Apply
- // ----------------------------------------------------------------------
- private static void Apply( ILookupValueCollection lookupValues, ILookupField lookupField )
- {
- if ( lookupValues == null )
- {
- throw new ArgumentNullException( "lookupValues" );
- }
- if ( lookupField == null )
- {
- throw new ArgumentNullException( "lookupField" );
- }
- lookupField.Items.Clear();
- foreach ( ILookupValue lookupValue in lookupValues )
- {
- lookupField.Items.Add( new ListItem( lookupValue.Value.ToString(), lookupValue.Key ) );
- }
- if ( lookupField.Items.Count > 0 )
- {
- lookupField.Items[ 0 ].Selected = true;
- }
- } // Apply
- } // class LookupAdapter
- } // namespace Itenso.WebUserForms.Runtime
- // -- EOF -------------------------------------------------------------------