Example #1
0
        /// <summary>
        /// Register a data control to give it Dynamic Data behavior
        /// </summary>
        /// <param name="setSelectionFromUrl">When true, if a primary key is found in the route values
        ///     (typically on the query string), it will get be set as the selected item. This only applies
        ///     to list controls.</param>
        public void RegisterControl(Control control, bool setSelectionFromUrl)
        {
            //
            if (DesignMode)
            {
                return;
            }

            IDataBoundControlInterface dataBoundControl = DataControlHelper.GetDataBoundControl(control, true /*failIfNotFound*/);

            // If we can't get an associated IDynamicDataSource, don't do anything
            IDynamicDataSource dataSource = dataBoundControl.DataSourceObject as IDynamicDataSource;

            if (dataSource == null)
            {
                return;
            }
            // If we can't get a MetaTable from the data source, don't do anything
            MetaTable table = MetaTableHelper.GetTableWithFullFallback(dataSource, Context.ToWrapper());

            // Save the datasource so we can process its parameters in OnLoad. The value we set is irrelevant
            _dataSources[dataSource] = null;

            ((INamingContainer)control).SetMetaTable(table);

            BaseDataBoundControl baseDataBoundControl = control as BaseDataBoundControl;

            if (baseDataBoundControl != null)
            {
                EnablePersistedSelection(baseDataBoundControl, table);
            }

            RegisterControlInternal(dataBoundControl, dataSource, table, setSelectionFromUrl, Page.IsPostBack);
        }
Example #2
0
        private static void BindData(Control ctrl, object source)
        {
            // ListControl & GridView
            BaseDataBoundControl bc = ctrl as BaseDataBoundControl;

            if (bc != null)
            {
                bc.DataSource = source;
                bc.DataBind();
                return;
            }

            Repeater r = ctrl as Repeater;

            if (r != null)
            {
                r.DataSource = source;
                r.DataBind();
                return;
            }

            DataList dl = ctrl as DataList;

            if (dl != null)
            {
                dl.DataSource = source;
                dl.DataBind();
                return;
            }

            throw new NotSupportedException(string.Format("Type={0} ID={1}", ctrl.GetType().Name, ctrl.ID));
        }
Example #3
0
 /// <summary>
 /// bind cycle count level to DataBoundControl
 /// </summary>
 /// <param name="dataControl"></param>
 public void BindCycleCountLevel(BaseDataBoundControl dataControl)
 {
     if (dataControl is ListControl)
     {
         ListControl control = (ListControl)dataControl;
         BindListControl(control, "LevelID", "LevelName");
     }
     BindDataControl(dataControl, this.CycleCountLevels);
 }
 public void Bind <TSource>(IEnumerable <TSource> source, BaseDataBoundControl control)  where TSource : ViewBase
 {
     if (control == null)
     {
         throw new InvalidOperationException("Some of controls are null, Binding impossible. ");
     }
     control.DataSource = source;
     control.DataBind();
 }
Example #5
0
 /// <summary>
 /// bind plants to DataBoundControl
 /// </summary>
 /// <param name="dataControl"></param>
 public void BindPlants(BaseDataBoundControl dataControl, bool addEmptyItem)
 {
     if (dataControl is ListControl)
     {
         ListControl control = (ListControl)dataControl;
         BindListControl(control, "PlantID", "PlantCode");
     }
     BindDataControl(dataControl, this.Plants, addEmptyItem);
 }
Example #6
0
 /// <summary>
 /// bind stocktake status to DataBoundControl
 /// </summary>
 /// <param name="dataControl"></param>
 public void BindStocktakeStatus(BaseDataBoundControl dataControl, bool insertEmptyValue)
 {
     if (dataControl is ListControl)
     {
         ListControl control = (ListControl)dataControl;
         BindListControl(control, "StatusID", "StatusName");
     }
     BindDataControl(dataControl, this.StocktakeStatuses);
 }
