/// <summary>
        /// Applies a join-based filter to the criteria for the specified authorization view.
        /// </summary>
        /// <param name="criteria">The criteria to which filters should be applied.</param>
        /// <param name="whereJunction">The <see cref="ICriterion" /> container for adding WHERE clause criterion.</param>
        /// <param name="parameters">The named parameters to be used to satisfy additional filtering requirements.</param>
        /// <param name="viewName">The name of the view to be filtered.</param>
        /// <param name="joinPropertyName">The name of the property to be joined between the entity being queried and the authorization view.</param>
        /// <param name="filterPropertyName">The name of the property to be used for applying filter values.</param>
        /// <param name="joinType">The <see cref="JoinType" /> to be used.</param>
        public static void ApplyJoinFilter(
            this ICriteria criteria,
            Junction whereJunction,
            IDictionary <string, object> parameters,
            string viewName,
            string joinPropertyName,
            string filterPropertyName,
            JoinType joinType)
        {
            string authViewAlias = $"authView{viewName}";

            // Apply authorization join using ICriteria
            criteria.CreateEntityAlias(
                authViewAlias,
                Restrictions.EqProperty($"aggregateRoot.{joinPropertyName}", $"{authViewAlias}.{joinPropertyName}"),
                joinType,
                $"{viewName.GetAuthorizationViewClassName()}".GetFullNameForView());

            object value;

            // Defensive check to ensure required parameter is present
            if (!parameters.TryGetValue(filterPropertyName, out value))
            {
                throw new Exception($"Unable to find parameter for filtering '{filterPropertyName}' on view '{viewName}'.");
            }

            var arrayOfValues = value as object[];

            if (arrayOfValues != null)
            {
                if (joinType == JoinType.InnerJoin)
                {
                    whereJunction.Add(Restrictions.In($"{authViewAlias}.{filterPropertyName}", arrayOfValues));
                }
                else
                {
                    var and = new AndExpression(
                        Restrictions.In($"{authViewAlias}.{filterPropertyName}", arrayOfValues),
                        Restrictions.IsNotNull($"{authViewAlias}.{joinPropertyName}"));

                    whereJunction.Add(and);
                }
            }
            else
            {
                if (joinType == JoinType.InnerJoin)
                {
                    whereJunction.Add(Restrictions.Eq($"{authViewAlias}.{filterPropertyName}", value));
                }
                else
                {
                    var and = new AndExpression(
                        Restrictions.Eq($"{authViewAlias}.{filterPropertyName}", value),
                        Restrictions.IsNotNull($"{authViewAlias}.{joinPropertyName}"));

                    whereJunction.Add(and);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Applies a join-based filter to the criteria for the specified authorization view.
        /// </summary>
        /// <param name="criteria">The criteria to which filters should be applied.</param>
        /// <param name="whereJunction">The <see cref="ICriterion" /> container for adding WHERE clause criterion.</param>
        /// <param name="parameters">The named parameters to be used to satisfy additional filtering requirements.</param>
        /// <param name="viewName">The name of the view to be filtered.</param>
        /// <param name="subjectEndpointName">The name of the property to be joined for the entity being queried .</param>
        /// <param name="viewTargetEndpointName">The name of the property to be joined for the other property as authorization view.</param>
        /// <param name="joinType">The <see cref="JoinType" /> to be used.</param>
        /// <param name="authViewAlias">The name of the property to be used for auth View Alias name.</param>
        public static void ApplyJoinFilter(
            this ICriteria criteria,
            Junction whereJunction,
            IDictionary <string, object> parameters,
            string viewName,
            string subjectEndpointName,
            string viewTargetEndpointName,
            JoinType joinType,
            string authViewAlias = null)
        {
            authViewAlias = string.IsNullOrWhiteSpace(authViewAlias) ? $"authView{viewName}" : $"authView{authViewAlias}";

            // Apply authorization join using ICriteria
            criteria.CreateEntityAlias(
                authViewAlias,
                Restrictions.EqProperty($"aggregateRoot.{subjectEndpointName}",
                                        $"{authViewAlias}.{viewTargetEndpointName}"),
                joinType,
                $"{viewName.GetAuthorizationViewClassName()}".GetFullNameForView());

            // Defensive check to ensure required parameter is present
            if (!parameters.TryGetValue(RelationshipAuthorizationConventions.ClaimsParameterName, out object value))
            {
                throw new Exception($"Unable to find parameter for filtering '{RelationshipAuthorizationConventions.ClaimsParameterName}' on view '{viewName}'. Available parameters: '{string.Join("', '", parameters.Keys)}'");
            }

            if (value is object[] arrayOfValues)
            {
                if (joinType == JoinType.InnerJoin)
                {
                    whereJunction.Add(Restrictions.In($"{authViewAlias}.{RelationshipAuthorizationConventions.ViewSourceColumnName}", arrayOfValues));
                }
                else
                {
                    var and = new AndExpression(
                        Restrictions.In($"{authViewAlias}.{RelationshipAuthorizationConventions.ViewSourceColumnName}", arrayOfValues),
                        Restrictions.IsNotNull($"{authViewAlias}.{viewTargetEndpointName}"));

                    whereJunction.Add(and);
                }
            }
            else
            {
                if (joinType == JoinType.InnerJoin)
                {
                    whereJunction.Add(Restrictions.Eq($"{authViewAlias}.{RelationshipAuthorizationConventions.ViewSourceColumnName}", value));
                }
                else
                {
                    var and = new AndExpression(
                        Restrictions.Eq($"{authViewAlias}.{RelationshipAuthorizationConventions.ViewSourceColumnName}", value),
                        Restrictions.IsNotNull($"{authViewAlias}.{viewTargetEndpointName}"));

                    whereJunction.Add(and);
                }
            }
        }
示例#3
0
 /// <summary>
 /// Applies property-level filter expressions to the criteria as either Equal or In expressions based on the supplied parameters.
 /// </summary>
 /// <param name="whereJunction">The <see cref="ICriterion" /> container for adding WHERE clause criterion.</param>
 /// <param name="parameters">The named parameters to be processed into the criteria query.</param>
 /// <param name="availableFilterProperties">The array of property names that can be used for filtering.</param>
 public static void ApplyPropertyFilters(this Junction whereJunction, IDictionary <string, object> parameters, params string[] availableFilterProperties)
 {
     foreach (var nameAndValue in parameters.Where(x => availableFilterProperties.Contains(x.Key, StringComparer.OrdinalIgnoreCase)))
     {
         if (nameAndValue.Value is object[] arrayOfValues)
         {
             whereJunction.Add(Restrictions.In($"{nameAndValue.Key}", arrayOfValues));
         }
         else
         {
             whereJunction.Add(Restrictions.Eq($"{nameAndValue.Key}", nameAndValue.Value));
         }
     }
 }
            public Junction Split(Node aNode)
            {
                // The 'top' (Child->node) of the junction is retained by this.
                // The 'bottom' (node->Parent) of the junction is returned.
                int index;

                if (!nodeIndices.TryGetValue(aNode, out index))
                {
                    return(null);
                }

                var bottom = new Junction(this, aNode);

                // Add 1, since aNode was at the index
                index += 1;
                while (index < NodesCount)
                {
                    Node node = this[index];
                    RemoveNode(node);
                    node.Ancestors.Remove(this);
                    node.Descendants.Remove(this);
                    bottom.Add(node);
                }

                return(bottom);
            }
示例#5
0
        private ICriteria BuildBaseTasksQuery(string tasktype, string reference, TaskStateEnum?taskState)
        {
            if (!reference.EndsWith("%"))
            {
                reference = string.Concat(reference, "%");
            }
            if (!(string.IsNullOrEmpty(tasktype) || tasktype.EndsWith("/")))
            {
                tasktype = string.Concat(tasktype, "/");
            }
            ICriteria criteria = Session
                                 .CreateCriteria <Task>()
                                 .Add(Restrictions.Like("Reference", reference));

            if (!string.IsNullOrEmpty(tasktype))
            {
                criteria.Add(Restrictions.Eq("TaskType", tasktype));
            }
            if (taskState.HasValue)
            {
                int      value       = (int)taskState.Value;
                Junction disjunction = Restrictions.Disjunction();
                int      state       = 1;
                while (state <= value)
                {
                    if ((state & value) != 0)
                    {
                        disjunction.Add(Restrictions.Eq("State", (TaskStateEnum)state));
                    }
                    state <<= 1;
                }
                criteria.Add(disjunction);
            }
            return(criteria);
        }
示例#6
0
        private ICriteria CreateSearchCriteria(ApplicationSearchRequest searchRequest)
        {
            var criteria = Session.CreateCriteria(typeof(Application));
            var name     = searchRequest.NameQuery;

            name += "";
            string[] split = name.Split(new[] { ' ', ',', '.', ':' });

            bool     includeNameQuery = false;
            Junction disjunction      = Restrictions.Disjunction(); // This adds an "or" between each clause instead of an "and"

            foreach (var s in split.Where(s => s.Trim() != ""))
            {
                includeNameQuery = true;
                SimpleExpression applicationNameExp = Restrictions.Like("ApplicationName", s, MatchMode.Anywhere);
                SimpleExpression aliasExp           = Restrictions.Like("Alias", s, MatchMode.Anywhere);
                disjunction.Add(Restrictions.Or(applicationNameExp, aliasExp));
            }
            if (includeNameQuery)
            {
                criteria.Add(disjunction);
            }

            if (searchRequest.SupportTeamId > 0)
            {
                criteria.Add(Restrictions.Eq("SupportTeam.Id", searchRequest.SupportTeamId));
            }

            if (searchRequest.HostId > 0)
            {
                criteria.CreateCriteria("Hosts").Add(Restrictions.Eq("Id", searchRequest.HostId));
            }

            return(criteria);
        }
        /// <summary>
        /// Adds an NHibernate.Criterion.ICriterion to the list of NHibernate.Criterion.ICriterions
        /// to junction together.
        /// </summary>
        /// <param name="junction">NHibernate junction</param>
        /// <param name="expression">Lambda expression</param>
        /// <returns>This NHibernate.Criterion.Junction instance.</returns>
        public static Junction Add(this Junction junction,
                                   Expression <Func <bool> > expression)
        {
            ICriterion criterion = ExpressionProcessor.ProcessExpression(expression);

            return(junction.Add(criterion));
        }
示例#8
0
        /// <summary>
        /// Works with any value that can be interpreted by the data provider being used.
        /// </summary>
        public override IParameter Build(IFieldPath path, params object[] values)
        {
            if (values == null)
            {
                return(Other.Build(path, null));
            }

            Junction j = (Type == JunctionType.Conjunction ? (Junction) new Conjunction() : new Disjunction());

            foreach (var v in values)
            {
                var p = Other.Build(path, v);
                if (p != null)
                {
                    j.Add(p);
                }
            }

            if (j.Count == 0)
            {
                return(null);
            }
            else if (j.Count == 1)
            {
                return(j[0]);
            }
            return(j);
        }
示例#9
0
        public Junction Filter(ILogger logger, Func<LogEntry, bool> func)
        {
            var junction = new Junction();
            junction.Add(logger, func);

            return junction;
        }
示例#10
0
 /// <summary>
 /// Builds the criteria.
 /// </summary>
 /// <param name="criteria">The criteria.</param>
 /// <param name="dependencyCriterion">The dependency criterion.</param>
 public override void BuildCriteria(DetachedCriteria criteria, Junction dependencyCriterion)
 {
     if (criteria == null)
     {
         ThrowHelper.ThrowArgumentNullException("criteria");
     }
     if (dependencyCriterion != null)
     {
         dependencyCriterion.Add(mCriterion);
     }
     else
     {
         criteria.Add(this.mCriterion);
     }
 }
示例#11
0
文件: Criteria.cs 项目: ewin66/Forge
        /// <summary>
        /// Builds the criteria.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <param name="dependencyCriterion">The dependency criterion.</param>
        public virtual void BuildCriteria(DetachedCriteria criteria, Junction dependencyCriterion)
        {
            if (criteria == null)
            {
                ThrowHelper.ThrowArgumentNullException("criteria");
            }

            if (FieldName.Contains(".") && !FieldName.ToLower().StartsWith("id."))
            {
                CreateDetachedCriteria(criteria, FieldName, dependencyCriterion);
            }
            else
            {
                string           fieldName = string.Empty;
                AssociationEntry e         = null;
                if (!FieldName.ToLower().Contains("id."))
                {
                    Dictionary <string, AssociationEntry> ascs = GetAssociations();
                    if (ascs.ContainsKey(FieldName))
                    {
                        e = ascs[FieldName];
                    }
                    else
                    {
                        e           = new AssociationEntry(FieldName, FieldName, string.Format("p{0}", Stopwatch.GetTimestamp().ToString()));
                        ascs[e.Key] = e;
                    }
                    fieldName = string.Format("{0}.{1}", criteria.Alias, e.Association);
                }
                else
                {
                    fieldName = string.IsNullOrEmpty(criteria.Alias) ? FieldName : string.Format("{0}.{1}", criteria.Alias, FieldName);
                }

                if (mCriterion == null)
                {
                    mCriterion = BuildCriterion(fieldName);
                }
                if (dependencyCriterion != null)
                {
                    dependencyCriterion.Add(mCriterion);
                }
                else
                {
                    criteria.Add(mCriterion);
                }
            }
        }
示例#12
0
        public override Criterion.IParameter GetParameter()
        {
            Junction junction = (Type == JunctionType.Conjunction ? (Junction) new Conjunction() : new Disjunction());

            foreach (var p in this)
            {
                var toAdd = p.GetParameter();
                if (toAdd != null)
                {
                    junction.Add(toAdd);
                }
            }

            if (junction.Count == 0)
            {
                return(null);
            }

            return(junction);
        }
示例#13
0
        /// <summary>
        /// Builds the criterion.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <param name="dependencyCriterion">The dependency criterion.</param>
        public override void BuildCriteria(DetachedCriteria criteria, Junction dependencyCriterion)
        {
            if (criteria == null)
            {
                ThrowHelper.ThrowArgumentNullException("criteria");
            }

            if (this.Criterias.Length == 1)
            {
                this.Criterias[0].BuildCriteria(criteria, dependencyCriterion);
            }
            else
            {
                if (mCriterion == null)
                {
                    mCriterion = BuildCriterion(string.Empty);
                }

                ICriterion localCriterion = mCriterion;
                if (Negation)
                {
                    localCriterion = Restrictions.Not(mCriterion);
                }

                if (dependencyCriterion != null)
                {
                    dependencyCriterion.Add(localCriterion);
                }
                else
                {
                    criteria.Add(localCriterion);
                }

                foreach (Criteria c in this.Criterias)
                {
                    c.BuildCriteria(criteria, (Junction)mCriterion);
                }
            }
        }
示例#14
0
        public int GetAdvancedSearchPersonCountByImperativeRequest(PersonSearchProxy proxy, ImperativeRequestLoadState IRLS, ImperativeRequest imperativeRequest, decimal userId, decimal managerId, PersonCategory searchCat)
        {
            {
                const string PersonDetailAlias = "prsDtl";
                const string WorkGroupAlias    = "wg";
                const string RuleGroupAlias    = "rg";
                const string CalculationDateRangeGroupAlias = "cdrg";
                const string DepartmentAlias       = "dep";
                const string OrganizationUnitAlias = "organ";


                ICriteria crit        = base.NHibernateSession.CreateCriteria(typeof(Person));
                Junction  disjunction = Restrictions.Disjunction();
                crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonDetail), PersonDetailAlias);
                crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().IsDeleted), false));

                //فعال
                if (proxy.PersonActivateState != null)
                {
                    crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Active), (bool)proxy.PersonActivateState));
                }

                //کد پرسنلی
                if (!Utility.Utility.IsEmpty(proxy.PersonCode))
                {
                    crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().BarCode), proxy.PersonCode, MatchMode.Anywhere));
                }

                //نام
                if (!Utility.Utility.IsEmpty(proxy.FirstName))
                {
                    crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().FirstName), proxy.FirstName, MatchMode.Anywhere));
                }

                //نام خانوادگی
                if (!Utility.Utility.IsEmpty(proxy.LastName))
                {
                    crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().LastName), proxy.LastName, MatchMode.Anywhere));
                }

                //نام پدر
                if (!Utility.Utility.IsEmpty(proxy.FatherName))
                {
                    crit.Add(Restrictions.Like(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().FatherName), proxy.FatherName, MatchMode.Anywhere));
                }

                //جنسیت
                if (!Utility.Utility.IsEmpty(proxy.Sex))
                {
                    crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Sex), proxy.Sex));
                }

                //شروع تاریخ تولد
                if (!Utility.Utility.IsEmpty(proxy.FromBirthDate))
                {
                    crit.Add(Restrictions.Ge(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().BirthDate), proxy.FromBirthDate));
                }

                //پایان تاریخ تولد
                if (!Utility.Utility.IsEmpty(proxy.ToBirthDate))
                {
                    crit.Add(Restrictions.Le(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().BirthDate), proxy.ToBirthDate));
                }

                //شروع تاریخ استخدام
                if (!Utility.Utility.IsEmpty(proxy.FromEmploymentDate))
                {
                    crit.Add(Restrictions.Ge(Utility.Utility.GetPropertyName(() => new Person().EmploymentDate), proxy.FromEmploymentDate));
                }

                //پایان تاریخ استخدام
                if (!Utility.Utility.IsEmpty(proxy.ToEmploymentDate))
                {
                    crit.Add(Restrictions.Ge(Utility.Utility.GetPropertyName(() => new Person().EndEmploymentDate), proxy.ToEmploymentDate));
                }

                //شماره کارت
                if (!Utility.Utility.IsEmpty(proxy.CartNumber))
                {
                    crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().CardNum), proxy.CartNumber));
                }

                //نظام وضیفه
                if (!Utility.Utility.IsEmpty(proxy.Military))
                {
                    crit.Add(Restrictions.Eq(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().MilitaryStatus), proxy.Military));
                }

                //تحصیلات
                if (!Utility.Utility.IsEmpty(proxy.Education))
                {
                    crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().Education), proxy.Education, MatchMode.Anywhere));
                }

                //تاهل
                if (!Utility.Utility.IsEmpty(proxy.MaritalStatus))
                {
                    crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().MaritalStatus), proxy.MaritalStatus));
                }

                //بخش
                if (!Utility.Utility.IsEmpty(proxy.DepartmentId))
                {
                    crit.CreateAlias("department", DepartmentAlias);

                    if (proxy.IncludeSubDepartments)
                    {
                        disjunction.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Department).ToLower(), new Department()
                        {
                            ID = (decimal)proxy.DepartmentId
                        }));
                        disjunction.Add(Restrictions.Like(DepartmentAlias + "." + Utility.Utility.GetPropertyName(() => new Department().ParentPath), "," + proxy.DepartmentId.ToString() + ",", MatchMode.Anywhere));
                    }
                    else
                    {
                        crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Department).ToLower(), new Department()
                        {
                            ID = (decimal)proxy.DepartmentId
                        }));
                    }
                }

                //پست سازمانی
                if (!Utility.Utility.IsEmpty(proxy.OrganizationUnitId))
                {
                    crit.CreateAlias("OrganizationUnitList", OrganizationUnitAlias);
                    crit.Add(Restrictions.Eq(OrganizationUnitAlias + "." + Utility.Utility.GetPropertyName(() => new OrganizationUnit().ID), (decimal)proxy.OrganizationUnitId));
                }

                //گروه کاری
                if (!Utility.Utility.IsEmpty(proxy.WorkGroupId))
                {
                    crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonWorkGroupList), WorkGroupAlias);
                    crit.Add(Restrictions.Eq(WorkGroupAlias + "." + Utility.Utility.GetPropertyName(() => new AssignWorkGroup().WorkGroup), new WorkGroup()
                    {
                        ID = (decimal)proxy.WorkGroupId
                    }));

                    if (!Utility.Utility.IsEmpty(proxy.WorkGroupFromDate))
                    {
                        crit.Add(Restrictions.Le(WorkGroupAlias + "." + Utility.Utility.GetPropertyName(() => new AssignWorkGroup().FromDate), proxy.WorkGroupFromDate));
                    }
                }

                //گروه قوانین
                if (!Utility.Utility.IsEmpty(proxy.RuleGroupId))
                {
                    crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonRuleCatAssignList), RuleGroupAlias);
                    crit.Add(Restrictions.Eq(RuleGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRuleCatAssignment().RuleCategory), new RuleCategory()
                    {
                        ID = (decimal)proxy.RuleGroupId
                    }));

                    if (!Utility.Utility.IsEmpty(proxy.RuleGroupFromDate))
                    {
                        crit.Add(Restrictions.Le(RuleGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRuleCatAssignment().FromDate), proxy.RuleGroupFromDate));
                    }
                    if (!Utility.Utility.IsEmpty(proxy.RuleGroupToDate))
                    {
                        crit.Add(Restrictions.Ge(RuleGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRuleCatAssignment().ToDate), proxy.RuleGroupToDate));
                    }
                }

                //محدوده محاسبات
                if (!Utility.Utility.IsEmpty(proxy.CalculationDateRangeId))
                {
                    crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonRangeAssignList), CalculationDateRangeGroupAlias);
                    crit.Add(Restrictions.Eq(CalculationDateRangeGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRangeAssignment().CalcDateRangeGroup), new CalculationRangeGroup()
                    {
                        ID = (decimal)proxy.CalculationDateRangeId
                    }));

                    if (!Utility.Utility.IsEmpty(proxy.CalculationFromDate))
                    {
                        crit.Add(Restrictions.Le(CalculationDateRangeGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRangeAssignment().FromDate), proxy.CalculationFromDate));
                    }
                }

                //ایستگاه کنترل
                if (!Utility.Utility.IsEmpty(proxy.ControlStationId))
                {
                    crit.Add(Restrictions.Eq("controlStation", new ControlStation()
                    {
                        ID = (decimal)proxy.ControlStationId
                    }));
                }

                //نوع استخدام
                if (!Utility.Utility.IsEmpty(proxy.EmploymentType))
                {
                    crit.Add(Restrictions.Eq("employmentType", new EmploymentType()
                    {
                        ID = (decimal)proxy.EmploymentType
                    }));
                }

                //جستجو در بین مدیران و اپراتورها
                if (proxy.SearchInCategory != PersonCategory.Public &&
                    !Utility.Utility.IsEmpty(proxy.SearchInCategory))
                {
                    if (proxy.SearchInCategory == PersonCategory.Manager)
                    {
                        IList <Person> personList = new ManagerRepository(false).GetAllManager();
                        var            ids        = from person in personList
                                                    select person.ID;
                        IList <decimal> idList = ids.ToList <decimal>();

                        crit.Add(Restrictions.In(Utility.Utility.GetPropertyName(() => new Person().ID), idList.ToArray()));
                    }
                }
                crit.Add(Expression.Sql(" prs_Id in (select * from fn_GetAccessiblePersons(?,?,?))", new object[] { managerId, userId, (int)searchCat }, new IType[] { NHibernateUtil.Decimal, NHibernateUtil.Decimal, NHibernateUtil.Int32 }));
                if (!disjunction.ToString().Equals("()"))
                {
                    crit.Add(disjunction);
                }
                if (IRLS == ImperativeRequestLoadState.Applied || IRLS == ImperativeRequestLoadState.NotApplied)
                {
                    IList <decimal> ImperativeRequestIDsList = this.NHibernateSession.QueryOver <ImperativeRequest>()
                                                               .Where(impReq => impReq.Precard.ID == imperativeRequest.Precard.ID && impReq.IsLocked && impReq.Year == imperativeRequest.Year && impReq.Month == imperativeRequest.Month)
                                                               .Select(impReq => impReq.ID)
                                                               .List <decimal>();
                    if (imperativeRequest.IsLocked)
                    {
                        crit.Add(Restrictions.In(Utility.Utility.GetPropertyName(() => new Person().ID), ImperativeRequestIDsList.ToArray()));
                    }
                    else
                    {
                        crit.Add(Restrictions.Not(Restrictions.In(Utility.Utility.GetPropertyName(() => new Person().ID), ImperativeRequestIDsList.ToArray())));
                    }
                }
                crit.SetProjection(Projections.Count(Utility.Utility.GetPropertyName(() => new Person().ID)));
                if (!Utility.Utility.IsEmpty(crit.ToString()))
                {
                    object count = crit.UniqueResult();
                    return((int)count);
                }
                return(0);
            }
        }
