Esempio n. 1
0
        public static Type ConvertUnboundColumnTypeToType(UnboundColumnType dataType)
        {
            Type unboundType = typeof(object);

            switch (dataType)
            {
            case UnboundColumnType.String:
                unboundType = typeof(String);
                break;

            case UnboundColumnType.DateTime:
                unboundType = typeof(DateTime);
                break;

            case UnboundColumnType.Integer:
                unboundType = typeof(System.Int32);
                break;

            case UnboundColumnType.Decimal:
                unboundType = typeof(System.Decimal);
                break;

            case UnboundColumnType.Boolean:
                unboundType = typeof(Double);
                break;

            case UnboundColumnType.Bound:
                unboundType = typeof(object);
                break;
            }

            return(unboundType);
        }
Esempio n. 2
0
        private static BandedGridColumn CreateBandedGridColumn(bool readOnly,
                                                               int rowIndex,
                                                               string caption,
                                                               string fieldName,
                                                               UnboundColumnType unboundColumnType,
                                                               SummaryItemType summaryItemType,
                                                               HorzAlignment headerAlignment,
                                                               object tag,
                                                               int?minWidth)
        {
            var bandedGridColumn = new BandedGridColumn();

            bandedGridColumn.Caption = caption;
            bandedGridColumn.DisplayFormat.FormatString = ColumnFormat;
            bandedGridColumn.DisplayFormat.FormatType   = FormatType.Numeric;
            bandedGridColumn.FieldName = fieldName;
            bandedGridColumn.Name      = "col" + fieldName;
            bandedGridColumn.Tag       = tag;

            bandedGridColumn.OptionsColumn.AllowSort = DefaultBoolean.False;
            bandedGridColumn.OptionsColumn.ShowInCustomizationForm = false;
            bandedGridColumn.OptionsFilter.AllowFilter             = false;
            bandedGridColumn.OptionsColumn.AllowEdit  = !readOnly;
            bandedGridColumn.OptionsColumn.ReadOnly   = readOnly;
            bandedGridColumn.OptionsColumn.AllowFocus = !readOnly;
            bandedGridColumn.AppearanceHeader.Options.UseTextOptions = true;
            bandedGridColumn.AppearanceHeader.TextOptions.HAlignment = headerAlignment;

            if (minWidth.HasValue)
            {
                bandedGridColumn.MinWidth = minWidth.Value;
            }

            bandedGridColumn.RowIndex = rowIndex;
            if (summaryItemType != SummaryItemType.None)
            {
                bandedGridColumn.Summary.AddRange(new GridSummaryItem[]
                {
                    new GridColumnSummaryItem(summaryItemType,
                                              fieldName,
                                              SummaryFormat)
                });
            }

            bandedGridColumn.Visible     = true;
            bandedGridColumn.UnboundType = unboundColumnType;
            bandedGridColumn.Width       = InitialColumnWidth;

            return(bandedGridColumn);
        }
Esempio n. 3
0
        //private void InsertColumn(int key, string name, DataGridViewContentAlignment alignHeader, DataGridViewContentAlignment alignRow, int width,Type type)
        //private void InsertColumn(int key, string name, HorzAlignment alignHeader, HorzAlignment alignRow, int width, UnboundColumnType type)
        private void InsertColumn(string name, int width, HorzAlignment alignCell, UnboundColumnType type, Type typeOri, bool readOnly)
        {
            var column = new DataGridViewTextBoxColumnEX();

            column.Name          = $"column{GV_PageHV.Columns.Count + 1}";
            column.HeaderText    = name;
            column.CellAlignment = alignCell;                              //CELL位置
            column.ColumnType    = type;
            column.SortMode      = DataGridViewColumnSortMode.NotSortable; //SORT 需設定為NOT 標題才會真的置中
            column.ValueType     = typeOri;
            column.Width         = width;
            column.ReadOnly      = readOnly;
            GV_PageHV.Columns.Add(column);
        }
