예제 #1
0
        public override void Refresh()
        {
            if (_suspendRefresh)
                return;
            _suspendRefresh = true;

            // check if we have loaded this page yet
            int firstRowIndex = (int)paging.PageNum * (int)paging.PageSize;
            
            // If we have deleted all rows, we don't want to refresh the grid on the first page
            bool allDataDeleted = (paging.TotalRows == 0) && (DeleteData != null) && (DeleteData.Count > 0);
           
            if (_data[firstRowIndex] == null && !allDataDeleted)
            {
                this.OnDataLoading.Notify(null, null, null);

                string orderBy = ApplySorting();

                // We need to load the data from the server
                int? fetchPageSize;
                if (_lazyLoadPages)
                {
                    fetchPageSize = this.paging.PageSize;
                }
                else
                {
                    fetchPageSize = 1000; // Maximum 1000 records returned in non-lazy load grid
                    
                    this.paging.extraInfo = "";
                    this.paging.PageNum = 0;
                    firstRowIndex = 0;
                    
                }
                if (String.IsNullOrEmpty(_fetchXml)) // If we have no fetchxml, then don't refresh
                    return;
                string parameterisedFetchXml = String.Format(_fetchXml, fetchPageSize, XmlHelper.Encode(this.paging.extraInfo), this.paging.PageNum + 1, orderBy);
                OrganizationServiceProxy.BeginRetrieveMultiple(parameterisedFetchXml, delegate(object result)
                {
                    try
                    {
                        EntityCollection results = OrganizationServiceProxy.EndRetrieveMultiple(result, _entityType);

                        // Set data
                        int i = firstRowIndex;
                        if (_lazyLoadPages)
                        {
                            // We are returning just one page - so add it into the data
                            foreach (Entity e in results.Entities)
                            {
                                _data[i] = (Entity)e;
                                i = i + 1;
                            }
                        }
                        else
                        {
                            // We are returning all results in one go
                            _data = results.Entities.Items();
                        }

                        // Notify
                        DataLoadedNotifyEventArgs args = new DataLoadedNotifyEventArgs();
                        args.From = 0;
                        args.To = (int)paging.PageSize - 1;

                        this.paging.TotalRows = results.TotalRecordCount;
                        this.paging.extraInfo = results.PagingCookie;
                        this.paging.FromRecord = firstRowIndex + 1;
                        this.paging.TotalPages = Math.Ceil(results.TotalRecordCount / this.paging.PageSize);
                        this.paging.ToRecord = Math.Min(results.TotalRecordCount, firstRowIndex + paging.PageSize);
                        if (this._itemAdded)
                        {
                            this.paging.TotalRows++;
                            this.paging.ToRecord++;
                            this._itemAdded = false;     
                        }
                        this.CalculatePaging(GetPagingInfo());
                        OnPagingInfoChanged.Notify(this.paging, null, this);
                        this.OnDataLoaded.Notify(args, null, null);
                    }
                    catch (Exception ex)
                    {
                        this.ErrorMessage = ex.Message;
                        DataLoadedNotifyEventArgs args = new DataLoadedNotifyEventArgs();
                        args.ErrorMessage = ex.Message;
                        this.OnDataLoaded.Notify(args, null, null);
                    }
                });
            }
            else
            {
                // We already have the data
                DataLoadedNotifyEventArgs args = new DataLoadedNotifyEventArgs();
                args.From = 0;
                args.To = (int)paging.PageSize - 1;
                this.paging.FromRecord = firstRowIndex + 1;
                this.paging.ToRecord = Math.Min(this.paging.TotalRows, firstRowIndex + paging.PageSize);

                this.CalculatePaging(GetPagingInfo());
                OnPagingInfoChanged.Notify(this.paging, null, this);
                this.OnDataLoaded.Notify(args, null, null);
                this._itemAdded = false;
                
            }

            this.OnRowsChanged.Notify(null, null, this);
            _suspendRefresh = false;
        }
예제 #2
0
        public override void Refresh()
        {
            if (rows != null)
            {
                DataLoadedNotifyEventArgs args = new DataLoadedNotifyEventArgs();
                args.From = 0;
                args.To = rows.Count - 1;
                this.OnDataLoaded.Notify(args, null, null);
                this.OnRowsChanged.Notify(args, null, this);
            }

           
        }
예제 #3
0
        /// <summary>
        /// Only show the view of selected activity
        /// </summary>
        private void RefreshActivityView()
        {
            // filter sessions by activity and seleced day

            data = new List<dev1_session>();
            foreach (dev1_session session in GetCurrentWeek())
            {
                if (
                    (
                    (SelectedActivityID == null)
                    ||
                    (session.dev1_ActivityId == SelectedActivityID.ToString())
                    )
                    &&
                    (
                    (SelectedDay == null)
                    ||
                    (session.dev1_StartTime.GetDay() == SelectedDay.GetDay())
                    )
                    ) // TODO: filter day
                {
                    data.Add(session);
                }
            }
            // Notify
            DataLoadedNotifyEventArgs args = new DataLoadedNotifyEventArgs();
            args.From = 0;
            args.To = data.Count - 1;

            this.OnDataLoaded.Notify(args, null, null);
            this.OnRowsChanged.Notify(null, null, this);
        }
