Esempio n. 1
0
        public void OpenSelectedRecordCommand()
        {
            List <int> selectedRows = DataViewBase.RangesToRows(Contacts.GetSelectedRows());

            if (selectedRows.Count != 1)
            {
                return;
            }

            List <Entity> itemsToOpen = new List <Entity>();

            foreach (int row in selectedRows)
            {
                itemsToOpen.Add((Entity)Contacts.GetItem(row));
            }
            try
            {
                foreach (Entity item in itemsToOpen)
                {
                    Utility.OpenEntityForm(item.LogicalName, item.Id, null);
                }
            }
            catch (Exception ex)
            {
                ErrorMessage.SetValue(ex.ToString());
            }
        }
Esempio n. 2
0
        public Action DeleteCommand()
        {
            if (_deleteCommand == null)
            {
                _deleteCommand = delegate()
                {
                    List <int> selectedRows = DataViewBase.RangesToRows(Lines.GetSelectedRows());
                    if (selectedRows.Count == 0)
                    {
                        return;
                    }

                    bool confirmed = Script.Confirm(String.Format("Are you sure that you want to delete the {0} quote lines in the Grid?", selectedRows.Count));
                    if (!confirmed)
                    {
                        return;
                    }
                    List <Entity> itemsToRemove = new List <Entity>();
                    foreach (int row in selectedRows)
                    {
                        itemsToRemove.Add((Entity)Lines.GetItem(row));
                    }
                    foreach (Entity item in itemsToRemove)
                    {
                        item.EntityState = EntityStates.Deleted;
                        Lines.RemoveItem(item);
                    }
                    Lines.Refresh();
                };
            }
            return(_deleteCommand);
        }
        public void DeleteSelectedCommand()
        {
            List <int> selectedRows = DataViewBase.RangesToRows(Connections.GetSelectedRows());

            if (selectedRows.Count == 0)
            {
                return;
            }

            Utility.ConfirmDialog(
                String.Format(ResourceStrings.ConfirmDeleteSelectedConnection, selectedRows.Count),
                delegate()
            {
                List <Entity> itemsToRemove = new List <Entity>();
                foreach (int row in selectedRows)
                {
                    itemsToRemove.Add((Entity)Connections.GetItem(row));
                }
                try
                {
                    foreach (Entity item in itemsToRemove)
                    {
                        OrganizationServiceProxy.Delete_(item.LogicalName, new Guid(item.Id));
                    }
                }
                catch (Exception ex)
                {
                    ErrorMessage.SetValue(ex.ToString());
                }
                Connections.RaiseOnSelectedRowsChanged(null);
                Connections.Reset();
                Connections.Refresh();
            }, null);
        }
Esempio n. 4
0
        /// <summary>
        /// create a field and fill it by data
        /// </summary>
        /// <param name = "dataview"> Dataview </param>
        /// <returns> the created filled field </returns>
        protected override FieldDef initField(DataViewBase dataview)
        {
            var field = new Field((DataView)dataview, _fields.Count);

            field.fillData();
            return(field);
        }
Esempio n. 5
0
        public Action DeleteCommand()
        {
            if (_deleteCommand == null)
            {
                _deleteCommand = delegate()
                {
                    // Delete all selected jobs in grid
                    SelectedRange[] ranges = JobsViewModel.GetSelectedRows();
                    List <int>      rows   = DataViewBase.RangesToRows(ranges);

                    bool confirmed = Script.Confirm(String.Format("Are you sure you want to delete these {0} job(s)?", rows.Count));
                    if (!confirmed)
                    {
                        return;
                    }



                    IsBusy.SetValue(true);
                    DelegateItterator.CallbackItterate(delegate(int index, Action nextCallback, ErrorCallBack errorCallBack)
                    {
                        dev1_ScheduledJob job = (dev1_ScheduledJob)this.JobsViewModel.GetItem(rows[index]);
                        // First delete the scheduled jobs associated
                        DeleteBulkDeleteJobs(job.dev1_ScheduledJobId, delegate(){
                            OrganizationServiceProxy.BeginDelete(dev1_ScheduledJob.EntityLogicalName, job.dev1_ScheduledJobId, delegate(object result)
                            {
                                try
                                {
                                    OrganizationServiceProxy.EndDelete(result);
                                    IsBusyProgress.SetValue((index / rows.Count) * 100);
                                    nextCallback();
                                }
                                catch (Exception ex)
                                {
                                    errorCallBack(ex);
                                }
                            });
                        });
                    },
                                                       rows.Count,
                                                       delegate()
                    {
                        // Completed
                        IsBusy.SetValue(false);
                        JobsViewModel.Reset();
                        JobsViewModel.Refresh();
                    },
                                                       delegate(Exception ex)
                    {
                        // Error
                        ReportError(ex);
                    });
                };
            }
            return(_deleteCommand);
        }
Esempio n. 6
0
        private void MoveFocusedRow(DataViewBase tableView, int index)
        {
            if (tableView == null)
            {
                return;
            }

            tableView.MoveFocusedRow(index);
            tableView.FocusedRowHandle = index;
        }
        public static void init()
        {
            MultiSearchViewModel2013 vm = new MultiSearchViewModel2013();


            // Create Grids
            FetchQuerySettings[] searches         = vm.Config.GetItems();
            jQueryObject         searchResultsDiv = jQuery.Select("#searchResults");

            jQuery.Window.Resize(delegate(jQueryEvent e)
            {
                OnResizeSearchResults(searchResultsDiv);
            });
            OnResizeSearchResults(searchResultsDiv);
            jQuery.Select(".sparkle-xrm").Bind("onmousewheel mousewheel DOMMouseScroll", OnSearchResultsMouseScroll);

            int i = 0;

            foreach (FetchQuerySettings config in searches)
            {
                List <Column> cardColumn = new List <Column>(new Column(ColumnProperties.Id, "card-column", ColumnProperties.Options, config.Columns, ColumnProperties.Name, "Name", ColumnProperties.Width, 290, ColumnProperties.CssClass, "card-column-cell"));

                cardColumn[0].Formatter    = RenderCardColumnCell;
                cardColumn[0].DataType     = "PrimaryNameLookup";
                config.Columns[0].DataType = "PrimaryNameLookup"; // This is so that clicking on the column opens the record
                GridDataViewBinder dataViewBinder = new GridDataViewBinder();
                GridOptions        gridOptions    = new GridOptions();
                gridOptions.EnableCellNavigation = true;
                gridOptions.AutoEdit             = false;
                gridOptions.Editable             = false;
                gridOptions.EnableAddRow         = false;
                // Set height to the number of columns
                int columns = config.Columns.Count;
                gridOptions.RowHeight = (columns > 3? 3 : columns) * 16;;
                if (gridOptions.RowHeight < 70)
                {
                    gridOptions.RowHeight = 70;
                }
                gridOptions.HeaderRowHeight = 0;

                string       gridId   = "grid" + i.ToString() + "container";
                DataViewBase dataView = config.DataView;

                Grid grid = new Grid("#" + gridId, dataView, cardColumn, gridOptions);
                grids[i] = grid;
                AddResizeEventHandlers(grid, gridId);
                dataViewBinder.DataBindEvents(grid, dataView, gridId);
                dataViewBinder.BindClickHandler(grid);
                i++;
            }


            // Data Bind
            ViewBase.RegisterViewModel(vm);
        }
Esempio n. 8
0
 static void ProcessUsingShowFilterPopupEvent(DataViewBase oldView, DataViewBase newView)
 {
     if (oldView != null)
     {
         oldView.ShowFilterPopup -= OnViewShowFilterPopup;
     }
     if (newView != null)
     {
         newView.ShowFilterPopup -= OnViewShowFilterPopup;
         newView.ShowFilterPopup += OnViewShowFilterPopup;
     }
 }
Esempio n. 9
0
        private void Contacts_OnSelectedRowsChanged()
        {
            List <int> selectedRows = DataViewBase.RangesToRows(Contacts.GetSelectedRows());

            if (selectedRows.Count == 1)
            {
                AllowOpen.SetValue(true);
            }
            else
            {
                AllowOpen.SetValue(false);
            }
        }
Esempio n. 10
0
                protected DataViewCursorBase(IHostEnvironment env, DataViewBase <TRow> dataView,
                                             Func <int, bool> predicate)
                    : base(env, dataView.Schema, dataView._schemaDefn, dataView._peeks, predicate)
                {
                    Contracts.AssertValue(env);
                    Ch = env.Start("Cursor");
                    Ch.AssertValue(dataView);
                    Ch.AssertValue(predicate);

                    DataView  = dataView;
                    _position = -1;
                    State     = CursorState.NotStarted;
                }
Esempio n. 11
0
        void View_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            Point position = e.GetPosition(null);

            if (this.startDrag && e.LeftButton == MouseButtonState.Pressed && IsGridRowAvailable(e) && (Math.Abs(position.X - this.startPoint.X) > SystemParameters.MinimumHorizontalDragDistance ||
                                                                                                        Math.Abs(position.Y - this.startPoint.Y) > SystemParameters.MinimumVerticalDragDistance))
            {
                DataViewBase view          = grdTasks.View;
                int          rowHandler    = view.GetRowHandleByMouseEventArgs(e);
                object       schedulerData = GetSchedulerData(rowHandler);
                this.startDrag = false;
                DragDropEffects de = DragDrop.DoDragDrop(grdTasks, schedulerData, DragDropEffects.Move);
            }
            this.startPoint = e.GetPosition(null);
        }
Esempio n. 12
0
        public void DeleteSelectedCommand()
        {
            List <int> selectedRows = DataViewBase.RangesToRows(Contacts.GetSelectedRows());

            if (selectedRows.Count == 0)
            {
                return;
            }
            Utility.ConfirmDialog(
                String.Format(ResourceStrings.ConfirmDeleteSelectedConnection, selectedRows.Count),
                delegate()
            {
                Delete_(selectedRows);
            }, null);
        }
