Esempio n. 1
0
        /// <summary>
        /// 为查询语句添加关联表的权限过滤
        /// </summary>
        /// <typeparam name="T">源数据类</typeparam>
        /// <param name="baseQuery">源Query</param>
        /// <param name="dps">数据权限</param>
        /// <param name="IdFields">关联表外键</param>
        /// <returns>修改后的查询语句</returns>
        public static IQueryable <T> DPWhere <T>(this IQueryable <T> baseQuery, List <DataPrivilege> dps, params Expression <Func <T, object> >[] IdFields)
        {
            //循环所有关联外键
            List <string> tableNameList = new List <string>();

            foreach (var IdField in IdFields)
            {
                //将外键 Id 用.分割,循环生成指向最终id的表达式,比如x=> x.a.b.Id
                var fieldName = IdField.GetPropertyName(false);
                //获取关联的类
                string typename = "";
                //如果外键名称不是‘id’,则根据model层的命名规则,它应该是xxxId,所以抹掉最后的 Id 应该是关联的类名
                if (fieldName.ToLower() != "id")
                {
                    fieldName = fieldName.Remove(fieldName.Length - 2);
                    typename  = IdField.GetPropertyInfo().DeclaringType.GetProperty(fieldName).PropertyType.Name;
                }
                //如果是 Id,则本身就是关联的类
                else
                {
                    typename = typeof(T).Name;
                }
                tableNameList.Add(typename);
            }
            //var test = DPWhere(baseQuery, dps, tableNameList, IdFields);
            return(DPWhere(baseQuery, dps, tableNameList, IdFields));
        }
Esempio n. 2
0
 /// <summary>
 ///     Removes the specified field.
 /// </summary>
 /// <param name="field">The field.</param>
 /// <externalUnit/>
 /// <revision revisor="dev11" date="11/2/2009" version="1.1.2.1101">
 ///     Member Created
 /// </revision>
 public void Remove(IdField field)
 {
     if (this.fieldMap.ContainsKey(field) == true)
     {
         this.fieldMap.Remove(field);
     }
 }
Esempio n. 3
0
        /// <summary>迭代抽取数据</summary>
        /// <returns></returns>
        public virtual IEnumerable <IList <IEntity> > Fetch()
        {
            while (true)
            {
                // 分割数据页,自增
                var exp = IdField >= Row;

                // 查询数据
                var list = Factory.FindAll(exp, IdField.Asc(), null, 0, BatchSize);
                if (list.Count == 0)
                {
                    break;
                }

                // 返回数据
                yield return(list);

                // 下一页
                if (list.Count < BatchSize)
                {
                    break;
                }

                // 自增分割时,取最后一行
                Row = (Int64)list.Last()[IdField.Name];
            }
        }
Esempio n. 4
0
        public override Form Init(object model, IPrincipal user = null)
        {
            var       init             = base.Init(model, user);
            CharField printTrayIdField = (CharField)GetField("PrinterTrayId");
            IdField   idField          = (IdField)GetField("Id");

            printTrayIdField.Options = new SelectList(PrintModelContext.GetPrinterTrays(Convert.ToInt32(idField.Value)), "Value", "Text", "Group.Name", printTrayIdField.Value, null);;
            return(init);
        }
Esempio n. 5
0
        /// <summary>
        ///     Gets the specified field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <returns>
        ///     The specified field.
        /// </returns>
        /// <externalUnit/>
        /// <revision revisor="dev11" date="4/8/2009" version="1.0.10.0501">
        ///     Comments added
        /// </revision>
        public object Get(IdField field)
        {
            object val = null;

            if (this.fieldMap.ContainsKey(field) == true)
            {
                val = this.fieldMap[field];
            }

            return(val);
        }