예제 #4
0
        public override void AddItem(object item)
        {
            // TODO: Set current week from the datetime on the new session
            if (this.SelectedActivity != null)
            {
                List<dev1_session> sessions = GetCurrentWeek();
                dev1_session itemAdding = (dev1_session)item;
                dev1_session newItem = new dev1_session();
                newItem.dev1_Description = itemAdding.dev1_Description;
                newItem.dev1_StartTime = itemAdding.dev1_StartTime;
                newItem.dev1_Duration = itemAdding.dev1_Duration;
                //newItem.activityName = itemAdding.activityName;
                newItem.dev1_ActivityId = this.SelectedActivity.Id.ToString();
                newItem.dev1_ActivityTypeName = this.SelectedActivity.LogicalName;
                // Set the activity reference
                switch (this.SelectedActivity.LogicalName)
                {
                    case "phonecall":
                        newItem.dev1_PhoneCallId = this.SelectedActivity;
                        break;
                    case "task":
                        newItem.dev1_TaskId = this.SelectedActivity;
                        break;
                    case "letter":
                        newItem.dev1_LetterId = this.SelectedActivity;
                        break;
                    case "email":
                        newItem.dev1_EmailId = this.SelectedActivity;
                        break;

                }

                newItem.EntityState = EntityStates.Created;
                // If no date set, set to the currently selected date
                if (newItem.dev1_StartTime == null)
                {
                    newItem.dev1_StartTime = SelectedDay == null ? WeekStart : SelectedDay;
                }

                // Add to the sessions view cache
                AddSession(sessions, newItem);

                // Add to the data view as well
                data.Add(newItem);

                // refresh
                DataLoadedNotifyEventArgs args = new DataLoadedNotifyEventArgs();
                args.From = data.Count - 1;
                args.To = data.Count - 1;

                this.OnDataLoaded.Notify(args, null, null);
                this.OnRowsChanged.Notify(null, null, null);
            }
        }
        public override void Refresh()
        {
            int requestedPage = paging.PageNum.Value;
            int pageLoadState = _pagesLoaded[requestedPage];

            if (_suspendRefresh == true)
            {
                return;
            }
           
            _suspendRefresh = true;
            
            // If we have deleted all rows, we don't want to refresh the grid on the first page
            bool allDataDeleted = (paging.TotalRows == 0) && (DeleteData != null) && (DeleteData.Count > 0);
            List<int> rows = new List<int>();
            int firstRowIndex = requestedPage * (int)paging.PageSize;

            if (pageLoadState!=LOADING && pageLoadState!=LOADED)
            {
                if (String.IsNullOrEmpty(_fetchXml))
                {
                    _suspendRefresh = false;
                    return;
                }
                _pagesLoaded[requestedPage] = LOADING;

                this.OnDataLoading.Notify(null, null, null);

                string orderBy = ApplySorting();

                // We need to load the data from the server
                int? fetchPageSize;

                fetchPageSize = this.paging.PageSize ;


                string parameterisedFetchXml = String.Format(_fetchXml, fetchPageSize, XmlHelper.Encode(this.paging.extraInfo), requestedPage + 1, orderBy);
                
                OrganizationServiceProxy.BeginRetrieveMultiple(parameterisedFetchXml, delegate(object result)
                {    
                    try
                    {
                        EntityCollection results = OrganizationServiceProxy.EndRetrieveMultiple(result, _entityType);

                        // Set data
                        int i = firstRowIndex;
                        if (_lazyLoadPages)
                        {
                            // We are returning just one page - so add it into the data
                            foreach (Entity e in results.Entities)
                            {
                                _data[i] = (Entity)e;
                                ArrayEx.Add(rows,i);
                                i = i + 1;
                            }
                        }
                        else
                        {
                            // We are returning all results in one go
                            _data = results.Entities.Items();
                        }

                        _pagesLoaded[requestedPage] = LOADED;
                        
                        this.paging.TotalRows = results.TotalRecordCount;
                        this.paging.extraInfo = results.PagingCookie;
                        this.paging.FromRecord = firstRowIndex + 1;
                        this.paging.TotalPages = Math.Ceil(results.TotalRecordCount / this.paging.PageSize);
                        this.paging.ToRecord = Math.Min(results.TotalRecordCount, firstRowIndex + paging.PageSize);
                        if (this._itemAdded)
                        {
                            this.paging.TotalRows++;
                            this.paging.ToRecord++;
                            this._itemAdded = false;
                        }
                        this.OnPagingInfoChanged.Notify(GetPagingInfo(), null, null);
                        // Notify
                        DataLoadedNotifyEventArgs args = new DataLoadedNotifyEventArgs();
                        args.From = firstRowIndex;
                        args.To = firstRowIndex + (int)paging.PageSize - 1;
                        this.OnDataLoaded.Notify(args, null, null);
                        FinishSuspend();
                       
                    }
                    catch (Exception ex)
                    {
                        // Issue #40 - Check for Quick Find Limit
                        bool quickFindLimit = ex.Message.IndexOf("QuickFindQueryRecordLimit") > -1;
                        _pagesLoaded[requestedPage] = LOADED;
                        this.paging.TotalRows = 5001;
                        this.OnPagingInfoChanged.Notify(GetPagingInfo(), null, null);
                        DataLoadedNotifyEventArgs args = new DataLoadedNotifyEventArgs();
                        if (!quickFindLimit)
                        {
                            this.ErrorMessage = ex.Message;
                            args.ErrorMessage = ex.Message;
                        }
                       
                        this.OnDataLoaded.Notify(args, null, null);
                        //_pendingRefresh = false;
                        FinishSuspend();
                    }
                });
            }
            else if (pageLoadState == LOADED)
            {
                // We already have the data
                DataLoadedNotifyEventArgs args = new DataLoadedNotifyEventArgs();
                args.From = 0;
                args.To = (int)paging.PageSize - 1;
                this.paging.FromRecord = firstRowIndex + 1;
                this.paging.ToRecord = Math.Min(this.paging.TotalRows, firstRowIndex + paging.PageSize);

                this.OnPagingInfoChanged.Notify(GetPagingInfo(), null, null);
                this.OnDataLoaded.Notify(args, null, null);
                this._itemAdded = false;
                FinishSuspend();
               
            }
        }