Ejemplo n.º 1
0
            public Object DoInHibernate(ISession session)
            {
                ICriteria criteriaValueSetEntry = session
                                                  .CreateCriteria(typeof(ValueSetEntry));

                ICriteria criteriaCodedValue = criteriaValueSetEntry
                                               .CreateCriteria("codedValue");
                var codeCriteria = NHibernate.Criterion.Restrictions.Eq("code", f_code);

                codeCriteria.IgnoreCase();
                criteriaCodedValue.Add(codeCriteria);

                ICriteria criteriaCodeSystem = criteriaCodedValue
                                               .CreateCriteria("codeSystem");

                criteriaCodeSystem.Add(NHibernate.Criterion.Restrictions.Eq("oid",
                                                                            f_systemOid));

                ICriteria criteriaValueSet = criteriaValueSetEntry.CreateCriteria("valueSet");

                criteriaValueSet.Add(NHibernate.Criterion.Restrictions.Eq("version", f_version));

                ICriteria criteriaVocabularyDomain = criteriaValueSet.CreateCriteria(
                    "vocabularyDomains");

                criteriaVocabularyDomain
                .Add(NHibernate.Criterion.Restrictions
                     .Eq(
                         "type",
                         f_domainType.Name));

                IList list = criteriaValueSetEntry.List();

                return(((list.Count == 0)) ? null : list[0]);
            }
        public ICriteria CreateSubcriteria(ICriteria parent, IEnumerable<ICriteriaEvent> criteriaEvents)
        {
			// call the right overload to actually create the Criteria
            ICriteria crit;
            switch(methodSig)
            {
                case MethodSig.Association:
                    crit = parent.CreateCriteria(association);
                    break;
                case MethodSig.AssociationAndJoinType:
                    crit = parent.CreateCriteria(association, joinType);
                    break;
                case MethodSig.AssociationAndAlias:
                    crit = parent.CreateCriteria(association, alias);
                    break;
                case MethodSig.AssociationAndAliasAndJoinType:
                    crit = parent.CreateCriteria(association, alias, joinType);
                    break;
                default:
                    throw new ShardedSessionException("Unknown constructor type for subcriteria creation: " + methodSig);
            }
			// apply the events
            foreach(ICriteriaEvent criteriaEvent in criteriaEvents)
            {
                criteriaEvent.OnEvent(crit);
            }
            return crit;
        }
Ejemplo n.º 3
0
            public Object DoInHibernate(ISession session)
            {
                ICriteria criteriaValueSetEntry = session
                                                  .CreateCriteria(typeof(ValueSetEntry));

                ICriteria criteriaCodedValue = criteriaValueSetEntry
                                               .CreateCriteria("codedValue");

                NHibernate.Criterion.SimpleExpression codeCriteria = NHibernate.Criterion.Restrictions.Eq("code", f_code);
                if (f_ignoreCase)
                {
                    codeCriteria.IgnoreCase();
                }
                criteriaCodedValue.Add(codeCriteria);

                ICriteria criteriaValueSet = criteriaValueSetEntry.CreateCriteria("valuset");

                criteriaValueSet.Add(NHibernate.Criterion.Restrictions.Eq("version", f_version));

                ICriteria criteriaVocabularyDomain = criteriaValueSet.CreateCriteria(
                    "vocabularyDomains");

                criteriaVocabularyDomain
                .Add(NHibernate.Criterion.Restrictions
                     .Eq(
                         "type",
                         f_domainType.Name));

                return(criteriaValueSetEntry.List());
            }
Ejemplo n.º 4
0
        private ICriteria GetByProductCriteria(Product product, PriceList priceList)
        {
            ICriteria crit = GetCriteria();

            ExecutePermissionValidator epv = new ExecutePermissionValidator();

            epv.ClassType     = typeof(PriceList);
            epv.KeyIdentifier = Config.SeePriceLists;

            if (PermissionManager.Check(epv) == false)
            {
                IList priceListIds    = PermissionManager.GetPermissionIdentifiers(typeof(PriceList), PermissionAction.Create);
                int[] intPriceListIds = new int[priceListIds.Count];
                for (int i = 0; i < priceListIds.Count; i++)
                {
                    intPriceListIds[i] = Convert.ToInt32(priceListIds[i]);
                }

                ICriteria critPriceList = crit.CreateCriteria("PriceList");
                critPriceList.Add(Expression.In("ID", intPriceListIds));
            }

            crit.CreateCriteria("PriceBase").CreateCriteria("Product").Add(Expression.Eq("ID", product.ID));
            if (priceList != null)
            {
                crit.Add(Expression.Eq("PriceList", priceList));
            }
            return(crit);
        }
