Esempio n. 1
0
        /// <summary>
        /// Invalidate based on a list
        /// </summary>
        /// <param name="lst">Object list</param>
        public virtual void Invalidate(IList <T> lst)
        {
            //Invalidate lookup edit columns to reflect all changes of lookup table
            //if (GridControl != null)
            //    GridControl.InvalidateLookupEditColumns();

            this.Clear();
            foreach (T obj in lst)
            {
                this.Add((T)obj.Clone());
            }

            //Invalidate original list same as itself
            OriginalList.Clear();
            foreach (T obj in this)
            {
                OriginalList.Add((T)obj.Clone());
            }

            if (GridControl != null)
            {
                GridControl.RefreshDataSource();
                if (this.Count > 0)
                {
                    if (CurrentIndex >= 0 && CurrentIndex < Count)
                    {
                        GridViewFocusRow(CurrentIndex);
                    }
                    else
                    {
                        GridViewFocusRow(0);
                    }
                }
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects)
                    OriginalList?.Clear();
                    OriginalList = null;

                    DataPage?.Clear();
                    DataPage = null;

                    FilteredList?.Clear();
                    FilteredList = null;

                    ModelValueList?.Clear();
                    ModelValueList = null;

                    SortDictionary?.Clear();
                    SortDictionary = null;

                    FilterDictionary?.Clear();
                    FilterDictionary = null;
                }

                // TODO: free unmanaged resources (unmanaged objects) and override finalizer
                // TODO: set large fields to null
                disposedValue = true;
            }
        }
        protected override void OnListChanged(ListChangedEventArgs e)
        {
            // If the list is reset, check for a filter. If a filter
            // is applied, don't allow items to be added to the list.
            if (e.ListChangedType == ListChangedType.Reset)
            {
                AllowNew = string.IsNullOrEmpty(Filter);
            }
            // Add the new item to the original list.
            if (e.ListChangedType == ListChangedType.ItemAdded)
            {
                OriginalList.Add(this[e.NewIndex]);
                if (!string.IsNullOrEmpty(Filter))
                {
                    var cachedFilter = Filter;
                    Filter = string.Empty;
                    Filter = cachedFilter;
                }
            }
            // Remove the new item from the original list.
            if (e.ListChangedType == ListChangedType.ItemDeleted)
            {
                OriginalList.RemoveAt(e.NewIndex);
            }

            base.OnListChanged(e);
        }
Esempio n. 4
0
        protected override void OnListChanged(ListChangedEventArgs e)
        {
            // If the list is reset, check for a filter. If a filter
            // is applied don't allow items to be added to the list.
            if (e.ListChangedType == ListChangedType.Reset)
            {
                if (Filter == null || Filter == "")
                {
                    AllowNew = true;
                }
                else
                {
                    AllowNew = false;
                }
            }
            // Add the new item to the original list.
            if (e.ListChangedType == ListChangedType.ItemAdded)
            {
                OriginalList.Add(this[e.NewIndex]);
                if (!String.IsNullOrEmpty(Filter))
                //if (Filter == null || Filter == "")
                {
                    string cachedFilter = this.Filter;
                    this.Filter = "";
                    this.Filter = cachedFilter;
                }
            }
            // Remove the new item from the original list.
            if (e.ListChangedType == ListChangedType.ItemDeleted)
            {
                OriginalList.RemoveAt(e.NewIndex);
            }

            base.OnListChanged(e);
        }
Esempio n. 5
0
        public virtual void Invalidate(DataTable table)
        {
            this.Clear();
            OriginalList.Clear();
            BaseBusinessController objItemController = BusinessControllerFactory.GetBusinessController(ItemTableName + "Controller");

            //Invalidate lookup edit columns to reflect all changes of lookup table
            //if (GridControl != null)
            //    GridControl.InvalidateLookupEditColumns();

            foreach (DataRow row in table.Rows)
            {
                T objT = (T)objItemController.GetObjectFromDataRow(row);
                this.Add(objT);
                OriginalList.Add((T)objT.Clone());
            }
            if (GridControl != null)
            {
                GridControl.RefreshDataSource();
                if (this.Count > 0)
                {
                    if (CurrentIndex >= 0 && CurrentIndex < Count)
                    {
                        GridViewFocusRow(CurrentIndex);
                    }
                    else
                    {
                        GridViewFocusRow(0);
                    }
                }
            }
        }
