예제 #1
0
 /// <summary>
 /// Instancia um objeto
 /// </summary>
 /// <param name="pTableQuery">Um objeto TableQuery de origem</param>
 /// <param name="pOn">Clausula on</param>
 public Join(TableQuery pTableQuery, WhereCollection pOn)
     : this()
 {
     this.TableQuery   = pTableQuery;
     this.RelationShip = eJoinRelationShip.ejrInnerJoin;
     this.On           = pOn;
 }
예제 #2
0
 /// <summary>
 /// Clona o objeto
 /// </summary>
 /// <param name="pJoin">Objeto de Origem</param>
 public Join(Join pJoin)
     : this()
 {
     this.RelationShip = pJoin.RelationShip;
     this.TableQuery   = new TableQuery(pJoin.TableQuery);
     //this.FieldName = new QueryParam ( pJoin.FieldName );
     this.On = new WhereCollection(pJoin.On);
 }
예제 #3
0
        public void WhereDoesFiltering()
        {
            var list     = Enumerable.Range(1, 100).ToList();
            var filtered = new WhereCollection <int>(list, i => i % 2 == 0);

            Assert.Equal(50, filtered.Count);
            for (int i = 0; i < 50; i++)
            {
                Assert.Equal((i + 1) * 2, filtered[i]);
            }
        }
        /// <summary>
        /// Append a <see cref="List{T}"/> of <see cref="FilterField"/> to a Where Collection
        /// </summary>
        /// <param name="whereCollection">Reference to the WhereCollection</param>
        /// <param name="queryFilters">The <see cref="List{T}"/> of <see cref="FilterField"/> containing the Query String filters</param>
        /// <param name="wrapIntoParenthesis">A flag to define whether to wrap the filters into a parenthesis</param>
        public static void AppendQueryFilters(this WhereCollection whereCollection, List <FilterField> queryFilters, bool wrapIntoParenthesis)
        {
            if (queryFilters == null)
            {
                return;
            }
            if (queryFilters.Count == 0)
            {
                return;
            }

            AppendQueryFilters(whereCollection, queryFilters.ToArray(), wrapIntoParenthesis);
        }
예제 #5
0
        public void RequeryOnSourceChange()
        {
            var list = new ThreadSafeBindableCollection <int>();

            list.AddRange(Enumerable.Range(1, 100));
            var filtered = new WhereCollection <int>(list, i => i % 2 == 0);

            Assert.Equal(50, filtered.Count);
            list.Add(3);
            Assert.Equal(50, filtered.Count);
            list.Add(4);
            Assert.Equal(51, filtered.Count);
        }
        /// <summary>
        /// Captura o Join do Banco de dados
        /// </summary>
        /// <param name="pOn">Tabelas</param>
        /// <returns>Um string do Join</returns>
        public StringBuilder GetJoinOn(WhereCollection pOn)
        {
            var where = new StringBuilder();

            foreach (QueryParam myItem in pOn)
            {
                where.AppendFormat("\t{0}\n",
                                   GetConditionFieldName(myItem, where.Length > 0, true));
            }

            if (where.Length > 0)
            {
                where.Insert(0, " ON ");
            }

            return(where);
        }
예제 #7
0
        public void SendPropertyChangeNotification()
        {
            var list = new ThreadSafeBindableCollection <int>();

            list.AddRange(Enumerable.Range(1, 100));
            var filtered = new WhereCollection <int>(list, i => i % 2 == 0);
            int ccFired  = 0;

            filtered.PropertyChanged += (s, e) =>
            {
                Assert.Equal(filtered, s);
                Assert.Equal("Count", e.PropertyName);
                ccFired++;
            };
            list.Add(4);
            Assert.Equal(1, ccFired);
        }
예제 #8
0
        public void SendListChangeNotification()
        {
            var list = new ThreadSafeBindableCollection <int>();

            list.AddRange(Enumerable.Range(1, 100));
            var filtered = new WhereCollection <int>(list, i => i % 2 == 0);
            int ccFired  = 0;

            filtered.CollectionChanged += (s, e) =>
            {
                Assert.Equal(filtered, s);
                Assert.Equal(NotifyCollectionChangedAction.Reset, e.Action);
                ccFired++;
            };
            list.Add(4);
            Assert.Equal(1, ccFired);
        }
        public void LoadDataFromServer_WhereCollection_CreatesRequest()
        {
            // Arrange
            var mockProvider = new MockProvider();
            var requestFactory = new DicomRequestFactoryFake();
            var dataLoader = new DicomDataLoader<TestInfo>(mockProvider.GetCacheProviderFake(), mockProvider.GetCacheIndexProviderFake(), mockProvider.GetDicomClientFactoryFake(), requestFactory);
            var whereCollection = new WhereCollection<TestInfo>(mockProvider.GetDicomMappingFake());
            whereCollection.WhereEquals(DicomTags.PatientID, 1);

            // Act
            dataLoader.LoadDataFromServer(whereCollection);

            var whereItem = ((IDicomWhereCollection)requestFactory.WhereCollection).Single();

            // Assert
            Assert.That(whereItem.DicomTag, Is.EqualTo(DicomTags.PatientID));
            Assert.That(whereItem.Value, Is.EqualTo("1"));
        }
