Пример #1
0
        protected override void CopyProperties(DataControlField newField)
        {
            base.CopyProperties(newField);
            TemplateFieldExt fieldExt = (TemplateFieldExt)newField;

            fieldExt.ColumnName = ColumnName;
        }
Пример #2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (DesignMode)
            {
                return;
            }

            TableDataSourceView view      = (TableDataSourceView)GetData();
            DataTable           dataTable = view.Table;

            Boolean allowPaging = (Boolean)(DataSetResourceManager.GetTableExtProperty(dataTable, TableExtProperties.ALLOW_PAGING) ?? true);

            if (allowPaging)
            {
                Int32 pageSize = (Int32)(DataSetResourceManager.GetTableExtProperty(dataTable, TableExtProperties.PAGE_SIZE) ?? 10);
                gridView.AllowPaging = true;
                gridView.PageSize    = pageSize;
                view.EnablePaging    = true;
            }
            var isTree = AllowTreeAndPaging || (bool)(DataSetResourceManager.GetTableExtProperty(dataTable, TableExtProperties.IS_TREE_REF) ?? false);

            if (!allowPaging || isTree)
            {
                view.EnablePaging = false;
                if (!isTree)
                {
                    gridView.AllowPaging = false;
                }
                if (GridTreeMode)
                {
                    String Relation = (String)(DataSetResourceManager.GetTableExtProperty(dataTable, TableExtProperties.TREE_REF_RELATION) ?? "");
                    gridView.ShowAsTree            = !String.IsNullOrEmpty(Relation);
                    gridView.AllowNewButtonForTree = false;
                    gridView.PostBackOnExpnad      = postBackOnTreeExpand;
                    if (gridView.ShowAsTree)
                    {
                        gridView.RelationName = Relation;
                    }
                }
            }

            gridView.AutoGenerateColumns = false;

            if (ViewState["ColumnsCreated"] == null)
            {
                ViewState["ColumnsCreated"] = true;

                if (AllowErrorIconColumn)
                {
                    var field = new TemplateFieldExt
                    {
                        ColumnName = "ErrorIconColumn",
                    };
                    gridView.Columns.Add(field);
                }

                foreach (DataColumn dc in dataTable.Columns)
                {
                    var showColumn     = (Boolean)(DataSetResourceManager.GetColumnExtProperty(dc, ColumnExtProperties.VISIBLE) ?? false);
                    var visibleCulture = (string)DataSetResourceManager.GetColumnExtProperty(dc, ColumnExtProperties.VISIBLE_CULTURE);
                    if (!string.IsNullOrEmpty(visibleCulture))
                    {
                        showColumn = showColumn && visibleCulture.Equals(CultureInfo.CurrentUICulture.Name, StringComparison.CurrentCultureIgnoreCase);
                    }

                    Object[] rights        = (Object[])(DataSetResourceManager.GetColumnExtProperty(dc, ColumnExtProperties.RIGHTS) ?? new Object[] {});
                    Boolean  userHasRights = true;
                    foreach (Object right in rights)
                    {
                        userHasRights = UserRoles.IsInRole(Convert.ToString(right));
                        if (!userHasRights)
                        {
                            break;
                        }
                    }

                    if (showColumn && userHasRights)
                    {
                        String columnCaption = (String)(DataSetResourceManager.GetColumnExtProperty(dc, ColumnExtProperties.CAPTION) ?? dc.Caption);
                        if (dc.DataType == typeof(DateTime))
                        {
                            String dataFormatString = (String)(DataSetResourceManager.GetColumnExtProperty(dc, ColumnExtProperties.FILTER_DATE_TIME_FORMAT) ?? null);

                            BoundField boundField = new BoundField();
                            boundField.DataField        = dc.ColumnName;
                            boundField.HeaderText       = columnCaption;
                            boundField.DataFormatString = dataFormatString;
                            boundField.HtmlEncode       = false;
                            boundField.SortExpression   = dc.ColumnName;
                            gridView.Columns.Add(boundField);
                        }
                        else if (dc.DataType == typeof(Boolean))
                        {
                            CheckBoxField checkBoxField = new CheckBoxField();
                            checkBoxField.DataField      = dc.ColumnName;
                            checkBoxField.HeaderText     = columnCaption;
                            checkBoxField.SortExpression = dc.ColumnName;
                            gridView.Columns.Add(checkBoxField);
                        }
                        else
                        {
                            BoundField boundField = new BoundField();
                            boundField.DataField      = dc.ColumnName;
                            boundField.HeaderText     = columnCaption;
                            boundField.SortExpression = dc.ColumnName;
                            Boolean htmlEncode = (Boolean)(DataSetResourceManager.GetColumnExtProperty(dc, ColumnExtProperties.HTML_ENCODED) ?? false);
                            boundField.HtmlEncode = htmlEncode;
                            gridView.Columns.Add(boundField);
                        }
                    }
                }

                if (AllowErrorColumn)
                {
                    var field = new TemplateFieldExt
                    {
                        ColumnName = "ErrorColumn",
                        HeaderText = ErrorHeaderText,
                    };
                    gridView.Columns.Add(field);
                }
            }
            if (AllowErrorColumn || AllowErrorIconColumn)
            {
                gridView.RowCreated += GridView_OnRowCreated;
            }
        }