示例#15
0
文件: Criteria.cs 项目: ewin66/Forge
        private void CreateNextPropertyLevel(DetachedCriteria criteria, List <string> propertyList, int listPointer, Junction dependencyCriterion)
        {
            Dictionary <string, AssociationEntry> ascs = GetAssociations();

            string           associationKey = GetAssociationKey(propertyList, listPointer);
            AssociationEntry e = null;

            if (ascs.ContainsKey(associationKey))
            {
                e = ascs[associationKey];
                if (listPointer == propertyList.Count - 1)
                {
                    if (mCriterion == null)
                    {
                        mCriterion = BuildCriterion(e.Association);
                    }
                    if (dependencyCriterion != null)
                    {
                        dependencyCriterion.Add(mCriterion);
                    }
                    else
                    {
                        criteria.Add(mCriterion);
                    }
                }
                else
                {
                    DetachedCriteria subCriteria = e.Criteria;
                    if (subCriteria == null)
                    {
                        subCriteria = criteria.CreateCriteria(e.Association, e.Alias, JoinType.InnerJoin);
                        e.Criteria  = subCriteria;
                    }
                    listPointer++;
                    CreateNextPropertyLevel(subCriteria, propertyList, listPointer, dependencyCriterion);
                }
            }
            else
            {
                bool isThisId = associationKey.ToLower().EndsWith(".id");
                if (listPointer == 0)
                {
                    e = new AssociationEntry(propertyList[0], propertyList[0], string.Format("p{0}{1}", Stopwatch.GetTimestamp().ToString(), listPointer.ToString()));
                }
                else
                {
                    string           parentAssociation = GetAssociationKey(propertyList, listPointer - 1);
                    AssociationEntry parentEntry       = ascs[parentAssociation]; // léteznie kell, máskülönben ide sem juthattam volna
                    e = new AssociationEntry(associationKey, string.Format("{0}.{1}", parentEntry.Alias, propertyList[listPointer]), string.Format("p{0}{1}", Stopwatch.GetTimestamp().ToString(), listPointer.ToString()));
                }
                if (!isThisId)
                {
                    // az id asszociációkat nem mentjük le
                    ascs[e.Key] = e;
                }

                if (listPointer == propertyList.Count - 1 || isThisId)
                {
                    if (mCriterion == null)
                    {
                        mCriterion = BuildCriterion((isThisId && listPointer < propertyList.Count - 1) ? string.Format("{0}.{1}", e.Association, propertyList[listPointer + 1]) : e.Association);
                    }
                    if (dependencyCriterion != null)
                    {
                        dependencyCriterion.Add(mCriterion);
                    }
                    else
                    {
                        criteria.Add(mCriterion);
                    }
                }
                else
                {
                    DetachedCriteria subCriteria = e.Criteria;
                    if (subCriteria == null)
                    {
                        subCriteria = criteria.CreateCriteria(e.Association, e.Alias, JoinType.InnerJoin);
                        e.Criteria  = subCriteria;
                    }
                    listPointer++;
                    CreateNextPropertyLevel(subCriteria, propertyList, listPointer, dependencyCriterion);
                }
            }
        }
        private static IQueryOver <SupplementCycleDefinition, SupplementCycleDefinition> getSupplementsCycleDefinitionsCriterias(GetSupplementsCycleDefinitionsParam param, Profile loggedProfile, List <Guid> ids, Profile myProfile,
                                                                                                                                 IQueryOver <SupplementCycleDefinition, SupplementCycleDefinition> queryCustomer)
        {
            SupplementCycleDosage dosage = null;
            SupplementCycleWeek   week   = null;

            queryCustomer = queryCustomer.JoinAlias(x => x.Weeks, () => week)
                            .JoinAlias(x => x.Weeks.First().Dosages, () => dosage);

            if (param.LegalCriteria == CanBeIllegalCriteria.OnlyLegal)
            {
                queryCustomer = queryCustomer.Where(x => !x.CanBeIllegal);
            }
            else if (param.LegalCriteria == CanBeIllegalCriteria.OnlyIllegal)
            {
                queryCustomer = queryCustomer.Where(x => x.CanBeIllegal);
            }

            if (param.PlanId.HasValue)
            {
                queryCustomer = queryCustomer.Where(x => x.GlobalId == param.PlanId.Value);
            }
            if (param.Languages.Count > 0)
            {
                var langOr = Restrictions.Disjunction();
                foreach (var lang in param.Languages)
                {
                    langOr.Add <SupplementCycleDefinition>(x => x.Language == lang);
                }
                queryCustomer = queryCustomer.And(langOr);
            }
            if (param.Purposes.Count > 0)
            {
                var purposeOr = Restrictions.Disjunction();
                foreach (var purpose in param.Purposes)
                {
                    purposeOr.Add <SupplementCycleDefinition>(x => x.Purpose == (WorkoutPlanPurpose)purpose);
                }
                queryCustomer = queryCustomer.And(purposeOr);
            }
            if (param.Difficults.Count > 0)
            {
                var mainOr = Restrictions.Disjunction();
                foreach (TrainingPlanDifficult diff in param.Difficults)
                {
                    var tt = (BodyArchitect.Model.TrainingPlanDifficult)diff;
                    mainOr.Add <SupplementCycleDefinition>(x => x.Difficult == tt);
                }
                queryCustomer = queryCustomer.And(mainOr);
            }

            if (param.Supplements.Count > 0)
            {
                Junction supplementsOperations = null;
                if (param.SupplementsListOperator == CriteriaOperator.Or)
                {
                    supplementsOperations = Restrictions.Disjunction();
                    foreach (var supplementId in param.Supplements)
                    {
                        supplementsOperations.Add <SupplementCycleDefinition>(x => dosage.Supplement.GlobalId == supplementId);
                    }
                }
                else
                {
                    supplementsOperations = Restrictions.Conjunction();
                    foreach (var supplementId in param.Supplements)
                    {
                        var orderIdsCriteria = DetachedCriteria.For <SupplementCycleDosage>();
                        orderIdsCriteria.SetProjection(Projections.CountDistinct("GlobalId"))
                        .Add(Restrictions.Where <SupplementCycleDosage>(x => x.Supplement.GlobalId == supplementId))
                        .Add(Restrictions.Where <SupplementCycleDosage>(x => x.Week.GlobalId == week.GlobalId));

                        supplementsOperations.Add(Subqueries.Lt(0, orderIdsCriteria));
                        //supplementsOperations.Add<SupplementCycleDosage>(x => dosage.Supplement.GlobalId == supplementId);
                    }
                }
                queryCustomer = queryCustomer.And(supplementsOperations);
            }

            queryCustomer = queryCustomer.Where(x => x.Profile == loggedProfile || (x.Profile != loggedProfile && x.Status == PublishStatus.Published));

            var groupOr = new Disjunction();

            if (param.SearchGroups.Count > 0)
            {
                if (param.SearchGroups.IndexOf(WorkoutPlanSearchCriteriaGroup.Mine) > -1)
                {
                    groupOr.Add <BodyArchitect.Model.SupplementCycleDefinition>(x => x.Profile == myProfile);
                }
                if (param.SearchGroups.IndexOf(WorkoutPlanSearchCriteriaGroup.Favorites) > -1)
                {
                    if (myProfile.FavoriteSupplementCycleDefinitions.Count > 0)
                    {
                        groupOr.Add <BodyArchitect.Model.SupplementCycleDefinition>(x => x.GlobalId.IsIn((ICollection)ids));
                    }
                }
                if (param.SearchGroups.IndexOf(WorkoutPlanSearchCriteriaGroup.Other) > -1)
                {
                    var tmpAnd = Restrictions.Conjunction();
                    tmpAnd.Add <BodyArchitect.Model.SupplementCycleDefinition>(
                        dto => dto.Profile != null && dto.Profile != myProfile);

                    if (ids.Count > 0)
                    {
                        tmpAnd.Add(Restrictions.On <BodyArchitect.Model.SupplementCycleDefinition>(x => x.GlobalId).Not.IsIn((ICollection)ids));
                    }

                    groupOr.Add(tmpAnd);
                }
                queryCustomer = queryCustomer.Where(groupOr);
            }
            return(queryCustomer);
        }
        private void BuildExpressionsInternal(JObject where, Junction expressions, string tableAlias, ResolveFieldContext fieldContext, IDictionary <string, string> indexAliases)
        {
            foreach (var entry in where.Properties())
            {
                IPredicate expression = null;

                var values = entry.Name.Split('_', 2);

                // Gets the full path name without the comparison e.g. aliasPart.alias, not aliasPart.alias_contains.
                var property = values[0];

                // figure out table aliases for collapsed parts and ones with the part suffix removed by the dsl
                if (tableAlias == null || !tableAlias.EndsWith("Part", StringComparison.OrdinalIgnoreCase))
                {
                    var whereArgument = fieldContext?.FieldDefinition?.Arguments.FirstOrDefault(x => x.Name == "where");

                    if (whereArgument != null)
                    {
                        var whereInput = (WhereInputObjectGraphType)whereArgument.ResolvedType;

                        foreach (var field in whereInput.Fields.Where(x => x.GetMetadata <string>("PartName") != null))
                        {
                            var partName = field.GetMetadata <string>("PartName");
                            if ((tableAlias == null && field.GetMetadata <bool>("PartCollapsed") && field.Name.Equals(property, StringComparison.OrdinalIgnoreCase)) ||
                                (tableAlias != null && partName.ToFieldName().Equals(tableAlias, StringComparison.OrdinalIgnoreCase)))
                            {
                                tableAlias = indexAliases.TryGetValue(partName, out var indexTableAlias) ? indexTableAlias : tableAlias;
                                break;
                            }
                        }
                    }
                }

                if (tableAlias != null)
                {
                    property = $"{tableAlias}.{property}";
                }

                if (values.Length == 1)
                {
                    if (string.Equals(values[0], "or", StringComparison.OrdinalIgnoreCase))
                    {
                        expression = Expression.Disjunction();
                        BuildWhereExpressions(entry.Value, (Junction)expression, tableAlias, fieldContext, indexAliases);
                    }
                    else if (string.Equals(values[0], "and", StringComparison.OrdinalIgnoreCase))
                    {
                        expression = Expression.Conjunction();
                        BuildWhereExpressions(entry.Value, (Junction)expression, tableAlias, fieldContext, indexAliases);
                    }
                    else if (string.Equals(values[0], "not", StringComparison.OrdinalIgnoreCase))
                    {
                        expression = Expression.Conjunction();
                        BuildWhereExpressions(entry.Value, (Junction)expression, tableAlias, fieldContext, indexAliases);
                        expression = Expression.Not(expression);
                    }
                    else if (entry.HasValues && entry.Value.Type == JTokenType.Object)
                    {
                        // Loop through the part's properties, passing the name of the part as the table tableAlias.
                        // This tableAlias can then be used with the table alias to index mappings to join with the correct table.
                        BuildWhereExpressions(entry.Value, expressions, values[0], fieldContext, indexAliases);
                    }
                    else
                    {
                        var propertyValue = entry.Value.ToObject <object>();
                        expression = Expression.Equal(property, propertyValue);
                    }
                }
                else
                {
                    var value = entry.Value.ToObject <object>();

                    switch (values[1])
                    {
                    case "not": expression = Expression.Not(Expression.Equal(property, value)); break;

                    case "gt": expression = Expression.GreaterThan(property, value); break;

                    case "gte": expression = Expression.GreaterThanOrEqual(property, value); break;

                    case "lt": expression = Expression.LessThan(property, value); break;

                    case "lte": expression = Expression.LessThanOrEqual(property, value); break;

                    case "contains": expression = Expression.Like(property, (string)value, MatchOptions.Contains); break;

                    case "not_contains": expression = Expression.Not(Expression.Like(property, (string)value, MatchOptions.Contains)); break;

                    case "starts_with": expression = Expression.Like(property, (string)value, MatchOptions.StartsWith); break;

                    case "not_starts_with": expression = Expression.Not(Expression.Like(property, (string)value, MatchOptions.StartsWith)); break;

                    case "ends_with": expression = Expression.Like(property, (string)value, MatchOptions.EndsWith); break;

                    case "not_ends_with": expression = Expression.Not(Expression.Like(property, (string)value, MatchOptions.EndsWith)); break;

                    case "in": expression = Expression.In(property, entry.Value.ToObject <object[]>()); break;

                    case "not_in": expression = Expression.Not(Expression.In(property, entry.Value.ToObject <object[]>())); break;

                    default: expression = Expression.Equal(property, value); break;
                    }
                }

                if (expression != null)
                {
                    expressions.Add(expression);
                }
            }
        }
