/// <summary>
        /// Subquery expression in the format
        /// .WhereAll(() =&gt; alias.Property [==, !=, >, etc.] detachedQueryOver.As&lt;propertyType&gt;())
        /// </summary>
        public TReturn WhereAll(Expression <Func <bool> > expression)
        {
            AbstractCriterion criterion = ExpressionProcessor.ProcessSubquery(LambdaSubqueryType.All, expression);

            root.And(criterion);
            return(root);
        }
        /// <summary>
        /// Subquery expression in the format
        /// .Where(t =&gt; t.Property [==, !=, >, etc.] detachedQueryOver.As&lt;propertyType&gt;())
        /// </summary>
        public TReturn Where(Expression <Func <TSubType, bool> > expression)
        {
            AbstractCriterion criterion = ExpressionProcessor.ProcessSubquery <TSubType>(LambdaSubqueryType.Exact, expression);

            root.And(criterion);
            return(root);
        }
Example #3
0
        private static void GetFilterCriteria(ICriteria cr, Dictionary <string, object> filters, Sort sort = null)
        {
            string   employee  = Convert.ToString(filters["employee"]);
            DateTime work_date = (DateTime)filters["work_date"];

            if (!string.IsNullOrEmpty(employee))
            {
                cr = cr.CreateCriteria("attendance.Employee", "e", JoinType.InnerJoin);

                AbstractCriterion a1 = Restrictions.InsensitiveLike("e.Firstname", employee, MatchMode.Anywhere);
                AbstractCriterion a2 = Restrictions.InsensitiveLike("e.Middlename", employee, MatchMode.Anywhere);
                AbstractCriterion a3 = Restrictions.InsensitiveLike("e.Lastname", employee, MatchMode.Anywhere);

                AbstractCriterion b1 = Restrictions.Or(a1, a2);
                AbstractCriterion b2 = Restrictions.Or(b1, a3);

                cr.Add(b2);
            }

            if (work_date != default(DateTime))
            {
                cr.Add(Restrictions.Eq("attendance.Workdate", work_date));
            }

            if (sort != null)
            {
                SetJoinCriteria(cr, sort);
            }
        }
Example #4
0
 protected static QueryBuilder<T> FromCriterion(AbstractCriterion criterion,
     string name, string assoicationPath)
 {
     QueryBuilder<T> queryBuilder = new QueryBuilder<T>(name, assoicationPath);
     queryBuilder.AddCriterion(criterion);
     return queryBuilder;
 }
Example #5
0
        private static void GetFilterCriteria(ICriteria cr, int find, string keyword)
        {
            if (!string.IsNullOrEmpty(keyword))
            {
                if (find == 1)
                {
                    cr.Add(Restrictions.InsensitiveLike("des.Title", keyword, MatchMode.Anywhere));
                }

                else if (find == 2)
                {
                    cr.Add(Restrictions.InsensitiveLike("des.Description", keyword, MatchMode.Anywhere));
                }

                else if (find == 3)
                {
                    cr.Add(Restrictions.InsensitiveLike("des.Note", keyword, MatchMode.Anywhere));
                }

                else
                {
                    AbstractCriterion a1 = Restrictions.InsensitiveLike("des.Title", keyword, MatchMode.Anywhere);
                    AbstractCriterion a2 = Restrictions.InsensitiveLike("des.Description", keyword, MatchMode.Anywhere);
                    AbstractCriterion a3 = Restrictions.InsensitiveLike("des.Note", keyword, MatchMode.Anywhere);

                    AbstractCriterion b1 = Restrictions.Or(a1, a2);
                    AbstractCriterion b2 = Restrictions.Or(b1, a3);

                    cr.Add(b2);
                }
            }
        }
Example #6
0
        public virtual StateTransition FindStateTransition(Context context, String fromStateCode, String toStateCode)
        {
            State from = null;

            foreach (State s in States)
            {
                if (s.Code.Equals(fromStateCode))
                {
                    from = s;
                }
            }
            State to = null;

            foreach (State s in States)
            {
                if (s.Code.Equals(toStateCode))
                {
                    to = s;
                }
            }

            AbstractCriterion fromExp = null == from?Expression.IsNull("FromState")
                                            : Expression.Eq("FromState", from);

            AbstractCriterion toExp = null == to?Expression.IsNull("ToState")
                                          : Expression.Eq("ToState", to);

            return(context.PersistenceSession.CreateCriteria <StateTransition>()
                   .Add(fromExp).Add(toExp).UniqueResult <StateTransition>());
        }
