Пример #1
0
        public static DataTable GetDataTable(object dataSource)
        {
            DataTable dataTable = dataSource as DataTable;

            if (dataTable != null)
            {
                return(dataTable);
            }
            DataView dataView = dataSource as DataView;

            if (dataView != null)
            {
                return(dataView.Table);
            }
            TableDataSourceView tableDataSourceView = dataSource as TableDataSourceView;

            if (tableDataSourceView != null)
            {
                return(tableDataSourceView.Table);
            }
            TableDataSource tableDataSource = dataSource as TableDataSource;

            if (tableDataSource != null)
            {
                return(tableDataSource.Table);
            }
            return(null);
        }
Пример #2
0
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            // Ensure ColumnFilterStorage
            if (ColumnFilterStorage == null)
            {
                throw new NullReferenceException("ColumnFilterStorage must be specified");
            }

            // Create controls hierarchy
            table = new Table();
            Controls.Add(table);
            table.Width = Width != Unit.Empty ? Width : Unit.Percentage(100);
            table.Style["table-layout"] = "fixed";
            //table.CssClass = "ms-gridtext";
            filterRow = new TableRow();
            filterRow.Cells.Add(new TableCell());
            filterRow.Cells.Add(new TableCell());

            int countItems;

            if ((ColumnFilterStorage.IsRefBound && ((ColumnFilterStorage.AvailableFilters & ColumnFilterType.Between) == 0)) ||
                ColumnFilterStorage.DataType == typeof(String))
            {
                countItems = 1;
                filterRow.Cells.Add(new TableCell {
                    ColumnSpan = 2, Width = Unit.Percentage(100)
                });
                filterRow.Cells.Add(new TableCell {
                    ID = "fillEmpty"
                });
            }
            else
            {
                countItems = 2;
                filterRow.Cells.Add(new TableCell {
                    Width = Unit.Pixel(150)
                });
                filterRow.Cells.Add(new TableCell {
                    Width = Unit.Pixel(150)
                });
                filterRow.Cells.Add(new TableCell {
                    ID = "fillEmpty"
                });
            }

            dropDownList    = new DropDownList();
            dropDownList.ID = "dropDownListID";
            filterRow.Cells[1].Controls.Add(dropDownList);

            controls = new WebControl[2];

            for (int i = 0; i != countItems; i++)
            {
                if (ColumnFilterStorage.IsRefBound)
                {
                    DataTable filterRefTable = DataSourceHelper.GetDataTable(ColumnFilterStorage.RefDataSource);

                    if (filterRefTable != null)
                    {
                        Type tableAdapterType = TableAdapterTools.GetTableAdapterType(filterRefTable.GetType());

                        tableDataSource              = new TableDataSource();
                        tableDataSource.ID           = String.Format("tableDataSource{0}_ID", i);
                        tableDataSource.TypeName     = tableAdapterType.FullName;
                        tableDataSource.SelectMethod = ColumnFilterStorage.SelectMethod;
                        tableDataSource.FillType     = TableDataSourceFillType.ParametersNotChanged;

                        if (SessionWorker == null)
                        {
                            SessionWorker sw = new SessionWorker(this.Page, Guid.NewGuid().ToString());
                            sw.Object     = filterRefTable.DataSet;
                            SessionWorker = sw;
                        }

                        tableDataSource.SessionWorker = SessionWorker;
                        tableDataSource.SetFilterByCustomConditions = false;
                        tableDataSource.View.CustomConditions.AddRange(ColumnFilterStorage.CustomConditions);
                        tableDataSource.HistoricalCountKeys = 0;

                        if (filterRefTable.Columns.IndexOf("dateEnd") != -1 && filterRefTable.Columns.IndexOf("dateStart") != -1)
                        {
                            tableDataSource.ShowHistoricalData = true;
                        }

                        filterRow.Cells[2 + i].Controls.Add(tableDataSource);

                        // This is only for compability with SMSES
                        ColumnFilterStorage.RefTableRolledIn =
                            (bool)(DataSetResourceManager.GetTableExtProperty(filterRefTable, TableExtProperties.ROLLED_IN) ?? false);
                    }
                    else
                    {
                        ColumnFilterStorage.RefTableRolledIn = false;
                    }

                    if (String.IsNullOrEmpty(ColumnFilterStorage.ValueColumn) || String.IsNullOrEmpty(ColumnFilterStorage.DisplayColumn))
                    {
                        throw new Exception("FILTER_REF_DISPLAY_COLUMN and FILTER_REF_VALUE_COLUMN attribute must be specified");
                    }

                    if (!string.IsNullOrEmpty(CheckedFilterCondition))
                    {
                        checkBoxForFilterCondition = new CheckBox
                        {
                            ID           = "checkBoxForFilter",
                            Text         = CheckedFilterConditionTooltip,
                            AutoPostBack = true,
                            TextAlign    = TextAlign.Right,
                        };
                        checkBoxForFilterCondition.CheckedChanged += OnCheckBoxForFilterConditionOnCheckedChanged;
                    }

                    if (ColumnFilterStorage.RefTableRolledIn)
                    {
                        LookupTextBox lookupTextBox = new LookupTextBox();
                        lookupTextBox.DataSource     = tableDataSource;
                        lookupTextBox.DataTextField  = ColumnFilterStorage.DisplayColumn;
                        lookupTextBox.DataValueField = ColumnFilterStorage.ValueColumn;
                        String Relation = (String)(DataSetResourceManager.GetTableExtProperty(filterRefTable, TableExtProperties.TREE_REF_RELATION) ?? "");
                        if (!String.IsNullOrEmpty(Relation))
                        {
                            String dataDisableRowField = (String)(DataSetResourceManager.GetTableExtProperty(filterRefTable, TableExtProperties.TREE_ALLOW_FIELD));

                            lookupTextBox.GridTreeMode = true;
                            if (!string.IsNullOrEmpty(dataDisableRowField))
                            {
                                lookupTextBox.DataDisableRowField = dataDisableRowField;
                            }
                        }
                        controls[i] = lookupTextBox;
                    }
                    else
                    {
                        var lookupList = new DropDownListExt();
                        if (tableDataSource != null)
                        {
                            lookupList.DataSource    = tableDataSource;
                            tableDataSource.FillType = TableDataSourceFillType.Always;
                        }
                        else
                        {
                            lookupList.DataSource = ColumnFilterStorage.RefDataSource;
                        }
                        lookupList.DataTextField   = ColumnFilterStorage.DisplayColumn;
                        lookupList.DataValueField  = ColumnFilterStorage.ValueColumn;
                        lookupList.IncludeNullItem = true;
                        lookupList.DataBind();
                        controls[i] = lookupList;
                    }
                }
                else if (ColumnFilterStorage.DataType == typeof(Int64) ||
                         ColumnFilterStorage.DataType == typeof(Int32) ||
                         ColumnFilterStorage.DataType == typeof(Int16) ||
                         ColumnFilterStorage.DataType == typeof(Byte) ||
                         ColumnFilterStorage.DataType == typeof(Double) ||
                         ColumnFilterStorage.DataType == typeof(Decimal) ||
                         ColumnFilterStorage.DataType == typeof(Single) ||
                         ColumnFilterStorage.DataType == typeof(String))
                {
                    var textBox = new TextBox();
                    controls[i] = textBox;
                    if (new Type[] { typeof(Int64), typeof(Int32), typeof(Int16) }.Contains(ColumnFilterStorage.DataType))
                    {
                        textBox.Attributes["type"] = "number";
                    }
                    if (TextBoxHeight != null)
                    {
                        textBox.Height   = TextBoxHeight.Value;
                        textBox.TextMode = TextBoxMode.MultiLine;
                    }
                }
                else if (ColumnFilterStorage.DataType == typeof(DateTime))
                {
                    DatePicker datePicker = new DatePicker();

                    switch (ColumnFilterStorage.DateTimeFormat)
                    {
                    case "{0:d}":
                        datePicker.Mode = DatePickerMode.Date;
                        break;

                    case "{0:t}":
                        datePicker.Mode = DatePickerMode.Time;
                        break;

                    case "{0:f}":
                        datePicker.Mode = DatePickerMode.DateTime;
                        break;
                    }
                    datePicker.PopupBehaviorParentNode = PopupBehaviorParentNode;
                    datePicker.Width = Unit.Pixel(150);
                    controls[i]      = datePicker;
                    ((DatePicker)controls[i]).AutoPostBack = postBack;
                }
                else if (ColumnFilterStorage.DataType == typeof(Boolean))
                {
                    DropDownList list = new DropDownList();
                    list.Items.Add(new ListItem(LookupControlsResources.STrue, true.ToString().ToLower()));
                    list.Items.Add(new ListItem(LookupControlsResources.SFalse, false.ToString().ToLower()));
                    controls[i] = list;
                }
                else
                {
                    throw new Exception(String.Format("Data type not supported: {0}", ColumnFilterStorage.DataType.Name));
                }

                controls[i].ID = String.Format("control{0}ID", i);
                filterRow.Cells[2 + i].Controls.Add(controls[i]);
                controls[i].Width = Unit.Percentage(100);
            }

            // Setup controls' properties
            filterRow.Cells[0].Text = ColumnFilterStorage.Caption;

            //filterRow.Cells[0].BackColor = Color.DarkTurquoise;
            //filterRow.Cells[1].BackColor = Color.DarkSeaGreen;
            //filterRow.Cells[2].BackColor = Color.Salmon;
            //filterRow.Cells[3].BackColor = Color.DodgerBlue;

            filterRow.Cells[0].Style["padding-right"] = "6px";
            filterRow.Cells[1].Style["padding-right"] = "6px";
            filterRow.Cells[2].Style["padding-right"] = "6px";
            filterRow.Cells[2].Style["display"]       = "none";
            if (filterRow.Cells.Count > 3 && filterRow.Cells[3].ID != "fillEmpty")
            {
                filterRow.Cells[3].Style["padding-right"] = "6px";
                filterRow.Cells[3].Style["display"]       = "none";
            }

            filterRow.Cells[0].Width = Unit.Pixel(170);
            filterRow.Cells[1].Width = Unit.Pixel(140);

            filterRow.Cells[0].HorizontalAlign = HorizontalAlign.Right;

            dropDownList.Width           = Unit.Percentage(100);
            dropDownList.AutoPostBack    = postBack;
            dropDownList.EnableViewState = false;
            foreach (ColumnFilterType columnFilterType in Enum.GetValues(typeof(ColumnFilterType)))
            {
                if (EnumHelper.Contains(columnFilterType, ColumnFilterStorage.AvailableFilters))
                {
                    ListItem ListItem = new ListItem();
                    ListItem.Value = Convert.ToInt64(columnFilterType).ToString();
                    if (CustomColumnFilterTypeCaptions != null && CustomColumnFilterTypeCaptions.ContainsKey(columnFilterType))
                    {
                        ListItem.Text = CustomColumnFilterTypeCaptions[columnFilterType];
                    }
                    else
                    {
                        ListItem.Text = columnFilterType.GetFilterTypeCaption();
                    }
                    dropDownList.Items.Add(ListItem);
                }
            }
            dropDownList.Enabled = dropDownList.Items.Count > 1;

            if (checkBoxForFilterCondition != null)
            {
                var tableRow = new TableRow();
                table.Rows.Add(tableRow);
                tableRow.Cells.Add(new TableCell {
                    Width = filterRow.Cells[0].Width, Height = new Unit(24, UnitType.Pixel),
                });
                tableRow.Cells.Add(new TableCell {
                    Width = filterRow.Cells[1].Width, Height = new Unit(24, UnitType.Pixel),
                });
                var tableCell = new TableCell
                {
                    Width      = filterRow.Cells[2].Width,
                    ColumnSpan = 2,
                    Height     = new Unit(24, UnitType.Pixel),
                };
                tableRow.Cells.Add(tableCell);
                tableCell.Controls.Add(checkBoxForFilterCondition);
                checkBoxForFilterCondition.Style["position"] = "relative";
                checkBoxForFilterCondition.Style["top"]      = "6px";

                tableRow.Cells[0].Style["padding-right"] = "6px";
                tableRow.Cells[1].Style["padding-right"] = "6px";
                tableRow.Cells[2].Style["padding-right"] = "6px";
            }

            table.Rows.Add(filterRow);
        }