private string CreateQueryString(ISearchExpression searchExpression, IList <ISearchOrder> searchOrders, NHibernate.ISessionFactory sessionFactory, Dictionary <string, object> paramNames)
        {
            if (searchExpression is QueryExpression)
            {
                return((searchExpression as QueryExpression).Query);
            }

            NHibernate.Metadata.IClassMetadata metaData = sessionFactory.GetClassMetadata(typeof(T));

            StringBuilder sb = new StringBuilder();

            sb.Append("from ");
            sb.Append(metaData.EntityName);
            sb.Append(" as Current ");
            if (searchExpression != null)
            {
                sb.Append("where ");
                sb.Append(GetQueryWhere(searchExpression, sessionFactory, paramNames));
            }

            if (searchOrders != null && searchOrders.Count > 0)
            {
                sb.Append("order by ");
                for (int i = 0; i < searchOrders.Count; ++i)
                {
                    sb.Append(GetQueryOrder(searchOrders[i]));
                    if (i != searchOrders.Count - 1)
                    {
                        sb.Append(",");
                    }
                }
            }

            // Eager Fetch
            if (this.EagerFetchs != null)
            {
                foreach (string s in this.EagerFetchs)
                {
                    sb.Append(" left join fetch Current.");
                    sb.Append(s);
                }
            }

            return(sb.ToString());
        }
        private string CreateQueryCountString(ISearchExpression searchExpression, NHibernate.ISessionFactory sessionFactory, Dictionary <string, object> paramNames)
        {
            if (searchExpression is QueryExpression)
            {
                string s = (searchExpression as QueryExpression).Query;

                int idx;
                //// remove joins
                //string[] joins = new string[] { "inner join", "left outer join", "right outer join", "full outer join", "left join", "right join", "full join" };
                //
                //foreach(string join in joins)
                //{
                //    idx = s.IndexOf(join);
                //    if (idx != -1)
                //    {
                //        s = s.Substring(0, idx).Trim();
                //    }
                //}

                idx = s.IndexOf("from");
                if (idx != -1)
                {
                    s = s.Substring(idx);
                }
                return("select count(*) " + s);
            }

            NHibernate.Metadata.IClassMetadata metaData = sessionFactory.GetClassMetadata(typeof(T));

            StringBuilder sb = new StringBuilder();

            sb.Append("select count(*) ");
            sb.Append("from ");
            sb.Append(metaData.EntityName);
            sb.Append(" ");
            if (searchExpression != null)
            {
                sb.Append("where ");

                sb.Append(GetQueryWhere(searchExpression, sessionFactory, paramNames));
            }
            return(sb.ToString());
        }
Beispiel #3
0
        private void tsbAttachment_Click(object sender, EventArgs e)
        {
            if (this.AttachmentForm == null)
            {
                return;
            }

            object entity = this.DisplayManager.CurrentItem;

            if (entity == null)
            {
                MessageForm.ShowWarning("请选择当前行!");
                return;
            }

            Type entityType = entity.GetType();
            var  sm         = ServiceProvider.GetService <Feng.NH.ISessionFactoryManager>();

            if (sm == null)
            {
                return;
            }
            NHibernate.ISessionFactory sessionFactory = sm.GetSessionFactory(Feng.Utils.RepositoryHelper.GetConfigNameFromType(entityType));
            if (sessionFactory == null)
            {
                return;
            }

            bool hasCollection;

            int idx = m_attachmentEntityIdExp.LastIndexOf('.');

            if (idx != -1)
            {
                string navi = m_attachmentEntityIdExp.Substring(0, idx);
                entityType = Feng.NH.NHibernateHelper.GetPropertyType(sessionFactory, entityType, navi, out hasCollection);
            }

            NHibernate.Metadata.IClassMetadata metaData = sessionFactory.GetClassMetadata(entityType);
            string entityName = metaData.EntityName;
            object id         = EntityScript.GetPropertyValue(entity, m_attachmentEntityIdExp);
            string entityId;

            //object id = EntityHelper.GetPropertyValue(entity, metaData.IdentifierPropertyName);
            if (id != null)
            {
                entityId = id.ToString();
            }
            else
            {
                MessageForm.ShowWarning("当前行无Id!");
                return;
            }

            string formText = entityName + ":" + entityId;
            IArhiveOperationMasterForm form = this.AttachmentForm;
            var form2 = form as ArchiveSeeForm;

            form2.tsbSearch.Visible = false;
            form.Text = formText + " 的附件";
            form.Show();
            form.DoView();

            form.DisplayManager.SearchManager.LoadData(SearchExpression.And(
                                                           SearchExpression.Eq("EntityName", entityName), SearchExpression.Eq("EntityId", entityId)), null);

            m_attachmentEntityName = entityName;
            m_attachmentEntityId   = entityId;
            //(form.ControlManager.Dao as BaseDao<AttachmentInfo>).EntityOperating += new EventHandler<OperateArgs<AttachmentInfo>>(delegate(object sender1, OperateArgs<AttachmentInfo> e1)
            //{
            //    e1.Entity.EntityName = entityName;
            //    e1.Entity.EntityId = entityId;
            //});

            (form.ControlManager.Dao as BaseDao <AttachmentInfo>).EntityOperating -= new EventHandler <OperateArgs <AttachmentInfo> >(AttachmentForm_EntityOperating);
            (form.ControlManager.Dao as BaseDao <AttachmentInfo>).EntityOperating += new EventHandler <OperateArgs <AttachmentInfo> >(AttachmentForm_EntityOperating);
        }