示例#18
0
        public IList <Person> GetAdvancedSearchPersonByImperativeRequest(PersonSearchProxy proxy, ImperativeRequestLoadState IRLS, ImperativeRequest imperativeRequest, decimal userId, decimal managerId, PersonCategory searchCat, int pageIndex, int pageSize)
        {
            const string PersonDetailAlias = "prsDtl";
            const string WorkGroupAlias    = "wg";
            const string RuleGroupAlias    = "rg";
            const string CalculationDateRangeGroupAlias = "cdrg";
            const string DepartmentAlias       = "dep";
            const string OrganizationUnitAlias = "organ";
            const string PersonTASpecAlias     = "prsTs";
            const string ContractAlias         = "con";
            const string GradeAlias            = "grade";
            const string EmploymentAlias       = "emp";
            ICriteria    crit        = base.NHibernateSession.CreateCriteria(typeof(Person));
            Junction     disjunction = Restrictions.Disjunction();

            crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().IsDeleted), false));
            crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonDetailList), PersonDetailAlias);

            //فعال
            if (proxy.PersonActivateState != null)
            {
                crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Active), (bool)proxy.PersonActivateState));
            }

            //کد پرسنلی
            if (!Utility.Utility.IsEmpty(proxy.PersonCode))
            {
                crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().BarCode), proxy.PersonCode, MatchMode.Anywhere));
            }

            //نام
            if (!Utility.Utility.IsEmpty(proxy.FirstName))
            {
                crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().FirstName), proxy.FirstName, MatchMode.Anywhere));
            }

            //نام خانوادگی
            if (!Utility.Utility.IsEmpty(proxy.LastName))
            {
                crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().LastName), proxy.LastName, MatchMode.Anywhere));
            }

            //نام پدر
            if (!Utility.Utility.IsEmpty(proxy.FatherName))
            {
                crit.Add(Restrictions.Like(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().FatherName), proxy.FatherName, MatchMode.Anywhere));
            }

            //جنسیت ,پیش فرض آن از واسط کاربر -1 است
            if (!Utility.Utility.IsEmpty(proxy.Sex) && proxy.Sex >= 0)
            {
                crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Sex), proxy.Sex));
            }

            //شماره کارت
            if (!Utility.Utility.IsEmpty(proxy.CartNumber))
            {
                crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().CardNum), proxy.CartNumber));
            }

            //نظام وضیفه , پیش فرض آن از واسط کاربر 0 است
            if (!Utility.Utility.IsEmpty(proxy.Military) && proxy.Military > 0)
            {
                crit.Add(Restrictions.Eq(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().MilitaryStatus), proxy.Military));
            }

            //تحصیلات
            if (!Utility.Utility.IsEmpty(proxy.Education))
            {
                crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().Education), proxy.Education, MatchMode.Anywhere));
            }

            //تاهل , پیش فرض آن از واسط کاربر 0 است
            if (!Utility.Utility.IsEmpty(proxy.MaritalStatus) && proxy.MaritalStatus > 0)
            {
                crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().MaritalStatus), proxy.MaritalStatus));
            }

            //شروع تاریخ تولد
            if (!Utility.Utility.IsEmpty(proxy.FromBirthDate))
            {
                crit.Add(Restrictions.Ge(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().BirthDate), proxy.FromBirthDate));
            }

            //پایان تاریخ تولد
            if (!Utility.Utility.IsEmpty(proxy.ToBirthDate))
            {
                crit.Add(Restrictions.Le(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().BirthDate), proxy.ToBirthDate));
            }

            //شروع تاریخ استخدام
            if (!Utility.Utility.IsEmpty(proxy.FromEmploymentDate))
            {
                crit.Add(Restrictions.Ge(Utility.Utility.GetPropertyName(() => new Person().EmploymentDate), proxy.FromEmploymentDate));
            }

            //پایان تاریخ استخدام
            if (!Utility.Utility.IsEmpty(proxy.ToEmploymentDate))
            {
                crit.Add(Restrictions.Ge(Utility.Utility.GetPropertyName(() => new Person().EndEmploymentDate), proxy.ToEmploymentDate));
            }

            //بخش
            //if (!Utility.Utility.IsEmpty(proxy.DepartmentId))
            //{
            //    crit.CreateAlias("department", DepartmentAlias);

            //    if (proxy.IncludeSubDepartments)
            //    {
            //        disjunction.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Department).ToLower(), new Department() { ID = (decimal)proxy.DepartmentId }));
            //        disjunction.Add(Restrictions.Like(DepartmentAlias + "." + Utility.Utility.GetPropertyName(() => new Department().ParentPath), "," + proxy.DepartmentId.ToString() + ",", MatchMode.Anywhere));

            //    }
            //    else
            //    {
            //        crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Department).ToLower(), new Department() { ID = (decimal)proxy.DepartmentId }));
            //    }

            //}

            if (!Utility.Utility.IsEmpty(proxy.DepartmentListId))
            {
                crit.CreateAlias("department", DepartmentAlias);

                if (proxy.IncludeSubDepartments)
                {
                    disjunction.Add(Restrictions.In(DepartmentAlias + "." + Utility.Utility.GetPropertyName(() => new Department().ID), proxy.DepartmentListId.ToArray()));

                    foreach (decimal item in proxy.DepartmentListId)
                    {
                        disjunction.Add(Restrictions.Like(DepartmentAlias + "." + Utility.Utility.GetPropertyName(() => new Department().ParentPath), "," + item.ToString() + ",", MatchMode.Anywhere));
                    }
                }
                else
                {
                    crit.Add(Restrictions.In(DepartmentAlias + "." + Utility.Utility.GetPropertyName(() => new Department().ID), proxy.DepartmentListId.ToArray()));
                }
            }

            //پست سازمانی
            if (!Utility.Utility.IsEmpty(proxy.OrganizationUnitId))
            {
                crit.CreateAlias("OrganizationUnitList", OrganizationUnitAlias);
                crit.Add(Restrictions.Eq(OrganizationUnitAlias + "." + Utility.Utility.GetPropertyName(() => new OrganizationUnit().ID), (decimal)proxy.OrganizationUnitId));
            }

            //گروه کاری
            if (!Utility.Utility.IsEmpty(proxy.WorkGroupId))
            {
                crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonWorkGroupList), WorkGroupAlias);
                crit.Add(Restrictions.Eq(WorkGroupAlias + "." + Utility.Utility.GetPropertyName(() => new AssignWorkGroup().WorkGroup), new WorkGroup()
                {
                    ID = (decimal)proxy.WorkGroupId
                }));

                if (!Utility.Utility.IsEmpty(proxy.WorkGroupFromDate))
                {
                    crit.Add(Restrictions.Le(WorkGroupAlias + "." + Utility.Utility.GetPropertyName(() => new AssignWorkGroup().FromDate), proxy.WorkGroupFromDate));
                }
            }
            //رتبه
            if (!Utility.Utility.IsEmpty(proxy.GradeId))
            {
                crit.CreateAlias("grade", GradeAlias);
                crit.Add(Restrictions.Eq(GradeAlias + "." + Utility.Utility.GetPropertyName(() => new Grade().ID), (decimal)proxy.GradeId));
            }
            //گروه قوانین
            if (!Utility.Utility.IsEmpty(proxy.RuleGroupId))
            {
                crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonRuleCatAssignList), RuleGroupAlias);
                crit.Add(Restrictions.Eq(RuleGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRuleCatAssignment().RuleCategory), new RuleCategory()
                {
                    ID = (decimal)proxy.RuleGroupId
                }));

                if (!Utility.Utility.IsEmpty(proxy.RuleGroupFromDate))
                {
                    crit.Add(Restrictions.Le(RuleGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRuleCatAssignment().FromDate), proxy.RuleGroupFromDate));
                }
                if (!Utility.Utility.IsEmpty(proxy.RuleGroupToDate))
                {
                    crit.Add(Restrictions.Ge(RuleGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRuleCatAssignment().ToDate), proxy.RuleGroupToDate));
                }
            }

            //محدوده محاسبات
            if (!Utility.Utility.IsEmpty(proxy.CalculationDateRangeId))
            {
                crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonRangeAssignList), CalculationDateRangeGroupAlias);
                crit.Add(Restrictions.Eq(CalculationDateRangeGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRangeAssignment().CalcDateRangeGroup), new CalculationRangeGroup()
                {
                    ID = (decimal)proxy.CalculationDateRangeId
                }));

                if (!Utility.Utility.IsEmpty(proxy.CalculationFromDate))
                {
                    crit.Add(Restrictions.Le(CalculationDateRangeGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRangeAssignment().FromDate), proxy.CalculationFromDate));
                }
            }

            ////ایستگاه کنترل
            //if (!Utility.Utility.IsEmpty(proxy.ControlStationId))
            //{
            //    crit.Add(Restrictions.Eq("controlStation", new ControlStation() { ID = (decimal)proxy.ControlStationId }));
            //}
            if (!Utility.Utility.IsEmpty(proxy.ControlStationListId))
            {
                List <ControlStation> controlStationList = new List <ControlStation>();
                foreach (decimal item in proxy.ControlStationListId)
                {
                    controlStationList.Add(new ControlStation()
                    {
                        ID = item
                    });
                }
                crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonTASpecList), PersonTASpecAlias);
                crit.Add(Restrictions.In(PersonTASpecAlias + "." + Utility.Utility.GetPropertyName(() => new PersonTASpec().ControlStation), controlStationList));
            }
            //نوع استخدام
            //if (!Utility.Utility.IsEmpty(proxy.EmploymentType))
            //{
            //    crit.Add(Restrictions.Eq("employmentType", new EmploymentType() { ID = (decimal)proxy.EmploymentType }));
            //}
            if (!Utility.Utility.IsEmpty(proxy.EmploymentTypeListId))
            {
                crit.CreateAlias("employmentType", EmploymentAlias);
                crit.Add(Restrictions.In(EmploymentAlias + "." + Utility.Utility.GetPropertyName(() => new EmploymentType().ID), proxy.EmploymentTypeListId.ToArray()));
            }
            // گروه واسط کاربری
            if (!Utility.Utility.IsEmpty(proxy.UIValidationGroupListId))
            {
                List <UIValidationGroup> uiValidationGroupList = new List <UIValidationGroup>();
                foreach (decimal item in proxy.UIValidationGroupListId)
                {
                    uiValidationGroupList.Add(new UIValidationGroup()
                    {
                        ID = item
                    });
                }
                crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonTASpecList), PersonTASpecAlias);
                crit.Add(Restrictions.In(PersonTASpecAlias + "." + Utility.Utility.GetPropertyName(() => new PersonTASpec().UIValidationGroup), uiValidationGroupList));
            }
            //قرارداد
            if (!Utility.Utility.IsEmpty(proxy.ContractId))
            {
                crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonContractAssignmentList), ContractAlias);
                crit.Add(Restrictions.Eq(ContractAlias + "." + Utility.Utility.GetPropertyName(() => new PersonContractAssignment().Contract), new Contract()
                {
                    ID = (decimal)proxy.ContractId
                }));
                crit.Add(Restrictions.Eq(ContractAlias + "." + Utility.Utility.GetPropertyName(() => new PersonContractAssignment().IsDeleted), false));
                if (!Utility.Utility.IsEmpty(proxy.ContractFromDate))
                {
                    crit.Add(Restrictions.Ge(ContractAlias + "." + Utility.Utility.GetPropertyName(() => new PersonContractAssignment().FromDate), Utility.Utility.ToMildiDateTime(proxy.ContractFromDate)));
                }
                if (!Utility.Utility.IsEmpty(proxy.RuleGroupToDate))
                {
                    crit.Add(Restrictions.Le(ContractAlias + "." + Utility.Utility.GetPropertyName(() => new PersonContractAssignment().ToDate), Utility.Utility.ToMildiDateTime(proxy.ContractToDate)));
                }
            }
            //جستجو در بین مدیران و اپراتورها
            if (proxy.SearchInCategory != PersonCategory.Public &&
                !Utility.Utility.IsEmpty(proxy.SearchInCategory))
            {
                if (proxy.SearchInCategory == PersonCategory.Manager)
                {
                    IList <Person> personList = new ManagerRepository(false).GetAllManager();
                    var            ids        = from person in personList
                                                select person.ID;
                    IList <decimal> idList = ids.ToList <decimal>();

                    crit.Add(Restrictions.In(Utility.Utility.GetPropertyName(() => new Person().ID), idList.ToArray()));
                }
            }
            IList <Person> list = new List <Person>();

            crit.Add(Expression.Sql(" prs_Id in (select * from fn_GetAccessiblePersons(?,?,?))", new object[] { managerId, userId, (int)searchCat }, new IType[] { NHibernateUtil.Decimal, NHibernateUtil.Decimal, NHibernateUtil.Int32 }));

            if (!disjunction.ToString().Equals("()"))
            {
                crit.Add(disjunction);
            }
            if (IRLS == ImperativeRequestLoadState.Applied || IRLS == ImperativeRequestLoadState.NotApplied)
            {
                IList <decimal> ImperativeRequestIDsList = this.NHibernateSession.QueryOver <ImperativeRequest>()
                                                           .Where(impReq => impReq.Precard.ID == imperativeRequest.Precard.ID && impReq.IsLocked && impReq.Year == imperativeRequest.Year && impReq.Month == imperativeRequest.Month)
                                                           .Select(impReq => impReq.ID)
                                                           .List <decimal>();
                if (imperativeRequest.IsLocked)
                {
                    crit.Add(Restrictions.In(Utility.Utility.GetPropertyName(() => new Person().ID), ImperativeRequestIDsList.ToArray()));
                }
                else
                {
                    crit.Add(Restrictions.Not(Restrictions.In(Utility.Utility.GetPropertyName(() => new Person().ID), ImperativeRequestIDsList.ToArray())));
                }
            }
            if (!Utility.Utility.IsEmpty(crit.ToString()))
            {
                if (pageIndex == 0 && pageSize == 0)
                {
                    list = crit
                           .List <Person>();
                }
                else
                {
                    list = crit
                           .SetFirstResult(pageIndex * pageSize)
                           .SetMaxResults(pageSize)
                           .List <Person>();
                }
            }
            return(list);
        }