Esempio n. 13
0
 public DemoModuleExportControl(DataViewBase view, bool allowDataAwareExport = true, bool allowWysiwygExport = true, bool allowReport = false)
 {
     ExportCommand = new DelegateCommand <ExportFormat>(Export);
     DataContext   = View = view;
     InitializeComponent();
     if (!allowDataAwareExport)
     {
         dataAwareExportPanel.Visibility = System.Windows.Visibility.Collapsed;
     }
     if (!allowWysiwygExport)
     {
         wysiwygExportPanel.Visibility = System.Windows.Visibility.Collapsed;
         printPreviewButton.Visibility = System.Windows.Visibility.Collapsed;
     }
 }
                protected DataViewCursorBase(IChannelProvider provider, DataViewBase <TRow> dataView,
                                             Func <int, bool> predicate)
                    : base(provider)
                {
                    Ch.AssertValue(dataView);
                    Ch.AssertValue(predicate);

                    DataView  = dataView;
                    _colCount = DataView._schema.SchemaDefn.Columns.Length;

                    _getters = new Delegate[_colCount];
                    for (int i = 0; i < _colCount; i++)
                    {
                        _getters[i] = predicate(i) ? CreateGetter(i) : null;
                    }
                }
Esempio n. 15
0
        public static GridViewHitInfoBase CalcHitInfo(this DataViewBase source, DependencyObject target)
        {
            switch (source)
            {
            case TableView view:
                return(view.CalcHitInfo(target));

            case TreeListView view:
                return(view.CalcHitInfo(target));

            case CardView view:
                return(view.CalcHitInfo(target));

            default:
                return(null);
            }
        }
        public static List <object> GetRowImages(DataViewBase view)
        {
            List <object> images = new List <object>();

            foreach (int rowHandle in view.DataControl.GetSelectedRowHandles())
            {
                FrameworkElement element = view.GetRowElementByRowHandle(rowHandle);
                if (element != null)
                {
                    element = VisualTreeHelper.GetChild(element, 0) as FrameworkElement;
                    RenderTargetBitmap bmp = new RenderTargetBitmap((int)element.ActualWidth, (int)element.ActualHeight, 96, 96, PixelFormats.Pbgra32);
                    bmp.Render(element);
                    images.Add(new Image()
                    {
                        ImageSource = bmp, Width = element.ActualWidth, Height = element.ActualHeight
                    });
                }
            }
            return(images);
        }
