Exemplo n.º 1
0
        private void Initialization()
        {
            if (tableDataSource == null)
            {
                DataTable filterRefTable = DataSourceHelper.GetDataTable(DataSource);

                // Initialization SessionWorker
                if (SessionWorker == null)
                {
                    var sw = new SessionWorker {
                        Key = Guid.NewGuid().ToString()
                    };
                    sw.SetSession(HttpContext.Current.Session);
                    sw.Object     = filterRefTable.DataSet;
                    SessionWorker = sw;
                }

                // Initialization tableDataSource
                Type tableAdapterType =
                    TableAdapterTools.GetTableAdapterType(filterRefTable.GetType());
                tableDataSource = new TableDataSource
                {
                    ID            = "tableDataSource_ID",
                    TypeName      = tableAdapterType.FullName,
                    SelectMethod  = this._storage.SelectMethod,
                    FillType      = TableDataSourceFillType.ParametersNotChanged,
                    SessionWorker = this.SessionWorker,
                    SetFilterByCustomConditions = false,
                };
                tableDataSource.View.CustomConditions.AddRange(_storage.CustomConditions);
            }
        }
Exemplo n.º 2
0
        private void LoadFiltersState()
        {
            var sid = GetSidBytes();
            // Loading user dependend filters state settings
            // In case there is no user setting apply default settings
            StorageValues storageValues = StorageValues.GetStorageValues(string.Format("{0}_{1}", Page.AppRelativeVirtualPath, ClientID), sid);

            if (storageValues != null)
            {
                foreach (ColumnFilterStorage storage in ColumnFilterStorages)
                {
                    storageValues.SetStorage(storage);
                }
            }
            else
            {
                WebInitializer.Initialize();
                foreach (ColumnFilterStorage storage in ColumnFilterStorages)
                {
                    ColumnFilterType columnFilterType = (ColumnFilterType)(DataSetResourceManager.GetColumnExtProperty(
                                                                               dataTable.Columns[storage.Name], ColumnExtProperties.FILTER_DEFAULT_CONDITION) ?? ColumnFilterType.None);
                    if (columnFilterType != ColumnFilterType.None)
                    {
                        if (!dataTable.Columns.Contains(storage.Name))
                        {
                            continue;
                        }
                        object[] values = new object[2];
                        values[0] = DataSetResourceManager.GetColumnExtProperty(dataTable.Columns[storage.Name], ColumnExtProperties.FILTER_DEFAULT_VALUE_1) ?? null;
                        values[1] = DataSetResourceManager.GetColumnExtProperty(dataTable.Columns[storage.Name], ColumnExtProperties.FILTER_DEFAULT_VALUE_2) ?? null;

                        string codeField = (String)DataSetResourceManager.GetColumnExtProperty(dataTable.Columns[storage.Name], ColumnExtProperties.FILTER_DEFAULT_VALUE_CODE_FIELD);

                        if (storage.IsRefBound && !string.IsNullOrEmpty(codeField))
                        {
                            for (int i = 0; i < values.Length; i++)
                            {
                                if (values[i] != null)
                                {
                                    DataTable table = (DataTable)storage.RefDataSource;

                                    QueryConditionList queryConditionList = new QueryConditionList();
                                    QueryCondition     queryCondition     = new QueryCondition(codeField, ColumnFilterType.Equal, values[i], null);
                                    queryConditionList.Add(queryCondition);
                                    Type tableAdapterType = TableAdapterTools.GetTableAdapterType(table.GetType());

                                    QueryGenerator queryGenerator;

                                    if (table.Columns.IndexOf("dateEnd") != -1 && table.Columns.IndexOf("dateStart") != -1)
                                    {
                                        Component adapter = HistoricalData.GetTableAdapterToHistoricalData("dateEnd", "dateStart", DateTime.Now, tableAdapterType, 0);
                                        queryGenerator = new QueryGenerator(adapter);
                                    }
                                    else
                                    {
                                        queryGenerator = new QueryGenerator(table);
                                    }

                                    queryGenerator.TopCount = 1;
                                    queryGenerator.Fill(table, queryConditionList);
                                    if (table.Rows.Count != 0)
                                    {
                                        values[i] = table.Rows[0][storage.ValueColumn];
                                    }
                                }
                            }
                        }
                        storage.FilterType = columnFilterType;
                        try
                        {
                            for (int i = 0; i != 2; i++)
                            {
                                if (values[i] != null)
                                {
                                    storage.SetValue(i, Convert.ChangeType(values[i], storage.DataType));
                                }
                            }
                        }
                        catch (InvalidCastException)
                        {
                        }
                    }
                }
            }
        }
Exemplo n.º 3
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);
        }