示例#1
0
        public GridNumericColumn AddNumericColumn(string dataField, string headerText)
        {
            GridNumericColumn c = new GridNumericColumn();

            _grid.MasterTableView.Columns.Add(c);
            SetBoundColumn(c, dataField, headerText, false);
            c.NumericType      = NumericType.Number;
            c.DataType         = typeof(int);
            c.DecimalDigits    = 0;
            c.DataFormatString = "{0:N0}";
            return(c);
        }
 protected void RadGrid1_ColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e)
 {
     if (e.Column is GridBoundColumn)
     {
         GridBoundColumn   boundColumn = e.Column as GridBoundColumn;
         GridNumericColumn numCol      = boundColumn as GridNumericColumn;
         if (numCol != null)
         {
             numCol.DataFormatString            = "{0:N0}";
             numCol.Aggregate                   = GridAggregateFunction.Sum;
             numCol.FooterAggregateFormatString = "{0:N0}";
         }
     }
 }
示例#3
0
        public override View GetSampleContent(Context context)
        {
            sfGrid    = new SfDataGrid(context);
            viewmodel = new EditingViewModel();
            sfGrid.AutoGenerateColumns    = false;
            sfGrid.RowHeight              = 50;
            sfGrid.AllowEditing           = true;
            sfGrid.EditTapAction          = TapAction.OnTap;
            sfGrid.ColumnSizer            = ColumnSizer.Star;
            sfGrid.SelectionMode          = SelectionMode.Single;
            sfGrid.NavigationMode         = NavigationMode.Cell;
            sfGrid.HeaderRowHeight        = 40;
            sfGrid.ItemsSource            = viewmodel.DealerInformation;
            sfGrid.VerticalOverScrollMode = VerticalOverScrollMode.None;

            GridNumericColumn productPrice = new GridNumericColumn();

            productPrice.MappingName         = "ProductPrice";
            productPrice.HeaderText          = "Product Price";
            productPrice.HeaderTextAlignment = GravityFlags.Center;

            GridDateTimeColumn shippedDate = new GridDateTimeColumn();

            shippedDate.MappingName         = "ShippedDate";
            shippedDate.HeaderText          = "Shipped Date";
            shippedDate.HeaderTextAlignment = GravityFlags.Center;
            shippedDate.Format = "d";

            GridPickerColumn dealerName = new GridPickerColumn();

            dealerName.MappingName         = "DealerName";
            dealerName.HeaderText          = "Dealer Name";
            dealerName.ItemsSource         = viewmodel.CustomerNames;
            dealerName.HeaderTextAlignment = GravityFlags.Center;

            GridTextColumn productNo = new GridTextColumn();

            productNo.MappingName         = "ProductNo";
            productNo.HeaderText          = "Product No";
            productNo.HeaderTextAlignment = GravityFlags.Center;

            sfGrid.Columns.Add(productNo);
            sfGrid.Columns.Add(dealerName);
            sfGrid.Columns.Add(shippedDate);
            sfGrid.Columns.Add(productPrice);

            return(sfGrid);
        }
        public Form1()
        {
            InitializeComponent();

            sfDataGrid.AutoGenerateColumns = false;
            sfDataGrid.DataSource          = new ViewModel().Orders;
            sfDataGrid.LiveDataUpdateMode  = LiveDataUpdateMode.AllowDataShaping;
            sfDataGrid.AllowEditing        = true;
            sfDataGrid.AutoSizeColumnsMode = AutoSizeColumnsMode.AllCells;
            sfDataGrid.AddNewRowPosition   = RowPosition.Top;
            GridNumericColumn gridTextColumn1 = new GridNumericColumn()
            {
                MappingName = "OrderID", HeaderText = "Order ID"
            };
            GridTextColumn gridTextColumn2 = new GridTextColumn()
            {
                MappingName = "CustomerID", HeaderText = "Customer ID", AllowEditing = true
            };
            GridTextColumn gridTextColumn3 = new GridTextColumn()
            {
                MappingName = "CustomerName", HeaderText = "Customer Name"
            };
            GridTextColumn gridTextColumn4 = new GridTextColumn()
            {
                MappingName = "Country", HeaderText = "Country"
            };
            GridTextColumn gridTextColumn5 = new GridTextColumn()
            {
                MappingName = "ShipCity", HeaderText = "Ship City"
            };
            GridCheckBoxColumn checkBoxColumn = new GridCheckBoxColumn()
            {
                MappingName = "IsShipped", HeaderText = "Is Shipped"
            };

            // enable the context menu for new records
            sfDataGrid.RecordContextMenu = new ContextMenuStrip();
            sfDataGrid.RecordContextMenu.Items.Add("Copy", null, OnBuscarMenuClicked);

            sfDataGrid.Columns.Add(gridTextColumn1);
            sfDataGrid.Columns.Add(gridTextColumn2);
            sfDataGrid.Columns.Add(gridTextColumn3);
            sfDataGrid.Columns.Add(gridTextColumn4);
            sfDataGrid.Columns.Add(gridTextColumn5);
            sfDataGrid.Columns.Add(checkBoxColumn);
            sfDataGrid.TableControl.MouseUp += SfDataGrid_MouseUp;
        }
