コード例 #1
0
        /// <summary>
        /// Updates the check box's Checked state based on the boolean property value.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            // let the base handle everything except value change
            base.UpdateElement(change - PropertyChange.Value);
            if (property == null)
            {
                return;
            }

            bool check = property.InternalValue is bool && (bool)property.InternalValue;

            if (change.IncludesValue())
            {
                ((CheckBox)control).Checked = check;
                DataListObject list = property.GetParent() as DataListObject;
                if (list != null)
                {
                    SetControlAttribute("row", "" + list.CurrentRow);
                }
            }
            // Update property value after binding to make it in sync with the checkbox.
            // Otherwise if the checkbox stays unchecked it will not post a false value
            // and the property value will remain whatever it was, e.g. null.
            if (change == PropertyChange.All && !check)
            {
                PostedValue = "false";
            }
        }
コード例 #2
0
 /// <summary>
 /// Handles AppliedCriteria property change on the list object to update the content of AppliedCriteria panel
 /// </summary>
 /// <param name="sender">Data list object that sent the event</param>
 /// <param name="e">Event arguments</param>
 protected virtual void OnListPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (AppliedCriteriaPanel != null && DataListObject.AppliedCriteriaProperty.Equals(e.PropertyName))
     {
         DataListObject list = sender as DataListObject;
         AppliedCriteriaPanel.BindTo(list != null ? list.AppliedCriteria : null);
     }
 }
コード例 #3
0
        public virtual NameValueCollection lnkDetailDetails_Params(int row)
        {
            NameValueCollection query = new NameValueCollection();
            DataListObject      list  = this.obj.DetailList;

            list.CurrentRow = row;
            query.Add("SalesOrderDetailId", this.obj.DetailList.SalesOrderDetailIdProperty.EditStringValue);
            query.Add(ViewParams.Mode.Param, ViewParams.Mode.Popup);
            query.Add(ViewParams.QuerySource, "lnkDetailDetails");
            return(query);
        }
コード例 #4
0
        protected virtual void lnkDetailDetails_Click(object sender, CommandEventArgs e)
        {
            NameValueCollection query = new NameValueCollection();
            DataListObject      list  = this.obj.DetailList;

            list.CurrentRow = int.Parse(e.CommandArgument.ToString());
            list.SelectRow(list.CurrentRow);
            query.Add("SalesOrderDetailId", this.obj.DetailList.SalesOrderDetailIdProperty.EditStringValue);
            query.Add(QuerySource, "lnkDetailDetails");
            NavigateTo(uclSalesOrderDetailView, query, ModePopup);
        }
コード例 #5
0
        /// <summary>
        /// Binds the specified control to the given data object list.
        /// </summary>
        /// <param name="ctl">Control to bind to the given data object list.</param>
        /// <param name="list">Data object list to bind the control to.</param>
        public static void BindToList(Control ctl, DataListObject list)
        {
            if (list == null || ctl == null)
            {
                return;
            }

            if (Create(ctl) is IListBindable listBinding)
            {
                listBinding.BindTo(list);
            }
        }
コード例 #6
0
        /// <summary>
        /// Handles selection update from the data list object by updating the list view selection
        /// </summary>
        private void OnListObjectSelectionChanged(object sender, EventArgs e)
        {
            ListView       listView = element as ListView;
            DataListObject listObj  = sender as DataListObject;

            if (PreventElementUpdate || listObj == null)
            {
                return;
            }

            PreventModelUpdate = true;

            // update selection model for list view as needed
            if (DataListObject.SelectionModeSingle.Equals(listObj.RowSelectionMode))
            {
                listView.SelectionMode = SelectionMode.Single;
            }
            else if (DataListObject.SelectionModeMultiple.Equals(listObj.RowSelectionMode) &&
                     listView.SelectionMode == SelectionMode.Single)
            {
                listView.SelectionMode = SelectionMode.Extended;
            }

            // clear selection
            if (listView.SelectionMode == SelectionMode.Single)
            {
                listView.SelectedItem = null;
            }
            else
            {
                listView.SelectedItems.Clear();
            }

            // set selected item(s) from the list object
            var listData = listObj.GetData();

            foreach (DataListObject.RowProxyObject r in listView.Items)
            {
                if (listData[r.Row].Selected)
                {
                    if (listView.SelectionMode == SelectionMode.Single)
                    {
                        listView.SelectedItem = r;
                        break;
                    }
                    else
                    {
                        listView.SelectedItems.Add(r);
                    }
                }
            }
            PreventModelUpdate = false;
        }
