public void Search()
 {
     StockInCriteria criteria = new StockInCriteria
                                    {
                                        FromDate = FromDate,
                                        ToDate = ToDate
                                    };
     IList<StockIn> list = StockInLogic.FindByMultiCriteria(criteria);
     StockInList = ObjectConverter.ConvertFrom(list);
 }
        public void Search()
        {
            StockInCriteria criteria = new StockInCriteria();
            if (SelectedCategory != null) criteria.CategoryName = SelectedCategory.CategoryName;

            if (!string.IsNullOrEmpty(ProductMasterNames))
            {
                criteria.ProductMasterNames = ProductMasterNames.Split(',').ToList();
            }
            if (!string.IsNullOrEmpty(ProductTypes))
            {
                criteria.TypeNames = ProductTypes.Split(',').ToList();
            }
            criteria.DatePick = DatePick;
            if (criteria.DatePick)
            {
                criteria.FromDate = FromDate;
                criteria.ToDate = ToDate;
            }
            ExecuteHelper.OnBackgroundThread(() => FindStockIns(criteria), CompletedLoadStockIns);
        }
 private object FindStockIns(StockInCriteria criteria)
 {
     IoC.Get<ICircularLoadViewModel>().StartLoading();
     IList<CoralPOS.Models.StockIn> stockOuts = StockInLogic.FindByMultiCriteria(criteria);
     StockInList = ObjectConverter.ConvertFrom(stockOuts);
     return null;
 }
Esempio n. 4
0
        public IList<StockIn> FindByMultiCriteria(StockInCriteria criteria)
        {
            bool hasDetailQuery = false;
            StockInDetail detail = null;
            // create detached criteria
            DetachedCriteria critMaster = DetachedCriteria.For<StockIn>();
            DetachedCriteria critDetail = DetachedCriteria.For<StockInDetail>();

            if (criteria != null)
            {
                // create ICriteria provider for all properties we need to search
                ProductMaster pm = null;
                DetachedCriteria pmCrit = critDetail.CreateCriteria((StockInDetail 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<StockIn>)StockInDao.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<StockInDetail>(p=>p.StockIn.StockInId));
                    // set master follow return values in subquery of detail
                    executeCrit.Add(LambdaSubquery.Property<StockIn>(p => p.StockInId).In(critDetail));
                }

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