Ejemplo n.º 5
0
        public int CountFilmsCriteres(string titre, string realisateur, string pays, string langueOriginale,
                                      string genre, string anneeSortie, string acteur)
        {
            using (ISession session = ClientSession.GetClientSession().OpenSession())
            {
                int count = 0;

                using (var tx = session.BeginTransaction())
                {
                    ICriteria criteria = session.CreateCriteria <Film>("f");

                    if (!titre.IsEmpty())
                    {
                        criteria.Add(Restrictions.InsensitiveLike("f.Titre", titre, MatchMode.Anywhere));
                    }
                    if (!realisateur.IsEmpty())
                    {
                        criteria.CreateCriteria("f.Realisateurs", "r").CreateCriteria("r.Personne", "pr")
                        .Add(Restrictions.Or(
                                 Restrictions.InsensitiveLike("pr.NomFamille", realisateur, MatchMode.Anywhere),
                                 Restrictions.InsensitiveLike("pr.Prenom", realisateur, MatchMode.Anywhere)
                                 ));
                    }
                    if (!pays.IsEmpty())
                    {
                        criteria.Add(Restrictions.InsensitiveLike("f.Pays", pays, MatchMode.Anywhere));
                    }
                    if (!langueOriginale.IsEmpty())
                    {
                        criteria.Add(Restrictions.InsensitiveLike("f.LangueOriginale", langueOriginale,
                                                                  MatchMode.Anywhere));
                    }
                    if (!genre.IsEmpty())
                    {
                        criteria.Add(Restrictions.InsensitiveLike("f.Genres", genre, MatchMode.Anywhere));
                    }
                    if (!anneeSortie.IsEmpty())
                    {
                        criteria.Add(Restrictions.Eq("f.AnneeSortie", Int32.Parse(anneeSortie)));
                    }
                    if (!acteur.IsEmpty())
                    {
                        criteria.CreateCriteria("f.FilmActeurs", "fm").CreateCriteria("fm.Personne", "pa")
                        .Add(Restrictions.Or(
                                 Restrictions.InsensitiveLike("pa.Prenom", acteur, MatchMode.Anywhere),
                                 Restrictions.InsensitiveLike("pa.NomFamille", acteur, MatchMode.Anywhere)
                                 ));
                    }
                    count = criteria.SetProjection(
                        Projections.Count(Projections.Id())
                        )
                            .UniqueResult <int>();

                    tx.Commit();
                }

                return(count);
            }
        }
Ejemplo n.º 6
0
        public IList <MasterGarment> GetBySelection(Silouhette silouhette, Fabric fabric, Pattern pattern, IList <EventType> selectedET, IList <ClosetGarment> closetGarments, IList <WishGarment> wishGarments)
        {
            fabricRepository = new FabricRepository();
            if (fabric == null || fabric.Id == 0)
            {
                fabric = fabricRepository.GetForSilouhette(silouhette, selectedET)[0];
            }
            if (pattern == null || pattern.Id == 0)
            {
                pattern = silouhette.AvailablePatterns[0];
            }
            List <int> eventTypesIds = new List <int>();

            foreach (EventType eventType in selectedET)
            {
                eventTypesIds.Add(eventType.Id);
            }

            ICriteria crit = Session.CreateCriteria(typeof(MasterGarment));

            ICriteria tags        = crit.CreateCriteria("Tags");
            ICriteria silouhettes = tags.CreateCriteria("Silouhette");

            silouhettes.Add(Expression.Eq("Id", silouhette.Id));

            ICriteria fabrics = tags.CreateCriteria("Fabric");

            fabrics.Add(Expression.Eq("Id", fabric.Id));

            ICriteria patterns = tags.CreateCriteria("Pattern");

            patterns.Add(Expression.Eq("Id", pattern.Id));

            int sum = 0;

            foreach (EventType et in selectedET)
            {
                sum += et.BinaryNumber;
            }

            crit.Add(Restrictions.Gt(Projections.SqlProjection("(this_.EventCode & " + sum + ") as bitWiseResult2", new[] { "bitWiseResult" }, new IType[] { NHibernateUtil.Int32 }), 0));

            foreach (ClosetGarment closetGarment in closetGarments)
            {
                crit.Add(Expression.Not(Expression.Eq("Id", closetGarment.Garment.Id)));
            }

            foreach (WishGarment wishGarment in wishGarments)
            {
                crit.Add(Expression.Not(Expression.Eq("Id", wishGarment.Garment.Id)));
            }

            crit.Add(Expression.Not(Expression.Eq("Id", 0)));
            crit.SetCacheable(true);
            crit.SetCacheRegion("Static");
            return(crit.List <MasterGarment>());
        }
Ejemplo n.º 7
0
        private ICriteria GetDistributorsCriteria(string name, Country country, PriceList priceList,
                                                  Lookup paymentTerm, DistributorStatus? status,
                                                  GridState gridState, Incoterm? saleCondition, Lookup type, CatalogPage page, IList priceListIds, bool isActive)
        {
            ICriteria crit = GetCriteria();

            if (priceListIds != null)
            {
                int[] intPriceListIds = new int[priceListIds.Count];
                for (int i = 0; i < priceListIds.Count; i++)
                    intPriceListIds[i] = Convert.ToInt32(priceListIds[i]);

                ICriteria critDistributor = crit.CreateCriteria("PriceList");
                critDistributor.Add(Expression.In("ID", intPriceListIds));
            }


            if (!string.IsNullOrEmpty(name))
            {
                Disjunction d = new Disjunction();
                d.Add(Expression.InsensitiveLike("Name", name, MatchMode.Anywhere));
                d.Add(Expression.InsensitiveLike("Code", name, MatchMode.Anywhere));
                crit.Add(d);
            }


            if (country != null)
            {
                ICriteria critCountry = crit.CreateCriteria("Country");
                critCountry.Add(Expression.Eq("ID", country.ID));
            }
            if (priceList != null)
            {
                ICriteria critPriceList = crit.CreateCriteria("PriceList");
                critPriceList.Add(Expression.Eq("ID", priceList.ID));
            }
            if (paymentTerm != null)
                crit.Add(Expression.Eq("PaymentTerm", paymentTerm));

            if (status != null)
                crit.Add(Expression.Eq("DistributorStatus", status));
            else
                if (isActive == false)
                 crit.Add(Expression.Eq("DistributorStatus", DistributorStatus.Active));

            if (saleCondition != null)
                crit.Add(Expression.Eq("SaleConditions", saleCondition));

            if (type != null)
                crit.Add(Expression.Eq("Type", type));

            if (page != null)
                crit.CreateCriteria("PriceList").CreateCriteria("CategoryPages").Add(Expression.Eq("ID", page.ID));

            return crit;
        }