Example #7
0
        protected ICriteria CreateSearchCriteria(RequestSearchRequest searchRequest)
        {
            ICriteria criteria = Session.CreateCriteria(typeof(Request));

            SimpleExpression shortDescExp = Restrictions.Like("ShortDesc", searchRequest.RequestQuery,
                                                              MatchMode.Anywhere);
            SimpleExpression longDescExp   = Restrictions.Like("LongDesc", searchRequest.RequestQuery, MatchMode.Anywhere);
            SimpleExpression dashboardDesc = Restrictions.Like("DashboardDescription", searchRequest.RequestQuery,
                                                               MatchMode.Anywhere);
            AbstractCriterion or  = Restrictions.Or(shortDescExp, longDescExp);
            AbstractCriterion or1 = Restrictions.Or(or, dashboardDesc);

            criteria.Add(or1);

            if (searchRequest.SystemId > 0)
            {
                criteria.Add(Restrictions.Eq("WrmsSystem.Id", searchRequest.SystemId));
            }
            if (searchRequest.RequestStatusId > 0)
            {
                criteria.Add(Restrictions.Eq("RequestStatus.Id", searchRequest.RequestStatusId));
            }
            if (searchRequest.ProjectManagerId > 0)
            {
                criteria.Add(Restrictions.Eq("ProjectManager.Id", searchRequest.ProjectManagerId));
            }
            return(criteria);
        }
Example #8
0
        // CONSTRUCTORS

        // METHODS
        public void Initialize()
        {
            this.m_criterion = AbstractCriterion.CreateCriterion(this);
            if (this.m_criterion != null)
            {
                this.m_criterion.AddUsefullness(this.Achievement);
            }
        }
        public static AbstractCriterion CriaFiltroBeforeOrEqData(DateTime data, string horaTxt)
        {
            AbstractCriterion crit1 = Expression.Lt("Data", data);
            AbstractCriterion crit2 = Expression.And(Expression.Le("Data", data), Expression.Le("HoraTxt", horaTxt));
            AbstractCriterion crit  = Expression.Or(crit1, crit2);

            return(crit);
        }
        /// <summary>
        /// Convert a lambda expression to NHibernate subquery AbstractCriterion
        /// </summary>
        /// <param name="subqueryType">type of subquery</param>
        /// <param name="expression">lambda expression to convert</param>
        /// <returns>NHibernate.ICriterion.AbstractCriterion</returns>
        public static AbstractCriterion ProcessSubquery(LambdaSubqueryType subqueryType,
                                                        Expression <Func <bool> > expression)
        {
            BinaryExpression  be        = (BinaryExpression)expression.Body;
            AbstractCriterion criterion = ProcessSubqueryExpression(subqueryType, be);

            return(criterion);
        }
Example #11
0
 private AbstractCriterion Process(AbstractCriterion criterion)
 {
     if (this.isNot)
     {
         return(Restrictions.Not(criterion));
     }
     return(criterion);
 }
