Exemple #1
0
        private async Task <FrameworkElement> BuildChildRecordDataGrid(IReferenceDataSource dataSource, object[] keyValues, CancellationToken cancellationToken)
        {
            var executionModel  = dataSource.CreateExecutionModel(keyValues);
            var executionResult = await _outputViewer.ConnectionAdapter.ExecuteChildStatementAsync(executionModel, cancellationToken);

            var childReferenceDataSources = await _outputViewer.StatementValidator.ApplyReferenceConstraintsAsync(executionResult, _outputViewer.ConnectionAdapter.DatabaseModel, cancellationToken);

            var resultInfo = executionResult.ResultInfoColumnHeaders.Keys.Last();
            var resultSet  = await _outputViewer.ConnectionAdapter.FetchRecordsAsync(resultInfo, ConfigurationProvider.Configuration.ResultGrid.FetchRowsBatchSize, cancellationToken);

            var childRecordDataGrid =
                new DataGrid
            {
                RowHeaderWidth = 0,
                Style          = (Style)Application.Current.Resources["ResultSetDataGrid"],
                ItemsSource    = new ObservableCollection <object[]>(resultSet)
            };

            childRecordDataGrid.AddHandler(VirtualizingStackPanel.CleanUpVirtualizedItemEvent, (CleanUpVirtualizedItemEventHandler)CleanUpVirtualizedItemHandler);
            childRecordDataGrid.BeginningEdit += App.DataGridBeginningEditCancelTextInputHandlerImplementation;
            childRecordDataGrid.RowStyle       = (Style)Resources["DataGridRowStyle"];

            var columnHeaders = executionResult.ResultInfoColumnHeaders.Values.Last();

            DataGridHelper.InitializeDataGridColumns(childRecordDataGrid, columnHeaders, _outputViewer.StatementValidator, _outputViewer.ConnectionAdapter);
            AddChildReferenceColumns(childRecordDataGrid, childReferenceDataSources);

            foreach (var columnTemplate in childRecordDataGrid.Columns)
            {
                columnTemplate.HeaderStyle = (Style)Application.Current.Resources["ColumnHeaderClickBubbleCancelation"];
            }

            return(childRecordDataGrid);
        }
Exemple #2
0
        public MainDataView()
        {
            this.InitializeComponent();

            DataGrid _DataGrid = this.FindControl <DataGrid>("mainDataGrid");

            _DataGrid.IsReadOnly = true;
            _DataGrid.AddHandler(DragDrop.DropEvent, Drop);

            var items = _DataGrid.Items;
        }
Exemple #3
0
 /// <summary>
 /// datagrid表格拖动
 /// </summary>
 /// <param name="dataGrid">表格对象</param>
 /// <param name="collection">模型队列</param>
 public DatagridDropHelper(DataGrid dataGrid, ObservableCollection <T> collection)
 {
     datagrid         = dataGrid;
     sourceCollection = collection;
     //设置为true可能会导致checkbox无法选择
     datagrid.AddHandler(InkCanvas.MouseLeftButtonDownEvent, new MouseButtonEventHandler(dg_PreviewMouseLeftButtonDown), false);
     //The Event on DataGrid for selecting the Row
     //this.datagrid.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(dg_PreviewMouseLeftButtonDown);
     //this.datagrid.MouseLeftButtonDown += new MouseButtonEventHandler(dg_PreviewMouseLeftButtonDown);
     //The Drop Event
     this.datagrid.Drop += new DragEventHandler(dg_Drop);
 }
        /// <summary>
        /// Called when the edit cells with a single click mode property is changed.
        /// </summary>
        /// <param name="dependencyObject">The dependency object.</param>
        /// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void OnIsSingleClickEditPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
        {
            DataGrid dataGrid = (DataGrid)dependencyObject;

            if (GetIsSingleClickEdit(dataGrid))
            {
                dataGrid.AddHandler(DataGridCell.GotFocusEvent, new RoutedEventHandler(OnDataGridCellGotFocus));
            }
            else
            {
                dataGrid.RemoveHandler(DataGridCell.GotFocusEvent, new RoutedEventHandler(OnDataGridCellGotFocus));
            }
        }
Exemple #5
0
        private static void AssociatedDataGridPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            // Gestion des synchonisations des colonnes
            DataGrid dgSource = (DataGrid)sender;

            Maindg = dgSource;

            DataGrid dgBottom = GetBottom(dgSource);
            DataGrid dgTop    = GetTop(dgSource);
            DataGrid dgLeft   = GetLeft(dgSource);
            DataGrid dgRight  = GetRight(dgSource);

            //CreateAssociatedColumns(dgSource, dgBottom);
            if ((dgBottom == null) &&
                (dgTop == null) &&
                (dgLeft == null) &&
                (dgRight == null))
            {
                dgSource.RemoveHandler(ScrollViewer.ScrollChangedEvent, new RoutedEventHandler(xDataGrid_ScrollChanged));
            }
            else
            {
                dgSource.AddHandler(ScrollViewer.ScrollChangedEvent, new RoutedEventHandler(xDataGrid_ScrollChanged));
            }

            if (dgBottom != null)
            {
                dgBottom.Loaded += dgBottom_Loaded;
                SynchronizeVerticalDataGrid(dgSource, dgBottom);
                dgBottom.AddHandler(ScrollViewer.ScrollChangedEvent, new RoutedEventHandler(yDataGrid_ScrollChanged));
            }


            if (dgTop != null)
            {
                SynchronizeVerticalDataGrid(dgSource, dgTop);
            }
            if (dgRight != null)
            {
                SynchronizeHorizontalDataGrid(dgSource, dgRight);
            }
            if (dgLeft != null)
            {
                SynchronizeHorizontalDataGrid(dgSource, dgLeft);
            }
        }