Ejemplo n.º 8
0
        public bool ExistsProduct(string code, ProductType type)
        {
            ICriteria crit      = GetCriteria();
            ICriteria product   = crit.CreateCriteria("Product");
            ICriteria pricelist = crit.CreateCriteria("PriceList");

            product.Add(Expression.InsensitiveLike("Code", code));
            pricelist.Add(Expression.Eq("Type", type));
            product.Add(Expression.Eq("Status", ProductStatus.Enable));

            return((crit.UniqueResult <ProductPrice>() != null) ? true : false);
        }
Ejemplo n.º 9
0
        public HesapHareket GetBySubeKoduAndFisNoAndHesapNo(string subeKodu, string fisNo, string hesapNo)
        {
            ICriteria criteria = Session.CreateCriteria(typeof(HesapHareket)).Add(Expression.Eq("FisNo", fisNo));

            ICriteria subeCriteria = criteria.CreateCriteria("Sube");

            subeCriteria.Add(NHibernate.Criterion.Expression.Eq("Id", subeKodu));
            ICriteria bankaCriteria = criteria.CreateCriteria("BankaHesap");

            bankaCriteria.Add(NHibernate.Criterion.Expression.Eq("HesapNo", hesapNo));
            return(criteria.UniqueResult <HesapHareket>());
        }
Ejemplo n.º 10
0
        public IList <UserMember> GetUsersByRole(string role, string site)
        {
            ICriteria crit  = GetCriteria();
            ICriteria sites = crit.CreateCriteria("Sites");

            sites.Add(Expression.Eq("Code", site));
            ICriteria roles = crit.CreateCriteria("Roles");

            roles.Add(Expression.Eq("Name", role));

            return(crit.List <UserMember>());
        }
Ejemplo n.º 11
0
 public async Task CanMakeCriteriaQueryAcrossBothAssociationsAsync()
 {
     AssertDialect();
     using (ISession s = OpenSession())
     {
         ICriteria criteria = s.CreateCriteria(typeof(Item));
         criteria.CreateCriteria("Ships", "s", JoinType.InnerJoin)
         .Add(Expression.Eq("s.Id", 15));
         criteria.CreateCriteria("Containers", "c", JoinType.LeftOuterJoin)
         .Add(Expression.Eq("c.Id", 15));
         criteria.SetMaxResults(2);
         await(criteria.ListAsync());
     }
 }
Ejemplo n.º 12
0
        public static ICriteria GetCriteriaForEmptyLegs(NameValueCollection pars)
        {
            ICriteria cr = NHibernateHelper.GetCurrentSession().CreateCriteria(typeof(EmptyLeg));

            if (!HttpContext.Current.User.IsInRole("Admin") && !HttpContext.Current.User.IsInRole("Operators"))
            {
                cr.Add(Restrictions.IsNull("AcceptedOffer"));
            }

            Operator o = OperatorBO.GetLoggedinOperator();

            if (o != null)
            {
                cr.CreateCriteria("Aircraft").Add(Restrictions.Eq("Vendor", o));
            }

            if (pars.Get("operator") != null)
            {
                cr.CreateCriteria("Aircraft").CreateCriteria("Vendor").Add(Restrictions.Like("CompanyName", pars.Get("operator"), MatchMode.Anywhere));
            }

            if (pars.Get("source") != null)
            {
                cr.CreateCriteria("Source")
                .Add(Restrictions.Disjunction()
                     .Add(Restrictions.Like("AirfieldName", pars.Get("source"), MatchMode.Anywhere))
                     .Add(Restrictions.Eq("ICAOCODE", pars.Get("source")))
                     .Add(Restrictions.Eq("City", pars.Get("source")))
                     );
            }
            if (pars.Get("destination") != null)
            {
                cr.CreateCriteria("Destination")
                .Add(Restrictions.Disjunction()
                     .Add(Restrictions.Like("AirfieldName", pars.Get("destination"), MatchMode.Anywhere))
                     .Add(Restrictions.Eq("ICAOCODE", pars.Get("destination")))
                     .Add(Restrictions.Eq("City", pars.Get("destination")))
                     );
            }
            if (pars.Get("status") != null)
            {
                cr.Add(Restrictions.Eq("Status", Int32.Parse(pars.Get("status"))));
            }
            else
            {
                cr.Add(Restrictions.Eq("Status", 1));
            }
            cr.AddOrder(new Order("PostedOn", false));
            return(cr);
        }
Ejemplo n.º 13
0
        private static void SetJoinCriteria(ICriteria cr, Sort sort)
        {
            ICriteria crej = cr.GetCriteriaByAlias("ej");

            if (sort.Column == "d.Title")
            {
                ICriteria crd = cr.GetCriteriaByAlias("d");
                if (crej != null && crd == null)
                {
                    cr = crej.CreateCriteria("ej.Designation", "d", JoinType.LeftOuterJoin);
                }

                else if (crej == null && crd == null)
                {
                    crej = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);
                    cr   = crej.CreateCriteria("ej.Designation", "d", JoinType.LeftOuterJoin);
                }
            }

            if (sort.Column == "es.Name")
            {
                ICriteria cres = cr.GetCriteriaByAlias("es");
                if (crej != null && cres == null)
                {
                    cr = crej.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);
                }

                else if (crej == null && cres == null)
                {
                    crej = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);
                    cr   = crej.CreateCriteria("ej.Employmentstatus", "es", JoinType.LeftOuterJoin);
                }
            }

            if (sort.Column == "dept.Name")
            {
                ICriteria crdept = cr.GetCriteriaByAlias("dept");
                if (crej != null && crdept == null)
                {
                    cr = crej.CreateCriteria("ej.Department", "dept", JoinType.LeftOuterJoin);
                }

                else if (crej == null && crdept == null)
                {
                    crej = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);
                    cr   = crej.CreateCriteria("ej.Department", "dept", JoinType.LeftOuterJoin);
                }
            }
        }