Example #12
0
        private DetachedCriteria GetVehiclesDetachedCriteria(int[] vehiclesIds, int[] empresaIds, int[] lineaIds)
        {
            DetachedCriteria dc = DetachedCriteria.For <Coche>("c").SetProjection(Projections.Property("Id"));

            if (vehiclesIds.Count() > 0)
            {
                dc.Add(Restrictions.In("Id", vehiclesIds));
            }

            if (empresaIds.Count() > 0)
            {
                AbstractCriterion nullEmpresa         = Restrictions.IsNull("Empresa.Id");
                int[]             empresasIds         = (empresaIds[0] == 0 ? empresaIds.Skip(1).ToArray() : empresaIds);
                AbstractCriterion empresasRestriction = Restrictions.In("Empresa.Id", empresasIds);

                if (empresaIds.Count() == 1)
                {
                    if (empresaIds[0] != 0)
                    {
                        dc.Add(empresasRestriction);
                    }
                    else if (empresaIds[0] == 0)
                    {
                        dc.Add(Restrictions.Or(nullEmpresa, empresasRestriction));
                    }
                    else
                    {
                        dc.Add(empresasRestriction);
                    }
                }
            }

            if (lineaIds.Count() > 0)
            {
                AbstractCriterion nulllinea         = Restrictions.IsNull("Linea.Id");
                int[]             lineasIds         = (lineaIds[0] == 0 ? lineaIds.Skip(1).ToArray() : lineaIds);
                AbstractCriterion lineasRestriction = Restrictions.In("Linea.Id", lineasIds);

                if (lineaIds.Count() == 1)
                {
                    if (lineaIds[0] != 0)
                    {
                        dc.Add(lineasRestriction);
                    }
                    else if (lineaIds[0] == 0)
                    {
                        dc.Add(Restrictions.Or(nulllinea, lineasRestriction));
                    }
                    else
                    {
                        dc.Add(lineasRestriction);
                    }
                }
            }

            return(dc);
        }
Example #13
0
        public void CanFindAllMatchingCriterion()
        {
            //create another object named Parent4
            CreateExampleParentObjectInDb("Parent4", 1);

            AbstractCriterion    whereName = Expression.Eq("Name", "Parent4");
            ICollection <Parent> loaded    = Repository <Parent> .FindAll(whereName);

            Assert.AreEqual(2, Collection.ToUniqueCollection(loaded).Count);
        }
        public void CanUseNotOperatorForExpressions()
        {
            AbstractCriterion lhs = Expression.Eq("foo", "bar");
            AbstractCriterion not = !lhs;

            Assert.AreEqual(typeof(NotExpression), not.GetType());
            AbstractCriterion not_value = (AbstractCriterion)GetField("_criterion", typeof(NotExpression)).GetValue(not);

            Assert.AreEqual(lhs, not_value);
        }
        public void CanUseAndOperatorForExpressions()
        {
            AbstractCriterion lhs = Expression.Eq("foo", "bar");
            AbstractCriterion rhs = Expression.Gt("date", DateTime.Today);

            AbstractCriterion and = lhs && rhs;

            Assert.AreEqual(typeof(AndExpression), and.GetType());
            Assert.AreEqual(lhs, GetLeftSide(and));
            Assert.AreEqual(rhs, GetRightSide(and));
        }
        public void CanUseOrOperatorForEpressions()
        {
            AbstractCriterion lhs = Expression.Eq("foo", "bar");
            AbstractCriterion rhs = Expression.Gt("date", DateTime.Today);

            AbstractCriterion or = lhs || rhs;

            Assert.AreEqual(typeof(OrExpression), or.GetType());
            Assert.AreEqual(lhs, GetLeftSide(or));
            Assert.AreEqual(rhs, GetRightSide(or));
        }
Example #17
0
 public XmlIn(string propertyName, IEnumerable values)
 {
     this.propertyName = propertyName;
     ArrayList arrayList = new ArrayList();
     foreach (object o in values)
     {
         arrayList.Add(o);
     }
     this.values = arrayList.ToArray();
     expr = Expression.In(propertyName, arrayList);
 }
            public AbstractCriterion And(object hi)
            {
                AbstractCriterion criterion = projection.Create <AbstractCriterion>(s => Restrictions.Between(s, lo, hi), p => Restrictions.Between(p, lo, hi));

                if (isNot)
                {
                    return(Restrictions.Not(criterion));
                }

                return(criterion);
            }
        public bool TryGetAbstractCriterion(string criterion, out AbstractCriterion result)
        {
            result = null;
            if (this.m_criterions.ContainsKey(criterion))
            {
                result = this.m_criterions[criterion];
                return(true);
            }

            return(false);
        }
Example #20
0
        private AbstractCriterion BuildCreatorAndAssigneeCriteria(Team team, Account account)
        {
            AbstractCriterion criteria = null;
            var member = team.GetMember(account);

            if (member != null)
            {
                criteria = Expression.Or(Expression.Eq("CreatorMemberId", member.ID), Expression.Eq("AssigneeId", member.ID));
            }
            return(criteria);
        }