示例#5
0
        public Editing()
        {
            sfGrid    = new SfDataGrid();
            viewmodel = new EditingViewModel();
            sfGrid.AutoGenerateColumns = false;
            sfGrid.RowHeight           = 50;
            sfGrid.AllowEditing        = true;
            sfGrid.SelectionMode       = SelectionMode.Single;
            sfGrid.NavigationMode      = NavigationMode.Cell;
            sfGrid.EditTapAction       = TapAction.OnTap;
            sfGrid.ColumnSizer         = ColumnSizer.Star;
            sfGrid.HeaderRowHeight     = 40;
            sfGrid.ItemsSource         = viewmodel.DealerInformation;

            GridNumericColumn productPrice = new GridNumericColumn();

            productPrice.MappingName         = "ProductPrice";
            productPrice.HeaderText          = "Product Price";
            productPrice.HeaderTextAlignment = UIKit.UITextAlignment.Center;

            GridDateTimeColumn shippedDate = new GridDateTimeColumn();

            shippedDate.MappingName         = "ShippedDate";
            shippedDate.HeaderText          = "Shipped Date";
            shippedDate.Format              = "d";
            shippedDate.HeaderTextAlignment = UIKit.UITextAlignment.Center;

            GridPickerColumn dealerName = new GridPickerColumn();

            dealerName.MappingName         = "DealerName";
            dealerName.HeaderText          = "Dealer Name";
            dealerName.ItemsSource         = viewmodel.CustomerNames;
            dealerName.HeaderTextAlignment = UIKit.UITextAlignment.Center;

            GridTextColumn productNo = new GridTextColumn();

            productNo.MappingName         = "ProductNo";
            productNo.HeaderText          = "Product No";
            productNo.HeaderTextAlignment = UIKit.UITextAlignment.Center;

            sfGrid.Columns.Add(productNo);
            sfGrid.Columns.Add(dealerName);
            sfGrid.Columns.Add(shippedDate);
            sfGrid.Columns.Add(productPrice);
            this.AddSubview(sfGrid);
        }
示例#6
0
        public Form1()
        {
            InitializeComponent();

            sfDataGrid.AutoGenerateColumns = false;
            sfDataGrid.DataSource          = new ViewModel().Orders;
            sfDataGrid.LiveDataUpdateMode  = LiveDataUpdateMode.AllowDataShaping;
            sfDataGrid.AllowEditing        = true;

            GridNumericColumn gridTextColumn1 = new GridNumericColumn()
            {
                MappingName = "OrderID", HeaderText = "Order ID"
            };
            GridTextColumn gridTextColumn2 = new GridTextColumn()
            {
                MappingName = "CustomerID", HeaderText = "Customer ID"
            };
            GridTextColumn gridTextColumn3 = new GridTextColumn()
            {
                MappingName = "CustomerName", HeaderText = "Customer Name"
            };
            GridTextColumn gridTextColumn4 = new GridTextColumn()
            {
                MappingName = "Country", HeaderText = "Country"
            };
            GridTextColumn gridTextColumn5 = new GridTextColumn()
            {
                MappingName = "ShipCity", HeaderText = "Ship City"
            };
            GridCheckBoxColumn checkBoxColumn = new GridCheckBoxColumn()
            {
                MappingName = "IsShipped", HeaderText = "Is Shipped"
            };

            sfDataGrid.Columns.Add(gridTextColumn1);
            sfDataGrid.Columns.Add(gridTextColumn2);
            sfDataGrid.Columns.Add(gridTextColumn3);
            sfDataGrid.Columns.Add(gridTextColumn4);
            sfDataGrid.Columns.Add(gridTextColumn5);
            sfDataGrid.Columns.Add(checkBoxColumn);

            btnExportExcel.Click += BtnExportExcel_Click;
        }