Example #7
0
 /// <summary>
 /// bind usergroups to DataBoundControl
 /// </summary>
 /// <param name="dataControl"></param>
 public void BindUserGroup(BaseDataBoundControl dataControl)
 {
     if (dataControl is ListControl)
     {
         ListControl control = (ListControl)dataControl;
         BindListControl(control, "GroupID", "GroupName");
     }
     BindDataControl(dataControl, this.UserGroups);
 }
Example #8
0
    public static void databindcontrol(String storedproc, BaseDataBoundControl c, String webconfigconn)
    {
        String[]    paramnames = { };
        Object[]    paramvals  = { };
        int[]       paramsizes = { };
        SqlDbType[] paramtypes = { };

        databindcontrol(storedproc, paramnames, paramvals, paramtypes, paramsizes, c, webconfigconn);
    }
        private static void Fill <U, T>(U dataControl, T data)
            where U : Control
            where T : class
        {
            if (dataControl.IsNull())
            {
                return;
            }

            if (data.IsNull())
            {
                Clear <U>(dataControl);
                return;
            }

            if (SObject.IsTypeNotInList <U>(typeof(BaseDataList), typeof(Repeater), typeof(BaseDataBoundControl)))
            {
                throw new InvalidCastException("Control parameter is not valid, you are only alowed to use: BaseDataList, Repeater and BaseDataBoundControl");
            }

            if (SObject.IsTypeNotInList <T>(typeof(IListSource), typeof(IEnumerable), typeof(IDataSource)))
            {
                throw new InvalidCastException("Data parameter is not valid, you are only alowed to use: IDataSource, IEnumerable and IListSource");
            }

            try
            {
                dataControl.GetType().GetProperty("DataSource").SetValue(dataControl, data);
                dataControl.GetType().GetMethod("DataBind").Invoke(dataControl, null);
            }
            catch (Exception)
            {
                if (dataControl is BaseDataList)
                {
                    BaseDataList dl = dataControl as BaseDataList;
                    dl.DataSource = data;
                    dl.DataBind();
                }
                else if (dataControl is Repeater)
                {
                    Repeater rptr = dataControl as Repeater;
                    rptr.DataSource = data;
                    rptr.DataBind();
                }
                else if (dataControl is BaseDataBoundControl)
                {
                    BaseDataBoundControl grv = dataControl as BaseDataBoundControl;
                    grv.DataSource = data;
                    grv.DataBind();
                }
            }

            if (data is DbDataReader)
            {
                data.GetType().GetMethod("Close").Invoke(data, null);
            }
        }
Example #10
0
 protected override void DataBind(BaseDataBoundControl dataBoundControl)
 {
     System.Web.UI.WebControls.Menu menu = (System.Web.UI.WebControls.Menu)dataBoundControl;
     if (((menu.DataSourceID != null) && (menu.DataSourceID.Length > 0)) || ((menu.DataSource != null) || (menu.Items.Count == 0)))
     {
         menu.Items.Clear();
         base.DataBind(menu);
     }
 }
Example #11
0
 internal static void EnablePersistedSelection(BaseDataBoundControl baseDataBoundControl, IMetaTable table)
 {
     Debug.Assert(baseDataBoundControl != null, "NULL!");
     // Make the persisted selection sync up with the selected index if possible
     if (!table.IsReadOnly)
     {
         DynamicDataExtensions.EnablePersistedSelectionInternal(baseDataBoundControl);
     }
 }
Example #12
0
 /// <summary>
 /// bind stocktake priority to DataBoundControl
 /// </summary>
 /// <param name="dataControl"></param>
 public void BindStocktakePriority(BaseDataBoundControl dataControl, bool addEmptyItem)
 {
     if (dataControl is ListControl)
     {
         ListControl control = (ListControl)dataControl;
         BindListControl(control, "PriorityID", "PriorityName");
     }
     BindDataControl(dataControl, this.Priorities, addEmptyItem);
 }
Example #13
0
 /// <summary>
 /// bind store location type to DataBoundControl
 /// </summary>
 /// <param name="dataControl"></param>
 public void BindStoreLocationType(BaseDataBoundControl dataControl, bool addEmptyItem)
 {
     if (dataControl is ListControl)
     {
         ListControl control = (ListControl)dataControl;
         BindListControl(control, "TypeID", "TypeName");
     }
     BindDataControl(dataControl, this.StoreLocationTypes, addEmptyItem);
 }
Example #14
0
    /// <summary>
    /// bind Workshops to DataBoundControl
    /// </summary>
    /// <param name="dataControl"></param>
    /// <param name="plant"></param>
    public void BindWorkshops(BaseDataBoundControl dataControl, Plant plant, bool addEmptyItem)
    {
        if (dataControl is ListControl)
        {
            ListControl control = (ListControl)dataControl;
            BindListControl(control, "WorkshopID", "WorkshopCode");
        }
        List <Workshop> workshops = Service.GetWorkshopbyPlant(plant);

        BindDataControl(dataControl, workshops, addEmptyItem);
    }
Example #15
0
        /// <summary>
        /// Raised when the news listview is rendered. Prevents from pagination problems.
        /// </summary>
        /// <param name="sender">Element which raised the event.</param>
        /// <param name="e">Event arguments</param>
        protected void listviewConferences_PreRender(object sender, EventArgs e)
        {
            BaseDataBoundControl listView = (BaseDataBoundControl)sender;

            if (listView.Visible)
            {
                IList <Conference> conferences = _webserviceConferences.GetConferences();

                listView.DataSource = conferences;
                listView.DataBind();
            }
        }
Example #16
0
 /// <summary>
 /// Bind data to DataBoundControl
 /// </summary>
 /// <param name="dataControl"></param>
 /// <param name="dataSource"></param>
 public void BindDataControl(BaseDataBoundControl dataControl, object dataSource, bool addEmptyItem)
 {
     dataControl.DataSource = dataSource;
     dataControl.DataBind();
     if (addEmptyItem)
     {
         ListControl control = dataControl as ListControl;
         if (control != null)
         {
             control.Items.Insert(0, new ListItem(Consts.DROPDOWN_UNSELECTED_TEXT, string.Empty));
         }
     }
 }
Example #17
0
        internal static void EnablePersistedSelectionInternal(BaseDataBoundControl dataBoundControl)
        {
            IDataBoundListControl dataBoundListControl = dataBoundControl as IDataBoundListControl;

            if (dataBoundListControl != null)
            {
                dataBoundListControl.EnablePersistedSelection = true;
                //

                if (dataBoundListControl.SelectedIndex < 0)
                {
                    // Force the first item to be selected
                    dataBoundListControl.SelectedIndex = 0;
                }
            }
        }