예제 #10
0
파일: TSQL.cs 프로젝트: lionzhou1981/Lion
 /// <summary>
 /// TSQL(TSQLType) 构造函数
 /// </summary>
 /// <param name="_type">Sql命令类型</param>
 /// <param name="_tableName">Table名称(选填)</param>
 public TSQL(TSQLType _type, string _tableName = "")
 {
     this.Type   = _type;
     this.Tables = new TableCollection();
     if (_tableName != "")
     {
         this.Tables.Add(_tableName);
     }
     this.Fields     = new FieldCollection();
     this.Outputs    = new OutputCollection();
     this.Wheres     = new WhereCollection();
     this.Groups     = new GroupCollection();
     this.Havings    = new WhereCollection();
     this.Orders     = new OrderCollection();
     this.Procedures = "";
     this.Parameters = new List <Parameter>();
     this.Limit      = 0;
     this.Offset     = 0;
 }
예제 #11
0
        private void button3_Click(object sender, EventArgs e)
        {
            ProfitabilityBase obj = DBTeste.CreateObject <ProfitabilityBase>();

            TableQuery query = new TableQuery(obj);

            WhereCollection where = new WhereCollection()
            {
                new QueryParam(obj.Collumns[0], "1")
            };

            WhereCollection where1 = new WhereCollection()
            {
                new QueryParam(obj.Collumns[1], eCondition.ecIsNull),
            };

            query.Wheres.Add(where);
            query.Wheres.Add(where1);

            SqlServerScriptWizard scrip = new SqlServerScriptWizard(query);

            var result = scrip.GetSelectStatment();
        }
 /// <summary>
 /// Construtores
 /// </summary>
 public SqlServerScriptWizard()
 {
     Parameters = new WhereCollection();
 }
예제 #13
0
        public async void LoadDataFromCacheAsync_ReturnsFromCache()
        {
            // Arrange
            var mockProvider = new MockProvider();
            var cacheProvider = mockProvider.GetCacheProviderFake();
            var dataLoader = new DicomDataLoader<TestInfo>(cacheProvider, mockProvider.GetCacheIndexProviderFake(), mockProvider.GetDicomClientFactoryFake(), mockProvider.GetDicomRequestFactoryFake());
            var whereCollection = new WhereCollection<TestInfo>(mockProvider.GetDicomMappingFake());
            whereCollection.WhereEquals(DicomTags.PatientID, 1);

            // Act
            var result = (await dataLoader.LoadDataFromCacheAsync(whereCollection)).Single();

            // Assert
            Assert.That(result.PatientID, Is.EqualTo(1));
            Assert.That(() => cacheProvider.Received(1).Retrieve<TestInfo>(), Throws.Nothing);
        }