Esempio n. 17
0
        public static void SetUpGrids(TimeSheetViewModel vm)
        {
            GridOptions daysGridOpts = new GridOptions();

            daysGridOpts.EnableCellNavigation = true;
            daysGridOpts.EnableColumnReorder  = false;
            daysGridOpts.AutoEdit             = false;
            daysGridOpts.Editable             = true;
            daysGridOpts.RowHeight            = 20;
            daysGridOpts.HeaderRowHeight      = 25;
            daysGridOpts.ForceFitColumns      = false;
            daysGridOpts.EnableAddRow         = true;



            // Create Timesheet Grid
            DataViewBase daysDataView = vm.Days;

            List <Column> columns = new List <Column>();

            GridDataViewBinder.BindRowIcon(GridDataViewBinder.AddColumn(columns, "", 50, "icon"), "activity");
            XrmLookupEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Activity", 300, "activity"), vm.ActivitySearchCommand, "activityid", "subject", "activitytypecode");

            GridDataViewBinder.AddColumn(columns, "Mon", 50, "day0");
            GridDataViewBinder.AddColumn(columns, "Tue", 50, "day1");
            GridDataViewBinder.AddColumn(columns, "Wed", 50, "day2");
            GridDataViewBinder.AddColumn(columns, "Thu", 50, "day3");
            GridDataViewBinder.AddColumn(columns, "Fri", 50, "day4");
            GridDataViewBinder.AddColumn(columns, "Sat", 50, "day5");
            GridDataViewBinder.AddColumn(columns, "Sun", 50, "day6");

            daysGrid = new Grid("#timesheetGridContainer", daysDataView, columns, daysGridOpts);

            GridDataViewBinder daysDataBinder = new GridDataViewBinder();

            daysDataBinder.DataBindEvents(daysGrid, daysDataView, "timesheetGridContainer");

            // Set the totals row meta data
            daysDataView.OnGetItemMetaData += delegate(object item)
            {
                DayEntry day = (DayEntry)item;
                if (day != null && day.isTotalRow)
                {
                    ItemMetaData metaData = new ItemMetaData();
                    metaData.Editor    = null;
                    metaData.Formatter = delegate(int row, int cell, object value, Column columnDef, object dataContext)
                    {
                        if (columnDef.Field == "activity")
                        {
                            return("Total");
                        }
                        else
                        {
                            return(Formatters.DefaultFormatter(row, cell, value, columnDef, dataContext));
                        }
                    };
                    metaData.CssClasses = "days_total_row";
                    return(metaData);
                }

                else
                {
                    return(null);
                }
            };

            daysDataBinder.DataBindSelectionModel(daysGrid, daysDataView);


            // ---------------------------------------
            // Sessions Grid
            // ---------------------------------------
            DataViewBase sessionsDataView = vm.SessionDataView;

            List <Column> sessionGridCols = new List <Column>();

            GridDataViewBinder.AddEditIndicatorColumn(sessionGridCols);

            XrmTextEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Description", 200, "dev1_description"));

            XrmDateEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Date", 200, "dev1_starttime"), true);

            XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Start", 100, "dev1_starttime")).Validator =
                delegate(object value, object item)
            {
                dev1_session     session      = (dev1_session)item;
                DateTime         newStartTime = (DateTime)value;
                ValidationResult result       = new ValidationResult();

                if (session.dev1_EndTime != null)
                {
                    result.Valid = true;
                    string valueText = (string)value;
                    // Check if the end time is before the start time

                    bool isValid = DateTimeEx.GetTimeDuration(newStartTime) < DateTimeEx.GetTimeDuration(session.dev1_EndTime);

                    result.Valid   = isValid;
                    result.Message = "The start time must be before the end time";
                }
                else
                {
                    result.Valid = true;
                }
                return(result);
            };

            XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "End", 100, "dev1_endtime")).Validator =
                delegate(object value, object item)
            {
                dev1_session session    = (dev1_session)item;
                DateTime     newEndTime = (DateTime)value;

                ValidationResult result = new ValidationResult();

                if (session.dev1_StartTime != null)
                {
                    result.Valid = true;
                    string valueText = (string)value;
                    // Check if the end time is before the start time

                    bool isValid = DateTimeEx.GetTimeDuration(session.dev1_StartTime) < DateTimeEx.GetTimeDuration(newEndTime);

                    result.Valid   = isValid;
                    result.Message = "The end time must be after the start time";
                }
                else
                {
                    result.Valid = true;
                }

                return(result);
            };


            XrmDurationEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Duration", 200, "dev1_duration"));



            GridDataViewBinder sessionsDataBinder = new GridDataViewBinder();

            sessionsGrid = sessionsDataBinder.DataBindXrmGrid(sessionsDataView, sessionGridCols, "sessionsGridContainer", null, true, true);
            sessionsDataBinder.DataBindSelectionModel(sessionsGrid, sessionsDataView);


            daysGrid.OnActiveCellChanged.Subscribe(delegate(EventData e, object args)
            {
                CellSelection activeCell = daysGrid.GetActiveCell();
                if (activeCell != null)
                {
                    if (activeCell.Cell < 2)
                    {
                        // Whole activity is selected
                        vm.Days.SelectedDay = null;
                    }
                    else
                    {
                        vm.Days.SelectedDay = activeCell.Cell - 1;
                    }
                }
            });
        }
        protected override void OnViewChanged(DataViewBase oldValue, DataViewBase newValue)
        {
            base.OnViewChanged(oldValue, newValue);

            if (oldValue != null)
            {
                oldValue.ShowGridMenu -= OnShowGridMenu;
                if (_miShowAutoFilter != null)
                {
                    _miShowAutoFilter.ItemClick -= ShowAutoFilterOnItemClick;
                }
                if (_miShowTotalSummary != null)
                {
                    _miShowTotalSummary.ItemClick -= ShowTotalSummaryOnItemClick;
                }

                _miShowAutoFilter = null;

                var oldView = oldValue as TreeListView;
                if (oldView != null)
                {
                    oldView.RowDoubleClick -= OnViewRowDoubleClick;
                    ItemsSourceChanged     -= OnItemsSourceChanged;
                }
            }

            var newView = newValue as TreeListView;

            if (newView != null)
            {
                newView.ShowGridMenu    += OnShowGridMenu;
                newView.ShowingEditor   += OnShowingEditor;
                newView.ShowFilterPopup += OnShowFilterPopup;

                ApplyPrefomanceSettings();

                // задаем специальный стиль для отображения автофильтра
                var newStyle = new Style(typeof(FilterCellContentPresenter), newView.AutoFilterRowCellStyle);
                newStyle.Setters.Add(new Setter(BackgroundProperty, AutoFilterRowDefaultColor));
                newView.AutoFilterRowCellStyle = newStyle;

                if (!UseStandardGridMenu)
                {
                    newView.ColumnMenuCustomizations.Add(new BarItemSeparator());

                    // добавляем кнопку для отображения автофильтра
                    _miShowAutoFilter = new BarButtonItem {
                        Name = "showAutoFilterItem"
                    };
                    _miShowAutoFilter.ItemClick += ShowAutoFilterOnItemClick;
                    newView.ColumnMenuCustomizations.Add(_miShowAutoFilter);

                    // добавляем кнопку для отображения панели суммирования
                    _miShowTotalSummary = new BarButtonItem {
                        Name = "showTotalSummaryItem"
                    };
                    _miShowTotalSummary.ItemClick += ShowTotalSummaryOnItemClick;
                    newView.ColumnMenuCustomizations.Add(_miShowTotalSummary);
                }

                newView.RowDoubleClick += OnViewRowDoubleClick;
                ItemsSourceChanged     += OnItemsSourceChanged;
            }
        }
Esempio n. 19
0
        public override object GetSidebarContent()
        {
            DataViewBase exportView = GetExportView();

            return(new DemoModuleExportControl(exportView, AllowDataAwareExport && exportView is TableView, AllowWYSIWYGExport, GetReportView() != null));
        }
Esempio n. 20
0
        protected override void OnViewChanged(DataViewBase oldValue, DataViewBase newValue)
        {
            base.OnViewChanged(oldValue, newValue);

            if (oldValue != null)
            {
                oldValue.ShowGridMenu -= OnShowGridMenu;
                if (_miShowAutoFilter != null)
                {
                    _miShowAutoFilter.ItemClick -= ShowAutoFilterOnItemClick;
                }
                if (_miShowTotalSummary != null)
                {
                    _miShowTotalSummary.ItemClick -= ShowTotalSummaryOnItemClick;
                }

                _miShowAutoFilter = null;

                var oldTableView = oldValue as TableView;
                if (oldTableView != null)
                {
                    oldTableView.RowDoubleClick -= TableViewOnRowDoubleClick;
                    ItemsSourceChanged          -= OnItemsSourceChanged;
                }
            }

            var tableView = newValue as TableView;

            if (tableView != null)
            {
                tableView.ShowGridMenu += OnShowGridMenu;

                ApplyPrefomanceSettings();

                // задаем специальный стиль для отображения автофильтра
                var newStyle = new Style(typeof(FilterCellContentPresenter), tableView.AutoFilterRowCellStyle);
                newStyle.Setters.Add(new Setter(BackgroundProperty, Brushes.Yellow));
                newStyle.Setters.Add(new Setter(ForegroundProperty, Brushes.Black));
                tableView.AutoFilterRowCellStyle = newStyle;
                //tableView.AutoFilterRowCellStyle.Setters.Add(new Setter(BackgroundProperty, Colors.Yellow));

                if (!UseStandardGridMenu)
                {
                    tableView.ColumnMenuCustomizations.Add(new BarItemSeparator());

                    // добавляем кнопку для отображения автофильтра
                    _miShowAutoFilter            = new BarButtonItem();
                    _miShowAutoFilter.Name       = "showAutoFilterItem";
                    _miShowAutoFilter.ItemClick += ShowAutoFilterOnItemClick;
                    tableView.ColumnMenuCustomizations.Add(_miShowAutoFilter);

                    // добавляем кнопку для отображения панели суммирования
                    _miShowTotalSummary            = new BarButtonItem();
                    _miShowTotalSummary.Name       = "showTotalSummaryItem";
                    _miShowTotalSummary.ItemClick += ShowTotalSummaryOnItemClick;
                    tableView.ColumnMenuCustomizations.Add(_miShowTotalSummary);
                }

                tableView.RowDoubleClick += TableViewOnRowDoubleClick;
                ItemsSourceChanged       += OnItemsSourceChanged;
            }
        }
 public ItemsGenerationTop10RowsStrategy(DataViewBase view) : base(view)
 {
 }