Example #21
0
        public static IList <PersonOrgRelation> List(Context context, TreeListNode category, Organization org, OrgUnit orgUnit, DateTime onDate)
        {
            AbstractCriterion orgUnitExp = orgUnit == null?Expression.IsNull("OrgUnit") : Expression.Eq("OrgUnit", orgUnit);

            return(context.PersistenceSession.CreateCriteria <PersonOrgRelation>()
                   .Add(Expression.Eq("RelationshipCategory", category))
                   .Add(Expression.Eq("Organization", org))
                   .Add(orgUnitExp)
                   .Add(Expression.Le("EffectivePeriod.From", onDate))
                   .Add(Expression.Ge("EffectivePeriod.To", onDate))
                   .List <PersonOrgRelation>());
        }
Example #22
0
        public void CanFindAllMatchingCriterionWithMultipleSortOrders()
        {
            Parent secondPosition = CreateExampleParentObjectInDb("ThisTestOnly", 3);
            Parent firstPosition  = CreateExampleParentObjectInDb("ThisTestOnly", 9999);

            CreateExampleParentObjectInDb("NoMatch", 5);

            AbstractCriterion    whereName = Expression.Eq("Name", "ThisTestOnly");
            ICollection <Parent> loaded    = Repository <Parent> .FindAll(OrderByNameAndAgeDescending, whereName);

            AssertCollectionsEqual(ExpectedList(firstPosition, secondPosition), loaded);
        }
        public void AddCriterion(AbstractCriterion criterion)
        {
            if (criterion == null)
            {
            }

            this.m_criterions.Add(criterion.Criterion, criterion);
            if (criterion.IsIncrementable)
            {
                this.AddIncrementableCriterion(criterion);
            }
        }
Example #24
0
        public XmlIn(string propertyName, IEnumerable values)
        {
            this.propertyName = propertyName;
            ArrayList arrayList = new ArrayList();

            foreach (object o in values)
            {
                arrayList.Add(o);
            }
            this.values = arrayList.ToArray();
            expr        = Expression.In(propertyName, arrayList);
        }
Example #25
0
        public QueryBuilder <T> In <K>(params K[] values)
        {
            AbstractCriterion inExpression = Expression.In(myName, values);
            QueryBuilder <T>  self         = this;

            if (backTrackAssociationsOnEquality)
            {
                self = new QueryBuilder <T>(myName, BackTrackAssociationPath(associationPath));
                children.Add(self);
            }
            self.AddCriterion(inExpression);
            return(this);
        }
Example #26
0
        private ICriteria GetEventsRowCount(Int32 top, AbstractCriterion ac, Order order, IProjection p)
        {
            var eventosCriteria = Session.CreateCriteria <LogMensaje>("lm")
                                  .Add(ac)
                                  .SetProjection(Projections.RowCount());


            if (p != null)
            {
                eventosCriteria.SetProjection(p);
            }

            return(eventosCriteria);
        }
        public void AddCriterion(AbstractCriterion criterion)
        {
            this.m_finishedCriterions.Add(criterion.Criterion, criterion);

            foreach (var item in criterion.UsefullFor)
            {
                if (item.Objectives.All(entry => this.m_finishedCriterions.ContainsKey(entry.Criterion)))
                {
                    this.CompleteAchievement(item);
                }
            }

            this.Owner.Record.FinishedAchievementObjectives.Add(criterion.DefaultObjective.Id);
        }
Example #28
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="values"></param>
        public XmlIn(string propertyName, IEnumerable values)
        {
            _propertyName = propertyName;

            var list = new ArrayList();

            foreach (object val in values)
            {
                list.Add(val);
            }
            _values = list.ToArray();

            _expr = Restrictions.In(propertyName, list);
        }