示例#7
0
        private GridColumn CreateSfColumn(Field field, int i)
        {
            GridColumn result;

            DataType t = field.SchemaType == SchemaType.Data
            ? ((DataField)field).DataType
            : DataType.String;

            if (t == DataType.Int32 ||
                t == DataType.Float ||
                t == DataType.Double ||
                t == DataType.Decimal)
            {
                result = new GridNumericColumn();
            }
            else if (t == DataType.DateTimeOffset)
            {
                result = new GridDateTimeColumn();
            }
            else if (t == DataType.Boolean)
            {
                result = new GridCheckBoxColumn();
            }
            else
            {
                result = new GridTextColumn()
                {
                    TextWrapping = TextWrapping.NoWrap
                };
            }

            result.MappingName    = $"[{i}]";
            result.HeaderText     = field.Name;
            result.AllowFiltering = false;
            result.AllowFocus     = true;
            result.AllowResizing  = true;
            result.AllowSorting   = true;
            result.FilterBehavior = FilterBehavior.StronglyTyped;
            result.AllowEditing   = true;

            return(result);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            this.View.BackgroundColor    = UIColor.White;
            dataGrid.ItemsSource         = viewModel.OrdersInfo;
            dataGrid.AutoGenerateColumns = true;
            dataGrid.SelectionMode       = SelectionMode.Single;
            dataGrid.NavigationMode      = NavigationMode.Cell;
            dataGrid.AllowEditing        = true;
            dataGrid.EditTapAction       = TapAction.OnTap;
            dataGrid.CellRenderers.Remove("Numeric");
            dataGrid.CellRenderers.Add("Numeric", new NumericColumnRenderer());
            var numericColumn = new GridNumericColumn();

            numericColumn.MappingName  = "OrderID";
            numericColumn.AllowEditing = true;
            dataGrid.Columns.Add(numericColumn);

            this.View.AddSubview(dataGrid);
        }
        private GridColumn CreateSfColumn(Series s, int i)
        {
            GridColumn result;

            if (s.DataType == typeof(int) ||
                s.DataType == typeof(float) ||
                s.DataType == typeof(double) ||
                s.DataType == typeof(decimal))
            {
                result = new GridNumericColumn();
            }
            else if (s.DataType == typeof(DateTime) ||
                     s.DataType == typeof(DateTimeOffset))
            {
                result = new GridDateTimeColumn();
            }
            else if (s.DataType == typeof(bool))
            {
                result = new GridCheckBoxColumn();
            }
            else
            {
                result = new GridTextColumn();
            }

            result.MappingName    = $"[{i}]";
            result.HeaderText     = s.Name;
            result.AllowFiltering = false;
            result.AllowFocus     = true;
            result.AllowResizing  = true;
            result.AllowSorting   = true;
            result.FilterBehavior = FilterBehavior.StronglyTyped;
            result.AllowEditing   = true;

            result.ShowToolTip = false;

            result.ShowHeaderToolTip     = true;
            result.HeaderToolTipTemplate = _headerTooltipTemplate;

            return(result);
        }
        public Form1()
        {
            InitializeComponent();

            this.sfDataGrid.AutoGenerateColumns = false;
            this.sfDataGrid.DataSource          = new ViewModel().Orders;
            this.sfDataGrid.LiveDataUpdateMode  = LiveDataUpdateMode.AllowDataShaping;

            GridNumericColumn gridTextColumn1 = new GridNumericColumn()
            {
                MappingName = "OrderID", HeaderText = "Order ID"
            };
            GridTextColumn gridTextColumn2 = new GridTextColumn()
            {
                MappingName = "CustomerID", HeaderText = "Customer ID"
            };
            GridTextColumn gridTextColumn3 = new GridTextColumn()
            {
                MappingName = "CustomerName", HeaderText = "Customer Name"
            };
            GridTextColumn gridTextColumn4 = new GridTextColumn()
            {
                MappingName = "Country", HeaderText = "Country"
            };
            GridDateTimeColumn gridDateTimeColumn = new GridDateTimeColumn()
            {
                MappingName = "Date", Width = 130, HeaderText = "Date", Pattern = Syncfusion.WinForms.Input.Enums.DateTimePattern.Custom, Format = "MM/dd/yyyy hh:mm"
            };

            this.sfDataGrid.Columns.Add(gridDateTimeColumn);
            this.sfDataGrid.Columns.Add(gridTextColumn1);
            this.sfDataGrid.Columns.Add(gridTextColumn2);
            this.sfDataGrid.Columns.Add(gridTextColumn3);
            this.sfDataGrid.Columns.Add(gridTextColumn4);

            this.sfDataGrid.CellRenderers.Remove("DateTime");
            this.sfDataGrid.CellRenderers.Add("DateTime", new GridDateTimeCellRendererExt());
        }
        private GridColumn CreateSfColumn(SchemaElement se, int i)
        {
            GridColumn result;

            if (se.ElementType == typeof(int) ||
                se.ElementType == typeof(float) ||
                se.ElementType == typeof(double) ||
                se.ElementType == typeof(decimal))
            {
                result = new GridNumericColumn();
            }
            else if (se.ElementType == typeof(DateTime) ||
                     se.ElementType == typeof(DateTimeOffset))
            {
                result = new GridDateTimeColumn();
            }
            else if (se.ElementType == typeof(bool))
            {
                result = new GridCheckBoxColumn();
            }
            else
            {
                result = new GridTextColumn();
            }

            result.MappingName    = $"[{i}]";
            result.HeaderText     = se.Name;
            result.AllowFiltering = false;
            result.AllowFocus     = true;
            result.AllowResizing  = true;
            result.AllowSorting   = true;
            result.FilterBehavior = FilterBehavior.StronglyTyped;
            result.AllowEditing   = true;

            return(result);
        }