Esempio n. 4
0
        //private void InsertColumn(int key,string name, HorzAlignment alignHeader, HorzAlignment alignRow, int width, UnboundColumnType type)
        //private void InsertColumn(int key, string name, DataGridViewContentAlignment alignHeader, DataGridViewContentAlignment alignRow, int width, Type type)
        private void InsertColumn(string name, int width, HorzAlignment alignCell, UnboundColumnType type, Type typeOri)
        {
            var column = new DataGridViewTextBoxColumnEX();

            //var column = new DataGridViewTextBoxColumn();

            /*var column = new GridColumn();
             * column.Caption = name;
             * column.AppearanceHeader.TextOptions.HAlignment = alignHeader;
             * column.AppearanceCell.TextOptions.HAlignment = alignRow;
             * column.UnboundType = type;
             * column.Width = width;
             * column.OptionsColumn.AllowSort = DefaultBoolean.False;*/

            column.Name          = $"column{GV_PageData.Columns.Count + 1}";
            column.HeaderText    = name;
            column.CellAlignment = alignCell;                              //CELL位置
            column.ColumnType    = type;
            column.SortMode      = DataGridViewColumnSortMode.NotSortable; //SORT 需設定為NOT 標題才會真的置中
            column.ValueType     = typeOri;
            column.Width         = width;
            GV_PageData.Columns.Add(column);
        }
Esempio n. 5
0
        public static void AddUnboundBandColumns(this GridBand band,
                                                 bool readOnly,
                                                 int rowIndex,
                                                 string captionFormat,
                                                 string fieldPrefix,
                                                 UnboundColumnType unboundColumnType,
                                                 SummaryItemType summaryType,
                                                 IEnumerable <string> header,
                                                 int?minWidth = null)
        {
            Debug.Assert(band != null && band.View != null, "band == null || band.View == null ");

            if (band == null || band.View == null)
            {
                return;
            }

            band.View.BeginUpdate();

            try
            {
                var gridColumnList = new List <BandedGridColumn>();

                foreach (var item in header)
                {
                    var fieldName = fieldPrefix + item;
                    var caption   = GetCaption(captionFormat, item);

                    var column = CreateBandedGridColumn(readOnly,
                                                        rowIndex,
                                                        caption,
                                                        fieldName,
                                                        unboundColumnType,
                                                        summaryType,
                                                        HorzAlignment.Far,
                                                        item,
                                                        minWidth);

                    gridColumnList.Add(column);
                }

                band.View.Columns.AddRange(gridColumnList.ToArray());

                foreach (var gridColumn in gridColumnList)
                {
                    band.Columns.Add(gridColumn);
                }

                if (summaryType != SummaryItemType.None)
                {
                    var groupSummaryList = new List <GridGroupSummaryItem>();
                    foreach (var gridColumn in gridColumnList)
                    {
                        var gridGroupSummaryItem = new GridGroupSummaryItem(summaryType,
                                                                            gridColumn.FieldName,
                                                                            gridColumn,
                                                                            SummaryFormat);

                        groupSummaryList.Add(gridGroupSummaryItem);
                    }

                    band.View.GroupSummary.AddRange(groupSummaryList.ToArray());
                }
            }
            finally
            {
                band.View.EndUpdate();
            }
        }
        // helper methods

        #region AddColumn()
        /// <summary>
        /// Utility method for derived classes to add game specific columns to the server or player list
        /// </summary>
        public GridColumn AddColumn(GridView view, string fieldName, string caption, string toolTip, int width = 70, int visibleIndex = -1, UnboundColumnType type = UnboundColumnType.String)
        {
            var col = new GridColumn();

            col.FieldName               = fieldName;
            col.Caption                 = caption;
            col.Tag                     = fieldName;
            col.Width                   = width;
            col.ToolTip                 = toolTip;
            col.UnboundType             = type;
            col.OptionsColumn.ReadOnly  = true;
            col.OptionsColumn.AllowEdit = false;
            if (type == UnboundColumnType.Decimal || type == UnboundColumnType.Integer)
            {
                col.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Far;
                col.AppearanceCell.Options.UseTextOptions = true;
            }
            else if (type == UnboundColumnType.String)
            {
                col.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
            }

            view.Columns.Add(col);
            col.VisibleIndex = visibleIndex >= 0 ? visibleIndex : view.Columns.Count;
            return(col);
        }
 private void AddColumnForRuleToServerGrid(string prefix, UnboundColumnType unboundColumnType)
 {
     var rule = (Rule)this.gvRules.GetFocusedRow();
       var col = this.gvServers.Columns[prefix + rule.Name];
       if (col == null)
     this.viewModel.gameExtension.AddColumn(this.gvServers, prefix + rule.Name, rule.Name, rule.Name, 70, this.gvServers.VisibleColumns.Count, unboundColumnType);
       else
       {
     XtraMessageBox.Show($"Rule {rule.Name} is already shown in column {col.Caption}.", this.Text,
       MessageBoxButtons.OK, MessageBoxIcon.Information);
     this.gvServers.FocusedColumn = col;
       }
 }