コード例 #7
0
        /// <inheritdoc/>
        public override void BindTo(ViewModel viewModel)
        {
            bool bind = viewModel != null;

            if ((viewModel ?? Model) is SearchViewModel svm)
            {
                if (btn_Select != null && bind && svm.Params != null)
                {
                    btn_Select.Visible = (svm.Params[ViewParams.SelectionMode.Param] != null);
                }

                // subscribe to property change events on the data list object
                if (bind)
                {
                    if (svm.List != null)
                    {
                        svm.List.PropertyChanged += OnListPropertyChanged;
                    }
                    // persist the object in session
                    ListObj = svm.List;
                }
                else
                {
                    if (svm.List != null)
                    {
                        svm.List.PropertyChanged -= OnListPropertyChanged;
                    }
                }
                OnModelPropertyChanged(svm, new PropertyChangedEventArgs(SearchViewModel.CriteriaCollapsedProperty));
                OnListPropertyChanged(bind ? svm.List : null, new PropertyChangedEventArgs(nameof(DataListObject.AppliedCriteria)));

                if (svm.List != null && grd_Results != null)
                {
                    if (svm.List.CriteriaObject != null && ucl_Criteria != null)
                    {
                        ucl_Criteria.DataBind();
                        WebPropertyBinding.BindToObject(ucl_Criteria, bind ? svm.List.CriteriaObject : null);
                        if (svm.List.AppliedCriteria != null) // recalculate applied criteria with updated labels after binding
                        {
                            svm.List.AppliedCriteria = svm.List.CriteriaObject.GetFieldCriteriaSettings();
                        }
                    }
                    if (grd_Results != null)
                    {
                        grd_Results.AutoGenerateSelectButton = ViewParams.SelectionMode.Single.Equals(svm.Params[ViewParams.SelectionMode.Param]);
                        WebPropertyBinding.BindToList(grd_Results, bind ? svm.List : null);
                    }
                }
            }
            base.BindTo(viewModel);
        }