Esempio n. 22
0
        public static void SetUpGrids(TimeSheetViewModel vm)
        {
            // Create Timesheet Grid
            DataViewBase daysDataView = vm.Days;

            List <Column> columns = new List <Column>();

            GridDataViewBinder.BindRowIcon(GridDataViewBinder.AddColumn(columns, "", 50, "icon"), "activity");
            XrmLookupEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Account", 300, "account"), vm.AccountSeachCommand, "accountid", "name", null);
            XrmLookupEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Regarding", 300, "regardingObjectId"), vm.RegardingObjectSearchCommand, "id", "displayName", null);
            XrmLookupEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Activity", 300, "activity"), vm.ActivitySearchCommand, "activityid", "subject", "activitytypecode");

            string[] daysOfWeek     = new string[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
            int      firstDayOfWeek = OrganizationServiceProxy.OrganizationSettings.WeekStartDayCode.Value.Value;

            GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek], 50, "day0");
            GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 1], 50, "day1");
            GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 2], 50, "day2");
            GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 3], 50, "day3");
            GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 4], 50, "day4");
            GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 5], 50, "day5");
            GridDataViewBinder.AddColumn(columns, daysOfWeek[firstDayOfWeek + 6], 50, "day6");

            GridDataViewBinder daysDataBinder = new GridDataViewBinder();

            daysDataBinder.SelectActiveRow         = true;
            daysDataBinder.AddCheckBoxSelectColumn = false;
            daysGrid = daysDataBinder.DataBindXrmGrid(daysDataView, columns, "timesheetGridContainer", null, true, true);

            // Set the totals row meta data
            daysDataView.OnGetItemMetaData += delegate(object item)
            {
                ItemMetaData metaData = new ItemMetaData();
                DayEntry     day      = (DayEntry)item;
                if (day != null && day.isTotalRow)
                {
                    metaData.Editor               = delegate(EditorArguments args) { return(null); };
                    metaData.Columns              = new Dictionary <object, Column>();
                    metaData.Columns["Account"]   = new Column("editor", null);
                    metaData.Columns["Regarding"] = new Column("editor", null);
                    metaData.Columns["Activity"]  = new Column("editor", null);
                    metaData.Formatter            = delegate(int row, int cell, object value, Column columnDef, object dataContext)
                    {
                        switch (columnDef.Field)
                        {
                        case "account":
                        case "regardingObjectId":
                            return("");

                        case "activity":
                            return("Total");

                        default:
                            return(XrmDurationEditor.Formatter(row, cell, value, columnDef, dataContext));
                        }
                    };

                    metaData.CssClasses = "days_total_row";
                }

                else
                {
                    metaData.Formatter = delegate(int row, int cell, object value, Column columnDef, object dataContext)
                    {
                        switch (columnDef.Field)
                        {
                        case "account":
                        case "regardingObjectId":
                        case "activity":
                            return(XrmLookupEditor.Formatter(row, cell, value, columnDef, dataContext));

                        default:
                            return(XrmDurationEditor.Formatter(row, cell, value, columnDef, dataContext));
                        }
                    };
                }

                return(metaData);
            };

            daysDataBinder.DataBindSelectionModel(daysGrid, daysDataView);


            // ---------------------------------------
            // Sessions Grid
            // ---------------------------------------
            DataViewBase sessionsDataView = vm.SessionDataView;

            List <Column> sessionGridCols = new List <Column>();

            GridDataViewBinder.AddEditIndicatorColumn(sessionGridCols);

            XrmTextEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Activity", 300, "activitypointer_subject")).Editor = null;



            XrmDateEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Date", 100, "dev1_starttime"), true);

            XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Start", 100, "dev1_starttime")).Validator =
                delegate(object value, object item)
            {
                dev1_session     session      = (dev1_session)item;
                DateTime         newStartTime = (DateTime)value;
                ValidationResult result       = new ValidationResult();

                if (session.dev1_EndTime != null)
                {
                    result.Valid = true;
                    string valueText = (string)value;
                    // Check if the end time is before the start time

                    bool isValid = DateTimeEx.GetTimeDuration(newStartTime) < DateTimeEx.GetTimeDuration(session.dev1_EndTime);

                    result.Valid   = isValid;
                    result.Message = "The start time must be before the end time";
                }
                else
                {
                    result.Valid = true;
                }
                return(result);
            };

            XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "End", 100, "dev1_endtime")).Validator =
                delegate(object value, object item)
            {
                dev1_session session    = (dev1_session)item;
                DateTime     newEndTime = (DateTime)value;

                ValidationResult result = new ValidationResult();

                if (session.dev1_StartTime != null)
                {
                    result.Valid = true;
                    string valueText = (string)value;
                    // Check if the end time is before the start time

                    bool isValid = DateTimeEx.GetTimeDuration(session.dev1_StartTime) < DateTimeEx.GetTimeDuration(newEndTime);

                    result.Valid   = isValid;
                    result.Message = "The end time must be after the start time";
                }
                else
                {
                    result.Valid = true;
                }

                return(result);
            };


            XrmDurationEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Duration", 70, "dev1_duration"));
            XrmTextEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Description", 300, "dev1_description"));


            GridDataViewBinder sessionsDataBinder = new GridDataViewBinder();

            sessionsDataBinder.SelectActiveRow         = false;
            sessionsDataBinder.AddCheckBoxSelectColumn = true;

            sessionsGrid = sessionsDataBinder.DataBindXrmGrid(sessionsDataView, sessionGridCols, "sessionsGridContainer", null, true, true);

            sessionsGrid.OnBeforeEditCell.Subscribe(delegate(EventData e, object args)
            {
                // Stop the row from being edited if locked
                Entity item = (Entity)((EditEventData)args).item;
                bool result = sessionsDataView.OnBeforeEdit(item);
                Script.Literal("return {0}", result);
            });

            daysGrid.OnActiveCellChanged.Subscribe(delegate(EventData e, object args)
            {
                CellSelection activeCell = daysGrid.GetActiveCell();
                if (activeCell != null)
                {
                    if (activeCell.Cell < StartDaysColumnIndex)
                    {
                        // Whole activity is selected
                        vm.Days.SelectedDay = null;
                    }
                    else
                    {
                        vm.Days.SelectedDay = activeCell.Cell - (StartDaysColumnIndex - 1);
                    }
                }
            });
        }