示例#12
0
        private void Startup(PrefabManager prefabManager)
        {
            ItemNameField.Text = _prefabName;

            FillPrefabDataTable();
            List <DataRow> origRows = new List <DataRow>();

            foreach (DataRow row in _prefabTable.Rows)
            {
                origRows.Add(row);
            }

            _prefabTable.RowChanged += (sender, args) =>
            {
                SaveButton.IsEnabled = !string.IsNullOrEmpty(ItemNameField.Text);
                if (args.Action == DataRowAction.Add)
                {
                    args.Row[1] = "TextField";
                    _prefabTable.AcceptChanges();
                }
                else
                {
                    switch (args.Action)
                    {
                    case DataRowAction.Change when !origRows.Contains(args.Row):
                        return;

                    case DataRowAction.Change:
                        int      index = origRows.IndexOf(args.Row);
                        string[] keys  = _changedColumnNames.Keys.ToArray();

                        _changedColumnNames[keys[index]] = args.Row[0].ToString();
                        _prefabTable.AcceptChanges();
                        break;
                    }
                }

                RowPositionTextBox.MaxValue = _prefabTable.Rows.Count;
            };
            _prefabTable.RowDeleting += (sender, args) =>
            {
                if (origRows.Contains(args.Row))
                {
                    _deletedColumns.Add(args.Row[0].ToString());
                }
            };
            _prefabTable.RowDeleted += (sender, args) =>
            {
                SaveButton.IsEnabled = !string.IsNullOrEmpty(ItemNameField.Text);
                _prefabTable.AcceptChanges();
                RowPositionTextBox.MaxValue = _prefabTable.Rows.Count;
            };
            RowPositionTextBox.MaxValue = _prefabTable.Rows.Count;

            PrefabGrid.ItemsSource = _prefabTable;
            var j = 0;

            PrefabGrid.Loaded += (sender, args) =>
            {
                var comboStrings = new HashSet <string>
                {
                    "TextField",
                    "AutoComplete",
                    "CheckBox",
                    "ComboBox",
                    "DatePicker",
                    "Numeric",
                    "Currency",
                    "Hyperlink",
                    "Percentage"
                };
                if (j == 0)
                {
                    for (var i = 0; i < _prefabTable.Columns.Count; i++)
                    {
                        GridColumn column;
                        if (i == 1)
                        {
                            column = new GridComboBoxColumn
                            {
                                MappingName     = _prefabTable.Columns[i].ColumnName,
                                ItemsSource     = comboStrings,
                                StaysOpenOnEdit = true,
                                IsEditable      = false,
                                HeaderText      = _prefabTable.Columns[i].ColumnName
                            };

                            PrefabGrid.Columns.Add(column);
                        }
                        else if (i > 1)
                        {
                            column = new GridNumericColumn
                            {
                                MappingName          = _prefabTable.Columns[i].ColumnName,
                                HeaderText           = _prefabTable.Columns[i].ColumnName,
                                NumberDecimalDigits  = 0,
                                NumberGroupSeparator = ","
                            };

                            PrefabGrid.Columns.Add(column);
                        }
                        else
                        {
                            column = new GridTextColumn
                            {
                                MappingName = _prefabTable.Columns[i].ColumnName,
                                HeaderText  = _prefabTable.Columns[i].ColumnName
                            };

                            PrefabGrid.Columns.Add(column);
                        }
                    }
                }

                j++;
            };
            _prefabManager = prefabManager;

            _changedColumnNames = new Dictionary <string, string>();
            foreach (DataRow dr in _prefabTable.Rows)
            {
                _changedColumnNames.Add(dr[0].ToString(), dr[0].ToString());
            }
            _deletedColumns = new List <string>();
        }
    private void CreateColumns(Report report)
    {
        DataTable table = new DataTable();

        using (SqlCommand command = new SqlCommand())
        {
            command.CommandText = report.GetSqlOld(true, filterControl.ReportConditions);
            command.CommandType = CommandType.Text;
            Report.CreateParameters(UserSession.LoginUser, command, UserSession.LoginUser.UserID);

            using (SqlConnection connection = new SqlConnection(GetReportConnectionString()))
            {
                connection.Open();
                command.Connection = connection;
                using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                {
                    adapter.FillSchema(table, SchemaType.Source);
                    adapter.Fill(table);
                }
                connection.Close();
            }
        }

        ReportFields fields = new ReportFields(UserSession.LoginUser);

        fields.LoadByReportID(_reportID);
        foreach (ReportField field in fields)
        {
            if (field.IsCustomField == false && (field.LinkedFieldID == 30 || field.LinkedFieldID == 146))
            {
                GridButtonColumn column = new GridButtonColumn();
                gridReport.MasterTableView.Columns.Add(column);
                column.ButtonType        = GridButtonColumnType.ImageButton;
                column.ImageUrl          = "../images/icons/open.png";
                column.UniqueName        = "ButtonOpen";
                column.CommandName       = "OpenItem";
                column.HeaderStyle.Width = new Unit(32, UnitType.Pixel);
                column.Resizable         = false;
                break;
            }
        }

        if (fields.IsEmpty)
        {
            if (table.Columns.Contains("Ticket_Number"))
            {
                GridButtonColumn column = new GridButtonColumn();
                gridReport.MasterTableView.Columns.Add(column);
                column.ButtonType        = GridButtonColumnType.ImageButton;
                column.ImageUrl          = "../images/icons/open.png";
                column.UniqueName        = "ButtonOpen";
                column.CommandName       = "OpenItem";
                column.HeaderStyle.Width = new Unit(32, UnitType.Pixel);
                column.Resizable         = false;
            }
        }



        foreach (DataColumn dataColumn in table.Columns)
        {
            GridBoundColumn gridColumn;
            if (dataColumn.DataType == typeof(System.DateTime))
            {
                gridColumn = new GridDateTimeColumn();
                gridColumn.DataFormatString = "{0:MM/dd/yyyy hh:mm tt}";
            }
            else if (dataColumn.DataType == typeof(System.Decimal) ||
                     dataColumn.DataType == typeof(System.Double)
                     )
            {
                gridColumn = new GridNumericColumn();
                gridColumn.DataFormatString = "{0:0.00}";
            }
            else if (dataColumn.DataType == typeof(System.Int16) ||
                     dataColumn.DataType == typeof(System.Int32) ||
                     dataColumn.DataType == typeof(System.Int64))
            {
                gridColumn = new GridNumericColumn();
                gridColumn.DataFormatString = "{0:0}";
            }
            else
            {
                gridColumn = new GridBoundColumn();
            }


            gridReport.MasterTableView.Columns.Add(gridColumn);
            gridColumn.DataType          = dataColumn.DataType;
            gridColumn.DataField         = dataColumn.ColumnName.Replace(' ', '_');
            gridColumn.UniqueName        = gridColumn.DataField;
            gridColumn.HeaderText        = dataColumn.ColumnName.Replace('_', ' ');
            gridColumn.HeaderStyle.Width = new Unit(200, UnitType.Pixel);
        }
    }
        public static void GenerateColumnsSfDataGrid(SfDataGrid dataGrid, DataTable table, string prefab)
        {
            using (var conn = new SqlConnection(App.ConnectionString))
            {
                conn.Open();
                if (!string.IsNullOrEmpty(prefab))
                {
                    DataTable prefabTable = App.GetPrefabDataTable(conn, $"{Settings.Default.Schema}_PREFABS", prefab);
                    DataTable comboTable  =
                        App.GetPrefabDataTable(conn, $"{Settings.Default.Schema}_COMBOBOXES", prefab);

                    //could loop by table.ColumnNames.Count; but if prebab is changed... problems; maybe not all columns showing
                    for (var i = 0; i < table.Columns.Count; i++)
                    {
                        GridColumn column;

                        try
                        {
                            if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("autocomplete"))
                            {
                                column = new GridTemplateColumn
                                {
                                    MappingName = table.Columns[i].ColumnName,
                                    HeaderText  = prefabTable.Rows[i]["COLUMNS"].ToString()
                                };

                                var comboStrings = new HashSet <string>();
                                for (var j = 0; j < comboTable.Rows.Count; j++)
                                {
                                    if (!string.IsNullOrEmpty(
                                            comboTable.Rows[j][prefabTable.Rows[i]["COLUMNS"].ToString()].ToString()))
                                    {
                                        comboStrings.Add(comboTable.Rows[j][prefabTable.Rows[i]["COLUMNS"].ToString()]
                                                         .ToString());
                                    }
                                }

                                var autoCompleteElem = new FrameworkElementFactory(typeof(AutoComplete));

                                var autoCompleteItemsBind = new Binding
                                {
                                    Source = comboStrings,
                                    UpdateSourceTrigger   = UpdateSourceTrigger.PropertyChanged,
                                    BindsDirectlyToSource = true
                                };

                                var autoCompleteBind =
                                    new Binding(table.Columns[i].ColumnName)
                                {
                                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                                    Mode = BindingMode.TwoWay,
                                    BindsDirectlyToSource = true
                                };

                                autoCompleteElem.SetValue(UIElement.FocusableProperty, true);
                                autoCompleteElem.SetValue(AutoComplete.IsDropDownOpenProperty, true);
                                autoCompleteElem.SetValue(ItemsControl.IsTextSearchEnabledProperty, true);
                                autoCompleteElem.SetValue(AutoComplete.IsAutoAppendProperty, true);
                                autoCompleteElem.SetValue(ItemsControl.IsTextSearchCaseSensitiveProperty, false);
                                autoCompleteElem.SetValue(AutoComplete.CustomSourceProperty, autoCompleteItemsBind);
                                autoCompleteElem.SetValue(AutoComplete.TextProperty, autoCompleteBind);
                                autoCompleteElem.SetValue(AutoComplete.CanResizePopupProperty, false);
                                //autoCompleteElem.SetValue(AutoComplete.IsFilterProperty, true);
                                autoCompleteElem.SetValue(AutoComplete.EnableSortingProperty, false);

                                var cellEditingTemplate =
                                    new DataTemplate(typeof(AutoComplete))
                                {
                                    VisualTree = autoCompleteElem
                                };
                                ((GridTemplateColumn)column).EditTemplate = cellEditingTemplate;

                                var defaultElement = new FrameworkElementFactory(typeof(TextBlock));

                                var bind = new Binding(table.Columns[i].ColumnName)
                                {
                                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                                    Mode = BindingMode.TwoWay,
                                    BindsDirectlyToSource = true
                                };

                                defaultElement.SetValue(TextBlock.TextProperty, bind);
                                defaultElement.SetValue(FrameworkElement.VerticalAlignmentProperty,
                                                        VerticalAlignment.Center);

                                var defaultTemplate = new DataTemplate(typeof(TextBlock))
                                {
                                    VisualTree = defaultElement
                                };
                                ((GridTemplateColumn)column).CellTemplate = defaultTemplate;

                                dataGrid.Columns.Add(column);
                            }
                            else if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("datepicker"))
                            {
                                column = new GridDateTimeColumn
                                {
                                    MappingName            = table.Columns[i].ColumnName,
                                    Pattern                = DateTimePattern.ShortDate,
                                    CanEdit                = true,
                                    AllowNullValue         = true,
                                    NullText               = string.Empty,
                                    AllowScrollingOnCircle = true,
                                    EnableBackspaceKey     = true,
                                    EnableDeleteKey        = true,
                                    ShowRepeatButton       = true,
                                    HeaderText             = prefabTable.Rows[i]["COLUMNS"].ToString()
                                };

                                dataGrid.Columns.Add(column);
                            }
                            else if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("checkbox"))
                            {
                                column = new GridCheckBoxColumn
                                {
                                    MappingName  = table.Columns[i].ColumnName,
                                    IsThreeState = false,
                                    HeaderText   = prefabTable.Rows[i]["COLUMNS"].ToString()
                                };

                                dataGrid.Columns.Add(column);
                            }
                            else if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("numeric"))
                            {
                                column = new GridNumericColumn
                                {
                                    MappingName          = table.Columns[i].ColumnName,
                                    HeaderText           = prefabTable.Rows[i]["COLUMNS"].ToString(),
                                    NumberDecimalDigits  = 3,
                                    NumberGroupSeparator = ","
                                };

                                dataGrid.Columns.Add(column);
                            }
                            else if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("currency"))
                            {
                                column = new GridCurrencyColumn
                                {
                                    MappingName = table.Columns[i].ColumnName,
                                    HeaderText  = prefabTable.Rows[i]["COLUMNS"].ToString()
                                };

                                dataGrid.Columns.Add(column);
                            }
                            else if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("hyperlink"))
                            {
                                column = new GridHyperlinkColumn
                                {
                                    MappingName = table.Columns[i].ColumnName,
                                    HeaderText  = prefabTable.Rows[i]["COLUMNS"].ToString()
                                };

                                dataGrid.Columns.Add(column);
                            }
                            else if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("percentage"))
                            {
                                column = new GridPercentColumn
                                {
                                    MappingName = table.Columns[i].ColumnName,
                                    HeaderText  = prefabTable.Rows[i]["COLUMNS"].ToString()
                                };

                                dataGrid.Columns.Add(column);
                            }
                            else if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("combobox"))
                            {
                                var comboStrings = new HashSet <string>();
                                for (var j = 0; j < comboTable.Rows.Count; j++)
                                {
                                    if (!string.IsNullOrEmpty(
                                            comboTable.Rows[j][prefabTable.Rows[i]["COLUMNS"].ToString()].ToString()))
                                    {
                                        comboStrings.Add(comboTable.Rows[j][prefabTable.Rows[i]["COLUMNS"].ToString()]
                                                         .ToString());
                                    }
                                }

                                column = new GridComboBoxColumn
                                {
                                    MappingName     = table.Columns[i].ColumnName,
                                    ItemsSource     = comboStrings,
                                    StaysOpenOnEdit = true,
                                    IsEditable      = true,
                                    HeaderText      = prefabTable.Rows[i]["COLUMNS"].ToString()
                                };

                                dataGrid.Columns.Add(column);
                            }
                            else
                            {
                                column = new GridTextColumn
                                {
                                    MappingName = table.Columns[i].ColumnName,
                                    HeaderText  = prefabTable.Rows[i]["COLUMNS"].ToString()
                                };

                                dataGrid.Columns.Add(column);
                            }
                        }
                        catch
                        {
                            column = new GridTextColumn
                            {
                                MappingName = table.Columns[i].ColumnName,
                                HeaderText  = table.Columns[i].ColumnName
                            };

                            dataGrid.Columns.Add(column);
                        }
                    }
                }
                else
                {
                    foreach (DataColumn column in table.Columns)
                    {
                        GridColumn gridColumn = new GridTextColumn
                        {
                            MappingName = column.ColumnName,
                            HeaderText  = column.ColumnName
                        };

                        dataGrid.Columns.Add(gridColumn);
                    }
                }

                conn.Close();
            }
        }