Example #29
0
        /// <summary>
        /// kiểm tra voucher code đã được dùng hay chưa
        /// </summary>
        /// <param name="code">voucher code</param>
        /// <param name="count">dùng để dưa kết quả của biến count ra ngoài</param>
        /// <param name="batch">gói voucher</param>
        public void CheckCode(String code, out int count, out VoucherBatch batch)
        {
            /*Điều kiện tìm booking : tìm theo bookingid và booking chưa bị deleted và đã có voucher code và status không phải là cancelled */
            int batchid;

            AbstractCriterion crit = Expression.Eq("Deleted", false);

            crit = Expression.And(crit, Expression.Or(Expression.Not(Expression.Eq("VoucherCode", null)), Expression.Not(Expression.Eq("VoucherCode", ""))));

            if (!string.IsNullOrEmpty(Request.QueryString["bookingid"]))
            {
                crit = Expression.And(crit,
                                      Expression.Not(Expression.Eq("Id",
                                                                   Convert.ToInt32(Request.QueryString["bookingid"]))));
                crit = Expression.And(crit,
                                      Expression.Not(Expression.Eq("Status",
                                                                   StatusType.Cancelled)));
            }

            count = 0;
            var bookingList = Module.GetObject <Booking>(crit, 0, 0);

            /* kiểm tra voucher nhập vào đã dùng trong các booking vừa tìm hay chưa, nếu trùng tăng biến đếm count
             *  và đưa kết quả ra ngoài để xử lý
             */
            foreach (Booking booking in bookingList)
            {
                string[] codeArray = booking.VoucherCode.Split(new char[] { ';' });
                for (int i = 0; i < codeArray.Length; i++)
                {
                    if (code == codeArray[i])
                    {
                        count++;
                    }
                }
            }
            try
            {
                /* giải mã voucher xem nó thuộc gói voucher nào*/
                VoucherCodeEncryption.Decrypt(Convert.ToUInt32(code), out batchid);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            /*tìm gói voucher và đưa kết quả ra ngoài để xử lý*/
            batch = Module.GetObject <VoucherBatch>(batchid);
        }
Example #30
0
        protected virtual void SetupFilter(ICriteria crit, F filter)
        {
            if (filter.Id.HasValue)
            {
                crit.Add(Restrictions.IdEq(filter.Id.Value));
            }
            if (!string.IsNullOrEmpty(filter.SearchString))
            {
                var properties           = typeof(T).GetProperties();
                AbstractCriterion clause = null;

                foreach (var property in properties)
                {
                    //определяем участвует ли свойство в поиске
                    var fs = property.GetCustomAttribute <FastSearchAttribute>();
                    if (fs == null)
                    {
                        continue;
                    }

                    AbstractCriterion like;

                    switch (fs.FiledType)
                    {
                    case FiledType.Int:
                        var proj = Projections
                                   .Cast(NHibernateUtil.Int32, Projections.Property(property.Name));
                        like   = Restrictions.InsensitiveLike(proj, filter.SearchString, MatchMode.Anywhere);
                        clause = (clause == null) ? like : Restrictions.Or(clause, like);
                        break;

                    case FiledType.ComplexEntity:
                        var c = crit.CreateCriteria(property.Name);
                        c.Add(Restrictions.InsensitiveLike("Name", filter.SearchString, MatchMode.Anywhere));
                        break;

                    default:
                        like   = Restrictions.InsensitiveLike(property.Name, filter.SearchString, MatchMode.Anywhere);
                        clause = (clause == null) ? like : Restrictions.Or(clause, like);
                        break;
                    }
                }

                if (clause != null)
                {
                    crit.Add(clause);
                }
            }
        }
Example #31
0
        public void CanFindAllMatchingCriterion_Paginated()
        {
            CreateExampleParentObjectInDb("X", 1);
            CreateExampleParentObjectInDb("ThisTestOnly", 1);
            CreateExampleParentObjectInDb("ThisTestOnly", 2);
            CreateExampleParentObjectInDb("ThisTestOnly", 3);


            AbstractCriterion    whereName = Expression.Eq("Name", "ThisTestOnly");
            ICollection <Parent> loaded
                = Repository <Parent> .FindAll(0, 2, whereName);

            Assert.AreEqual(2, loaded.Count, "2 objects returned");
            Assert.AreEqual("ThisTestOnly", Collection.First(loaded).Name, "first expected object returned");
            Assert.AreEqual("ThisTestOnly", Collection.Last(loaded).Name, "second expected object returned");
        }