Esempio n. 6
0
        /// <summary>
        ///     Sets the specified field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="val">The value.</param>
        /// <returns>
        ///     returns [true] if the field was set. Typically this is
        ///     constrained by the mask
        /// </returns>
        /// <externalUnit/>
        /// <revision revisor="dev11" date="12/24/2008" version="1.0.0.0">
        ///     Member Created
        /// </revision>
        /// <revision revisor="dev11" date="03/11/2009" version="1.0.8.2201">
        ///     method now sets a field only if the mask allows it
        /// </revision>
        /// <revision revisor="dev11" date="11/02/2009" version="1.1.2.1101">
        ///     <see cref="IdField.ControlBallot"/> is not required to be
        ///     selected to be added to the identifier.
        /// </revision>
        public bool Set(IdField field, object val)
        {
            bool success = false;

            if (this.IsFieldSelected(field) || (IdField.ControlBallot == field))
            {
                if (this.fieldMap.ContainsKey(field) == true)
                {
                    this.fieldMap.Remove(field);
                }

                this.fieldMap.Add(field, val);
                success = true;
            }

            return(success);
        }
        public string Serialize(object value)
        {
            var valueList = value as List <object>;
            var docList   = new List <object>();

            foreach (var v in valueList)
            {
                JObject jObj         = JObject.FromObject(v);
                var     obj          = new object();
                var     objPropertys = JObject.FromObject(obj);

                var sp = IdField.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var s in sp)
                {
                    var t = jObj.GetValue(s);
                    if (t == null)
                    {
                        continue;
                    }
                    var sv = t.ToString();
                    jObj.Remove(s);
                    objPropertys.Add(s, sv);
                }

                var ps = jObj.Properties();
                foreach (var p in ps)
                {
                    var o = new
                    {
                        set = p.Value.ToObject <object>()
                    };

                    var vv = JToken.FromObject(o);
                    objPropertys.Add(p.Name, vv);
                }

                docList.Add(objPropertys);
            }

            return(JsonConvert.SerializeObject(docList));
        }
 public IdFieldTransformer(IdField field) : base("id", field.Negate)
 {
     Key = field.Id;
 }
Esempio n. 9
0
 public void FocusFirstField()
 {
     IdField.Focus();
 }
Esempio n. 10
0
 protected void PartnerForm_Loaded(object sender, RoutedEventArgs e)
 {
     IdField.Focus();
 }
Esempio n. 11
0
        /// <summary>
        /// 获取列表数据库
        /// </summary>
        /// <returns></returns>
        public string GetData()
        {
            string   json     = "";
            Database database = GetDatabase();
            object   obj      = "0";

            if (database != null)
            {
                string[] idFields = IdField.Split(',');
                for (int i = 0; i < idFields.Length; i++)
                {
                    idFields[i] = "[" + idFields[i] + "]";
                }

                string pkField = string.Join("+", idFields);

                string[] sortFields  = Sort.Split(',');
                string[] orderFields = Order.Split(',');
                for (int i = 0; i < sortFields.Length; i++)
                {
                    sortFields[i] = "[" + sortFields[i] + "]";
                    if (orderFields.Length > i)
                    {
                        sortFields[i] = sortFields[i] + " " + orderFields[i];
                    }
                }

                string sortField = string.Join(",", sortFields);
                Condition = Condition + Where;

                string sql = string.Empty;
                //多行递归
                if (ParentField != "" && ChildField != "")
                {
                    string lstr = string.Empty;
                    string sqls = string.Empty;
                    if (int.Parse(Page) > 1)
                    {
                        //是否关联查询
                        if (RelevanSearch == "true")
                        {
                            sql = "select * from (select row_number() over (order by " + sortField + ") as rowNum,* from " + TableName + " where 1=1 and ([" + ParentField + "] is NULL or [" + ParentField + "]='') " + Condition + " or (" + ChildField + " in (select " + ParentField + " from [" + TableName + "] where 1=1 " + Condition + ")) ) as t where rowNum between " + (int.Parse(Rows) * (int.Parse(Page) - 1) + 1) + " and " + (int.Parse(Rows) * (int.Parse(Page))) + " order by rowNum;";
                        }
                        else
                        {
                            sql = "select * from (select row_number() over (order by " + sortField + ") as rowNum,* from " + TableName + " where 1=1 and ([" + ParentField + "] is NULL or [" + ParentField + "]='') " + Condition + " ) as t where rowNum between " + (int.Parse(Rows) * (int.Parse(Page) - 1) + 1) + " and " + (int.Parse(Rows) * (int.Parse(Page))) + " order by rowNum;";
                        }
                    }
                    else
                    {
                        //是否关联查询
                        if (RelevanSearch == "true")
                        {
                            sql = "select top " + Rows + " * from (select row_number() over (order by " + sortField + ") as rowNum, * from [" + TableName + "] where 1=1 and ([" + ParentField + "] is NULL or [" + ParentField + "]='') " + Condition + " or (" + ChildField + " in (select " + ParentField + " from [" + TableName + "] where 1=1 " + Condition + "))  ) AS t ORDER BY rowNum;";
                        }
                        else
                        {
                            sql = "select top " + Rows + " * from (select row_number() over (order by " + sortField + ") as rowNum, * from [" + TableName + "] where 1=1 and ([" + ParentField + "] is NULL or [" + ParentField + "]='') " + Condition + "  ) AS t ORDER BY rowNum;";
                        }
                    }

                    //是否关联查询
                    if (RelevanSearch == "true")
                    {
                        obj = database.ExecuteScalar("select count(*) from " + TableName + " where 1=1 and ([" + ParentField + "] is NULL or [" + ParentField + "]='') " + Condition + " or (" + ChildField + " in (select " + ParentField + " from [" + TableName + "] where 1=1 " + Condition + "))");
                        sql = sql + "select * from [" + TableName + "] where  1=1 " + Condition + " or (" + ChildField + " in (select " + ParentField + " from [" + TableName + "] where 1=1 " + Condition + ") and sysstatus<>-1) or (" + ParentField + " in (select " + ChildField + " from [" + TableName + "] where 1=1 " + Condition + ") and sysstatus<>-1) order by " + sortField;
                    }
                    else
                    {
                        obj = database.ExecuteScalar("select count(*) from " + TableName + " where 1=1 and ([" + ParentField + "] is NULL or [" + ParentField + "]='') " + Condition);
                        sql = sql + "select * from [" + TableName + "] where  1=1 " + Condition + " order by " + sortField;
                    }
                    DataSet doc = database.ExecuteDataSet(sql);
                    if (doc.Tables[0].Rows.Count > 0)
                    {
                        //ParentField   TopGuid
                        //ChildField    Guid
                        json = "[";
                        var temp  = doc.Tables[0].Select();
                        var temp2 = doc.Tables[1].Select();
                        foreach (DataRow dr in doc.Tables[0].Select())
                        {
                            lstr = "";
                            DataRow[] drs = doc.Tables[1].Select(string.Format("{0}='{1}'", ParentField, dr[ChildField].ToString()));
                            if (drs.Length > 0)
                            {
                                json += ConvertJson.ToParentJson(dr, doc.Tables[0]);
                                json += ForTable(doc.Tables[1], dr[ChildField].ToString(), ParentField, ChildField, lstr);
                                json  = json.TrimEnd(',');
                                json += "]},";
                            }
                            else
                            {
                                json += ConvertJson.ToNoParentJson(dr, doc.Tables[0]);
                            }
                        }
                        json  = json.TrimEnd(',');
                        json += "]";
                    }
                    else
                    {
                        json = "[]";
                    }
                }
                //无递归
                else
                {
                    if (int.Parse(Page) > 1)
                    {
                        sql = "select * from (select row_number() over (order by " + sortField + ") as rowNum,* from " + TableName + " where 1=1" + Condition + " ) as t where rowNum between " + (int.Parse(Rows) * (int.Parse(Page) - 1) + 1) + " and " + (int.Parse(Rows) * (int.Parse(Page))) + " order by rowNum";
                        //sql = "select top " + rows + " *  from [" + tableName + "] where " + pkField + " not in (select top " + (int.Parse(rows) * (int.Parse(page) - 1)).ToString() + " " + pkField + " from [" + tableName + "] where 1=1 " + condition + " order by " + sortField + " " + order + ") " + condition + " order by " + sortField + " " + order;
                    }
                    else
                    {
                        sql = "select top " + Rows + " * from (select row_number() over (order by " + sortField + ") as rowNum, * from [" + TableName + "] where 1=1 " + Condition + "  ) AS t ORDER BY rowNum";
                    }



                    DataSet doc = database.ExecuteDataSet(sql);
                    obj = database.ExecuteScalar("select count(*) from " + TableName + " where 1=1 " + Condition);

                    if (doc.Tables[0].Rows.Count > 0)
                    {
                        json = ConvertJson.ToJson(doc.Tables[0]);
                    }
                    else
                    {
                        json = "[]";
                    }
                }
            }
            else
            {
                json = "[]";
                obj  = "0";
            }
            json = "{\"total\":" + obj.ToString() + ",\"rows\":" + json + "}";
            return(json);
        }
Esempio n. 12
0
        /// <summary>
        /// 为查询语句添加关联表的权限过滤
        /// </summary>
        /// <typeparam name="T">源数据类</typeparam>
        /// <param name="baseQuery">源Query</param>
        /// <param name="dps">数据权限</param>
        /// <param name="tableName">关联数据权限的表名,如果关联外键为自身,则参数第一个为自身</param>
        /// <param name="IdFields">关联表外键</param>
        /// <returns>修改后的查询语句</returns>
        public static IQueryable <T> DPWhere <T>(this IQueryable <T> baseQuery, List <DataPrivilege> dps, List <string> tableName, params Expression <Func <T, object> >[] IdFields)
        {
            // var dpsSetting = BaseVM.AllDPS;
            ParameterExpression pe       = Expression.Parameter(typeof(T));
            Expression          left1    = Expression.Constant(1);
            Expression          right1   = Expression.Constant(1);
            Expression          trueExp  = Expression.Equal(left1, right1);
            Expression          falseExp = Expression.NotEqual(left1, right1);
            Expression          finalExp = null;

            //循环所有关联外键
            foreach (var IdField in IdFields)
            {
                Expression exp = trueExp;
                //将外键Id用.分割,循环生成指向最终id的表达式,比如x=> x.a.b.Id
                var        fullname = IdField.GetPropertyName();
                string[]   splits   = fullname.Split('.');
                Expression peid     = Expression.PropertyOrField(pe, splits[0]);
                for (int i = 1; i < splits.Length; i++)
                {
                    peid = Expression.PropertyOrField(peid, splits[i]);
                }
                //如果dps为空,则拼接一个返回假的表达式,这样就查询不出任何数据
                if (dps == null)
                {
                    exp = falseExp;
                }
                else
                {
                    var fieldName = IdField.GetPropertyName(false);
                    //如果外键名称不是‘id’,则根据model层的命名规则,它应该是xxxId,所以抹掉最后的 Id 应该是关联的类名
                    if (fieldName.ToLower() != "id")
                    {
                        fieldName = fieldName.Remove(fieldName.Length - 2);
                        //var IsTableName = tableName?.Where(x => x == fieldName).FirstOrDefault();
                        var IsTableName = tableName?.Where(x => x.ToLower().Contains(fieldName.ToLower())).FirstOrDefault();
                        if (string.IsNullOrEmpty(IsTableName))
                        {
                            continue;
                        }
                        fieldName = IsTableName;
                        //typename = PropertyHelper.GetPropertyInfo(IdField).DeclaringType.GetProperty(fieldName).PropertyType.Name;
                    }
                    //如果是Id,则本身就是关联的类
                    else
                    {
                        fieldName = tableName[0];
                    }
                    var dpsSetting = GlobalServices.GetService <Configs>().DataPrivilegeSettings;

                    //循环系统设定的数据权限,如果没有和关联类一样的表,则跳过
                    if (dpsSetting.Where(x => x.ModelName == fieldName).SingleOrDefault() == null)
                    {
                        continue;
                    }
                    //获取dps中关联到关联类的id列表
                    var ids = dps.Where(x => x.TableName == fieldName).Select(x => x.RelateId).ToList();
                    //如果没有关联的id,则拼接一个返回假的where,是语句查询不到任何数据
                    if (ids == null || ids.Count() == 0)
                    {
                        if (peid.Type == typeof(Guid))
                        {
                            exp = Expression.Equal(peid, Expression.Constant(Guid.NewGuid()));
                        }
                        else
                        {
                            exp = Expression.Equal(peid, Expression.Constant(null));
                        }
                    }
                    //如果有关联 Id
                    else
                    {
                        //如果关联 Id 不包含null,则生成类似 x=> ids.Contains(x.a.b.Id) 这种条件
                        //如果关联 Id 包括null,则代表可以访问所有数据,就不需要再拼接where条件了
                        if (!ids.Contains(null))
                        {
                            exp = ids.GetContainIdExpression <T>(peid).Body;
                        }
                    }
                }
                //把所有where里的条件用And拼接在一起
                if (finalExp == null)
                {
                    finalExp = exp;
                }
                else
                {
                    finalExp = Expression.Or(finalExp, exp);
                }
            }
            //如果没有进行任何修改,则还返回baseQuery
            if (finalExp == null)
            {
                return(baseQuery);
            }
            else
            {
                //返回加入了where条件之后的baseQuery
                var query = baseQuery.Where(Expression.Lambda <Func <T, bool> >(finalExp, pe));
                return(query);
            }
        }