Esempio n. 23
0
        public static void init()
        {
            DataGroupingViewModel vm = new DataGroupingViewModel();
            NumberFormatInfo      numberFormatInfo = NumberEx.GetNumberFormatInfo();

            numberFormatInfo.MinValue  = 0;
            numberFormatInfo.MaxValue  = 1000;
            numberFormatInfo.Precision = 2;
            BooleanBindingOptions boolFormatInfo = new BooleanBindingOptions();

            boolFormatInfo.FalseOptionDisplayName = "No";
            boolFormatInfo.TrueOptionDisplayName  = "Yes";

            // Add Columns
            SubTotalsFormatterDelegate sumTotalsFormatterDelegate = SumTotalsFormatter;
            SubTotalsFormatterDelegate avgTotalsFormatterDelegate = AvgTotalsFormatter;
            FormatterDelegate          percentageFormatter        = XrmNumberEditor.Formatter;
            FormatterDelegate          checkboxFormatter          = XrmBooleanEditor.Formatter;

            List <Column> columns = new List <Column>(
                new Column(
                    ColumnProperties.Id, "sel",
                    ColumnProperties.Name, "#",
                    ColumnProperties.Field, "num",
                    ColumnProperties.CssClass, "cell-selection",
                    ColumnProperties.Width, 40,
                    ColumnProperties.Resizable, false,
                    ColumnProperties.Selectable, false,
                    ColumnProperties.Focusable, false),
                new Column(
                    ColumnProperties.Id, "title",
                    ColumnProperties.Name, "Title",
                    ColumnProperties.Field, "title",
                    ColumnProperties.Width, 70,
                    ColumnProperties.MinWidth, 50,
                    ColumnProperties.CssClass, "cell-title",
                    ColumnProperties.Sortable, true,
                    ColumnProperties.Editor, XrmTextEditor.TextEditor),
                new Column(
                    ColumnProperties.Id, "duration",
                    ColumnProperties.Name, "Duration",
                    ColumnProperties.Field, "duration",
                    ColumnProperties.Width, 70,
                    ColumnProperties.Sortable, true,
                    ColumnProperties.GroupTotalsFormatter, sumTotalsFormatterDelegate),
                new Column(
                    ColumnProperties.Id, "%",
                    ColumnProperties.Name, "% Complete",
                    ColumnProperties.Field, "percentComplete",
                    ColumnProperties.Width, 80,
                    ColumnProperties.Formatter, percentageFormatter,
                    ColumnProperties.Options, numberFormatInfo,
                    ColumnProperties.Sortable, true,
                    ColumnProperties.GroupTotalsFormatter, avgTotalsFormatterDelegate),
                new Column(
                    ColumnProperties.Id, "start",
                    ColumnProperties.Name, "Start",
                    ColumnProperties.Field, "start",
                    ColumnProperties.MinWidth, 60,
                    ColumnProperties.Sortable, true),
                new Column(
                    ColumnProperties.Id, "finish",
                    ColumnProperties.Name, "Finish",
                    ColumnProperties.Field, "finish",
                    ColumnProperties.MinWidth, 60,
                    ColumnProperties.Sortable, true),
                new Column(
                    ColumnProperties.Id, "cost",
                    ColumnProperties.Name, "Cost",
                    ColumnProperties.Field, "cost",
                    ColumnProperties.Width, 90,
                    ColumnProperties.Sortable, true,
                    ColumnProperties.GroupTotalsFormatter, sumTotalsFormatterDelegate),
                new Column(
                    ColumnProperties.Id, "effort-driven",
                    ColumnProperties.Name, "Effort Driven",
                    ColumnProperties.Width, 80,
                    ColumnProperties.MinWidth, 20,
                    ColumnProperties.CssClass, "cell-effort-driven",
                    ColumnProperties.Field, "effortDriven",
                    ColumnProperties.Formatter, checkboxFormatter,
                    ColumnProperties.Options, boolFormatInfo,
                    ColumnProperties.Sortable, true)
                );

            GridOptions options = new GridOptions();

            options.EnableCellNavigation = true;
            options.Editable             = true;
            DataViewBase view = (DataViewBase)(object)vm.Projects;

            GridDataViewBinder binder = new GridDataViewBinder();
            Grid grid = binder.DataBindDataViewGrid(vm.Projects, columns, "myGrid", null, true, false);

            // register the group item metadata provider to add expand/collapse group handlers
            grid.RegisterPlugin(new GroupItemMetadataProvider());

            // Data Bind
            ViewBase.RegisterViewModel(vm);
        }
        public void SetUp()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.serviceLocator       = new Mock <IServiceLocator>();

            var treeList = new TreeListControl {
                View = new TreeListView()
            };

            this.dataViewBase      = treeList.View;
            this.dataViewBase.Name = "DataViewBase";

            this.dialogNavigationService = new Mock <IDialogNavigationService>();
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IDialogNavigationService>()).Returns(this.dialogNavigationService.Object);

            this.savedUserPreferenceService = new Mock <ISavedUserPreferenceService>();
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <ISavedUserPreferenceService>()).Returns(this.savedUserPreferenceService.Object);

            this.session = new Mock <ISession>();

            this.category1 = new Category(Guid.NewGuid(), null, null)
            {
                Name = CategoryName1
            };

            this.category2 = new Category(Guid.NewGuid(), null, null)
            {
                Name = CategoryName2
            };

            this.parentRow = new CategoryTestRowViewModel(this.category1, this.session.Object, null);
            this.childRow  = new CategoryTestRowViewModel(this.category2, this.session.Object, this.parentRow);

            this.parentRow.ContainedRows.Add(this.childRow);

            this.filterEditorQueryOperatorsEventArgs =
                this.CreateInstance <FilterEditorQueryOperatorsEventArgs>(CriteriaOperator.And(), nameof(CategoryTestRowViewModel.Category));

            var filterEditorOperatorItem = new List <FilterEditorOperatorItem>
            {
                new FilterEditorOperatorItem(FilterEditorOperatorType.AboveAverage),
                new FilterEditorOperatorItem(FilterEditorOperatorType.Equal),
                new FilterEditorOperatorItem(FilterEditorOperatorType.Greater),
                new FilterEditorOperatorItem(FilterEditorOperatorType.AnyOf)
            };

            this.filterEditorOperatorItemList = this.CreateInstance <FilterEditorOperatorItemList>(filterEditorOperatorItem);
            this.filterEditorQueryOperatorsEventArgs.Operators = this.filterEditorOperatorItemList;

            this.customFilterOperatorsViewModel = new Mock <IHaveCustomFilterOperators>();

            var customFilterOperators = new Dictionary <DataViewBase, Dictionary <string, (CustomFilterOperatorType, IEnumerable <IRowViewModelBase <Thing> >)> >();
            var browserDictionary     = new Dictionary <string, (CustomFilterOperatorType, IEnumerable <IRowViewModelBase <Thing> >)>();

            browserDictionary.Add(nameof(CategoryTestRowViewModel.Category), (CustomFilterOperatorType.Category, new [] { this.parentRow }));

            customFilterOperators.Add(this.dataViewBase, browserDictionary);

            this.customFilterOperatorsViewModel.Setup(x => x.CustomFilterOperators).Returns(customFilterOperators);

            this.dataViewBase.DataContext = this.customFilterOperatorsViewModel.Object;
        }
 public CustomColumnChooser(DataViewBase ownerView)
 {
     Owner = ownerView;
 }
