예제 #1
0
        private async void DtGrid_Loaded(object sender, RoutedEventArgs e)
        {
            if (columnDictionary.Count == 0 && DataContext != null)
            {
                var ddd   = (DataContext as ICRUDViewModel).DtGridProperties;
                var items = (DataContext as ICRUDViewModel).DtGridProperties.Split(';');
                foreach (string item in items)
                {
                    string[] keyValue = item.Split('=');
                    if (keyValue[0] != "")
                    {
                        columnDictionary.Add(keyValue[0], keyValue[1]);
                    }
                }
            }

            foreach (var item in columnDictionary)
            {
                if (item.Value == "false")
                {
                    try
                    {
                        var column = ButtonMenuContentItemList.Where(p => p.HeaderName == item.Key).Single();
                        column.IsChecked = false;
                        DtGrid.Columns.Where(p => p.Header.ToString() == column.HeaderName).Single().Visibility = Visibility.Collapsed;
                    }
                    catch { }
                }
            }

            await SetDtGridLastColumnWidth();
        }
예제 #2
0
 private void AddNewColumnToDataGrid(string headerName, string bindingProperty)
 {
     DtGrid.Columns.Add(new DataGridTextColumn {
         Header = headerName, Binding = new Binding(bindingProperty)
     });
     ButtonMenuContentItemList.Add(new DataGridColumnPropertyItem {
         HeaderName = headerName, IsChecked = true
     });
     SearchPropertyItemList.Add(new DataGridColumnPropertyItem {
         HeaderName = headerName, IsChecked = true
     });
 }
예제 #3
0
        private void DataGrid_AutoGeneratedColumns(object sender, EventArgs e)
        {
            ButtonMenuContentItemList.Clear();
            SearchPropertyItemList.Clear();
            ButtonMenuContentItemList.Add(new DataGridColumnPropertyItem {
                HeaderName = "Deselect All", IsChecked = true
            });

            foreach (DataGridColumn d in DtGrid.Columns)
            {
                ButtonMenuContentItemList.Add(new DataGridColumnPropertyItem {
                    HeaderName = d.Header.ToString(), IsChecked = true
                });
                SearchPropertyItemList.Add(new DataGridColumnPropertyItem {
                    HeaderName = d.Header.ToString(), IsChecked = true
                });
            }


            if (DtGrid.DataContext is CustomerViewModel)
            {
                AddNewColumnToDataGrid("Customer Rank", "CustomerRank.Name");

                SearchPropertyItemList.RemoveAt(4); //Remove address1
                SearchPropertyItemList.RemoveAt(4); //Remove address2
                SearchPropertyItemList.Insert(4, new DataGridColumnPropertyItem {
                    HeaderName = "Address"
                });
            }

            if (DtGrid.DataContext is CustomerRankViewModel)
            {
                AddNewColumnToDataGrid("Number of Customers", "Customers.Count");
            }

            if (DtGrid.DataContext is CategoryViewModel)
            {
                AddNewColumnToDataGrid("Number of Products", "Products.Count");
            }

            if (DtGrid.DataContext is ProductViewModel)
            {
                AddNewColumnToDataGrid("Category", "Category.Name");
            }

            if (DtGrid.DataContext is GoodsReceiptViewModel)
            {
                AddNewColumnToDataGrid("Items Count", "ReceiptDetails.Count");
                AddNewColumnToDataGrid("Purchased In Store", "Store.Name");
            }

            var context = (DataContext as ICRUDViewModel);

            if (context.DtGridProperties == "Default")
            {
                context.DtGridProperties = "";
                foreach (var item in DtGrid.Columns)
                {
                    context.DtGridProperties += item.Header + "=true;";
                }
            }
        }