예제 #14
0
        public async void LoadDataFromServerAsync_GetResponse_StoresInCache()
        {
            // Arrange
            var mockProvider = new MockProvider();
            var cacheProvider = mockProvider.GetCacheProviderFake();
            var dataLoader = new DicomDataLoader<TestInfo>(cacheProvider, mockProvider.GetCacheIndexProviderFake(), mockProvider.GetDicomClientFactoryFake(), mockProvider.GetDicomRequestFactoryFake());

            var whereCollection = new WhereCollection<TestInfo>(mockProvider.GetDicomMappingFake());
            whereCollection.WhereEquals(DicomTags.PatientID, 1);

            // Act
            var result = await dataLoader.LoadDataFromServerAsync(whereCollection);

            // Assert
            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(result.All(c=>c.PatientID == 1), Is.True);
            Assert.That(() => cacheProvider.Received(1).Store(Arg.Any<string>(), Arg.Any<object>(), Arg.Any<bool>()), Throws.Nothing);
        }
        /// <summary>
        /// Append an array of <see cref="FilterField"/> to a Where Collection
        /// </summary>
        /// <param name="whereCollection">Reference to the WhereCollection</param>
        /// <param name="filterFields">An array of <see cref="FilterField"/> containing the query string filters</param>
        /// <param name="wrapIntoParenthesis">A flag to define whether to wrap the filters into a parenthesis</param>
        public static void AppendQueryFilters(this WhereCollection whereCollection, FilterField[] filterFields, bool wrapIntoParenthesis)
        {
            // Make sure filters are not null
            if (filterFields == null)
            {
                return;
            }
            if (filterFields.Length == 0)
            {
                return;
            }

            // Makre sure where collection is initialized
            if (whereCollection == null)
            {
                throw new NullReferenceException("The 'WhereCollection' is empty. System is unable to Append Query Filters to a null collection");
            }

            // The Grouped Where Collection
            var groupedWhereCollection = new GroupedFilterExpression(FieldAndOr.And);

            // Loop thru all filters on the QueryFilters
            foreach (var filter in filterFields)
            {
                // Creates the Expression
                var filterExpression = new FilterExpression()
                {
                    Field1 = new Field(filter.Field),
                    Field2 = filter.Value,
                    AndOr  = FieldAndOr.And,
                };

                // Chooses the Operator
                switch (filter.Operator)
                {
                case FilterFieldOperations.NotEqual: filterExpression.Operator = FieldOperators.NotEqual; break;

                case FilterFieldOperations.In: filterExpression.Operator = FieldOperators.In; break;

                case FilterFieldOperations.NotIn: filterExpression.Operator = FieldOperators.NotIn; break;

                case FilterFieldOperations.LessThan: filterExpression.Operator = FieldOperators.LessThan; break;

                case FilterFieldOperations.LessThanOrEqualTo: filterExpression.Operator = FieldOperators.LessThanOrEqual; break;

                case FilterFieldOperations.GreaterThan: filterExpression.Operator = FieldOperators.GreaterThan; break;

                case FilterFieldOperations.GreaterThanOrEqualTo: filterExpression.Operator = FieldOperators.GreaterThanOrEqual; break;

                default:
                    filterExpression.Operator = FieldOperators.Equal;
                    break;
                }

                // Adds the Other Side of the Filter
                //if (filter.Value.GetType().IsArray)
                //{
                //    filterExpression.Field2 = filter.Value;
                //}
                //else
                //{
                //    filterExpression.Field2 = filter.Value;
                //}

                // Includes it on the collection
                if (wrapIntoParenthesis)
                {
                    groupedWhereCollection.Add(filterExpression);
                }
                else
                {
                    whereCollection.Add(filterExpression);
                }
            }

            // When wrapping, adds the GroupedWhereCollection later
            if (wrapIntoParenthesis)
            {
                whereCollection.Add(groupedWhereCollection);
            }
        }
        private bool HasOneLine(string pFieldName, ref ChooseFromListEventArgs e)
        {
            var query = new TableQuery(Query)
            {
                Top = 2
            };

            var serarchField = new List <TableAdapterField>
            {
                query.Fields[pFieldName]
            };

            if (pFieldName == FieldNameDescription)
            {
                serarchField.AddRange(WhereColumns);
            }

            var where = new WhereCollection();

            foreach (var column in serarchField)
            {
                where.Add(column.DbTypeIsNumeric()
                    ? new QueryParam(column, e.SearchBy == null ? 0 : e.SearchBy.To <Int64>())
                               : new QueryParam(column, e.SearchBy ?? string.Empty));

                where.Last().Relationship = eRelationship.erOr;

                if (ConditionQuery != eCondition.ecNone)
                {
                    where.Last().Condition = ConditionQuery;
                }
            }

            query.Wheres.Add(where);

            var script = new SqlServerScriptWizard(query);

            var command = script.GetSelectStatment();
            var data    = Connection.Instance.SqlServerQuery(command.Item1, command.Item2);

            if (data.Rows.Count == 1)
            {
                e.Record = data.Rows[0];
            }
            else
            {
                serarchField = new List <TableAdapterField> {
                    query.Fields[pFieldName]
                };

                if (pFieldName == FieldNameDescription)
                {
                    serarchField.AddRange(WhereColumns);
                }

                where = new WhereCollection();

                foreach (var column in serarchField)
                {
                    @where.Add(column.DbTypeIsNumeric()
                                   ? new QueryParam(column, e.SearchBy == null ? 0 : e.SearchBy.To <Int64>())
                                   : new QueryParam(column, eCondition.ecLike, e.SearchBy ?? String.Empty));

                    where.Last().Relationship = eRelationship.erOr;
                }

                query.Wheres.Add(where);

                var comand = script.GetSelectStatment();
                data = Connection.Instance.SqlServerQuery(comand.Item1, comand.Item2);

                if (data.Rows.Count == 1)
                {
                    e.Record = data.Rows[0];
                }
            }

            return(data.Rows.Count == 1);
        }
예제 #17
0
        private void FillResult()
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                var query = new TableQuery(Query);

                if (!String.IsNullOrEmpty(SearchBy))
                {
                    var where = new WhereCollection();
                    foreach (var item in SearchColumns)
                    {
                        QueryParam param;

                        if (item.DbTypeIsNumeric())
                        {
                            int intConvert;

                            if (!int.TryParse(SearchBy, out intConvert))
                            {
                                continue;
                            }

                            param = new QueryParam(item, intConvert);
                        }
                        else
                        {
                            param = new QueryParam(item, eCondition.ecLike, SearchBy);
                        }

                        param.Relationship = eRelationship.erOr;
                        where.Add(param);

                        query.OrderBy.Add(new OrderBy(param));
                    }
                    query.Wheres.Add(where);
                }

                var command = new SqlServerScriptWizard(query).GetSelectStatment();
                grdResult.DataSource = Connection.Instance.SqlServerQuery(command.Item1, command.Item2);
                ViewResult.BestFitColumns();

                ViewResult.ClearSorting();

                if (!SearchColumns.IsEmpty())
                {
                    ViewResult.FocusedColumn           = ViewResult.Columns[SearchColumns.First().Name];
                    ViewResult.FocusedColumn.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;

                    if (Record != null)
                    {
                        var fieldValue = Record[ViewResult.FocusedColumn.FieldName].ToString();
                        ViewResult.StartIncrementalSearch(fieldValue);
                    }
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }