public List <T> GetByInclusionExample(T exampleInstance, string propertyName, bool ascending, params string[] propertiesToInclude)
        {
            //Get all of the properties of the given type (T)
            System.Reflection.PropertyInfo[] properties = persitentType.GetProperties();
            //System.Reflection.PropertyInfo[] properties = exampleInstance.GetType().GetProperties();

            ICriteria criteria = NHibernateSession.CreateCriteria(persitentType);
            Example   example  = Example.Create(exampleInstance);

            List <string> includedProperties = new List <string>(propertiesToInclude);

            //Exclude app properties except for the included properties
            foreach (System.Reflection.PropertyInfo property in properties)
            {
                if (!includedProperties.Contains(property.Name))
                {
                    //only exclude the property if it isn't in the propertiesToInclude list
                    example.ExcludeProperty(property.Name);
                }
            }

            criteria.Add(example);

            if (!string.IsNullOrEmpty(propertyName))
            {
                criteria.AddOrder(new Order(propertyName, ascending));
            }

            ListToGenericListConverter <T> converter = new ListToGenericListConverter <T>();

            return(converter.ConvertToGenericList(criteria.List()));
        }
Esempio n. 2
0
        private CurrencyRateConverter[,] UpdateCurrenciesArray()
        {
            object o = CacheManager.GetCached(CurrencyRate.CURRENCY_RATE);

            if (o != null)
            {
                CacheManager.ExpireItem(CurrencyRate.CURRENCY_RATE);
            }

            ICriteria crit = NHibernateSession.CreateCriteria(typeof(CurrencyRateView));

            crit.AddOrder(new Order("FromCurrency", true));
            crit.AddOrder(new Order("ToCurrency", true));

            IList <CurrencyRateView> tmp = crit.List <CurrencyRateView>();

            int indice = Convert.ToInt32(Math.Pow(tmp.Count, Convert.ToDouble(1) / 2));

            CurrencyRateConverter[,] lst = new CurrencyRateConverter[indice, indice];
            foreach (CurrencyRateView currencyRateView in tmp)
            {
                lst[currencyRateView.FromCurrency.ID - 1, currencyRateView.ToCurrency.ID - 1] = new CurrencyRateConverter(currencyRateView.ToCurrency.Description, currencyRateView.Rate);
            }
            o = lst;

            CacheManager.AddItem(CurrencyRate.CURRENCY_RATE, o);

            return(lst);
        }
Esempio n. 3
0
        public List <ProjectChangeRequest> Get(int projectID)
        {
            ICriteria criteria = NHibernateSession.CreateCriteria(typeof(ProjectChangeRequest))
                                 .Add(Expression.Eq("ProjectID", projectID));

            return(criteria.List <ProjectChangeRequest>() as List <ProjectChangeRequest>);
        }
 protected IList <T> _GetFirstN(int n)
 {
     return(NHibernateSession.CreateCriteria(concreteType)
            .SetFirstResult(0)
            .SetMaxResults(n)
            .List <T>() as List <T>);
 }
Esempio n. 5
0
        private ICriteria ListSearchCriteria(string search, Type type, CategoryBase parent)
        {
            ICriteria crit = GetCriteria();

            if (type != null)
            {
                crit = NHibernateSession.CreateCriteria(type);
            }


            if (!string.IsNullOrEmpty(search))
            {
                Disjunction d = new Disjunction();
                d.Add(Expression.InsensitiveLike("Name", search, MatchMode.Anywhere));
                d.Add(Expression.InsensitiveLike("Description", search, MatchMode.Anywhere));
                d.Add(Expression.InsensitiveLike("NameEnglish", search, MatchMode.Anywhere));
                d.Add(Expression.InsensitiveLike("DescripionEnglish", search, MatchMode.Anywhere));
                crit.Add(d);
            }

            if (parent != null)
            {
                crit.Add(Expression.Eq("Parent", parent));
            }

            return(crit);
        }
Esempio n. 6
0
 public IList <T> GetAll <T>() where T : class
 {
     return
         (NHibernateSession
          .CreateCriteria <T>()
          .List <T>());
 }
Esempio n. 7
0
        public decimal GetRate(Currency fromCurrency, Currency toCurrency)
        {
            ICriteria crit = NHibernateSession.CreateCriteria(typeof(CurrencyRateView));

            crit.Add(Expression.And(Expression.Eq("FromCurrency", fromCurrency), Expression.Eq("ToCurrency", toCurrency)));

            return(crit.UniqueResult <CurrencyRateView>().Rate);
        }
Esempio n. 8
0
        /// <summary>
        /// Gets all the records. It shouldn't be used unless the table has a few records for sure
        /// </summary>
        /// <returns></returns>
        public System.Collections.IList GetAll()
        {
            //NHibernateSession.Clear(); // temprorary fix for Dataaccess bug

            ICriteria criteria = NHibernateSession.CreateCriteria(persistentTypeT);

            return(criteria.List <T>() as List <T>);
        }
        public IList <Contact> GetProposerContacts(string description)
        {
            ICriteria criteria = NHibernateSession.CreateCriteria <Contact>();

            criteria.Add(Restrictions.Eq("Description", description));
            criteria.Add(Restrictions.Like("FullIncrementalPath", string.Format("{0}|", DocSuiteContext.Current.ResolutionEnv.ProposerContact.Value.ToString()), MatchMode.Start));
            return(criteria.List <Contact>());
        }
        /// <summary>
        /// Loads every instance of the requested type using the supplied <see cref="ICriterion" />.
        /// If no <see cref="ICriterion" /> is supplied, this behaves like <see cref="GetAll" />.
        /// </summary>
        public List <T> GetByCriteria(params ICriterion[] criterion)
        {
            ICriteria criteria = NHibernateSession.CreateCriteria(persitentType);

            foreach (ICriterion criterium in criterion)
            {
                criteria.Add(criterium);
            }
            return(criteria.List <T>() as List <T>);
        }
Esempio n. 11
0
        /// <summary>
        /// 根据给定的 <see cref="ICriterion" /> 来查询结果
        /// 如果没有传入 <see cref="ICriterion" />, 效果与 <see cref="GetAll" />一致.
        /// </summary>
        public IList <T> GetByCriteria(params ICriterion[] criterion)
        {
            ICriteria criteria = NHibernateSession.CreateCriteria(persitentType);

            foreach (ICriterion criterium in criterion)
            {
                criteria.Add(criterium);
            }
            criteria.AddOrder(new Order("ID", false));
            return(criteria.List <T>());
        }
Esempio n. 12
0
        public ShareCode GetByShortIdAndEntityTitle(string shareCodeShortId, string urlFriendlyEntityTitle)
        {
            ICriteria criteria = NHibernateSession
                                 .CreateCriteria(typeof(ShareCode), "ShareCode")
                                 .Add(Restrictions.Eq("ShareCode.ShortId", shareCodeShortId))
                                 .Add(Restrictions.Eq("ShareCode.UrlFriendlyEntityTitle", urlFriendlyEntityTitle));

            var shareCode = criteria.UniqueResult <ShareCode>();

            return(shareCode);
        }
        public int GetUniqueProjection(params IProjection[] proj)
        {
            ICriteria criteria = NHibernateSession.CreateCriteria(persitentType);

            foreach (IProjection criterium in proj)
            {
                criteria.SetProjection(criterium);
            }

            return(criteria.UniqueResult <int>());
        }
Esempio n. 14
0
        /// <summary>
        /// Loads a unique instance of the requested type using the supplied <see cref="ICriterion" />.
        /// </summary>
        public T GetUniqueByCriteria(params ICriterion[] criterion)
        {
            ICriteria criteria = NHibernateSession.CreateCriteria(persitentType);

            foreach (ICriterion criterium in criterion)
            {
                criteria.Add(criterium);
            }

            return((T)criteria.UniqueResult());
        }
        public List <T> GetByExample(T exampleInstance, params string[] propertiesToExclude)
        {
            ICriteria criteria = NHibernateSession.CreateCriteria(persitentType);
            Example   example  = Example.Create(exampleInstance);

            foreach (string propertyToExclude in propertiesToExclude)
            {
                example.ExcludeProperty(propertyToExclude);
            }
            criteria.Add(example);

            return(criteria.List <T>() as List <T>);
        }