Ejemplo n.º 14
0
        public void CanLoadCollectionUsingLeftOuterJoin()
        {
            String itemName = "a";
            String shipName = "blah";

            Item item = new Item();

            item.Name = itemName;

            Ship ship = new Ship();

            ship.Name = shipName;
            item.Ships.Add(ship);
            using (ISession s = OpenSession())
            {
                s.Save(ship);
                s.Save(item);
                s.Flush();
            }
            using (ISession s = OpenSession())
            {
                ICriteria criteria = s.CreateCriteria(typeof(Item));
                criteria.CreateCriteria("Ships", "s", JoinType.InnerJoin)
                .Add(Expression.IsNotNull("s.Id"));
                criteria.CreateCriteria("Containers", "c", JoinType.LeftOuterJoin)
                .Add(Expression.IsNull("c.Id"));

                IList <Item> results = criteria.List <Item>();
                Assert.AreEqual(1, results.Count);

                Item loadedItem = results[0];
                Assert.AreEqual(itemName, loadedItem.Name);

                Assert.AreEqual(1, loadedItem.Ships.Count);
                foreach (Ship loadedShip in item.Ships)
                {
                    Assert.AreEqual(shipName, loadedShip.Name);
                }

                Assert.IsTrue(loadedItem.Containers.IsEmpty);
            }
            using (ISession s = OpenSession())
            {
                s.Delete(ship);
                s.Delete(item);
                s.Flush();
            }
        }
Ejemplo n.º 15
0
        public FatIrsUst GetByBelgeNoBelgeTipAndSubeKodu(string belgeNo, FTIRSIP ftirsip, string subeKodu)
        {
            ICriteria criteria   = Session.CreateCriteria(typeof(FatIrsUst)).Add(Expression.Eq("FatirsNo", belgeNo)).Add(Expression.Eq("Ftirsip", ftirsip));
            ICriteria subeCriter = criteria.CreateCriteria("Sube").Add(Expression.Eq("Id", subeKodu));

            return(criteria.UniqueResult <FatIrsUst>());
        }
Ejemplo n.º 16
0
        public List <FatIrsUst> GetListByCriter(FatIrsUst fat, DateTime?dtTarBas, DateTime?dtTarBit, DateTime?dtVadeBas, DateTime?dtVadeBit)
        {
            ICriteria crit = Session.CreateCriteria <FatIrsUst>();

            if (!string.IsNullOrEmpty(fat.FatirsNo))
            {
                crit.Add(Expression.Like("FatirsNo", fat.FatirsNo, MatchMode.Start));
            }
            crit.Add(Expression.Eq("FatTipi", fat.FatTipi));
            if (dtTarBas.HasValue && dtTarBit.HasValue)
            {
                crit.Add(Expression.Between("Tarih", dtTarBas.Value.JustDate(), dtTarBit.Value.JustDate()));
            }
            if (dtVadeBas.HasValue && dtVadeBit.HasValue)
            {
                crit.Add(Expression.Between("VadeTarih", dtVadeBas.Value.JustDate(), dtVadeBit.Value.JustDate()));
            }
            if (!string.IsNullOrEmpty(fat.CariKodu))
            {
                crit.Add(Expression.Like("CariKodu", fat.CariKodu, MatchMode.Start));
            }
            crit.Add(Expression.Eq("Ftirsip", fat.Ftirsip));
            crit.CreateCriteria("Sube").Add(Expression.Eq("Id", fat.Sube.Id)).SetMaxResults(GetMaxResult);
            return((List <FatIrsUst>)crit.List <FatIrsUst>());
        }
        public IList <PurchaseOrderItem> GetMonthlyTransaction(int year, int month)
        {
            DateTime startDate = new DateTime(year, month, 1);
            DateTime endDate   = startDate.AddMonths(1);

            ICriteria crit = GetCriteria();

            ICriteria purchase = crit.CreateCriteria("PurchaseOrder");

            purchase.Add(new LtExpression("Date", endDate));
            purchase.Add(new GeExpression("Date", startDate));
            purchase.Add(new OrExpression(new EqExpression("Location", "01"), new EqExpression("Location", "09")));
            crit.SetProjection(Projections.ProjectionList()
                               .Add(Projections.Sum("QuantityOrdered"))
                               .Add(Projections.GroupProperty("Product"))
                               );

            crit.SetResultTransformer(
                new NHibernate.Transform.AliasToBeanConstructorResultTransformer(typeof(PurchaseOrderItem).GetConstructors()[1])
                );

            //IList obj = new ArrayList();
            //crit.List(obj);

            return(crit.List <PurchaseOrderItem>());
        }