示例#15
0
        public static void GenerateColumnsSfDataGrid(SfDataGrid dataGrid, DataTable table, string prefab)
        {
            using (var conn = new SqlConnection(App.ConnectionString))
            {
                conn.Open();
                if (!string.IsNullOrEmpty(prefab))
                {
                    DataTable prefabTable = App.GetPrefabDataTable(conn, $"{App.Settings["Schema"]}_PREFABS", prefab);
                    DataTable comboTable  =
                        App.GetPrefabDataTable(conn, $"{App.Settings["Schema"]}_COMBOBOXES", prefab);

                    //could loop by table.ColumnNames.Count; but if prebab is changed... problems; maybe not all columns showing
                    for (var i = 0; i < table.Columns.Count; i++)
                    {
                        GridColumn column;

                        try
                        {
                            if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("autocomplete"))
                            {
                                var comboStrings = new HashSet <string>();
                                for (var j = 0; j < comboTable.Rows.Count; j++)
                                {
                                    if (!string.IsNullOrEmpty(
                                            comboTable.Rows[j][prefabTable.Rows[i]["COLUMNS"].ToString()].ToString()))
                                    {
                                        comboStrings.Add(comboTable.Rows[j][prefabTable.Rows[i]["COLUMNS"].ToString()]
                                                         .ToString());
                                    }
                                }

                                StringBuilder sb1 = new StringBuilder();
                                sb1.AppendLine(
                                    "<DataTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">");
                                sb1.AppendLine("<ComboBox PlaceholderText=\"{Binding " + prefabTable.Rows[i]["COLUMNS"] +
                                               ", Mode=TwoWay}\" IsEditable=\"True\" IsTextSearchEnabled=\"True\" IsDropDownOpen=\"True\" >");
                                foreach (var comboString in comboStrings)
                                {
                                    sb1.AppendLine($"<x:String>{comboString}</x:String>");
                                }
                                sb1.AppendLine("</ComboBox>");
                                sb1.AppendLine("</DataTemplate>");
                                DataTemplate cellTemplate = (DataTemplate)XamlReader.Load(sb1.ToString());
                                column = new GridTemplateColumn
                                {
                                    MappingName  = table.Columns[i].ColumnName,
                                    HeaderText   = prefabTable.Rows[i]["COLUMNS"].ToString(),
                                    EditTemplate = cellTemplate
                                };
                                dataGrid.Columns.Add(column);
                            }
                            else if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("datepicker"))
                            {
                                column = new GridDateTimeColumn
                                {
                                    MappingName        = table.Columns[i].ColumnName,
                                    FormatString       = "MM/dd/yyyy",
                                    AllowInlineEditing = true,
                                    AllowNullValue     = true,
                                    HeaderText         = prefabTable.Rows[i]["COLUMNS"].ToString(),
                                    WaterMark          = string.Empty
                                };

                                dataGrid.Columns.Add(column);
                            }
                            else if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("checkbox"))
                            {
                                column = new GridCheckBoxColumn
                                {
                                    MappingName  = table.Columns[i].ColumnName,
                                    IsThreeState = false,
                                    HeaderText   = prefabTable.Rows[i]["COLUMNS"].ToString()
                                };

                                dataGrid.Columns.Add(column);
                            }
                            else if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("numeric"))
                            {
                                column = new GridNumericColumn
                                {
                                    MappingName = table.Columns[i].ColumnName,
                                    HeaderText  = prefabTable.Rows[i]["COLUMNS"].ToString(),
                                    MaximumNumberDecimalDigits = 3
                                };

                                dataGrid.Columns.Add(column);
                            }                            /*
                                                          * else if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("currency"))
                                                          * {
                                                          *     column = new GridCurrencyColumn
                                                          *     {
                                                          *             MappingName = table.Columns[i].ColumnName,
                                                          *             HeaderText = prefabTable.Rows[i]["COLUMNS"].ToString()
                                                          *     };
                                                          *
                                                          *     dataGrid.Columns.Add(column);
                                                          * }*/
                            else if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("hyperlink"))
                            {
                                column = new GridHyperlinkColumn
                                {
                                    MappingName = table.Columns[i].ColumnName,
                                    HeaderText  = prefabTable.Rows[i]["COLUMNS"].ToString()
                                };

                                dataGrid.Columns.Add(column);
                            }                            /*
                                                          * else if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("percentage"))
                                                          * {
                                                          *     column = new GridPercentColumn
                                                          *     {
                                                          *             MappingName = table.Columns[i].ColumnName,
                                                          *             HeaderText = prefabTable.Rows[i]["COLUMNS"].ToString()
                                                          *     };
                                                          *
                                                          *     dataGrid.Columns.Add(column);
                                                          * }*/
                            else if (prefabTable.Rows[i]["TYPES"].ToString().ToLower().Equals("combobox"))
                            {
                                var comboStrings = new HashSet <string>();
                                for (var j = 0; j < comboTable.Rows.Count; j++)
                                {
                                    if (!string.IsNullOrEmpty(
                                            comboTable.Rows[j][prefabTable.Rows[i]["COLUMNS"].ToString()].ToString()))
                                    {
                                        comboStrings.Add(comboTable.Rows[j][prefabTable.Rows[i]["COLUMNS"].ToString()]
                                                         .ToString());
                                    }
                                }

                                column = new GridComboBoxColumn
                                {
                                    MappingName = table.Columns[i].ColumnName,
                                    ItemsSource = comboStrings,
                                    HeaderText  = prefabTable.Rows[i]["COLUMNS"].ToString()
                                };

                                dataGrid.Columns.Add(column);
                            }
                            else
                            {
                                column = new GridTextColumn
                                {
                                    MappingName = table.Columns[i].ColumnName,
                                    HeaderText  = prefabTable.Rows[i]["COLUMNS"].ToString()
                                };

                                dataGrid.Columns.Add(column);
                            }                             //TODO: More? CalendarDatePicker, TimePicker, DatePicker, Slider, ToggleSwitch, RichEditBox, PasswordBox, ColorPicker, ComboBox, RatingControl
                        }
                        catch
                        {
                            column = new GridTextColumn
                            {
                                MappingName = table.Columns[i].ColumnName,
                                HeaderText  = table.Columns[i].ColumnName
                            };

                            dataGrid.Columns.Add(column);
                        }
                    }
                }
                else
                {
                    foreach (DataColumn column in table.Columns)
                    {
                        GridColumn gridColumn = new GridTextColumn
                        {
                            MappingName = column.ColumnName,
                            HeaderText  = column.ColumnName
                        };

                        dataGrid.Columns.Add(gridColumn);
                    }
                }

                conn.Close();
            }
        }
        private void AddColumnsToGrid(DataTable columnsDT)
        {
            gridResults.Columns.Clear();

            //Level Column
            var levelColumn = new GridBoundColumn();
            gridResults.Columns.Add(levelColumn);
            levelColumn.DataField = "LevelText";
            levelColumn.HeaderText = "Level";
            levelColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Left;

            //Label Column
            var labelColumn = new GridBoundColumn();
            gridResults.Columns.Add(labelColumn);
            labelColumn.HeaderText = "";
            labelColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Left;

            switch (_displayOption)
            {
                case "Level":
                    labelColumn.DataFormatString = "Counts<br/>Distribution%";
                    break;

                case "Score":
                    labelColumn.DataFormatString = "Counts<br/>Scores";
                    break;

                case "All":
                    labelColumn.DataFormatString = "Counts<br/>Distribution%<br/>Scores";
                    break;
            }

            //Column for each demographic
            foreach (DataRow r in columnsDT.Rows)
            {
                var column = new GridNumericColumn();
                gridResults.Columns.Add(column);
                column.HeaderText = r["DemoLabel"].ToString();

                _addedColumns++;
            }
        }