Esempio n. 16
0
        public User GetByGooglePlusId(string googlePlusId)
        {
            User user = null;

            if (googlePlusId != string.Empty)
            {
                ICriteria criteria = NHibernateSession
                                     .CreateCriteria(typeof(User), "User")
                                     .Add(Restrictions.Eq("User.GooglePlusId", googlePlusId));

                user = criteria.UniqueResult <User>();
            }

            return(user);
        }
Esempio n. 17
0
        public void DeleteBy(String MaCt, DateTime TuNgay, DateTime DenNgay, Boolean TuDong)
        {
            ICriteria isearch = NHibernateSession.CreateCriteria <VnsKhNganSach>();

            isearch.Add(Restrictions.Eq("MaCt", MaCt));
            isearch.Add(Restrictions.Between("NgayKeHoach", TuNgay, DenNgay));
            isearch.Add(Restrictions.Eq("TuDong", TuDong));

            IList <VnsKhNganSach> lst = isearch.List <VnsKhNganSach>();

            foreach (VnsKhNganSach tmp in lst)
            {
                DeleteById(tmp.Id);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// 根据exampleInstance的属性值来查找对象,返回与其值一样的对象对表。
        /// exampleInstance中值为0或NULL的属性将不做为查找条件
        /// </summary>
        /// <param name="exampleInstance">参考对象</param>
        /// <param name="propertiesToExclude">要排除的查询条件属性名</param>
        /// <returns></returns>
        public IList <T> GetByExample(T exampleInstance, params string[] propertiesToExclude)
        {
            ICriteria criteria = NHibernateSession.CreateCriteria(exampleInstance.GetType());
            Example   example  = Example.Create(exampleInstance);

            foreach (string propertyToExclude in propertiesToExclude)
            {
                example.ExcludeProperty(propertyToExclude);
            }
            example.ExcludeNone();
            example.ExcludeNulls();
            example.ExcludeZeroes();
            criteria.Add(example);
            criteria.AddOrder(new Order("ID", false));
            return(criteria.List <T>());
        }
Esempio n. 19
0
        public IList <VnsChungTu> LoadBy(Guid LoaiCt, int Nam)
        {
            ICriteria isearch = NHibernateSession.CreateCriteria <VnsChungTu>();

            isearch.Add(Restrictions.Eq("LoaiCt", LoaiCt));


            isearch.Add(Restrictions.Le("NgayCt", VnsConvert.CEndOfDate(new DateTime(Nam, 12, 31))));
            isearch.Add(Restrictions.Ge("NgayCt", VnsConvert.CStartOfDate(new DateTime(Nam, 1, 1))));

            IList <VnsChungTu> lst = new List <VnsChungTu>();

            isearch.SetResultTransformer(Transformers.DistinctRootEntity);
            lst = isearch.List <VnsChungTu>();
            return(lst);
        }
Esempio n. 20
0
        public VnsLoaiChungTu GetByMa(String MaLoaiChungTu)
        {
            ICriteria isearch = NHibernateSession.CreateCriteria <VnsLoaiChungTu>();

            isearch.Add(Restrictions.Eq("MaLoaiChungTu", MaLoaiChungTu));

            IList <VnsLoaiChungTu> lst = isearch.List <VnsLoaiChungTu>();

            if (lst != null && lst.Count > 0)
            {
                return(lst[0]);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Overload that allows for sorting by one property
        /// If no <see cref="ICriterion" /> is supplied, this behaves like <see cref="GetAll" />.
        /// </summary>
        public List <T> GetByCriteria(string propertyName, bool ascending, params ICriterion[] criterion)
        {
            ICriteria criteria = NHibernateSession.CreateCriteria(persitentType);

            foreach (ICriterion criterium in criterion)
            {
                criteria.Add(criterium);
            }

            if (!string.IsNullOrEmpty(propertyName))
            {
                //If the propertyName is not empty, sort by that property
                criteria.AddOrder(new Order(propertyName, ascending));
            }

            ListToGenericListConverter <T> converter = new ListToGenericListConverter <T>();

            return(converter.ConvertToGenericList(criteria.List()));
        }
Esempio n. 22
0
        public IPageOfList <T> GetByExample(T exampleInstance, int pageIndex, int pageSize, params string[] propertiesToExclude)
        {
            ICriteria criteria = NHibernateSession.CreateCriteria(persitentType);
            Example   example  = Example.Create(exampleInstance);

            foreach (string propertyToExclude in propertiesToExclude)
            {
                example.ExcludeProperty(propertyToExclude);
            }
            example.ExcludeNone();
            example.ExcludeNulls();
            example.ExcludeZeroes();

            int recordTotal = Convert.ToInt32((criteria.Clone() as ICriteria).SetProjection(Projections.Count("ID")).UniqueResult());

            criteria.AddOrder(new Order("ID", false));
            criteria.Add(example).SetFirstResult(pageIndex * pageSize).SetMaxResults(pageSize);

            return(new PageOfList <T>(criteria.List <T>(), pageIndex, pageSize, recordTotal));
        }
        /// <summary>
        /// Loads every instance of the requested type using the supplied <see cref="ICriterion" />.
        /// If no <see cref="ICriterion" /> is supplied, this behaves like <see cref="GetAll" />.
        /// </summary>
        public T GetUniqueByCriteria(params ICriterion[] criterion)
        {
            ICriteria criteria = NHibernateSession.CreateCriteria(persitentType);

            if (criterion != null)
            {
                foreach (ICriterion criterium in criterion)
                {
                    criteria.Add(criterium);
                }
            }

            try
            {
                return(criteria.UniqueResult <T>());
            }
            catch
            {
                return(null);
            }
        }
        public List <T> GetByCriteria(ICriterion[] criterion, Order[] ords, List <KeyValuePair <String, String> > aliases)
        {
            ICriteria criteria = NHibernateSession.CreateCriteria(persitentType);

            if (criterion != null)
            {
                foreach (ICriterion criterium in criterion)
                {
                    criteria.Add(criterium);
                }
            }

            if (ords != null)
            {
                foreach (Order orden in ords)
                {
                    criteria.AddOrder(orden);
                }
            }

            if (aliases != null && aliases.Count > 0)
            {
                foreach (KeyValuePair <String, String> par in aliases)
                {
                    criteria.CreateAlias(par.Key, par.Value);
                }
            }

            var l = criteria.List <T>();

            if (l != null && l.Count > 0)
            {
                return(criteria.List <T>() as List <T>);
            }
            return(null);
        }
Esempio n. 25
0
        public IList <RpChiTietNganSach> GetBangKeChiTiet(DateTime TuNgay, DateTime DenNgay, String MaCt, Guid DonViId)
        {
            ICriteria isearch = NHibernateSession.CreateCriteria <VnsChungTu>().CreateAlias("LstGiaoDich", "d");

            if (!string.IsNullOrEmpty(MaCt))
            {
                isearch.Add(Restrictions.Eq("MaCt", MaCt));
            }

            isearch.Add(Restrictions.Le("NgayCt", VnsConvert.CEndOfDate(DenNgay)));
            isearch.Add(Restrictions.Ge("NgayCt", VnsConvert.CStartOfDate(TuNgay)));

            if (!VnsCheck.IsNullGuid(DonViId))
            {
                isearch.Add(Restrictions.Eq("DonViId", DonViId));
            }

            isearch.AddOrder(new Order("NgayCt", true));

            IList <VnsChungTu> lst = new List <VnsChungTu>();

            isearch.SetResultTransformer(Transformers.DistinctRootEntity);
            lst = isearch.List <VnsChungTu>();
            IList <RpChiTietNganSach> lstRp = new List <RpChiTietNganSach>();

            foreach (VnsChungTu tmph in lst)
            {
                foreach (VnsGiaoDich tmpd in tmph.LstGiaoDich)
                {
                    RpChiTietNganSach rp = new RpChiTietNganSach(tmph, tmpd);
                    lstRp.Add(rp);
                }
            }

            return(lstRp);
        }
Esempio n. 26
0
        public List <CategoryBase> GetByType(Type type)
        {
            ICriteria crit = NHibernateSession.CreateCriteria(type).AddOrder(new Order("Name", true));

            return(crit.List <CategoryBase>() as List <CategoryBase>);
        }
Esempio n. 27
0
        /// <summary>
        /// Gets all (view)
        /// </summary>
        /// <returns></returns>
        public IList <V> GetAllV()
        {
            ICriteria criteria = NHibernateSession.CreateCriteria(persistentTypeV);

            return(criteria.List <V>() as List <V>);
        }
Esempio n. 28
0
 public ICriteria GetCriteria(Type currentType)
 {
     return(NHibernateSession.CreateCriteria(currentType));
 }
Esempio n. 29
0
 public ICriteria GetCriteria()
 {
     return(NHibernateSession.CreateCriteria(persitentType));
 }
Esempio n. 30
0
        /// <summary>
        /// Imports an existing PriceImport into the final tables.
        /// </summary>
        /// <param name="id">Id of the PriceImport to process</param>
        /// <returns>True if import was successfully, otherwise false.</returns>
        ///

        public bool Import(Guid id, Guid userId)
        {
            List <CategoryBase> lstcat = new List <CategoryBase>();
            PriceImport         pi     = GetById(id);

            if (pi == null)
            {
                return(false);
            }
#if !DEBUG
            if (pi.ImportStatus != ImportStatus.SendToExecute)
            {
                Utils.GetLogger().Info(string.Format("[[PRODUCT IMPORT PROCESS]] Invalid Status: {0}", pi.ImportStatus));
                return(false);
            }

            pi.ImportStatus = ImportStatus.Executing;
            Save(pi);

            NHibernateSession.Flush();
#endif
            Utils.GetLogger().Info(string.Format("[[PRODUCT IMPORT PROCESS]] Starting ID: {0}", id));

            List <Currency>     currlist      = ControllerManager.Currency.GetAll() as List <Currency>;
            Currency            baseCurrency  = ControllerManager.Currency.GetByDescription("€");
            List <CurrencyRate> currencyRates = ControllerManager.CurrencyRate.GetLastList();

            // Todo make sure to free memory
            NHibernateSession.Flush();
            NHibernateSession.Clear();

            DetachedCriteria groupPermissionCriteria = DetachedCriteria.For <CategoryBase>()
                                                       .SetProjection(Projections.Property("ID"))
                                                       .CreateCriteria("PriceImportLogs").Add(Expression.Eq("PriceImport", pi));

            ICriterion groupSubquery = Subqueries.PropertyIn("ID", groupPermissionCriteria);

            ICriteria critCategories = NHibernateSession.CreateCriteria(typeof(CategoryBase));
            critCategories.SetFetchMode("Products", FetchMode.Join);
            critCategories.Add(groupSubquery);
            critCategories.SetResultTransformer(new NHibernate.Transform.DistinctRootEntityResultTransformer());
            List <CategoryBase> catlist = critCategories.List <CategoryBase>() as List <CategoryBase>;

            pi = this.GetById(id);

            // Save temporal priceBases changes
            IList <PriceBase> priceBasesAdd    = new List <PriceBase>();
            IList <PriceBase> priceBasesModify = new List <PriceBase>();

            ICriteria critLogResults = NHibernateSession.CreateCriteria(typeof(PriceImportLog)).
                                       SetFetchMode("ParsedCategories", FetchMode.Join).
                                       SetFetchMode("ParsedPriceBase", FetchMode.Join).
                                       SetFetchMode("ParsedPriceBase.PriceImports", FetchMode.Join).
                                       SetFetchMode("ParsedProvider", FetchMode.Join).
                                       Add(Expression.Eq("PriceImport", pi)).
                                       Add(Expression.Not(Expression.Eq("Status", PriceImportLogStatus.Error)));


            IList <PriceImportLog> pilList = critLogResults.List <PriceImportLog>();

            this.BeginTransaction();

            Utils.GetLogger().Info("[[PRODUCT IMPORT PROCESS]] Starting.");

            try
            {
                foreach (PriceImportLog logResult in pilList)
                {
                    PriceBase currentPriceBase = null;

                    switch (logResult.Status)
                    {
                    case PriceImportLogStatus.Add:

                        Product p = new Product();
                        p.Status         = ProductStatus.Active;
                        currentPriceBase = ControllerManager.PriceBase.Create(pi, logResult.CodGrundfos, logResult.CodProvider,
                                                                              logResult.Model, logResult.Description, logResult.ParsedProvider, logResult.ParsedFrequency,
                                                                              logResult.TP, FindInMemory(currlist, logResult.TPCurrency),
                                                                              logResult.GRP, FindInMemory(currlist, logResult.GRPCurrency),
                                                                              logResult.PL, FindInMemory(currlist, logResult.PLCurrency),
                                                                              logResult.ParsedCategories,
                                                                              p,
                                                                              baseCurrency,
                                                                              currencyRates);

                        priceBasesAdd.Add(currentPriceBase);
                        break;

                    case PriceImportLogStatus.Modify:
                        currentPriceBase = logResult.ParsedPriceBase;
                        //ControllerManager.PriceBaseHistory.SaveAudit(currentPriceBase, HistoryStatus.ModificationImport, userId);

                        currentPriceBase = ControllerManager.PriceBase.Modify(pi, logResult.CodGrundfos, logResult.CodProvider,
                                                                              logResult.Model, logResult.Description, logResult.ParsedProvider, logResult.ParsedFrequency,
                                                                              logResult.TP, FindInMemory(currlist, logResult.TPCurrency),
                                                                              logResult.GRP, FindInMemory(currlist, logResult.GRPCurrency),
                                                                              logResult.PL, FindInMemory(currlist, logResult.PLCurrency),
                                                                              logResult.ParsedCategories, currentPriceBase, baseCurrency, HistoryStatus.PriceChange, currencyRates);

                        priceBasesModify.Add(currentPriceBase);
                        break;
                    }

                    if (currentPriceBase != null)
                    {
                        foreach (CategoryBase cb in logResult.ParsedCategories)
                        {
                            catlist[catlist.IndexOf(cb)].Products.Add(currentPriceBase.Product);
                            if (!lstcat.Exists(delegate(CategoryBase record){ if ((record.ID == cb.ID))
                                                                              {
                                                                                  return(true);
                                                                              }
                                                                              return(false); }))
                            {
                                lstcat.Add(cb);
                            }
                        }
                    }

                    if (logResult.FileIndex % 500 == 0)
                    {
                        Utils.GetLogger().Debug(string.Format("[[PRODUCT IMPORT PROCESS]] Processing line: {0}", logResult.FileIndex));
                    }
                }
#if !DEBUG
                pi.ImportStatus         = ImportStatus.Processed;
                pi.TimeStamp.ModifiedBy = userId;
                pi.TimeStamp.ModifiedOn = DateTime.Now;
                Save(pi);
#endif
                // Make sure to process insert & updates in order.
                foreach (PriceBase pb in priceBasesAdd)
                {
                    pb.Product.TimeStamp.CreatedBy = userId;
                    pb.Product.TimeStamp.CreatedOn = DateTime.Now;
                    NHibernateSession.Save(pb.Product);
                }

                foreach (PriceBase pb in priceBasesAdd)
                {
                    pb.TimeStamp.CreatedBy = userId;
                    pb.TimeStamp.CreatedOn = DateTime.Now;
                    NHibernateSession.Save(pb);
                }

                foreach (PriceBase pb in priceBasesModify)
                {
                    pb.TimeStamp.ModifiedBy = userId;
                    pb.TimeStamp.ModifiedOn = DateTime.Now;
                    NHibernateSession.Save(pb);
                }

                foreach (PriceBase pb in priceBasesModify)
                {
                    pb.Product.TimeStamp.ModifiedBy = userId;
                    pb.Product.TimeStamp.ModifiedOn = DateTime.Now;
                    NHibernateSession.Save(pb.Product);
                }

                // Commit changes to DB
                CommitChanges();

                IQuery q = NHibernateSession.GetNamedQuery("CategoryCountUpdate");
                foreach (CategoryBase categoryBase in lstcat)
                {
                    q.SetInt32("CategoryId", categoryBase.ID);
                    q.UniqueResult();
                }

                IList <PriceBase> pbList = ControllerManager.PriceBase.Get(pi, PriceBaseStatus.NotVerified);
                PriceCalculator   pc     = new PriceCalculator(false, userId);
                pc.Run(pbList);

                // TODO: Send email to creator looking for the userId.
                // TODO: This process is run out of the web server, so it should look for it.

                Utils.GetLogger().Info("[[PRODUCT IMPORT PROCESS]] Finished Processing");
            }
            catch (Exception ex)
            {
                Utils.GetLogger().Error(ex);

                this.RollbackChanges();

                pi = GetById(id);
                pi.ImportStatus = ImportStatus.Failed;
                Save(pi);
                CommitChanges();

                throw ex;
            }

            return(true);
        }