Exemple #6
0
        /// <summary>
        /// 数据集合视图初始化
        /// </summary>
        /// <param name="datagrid">DataGrid</param>
        /// <param name="lists">数据</param>
        /// <param name="pageSize">一页所显示的数据</param>
        public void listInit(DataGrid datagrid, IList lists, int pageSize)
        {
            try
            {
                #region 添加加载页功能

                datagrid.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(datagrid_ScrollChanged));
                timer.Interval = TimeSpan.FromSeconds(1);
                timer.Tick    += new EventHandler(timer_Tick);

                #endregion

                this.IntPageSize = pageSize;
                ListCollectionView coll = new ListCollectionView(lists);
                this.Collection = coll;

                if (Collection != null)
                {
                    #region datapager初始化
                    //当前页
                    this.intPageNow = 1;
                    //总页数
                    this.intPageCount = 0;
                    //数据源
                    this.list.Clear();
                    //总页数数量显示
                    //this.txtCount.Text = "1";
                    //当前页显示
                    //this.txtNow.Text = "1";

                    #endregion
                    //填充数据源
                    for (int i = 0; i < collection.Count; i++)
                    {
                        list.Add(collection.GetItemAt(i));
                    }

                    //清除分配数据
                    ClearAll();

                    //如果分页的数量比总数量小的话,直接传分页的数量
                    if (IntPageSize < list.Count)
                    {
                        for (int i = 0; i < IntPageSize; i++)
                        {
                            Collection.AddNewItem(list[i]);
                        }
                    }
                    //如果分页的数量比总页大的话,直接传总页的数量
                    else
                    {
                        for (int i = 0; i < list.Count; i++)
                        {
                            Collection.AddNewItem(list[i]);
                        }
                    }

                    #region 设置信息显示(总页数,当前页位置)

                    //获取总页数
                    intPageCount = (int)Math.Ceiling((double)list.Count / IntPageSize);

                    //this.txtCount.Text = intPageCount.ToString();
                    //当前页
                    //this.txtNow.Text = intPageNow.ToString();
                    txtAllcount.Text = list.Count.ToString();

                    #endregion

                    Collection.AddNewItem(null);
                    Collection.CancelNew();
                }
                datagrid.ItemsSource = coll;
            }
            catch (Exception ex)
            {
                MethodLb.CreateLog(this.GetType().FullName, "listInit", ex.ToString());
            }
            finally
            {
            }
        }
        private void refreshData()
        {
            foreach (TabItem item in mainTabs.Items)
            {
                stopEdit((DataGrid)item.Content);   //f*****g WPF
            }
            mainTabs.Items.Clear();
            int index = 0;

            for (int i = 0; i < parser.datasets.Count; ++i)
            {
                TabDataset dataset = parser.datasets[i];
                if (dataset.hidden)
                {
                    continue;
                }
                TabItem tab = new TabItem();
                tab.Header    = dataset.name;
                dataset.index = index++;

                DataGrid grid = new DataGrid();
                grid.AddHandler(UIElement.LostFocusEvent, (RoutedEventHandler)lostFocus);    //enables single click edit
                grid.AddHandler(UIElement.GotFocusEvent, (RoutedEventHandler)gotFocus);      //enables single click edit
                grid.AddHandler(UIElement.PreviewKeyDownEvent, (RoutedEventHandler)keyDown); //enables Enter to commit edit, edit cell below
                grid.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
                grid.VerticalAlignment   = System.Windows.VerticalAlignment.Stretch;
                grid.AutoGenerateColumns = false;
                //grid.Name                = dataset.name;

                for (int j = 0; j < dataset.factory.index; ++j)
                {
                    Attribute att = dataset.attributes[j];
                    if (att.hidden)
                    {
                        continue;
                    }
                    DataGridTextColumn col = new DataGridTextColumn();
                    col.Header     = att.friendlyName;
                    col.IsReadOnly = !att.editable;

                    if (att.type == typeof(float))
                    {
                        col.Binding = new Binding("floats[" + att.index.ToString() + "]");
                    }
                    else if (att.type == typeof(int) || att.type == typeof(short) || att.type == typeof(char))
                    {
                        col.Binding = new Binding("ints[" + att.index.ToString() + "]");
                    }
                    else if (att.type == typeof(string))
                    {
                        col.Binding = new Binding("strings[" + att.index.ToString() + "]");
                    }

                    grid.Columns.Add(col);
                }

                grid.ItemsSource = dataset.data;
                tab.Content      = grid;
                mainTabs.Items.Add(tab);
            }
        }