Esempio n. 26
0
 public static void SetViewMirror(DependencyObject d, DataViewBase value)
 {
     d.SetValue(ViewMirrorProperty, value);
 }
Esempio n. 27
0
        public Action DeleteCommand()
        {
            if (_deleteCommand == null)
            {
                _deleteCommand = delegate()
                {
                    List <int> selectedRows = DataViewBase.RangesToRows(this.SessionDataView.GetSelectedRows());
                    if (selectedRows.Count == 0)
                    {
                        return;
                    }

                    bool confirmed = Script.Confirm(String.Format("Are you sure you want to delete the {0} selected sessions?", selectedRows.Count));
                    if (!confirmed)
                    {
                        return;
                    }


                    IsBusyMessage.SetValue("Deleting Sessions...");
                    IsBusyProgress.SetValue(0);
                    IsBusy.SetValue(true);

                    // Get each item to remove
                    List <dev1_session> itemsToDelete = new List <dev1_session>();
                    for (int i = 0; i < selectedRows.Count; i++)
                    {
                        itemsToDelete.Add((dev1_session)this.SessionDataView.GetItem(i));
                    }
                    DelegateItterator.CallbackItterate(delegate(int index, Action nextCallback, ErrorCallBack errorCallBack)
                    {
                        dev1_session session = itemsToDelete[index];
                        IsBusyProgress.SetValue((index / selectedRows.Count) * 100);
                        OrganizationServiceProxy.BeginDelete(session.LogicalName, session.dev1_sessionId, delegate(object result)
                        {
                            try
                            {
                                OrganizationServiceProxy.EndDelete(result);
                                this.SessionDataView.RemoveItem(session);
                                this.SessionDataView.Refresh();
                                nextCallback();
                            }
                            catch (Exception ex)
                            {
                                Script.Alert(ex.Message);
                                nextCallback();
                            }
                        });
                    },
                                                       selectedRows.Count,
                                                       delegate()
                    {
                        // Complete
                        IsBusyProgress.SetValue(100);
                        IsBusy.SetValue(false);
                        SessionDataView.Refresh();
                        Days.ReCalculate();
                    },
                                                       delegate(Exception ex)
                    {
                        ReportError(ex);
                    }
                                                       );
                };
            }
            return(_deleteCommand);
        }
        public override PropertyDefinitionBase GetDefinition(DataController controller, 
      DataViewBase view, RowHandle handle, bool showCategories, bool getStandard = true)
        {
            PropertyDefinitionBase result = base.GetDefinition(controller, view, handle, showCategories, getStandard);

              if (result is PropertyDefinition)
              {
            PropertyInfo propertyInfo = propertyGridControl.SelectedObject.GetType().GetProperty(view.GetDisplayName(handle));
            if (propertyInfo != null)
            {
              EditorAttribute attribute = (EditorAttribute)propertyInfo.GetCustomAttributes(typeof(EditorAttribute), true).FirstOrDefault();
              // Также ищем вспомогательный атрибут с дополнительной информацией.
              EditorInfoAttribute attributeInfo = (EditorInfoAttribute)propertyInfo.GetCustomAttributes(typeof(EditorInfoAttribute), true).FirstOrDefault();
              if (attribute != null)
              {
            string info = attributeInfo != null ? attributeInfo.Info : null;
            BaseEditSettings settings = AttributesDispatcher.GetSettings(attribute.EditorTypeName, info, propertyGridControl, WixDataSource);
            if (settings != null)
              ((PropertyDefinition)result).EditSettings = settings;
              }
            }
              }
              return result;
        }