Beispiel #1
0
        public JsonResult List(SysDictViewModel viewModel, PageInfo pageInfo)
        {
            QueryCollection queries = new QueryCollection();

            if (!string.IsNullOrEmpty(viewModel.Name))
            {
                queries.Add(new Query {
                    Name = "Name", Operator = Query.Operators.Contains, Value = viewModel.Name
                });
            }
            else if (!string.IsNullOrEmpty(viewModel.Code))
            {
                queries.Add(new Query {
                    Name = "Code", Operator = Query.Operators.Contains, Value = viewModel.Code
                });
            }
            else if (viewModel.TypeId != 0)
            {
                queries.Add(new Query {
                    Name = "TypeId", Operator = Query.Operators.Equal, Value = viewModel.TypeId
                });
            }
            var list = SysDictService.GetListByPage(queries.AsExpression <SysDict>(), x => true, pageInfo.Limit, pageInfo.Page, out int totalCount, true).Select(x => new
            {
                x.Id,
                x.Name,
                x.Code,
                x.SortCode
            }).ToList();

            return(Json(Pager.Paging(list, totalCount), JsonRequestBehavior.AllowGet));
        }
        public JsonResult List(SysUserViewModel viewModel, PageInfo pageInfo)
        {
            QueryCollection queries = new QueryCollection();

            if (!string.IsNullOrEmpty(viewModel.UserName))
            {
                queries.Add(new Query {
                    Name = "UserName", Operator = Query.Operators.Contains, Value = viewModel.UserName
                });
            }
            if (!string.IsNullOrEmpty(viewModel.NickName))
            {
                queries.Add(new Query {
                    Name = "NickName", Operator = Query.Operators.Contains, Value = viewModel.NickName
                });
            }
            var list = SysUserService.GetListByPage(queries.AsExpression <SysUser>(), x => true, pageInfo.Limit, pageInfo.Page, out int totalCount, true).Select(x => new
            {
                x.Id,
                x.UserName,
                x.NickName,
                x.HeadIcon,
                x.MobilePhone,
                x.Email,
                x.EnabledMark
            }).ToList();

            return(Json(Pager.Paging(list, totalCount), JsonRequestBehavior.AllowGet));
        }
        private string GenPostData()
        {
            QueryCollection queries = new QueryCollection();

            PropertyInfo[] propertyInfos = this.GetType().GetProperties(InstanceBindFlags);
            if (propertyInfos == null || propertyInfos.Length == 0)
            {
                throw new Exception("Can not get class properties.");
            }
            foreach (var item in propertyInfos)
            {
                string name = item.Name;
                if (name == "IsSignature")
                {
                    continue;
                }
                object valueObj = item.GetValue(this, null);
                string value    = valueObj?.ToString();
                queries.Add(name, value);
            }
            return(string.Join("&", queries.Select(t =>
            {
                if (string.Equals(t.Key, "domain", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(t.Key, "Signature") ||
                    string.Equals(t.Key, "recordline", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(t.Key, "subDomain", StringComparison.OrdinalIgnoreCase))
                {
                    return $"{t.Key}={(t.Value ?? "")}";
                }
                else
                {
                    return $"{HttpUtil.UrlEncode(t.Key)}={(t.Value == null ? "" : HttpUtil.UrlEncode(t.Value))}";
                }
            })));
        }
Beispiel #4
0
        /// <summary>
        /// Convert query collection business entity collection to model
        /// </summary>
        /// <param name="argQueryBECollection">Query business entity collection</param>
        /// <returns></returns>
        private QueryCollection ConvertUserRequestsToModel(QueryBECollection argQueryBECollection)
        {
            #region Declarations
            QueryCollection l_QueryCollection = new QueryCollection();
            Query           l_Query;
            #endregion
            try
            {
                if (argQueryBECollection != null && argQueryBECollection.Count > 0)
                {
                    foreach (var item in argQueryBECollection)
                    {
                        l_Query               = new Query();
                        l_Query.Name          = item.Name;
                        l_Query.Email         = item.Email;
                        l_Query.ContactNumber = item.ContactNumber;
                        l_Query.SkillPoints   = item.SkillPoints;

                        l_QueryCollection.Add(l_Query);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(l_QueryCollection);
        }
        protected CollectionBase  GenerateQueryCollectionFromReader(IDataReader returnData)
        {
            QueryCollection qCollection = new QueryCollection();

            while (returnData.Read())
            {
                Query newQuery = new Query((int)returnData["QueryId"], (string)returnData["QueryName"]);
                qCollection.Add(newQuery);
            }
            return(qCollection);
        }
Beispiel #6
0
        public void DoNotDuplicateQueryWhenCallingGetQuery()
        {
            var collection = new QueryCollection();
            var user       = new User("Test");
            var query      = new Query(user);

            collection.Add(query);
            var query2 = collection.GetQuery(user);

            Assert.Single(collection);
            Assert.Same(query, query2);
        }
Beispiel #7
0
        protected override void LoadDocument(string filename)
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.Load(filename);

            _queries = new QueryCollection(this);

            foreach (XmlNode node in xmlDocument.SelectNodes(@"xinq/queries/query"))
            {
                var query = new Query(this, node);
                _queries.Add(query);
            }
        }
Beispiel #8
0
        public JsonResult List(SysLogLogonViewModel viewModel, PageInfo pageInfo)
        {
            QueryCollection queries = new QueryCollection();

            if (!string.IsNullOrEmpty(viewModel.RealName))
            {
                queries.Add(new Query {
                    Name = "RealName", Operator = Query.Operators.Contains, Value = viewModel.RealName
                });
            }
            if (!string.IsNullOrEmpty(viewModel.Account))
            {
                queries.Add(new Query {
                    Name = "Account", Operator = Query.Operators.Contains, Value = viewModel.Account
                });
            }
            if (!string.IsNullOrEmpty(viewModel.StartEndDate))
            {
                queries.Add(new Query {
                    Name = "CreateTime", Operator = Query.Operators.GreaterThanOrEqual, Value = StartEndDateHelper.GteStartDate(viewModel.StartEndDate)
                });
                queries.Add(new Query {
                    Name = "CreateTime", Operator = Query.Operators.LessThanOrEqual, Value = StartEndDateHelper.GteEndDate(viewModel.StartEndDate)
                });
            }
            var list = SysLogLogonService.GetListByPage(queries.AsExpression <SysLogLogon>(), x => true, pageInfo.Limit, pageInfo.Page, out int totalCount, true).Select(x => new
            {
                x.Id,
                x.LogType,
                x.Account,
                x.RealName,
                x.Description,
                x.IPAddress,
                x.IPAddressName,
                x.CreateTime
            }).ToList();

            return(Json(Pager.Paging(list, totalCount), JsonRequestBehavior.AllowGet));
        }
        public Expression <Func <T, bool> > AsExpression <T>() where T : class
        {
            QueryCollection queryCollection = new QueryCollection();
            var             properties      = typeof(T).GetTypeInfo().GetProperties();

            foreach (var item in Columns)
            {
                var p = properties.FirstOrDefault(m => m.Name.Equals(item.Data, StringComparison.OrdinalIgnoreCase));
                if (p == null)
                {
                    continue;
                }
                var    realType = Nullable.GetUnderlyingType(p.PropertyType) ?? p.PropertyType;
                string value    = null;
                if (item.Search != null && item.Search.Value.IsNotNullAndWhiteSpace())
                {
                    value = item.Search.Value;
                }
                else if (Search != null && Search.Value.IsNotNullAndWhiteSpace() && realType == typeof(string))
                {
                    value = Search.Value;
                }
                if ((item.Search.Opeartor == Query.Operators.Range && item.Search.ValueMin.IsNullOrWhiteSpace() && item.Search.ValueMax.IsNullOrWhiteSpace()) ||
                    (item.Search.Opeartor != Query.Operators.Range && value.IsNullOrWhiteSpace()))
                {
                    continue;
                }

                Query query = new Query();
                query.Name = p.Name;
                try
                {
                    query.Value    = Easy.Reflection.ClassAction.ValueConvert(p, value);
                    query.ValueMin = Easy.Reflection.ClassAction.ValueConvert(p, item.Search.ValueMin);
                    query.ValueMax = Easy.Reflection.ClassAction.ValueConvert(p, item.Search.ValueMax);

                    if (query.ValueMax != null && query.ValueMax is DateTime)
                    {
                        query.ValueMax = ((DateTime)query.ValueMax).AddDays(1).AddMilliseconds(-1);
                    }
                }
                catch
                {
                    continue;
                }

                query.Operator = item.Search.Opeartor;
                queryCollection.Add(query);
            }
            return(queryCollection.AsExpression <T>(Query.Condition.AndAlso));
        }
Beispiel #10
0
        /// <summary>
        /// Gets the report queries.
        /// </summary>
        /// <param name="reportId">The report identifier.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        QueryCollection IReportIQTools.GetReportQueries(int reportId)
        {
            try
            {
                QueryCollection qCollection   = new QueryCollection();
                ClsObject       ReportManager = new ClsObject();
                ClsUtility.Init_Hashtable();
                string  queryStatement;
                DataMgr dataManager = new DataMgr();
                ClsUtility.AddParameters("@ReportID", SqlDbType.Int, reportId.ToString());
                queryStatement = @"Select Distinct	Q.QryID QueryID,
				                SB.sbCatID SubCategoryID,
				                SB.sbCategory SubCategory,
				                Q.qryName QueryName,
				                Q.qryDefinition Defination,
				                Q.qryDescription Description
                From dbo.aa_sbCategory SB
                Inner Join aa_Category C
	                On SB.CatID = C.CatID
                Inner Join dbo.aa_Queries Q On Q.qryID = SB.QryID
                Where (SB.DeleteFlag Is Null Or SB.DeleteFlag = 0) 
                And SB.QryID Is Not Null 
                And C.CatID=@ReportID;";
                DataTable dt = (DataTable)ReportManager.ReturnIQToolsObject(ClsUtility.theParams, queryStatement, ClsDBUtility.ObjectEnum.DataTable, ConnectionMode.REPORT);
                if (dt == null)
                {
                    return(null);
                }
                foreach (DataRow row in dt.Rows)
                {
                    //Query q = new
                    qCollection.Add(new Query()
                    {
                        QueryID       = Convert.ToInt16(row["QueryID"]),
                        Name          = row["QueryName"].ToString(),
                        SubCategoryID = Convert.ToInt16(row["SubCategoryID"]),
                        SubCategory   = row["SubCategory"].ToString(),
                        Defination    = row["Defination"].ToString(),
                        Description   = row["Description"].ToString()
                    });
                }
                ;

                return(qCollection);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #11
0
        private void Append(string value)
        {
            if (string.IsNullOrEmpty(Context))
            {
                throw new Exception("OData expression must have a context.");
            }

            if (!QueryCollection.ContainsKey(Context))
            {
                QueryCollection.Add(Context, value);
            }
            else
            {
                QueryCollection[Context] += value;
            }
        }
Beispiel #12
0
        //========================================================================================
        // ShowOpenCursors()
        //========================================================================================

        /// <summary>
        /// Opens a new query window and executes the SELECT FROM v$open_cursors statement.
        /// </summary>

        public void ShowOpenCursors()
        {
            string formattedSQL =
                "SELECT count(*), sql_text\n"
                + "  FROM v$open_cursor\n"
                + " GROUP BY sql_text\n"
                + " ORDER BY 1 DESC\n";

            InsertText(formattedSQL);

            IsSaved = true;
            SetTitle();

            //Execute(ParseMode.Sequential, editorView.SelectedText, 1);

            Logger.WriteLine("QueryWindow.ShowOpenCursors");
            commander.ExecuteControls.IsEnabled = true;
            SetStatusMessage(RxExecutingStatus);

            resultsView.Clear();

            if (splitContainer.Panel2Collapsed)
            {
                DoToggleResults(null, null);
            }

            splitContainer.SplitterDistance = (int)(splitContainer.Height * 0.2);

            // catch up on Windows messages just to look better
            Application.DoEvents();

            queries.Clear();
            driver.Reset();

            var query  = new Database.Query(formattedSQL.Replace("\n", String.Empty));
            var parser = new StatementParser();

            parser.ParseStatement(dbase, query, browser);
            queries.Add(query);

            // execute query collection

            resultsView.Lock();

            driver.Execute(queries, basePath, 1);
        }
Beispiel #13
0
        internal void SignatureRequest()
        {
            QueryCollection queries = new QueryCollection();

            PropertyInfo[] propertyInfos = this.GetType().GetProperties(InstanceBindFlags);
            if (propertyInfos == null || propertyInfos.Length == 0)
            {
                throw new Exception("Can not get class properties.");
            }
            foreach (var item in propertyInfos)
            {
                string name = item.Name;
                if (name == "IsSignature" || name == "Signature")
                {
                    continue;
                }
                object valueObj = item.GetValue(this, null);
                string value    = valueObj?.ToString();
                queries.Add(name, value);
            }
            queries.Sort((x, y) =>
            {
                for (int i = 0; i < (x.Key.Length < y.Key.Length ? x.Key.Length : y.Key.Length); i++)
                {
                    int val = x.Key[i] - y.Key[i];
                    if (val != 0)
                    {
                        return(val);
                    }
                    else
                    {
                        continue;
                    }
                }
                return(0);
            });

            StringBuilder sb = new StringBuilder();

            sb.Append(AppConfig.DdnsApiRequestMethod);
            sb.Append(AppConfig.DdnsApiRequestUrl.Replace("https://", ""));
            sb.Append("?");
            sb.Append(string.Join("&", queries.Select(t =>
            {
                //不能对中文进行URL Encode
                if (string.Equals(t.Key, "domain", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(t.Key, "recordline", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(t.Key, "subDomain", StringComparison.OrdinalIgnoreCase))
                {
                    return($"{t.Key}={(t.Value ?? "")}");
                }
                return($"{HttpUtil.UrlEncode(t.Key)}={(t.Value == null ? "" : HttpUtil.UrlEncode(t.Value))}");
            })));

            HMAC mac = null;

            if (SignatureMethod == SignatureType.HmacSHA1)
            {
                mac = new HMACSHA1(Encoding.UTF8.GetBytes(AppConfig.SecretKey));
            }
            else
            {
                mac = new HMACSHA256(Encoding.UTF8.GetBytes(AppConfig.SecretKey));
            }
            byte[] hashBytes = mac.ComputeHash(Encoding.UTF8.GetBytes(sb.ToString()));
            mac.Dispose();
            Signature   = HttpUtil.UrlEncode(Convert.ToBase64String(hashBytes));
            IsSignature = true;
        }
        public LambdaExpression GetExpression(Dictionary <string, object> enviromens = null)
        {
            FilterValues = FilterValue?.Split(',');
            if (enviromens != null && enviromens.ContainsKey(FilterValue))
            {
                var realValue     = enviromens[FilterValue];
                var realValueType = realValue.GetType();
                if (realValueType.GetInterface(nameof(IEnumerable)) != null && typeof(string) != realValueType)
                {
                    realValueType = realValueType.GetGenericArguments()[0];
                    MethodInfo toArrayMethod = typeof(Enumerable).GetMethod("ToArray")
                                               .MakeGenericMethod(new System.Type[] { realValueType });
                    FilterValues = toArrayMethod.Invoke(null, new object[] { realValue }) as object[];
                }

                else
                {
                    FilterValues = new object[] { realValue }
                };

                if (Type.GetType(this.PropertyType) != realValueType)
                {
                    throw new NotSupportedException("the propertyType can not compare to the value type ");
                }
            }

            PropertyPath = string.Join(".", PropertyNames);
            var enityType = Type.GetType(EntityType);
            LambdaExpression lambdaExpression = null;
            var parameter = Expression.Parameter(enityType, QueryCollection.ParameterSymbol);

            switch (FieldKind)
            {
            case FieldKind.ValueType:     //如:m.Id==2 或者m.Name.Contains("a") 或者m.Group.Name="a"
            case FieldKind.Reference:     //reference下的属性处理与ValueType是一致的,其实可以忽略掉
            {
                var queryCollection = new QueryCollection();
                var query           = new Query {
                    Name = this.PropertyPath, Operator = this.Operator
                };
                switch (query.Operator)
                {
                case Operators.Range:
                {
                    query.ValueMin = this.FilterValues[0];
                    query.ValueMax = this.FilterValues[1];
                    break;
                }

                case Operators.In:
                {
                    query.Value = this.FilterValues;
                    break;
                }

                default:
                    query.Value = this.FilterValues[0];
                    break;
                }
                queryCollection.Add(query);
                var method = typeof(QueryCollection).GetMethod("AsExpression");
                method = method.MakeGenericMethod(enityType);

                lambdaExpression = (LambdaExpression)method.GetReflector().Invoke(queryCollection, Query.Condition.AndAlso);
                break;
            }

            case FieldKind.ICollection:
            {
                if (this.RuleGroup == null)
                {
                    break;
                }
                var childLambda = this.RuleGroup.GetExpression();

                var member = QueryCollection.GetPropertyExpression(parameter, PropertyPath);
                if (member.Type.GetInterface(nameof(IEnumerable)) != null)
                {
                    lambdaExpression = Expression.Lambda(
                        Expression.Call(typeof(Enumerable), "Any", new Type[] { Type.GetType(this.RuleGroup.EntityType) }, member, childLambda),
                        parameter);
                }
                break;
            }

            case FieldKind.EnvType:    //用户的上下文环境变量,在json字符串阶段需提前用变量值替换掉,替换后,propertyPath其实就是一个值
            {
                var propertyType = Type.GetType(this.PropertyType);
                if (enviromens == null)
                {
                    throw new ArgumentNullException("enviroment values is null");
                }
                if (!enviromens.ContainsKey(this.PropertyPath))
                {
                    throw new ArgumentNullException("not such enviroment key and value");
                }
                var environmentValue = enviromens[this.PropertyPath];
                var left             = Expression.Constant(environmentValue);

                Expression expression = null;
                switch (Operator)
                {
                case Query.Operators.Equal:
                {
                    var right = Expression.Constant(ReflectorHelper.ValueConvert(propertyType, FilterValues[0]));
                    expression = Expression.Equal(left, right);
                    break;
                }

                case Query.Operators.GreaterThan:
                {
                    var right = Expression.Constant(ReflectorHelper.ValueConvert(propertyType, FilterValues[0]));
                    expression = Expression.GreaterThan(left, right);

                    break;
                }

                case Query.Operators.GreaterThanOrEqual:
                {
                    var right = Expression.Constant(ReflectorHelper.ValueConvert(propertyType, FilterValues[0]));
                    expression = Expression.GreaterThanOrEqual(left, right);

                    break;
                }

                case Query.Operators.LessThan:
                {
                    var right = Expression.Constant(ReflectorHelper.ValueConvert(propertyType, FilterValues[0]));
                    expression = Expression.LessThan(left, right);

                    break;
                }

                case Query.Operators.LessThanOrEqual:
                {
                    var right = Expression.Constant(ReflectorHelper.ValueConvert(propertyType, FilterValues[0]));
                    expression = Expression.LessThanOrEqual(left, right);

                    break;
                }

                case Query.Operators.Contains:
                {
                    var itemType = propertyType != typeof(string) && propertyType.GetInterface(nameof(IEnumerable)) != null ? propertyType.GenericTypeArguments[0] : propertyType;
                    var right    = Expression.Constant(ReflectorHelper.ValueConvert(itemType, FilterValues[0]));
                    expression = Expression.Call(left, "Contains", null, right);
                    break;
                }

                case Query.Operators.In:            //value必须是集合类型
                {
                    var constantVaule = ReflectorHelper.ValueConvert(propertyType, FilterValues);
                    var right         = Expression.Constant(constantVaule);

                    expression = Expression.Call(typeof(Enumerable), "Contains", new Type[] { propertyType }, right, left);

                    break;
                }

                case Query.Operators.StartWith:
                {
                    var right = Expression.Constant(ReflectorHelper.ValueConvert(propertyType, FilterValues[0]));

                    expression = Expression.Call(left, "StartsWith", null, right);

                    break;
                }

                case Query.Operators.EndWidth:
                {
                    var right = Expression.Constant(ReflectorHelper.ValueConvert(propertyType, FilterValues[0]));

                    expression = Expression.Call(left, "EndsWith", null, right);
                    break;
                }

                case Query.Operators.Range:
                {
                    Expression minExp = null, maxExp = null;
                    if (FilterValues.Length > 0 && FilterValues[0] != null)
                    {
                        var right = Expression.Constant(ReflectorHelper.ValueConvert(propertyType, FilterValues[0]));
                        minExp = Expression.GreaterThanOrEqual(left, right);
                    }
                    if (FilterValues.Length > 1 && FilterValues[1] != null)
                    {
                        var right = Expression.Constant(ReflectorHelper.ValueConvert(propertyType, FilterValues[1]));
                        maxExp = Expression.LessThanOrEqual(left, right);
                    }

                    if (minExp != null && maxExp != null)
                    {
                        expression = Expression.AndAlso(minExp, maxExp);
                    }
                    else if (minExp != null)
                    {
                        expression = minExp;
                    }
                    else if (maxExp != null)
                    {
                        expression = maxExp;
                    }

                    break;
                }
                }
                lambdaExpression = Expression.Lambda(expression, parameter);
                break;
            }

            default:
                break;
            }


            return(lambdaExpression);
        }
    }