Ejemplo n.º 1
0
 public void Search()
 {
     DeptStockInCriteria criteria = new DeptStockInCriteria
                                    {
                                        FromDate = FromDate,
                                        ToDate = ToDate
                                    };
     IList<DepartmentStockIn> list = DepartmentStockInLogic.FindByMultiCriteria(criteria);
     StockInList = ObjectConverter.ConvertFrom(list);
 }
Ejemplo n.º 2
0
        public IList<DepartmentStockIn> FindByMultiCriteria(DeptStockInCriteria criteria)
        {
            bool hasDetailQuery = false;
            StockInDetail detail = null;
            // create detached criteria
            DetachedCriteria critMaster = DetachedCriteria.For<DepartmentStockIn>();
            DetachedCriteria critDetail = DetachedCriteria.For<DepartmentStockInDetail>();

            if (criteria != null)
            {
                // create ICriteria provider for all properties we need to search
                ProductMaster pm = null;
                DetachedCriteria pmCrit = critDetail.CreateCriteria((DepartmentStockInDetail sod) => sod.ProductMaster,
                                                                    () => pm, JoinType.InnerJoin);
                Category cat = null;
                DetachedCriteria catCrit = pmCrit.CreateCriteria((ProductMaster p) => p.Category, () => cat,
                                                                 JoinType.InnerJoin);

                ProductType type = null;
                DetachedCriteria typeCrit = pmCrit.CreateCriteria((ProductMaster p) => p.ProductType, () => type,
                                                                 JoinType.InnerJoin);

                // has search product master name
                if (!ObjectUtility.IsNullOrEmpty(criteria.ProductMasterNames))
                {
                    hasDetailQuery = true;
                    int count = 1;
                    // create OR expression A or B or C
                    Junction pmJunction = Expression.Disjunction();
                    foreach (string masterName in criteria.ProductMasterNames)
                    {
                        pmJunction.Add(SqlExpression.Like<ProductMaster>(sod => sod.ProductName, masterName, MatchMode.Anywhere));
                    }
                    pmCrit.Add(pmJunction);
                }

                // search follow category name
                if (!ObjectUtility.IsNullOrEmpty(criteria.CategoryName))
                {
                    hasDetailQuery = true;
                    catCrit.Add<Category>(
                        sod => sod.CategoryName == criteria.CategoryName);
                }

                // search follow type names
                if (!ObjectUtility.IsNullOrEmpty(criteria.TypeNames))
                {
                    hasDetailQuery = true;
                    // create OR expression A or B or C
                    Junction typeJunction = Expression.Disjunction();
                    foreach (string typeName in criteria.TypeNames)
                    {
                        typeJunction.Add(SqlExpression.Like<ProductType>(sod => sod.TypeName, typeName, MatchMode.Anywhere));
                    }
                    typeCrit.Add(typeJunction);
                }

                // search from date to date
                if (criteria.DatePick)
                {
                    critMaster.Add(SqlExpression.Between<StockIn>(so => so.StockInDate,
                                                                   DateUtility.ZeroTime(criteria.FromDate),
                                                                   DateUtility.MaxTime(criteria.ToDate)));
                }
            }

            return (IList<DepartmentStockIn>)DepartmentStockInDao.Execute(delegate(ISession session)
            {
                ICriteria executeCrit = critMaster.GetExecutableCriteria(session);
                if (hasDetailQuery) // if has search in detail
                {
                    // set projection so detail return stock_in_id
                    critDetail.SetProjection(LambdaProjection.Property<DepartmentStockInDetail>(p => p.DepartmentStockIn.DepartmentStockInPK.StockInId));
                    // set master follow return values in subquery of detail
                    executeCrit.Add(LambdaSubquery.Property<DepartmentStockIn>(p => p.DepartmentStockInPK.StockInId).In(critDetail));
                }

                // max result, should put in common properties
                executeCrit.SetMaxResults(20);
                //executeCrit.SetResultTransformer(Transformers.DistinctRootEntity);
                return executeCrit.List<StockIn>();
            }
                                 );
        }