Ejemplo n.º 18
0
        public IList <PriceImport> GetByStatus(ImportStatus status, string orderBy)
        {
            ICriteria crit = GetCriteria();

            crit.Add(Expression.Eq("ImportStatus", status));

            ICriteria critSort = crit;

            if (string.IsNullOrEmpty(orderBy))
            {
                string[] sort      = orderBy.Split('.');
                string   sortField = orderBy;
                if (!sortField.Contains("TimeStamp") && sort.Length > 1)
                {
                    critSort = crit.GetCriteriaByPath(sort[0]);
                    if (critSort == null)
                    {
                        critSort = crit.CreateCriteria(sort[0]);
                    }
                    sortField = sort[1];
                }
                critSort.AddOrder(new Order(sortField, true));
            }

            return(crit.List <PriceImport>());
        }
Ejemplo n.º 19
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);
            }
        }
Ejemplo n.º 20
0
        public List <WebClosetGarment> GetWebClosetGarments(RegisteredUser registeredUser)
        {
            ICriteria crit     = Session.CreateCriteria(typeof(UserGarment), "garment");
            ICriteria user     = crit.CreateCriteria("User");
            ICriteria category = crit.CreateCriteria("Tags").CreateCriteria("Silouhette").CreateCriteria("Category", "category");

            user.Add(Expression.Eq("Id", registeredUser.Id));
            crit.SetProjection(Projections.ProjectionList().Add(Projections.Property("Id"))
                               .Add(Projections.Property("garment.Title"))
                               .Add(Projections.Property("garment.ImageUri"))
                               .Add(Projections.Property("category.Id"))
                               );

            crit.SetResultTransformer(new NHibernate.Transform.AliasToBeanConstructorResultTransformer(typeof(WebClosetGarment).GetConstructors()[1]));
            return(crit.List <WebClosetGarment>() as List <WebClosetGarment>);
        }
Ejemplo n.º 21
0
        public IList <Distributor> GetActivesByPriceGroup(PriceGroup pG, int?maxResults, IList priceListIds)
        {
            ICriteria crit = GetCriteria();

            crit.Add(Expression.Not(Expression.Eq("DistributorStatus", DistributorStatus.Disable)));

            ICriteria critPriceList = crit.CreateCriteria("PriceList");

            if (priceListIds != null)
            {
                int[] intPriceListIds = new int[priceListIds.Count];
                for (int i = 0; i < priceListIds.Count; i++)
                {
                    intPriceListIds[i] = Convert.ToInt32(priceListIds[i]);
                }

                critPriceList.Add(Expression.In("ID", intPriceListIds));
            }

            critPriceList.Add(Expression.Or(Expression.Eq("PriceListStatus", PriceListStatus.Active), Expression.Eq("PriceListStatus", PriceListStatus.New)));
            critPriceList.Add(Expression.Eq("PriceGroup", pG));


            crit.AddOrder(new Order("TimeStamp.CreatedOn", false));
            if (maxResults.HasValue)
            {
                crit.SetMaxResults(maxResults.Value);
            }

            return(crit.List <Distributor>() as IList <Distributor>);
        }
Ejemplo n.º 22
0
        //Buscar Produto no BD
        public IList <Produto> BuscaProdutos(string nome, decimal precoMinimo, string nomeCategoria)
        {
            ICriteria criteria = session.CreateCriteria <Produto>();

            if (!String.IsNullOrEmpty(nome))
            {
                criteria.Add(Restrictions.Eq("Nome", nome));
            }
            if (precoMinimo > 0)
            {
                criteria.Add(Restrictions.Ge("Preco", precoMinimo));
            }
            if (!String.IsNullOrEmpty(nomeCategoria))
            {
                ICriteria criteriaCategoria = criteria.CreateCriteria("Categoria");
                criteriaCategoria.Add(Restrictions.Eq(nome, nomeCategoria));
            }

            var todosOsProdutos = criteria.List <Produto>();

            foreach (var produtos in todosOsProdutos)
            {
                Console.WriteLine("ID: {0}\t{1}\tR$:{2}\tCategoria:{3}", produtos.Id, produtos.Nome.PadRight(20), produtos.Preco, produtos.Categoria.Nome);
            }
            return(todosOsProdutos);
        }
Ejemplo n.º 23
0
        public List <HesapHareket> GetHesapNoWithDate(string subeKodu, string hesapNo, DateTime startDate, DateTime finishDate, HesapHareketTuru?hareketTuru)
        {
            ICriteria criteria = Session.CreateCriteria(typeof(HesapHareket)).Add(Expression.Between("Tarih", startDate, finishDate));

            if (hareketTuru.HasValue)
            {
                criteria.Add(Expression.Eq("HareketTuru", hareketTuru.Value));
            }
            ICriteria subeCriteria = criteria.CreateCriteria("Sube");

            subeCriteria.Add(NHibernate.Criterion.Expression.Eq("Id", subeKodu));
            ICriteria bankaCriteria = criteria.CreateCriteria("BankaHesap");

            bankaCriteria.Add(NHibernate.Criterion.Expression.Eq("HesapNo", hesapNo));
            return(criteria.List <HesapHareket>() as List <HesapHareket>);
        }
        public List <AlertReposition> ShowAlert(string column, string order)
        {
            if (string.IsNullOrEmpty(column))
            {
                return(ShowAlert6());
            }

            bool boolorder = true;

            if (order == "desc")
            {
                boolorder = false;
            }

            ICriteria crit = GetCriteria();

            string[] sortfield = new string[2];
            sortfield = column.Split('.');

            if (sortfield.Length < 2)
            {
                crit.AddOrder(new Order(sortfield[0], boolorder));
            }
            else
            {
                ICriteria products = crit.CreateCriteria("Product");
                products.AddOrder(new Order(sortfield[1], boolorder));
            }
            return(crit.List <AlertReposition>() as List <AlertReposition>);
        }