Esempio n. 6
0
        protected override void OnListChanged(ListChangedEventArgs e)
        {
            if (e.ListChangedType == ListChangedType.Reset)
            {
                if (Filter == null || Filter == "")
                {
                    AllowNew = true;
                }
                else
                {
                    AllowNew = false;
                }
            }

            if (e.ListChangedType == ListChangedType.ItemAdded)
            {
                OriginalList.Add(this[e.NewIndex]);
                if (!String.IsNullOrEmpty(Filter))
                {
                    string cachedFilter = this.Filter;
                    this.Filter = "";
                    this.Filter = cachedFilter;
                }
            }
            if (e.ListChangedType == ListChangedType.ItemDeleted)
            {
                OriginalList.RemoveAt(e.NewIndex);
            }

            base.OnListChanged(e);
        }
Esempio n. 7
0
 /// <summary>
 ///     Detaches this instance from its associated object.
 /// </summary>
 public void Detach()
 {
     if (_applicationBar == null)
     {
         throw new InvalidOperationException(
                   "The BindableApplicationBarMenuItem is not attached to an IBindableApplicationBar.");
     }
     OriginalList.Remove(ApplicationBarItem);
     _applicationBar = null;
     _position       = -1;
 }
Esempio n. 8
0
        /// <summary>
        /// Filters the current collection.
        /// </summary>
        public void FilterCollection()
        {
            try
            {
                IsFiltering = true;

                var statement = GetStatement(ExpressionType.Linq);

                var ri             = OriginalList.Where(statement);
                var remainingItems = ri as IList <object> ?? ri.Cast <object>().ToList();

                IList itemsToRemove = new List <object>();
                IList itemsToAdd    = new List <object>();

                foreach (var item in CollectionToFilter)
                {
                    if (!remainingItems.Contains(item))
                    {
                        itemsToRemove.Add(item);
                    }
                }
                foreach (var item in remainingItems)
                {
                    if (!CollectionToFilter.Contains(item))
                    {
                        itemsToAdd.Add(item);
                    }
                }

                foreach (var item in itemsToRemove)
                {
                    CollectionToFilter.Remove(item);
                }

                foreach (var item in itemsToAdd)
                {
                    CollectionToFilter.Add(item);
                }
            }
            catch (Exception e)
            {
                if (AutoUpdateCheckBox.IsChecked == true)
                {
                    return;
                }
                MessageBox.Show(e.Message, "Error filtering collection", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                IsFiltering = false;
            }
        }
Esempio n. 9
0
        private void ClearExpressionsOnClick(object sender, RoutedEventArgs e)
        {
            var result = MessageBox.Show("Are you sure you want to clear all expressions?", "Are you sure?",
                                         MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                ExpressionStackPanel.Children.Clear();
                RootExpressionGroup = null;
                InitializeRootExpressionGroup();
                CollectionToFilter = OriginalList.JsonCloneObject(TheType) as IList;
            }
        }
        /// <summary>
        /// This method removes list filtering.
        /// </summary>
        private void OnCancelFilerClick()
        {
            FilterActive = false;

            foreach (var key in FilterDictionary.Keys.ToList())
            {
                FilterDictionary[key] = "";
            }

            Parameters.DataList.Clear();
            Parameters.DataList = OriginalList.GetRange(0, OriginalList.Count);

            SetPageCount(OriginalList);

            GetPage("first");
        }
        /// <summary>
        /// This method displays the indicated page.
        /// </summary>
        /// <param name="direction">Direction can be a word like next, previous last or first.  Direction can also be an integer number.</param>
        private void GetPage(string direction)
        {
            if (Parameters.ShowPager)
            {
                if (direction == "next")
                {
                    CurrentPage++;
                }
                else if (direction == "previous")
                {
                    CurrentPage--;
                }
                else if (direction == "first")
                {
                    CurrentPage = 1;
                }
                else if (direction == "last")
                {
                    CurrentPage = TotalPages;
                }
                else
                {
                    CurrentPage = Convert.ToInt32(direction);
                }

                if (CurrentPage > TotalPages)
                {
                    CurrentPage = TotalPages;
                }
                if (CurrentPage < 1)
                {
                    CurrentPage = 1;
                }

                if (!FilterActive)
                {
                    Parameters.DataList = OriginalList.Skip((CurrentPage - 1) * Parameters.PageSize).Take(Parameters.PageSize).ToList();
                }
                else
                {
                    Parameters.DataList = FilteredList.Skip((CurrentPage - 1) * Parameters.PageSize).Take(Parameters.PageSize).ToList();
                }
            }
        }
        /// <summary>
        /// This method applies list sorting.
        /// </summary>
        /// <param name="columnName"></param>
        protected void OnSortClick(string columnName)
        {
            bool sortAsc = !SortDictionary[columnName];

            OriginalList = _genericSorter.Sort(OriginalList, columnName, sortAsc == true ? "asc" : "desc").ToList();

            if (FilteredList == null || FilteredList?.Count == 0)
            {
                Parameters.DataList.Clear();
                Parameters.DataList = OriginalList.GetRange(0, OriginalList.Count);
                SetPageCount(OriginalList);
                GetPage("first");
            }
            else
            {
                OnFilterInput();
            }

            SortDictionary[columnName] = sortAsc;
        }
Esempio n. 13
0
 public void Clear()
 {
     NewList.Clear();
     OriginalList.Clear();
 }
Esempio n. 14
0
 public void RemoveAt(int index)
 {
     NewList.RemoveAt(index);
     OriginalList.RemoveAt(index);
 }
Esempio n. 15
0
 public void Insert(int index, TNew item)
 {
     NewList.Insert(index, item);
     OriginalList.Insert(index, item.OriginalDictionary);
 }
Esempio n. 16
0
 public bool Remove(TNew item)
 {
     OriginalList.Remove(item.OriginalDictionary);
     return(NewList.Remove(item));
 }
Esempio n. 17
0
 public void Add(TNew item)
 {
     NewList.Add(item);
     OriginalList.Add(item.OriginalDictionary);
 }
Esempio n. 18
0
        public virtual void SaveItemObjects()
        {
            try
            {
                EndCurrentEdit();

                VinaDbUtil             dbUtil = new VinaDbUtil();
                String                 strItemTablePrimaryKey = dbUtil.GetTablePrimaryColumn(ItemTableName);
                BaseBusinessController objItemsController     = BusinessControllerFactory.GetBusinessController(ItemTableName + "Controller");
                int iParentObjectID = GetParentObjectID();

                //Create or update
                foreach (T objT in this)
                {
                    int iItemObjectID = (int)dbUtil.GetPropertyValue(objT, strItemTablePrimaryKey);

                    if (iItemObjectID == 0 && Relation == cstRelationForeign)
                    {
                        if (iParentObjectID > 0)
                        {
                            if (dbUtil.GetPropertyValue(objT, ItemTableForeignKey) != null)
                            {
                                dbUtil.SetPropertyValue(objT, ItemTableForeignKey, iParentObjectID);
                            }
                        }
                    }

                    bool isUpdate = iItemObjectID > 0;
                    if (isUpdate)
                    {
                        dbUtil.SetPropertyValue(objT, ERPModuleEntities.AAUpdatedUser, VinaApp.CurrentUserName);
                        dbUtil.SetPropertyValue(objT, ERPModuleEntities.AAUpdatedDate, DateTime.Now);
                        objItemsController.UpdateObject(objT);
                    }
                    else
                    {
                        dbUtil.SetPropertyValue(objT, ERPModuleEntities.AACreatedUser, VinaApp.CurrentUserName);
                        dbUtil.SetPropertyValue(objT, ERPModuleEntities.AACreatedDate, DateTime.Now);
                        iItemObjectID = objItemsController.CreateObject(objT);
                    }
                }

                //Delete items
                foreach (T obj in OriginalList)
                {
                    int iItemObjectID = (int)dbUtil.GetPropertyValue(obj, strItemTablePrimaryKey);
                    if (iItemObjectID > 0 && !this.Exists(strItemTablePrimaryKey, iItemObjectID))
                    {
                        objItemsController.DeleteObject(iItemObjectID);
                        //Entity.DeleteObjectRelations(ItemTableName, iItemObjectID);
                    }
                }
                //Invalidate original list
                OriginalList.Clear();
                foreach (T obj in this)
                {
                    OriginalList.Add((T)obj.Clone());
                }
            }
            catch (Exception e)
            {
                // MessageBox.Show(e.ToString(), CommonLocalizedResources.MessageBoxDefaultCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }