RookeyFrame 代码层面 常用方法
Posted guxingy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RookeyFrame 代码层面 常用方法相关的知识,希望对你有一定的参考价值。
测试代码均写在这个类里面的,因为是测试嘛,所以表名那些就将就看了。最后写完了再贴上全部代码
类的路径:Rookey.Frame.Operate.Base -> Test -> Class1.cs
1、获取用户信息
//获取 用户信息 public static string test1() string tempUserName = "admin"; string userpwd = "admin"; string errMsg = ""; UserInfo userInfo = UserOperate.GetUserInfo(tempUserName, userpwd, out errMsg); return JsonHelper.Serialize(userInfo);
2、获取分页数据
public static string test2() //用户信息 string tempUserName = "admin"; string userpwd = "admin"; string errMsg = ""; var currUser = UserOperate.GetUserInfo(tempUserName, userpwd, out errMsg); //构建request对象 var url = "http://localhost:8088/DataAsync/LoadGridData.html"; var para = "moduleId=d8e80345-71b7-4a3f-8d37-2f0f32e17cc5&tgt=0&gvId=bb9e294c-fcff-4c3c-bcd4-6584a0e5140a&page=1&rows=15"; var request = new HttpRequest("", url, para); HttpRequestWrapper wrapper = new HttpRequestWrapper(request); //获取 分页参数 var para_grid = GetGridDataParams(wrapper); //获取 分页数据 long total = 0; object list = CommonOperate.GetGridData(para_grid, out total, currUser); //var result = (list as IEnumerable).Paged(total); return JsonHelper.Serialize(list);
public static GridDataParmas GetGridDataParams(HttpRequestBase request) //模块信息 Sys_Module module = SystemOperate.GetModuleByRequest(request); if (module == null) return null; Type modelType = GetModelType(module.TableName); bool isEnableCache = ModelConfigHelper.IsModelEnableCache(modelType); string defaultSortField = isEnableCache || ModelConfigHelper.ModelIsViewMode(modelType) ? "CreateDate" : null; //分页信息 PageInfo pageInfo = PageInfo.GetPageInfo(request, defaultSortField); List<string> sortNames = pageInfo.sortname.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList(); if (sortNames != null && sortNames.Count > 0) List<string> tempSortNames = new List<string>(); foreach (string sortName in sortNames) if (SystemOperate.IsForeignNameField(module.Id, sortName)) tempSortNames.Add(sortName.Substring(0, sortName.Length - 4) + "Id"); else tempSortNames.Add(sortName); pageInfo.sortname = string.Join(",", tempSortNames); //搜索条件 string q = request["q"].ObjToStr().Trim(); if (!string.IsNullOrEmpty(q) && (string.IsNullOrEmpty(pageInfo.sortname) || pageInfo.sortname == "CreateDate")) var searchDic = JsonHelper.Deserialize<Dictionary<string, string>>(q); if (searchDic != null && searchDic.Count == 1) if (isEnableCache) pageInfo.sortname = string.Format("CreateDate,len(0)", searchDic.Keys.FirstOrDefault()); pageInfo.sortorder = "desc,asc"; else pageInfo.sortname = string.IsNullOrEmpty(pageInfo.sortname) ? string.Format("len(0),AutoIncrmId", searchDic.Keys.FirstOrDefault()) : string.Format("len(0),CreateDate", searchDic.Keys.FirstOrDefault()); pageInfo.sortorder = "asc,desc"; //自定义条件 string condition = HttpUtility.UrlDecode(request["condition"].ObjToStr()); //复杂条件集合 string cdItemStr = HttpUtility.UrlDecode(request["cdItems"]).ObjToStr(); List<ConditionItem> cdItems = new List<ConditionItem>(); if (!string.IsNullOrEmpty(cdItemStr)) try cdItems = JsonHelper.Deserialize<List<ConditionItem>>(cdItemStr); catch //where条件语句,用Base64加密后传输 string whereCon = string.Empty; try string tempWhere = HttpUtility.UrlDecode(request["where"].ObjToStr()); if (!string.IsNullOrWhiteSpace(tempWhere)) whereCon = HttpUtility.UrlDecode(MySecurity.DecodeBase64(tempWhere)).ReplaceSpecialCharOfSQL(); catch //弹出框的原始模块 string initModule = HttpUtility.UrlDecode(request["initModule"].ObjToStr()); //弹出框的原始字段 string initField = request["initField"].ObjToStr(); //弹出框的依赖字段值 string relyFieldsValue = HttpUtility.UrlDecode(request["p_relyValues"]); //自动完成字段名 string fieldName = request["fieldName"].ObjToStr(); //字段名 //组装参数对象 GridDataParmas gridParams = null; pageInfo.request = request; if (!string.IsNullOrWhiteSpace(initModule) && !string.IsNullOrWhiteSpace(initField)) //弹出框网格数据参数 gridParams = new DialogGridDataParams(module.Id, initModule, initField, pageInfo, q, condition, relyFieldsValue, cdItems, whereCon); else if (!string.IsNullOrWhiteSpace(fieldName)) //自动完成数据参数 gridParams = new AutoCompelteDataParams(module.Id, fieldName, pageInfo, q, condition, cdItems, whereCon); else gridParams = new GridDataParmas(module.Id, pageInfo, q, condition, cdItems, whereCon); try string gt = request["tgt"].ObjToStr(); gridParams.GridType = (DataGridType)Enum.Parse(typeof(DataGridType), gt); gridParams.PagingInfo.gridTypeParam = gridParams.GridType; if (gridParams.IsEditGridPageing) if (gridParams.GridType == DataGridType.EditDetailGrid && gridParams.PagingInfo != null && gridParams.PagingInfo.pagesize > 100) gridParams.PagingInfo.pagesize = 100; //编辑网格最多支持100条记录 else if (gridParams.GridType == DataGridType.EditDetailGrid) gridParams.PagingInfo.pagesize = 100; catch //其他参数 if (request.Params.AllKeys.Where(x => x.StartsWith("p_")).Count() > 0) gridParams.OtherParams = new Dictionary<string, string>(); List<string> keys = request.Params.AllKeys.Where(x => x.StartsWith("p_")).ToList(); foreach (string key in keys) gridParams.OtherParams.Add(key, request.Params[key]); if (request["node"].ObjToStr() != string.Empty) if (gridParams.OtherParams == null) gridParams.OtherParams = new Dictionary<string, string>(); gridParams.OtherParams.Add("node", HttpUtility.UrlDecode(request["node"].ObjToStr())); //行过滤规则解析 string filterRules = request["filterRules"].ObjToStr(); if (!string.IsNullOrEmpty(filterRules)) try List<GridFilterRule> gridFilters = JsonHelper.Deserialize<List<GridFilterRule>>(filterRules); List<ConditionItem> ruleItems = new List<ConditionItem>(); foreach (GridFilterRule rule in gridFilters) QueryMethod method = QueryMethod.Equal; string field = rule.field; if (rule.op == FilterOpEnum.isnull || rule.op == FilterOpEnum.isnotnull) method = rule.op == FilterOpEnum.isnull ? QueryMethod.Equal : QueryMethod.NotEqual; else method = (QueryMethod)Enum.Parse(typeof(QueryMethod), ((int)rule.op).ToString()); object value = rule.value; if (rule.op == FilterOpEnum.isnull || rule.op == FilterOpEnum.isnotnull) value = null; if (!CommonDefine.BaseEntityFields.Contains(field)) if (SystemOperate.IsForeignNameField(module.Id, field)) field = field.Substring(0, field.Length - 4) + "Id"; ruleItems.Add(new ConditionItem() Field = field, Method = method, Value = value ); gridParams.FilterRules = ruleItems; catch gridParams.ViewId = request["viewId"].ObjToGuidNull(); //综合视图Id gridParams.GridViewId = request["gvId"].ObjToGuidNull(); //当前加载视图ID gridParams.IsComprehensiveDetailView = request["dv"].ObjToInt() == 1; //综合明细视图 gridParams.IsDetailCopy = request["copy"].ObjToInt() == 1; //是否明细复制 gridParams.IsTreeGrid = request["tg"].ObjToInt() == 1; //是否为树型网格 gridParams.IsPermissionFilter = request["nfp"].ObjToInt() != 1; //是否过滤权限 gridParams.IsRestartFlow = request["rsf"].ObjToInt() == 1; //是否为重新发起流程 //调用自定义设置参数方法 ExecuteCustomeOperateHandleMethod(module.Id, "GridLoadDataParamsSet", new object[] module, gridParams, null ); return gridParams; public static Type GetModelType(string tableName) return BridgeObject.GetModelType(tableName); public static Type GetModelType(Guid moduleId) string tableName = SystemOperate.GetModuleTableNameById(moduleId); return BridgeObject.GetModelType(tableName); public static object ExecuteCustomeOperateHandleMethod(Guid moduleId, string methodName, object[] args) try Type tempType = typeof(OperateHandleFactory<>); Type modelType = GetModelType(moduleId); Type relectType = tempType.MakeGenericType(new Type[] modelType ); //实例化对象 object obj = Activator.CreateInstance(relectType); MethodInfo method = relectType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); if (method == null) return null; //反射执行方法 FastInvoke.FastInvokeHandler fastInvoker = FastInvoke.GetMethodInvoker(method); object executedObj = fastInvoker(obj, args); return executedObj; catch return null;
3、创建 Model
public static string test3() //这个类有一些要求,比如:需要用特性 ModuleConfig 来描述这个类 string errMsg = ToolOperate.RepairTables(new List<string> "Class1" ); return "测试:" + errMsg;
以上是关于RookeyFrame 代码层面 常用方法的主要内容,如果未能解决你的问题,请参考以下文章
Java 集合框架概述及Collection接口中常用的方法总结
SAP WM 初阶之不常用事务代码LB01 - Create TR Document