Ejemplo n.º 25
0
        public IList <UserCampaign> GetByCampaign(int campaignID)
        {
            ICriteria crit = GetCriteria( );

            crit.CreateCriteria("Campaign").Add(Expression.Eq("ID", campaignID));
            return(crit.List <UserCampaign>( ));
        }
Ejemplo n.º 26
0
        public IList <Item> FindByFields(Filter <string> categoryName,
                                         Filter <string> tag,
                                         DateTime?fromDate, DateTime?toDate,
                                         PagingInfo paging)
        {
            ICriteria criteria = CreateCriteria();

            if (tag != null)
            {
                criteria.Add(tag.ToCriterion("Tag"));
            }

            if (fromDate != null)
            {
                criteria.Add(Expression.Ge("NewsDate", fromDate));
            }

            if (toDate != null)
            {
                criteria.Add(Expression.Le("NewsDate", toDate));
            }

            if (categoryName != null)
            {
                ICriteria categoryCriteria = criteria.CreateCriteria("Category");
                categoryCriteria.Add(categoryName.ToCriterion("Name"));
            }

            criteria.AddOrder(Order.Desc("NewsDate"));

            return(Find(criteria, paging, false));
        }
Ejemplo n.º 27
0
        public IList <Distributor> GetActivesByPriceList()
        {
            ICriteria crit = GetCriteria();

            crit.Add(Expression.Eq("DistributorStatus", DistributorStatus.Active));

            ExecutePermissionValidator epv = new ExecutePermissionValidator();

            epv.ClassType     = typeof(PriceList);
            epv.KeyIdentifier = Config.SeePriceLists;

            if (PermissionManager.Check(epv) == false)
            {
                IList priceListIds    = PermissionManager.GetPermissionIdentifiers(typeof(PriceList), PermissionAction.Create);
                int[] intPriceListIds = new int[priceListIds.Count];
                for (int i = 0; i < priceListIds.Count; i++)
                {
                    intPriceListIds[i] = Convert.ToInt32(priceListIds[i]);
                }

                ICriteria critPriceList = crit.CreateCriteria("PriceList");
                critPriceList.Add(Expression.In("ID", intPriceListIds));
            }

            crit.AddOrder(new Order("Name", false));

            return(crit.List <Distributor>());
        }
Ejemplo n.º 28
0
        public IList <Friend> Search(RegisteredUser user, string friend, FriendStatus status, int limit)
        {
            ICriteria crit = NHibernateSession.Current.CreateCriteria(typeof(Friend));

            crit.SetFetchMode("User", FetchMode.Join);
            crit.Add(Restrictions.Eq("BasicUser.Id", user.Id));

            crit.Add(Expression.Not(Expression.Eq("Status", FriendStatus.Denied)));

            if (status != FriendStatus.All)
            {
                crit.Add(Expression.Eq("Status", status));
            }

            Disjunction d = new Disjunction();

            if (!string.IsNullOrEmpty(friend))
            {
                ICriteria critUser = crit.CreateCriteria("User");
                d.Add(Expression.Like("FirstName", friend, MatchMode.Anywhere));
                d.Add(Expression.Like("LastName", friend, MatchMode.Anywhere));
                d.Add(Expression.Like("EmailAddress", friend, MatchMode.Anywhere));
                critUser.Add(d);
            }

            if (limit > 0)
            {
                crit.SetMaxResults(limit);
            }

            return(crit.List <Friend>());
        }
Ejemplo n.º 29
0
        public List <FatIrsUst> GetListByFtirsipAndSubeKodu(FTIRSIP ftirsip, string subeKodu)
        {
            ICriteria criteria   = Session.CreateCriteria(typeof(FatIrsUst)).Add(Expression.Eq("Ftirsip", ftirsip)).SetMaxResults(GetMaxResult);
            ICriteria subeCriter = criteria.CreateCriteria("Sube").Add(Expression.Eq("Id", subeKodu));

            return(criteria.List <FatIrsUst>() as List <FatIrsUst>);
        }
Ejemplo n.º 30
0
        public IList <Article> FindByCategory(Category category)
        {
            ICriteria criteria = CreateCriteria();

            criteria.CreateCriteria("Category").Add(Expression.Eq("Id", category.Id));
            return(Find(criteria, false));
        }
 public ICriteria AddCriteria(ICriteria criteria)
 {
     Debug.Assert(_objectId >= 0);
     var rest = Restrictions.Eq("Id", _objectId);
     var subcriteria = criteria.CreateCriteria(_propertyName);
     subcriteria.Add(rest);
     return criteria;
 }