コード例 #8
0
        public virtual void lnkDetailDetails_Command(IView tgtView, IView curView, int row)
        {
            NameValueCollection query    = lnkDetailDetails_Params(row);
            ViewModel           tgtModel = ServiceProvider.GetService <SalesOrderDetailViewModel>();

            if (NavigateTo(tgtModel, tgtView, query, this, curView))
            {
                DataListObject list = this.obj.DetailList;
                if (list != null)
                {
                    list.SelectRow(row);
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Binds the view to its model, or unbinds the current model if null is passed.
        /// </summary>
        /// <param name="viewModel">Model to bind the view to</param>
        public override void BindTo(ViewModel viewModel)
        {
            bool            bind = viewModel != null;
            SearchViewModel svm  = (bind ? viewModel : this.Model) as SearchViewModel;

            if (svm != null)
            {
                if (btn_Select != null && bind && svm.Params != null)
                {
                    btn_Select.Visible = (svm.Params[ViewParams.SelectionMode.Param] != null);
                }

                // subscribe to property change events on the data list object
                if (bind)
                {
                    if (svm.List != null)
                    {
                        svm.List.PropertyChanged += OnListPropertyChanged;
                    }
                    // persist the object in session
                    listObj = svm.List;
                }
                else
                {
                    if (svm.List != null)
                    {
                        svm.List.PropertyChanged -= OnListPropertyChanged;
                    }
                }
                OnModelPropertyChanged(svm, new PropertyChangedEventArgs(SearchViewModel.CriteriaCollapsedProperty));
                OnListPropertyChanged(bind ? svm.List : null, new PropertyChangedEventArgs(DataListObject.AppliedCriteriaProperty));

                if (svm.List != null && grd_Results != null)
                {
                    if (svm.List.CriteriaObject != null && ucl_Criteria != null)
                    {
                        ucl_Criteria.DataBind();
                        WebPropertyBinding.BindToObject(ucl_Criteria, bind ? svm.List.CriteriaObject : null);
                    }
                    if (grd_Results != null)
                    {
                        grd_Results.AutoGenerateSelectButton = ViewParams.SelectionMode.Single.Equals(svm.Params[ViewParams.SelectionMode.Param]);
                        WebPropertyBinding.BindToList(grd_Results, bind ? svm.List : null);
                    }
                }
            }
            base.BindTo(viewModel);
        }
コード例 #10
0
        /// <summary>
        /// Handles selection update from the list view by updating selection in the data list object
        /// </summary>
        private void OnListViewSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListView       listView = element as ListView;
            DataListObject listObj  = context as DataListObject;

            if (PreventModelUpdate || listObj == null || listObj.CollectionChangeFiring)
            {
                return;
            }

            PreventElementUpdate = true;
            listObj.ClearSelectedRows();
            foreach (DataListObject.RowProxyObject r in listView.SelectedItems)
            {
                listObj.SelectRows(r.Row, r.Row, false);
            }
            PreventElementUpdate = false;
        }
コード例 #11
0
        /// <summary>
        /// Binds the current GridView control to the specified data list object.
        /// Subscribes to listen for changes in the data list and update the grid accordingly.
        /// </summary>
        /// <param name="list">The data list object to bind to.</param>
        public virtual void BindTo(DataListObject list)
        {
            if (this.list != null)
            {
                this.list.CollectionChanged -= OnListChanged;
                this.list.SelectionChanged  -= OnListSelectionChanged;
            }
            this.list = list;
            if (list != null)
            {
                this.list.CollectionChanged += OnListChanged;
                this.list.SelectionChanged  += OnListSelectionChanged;
            }

            GridView grid = (GridView)control;

            grid.DataSource = list?.GetData();
            grid.DataBind();
        }
コード例 #12
0
        /// <summary>
        /// Updates selection in the specified list object for a details open/close event
        /// using the provided key property on the details view object.
        /// </summary>
        /// <param name="list">Data list object to update.</param>
        /// <param name="keyChildProp">The key property on the child details view.</param>
        /// <param name="e">Open/close event of the child details view.</param>
        /// <returns></returns>
        protected virtual bool UpdateListSelection(DataListObject list, DataProperty keyChildProp, ViewEvent e)
        {
            // Find key property in the list with the same name, as the key property in the child details object.
            var keyListProp = list?.Properties?.Where(p => p.IsKey && p.Name == keyChildProp?.Name)?.FirstOrDefault();

            if (keyListProp != null)
            {
                if (e.IsOpened())
                {
                    list.SelectedRows = list.GetData().Where(r => Equals(keyListProp.GetValue(ValueFormat.Internal, r),
                                                                         keyChildProp.InternalValue)).ToList();
                }
                else if (e.IsClosed())
                {
                    list.ClearSelectedRows();
                }
                return(true);
            }
            return(false);
        }
コード例 #13
0
 /// <summary>
 /// Constructs a new check box property binding for the given check box.
 /// </summary>
 /// <param name="checkBox">The check box to be bound to the property.</param>
 protected CheckBoxPropertyBinding(CheckBox checkBox)
     : base(checkBox)
 {
     // check box sets values on selection change, since unchecked control posts no value
     // and we have to use selection change to detect this as opposed to no post at all
     PostedValue              = null;
     checkBox.CheckedChanged += delegate
     {
         if (property != null && control.Page != null && !PreventModelUpdate)
         {
             PostedValue = control.Page.Request.Form[control.UniqueID];
             int            row;
             DataListObject list = property.GetParent() as DataListObject;
             if (list != null && int.TryParse(GetControlAttribute("row"), out row))
             {
                 list.CurrentRow = row;
             }
             UpdateProperty(PostedValue == null ? false : true);
         }
     };
 }
コード例 #14
0
        /// <summary>
        /// Initializes the already constructed view model for each request
        /// </summary>
        /// <param name="e">Standard event arguments</param>
        protected override void OnLoad(EventArgs e)
        {
            // restore view model state
            SearchViewModel svm = Model as SearchViewModel;

            if (svm != null)
            {
                DataListObject list = listObj;
                if (list != null)
                {
                    svm.List = list;
                }
                ICollapsiblePanel collapsible = ucl_Criteria as ICollapsiblePanel;
                if (collapsible != null)
                {
                    svm.CriteriaCollapsed = collapsible.Collapsed;
                }
            }

            // wire up event handlers for buttons
            if (btn_Search != null)
            {
                btn_Search.Click += Search;
            }
            if (btn_Refresh != null)
            {
                btn_Refresh.Click += Refresh;
            }
            if (btn_Reset != null)
            {
                btn_Reset.Click += Reset;
            }
            if (btn_Select != null)
            {
                btn_Select.Click += Select;
            }

            base.OnLoad(e);
        }
コード例 #15
0
        /// <summary>
        /// Binds the framework element to the given data object.
        /// </summary>
        /// <param name="obj">The data object to bind the framework element to.</param>
        public override void BindTo(DataObject obj)
        {
            DataListObject lst = obj as DataListObject;

            if (lst != null)
            {
                lst.SelectionChanged  -= OnListObjectSelectionChanged;
                lst.CollectionChanged -= CleanupBindings;
            }
            base.BindTo(obj);                                       // assigns context
            OnListObjectSelectionChanged(context, EventArgs.Empty); // update current selection
            lst = obj as DataListObject;
            if (lst != null)
            {
                lst.SelectionChanged  += OnListObjectSelectionChanged;
                lst.CollectionChanged += CleanupBindings;
            }
            else
            {
                CleanupBindings(element, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
            ((ListView)element).ItemsSource = lst;
        }
コード例 #16
0
        /// <summary>
        /// Binds the current GridView control to the specified data list object.
        /// Subscribes to listen for changes in the data list and update the grid accordingly.
        /// </summary>
        /// <param name="list">The data list object to bind to.</param>
        public virtual void BindTo(DataListObject list)
        {
            INotifyCollectionChanged observableList = this.list as INotifyCollectionChanged;

            if (observableList != null)
            {
                observableList.CollectionChanged -= OnListChanged;
            }
            if (this.list != null)
            {
                this.list.SelectionChanged -= OnListSelectionChanged;
            }
            this.list      = list;
            observableList = list as INotifyCollectionChanged;
            if (observableList != null)
            {
                OnListChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
                observableList.CollectionChanged += OnListChanged;
            }
            if (list != null)
            {
                list.SelectionChanged += OnListSelectionChanged;
            }
        }
コード例 #17
0
        /// <inheritdoc/>
        public async override Task <object> ReadAsync(DataManagerRequest dm, string key = null)
        {
            DataListObject list = DataManager?.List;

            if (list == null)
            {
                return dm.RequiresCounts ? new DataResult()
                       {
                           Result = null, Count = 0
                       }
            }
            : null;

            IEnumerable <DataRow> data = list.GetData();

            if (dm.Where != null && dm.Where.Count > 0)
            {
                data = data.Where(r => Matches(r, "and", dm.Where));
            }
            if (dm.Search != null && dm.Search.Count > 0)
            {
                data = data.Where(r => Matches(r, "and", SearchToWhere(dm.Search)));
            }

            data = data.ToList(); // run the search before sorting and counting
            if (dm.Sorted != null && dm.Sorted.Count > 0)
            {
                var sortCrit = ToSortCriteria(dm.Sorted.Reverse <Sort>()); // multi-column sort comes in reverse order
                ((List <DataRow>)data).Sort(sortCrit);
            }

            int count = data.Count();

            if (dm.Skip != 0)
            {
                data = data.Skip(dm.Skip);
            }
            if (dm.Take != 0)
            {
                data = data.Take(dm.Take);
            }

            if (dm.Group != null)
            {
                IEnumerable groupedData = data;
                foreach (var group in dm.Group)
                {
                    groupedData = DataUtil.Group <DataRow>(groupedData, group, dm.Aggregates, 0, dm.GroupByFormatter);
                }
                return(dm.RequiresCounts ? new DataResult()
                {
                    Result = groupedData, Count = count
                } : (object)data);
            }
            var res = dm.RequiresCounts ? new DataResult()
            {
                Result = data, Count = count
            } : (object)data;

            return(await Task.FromResult(res));
        }
コード例 #18
0
 /// <summary>
 /// Binds the current GridView control to the specified data list object.
 /// Subscribes to listen for changes in the data list and update the grid accordingly.
 /// </summary>
 /// <param name="list">The data list object to bind to.</param>
 public virtual void BindTo(DataListObject list)
 {
     INotifyCollectionChanged observableList = this.list as INotifyCollectionChanged;
     if (observableList != null) observableList.CollectionChanged -= OnListChanged;
     this.list = list;
     observableList = list as INotifyCollectionChanged;
     if (observableList != null)
     {
         OnListChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
         observableList.CollectionChanged += OnListChanged;
     }
     // set up grid selection
     GridView grid = (GridView)control;
     if (grid != null && list != null)
     {
         grid.AutoGenerateSelectButton = (list.RowSelectionMode == DataListObject.SelectionModeSingle);
     }
 }