Esempio n. 13
0
 public override int GetHashCode()
 {
     return(CategoryField.GetHashCode() + IdField.GetHashCode()
            + (InputDataFile ?? "").GetHashCode() + (ReadHeader ? 1 : 0));
 }
Esempio n. 14
0
 private SearchNode(IdField id)
 {
     Id   = id;
     Type = SearchNodeType.Id;
 }
Esempio n. 15
0
 public static SearchNode IdSearchNode(IdField idField)
 {
     return(new SearchNode(idField));
 }
Esempio n. 16
0
        /// <summary>
        /// 为查询语句添加关联表的权限过滤
        /// </summary>
        /// <typeparam name="T">源数据类</typeparam>
        /// <param name="baseQuery">源Query</param>
        /// <param name="knifeVirgo">context</param>
        /// <param name="tableName">关联数据权限的表名,如果关联外键为自身,则参数第一个为自身</param>
        /// <param name="IdFields">关联表外键</param>
        /// <returns>修改后的查询语句</returns>
        public static IQueryable <T> DPWhere <T>(this IQueryable <T> baseQuery, VirgoContext knifeVirgo, List <string> tableName, params Expression <Func <T, object> >[] IdFields) where T : TopBasePoco
        {
            var dps = knifeVirgo?.LoginUserInfo?.DataPrivileges;

            // var dpsSetting = BaseVM.AllDPS;
            ParameterExpression pe       = Expression.Parameter(typeof(T));
            Expression          left1    = Expression.Constant(1);
            Expression          right1   = Expression.Constant(1);
            Expression          trueExp  = Expression.Equal(left1, right1);
            Expression          falseExp = Expression.NotEqual(left1, right1);
            Expression          finalExp = null;
            int tindex = 0;

            //循环所有关联外键
            foreach (var IdField in IdFields)
            {
                bool       mtm = false;
                Expression exp = trueExp;
                //将外键Id用.分割,循环生成指向最终id的表达式,比如x=> x.a.b.Id
                var      fullname  = IdField.GetPropertyName();
                string[] splits    = fullname.Split('.');
                int      leftindex = splits[0].IndexOf('[');
                if (leftindex > 0)
                {
                    mtm       = true;
                    splits[0] = splits[0].Substring(0, leftindex);
                }
                Expression peid       = Expression.MakeMemberAccess(pe, pe.Type.GetSingleProperty(splits[0]));
                Type       middletype = null;
                if (mtm)
                {
                    middletype = peid.Type.GetGenericArguments()[0];
                }
                else
                {
                    for (int i = 1; i < splits.Length; i++)
                    {
                        peid = Expression.MakeMemberAccess(peid, peid.Type.GetSingleProperty(splits[i]));
                    }
                    middletype = (peid as MemberExpression).Member.DeclaringType;
                }
                //如果dps为空,则拼接一个返回假的表达式,这样就查询不出任何数据
                if (dps == null)
                {
                    exp = falseExp;
                }
                else
                {
                    var fieldName = IdField.GetPropertyName(false);
                    //如果外键名称不是‘id’,则根据model层的命名规则,它应该是xxxId,所以抹掉最后的 Id 应该是关联的类名
                    if (fieldName.ToLower() != "id")
                    {
                        fieldName = fieldName.Remove(fieldName.Length - 2);
                        var typeinfo = middletype.GetSingleProperty(fieldName);
                        //var IsTableName = tableName?.Where(x => x == fieldName).FirstOrDefault();
                        var IsTableName = tableName?.Where(x => x.ToLower() == typeinfo.PropertyType.Name.ToLower()).FirstOrDefault();
                        if (string.IsNullOrEmpty(IsTableName))
                        {
                            continue;
                        }
                        fieldName = IsTableName;
                        //typename = PropertyHelper.GetPropertyInfo(IdField).DeclaringType.GetProperty(fieldName).PropertyType.Name;
                    }
                    //如果是Id,则本身就是关联的类
                    else
                    {
                        fieldName = tableName[tindex];
                    }
                    var dpsSetting = knifeVirgo.DataPrivilegeSettings;

                    //循环系统设定的数据权限,如果没有和关联类一样的表,则跳过
                    if (dpsSetting.Where(x => x.ModelName == fieldName).SingleOrDefault() == null)
                    {
                        continue;
                    }
                    //获取dps中关联到关联类的id列表
                    var ids = dps.Where(x => x.TableName == fieldName).Select(x => x.RelateId).ToList();
                    //如果没有关联的id,则拼接一个返回假的where,是语句查询不到任何数据
                    if (ids == null || ids.Count == 0)
                    {
                        exp = falseExp;
                        //if (peid.Type == typeof(Guid))
                        //{
                        //    exp = Expression.Equal(peid, Expression.Constant(Guid.NewGuid()));
                        //}
                        //else
                        //{
                        //    exp = Expression.Equal(peid, Expression.Constant(null));
                        //}
                    }
                    //如果有关联 Id
                    else
                    {
                        //如果关联 Id 不包含null,则生成类似 x=> ids.Contains(x.a.b.Id) 这种条件
                        //如果关联 Id 包括null,则代表可以访问所有数据,就不需要再拼接where条件了
                        if (!ids.Contains(null))
                        {
                            if (mtm == true)
                            {
                                ParameterExpression midpe    = Expression.Parameter(middletype);
                                Expression          middleid = Expression.PropertyOrField(midpe, IdField.GetPropertyName(false));

                                var queryable = Expression.Call(
                                    typeof(Queryable),
                                    "AsQueryable",
                                    new Type[] { middletype },
                                    peid);

                                List <Guid> ddd = new List <Guid>();

                                exp = Expression.Call(
                                    typeof(Queryable),
                                    "Any",
                                    new Type[] { middletype },
                                    queryable,
                                    Expression.Lambda(typeof(Func <,>).MakeGenericType(middletype, typeof(bool)), ids.GetContainIdExpression(middletype, midpe, middleid).Body, new ParameterExpression[] { midpe }));
                            }
                            else
                            {
                                exp = ids.GetContainIdExpression(typeof(T), pe, peid).Body;
                            }
                        }
                    }
                }
                //把所有where里的条件用And拼接在一起
                if (finalExp == null)
                {
                    finalExp = exp;
                }
                else
                {
                    finalExp = Expression.OrElse(finalExp, exp);
                }
                tindex++;
            }
            //如果没有进行任何修改,则还返回baseQuery
            if (finalExp == null)
            {
                return(baseQuery);
            }
            else
            {
                //返回加入了where条件之后的baseQuery
                var query = baseQuery.Where(Expression.Lambda <Func <T, bool> >(finalExp, pe));
                return(query);
            }
        }
Esempio n. 17
0
 /// <summary>
 ///     Determines whether the specified field is present on the
 ///     identifier
 /// </summary>
 /// <param name="field">The field.</param>
 /// <returns>
 ///     <c>true</c> if the specified field is present;
 ///     otherwise, <c>false</c>.
 /// </returns>
 /// <externalUnit/>
 /// <revision revisor="dev11" date="11/2/2009" version="1.1.2.1101">
 ///     Member Created
 /// </revision>
 public bool HasField(IdField field)
 {
     return(this.fieldMap.ContainsKey(field));
 }