Ejemplo n.º 32
0
        private static void GetFilterCriteria(ICriteria cr, Dictionary<string, object> filters)
        {
            string employee = Convert.ToString(filters["employee"]);
            string username = Convert.ToString(filters["username"]);
            int role = (int)filters["role"];
            int status = (int)filters["status"];
            bool statusVal = status == 1 ? true : false;

            if (!string.IsNullOrEmpty(username))
                cr.Add(Restrictions.InsensitiveLike("user.Username", username, MatchMode.Anywhere));

            if (role != 0)
                cr.Add(Restrictions.Eq("user.Role", role));

            if (status != 0)
                cr.Add(Restrictions.Eq("user.Status", statusVal));

            if (!string.IsNullOrEmpty(employee))
            {
                cr = cr.CreateCriteria("user.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);
            }
        }
Ejemplo n.º 33
0
    /// <summary>
    /// Adds the expressions criteria.
    /// </summary>
    /// <param name="criteria">The criteria.</param>
    /// <param name="expressions">The expressions.</param>
    /// <returns></returns>
    private void AddExpressionsCriteria(ICriteria criteria, IExpressionFactory expressions)
    {
        if (criteria != null)
        {
            SearchParameter clause;
            Boolean isLeads = (rdgIncludeType.SelectedIndex == 0);
            Boolean isPrimaryContact = (rdgIncludeType.SelectedIndex == 1);
            Boolean isIndividual = (rdgIncludeType.SelectedIndex == 3);

            criteria.Add(expressions.Eq("address.IsPrimary", true));
            if (isPrimaryContact)
            {
                criteria.Add(expressions.Eq("a1.IsPrimary", true));
            }
            if (chkCompany.Checked)
            {
                clause = (SearchParameter)lbxCompany.SelectedIndex;
                if (isLeads)
                    criteria.Add(GetExpression(expressions, clause, "a1.Company", txtCompany.Text));
                else
                    criteria.Add(GetExpression(expressions, clause, "account.AccountName", txtCompany.Text));
            }
            if (chkIndustry.Checked)
            {
                clause = (SearchParameter)lbxIndustry.SelectedIndex;
                if (isLeads)
                    criteria.Add(GetExpression(expressions, clause, "a1.Industry", pklIndustry.PickListValue));
                else
                    criteria.Add(GetExpression(expressions, clause, "account.Industry", pklIndustry.PickListValue));
            }
            if (chkSIC.Checked)
            {
                clause = (SearchParameter)lbxSIC.SelectedIndex;
                if (isLeads)
                    criteria.Add(GetExpression(expressions, clause, "a1.SICCode", txtSIC.Text));
                else
                    criteria.Add(GetExpression(expressions, clause, "account.SicCode", txtSIC.Text));
            }
            if (chkTitle.Checked)
            {
                clause = (SearchParameter)lbxTitle.SelectedIndex;
                criteria.Add(GetExpression(expressions, clause, "a1.Title", pklTitle.PickListValue));
            }
            if (chkProducts.Checked && !isLeads)
            {
                criteria.CreateCriteria("account.AccountProducts", "product");
                clause = (SearchParameter)lbxProducts.SelectedIndex;
                criteria.Add(GetExpression(expressions, clause, "product.ProductName", lueProducts.Text));
            }
            if (chkStatus.Checked)
            {
                clause = (SearchParameter)lbxStatus.SelectedIndex;
                if (isLeads || isIndividual)
                    criteria.Add(GetExpression(expressions, clause, "a1.Status", pklStatus.PickListValue));
                else
                    criteria.Add(GetExpression(expressions, clause, "account.Status", pklStatus.PickListValue));
            }
            if (!chkSolicit.Checked)
                criteria.Add(expressions.Or(expressions.Eq("a1.DoNotSolicit", false), expressions.IsNull("a1.DoNotSolicit")));
            if (!chkEmail.Checked)
                criteria.Add(expressions.Or(expressions.Eq("a1.DoNotEmail", false), expressions.IsNull("a1.DoNotEmail")));
            if (!chkCall.Checked)
                criteria.Add(expressions.Or(expressions.Eq("a1.DoNotPhone", false), expressions.IsNull("a1.DoNotPhone")));
            if (!chkMail.Checked)
                criteria.Add(expressions.Or(expressions.Eq("a1.DoNotMail", false), expressions.IsNull("a1.DoNotMail")));
            if (!chkFax.Checked)
            {
                if (isLeads)
                    criteria.Add(expressions.Or(expressions.Eq("a1.DoNotFAX", false), expressions.IsNull("a1.DoNotFAX")));
                else
                    criteria.Add(expressions.Or(expressions.Eq("a1.DoNotFax", false), expressions.IsNull("a1.DoNotFax")));
            }
            if (chkCity.Checked)
            {
                clause = (SearchParameter)lbxCity.SelectedIndex;
                AddCommaDelimitedStringsToExpression(criteria, expressions, txtCity.Text, "address.City", clause);
            }
            if (chkState.Checked)
            {
                clause = (SearchParameter)lbxState.SelectedIndex;
                AddCommaDelimitedStringsToExpression(criteria, expressions, txtState.Text, "address.State", clause);
            }
            if (chkZip.Checked)
            {
                clause = (SearchParameter)lbxZip.SelectedIndex;
                AddCommaDelimitedStringsToExpression(criteria, expressions, txtZip.Text, "address.PostalCode", clause);
            }
            if (chkLeadSource.Checked)
            {
                switch (rdgIncludeType.SelectedIndex)
                {
                    case 0:
                        criteria.CreateCriteria("a1.LeadSource", "leadsource");
                        break;
                    case 3:
                        criteria.CreateCriteria("a1.LeadSources", "leadsource");
                        break;
                    default:
                        criteria.CreateCriteria("account.LeadSource", "leadsource");
                        break;
                }
                clause = (SearchParameter)lbxLeadSource.SelectedIndex;
                criteria.Add(GetExpression(expressions, clause, "leadsource.Description", lueLeadSource.Text));
            }
            if (chkImportSource.Checked)
            {
                clause = (SearchParameter)lbxImportSource.SelectedIndex;
                if (isLeads || isIndividual)
                    criteria.Add(GetExpression(expressions, clause, "a1.ImportSource", pklImportSource.PickListValue));
                else
                    criteria.Add(GetExpression(expressions, clause, "account.ImportSource", pklImportSource.PickListValue));
            }
            if (!string.IsNullOrEmpty(dtpCreateFromDate.Text))
            {
                if (chkCreateDate.Checked && (isLeads || isIndividual))
                    criteria.Add(expressions.Between("a1.CreateDate", CheckForNullDate(dtpCreateFromDate.DateTimeValue), CheckForNullDate(dtpCreateToDate.DateTimeValue)));
                else if (chkCreateDate.Checked)
                    criteria.Add(expressions.Between("account.CreateDate", CheckForNullDate(dtpCreateFromDate.DateTimeValue), CheckForNullDate(dtpCreateToDate.DateTimeValue)));
            }
        }
        return;
    }
 public ICriteria CreateSubcriteria(ICriteria parent, IEnumerable<ICriteriaEvent> criteriaEvents)
 {
     // call the right overload to actually create the Criteria
     ICriteria crit;
     switch(methodSig)
     {
         case MethodSig.Association:
             crit = parent.CreateCriteria(association);
             break;
         case MethodSig.AssociationAndJoinType:
             crit = parent.CreateCriteria(association, joinType);
             break;
         case MethodSig.AssociationAndAlias:
             crit = parent.CreateCriteria(association, alias);
             break;
         case MethodSig.AssociationAndAliasAndJoinType:
             crit = parent.CreateCriteria(association, alias, joinType);
             break;
         default:
             throw new ShardedSessionException("Unknown constructor type for subcriteria creation: " + methodSig);
     }
     // apply the events
     foreach(ICriteriaEvent criteriaEvent in criteriaEvents)
     {
         criteriaEvent.OnEvent(crit);
     }
     return crit;
 }
Ejemplo n.º 35
0
        private static void SetJoinCriteria(ICriteria cr, Sort sort)
        {
            ICriteria crej = cr.GetCriteriaByAlias("ej");

            if (sort.Column == "d.Title")
            {
                ICriteria crd = cr.GetCriteriaByAlias("d");
                if (crej != null && crd == null)
                    cr = crej.CreateCriteria("ej.Designation", "d", JoinType.LeftOuterJoin);

                else if (crej == null && crd == null)
                {
                    crej = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);
                    cr = crej.CreateCriteria("ej.Designation", "d", JoinType.LeftOuterJoin);
                }
            }

            if (sort.Column == "es.Name")
            {
                ICriteria cres = cr.GetCriteriaByAlias("es");
                if (crej != null && cres == null)
                    cr = crej.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);

                else if (crej == null && cres == null)
                {
                    crej = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);
                    cr = crej.CreateCriteria("ej.Employmentstatus", "es", JoinType.LeftOuterJoin);
                }
            }

            if (sort.Column == "dept.Name")
            {
                ICriteria crdept = cr.GetCriteriaByAlias("dept");
                if (crej != null && crdept == null)
                    cr = crej.CreateCriteria("ej.Department", "dept", JoinType.LeftOuterJoin);

                else if (crej == null && crdept == null)
                {
                    crej = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);
                    cr = crej.CreateCriteria("ej.Department", "dept", JoinType.LeftOuterJoin);
                }
            }
        }