Esempio n. 8
0
 /// <summary>
 /// Utility method for derived classes to add game specific GridColumns to the server list
 /// </summary>
 protected GridColumn AddColumn(GridView view, string fieldName, string caption, string toolTip, int width=70, int visibleIndex=-1, UnboundColumnType type=UnboundColumnType.String)
 {
     var col = new GridColumn();
       col.FieldName = fieldName;
       col.Caption = caption;
       col.Tag = fieldName;
       col.Width = width;
       col.ToolTip = toolTip;
       col.UnboundType = type;
       col.OptionsColumn.ReadOnly = true;
       col.OptionsColumn.AllowEdit = false;
       if (type == UnboundColumnType.Decimal || type == UnboundColumnType.Integer)
       {
     col.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Far;
     col.AppearanceCell.Options.UseTextOptions = true;
       }
       view.Columns.Add(col);
       col.VisibleIndex = visibleIndex >= 0 ? visibleIndex : view.Columns.Count;
       return col;
 }
Esempio n. 9
0
        /// <summary>
        /// Добавить столбец
        /// </summary>
        /// <param name="caption">Заголовок</param>
        /// <param name="fieldName">Имя привязываемого поля</param>
        /// <param name="visibleIndex">Индекс</param>
        /// <param name="unboundType">Тип</param>
        /// <param name="width">Ширина</param>
        /// <returns></returns>
        public GridColumn AddColumn(string caption, string fieldName, int visibleIndex = 0, UnboundColumnType unboundType = UnboundColumnType.Bound, int?width = null)
        {
            var gridColumn = GridView.Columns.AddVisible(fieldName, caption);

            gridColumn.VisibleIndex = visibleIndex;
            gridColumn.UnboundType  = unboundType;
            gridColumn.Visible      = true;

            if (width.HasValue)
            {
                gridColumn.MinWidth = width.Value;
                gridColumn.Width    = width.Value;
                gridColumn.MaxWidth = width.Value;
            }

            return(gridColumn);
        }
Esempio n. 10
0
        /// <summary>
        /// 创建GridView的列
        /// </summary>
        public static GridColumn CreateColumn(this GridView gridView, string fieldName, string caption, int width = 80, bool allowEdit = true,
                                              UnboundColumnType unboundColumnType = UnboundColumnType.Bound, DefaultBoolean allowMerge = DefaultBoolean.False,
                                              FixedStyle fixedStyle = FixedStyle.None)
        {
            //使用多语言处理标题
            caption = JsonLanguage.Default.GetString(caption);

            GridColumn gridColumn = new GridColumn
            {
                FieldName   = fieldName,
                Caption     = caption,
                Width       = width,
                UnboundType = unboundColumnType
            };

            gridView.Columns.Add(gridColumn);
            gridColumn.AbsoluteIndex = gridView.Columns.Count;
            gridColumn.VisibleIndex  = gridView.Columns.Count;
            gridColumn.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gridColumn.AppearanceCell.TextOptions.VAlignment   = VertAlignment.Center;
            gridColumn.OptionsColumn.AllowEdit = allowEdit;

            if (!allowEdit)
            {
                gridColumn.AppearanceHeader.ForeColor = Color.Gray;
            }

            bool allowCellMerge = !gridView.OptionsView.AllowCellMerge && allowMerge == DefaultBoolean.True;

            if (allowCellMerge)
            {
                gridView.OptionsView.AllowCellMerge = true;
            }
            gridColumn.OptionsColumn.AllowMerge = allowMerge;
            gridColumn.Fixed = fixedStyle;

            bool isTime = caption.Contains("时间");

            if (isTime)
            {
                gridColumn.DisplayFormat.FormatType   = FormatType.DateTime;
                gridColumn.DisplayFormat.FormatString = "yyyy-MM-dd HH:mm:ss";
            }
            else
            {
                bool isDate = caption.Contains("日期");
                if (isDate)
                {
                    gridColumn.DisplayFormat.FormatType   = FormatType.DateTime;
                    gridColumn.DisplayFormat.FormatString = "yyyy-MM-dd";
                }
                else
                {
                    bool isPercent = caption.Contains("百分比") || caption.Contains("率");
                    if (isPercent)
                    {
                        gridColumn.DisplayFormat.FormatType   = FormatType.Numeric;
                        gridColumn.DisplayFormat.FormatString = "P";
                    }
                }
            }
            return(gridColumn);
        }