示例#1
0
        public static QueryConditionList GetHistoricalOverCondition(string endDateField, DateTime?HistolicalPoint)
        {
            var      queryConditions = new QueryConditionList();
            DateTime Date            = HistolicalPoint ?? DateTime.Now;
            var      condition       = new QueryCondition(endDateField, ColumnFilterType.Less, Date, null);

            queryConditions.Add(condition);
            return(queryConditions);
        }
示例#2
0
        public static QueryConditionList GetHistoricalCondition(string endDateField, string StartDateField, DateTime?HistolicalPoint)
        {
            var      queryConditions    = new QueryConditionList();
            DateTime Date               = HistolicalPoint ?? DateTime.Now;
            var      startDateCondition = new QueryCondition(StartDateField, ColumnFilterType.LessOrEqual, Date, null);

            queryConditions.Add(startDateCondition);

            var nullEndDateCondition = new QueryCondition(endDateField, ColumnFilterType.IsNull);
            var lessEndDateCondition = new QueryCondition(endDateField, ColumnFilterType.MoreOrEqual, Date, null);

            var endDateCondition = new QueryCondition();

            endDateCondition.Conditions = new QueryConditionList {
                ConditionJunction = ConditionJunction.Or
            };
            endDateCondition.Conditions.Add(nullEndDateCondition);
            endDateCondition.Conditions.Add(lessEndDateCondition);
            queryConditions.Add(endDateCondition);
            return(queryConditions);
        }
        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)
                        {
                        }
                    }
                }
            }
        }