Ejemplo n.º 36
0
        private static void GetFilterCriteria(ICriteria cr, Dictionary<string, object> filters, Sort sort = null)
        {
            string employee = Convert.ToString(filters["employee"]);
            string staff_id = Convert.ToString(filters["staff_id"]);
            int employment_status = (int)filters["employment_status"];
            int designation = (int)filters["designation"];
            int dept = (int)filters["dept"];

            if (!string.IsNullOrEmpty(employee))
            {
                AbstractCriterion a1 = Restrictions.InsensitiveLike("employee.Firstname", employee, MatchMode.Anywhere);
                AbstractCriterion a2 = Restrictions.InsensitiveLike("employee.Middlename", employee, MatchMode.Anywhere);
                AbstractCriterion a3 = Restrictions.InsensitiveLike("employee.Lastname", employee, MatchMode.Anywhere);

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

                cr.Add(b2);
            }

            if (!string.IsNullOrEmpty(staff_id))
                cr.Add(Restrictions.InsensitiveLike("employee.Staffid", staff_id, MatchMode.Anywhere));

            if (employment_status != 0)
            {
                cr = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.InnerJoin);
                cr = cr.CreateCriteria("ej.Employmentstatus", "es", JoinType.InnerJoin);
                cr.Add(Restrictions.Eq("es.Id", employment_status));
            }

            if (designation != 0)
            {
                ICriteria crej = cr.GetCriteriaByAlias("ej");
                if (crej == null)
                    cr = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.InnerJoin);

                else
                    cr = crej;

                cr = cr.CreateCriteria("ej.Designation", "d", JoinType.InnerJoin);

                cr.Add(Restrictions.Eq("d.Id", designation));
            }

            if (dept != 0)
            {
                ICriteria crej = cr.GetCriteriaByAlias("ej");
                if (crej == null)
                    cr = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.InnerJoin);

                else
                    cr = crej;

                cr = cr.CreateCriteria("ej.Department", "dept", JoinType.InnerJoin);

                cr.Add(Restrictions.Eq("dept.Id", dept));
            }

            if (sort != null)
                SetJoinCriteria(cr, sort);
        }
Ejemplo n.º 37
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);
        }
Ejemplo n.º 38
0
 private static void SetJoinCriteria(ICriteria cr, Sort sort)
 {
     if (sort.Column == "e.Firstname")
     {
         ICriteria cre = cr.GetCriteriaByAlias("e");
         if (cre == null)
             cr = cr.CreateCriteria("attendance.Employee", "e", JoinType.LeftOuterJoin);
     }
 }