示例#19
0
        /// <summary>
        /// شرط را اعمال میکند
        /// و خروجی را در پارامتر دوم و سوم میریزد
        /// </summary>
        /// <param name="criteriaStruct"></param>
        /// <param name="criteria"></param>
        private void MakeCriteria(CriteriaStruct criteriaStruct, ref ICriteria criteria, ref Junction disjunction, ConditionOperations conOp)
        {
            CriteriaStruct c = criteriaStruct;

            switch (c.Operation)
            {
            case CriteriaOperation.Equal:
                if (conOp == ConditionOperations.AND)
                {
                    criteria.Add(Restrictions.Eq(c.PropertyName, c.Value));
                }
                else if (conOp == ConditionOperations.OR)
                {
                    disjunction.Add(Restrictions.Eq(c.PropertyName, c.Value));
                }
                break;

            case CriteriaOperation.NotEqual:
                if (conOp == ConditionOperations.AND)
                {
                    criteria.Add(Restrictions.Not(Restrictions.Eq(c.PropertyName, c.Value)));
                }
                else if (conOp == ConditionOperations.OR)
                {
                    disjunction.Add(Restrictions.Not(Restrictions.Eq(c.PropertyName, c.Value)));
                }
                break;

            case CriteriaOperation.GreaterThan:
                if (conOp == ConditionOperations.AND)
                {
                    criteria.Add(Restrictions.Gt(c.PropertyName, c.Value));
                }
                else if (conOp == ConditionOperations.OR)
                {
                    disjunction.Add(Restrictions.Gt(c.PropertyName, c.Value));
                }
                break;

            case CriteriaOperation.LessThan:
                if (conOp == ConditionOperations.AND)
                {
                    criteria.Add(Restrictions.Lt(c.PropertyName, c.Value));
                }
                else if (conOp == ConditionOperations.OR)
                {
                    disjunction.Add(Restrictions.Lt(c.PropertyName, c.Value));
                }
                break;

            case CriteriaOperation.GreaterEqThan:
                if (conOp == ConditionOperations.AND)
                {
                    criteria.Add(Restrictions.Ge(c.PropertyName, c.Value));
                }
                else if (conOp == ConditionOperations.OR)
                {
                    disjunction.Add(Restrictions.Ge(c.PropertyName, c.Value));
                }
                break;

            case CriteriaOperation.LessEqThan:
                if (conOp == ConditionOperations.AND)
                {
                    criteria.Add(Restrictions.Le(c.PropertyName, c.Value));
                }
                else if (conOp == ConditionOperations.OR)
                {
                    disjunction.Add(Restrictions.Le(c.PropertyName, c.Value));
                }
                break;

            case CriteriaOperation.IsNotNull:
                criteria.Add(Restrictions.IsNotNull(c.PropertyName));
                break;

            case CriteriaOperation.IsNull:
                criteria.Add(Restrictions.IsNull(c.PropertyName));
                break;

            case CriteriaOperation.IN:
                if (conOp == ConditionOperations.AND)
                {
                    criteria.Add(Restrictions.In(c.PropertyName, (object[])c.Value));
                }
                else if (conOp == ConditionOperations.OR)
                {
                    disjunction.Add(Restrictions.In(c.PropertyName, (object[])c.Value));
                }
                break;

            case CriteriaOperation.Like:
                if (conOp == ConditionOperations.AND)
                {
                    if (c.Value is string)
                    {
                        criteria.Add(Restrictions.Like(c.PropertyName, c.Value.ToString(), MatchMode.Anywhere));
                    }
                    else
                    {
                        criteria.Add(Restrictions.Like(c.PropertyName, c.Value));
                    }
                }
                else if (conOp == ConditionOperations.OR)
                {
                    if (c.Value is string)
                    {
                        disjunction.Add(Restrictions.Like(c.PropertyName, c.Value.ToString(), MatchMode.Anywhere));
                    }
                    else
                    {
                        disjunction.Add(Restrictions.Like(c.PropertyName, c.Value));
                    }
                }
                break;
            }
        }
示例#20
0
            public Junction Split(Node aNode)
            {
                // The 'top' (Child->node) of the junction is retained by this.
                // The 'bottom' (node->Parent) of the junction is returned.
                int index;
                if (!nodeIndices.TryGetValue(aNode, out index))
                    return null;

                var bottom = new Junction(this, aNode);
                // Add 1, since aNode was at the index
                index += 1;
                while (index < NodesCount)
                {
                    Node node = this[index];
                    RemoveNode(node);
                    node.Ancestors.Remove(this);
                    node.Descendants.Remove(this);
                    bottom.Add(node);
                }

                return bottom;
            }
示例#21
0
            public Junction Split(Node aNode)
            {
                // The 'top' (Child->node) of the junction is retained by
                // The 'bottom' (node->Parent) of the junction is returned.
                int index = Bunch.IndexOf(aNode);
                if (index == -1)
                {
                    return null;
                }
                var bottom = new Junction(this, aNode);
                // Add 1, since aNode was at the index
                index += 1;
                while (Bunch.Count > index)
                {
                    Node node = Bunch[index];
                    Bunch.RemoveAt(index);
                    node.Ancestors.Remove(this);
                    node.Descendants.Remove(this);
                    bottom.Add(node);
                }

                return bottom;
            }