Example #18
0
        /// <summary>
        /// 绑定数据控件
        /// </summary>
        /// <remarks>
        ///  绑定数据控件
        /// </remarks>
        private void BindDataControl()
        {
            BaseDataBoundControl boundControl = (BaseDataBoundControl)this.Page.FindControlByID(this.DataBoundControlID, true);

            if (boundControl != null)
            {
                System.Type             type             = boundControl.GetType();
                IPagerBoundControlType  pagerControlType = new PagerBoundControlType();
                PagerBoundControlStatus pbControlStatus  = pagerControlType.GetPagerBoundControl(type);

                if (pbControlStatus.DataListControlType != DataListControlType.DataGrid)
                {
                    boundControl.DataBound += new EventHandler(BoundControl_DataBound);
                    this._BoundControl      = boundControl;
                }
            }
        }
        public void Bind <TSource1, TSource2, TSource3>(IEnumerable <TSource1> source1, IEnumerable <TSource2> source2, IEnumerable <TSource3> source3,
                                                        BaseDataBoundControl control1, BaseDataBoundControl control2, BaseDataBoundControl control3)
            where TSource1 : ViewBase
            where TSource2 : ViewBase
            where TSource3 : ViewBase
        {
            if (control1 == null || control2 == null || control3 == null)
            {
                throw new InvalidOperationException("Some of controls are null, Binding impossible. ");
            }
            control1.DataSource = source1;
            control2.DataSource = source2;
            control3.DataSource = source3;

            control1.DataBind();
            control2.DataBind();
            control3.DataBind();
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="baseDataBoundControl"></param>
 /// <param name="query"></param>
 public void BindControl(BaseDataBoundControl baseDataBoundControl, string query)
 {
     try
     {
         baseDataBoundControl.DataSourceID = "";
         baseDataBoundControl.DataSource   = "";
         baseDataBoundControl.DataBind();
         Connect();
         CommandText = query;
         IDataReader rd = Command.ExecuteReader();
         if (rd.FieldCount == 0)
         {
             return;
         }
         baseDataBoundControl.DataSourceID = "";
         baseDataBoundControl.DataSource   = rd;
         if (baseDataBoundControl is ListControl && rd.FieldCount > 0)
         {
             ListControl lc = (ListControl)baseDataBoundControl;
             if (lc.DataTextField == "")
             {
                 lc.DataTextField = rd.GetName(0);
             }
             if (rd.FieldCount > 1 && lc.DataValueField == "")
             {
                 lc.DataValueField = rd.GetName(1);
             }
         }
         baseDataBoundControl.DataBind();
         rd.Close();
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     finally
     {
         if (!IsTransaction)
         {
             Disconnect();
         }
     }
 }
Example #21
0
    /// <summary>
    /// bind Segments to DataBoundControl
    /// </summary>
    /// <param name="dataControl"></param>
    /// <param name="plant"></param>
    public void BindSegments(BaseDataBoundControl dataControl, Workshop workshop, bool addEmptyItem)
    {
        if (dataControl is ListControl)
        {
            ListControl control = (ListControl)dataControl;
            BindListControl(control, "SegmentID", "SegmentCode");
        }
        List <Segment> segments;

        if (workshop == null)
        {
            segments = Service.GetSegment();
        }
        else
        {
            segments = Service.GetSegmentbyWorkshop(workshop);
        }
        BindDataControl(dataControl, segments, addEmptyItem);
    }
Example #22
0
        /// <summary>
        /// 自动调用控件的DataSource.Dispose()
        /// </summary>
        /// <param name="page"></param>
        public static void DataSouceAutoCollect(Control rootControl)
        {
            if ((rootControl is BaseDataBoundControl))
            {
                BaseDataBoundControl bdbc = (BaseDataBoundControl)rootControl;
                if ((bdbc.DataSource is IDisposable))
                {
                    IDisposable d = (IDisposable)rootControl;
                    d.Dispose();
                    bdbc.DataSource = null;
                }
            }
            if (rootControl.Controls.Count == 0)
                return;
            foreach (Control c in rootControl.Controls)
            {
                DataSouceAutoCollect(c);
            }

        }
        protected override void DataBind(BaseDataBoundControl dataBoundControl)
        {
            IEnumerable designTimeDataSource = this.GetDesignTimeDataSource();
            string      dataSourceID         = dataBoundControl.DataSourceID;
            object      dataSource           = dataBoundControl.DataSource;

            dataBoundControl.DataSource   = designTimeDataSource;
            dataBoundControl.DataSourceID = string.Empty;
            try
            {
                if (designTimeDataSource != null)
                {
                    dataBoundControl.DataBind();
                }
            }
            finally
            {
                dataBoundControl.DataSource   = dataSource;
                dataBoundControl.DataSourceID = dataSourceID;
            }
        }
Example #24
0
        protected override void DataBind(BaseDataBoundControl dataBoundControl)
        {
            IHierarchicalEnumerable designTimeDataSource = this.GetDesignTimeDataSource();
            string dataSourceID = dataBoundControl.DataSourceID;
            object dataSource   = dataBoundControl.DataSource;
            HierarchicalDataBoundControl control = (HierarchicalDataBoundControl)dataBoundControl;

            control.DataSource   = designTimeDataSource;
            control.DataSourceID = string.Empty;
            try
            {
                if (designTimeDataSource != null)
                {
                    control.DataBind();
                }
            }
            finally
            {
                control.DataSource   = dataSource;
                control.DataSourceID = dataSourceID;
            }
        }
Example #25
0
        private static void Clear <T>(T dataControl)
            where T : Control
        {
            if (SObject.IsTypeNotInList <T>(typeof(BaseDataList), typeof(Repeater), typeof(BaseDataBoundControl)))
            {
                throw new InvalidCastException("Control parameter is not valid, you are only alowed to use: BaseDataList, Repeater and BaseDataBoundControl");
            }

            object data = null;

            try
            {
                dataControl.GetType().GetProperty("DataSource").SetValue(dataControl, data);
                dataControl.GetType().GetMethod("DataBind").Invoke(dataControl, null);
            }
            catch (Exception)
            {
                if (dataControl is BaseDataList)
                {
                    BaseDataList dl = dataControl as BaseDataList;
                    dl.DataSource = data;
                    dl.DataBind();
                }
                else if (dataControl is Repeater)
                {
                    Repeater rptr = dataControl as Repeater;
                    rptr.DataSource = data;
                    rptr.DataBind();
                }
                else if (dataControl is BaseDataBoundControl)
                {
                    BaseDataBoundControl grv = dataControl as BaseDataBoundControl;
                    grv.DataSource = data;
                    grv.DataBind();
                }
            }
        }
Example #26
0
 protected abstract void DataBind(BaseDataBoundControl dataBoundControl);
Example #27
0
 private void AddAlliance(ITextControl allyId,
     ITextControl allyName,
     int type,
     BaseDataBoundControl downListAlly)
 {
     string id = allyId.Text;
     string name = allyName.Text;
     if (!Misc.IsNumber(id) || (name.Length < 1))
     {
         LabelStatus.Text = "Specify correct values...";
         return;
     }
     DataBase dataBase = new DataBase();
     if (dataBase.AddExcludedAlliance(id, name, type))
     {
         PopulateExcludedAlliances(type, downListAlly);
         ClearTextFields();
     }
     else
     {
         LabelStatus.Text = "Can't save excluded Alliance!";
     }
 }
Example #28
0
 public static void EnablePersistedSelection(this BaseDataBoundControl dataBoundControl)
 {
     EnablePersistedSelectionInternal(dataBoundControl);
 }
Example #29
0
 private void PopulateExcludedAlliances(int type,
     BaseDataBoundControl list)
 {
     const string srcTable = "ExcludedAlliances";
     DataBase dataBase = new DataBase();
     DataSet dataSet = dataBase.GetExcludedAlliances(srcTable, type);
     if (dataSet == null)
     {
         LabelStatus.Text = "Can't get list of excluded alliances!";
     }
     else
     {
         list.DataSource = dataSet.Tables[srcTable].DefaultView;
         list.DataBind();
         ClearTextFields();
     }
 }
Example #30
0
 /// <summary>
 /// bind cycle count level to DataBoundControl
 /// </summary>
 /// <param name="dataControl"></param>
 protected void BindCycleCountLevel(BaseDataBoundControl dataControl)
 {
     this.Container.BindCycleCountLevel(dataControl);
 }
Example #31
0
 public static void DataBind(this BaseDataBoundControl control, Object dataSource)
 {
     control.DataSource = dataSource;
     control.DataBind();
 }
Example #32
0
 /// <summary>
 /// bind stocktake status to DataBoundControl
 /// </summary>
 /// <param name="dataControl"></param>
 protected void BindStocktakeStatus(BaseDataBoundControl dataControl)
 {
     this.Container.BindStocktakeStatus(dataControl);
 }