예제 #1
0
        public override System.Data.DataSet GetList(Guid treeNodeID, Guid userID, OrderExpression order, List<SearchExpression> searchExpression, PagingInfo pagingInfo)
        {
            Query.Query query = new Query.Query(this);
            //query.ClassificationTreeID = treeNodeID;
            query.Columns = this.GetUserProperties(userID, treeNodeID, FieldPlaceHolder.Grid);

            foreach (SearchExpression expr in searchExpression)
            {
                // основная версия
                if (expr.FieldID == new Guid("BBE170B0-28E4-4738-B365-1038B03F4552") && !query.Columns.Exists(p => p.ID == new Guid("BBE170B0-28E4-4738-B365-1038B03F4552")))
                {
                    query.Columns.Add(this.GetColumnPropertyByID(new Guid("BBE170B0-28E4-4738-B365-1038B03F4552")));
                }
                // IsBeing
                if (expr.FieldCond == Condition.Beable && !query.Columns.Exists(p => p.ID == new Guid(expr.FieldValue)))
                {
                    query.Columns.Add(this.GetColumnPropertyByID(new Guid(expr.FieldValue)));
                }
                // InList
                if (expr.FieldCond == Condition.Inset && expr.FieldName == "ID")
                {
                    expr.FieldName = "Product.ID";
                }
            }

            query.UserFields = this.GetUserFields(userID, treeNodeID, FieldPlaceHolder.Grid);
            // default order by nomen super pole
            if (order.OrderClause == string.Empty)
            {
                //IUserField uf = query.UserFields.SingleOrDefault(u => u.DictionaryProperty.ID == new Guid("CAE5AFF1-1103-45CF-8135-7834DC9FAD35"));
                IUserField uf = query.UserFields.FirstOrDefault(u => u.DictionaryProperty.ID == new Guid("CAE5AFF1-1103-45CF-8135-7834DC9FAD35") && u.DictionaryTreeID == new Guid("316C6BC7-D883-44C8-AAE0-602F49C73595"));

                if (uf != null)
                {
                    order = new OrderExpression()
                    {
                        Expression = string.Format("{0}.{1}", uf.DictionaryTree.Alias, uf.DictionaryProperty.ColumnName),
                        SortDirection = SortDirection.asc
                    };
                }
            }
            //
            query.OrderExpression = order;
            query.SearchExpression = this.ValidateSearchExpression(query.Columns, query.UserFields, searchExpression);

            string sql = query.BuildListQuery(treeNodeID);
            using (CommonDataProvider provider = new CommonDataProvider())
            {
                if (pagingInfo.Enabled)
                {
                    StringBuilder cursor = new StringBuilder();
                    cursor.AppendLine("DECLARE @handle int, @rows int;");
                    cursor.AppendLine("EXEC sp_cursoropen @handle OUT,");
                    cursor.AppendFormat("'{0}',", sql.Replace("'", "''"));
                    cursor.AppendLine("1,1,@rows OUT SELECT @rows;");
                    cursor.AppendFormat("EXEC sp_cursorfetch @handle, 16, {0}, {1}\n", pagingInfo.Start + 1, pagingInfo.Limit);
                    cursor.AppendLine("EXEC sp_cursorclose @handle;");
                    return provider.ExecuteCommand(cursor.ToString());
                }
                else
                {
                    return provider.ExecuteCommand(sql);
                }
            }
        }
예제 #2
0
 public override System.Data.DataRow GetEntity(Guid ID, Guid userID, Guid treeNodeID)
 {
     Query.Query query = new Query.Query(this);
     query.Columns = this.GetUserProperties(userID, treeNodeID, FieldPlaceHolder.GridCard);
     query.UserFields = this.GetUserFields(userID, treeNodeID, FieldPlaceHolder.GridCard);
     string sql = query.BuildEntityQuery(ID);
     using (CommonDataProvider provider = new CommonDataProvider())
     {
         System.Data.DataSet ds = provider.ExecuteCommand(sql);
         if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) return ds.Tables[0].Rows[0];
         else return null;
     }
 }